Example #1
0
        internal SharpDX.Direct3D11.SamplerState GetState(GraphicsDevice device)
        {
            if (_state == null)
            {
                // Build the description.
                var desc = new SharpDX.Direct3D11.SamplerStateDescription();

                desc.AddressU = GetAddressMode(AddressU);
                desc.AddressV = GetAddressMode(AddressV);
                desc.AddressW = GetAddressMode(AddressW);

                desc.Filter            = GetFilter(Filter);
                desc.MaximumAnisotropy = MaxAnisotropy;
                desc.MipLodBias        = MipMapLevelOfDetailBias;

                // TODO: How do i do these?
                desc.MinimumLod  = 0.0f;
                desc.BorderColor = new SharpDX.Color4(0, 0, 0, 0);

                // To support feature level 9.1 these must
                // be set to these exact values.
                desc.MaximumLod         = float.MaxValue;
                desc.ComparisonFunction = SharpDX.Direct3D11.Comparison.Never;

                // Create the state.
                _state = new SharpDX.Direct3D11.SamplerState(GraphicsDevice._d3dDevice, desc);
            }

            Debug.Assert(GraphicsDevice == device, "The state was created for a different device!");

            return(_state);
        }
        private void CreateNativeDeviceChild()
        {
            SharpDX.Direct3D11.SamplerStateDescription nativeDescription;

            nativeDescription.AddressU = (SharpDX.Direct3D11.TextureAddressMode)Description.AddressU;
            nativeDescription.AddressV = (SharpDX.Direct3D11.TextureAddressMode)Description.AddressV;
            nativeDescription.AddressW = (SharpDX.Direct3D11.TextureAddressMode)Description.AddressW;
            nativeDescription.BorderColor = ColorHelper.Convert(Description.BorderColor);
            nativeDescription.ComparisonFunction = (SharpDX.Direct3D11.Comparison)Description.CompareFunction;
            nativeDescription.Filter = (SharpDX.Direct3D11.Filter)Description.Filter;
            nativeDescription.MaximumAnisotropy = Description.MaxAnisotropy;
            nativeDescription.MaximumLod = Description.MaxMipLevel;
            nativeDescription.MinimumLod = Description.MinMipLevel;
            nativeDescription.MipLodBias = Description.MipMapLevelOfDetailBias;

            // For 9.1, anisotropy cannot be larger then 2
            // mirror once is not supported either
            if (GraphicsDevice.Features.Profile == GraphicsProfile.Level_9_1)
            {
                // TODO: Min with user-value instead?
                nativeDescription.MaximumAnisotropy = 2;

                if (nativeDescription.AddressU == SharpDX.Direct3D11.TextureAddressMode.MirrorOnce)
                    nativeDescription.AddressU = SharpDX.Direct3D11.TextureAddressMode.Mirror;
                if (nativeDescription.AddressV == SharpDX.Direct3D11.TextureAddressMode.MirrorOnce)
                    nativeDescription.AddressV = SharpDX.Direct3D11.TextureAddressMode.Mirror;
                if (nativeDescription.AddressW == SharpDX.Direct3D11.TextureAddressMode.MirrorOnce)
                    nativeDescription.AddressW = SharpDX.Direct3D11.TextureAddressMode.Mirror;
            }

            NativeDeviceChild = new SharpDX.Direct3D11.SamplerState(NativeDevice, nativeDescription);
        }
        internal SharpDX.Direct3D11.SamplerState GetState(GraphicsDevice device)
        {
            if (_state == null)
            {
                // Build the description.
                var desc = new SharpDX.Direct3D11.SamplerStateDescription();

                desc.AddressU = GetAddressMode(AddressU);
                desc.AddressV = GetAddressMode(AddressV);
                desc.AddressW = GetAddressMode(AddressW);

                desc.Filter = GetFilter(Filter);
                desc.MaximumAnisotropy = MaxAnisotropy;
                desc.MipLodBias = MipMapLevelOfDetailBias;

                // TODO: How do i do these?
                desc.MinimumLod = 0.0f;
                desc.BorderColor = new SharpDX.Color4(0, 0, 0, 0);

                // To support feature level 9.1 these must 
                // be set to these exact values.
                desc.MaximumLod = float.MaxValue;
                desc.ComparisonFunction = SharpDX.Direct3D11.Comparison.Never;

                // Create the state.
                _state = new SharpDX.Direct3D11.SamplerState(GraphicsDevice._d3dDevice, desc);
            }

            Debug.Assert(GraphicsDevice == device, "The state was created for a different device!");

            return _state;
        }
Example #4
0
        public GpuSamplerState(GpuDevice device,
                               GpuTextureAddressMode addressU,
                               GpuTextureAddressMode addressV,
                               GpuTextureAddressMode addressW,
                               GpuTextureFilter filter = GpuTextureFilter.MinMagMipLinear)
        {
            GpuDevice = device;

            //set address mode
            AddressU = addressU;
            AddressV = addressV;
            AddressW = addressW;

            Filter = filter;

            mSamplerState = new SharpDX.Direct3D11.SamplerState(GpuDevice.Device, new SharpDX.Direct3D11.SamplerStateDescription()
            {
                AddressU           = GpuConvert.ToTextureAddressMode(AddressU),
                AddressV           = GpuConvert.ToTextureAddressMode(AddressV),
                AddressW           = GpuConvert.ToTextureAddressMode(AddressW),
                Filter             = GpuConvert.ToTextureFilter(Filter),
                ComparisonFunction = SharpDX.Direct3D11.Comparison.Never,
                MinimumLod         = float.MinValue,
                MaximumLod         = float.MaxValue,
                BorderColor        = new SharpDX.Mathematics.Interop.RawColor4(1, 1, 1, 1),
                MaximumAnisotropy  = 4,
                MipLodBias         = 0.0f
            });
        }
Example #5
0
        internal void PlatformSetSamplers(GraphicsDevice device)
        {
            if (_applyToVertexStage && !device.GraphicsCapabilities.SupportsVertexTextures)
            {
                return;
            }

            // Skip out if nothing has changed.
            if (_d3dDirty == 0)
            {
                return;
            }

            // NOTE: We make the assumption here that the caller has
            // locked the d3dContext for us to use.
            SharpDX.Direct3D11.CommonShaderStage shaderStage;
            if (_applyToVertexStage)
            {
                shaderStage = device._d3dContext.VertexShader;
            }
            else
            {
                shaderStage = device._d3dContext.PixelShader;
            }

            for (var i = 0; i < _actualSamplers.Length; i++)
            {
                var mask = 1 << i;
                if ((_d3dDirty & mask) == 0)
                {
                    continue;
                }

                var sampler = _actualSamplers[i];
                SharpDX.Direct3D11.SamplerState state = null;
                if (sampler != null)
                {
                    state = sampler.GetState(device);
                }

                shaderStage.SetSampler(i, state);

                _d3dDirty &= ~mask;
                if (_d3dDirty == 0)
                {
                    break;
                }
            }

            if (_d3dDirty != 0)
            {
                throw new System.Exception($"SamplerStateCollection still dirty ({_d3dDirty})");
            }
            //_d3dDirty = 0;
        }
Example #6
0
        /// <summary>
        /// Creates device-based resources to store a constant buffer, cube
        /// geometry, and vertex and pixel shaders. In some cases this will also
        /// store a geometry shader.
        /// </summary>
        public void CreateDeviceDependentResourcesAsync()
        {
            ReleaseDeviceDependentResources();

            // Create a constant buffer to store the model matrix.
            modelConstantBuffer = this.ToDispose(SharpDX.Direct3D11.Buffer.Create(
                                                     deviceResources.D3DDevice,
                                                     SharpDX.Direct3D11.BindFlags.ConstantBuffer,
                                                     ref modelConstantBufferData));

            // Create the Texture, ShaderResource and Sampler state
            lock (thisLock)
            {
                m_texture = this.ToDispose(new SharpDX.Direct3D11.Texture2D(deviceResources.D3DDevice, new SharpDX.Direct3D11.Texture2DDescription()
                {
                    Format            = SharpDX.DXGI.Format.R8G8B8A8_UNorm,
                    Width             = (int)m_mediaPlayer.PlaybackSession.NaturalVideoWidth,  //Width
                    Height            = (int)m_mediaPlayer.PlaybackSession.NaturalVideoHeight, //Height
                    MipLevels         = 1,
                    ArraySize         = 1,
                    BindFlags         = SharpDX.Direct3D11.BindFlags.ShaderResource | SharpDX.Direct3D11.BindFlags.RenderTarget,
                    Usage             = SharpDX.Direct3D11.ResourceUsage.Default,
                    CpuAccessFlags    = SharpDX.Direct3D11.CpuAccessFlags.None,
                    SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                    OptionFlags       = SharpDX.Direct3D11.ResourceOptionFlags.None
                }));

                m_textureView = this.ToDispose(new SharpDX.Direct3D11.ShaderResourceView(deviceResources.D3DDevice, m_texture));
            }

            m_quadTextureSamplerState = this.ToDispose(new SharpDX.Direct3D11.SamplerState(deviceResources.D3DDevice, new SharpDX.Direct3D11.SamplerStateDescription()
            {
                Filter             = SharpDX.Direct3D11.Filter.Anisotropic,
                AddressU           = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                AddressV           = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                AddressW           = SharpDX.Direct3D11.TextureAddressMode.Clamp,
                MaximumAnisotropy  = 3,
                MinimumLod         = 0,
                MaximumLod         = 3,
                MipLodBias         = 0,
                BorderColor        = new SharpDX.Mathematics.Interop.RawColor4(0, 0, 0, 0),
                ComparisonFunction = SharpDX.Direct3D11.Comparison.Never
            }));

            CreateD3D11Surface();
            LoadShaders();
        }
Example #7
0
        internal void SetSamplers(GraphicsDevice device)
        {
            // Skip out if nothing has changed.
            if (_dirty == 0)
            {
                return;
            }

#if DIRECTX
            // NOTE: We make the assumption here that the caller has
            // locked the d3dContext for us to use.
            var pixelShaderStage = device._d3dContext.PixelShader;
#endif
            for (var i = 0; i < _samplers.Length; i++)
            {
                var mask = 1 << i;
                if ((_dirty & mask) == 0)
                {
                    continue;
                }

                var sampler = _samplers[i];
#if OPENGL
                var texture = device.Textures[i];
                if (sampler != null && texture != null)
                {
                    sampler.Activate(texture.glTarget, texture.LevelCount > 1);
                }
#elif DIRECTX
                SharpDX.Direct3D11.SamplerState state = null;
                if (sampler != null)
                {
                    state = sampler.GetState(device);
                }

                pixelShaderStage.SetSampler(i, state);
#endif

                _dirty &= ~mask;
                if (_dirty == 0)
                {
                    break;
                }
            }

            _dirty = 0;
        }
        private void CreateNativeDeviceChild()
        {
            SharpDX.Direct3D11.SamplerStateDescription nativeDescription;

            nativeDescription.AddressU           = (SharpDX.Direct3D11.TextureAddressMode)Description.AddressU;
            nativeDescription.AddressV           = (SharpDX.Direct3D11.TextureAddressMode)Description.AddressV;
            nativeDescription.AddressW           = (SharpDX.Direct3D11.TextureAddressMode)Description.AddressW;
            nativeDescription.BorderColor        = ColorHelper.Convert(Description.BorderColor);
            nativeDescription.ComparisonFunction = (SharpDX.Direct3D11.Comparison)Description.CompareFunction;
            nativeDescription.Filter             = (SharpDX.Direct3D11.Filter)Description.Filter;
            nativeDescription.MaximumAnisotropy  = Description.MaxAnisotropy;
            nativeDescription.MaximumLod         = Description.MaxMipLevel;
            nativeDescription.MinimumLod         = Description.MinMipLevel;
            nativeDescription.MipLodBias         = Description.MipMapLevelOfDetailBias;

            NativeDeviceChild = new SharpDX.Direct3D11.SamplerState(NativeDevice, nativeDescription);
        }
        internal void PlatformSetSamplers(GraphicsDevice device)
        {
            // Skip out if nothing has changed.
            if (_d3dDirty == 0)
            {
                return;
            }

            // NOTE: We make the assumption here that the caller has
            // locked the d3dContext for us to use.
            SharpDX.Direct3D11.CommonShaderStage shaderStage;
            if (_applyToVertexStage)
            {
                shaderStage = device._d3dContext.VertexShader;
            }
            else
            {
                shaderStage = device._d3dContext.PixelShader;
            }

            for (var i = 0; i < _actualSamplers.Length; i++)
            {
                var mask = 1 << i;
                if ((_d3dDirty & mask) == 0)
                {
                    continue;
                }

                var sampler = _actualSamplers[i];
                SharpDX.Direct3D11.SamplerState state = null;
                if (sampler != null)
                {
                    state = sampler.GetState(device);
                }

                shaderStage.SetSampler(i, state);

                _d3dDirty &= ~mask;
                if (_d3dDirty == 0)
                {
                    break;
                }
            }

            _d3dDirty = 0;
        }
        /// <summary>
        /// Draws a quad with a texture. This Draw method is using a simple pixel shader that is sampling the texture.
        /// </summary>
        /// <param name="texture">The texture to draw.</param>
        /// <param name="samplerState">State of the sampler. If null, default sampler is <see cref="SamplerStateCollection.LinearClamp" />.</param>
        /// <param name="fullScreenTriangle">if set to <c>true</c> to draw an optimized full screen triangle as a full screen quad.</param>
        public void Draw(SharpDX.Direct3D11.ShaderResourceView texture, SharpDX.Direct3D11.SamplerState samplerState = null, bool fullScreenTriangle = false)
        {
            GraphicsDevice.SetVertexBuffer(fullScreenTriangle ? sharedData.VertexBufferFullQuad : sharedData.VertexBuffer);
            GraphicsDevice.SetVertexInputLayout(sharedData.VertexInputLayout);

            ResetShaderStages();

            // Make sure that we are using our vertex shader
            textureParameter.SetResource(texture);
            textureSamplerParameter.SetResource(samplerState ?? GraphicsDevice.SamplerStates.LinearClamp);
            textureCopyPass.Apply();
            GraphicsDevice.Draw(PrimitiveType.TriangleStrip, fullScreenTriangle ? 3 : 4);

            // Reset the vertex buffer
            GraphicsDevice.SetVertexBuffer(0, null, 0);
            GraphicsDevice.InputAssemblerStage.InputLayout = null; // NOTE SmartK8: Verify functionality
            GraphicsDevice.Context.PixelShader.SetShaderResource(0, null);
        }
Example #11
0
        /// <summary>
        /// Draws a quad with a texture. This Draw method is using a simple pixel shader that is sampling the texture.
        /// </summary>
        /// <param name="texture">The texture to draw.</param>
        /// <param name="samplerState">State of the sampler. If null, default sampler is <see cref="SamplerStateCollection.LinearClamp" />.</param>
        public void Draw(SharpDX.Direct3D11.ShaderResourceView texture, SharpDX.Direct3D11.SamplerState samplerState = null)
        {
            GraphicsDevice.SetVertexBuffer(sharedData.VertexBuffer);
            GraphicsDevice.SetVertexInputLayout(sharedData.VertexInputLayout);

            ResetShaderStages();

            // Make sure that we are using our vertex shader
            textureParameter.SetResource(texture);
            textureSamplerParameter.SetResource(samplerState ?? GraphicsDevice.SamplerStates.LinearClamp);
            textureCopyPass.Apply();
            GraphicsDevice.Draw(PrimitiveType.TriangleStrip, 4);

            // Reset the vertex buffer
            GraphicsDevice.SetVertexBuffer(0, null, 0);
            GraphicsDevice.InputAssemblerStage.SetInputLayout(null);
            GraphicsDevice.Context.PixelShader.SetShaderResource(0, null);
        }
        internal SharpDX.Direct3D11.SamplerState GetState(GraphicsDevice device)
        {
            if (_state == null)
            {
                // Build the description.
                var desc = new SharpDX.Direct3D11.SamplerStateDescription
                {
                    AddressU = GetAddressMode(AddressU),
                    AddressV = GetAddressMode(AddressV),
                    AddressW = GetAddressMode(AddressW),

#if WINDOWS_UAP
                    desc.BorderColor = new SharpDX.Mathematics.Interop.RawColor4(
                        BorderColor.R / 255.0f,
                        BorderColor.G / 255.0f,
                        BorderColor.B / 255.0f,
                        BorderColor.A / 255.0f);
#else
                    BorderColor = BorderColor.ToColor4(),
#endif
                    Filter             = GetFilter(Filter, FilterMode),
                    MaximumAnisotropy  = Math.Min(MaxAnisotropy, device.Capabilities.MaxTextureAnisotropy),
                    MipLodBias         = MipMapLevelOfDetailBias,
                    ComparisonFunction = ComparisonFunction.ToComparison(),

                    // TODO: How do i do this?
                    MinimumLod = 0.0f,

                    // To support feature level 9.1 these must
                    // be set to these exact values.
                    MaximumLod = float.MaxValue
                };

                // Create the state.
                _state = new SharpDX.Direct3D11.SamplerState(GraphicsDevice._d3dDevice, desc);
            }

            Debug.Assert(GraphicsDevice == device, "The state was created for a different device!");

            return(_state);
        }
        internal SharpDX.Direct3D11.SamplerState GetState(GraphicsDevice device)
        {
            if (_state == null)
            {
                // Build the description.
                var desc = new SharpDX.Direct3D11.SamplerStateDescription();

                desc.AddressU = GetAddressMode(AddressU);
                desc.AddressV = GetAddressMode(AddressV);
                desc.AddressW = GetAddressMode(AddressW);

#if WINDOWS_UAP
				desc.BorderColor = new SharpDX.Mathematics.Interop.RawColor4(
					BorderColor.R / 255.0f,
					BorderColor.G / 255.0f,
					BorderColor.B / 255.0f,
					BorderColor.A / 255.0f);
#else
				desc.BorderColor = BorderColor.ToColor4();
#endif
				desc.Filter = GetFilter(Filter, ComparisonFunction != CompareFunction.Never);
                desc.MaximumAnisotropy = MaxAnisotropy;
                desc.MipLodBias = MipMapLevelOfDetailBias;
                desc.ComparisonFunction = ComparisonFunction.ToComparison();

                // TODO: How do i do this?
                desc.MinimumLod = 0.0f;

                // To support feature level 9.1 these must 
                // be set to these exact values.
                desc.MaximumLod = float.MaxValue;

                // Create the state.
                _state = new SharpDX.Direct3D11.SamplerState(GraphicsDevice._d3dDevice, desc);
            }

            Debug.Assert(GraphicsDevice == device, "The state was created for a different device!");

            return _state;
        }
Example #14
0
        private void CreateNativeDeviceChild()
        {
            SharpDX.Direct3D11.SamplerStateDescription nativeDescription;

            nativeDescription.AddressU           = (SharpDX.Direct3D11.TextureAddressMode)Description.AddressU;
            nativeDescription.AddressV           = (SharpDX.Direct3D11.TextureAddressMode)Description.AddressV;
            nativeDescription.AddressW           = (SharpDX.Direct3D11.TextureAddressMode)Description.AddressW;
            nativeDescription.BorderColor        = ColorHelper.Convert(Description.BorderColor);
            nativeDescription.ComparisonFunction = (SharpDX.Direct3D11.Comparison)Description.CompareFunction;
            nativeDescription.Filter             = (SharpDX.Direct3D11.Filter)Description.Filter;
            nativeDescription.MaximumAnisotropy  = Description.MaxAnisotropy;
            nativeDescription.MaximumLod         = Description.MaxMipLevel;
            nativeDescription.MinimumLod         = Description.MinMipLevel;
            nativeDescription.MipLodBias         = Description.MipMapLevelOfDetailBias;

            // For 9.1, anisotropy cannot be larger then 2
            // mirror once is not supported either
            if (GraphicsDevice.Features.CurrentProfile == GraphicsProfile.Level_9_1)
            {
                // TODO: Min with user-value instead?
                nativeDescription.MaximumAnisotropy = 2;

                if (nativeDescription.AddressU == SharpDX.Direct3D11.TextureAddressMode.MirrorOnce)
                {
                    nativeDescription.AddressU = SharpDX.Direct3D11.TextureAddressMode.Mirror;
                }
                if (nativeDescription.AddressV == SharpDX.Direct3D11.TextureAddressMode.MirrorOnce)
                {
                    nativeDescription.AddressV = SharpDX.Direct3D11.TextureAddressMode.Mirror;
                }
                if (nativeDescription.AddressW == SharpDX.Direct3D11.TextureAddressMode.MirrorOnce)
                {
                    nativeDescription.AddressW = SharpDX.Direct3D11.TextureAddressMode.Mirror;
                }
            }

            NativeDeviceChild = new SharpDX.Direct3D11.SamplerState(NativeDevice, nativeDescription);
        }
        /// <summary>
        /// Creates device-based resources to store a constant buffer, cube
        /// geometry, and vertex and pixel shaders. In some cases this will also
        /// store a geometry shader.
        /// </summary>
        public async void CreateDeviceDependentResourcesAsync()
        {
            ReleaseDeviceDependentResources();

            usingVprtShaders = deviceResources.D3DDeviceSupportsVprt;

            var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;

            // On devices that do support the D3D11_FEATURE_D3D11_OPTIONS3::
            // VPAndRTArrayIndexFromAnyShaderFeedingRasterizer optional feature
            // we can avoid using a pass-through geometry shader to set the render
            // target array index, thus avoiding any overhead that would be
            // incurred by setting the geometry shader stage.
            var vertexShaderFileName = usingVprtShaders ? "Content\\Shaders\\VPRTVertexShader.cso" : "Content\\Shaders\\VertexShader.cso";

            // Load the compiled vertex shader.
            var vertexShaderByteCode = await DirectXHelper.ReadDataAsync(await folder.GetFileAsync(vertexShaderFileName));

            // After the vertex shader file is loaded, create the shader and input layout.
            vertexShader = this.ToDispose(new SharpDX.Direct3D11.VertexShader(
                                              deviceResources.D3DDevice,
                                              vertexShaderByteCode));

            //TODO: Change VertexDesc to use new structure: VertexPositionTextureCoordinates
            SharpDX.Direct3D11.InputElement[] vertexDesc =
            {
                new SharpDX.Direct3D11.InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32_Float,  0, 0, SharpDX.Direct3D11.InputClassification.PerVertexData, 0),
                new SharpDX.Direct3D11.InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32B32_Float, 12, 0, SharpDX.Direct3D11.InputClassification.PerVertexData, 0),
            };


            inputLayout = this.ToDispose(new SharpDX.Direct3D11.InputLayout(
                                             deviceResources.D3DDevice,
                                             vertexShaderByteCode,
                                             vertexDesc));

            if (!usingVprtShaders)
            {
                // Load the compiled pass-through geometry shader.
                var geometryShaderByteCode = await DirectXHelper.ReadDataAsync(await folder.GetFileAsync("Content\\Shaders\\GeometryShader.cso"));

                // After the pass-through geometry shader file is loaded, create the shader.
                geometryShader = this.ToDispose(new SharpDX.Direct3D11.GeometryShader(
                                                    deviceResources.D3DDevice,
                                                    geometryShaderByteCode));
            }

            // Load the compiled pixel shader.
            var pixelShaderByteCode = await DirectXHelper.ReadDataAsync(await folder.GetFileAsync("Content\\Shaders\\PixelShader.cso"));

            // After the pixel shader file is loaded, create the shader.
            pixelShader = this.ToDispose(new SharpDX.Direct3D11.PixelShader(
                                             deviceResources.D3DDevice,
                                             pixelShaderByteCode));

            //TODO: Use a photo editing app to create a texture, like GIMP2 with DDS Plugin, make sure photo width & height divisible by 4, for a cube must be an exact square
            //used Gimp 2 with DDS Plugin to create a 2000x2000 image and export at .dds file.
            //in the export options I used BC3_UNorm format, along with automatic MIP levels
            string textureName2 = "Content\\Textures\\nuwaupian_holding_fire3.dds";

            //TODO: Create the SamplerState
            var samplerStateDescription = new SharpDX.Direct3D11.SamplerStateDescription();

            samplerStateDescription.Filter      = SharpDX.Direct3D11.Filter.MinMagMipLinear;
            samplerStateDescription.AddressU    = SharpDX.Direct3D11.TextureAddressMode.Wrap;
            samplerStateDescription.AddressV    = SharpDX.Direct3D11.TextureAddressMode.Wrap;
            samplerStateDescription.AddressW    = SharpDX.Direct3D11.TextureAddressMode.Wrap;
            samplerStateDescription.BorderColor = new SharpDX.Mathematics.Interop.RawColor4(0f, 0f, 0f, 1f);

            samplerState = new SharpDX.Direct3D11.SamplerState(deviceResources.D3DDevice, samplerStateDescription);

            //TODO: Use the TextureLoader class to create a bitmap source from a .DDS texture file
            //Retreived TextureLoader from DirectXTK or DirectText Tool
            var bitmapSource2 = TextureLoader.LoadBitmap(new SharpDX.WIC.ImagingFactory2(), textureName2);

            //TODO: Create a Texture Description to describe the texture you'll be using or converting to
            var textDesc = new SharpDX.Direct3D11.Texture2DDescription()
            {
                Width             = bitmapSource2.Size.Width,
                Height            = bitmapSource2.Size.Height,
                ArraySize         = 6,
                BindFlags         = SharpDX.Direct3D11.BindFlags.ShaderResource,
                Usage             = SharpDX.Direct3D11.ResourceUsage.Default,
                CpuAccessFlags    = SharpDX.Direct3D11.CpuAccessFlags.None,
                Format            = SharpDX.DXGI.Format.R8G8B8A8_UNorm,
                MipLevels         = 1,
                OptionFlags       = SharpDX.Direct3D11.ResourceOptionFlags.TextureCube,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
            };

            //TODO: Create Shader Resource View
            var shaderResourceDesc = new SharpDX.Direct3D11.ShaderResourceViewDescription()
            {
                Format      = textDesc.Format,
                Dimension   = SharpDX.Direct3D.ShaderResourceViewDimension.TextureCube,
                TextureCube = new SharpDX.Direct3D11.ShaderResourceViewDescription.TextureCubeResource()
                {
                    MipLevels = textDesc.MipLevels, MostDetailedMip = 0
                }
            };

            //TODO: Create 6 pointers for the 6 sides of the cube, each pointing to an 2000x2000 image you want to display
            IntPtr[] ptrImages = new IntPtr[6];

            //TODO: Get the Stride of each image - stride is the size of 1 row pixels
            int stride = bitmapSource2.Size.Width * 4;

            //TODO: for each of the 6 pointers, create a buffer to hold the pixels using the DataStream object,
            using (var buffer = new SharpDX.DataStream(bitmapSource2.Size.Height * stride, true, true))
            {
                //TODO: for each of the 6 data streams, copy the pixels into a buffer
                // Copy the content of the WIC to the buffer
                bitmapSource2.CopyPixels(stride, buffer);

                //TODO: for each of the 6 pointers get the IntPtr to the buffers, taking care not get rid of the buffers, pointers, or datastreams before we can create the texture cube
                ptrImages[0] = buffer.DataPointer;


                using (var buffer1 = new SharpDX.DataStream(bitmapSource2.Size.Height * stride, true, true))
                {
                    // Copy the content of the WIC to the buffer
                    bitmapSource2.CopyPixels(stride, buffer1);
                    ptrImages[1] = buffer1.DataPointer;


                    using (var buffer2 = new SharpDX.DataStream(bitmapSource2.Size.Height * stride, true, true))
                    {
                        // Copy the content of the WIC to the buffer
                        bitmapSource2.CopyPixels(stride, buffer2);
                        ptrImages[2] = buffer2.DataPointer;

                        using (var buffer3 = new SharpDX.DataStream(bitmapSource2.Size.Height * stride, true, true))
                        {
                            // Copy the content of the WIC to the buffer
                            bitmapSource2.CopyPixels(stride, buffer3);
                            ptrImages[3] = buffer3.DataPointer;

                            using (var buffer4 = new SharpDX.DataStream(bitmapSource2.Size.Height * stride, true, true))
                            {
                                // Copy the content of the WIC to the buffer
                                bitmapSource2.CopyPixels(stride, buffer4);
                                ptrImages[4] = buffer4.DataPointer;

                                using (var buffer5 = new SharpDX.DataStream(bitmapSource2.Size.Height * stride, true, true))
                                {
                                    // Copy the content of the WIC to the buffer
                                    bitmapSource2.CopyPixels(stride, buffer5);
                                    ptrImages[5] = buffer5.DataPointer;


                                    //TODO: create a DataBox of the 6 pixel buffers. The DataBox is the typed array which we described in the TextureDescription and ShaderResource Description to hold the 6 sides
                                    var dataRects = new SharpDX.DataBox[] { new SharpDX.DataBox(ptrImages[0], stride, 0),
                                                                            new SharpDX.DataBox(ptrImages[1], stride, 0),
                                                                            new SharpDX.DataBox(ptrImages[2], stride, 0),
                                                                            new SharpDX.DataBox(ptrImages[3], stride, 0),
                                                                            new SharpDX.DataBox(ptrImages[4], stride, 0),
                                                                            new SharpDX.DataBox(ptrImages[5], stride, 0) };

                                    //TODO: Now create the TextureCube
                                    var texture2D = new SharpDX.Direct3D11.Texture2D(deviceResources.D3DDevice, textDesc, dataRects);

                                    //TODO: Now create the TextureShaderResourceView - which will be used in the PixelShader, after this point we can release all the buffers
                                    textureResource = new SharpDX.Direct3D11.ShaderResourceView(deviceResources.D3DDevice, texture2D, shaderResourceDesc);
                                }
                            }
                        }
                    }
                }
            }

            //TODO: Change to VertexPositionCoordinate
            // Load mesh vertices. Each vertex has a position and a color.
            // Note that the cube size has changed from the default DirectX app
            // template. Windows Holographic is scaled in meters, so to draw the
            // cube at a comfortable size we made the cube width 0.2 m (20 cm).
            VertexPositionCoordinate[] cubeVertices =
            {
                new VertexPositionCoordinate(new Vector3(-0.1f, -0.1f, -0.1f), new Vector3(0.0f, 0.0f, 0.0f)),
                new VertexPositionCoordinate(new Vector3(-0.1f, -0.1f,  0.1f), new Vector3(0.0f, 0.0f, 1.0f)),
                new VertexPositionCoordinate(new Vector3(-0.1f,  0.1f, -0.1f), new Vector3(0.0f, 1.0f, 0.0f)),
                new VertexPositionCoordinate(new Vector3(-0.1f,  0.1f,  0.1f), new Vector3(0.0f, 1.0f, 1.0f)),
                new VertexPositionCoordinate(new Vector3(0.1f,  -0.1f, -0.1f), new Vector3(1.0f, 0.0f, 0.0f)),
                new VertexPositionCoordinate(new Vector3(0.1f,  -0.1f,  0.1f), new Vector3(1.0f, 0.0f, 1.0f)),
                new VertexPositionCoordinate(new Vector3(0.1f,   0.1f, -0.1f), new Vector3(1.0f, 1.0f, 0.0f)),
                new VertexPositionCoordinate(new Vector3(0.1f,   0.1f,  0.1f), new Vector3(1.0f, 1.0f, 1.0f)),
            };

            vertexBuffer = this.ToDispose(SharpDX.Direct3D11.Buffer.Create(
                                              deviceResources.D3DDevice,
                                              SharpDX.Direct3D11.BindFlags.VertexBuffer,
                                              cubeVertices));

            // Load mesh indices. Each trio of indices represents
            // a triangle to be rendered on the screen.
            // For example: 0,2,1 means that the vertices with indexes
            // 0, 2 and 1 from the vertex buffer compose the
            // first triangle of this mesh.
            ushort[] cubeIndices =
            {
                2, 1, 0, // -x
                2, 3, 1,

                6, 4, 5, // +x
                6, 5, 7,

                0, 1, 5, // -y
                0, 5, 4,

                2, 6, 7, // +y
                2, 7, 3,

                0, 4, 6, // -z
                0, 6, 2,

                1, 3, 7, // +z
                1, 7, 5,
            };

            indexCount = cubeIndices.Length;

            indexBuffer = this.ToDispose(SharpDX.Direct3D11.Buffer.Create(
                                             deviceResources.D3DDevice,
                                             SharpDX.Direct3D11.BindFlags.IndexBuffer,
                                             cubeIndices));

            // Create a constant buffer to store the model matrix.
            modelConstantBuffer = this.ToDispose(SharpDX.Direct3D11.Buffer.Create(
                                                     deviceResources.D3DDevice,
                                                     SharpDX.Direct3D11.BindFlags.ConstantBuffer,
                                                     ref modelConstantBufferData));

            // Once the cube is loaded, the object is ready to be rendered.
            loadingComplete = true;
        }
        internal void SetSamplers(GraphicsDevice device)
        {
#if DIRECTX
            // Skip out if nothing has changed.
            if (_d3dDirty == 0)
            {
                return;
            }

            // NOTE: We make the assumption here that the caller has
            // locked the d3dContext for us to use.
            var pixelShaderStage = device._d3dContext.PixelShader;

            for (var i = 0; i < _samplers.Length; i++)
            {
                var mask = 1 << i;
                if ((_d3dDirty & mask) == 0)
                {
                    continue;
                }

                var sampler = _samplers[i];
                SharpDX.Direct3D11.SamplerState state = null;
                if (sampler != null)
                {
                    state = sampler.GetState(device);
                }

                pixelShaderStage.SetSampler(i, state);

                _d3dDirty &= ~mask;
                if (_d3dDirty == 0)
                {
                    break;
                }
            }

            _d3dDirty = 0;
#elif OPENGL
            for (var i = 0; i < _samplers.Length; i++)
            {
                var sampler = _samplers[i];
                var texture = device.Textures[i];

                if (sampler != null && texture != null && sampler != texture.glLastSamplerState)
                {
                    // TODO: Avoid doing this redundantly (see TextureCollection.SetTextures())
                    // However, I suspect that rendering from the same texture with different sampling modes
                    // is a relatively rare occurrence...
                    GL.ActiveTexture(TextureUnit.Texture0 + i);
                    GraphicsExtensions.CheckGLError();

                    // NOTE: We don't have to bind the texture here because it is already bound in
                    // TextureCollection.SetTextures(). This, of course, assumes that SetTextures() is called
                    // before this method is called. If that ever changes this code will misbehave.
                    // GL.BindTexture(texture.glTarget, texture.glTexture);
                    // GraphicsExtensions.CheckGLError();

                    sampler.Activate(texture.glTarget, texture.LevelCount > 1);
                    texture.glLastSamplerState = sampler;
                }
            }
#endif
        }