示例#1
0
        private async Task CreateDeviceDenpendantResources()
        {
            ReleaseDeviceDependentResources();

            var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
            var vertexShaderFilename = @"Content\Shaders\Mesh Testing\VprtVertexShader.cso";
            var vertexShaderFile     = await folder.GetFileAsync(vertexShaderFilename);

            var vertexShaderBytecode = await DirectXHelper.ReadDataAsync(vertexShaderFile);

            var device = DeviceResources.D3DDevice;

            VertexShader = ToDispose(new VertexShader(device, vertexShaderBytecode));

            var pixelShaderBytecode = await DirectXHelper.ReadDataAsync(await folder.GetFileAsync(@"Content\Shaders\Mesh Testing\PixelShader.cso"));

            PixelShader = ToDispose(new PixelShader(device, pixelShaderBytecode));

            var cubeVertexShaderBytecode = await DirectXHelper.ReadDataAsync(await folder.GetFileAsync(@"Content\Shaders\Cube Rendering\VprtVertexShader.cso"));

            CubeVertexShader = ToDispose(new VertexShader(device, cubeVertexShaderBytecode));
            var cubePixelShaderBytecode = await DirectXHelper.ReadDataAsync(await folder.GetFileAsync(@"Content\Shaders\Cube Rendering\PixelShader.cso"));

            CubePixelShader = ToDispose(new PixelShader(device, cubePixelShaderBytecode));

            CameraConstantBuffer          = ToDispose(SharpDX.Direct3D11.Buffer.Create(device, BindFlags.ConstantBuffer, ref CameraData));
            CameraDirectionConstantBuffer = ToDispose(SharpDX.Direct3D11.Buffer.Create(device, BindFlags.ConstantBuffer, ref CameraDirectionData));

            Meshes  = new MeshCollection(DeviceResources, cubeVertexShaderBytecode);
            CubeMap = new RenderableCubemap(DeviceResources, Vector3.Zero);
            CubeMap.Initialize();
        }
        public async void CreateDeviceDependentResourcesAsync()
        {
            var device = Resources.D3DDevice;
            var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;

            VertexShader = ToDispose(await DirectXHelper.LoadShader <VertexShader>(device, folder, @"Content\Shaders\Texture Debug\VertexShader.cso"));

            InputElement[] vertexDescription =
            {
                new InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32_Float,  0, 0, InputClassification.PerVertexData, 0),
                new InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32_Float,    12, 0, InputClassification.PerVertexData, 0)
            };

            var vertexShaderBytecode = await DirectXHelper.ReadDataAsync(await folder.GetFileAsync(@"Content\Shaders\Texture Debug\VertexShader.cso"));

            InputLayout = ToDispose(new InputLayout(device, vertexShaderBytecode, vertexDescription));

            PixelShader = ToDispose(await DirectXHelper.LoadShader <PixelShader>(device, folder, @"Content\Shaders\Texture Debug\PixelShader.cso"));

            VertexPositionUV[] vertices =
            {
                new VertexPositionUV(new Vector3(0.0f, 0.0f, 0.0f), new Vector2(0.0f, 0.0f)),
                new VertexPositionUV(new Vector3(1.0f, 0.0f, 0.0f), new Vector2(1.0f, 0.0f)),
                new VertexPositionUV(new Vector3(1.0f, 1.0f, 0.0f), new Vector2(1.0f, 1.0f)),
                new VertexPositionUV(new Vector3(0.0f, 1.0f, 0.0f), new Vector2(0.0f, 1.0f))
            };
            VertexBuffer = ToDispose(SharpDX.Direct3D11.Buffer.Create(device, BindFlags.VertexBuffer, vertices));

            ushort[] indices = { 0, 1, 2, 2, 3, 0 };
            IndexBuffer = ToDispose(SharpDX.Direct3D11.Buffer.Create(device, BindFlags.IndexBuffer, indices));

            ScreenPositionBuffer = ToDispose(SharpDX.Direct3D11.Buffer.Create(device, BindFlags.ConstantBuffer, ref ScreenPositionData));
        }
        private async Task <MemoryStream> GetImageAsync(string id)
        {
            var          fileName = FileName(Settings.CaseID + id);
            IStorageItem file     = null;

            if (Settings.SaveTexture)
            {
                file = await localCacheFolder.TryGetItemAsync(fileName);
            }

            if (file == null)
            {
                string urlID = Url(id.Replace(";", "/"));
                //System.Diagnostics.Debug.WriteLine(urlID);
                var request = (HttpWebRequest)WebRequest.Create(urlID);

                try
                {
                    using (var response = (HttpWebResponse)await request.GetResponseAsync())
                    {
                        if (response.StatusCode == HttpStatusCode.OK)
                        {
                            Settings.Online = true;

                            using (var stream = response.GetResponseStream())
                            {
                                var memoryStream = new MemoryStream((int)response.ContentLength);
                                await stream.CopyToAsync(memoryStream);

                                if (Settings.SaveTexture)
                                {
                                    await SaveTextureAsync(fileName, memoryStream);
                                }

                                memoryStream.Position = 0;
                                return(memoryStream);
                            }
                        }
                        else
                        {
                            Settings.Online = false;
                            return(null);
                        }
                    }
                }
                catch (Exception)
                {
                    return(null);
                }
            }
            else
            {
                var bytes = await DirectXHelper.ReadDataAsync((StorageFile)file);

                var memoryStream = new MemoryStream(bytes);
                return(memoryStream);
            }
        }
        private async Task BuildPixelShader()
        {
            var folder = Package.Current.InstalledLocation;
            var pixelShaderByteCode =
                await DirectXHelper.ReadDataAsync(await folder.GetFileAsync("Content\\Shaders\\PixelShader.cso"));

            _pixelShader = ToDispose(new PixelShader(
                                         _deviceResources.D3DDevice,
                                         pixelShaderByteCode));
        }
示例#5
0
        private async void LoadShaders()
        {
            usingVprtShaders = deviceResources.D3DDeviceSupportsVprt;
            // 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";
            var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
            // 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));

            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", 1, SharpDX.DXGI.Format.R32G32_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));

            ComputeSphere(16, true);
            // Once the cube is loaded, the object is ready to be rendered.
            loadingComplete = true;
        }
示例#6
0
        /// <summary>
        /// Creates device-based resources to store a constant buffer, object
        /// geometry, and vertex and pixel shaders. In some cases this will also
        /// store a geometry shader.
        /// </summary>
        internal virtual async Task CreateDeviceDependentResourcesAsync()
        {
            ReleaseDeviceDependentResources();

            usingVprtShaders = deviceResources.D3DDeviceSupportsVprt;

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

            var vertexShaderFileName = usingVprtShaders ? VPRT_VERTEX_SHADER : VERTEX_SHADER;
            var vertexShaderByteCode = await DirectXHelper.ReadDataAsync(
                await folder.GetFileAsync(vertexShaderFileName));

            vertexShader = ToDispose(new VertexShader(
                                         deviceResources.D3DDevice,
                                         vertexShaderByteCode));

            var vertexDesc = InputElement;

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

            if (!usingVprtShaders)
            {
                var geometryShaderByteCode = await DirectXHelper.ReadDataAsync(
                    await folder.GetFileAsync(GEOMETRY_SHADER));

                geometryShader = ToDispose(new GeometryShader(
                                               deviceResources.D3DDevice,
                                               geometryShaderByteCode));
            }

            var pixelShaderByteCode = await DirectXHelper.ReadDataAsync(
                await folder.GetFileAsync(PIXEL_SHADER));

            pixelShader = ToDispose(new PixelShader(
                                        deviceResources.D3DDevice,
                                        pixelShaderByteCode));

            samplerState = ToDispose(new SamplerState(
                                         deviceResources.D3DDevice,
                                         TextureLoader.SamplerStateDescription()));

            await LoadTextureAsync();

            LoadGeometry();

            refreshNeeded   = true;
            loadingComplete = true;
        }
        private async Task <byte[]> BuildVertexShader()
        {
            var folder = Package.Current.InstalledLocation;

            var vertexShaderFileName = _usingVprtShaders
                ? "Content\\Shaders\\VPRTVertexShader.cso"
                : "Content\\Shaders\\VertexShader.cso";

            var vertexShaderByteCode =
                await DirectXHelper.ReadDataAsync(await folder.GetFileAsync(vertexShaderFileName));

            _vertexShader = ToDispose(new VertexShader(_deviceResources.D3DDevice, vertexShaderByteCode));
            return(vertexShaderByteCode);
        }
示例#8
0
        public async void CreateDeviceDependentResources()
        {
            var device = Resources.D3DDevice;
            var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;

            Meshes = new MeshCollection(Resources, await DirectXHelper.ReadDataAsync(await folder.GetFileAsync(@"Content\Shaders\Mesh Updating\VertexShader.cso")));
            Meshes.OnMeshChanged += RequestPackingUpdate;

            await MeshRenderer.CreateDeviceDependantResources();

            await ModelLoader.LoadObj(Resources, @"Content\Assets\cube rounded.obj");

            await InitializeSurfaceObservation();

            Active = true;
        }
        public async void CreateDeviceDependentResourcesAsync()
        {
            ReleaseDeviceDependentResources();

            _usingVprtShaders = _deviceResources.D3DDeviceSupportsVprt;

            var folder = Package.Current.InstalledLocation;

            var vertexShaderFileName = _usingVprtShaders
                ? "Content\\Shaders\\VPRTVertexShader.cso"
                : "Content\\Shaders\\VertexShader.cso";

            var vertexShaderByteCode =
                await DirectXHelper.ReadDataAsync(await folder.GetFileAsync(vertexShaderFileName));

            _vertexShader = ToDispose(new VertexShader(
                                          _deviceResources.D3DDevice,
                                          vertexShaderByteCode));

            var vertexDesc = new InputElement[]            {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
                new InputElement("COLOR", 0, Format.R32G32B32_Float, 12, 0, InputClassification.PerVertexData, 0)
            };

            _inputLayout = ToDispose(new InputLayout(
                                         _deviceResources.D3DDevice,
                                         vertexShaderByteCode,
                                         vertexDesc));

            if (!_usingVprtShaders)
            {
                var geometryShaderByteCode =
                    await DirectXHelper.ReadDataAsync(await folder.GetFileAsync("Content\\Shaders\\GeometryShader.cso"));

                _geometryShader = ToDispose(new GeometryShader(_deviceResources.D3DDevice, geometryShaderByteCode));
            }

            var pixelShaderByteCode =
                await DirectXHelper.ReadDataAsync(await folder.GetFileAsync("Content\\Shaders\\PixelShader.cso"));

            _pixelShader = ToDispose(new PixelShader(
                                         _deviceResources.D3DDevice,
                                         pixelShaderByteCode));

            BuildSpatialSurfaceObserver();
        }
        public async void CreateDeviceDependentResourcesAsync()
        {
            ReleaseDeviceDependentResources();

            var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
            var vertexShaderFilename = @"Content\Shaders\Camera Testing\VprtVertexShader.cso";
            var vertexShaderBytecode = await DirectXHelper.ReadDataAsync(await folder.GetFileAsync(vertexShaderFilename));

            vertexShader = ToDispose(new SharpDX.Direct3D11.VertexShader(deviceResources.D3DDevice, vertexShaderBytecode));

            SharpDX.Direct3D11.InputElement[] vertexDescription =
            {
                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.R32G32_Float,    12, 0, SharpDX.Direct3D11.InputClassification.PerVertexData, 0)
            };

            inputLayout = ToDispose(new SharpDX.Direct3D11.InputLayout(deviceResources.D3DDevice, vertexShaderBytecode, vertexDescription));

            var pixelShaderBytecode = await DirectXHelper.ReadDataAsync(await folder.GetFileAsync(@"Content\Shaders\Camera Testing\PixelShader.cso"));

            pixelShader = ToDispose(new SharpDX.Direct3D11.PixelShader(deviceResources.D3DDevice, pixelShaderBytecode));

            VertexPositionUV[] vertices =
            {
                new VertexPositionUV(new Vector3(-0.2f, -0.2f, 0.0f), new Vector2(0.0f, 0.0f)),
                new VertexPositionUV(new Vector3(0.2f,  -0.2f, 0.0f), new Vector2(1.0f, 0.0f)),
                new VertexPositionUV(new Vector3(0.2f,   0.2f, 0.0f), new Vector2(1.0f, 1.0f)),
                new VertexPositionUV(new Vector3(-0.2f,  0.2f, 0.0f), new Vector2(0.0f, 1.0f))
            };
            vertexBuffer = ToDispose(SharpDX.Direct3D11.Buffer.Create(deviceResources.D3DDevice, SharpDX.Direct3D11.BindFlags.VertexBuffer, vertices));

            ushort[] indices = { 0, 1, 2, 2, 3, 0 };
            indexBuffer = ToDispose(SharpDX.Direct3D11.Buffer.Create(deviceResources.D3DDevice, SharpDX.Direct3D11.BindFlags.IndexBuffer, indices));

            modelConstantBuffer = ToDispose(SharpDX.Direct3D11.Buffer.Create(deviceResources.D3DDevice, SharpDX.Direct3D11.BindFlags.ConstantBuffer, ref modelConstantBufferData));

            loadingFinished = true;
        }
示例#11
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 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));

            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("COLOR",    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));

            // 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).
            VertexPositionColor[] cubeVertices =
            {
                new VertexPositionColor(new Vector3(-0.1f, -0.1f, -0.1f), new Vector3(0.0f, 0.0f, 0.0f)),
                new VertexPositionColor(new Vector3(-0.1f, -0.1f,  0.1f), new Vector3(0.0f, 0.0f, 1.0f)),
                new VertexPositionColor(new Vector3(-0.1f,  0.1f, -0.1f), new Vector3(0.0f, 1.0f, 0.0f)),
                new VertexPositionColor(new Vector3(-0.1f,  0.1f,  0.1f), new Vector3(0.0f, 1.0f, 1.0f)),
                new VertexPositionColor(new Vector3(0.1f,  -0.1f, -0.1f), new Vector3(1.0f, 0.0f, 0.0f)),
                new VertexPositionColor(new Vector3(0.1f,  -0.1f,  0.1f), new Vector3(1.0f, 0.0f, 1.0f)),
                new VertexPositionColor(new Vector3(0.1f,   0.1f, -0.1f), new Vector3(1.0f, 1.0f, 0.0f)),
                new VertexPositionColor(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;
        }
        /// <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;
        }
示例#13
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 virtual 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));

            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("NORMAL",   0, SharpDX.DXGI.Format.R32G32B32_Float, 12, 0, SharpDX.Direct3D11.InputClassification.PerVertexData, 0),
                new SharpDX.Direct3D11.InputElement("COLOR",    0, SharpDX.DXGI.Format.R32G32B32_Float, 24, 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));

            GeometricPrimitives.GeometricData geometricData = GetGeometricData();

            VertexPositionNormalColor[] vertices = new VertexPositionNormalColor[geometricData.VertexCount];
            for (var i = 0; i < geometricData.VertexCount; i++)
            {
                vertices[i] = new VertexPositionNormalColor(geometricData.vertices[i], geometricData.normals[i], geometricData.colors[i]);
            }
            int[] indices = geometricData.indices;

            indexCount = indices.Length;

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

            // 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.

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

            // 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;
        }
示例#14
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 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));

            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.R32G32_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\\TexturePixelShader.cso"));

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

            // Load mesh vertices. Each vertex has a position, a texture-coord and a colour.
            VertexPositionTextureColor[] quadVertices =
            {
                new VertexPositionTextureColor(new Vector3(-(QUAD_SIZE / 2.0f), -(QUAD_SIZE / 2.0f), 0f), new Vector2(0, 1), Vector3.Zero),
                new VertexPositionTextureColor(new Vector3(-(QUAD_SIZE / 2.0f), (QUAD_SIZE / 2.0f),  0f), new Vector2(0, 0), Vector3.Zero),
                new VertexPositionTextureColor(new Vector3((QUAD_SIZE / 2.0f),  (QUAD_SIZE / 2.0f),  0f), new Vector2(1, 0), Vector3.Zero),
                new VertexPositionTextureColor(new Vector3((QUAD_SIZE / 2.0f),  -(QUAD_SIZE / 2.0f), 0f), new Vector2(1, 1), Vector3.Zero)
            };

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

            // 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 =
            {
                0, 1, 2,
                0, 2, 3
            };

            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));

            this.samplerState = this.ToDispose(
                new SamplerState(
                    this.deviceResources.D3DDevice,
                    new SamplerStateDescription()
            {
                AddressU           = TextureAddressMode.Clamp,
                AddressV           = TextureAddressMode.Clamp,
                AddressW           = TextureAddressMode.Clamp,
                ComparisonFunction = Comparison.Never,
                MaximumAnisotropy  = 16,
                MipLodBias         = 0,
                MinimumLod         = -float.MaxValue,
                MaximumLod         = float.MaxValue
            }
                    )
                );

            Texture2DDescription desc = new Texture2DDescription()
            {
                Width             = TEXTURE_SIZE,
                Height            = TEXTURE_SIZE,
                ArraySize         = 1,
                MipLevels         = 1,
                Usage             = ResourceUsage.Default,
                Format            = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                CpuAccessFlags    = CpuAccessFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                BindFlags         = BindFlags.RenderTarget | BindFlags.ShaderResource
            };

            this.texture2D = this.ToDispose(new Texture2D(this.deviceResources.D3DDevice, desc));

            this.shaderResourceView = this.ToDispose(new ShaderResourceView(
                                                         this.deviceResources.D3DDevice, texture2D));

            this.renderTargetView = this.ToDispose(new RenderTargetView(
                                                       this.deviceResources.D3DDevice, texture2D));

            using (var surface = texture2D.QueryInterface <Surface>())
            {
                this.renderTarget = this.ToDispose(
                    new RenderTarget(
                        this.deviceResources.D2DFactory,
                        surface,
                        new RenderTargetProperties()
                {
                    DpiX        = 96,
                    DpiY        = 96,
                    Type        = RenderTargetType.Default,
                    Usage       = RenderTargetUsage.None,
                    MinLevel    = FeatureLevel.Level_DEFAULT,
                    PixelFormat = new PixelFormat(Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied)
                }
                        )
                    );
            }
            this.redBrush = this.ToDispose(new SolidColorBrush(renderTarget, new RawColor4(255, 0, 0, 255)));

            this.whiteBrush = this.ToDispose(new SolidColorBrush(renderTarget, new RawColor4(255, 255, 255, 255)));

            this.textFormat = this.ToDispose(new TextFormat(this.deviceResources.DWriteFactory, "Consolas", 24));

            this.ellipse = new Ellipse(new RawVector2(TEXTURE_SIZE / 2, TEXTURE_SIZE / 2), TEXTURE_SIZE / 4, TEXTURE_SIZE / 4);

            this.fillRectangle = new RawRectangleF(0, 0, TEXTURE_SIZE, TEXTURE_SIZE);
            this.textRectangle = new RawRectangleF(24, 24, 240, 60); // magic numbers, hard-coded to fit.

            // Once the cube is loaded, the object is ready to be rendered.
            loadingComplete = true;
        }
示例#15
0
        public async void CreateDeviceDependentResourcesAsync()
        {
            IsLoaded = false;

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

            usingVprtShaders = deviceResources.D3DDeviceSupportsVprt;

            string vertexShaderFileName = usingVprtShaders ? "Content\\Shaders\\QuadVPRTVertexShader.cso" : "Content\\Shaders\\QuadVertexShader.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 VertexShader(deviceResources.D3DDevice, vertexShaderByteCode));

            InputElement[] vertexDesc =
            {
                new InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32_Float,  0, 0, InputClassification.PerVertexData, 0),
                new InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32_Float,    12, 0, InputClassification.PerVertexData, 0),
            };

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

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

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

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

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

            // Load mesh vertices. Each vertex has a position and a color.
            // Note that the quad size has changed from the default DirectX app
            // template. Windows Holographic is scaled in meters, so to draw the
            // quad at a comfortable size we made the quad width 0.2 m (20 cm).
            VertexPositionTex[] quadVertices = new[]
            {
                new VertexPositionTex(new Vector3(-0.5f, 0.5f, 0f), new Vector2(0f, 0f)),
                new VertexPositionTex(new Vector3(0.5f, 0.5f, 0f), new Vector2(1f, 0f)),
                new VertexPositionTex(new Vector3(0.5f, -0.5f, 0f), new Vector2(1f, 1f)),
                new VertexPositionTex(new Vector3(-0.5f, -0.5f, 0f), new Vector2(0f, 1f))
            };

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

            // Load mesh indices. Each trio of indices represents
            // a triangle to be rendered on the screen.
            // For example: 2,1,0 means that the vertices with indexes
            // 2, 1, and 0 from the vertex buffer compose the
            // first triangle of this mesh.
            // Note that the winding order is clockwise by default.
            ushort[] quadIndices =
            {
                // -z
                0, 2, 3,
                0, 1, 2,
                // +z
                2, 0, 3,
                1, 0, 2,
            };

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

            samplerState = ToDispose(new SamplerState(deviceResources.D3DDevice, new SamplerStateDescription()
            {
                AddressU           = TextureAddressMode.Wrap,
                AddressV           = TextureAddressMode.Wrap,
                AddressW           = TextureAddressMode.Wrap,
                BorderColor        = new RawColor4(0, 0, 0, 0),
                ComparisonFunction = Comparison.Never,
                Filter             = Filter.MinMagMipLinear,
                MaximumAnisotropy  = 16,
                MaximumLod         = float.MaxValue,
                MinimumLod         = 0,
                MipLodBias         = 0.0f
            }));

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

            IsLoaded = true;
        }