Beispiel #1
0
        protected override void Dispose(bool disposing)
        {
            if (!IsDisposed)
            {
#if DIRECTX
                if (disposing)
                {
                    if (_resourceView != null)
                    {
                        _resourceView.Dispose();
                        _resourceView = null;
                    }

                    if (_texture != null)
                    {
                        _texture.Dispose();
                        _texture = null;
                    }
                }
#elif OPENGL
                GraphicsDevice.AddDisposeAction(() =>
                {
                    GL.DeleteTextures(1, ref glTexture);
                    GraphicsExtensions.CheckGLError();
                    glTexture = -1;
                });

                glLastSamplerState = null;
#endif
            }
            base.Dispose(disposing);
        }
        public void Render()
        {
            if (!loadingFinished || !physicalCamera.Ready)
            {
                return;
            }

            var device        = deviceResources.D3DDevice;
            var context       = deviceResources.D3DDeviceContext;
            int stride        = SharpDX.Utilities.SizeOf <VertexPositionUV>();
            int offset        = 0;
            var bufferBinding = new SharpDX.Direct3D11.VertexBufferBinding(vertexBuffer, stride, offset);

            context.InputAssembler.SetVertexBuffers(0, bufferBinding);
            context.InputAssembler.SetIndexBuffer(indexBuffer, SharpDX.DXGI.Format.R16_UInt, 0);
            context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
            context.InputAssembler.InputLayout       = inputLayout;

            context.VertexShader.SetShader(vertexShader, null, 0);
            context.VertexShader.SetConstantBuffers(0, modelConstantBuffer);
            context.PixelShader.SetShader(pixelShader, null, 0);
            var cameraTexture = physicalCamera.AcquireTexture();

            if (cameraTexture == null)
            {
                return;
            }
            var luminanceView = new SharpDX.Direct3D11.ShaderResourceView(device, cameraTexture, new SharpDX.Direct3D11.ShaderResourceViewDescription()
            {
                Format    = SharpDX.DXGI.Format.R8_UInt,
                Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D,
                Texture2D = new SharpDX.Direct3D11.ShaderResourceViewDescription.Texture2DResource()
                {
                    MipLevels = 1
                }
            });
            var chrominanceView = new SharpDX.Direct3D11.ShaderResourceView(device, cameraTexture, new SharpDX.Direct3D11.ShaderResourceViewDescription()
            {
                Format    = SharpDX.DXGI.Format.R8G8_UInt,
                Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D,
                Texture2D = new SharpDX.Direct3D11.ShaderResourceViewDescription.Texture2DResource()
                {
                    MipLevels = 1
                }
            });

            context.PixelShader.SetShaderResource(0, luminanceView);
            context.PixelShader.SetShaderResource(1, chrominanceView);

            context.DrawIndexedInstanced(6, 2, 0, 0, 0);

            luminanceView.Dispose();
            chrominanceView.Dispose();
            physicalCamera.ReleaseTexture();
        }
Beispiel #3
0
        public override void Dispose()
        {
#if DIRECTX
            if (_resourceView != null)
            {
                _resourceView.Dispose();
                _resourceView = null;
            }

            if (_texture != null)
            {
                _texture.Dispose();
                _texture = null;
            }
#elif OPENGL
            GL.DeleteTextures(1, ref glTexture);
            GraphicsExtensions.CheckGLError();
#endif
            base.Dispose();
        }
Beispiel #4
0
 public void Dispose()
 {
     texture.Dispose();
     textureView.Dispose();
 }