private void PlatformConstruct(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage) { // Setup the multisampling description. var multisampleDesc = new SharpDX.DXGI.SampleDescription(1, 0); if (preferredMultiSampleCount > 1) { multisampleDesc.Count = preferredMultiSampleCount; multisampleDesc.Quality = (int)StandardMultisampleQualityLevels.StandardMultisamplePattern; } // Create a descriptor for the depth/stencil buffer. // Allocate a 2-D surface as the depth/stencil buffer. // Create a DepthStencil view on this surface to use on bind. using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(graphicsDevice._d3dDevice, new Texture2DDescription { Format = SharpDXHelper.ToFormat(preferredDepthFormat), ArraySize = 1, MipLevels = 1, Width = width, Height = height, SampleDescription = multisampleDesc, BindFlags = BindFlags.DepthStencil, })) { // Create the view for binding to the device. _depthStencilView = new DepthStencilView(graphicsDevice._d3dDevice, depthBuffer, new DepthStencilViewDescription() { Format = SharpDXHelper.ToFormat(preferredDepthFormat), Dimension = DepthStencilViewDimension.Texture2D }); } }
private void PlatformConstruct(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage) { // Setup the multisampling description. var multisampleDesc = new SharpDX.DXGI.SampleDescription(1, 0); if (preferredMultiSampleCount > 1) { multisampleDesc.Count = preferredMultiSampleCount; multisampleDesc.Quality = (int)StandardMultisampleQualityLevels.StandardMultisamplePattern; } // Create a descriptor for the depth/stencil buffer. // Allocate a 2-D surface as the depth/stencil buffer. // Create a DepthStencil view on this surface to use on bind. using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(graphicsDevice._d3dDevice, new Texture2DDescription { Format = SharpDXHelper.ToFormat(preferredDepthFormat), ArraySize = 1, MipLevels = 1, Width = width, Height = height, SampleDescription = multisampleDesc, BindFlags = BindFlags.DepthStencil, })) { // Create the view for binding to the device. _depthStencilView = new DepthStencilView(graphicsDevice._d3dDevice, depthBuffer, new DepthStencilViewDescription() { Format = SharpDXHelper.ToFormat(preferredDepthFormat), Dimension = DepthStencilViewDimension.Texture2D }); } }
private void GenerateIfRequired() { if (_renderTargetView != null) { return; } // Create a view interface on the rendertarget to use on bind. _renderTargetView = new RenderTargetView(GraphicsDevice._d3dDevice, GetTexture()); // If we don't need a depth buffer then we're done. if (DepthStencilFormat == DepthFormat.None) { return; } // Setup the multisampling description. var multisampleDesc = new SharpDX.DXGI.SampleDescription(1, 0); if (MultiSampleCount > 1) { multisampleDesc.Count = MultiSampleCount; multisampleDesc.Quality = (int)StandardMultisampleQualityLevels.StandardMultisamplePattern; } // Create a descriptor for the depth/stencil buffer. // Allocate a 2-D surface as the depth/stencil buffer. // Create a DepthStencil view on this surface to use on bind. using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(GraphicsDevice._d3dDevice, new Texture2DDescription { Format = SharpDXHelper.ToFormat(DepthStencilFormat), ArraySize = 1, MipLevels = 1, Width = width, Height = height, SampleDescription = multisampleDesc, BindFlags = BindFlags.DepthStencil, })) { // Create the view for binding to the device. _depthStencilView = new DepthStencilView(GraphicsDevice._d3dDevice, depthBuffer, new DepthStencilViewDescription() { Format = SharpDXHelper.ToFormat(DepthStencilFormat), Dimension = DepthStencilViewDimension.Texture2D }); } }
static SharpDX.DXGI.SampleDescription DetectSampleDescription(Device device, SharpDX.DXGI.Format format) { var desc = new SharpDX.DXGI.SampleDescription(); for (int multisample_count = Device.MultisampleCountMaximum; multisample_count > 0; --multisample_count) { int quality_levels = device.CheckMultisampleQualityLevels(format, multisample_count); if (quality_levels > 0) { desc.Count = multisample_count; desc.Quality = quality_levels - 1; break; } } Console.WriteLine("sample count {0} quality {1}", desc.Count, desc.Quality); return(desc); }
public RenderTarget3D(GraphicsDevice graphicsDevice, int width, int height, int depth, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage) :base (graphicsDevice, width, height, depth, mipMap, preferredFormat, true) { DepthStencilFormat = preferredDepthFormat; MultiSampleCount = preferredMultiSampleCount; RenderTargetUsage = usage; // If we don't need a depth buffer then we're done. if (preferredDepthFormat == DepthFormat.None) return; #if DIRECTX // Setup the multisampling description. var multisampleDesc = new SharpDX.DXGI.SampleDescription(1, 0); if ( preferredMultiSampleCount > 1 ) { multisampleDesc.Count = preferredMultiSampleCount; multisampleDesc.Quality = (int)StandardMultisampleQualityLevels.StandardMultisamplePattern; } // Create a descriptor for the depth/stencil buffer. // Allocate a 2-D surface as the depth/stencil buffer. // Create a DepthStencil view on this surface to use on bind. using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(graphicsDevice._d3dDevice, new Texture2DDescription { Format = SharpDXHelper.ToFormat(preferredDepthFormat), ArraySize = 1, MipLevels = 1, Width = width, Height = height, SampleDescription = multisampleDesc, BindFlags = BindFlags.DepthStencil, })) { // Create the view for binding to the device. _depthStencilView = new DepthStencilView(graphicsDevice._d3dDevice, depthBuffer, new DepthStencilViewDescription() { Format = SharpDXHelper.ToFormat(preferredDepthFormat), Dimension = DepthStencilViewDimension.Texture2D }); } #endif // DIRECTX }
public RenderTarget3D(GraphicsDevice graphicsDevice, int width, int height, int depth, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage) : base(graphicsDevice, width, height, depth, mipMap, preferredFormat, true) { DepthStencilFormat = preferredDepthFormat; MultiSampleCount = preferredMultiSampleCount; RenderTargetUsage = usage; // If we don't need a depth buffer then we're done. if (preferredDepthFormat == DepthFormat.None) { return; } #if DIRECTX // Setup the multisampling description. var multisampleDesc = new SharpDX.DXGI.SampleDescription(1, 0); if (preferredMultiSampleCount > 1) { multisampleDesc.Count = preferredMultiSampleCount; multisampleDesc.Quality = (int)StandardMultisampleQualityLevels.StandardMultisamplePattern; } // Create a descriptor for the depth/stencil buffer. // Allocate a 2-D surface as the depth/stencil buffer. // Create a DepthStencil view on this surface to use on bind. using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(graphicsDevice._d3dDevice, new Texture2DDescription { Format = SharpDXHelper.ToFormat(preferredDepthFormat), ArraySize = 1, MipLevels = 1, Width = width, Height = height, SampleDescription = multisampleDesc, BindFlags = BindFlags.DepthStencil, })) { // Create the view for binding to the device. _depthStencilView = new DepthStencilView(graphicsDevice._d3dDevice, depthBuffer, new DepthStencilViewDescription() { Format = SharpDXHelper.ToFormat(preferredDepthFormat), Dimension = DepthStencilViewDimension.Texture2D }); } #endif // DIRECTX }
/// <summary> /// Retourne une ressource utilisable par DirectX /// </summary> public Resource GetTexture2D() { SharpDX.DXGI.SampleDescription sampleDescription = new SharpDX.DXGI.SampleDescription() { Count = 1 }; DataStream stre = new DataStream(Width * Height * 4 * 4, true, true); for (int i = 0; i < Height; i++) { for (int j = 0; j < Width; j++) { stre.Write(GetPixel(j, i).r); stre.Write(GetPixel(j, i).g); stre.Write(GetPixel(j, i).b); stre.Write(GetPixel(j, i).a); } } Texture2DDescription description = new Texture2DDescription() { ArraySize = 1, Width = Width, Height = Height, MipLevels = 1, Format = SharpDX.DXGI.Format.R32G32B32A32_Float, Usage = ResourceUsage.Dynamic, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = 0, SampleDescription = sampleDescription }; DataRectangle rec = new DataRectangle(stre.DataPointer, Width * 4 * 4); Texture2D texture2D = new Texture2D(ApplicationDX11.Instance.Device, description, rec); texture2D.FilterTexture(ApplicationDX11.Instance.DeviceContext, 0, FilterFlags.Mirror); Resource res = new Resource(texture2D.NativePointer); return(res); }
private void GenerateIfRequired() { if (_renderTargetView != null) return; // Create a view interface on the rendertarget to use on bind. _renderTargetView = new RenderTargetView(GraphicsDevice._d3dDevice, GetTexture()); // If we don't need a depth buffer then we're done. if (DepthStencilFormat == DepthFormat.None) return; // Setup the multisampling description. var multisampleDesc = new SharpDX.DXGI.SampleDescription(1, 0); if (MultiSampleCount > 1) { multisampleDesc.Count = MultiSampleCount; multisampleDesc.Quality = (int)StandardMultisampleQualityLevels.StandardMultisamplePattern; } // Create a descriptor for the depth/stencil buffer. // Allocate a 2-D surface as the depth/stencil buffer. // Create a DepthStencil view on this surface to use on bind. using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(GraphicsDevice._d3dDevice, new Texture2DDescription { Format = SharpDXHelper.ToFormat(DepthStencilFormat), ArraySize = 1, MipLevels = 1, Width = width, Height = height, SampleDescription = multisampleDesc, BindFlags = BindFlags.DepthStencil, })) { // Create the view for binding to the device. _depthStencilView = new DepthStencilView(GraphicsDevice._d3dDevice, depthBuffer, new DepthStencilViewDescription() { Format = SharpDXHelper.ToFormat(DepthStencilFormat), Dimension = DepthStencilViewDimension.Texture2D }); } }
public RenderTarget2D (GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage, bool shared) :base (graphicsDevice, width, height, mipMap, preferredFormat, SurfaceType.RenderTarget, shared) { DepthStencilFormat = preferredDepthFormat; MultiSampleCount = preferredMultiSampleCount; RenderTargetUsage = usage; #if DIRECTX // Create a view interface on the rendertarget to use on bind. _renderTargetView = new RenderTargetView(graphicsDevice._d3dDevice, _texture); #elif PSM _frameBuffer = new FrameBuffer(); _frameBuffer.SetColorTarget(_texture2D,0); #endif // If we don't need a depth buffer then we're done. if (preferredDepthFormat == DepthFormat.None) return; #if DIRECTX // Setup the multisampling description. var multisampleDesc = new SharpDX.DXGI.SampleDescription(1, 0); if ( preferredMultiSampleCount > 1 ) { multisampleDesc.Count = preferredMultiSampleCount; multisampleDesc.Quality = (int)StandardMultisampleQualityLevels.StandardMultisamplePattern; } // Create a descriptor for the depth/stencil buffer. // Allocate a 2-D surface as the depth/stencil buffer. // Create a DepthStencil view on this surface to use on bind. using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(graphicsDevice._d3dDevice, new Texture2DDescription { Format = SharpDXHelper.ToFormat(preferredDepthFormat), ArraySize = 1, MipLevels = 1, Width = width, Height = height, SampleDescription = multisampleDesc, BindFlags = BindFlags.DepthStencil, })) { // Create the view for binding to the device. _depthStencilView = new DepthStencilView(graphicsDevice._d3dDevice, depthBuffer, new DepthStencilViewDescription() { Format = SharpDXHelper.ToFormat(preferredDepthFormat), Dimension = DepthStencilViewDimension.Texture2D }); } #elif PSM throw new NotImplementedException(); #elif OPENGL #if GLES GL.GenRenderbuffers(1, ref glDepthStencilBuffer); #else GL.GenRenderbuffers(1, out glDepthStencilBuffer); #endif GraphicsExtensions.CheckGLError(); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, this.glDepthStencilBuffer); GraphicsExtensions.CheckGLError(); var glDepthStencilFormat = GLDepthComponent16; switch (preferredDepthFormat) { case DepthFormat.Depth16: glDepthStencilFormat = GLDepthComponent16; break; case DepthFormat.Depth24: glDepthStencilFormat = GLDepthComponent24; break; case DepthFormat.Depth24Stencil8: glDepthStencilFormat = GLDepth24Stencil8; break; } GL.RenderbufferStorage(GLRenderbuffer, glDepthStencilFormat, this.width, this.height); GraphicsExtensions.CheckGLError(); #endif }
public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage) : base(graphicsDevice, width, height, mipMap, preferredFormat, true) { DepthStencilFormat = preferredDepthFormat; MultiSampleCount = preferredMultiSampleCount; RenderTargetUsage = usage; #if DIRECTX // Create a view interface on the rendertarget to use on bind. _renderTargetView = new SharpDX.Direct3D11.RenderTargetView(graphicsDevice._d3dDevice, _texture); #endif // If we don't need a depth buffer then we're done. if (preferredDepthFormat == DepthFormat.None) { return; } #if DIRECTX // Setup the multisampling description. var multisampleDesc = new SharpDX.DXGI.SampleDescription(1, 0); if (preferredMultiSampleCount > 1) { multisampleDesc.Count = preferredMultiSampleCount; multisampleDesc.Quality = (int)SharpDX.Direct3D11.StandardMultisampleQualityLevels.StandardMultisamplePattern; } // Create a descriptor for the depth/stencil buffer. // Allocate a 2-D surface as the depth/stencil buffer. // Create a DepthStencil view on this surface to use on bind. using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(graphicsDevice._d3dDevice, new SharpDX.Direct3D11.Texture2DDescription() { Format = SharpDXHelper.ToFormat(preferredDepthFormat), ArraySize = 1, MipLevels = 1, Width = width, Height = height, SampleDescription = multisampleDesc, BindFlags = SharpDX.Direct3D11.BindFlags.DepthStencil, })) // Create the view for binding to the device. _depthStencilView = new SharpDX.Direct3D11.DepthStencilView(graphicsDevice._d3dDevice, depthBuffer, new SharpDX.Direct3D11.DepthStencilViewDescription() { Format = SharpDXHelper.ToFormat(preferredDepthFormat), Dimension = SharpDX.Direct3D11.DepthStencilViewDimension.Texture2D }); #elif OPENGL #if GLES GL.GenRenderbuffers(1, ref glDepthStencilBuffer); #else GL.GenRenderbuffers(1, out glDepthStencilBuffer); #endif GraphicsExtensions.CheckGLError(); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, this.glDepthStencilBuffer); GraphicsExtensions.CheckGLError(); var glDepthStencilFormat = GLDepthComponent16; switch (preferredDepthFormat) { case DepthFormat.Depth16: glDepthStencilFormat = GLDepthComponent16; break; case DepthFormat.Depth24: glDepthStencilFormat = GLDepthComponent24; break; case DepthFormat.Depth24Stencil8: glDepthStencilFormat = GLDepth24Stencil8; break; } GL.RenderbufferStorage(GLRenderbuffer, glDepthStencilFormat, this.width, this.height); GraphicsExtensions.CheckGLError(); #endif }
public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage, bool shared) : base(graphicsDevice, width, height, mipMap, preferredFormat, SurfaceType.RenderTarget, shared) { DepthStencilFormat = preferredDepthFormat; MultiSampleCount = preferredMultiSampleCount; RenderTargetUsage = usage; #if DIRECTX // Create a view interface on the rendertarget to use on bind. _renderTargetView = new RenderTargetView(graphicsDevice._d3dDevice, _texture); #elif PSM _frameBuffer = new FrameBuffer(); _frameBuffer.SetColorTarget(_texture2D, 0); #endif // If we don't need a depth buffer then we're done. if (preferredDepthFormat == DepthFormat.None) { return; } #if DIRECTX // Setup the multisampling description. var multisampleDesc = new SharpDX.DXGI.SampleDescription(1, 0); if (preferredMultiSampleCount > 1) { multisampleDesc.Count = preferredMultiSampleCount; multisampleDesc.Quality = (int)StandardMultisampleQualityLevels.StandardMultisamplePattern; } // Create a descriptor for the depth/stencil buffer. // Allocate a 2-D surface as the depth/stencil buffer. // Create a DepthStencil view on this surface to use on bind. using (var depthBuffer = new SharpDX.Direct3D11.Texture2D(graphicsDevice._d3dDevice, new Texture2DDescription { Format = SharpDXHelper.ToFormat(preferredDepthFormat), ArraySize = 1, MipLevels = 1, Width = width, Height = height, SampleDescription = multisampleDesc, BindFlags = BindFlags.DepthStencil, })) { // Create the view for binding to the device. _depthStencilView = new DepthStencilView(graphicsDevice._d3dDevice, depthBuffer, new DepthStencilViewDescription() { Format = SharpDXHelper.ToFormat(preferredDepthFormat), Dimension = DepthStencilViewDimension.Texture2D }); } #elif PSM throw new NotImplementedException(); #elif OPENGL var glDepthFormat = GLDepthComponent16; var glStencilFormat = GLStencilIndex8; switch (preferredDepthFormat) { case DepthFormat.Depth16: glDepthFormat = GLDepthComponent16; break; #if GLES case DepthFormat.Depth24: glDepthFormat = GraphicsCapabilities.SupportsDepth24 ? GLDepthComponent24 : GraphicsCapabilities.SupportsDepthNonLinear ? GLDepthComponent16NonLinear : GLDepthComponent16; break; case DepthFormat.Depth24Stencil8: glDepthFormat = GraphicsCapabilities.SupportsDepth24 ? GLDepthComponent24 : GraphicsCapabilities.SupportsDepthNonLinear ? GLDepthComponent16NonLinear : GLDepthComponent16; glStencilFormat = GLStencilIndex8; break; #else case DepthFormat.Depth24: glDepthFormat = GLDepthComponent24; break; case DepthFormat.Depth24Stencil8: glDepthFormat = GLDepthComponent24; glStencilFormat = GLStencilIndex8; break; #endif } #if GLES GL.GenRenderbuffers(1, ref glDepthBuffer); #else GL.GenRenderbuffers(1, out glDepthBuffer); #endif GraphicsExtensions.CheckGLError(); if (preferredDepthFormat == DepthFormat.Depth24Stencil8) { if (GraphicsCapabilities.SupportsPackedDepthStencil) { this.glStencilBuffer = this.glDepthBuffer; GL.BindRenderbuffer(GLRenderbuffer, this.glDepthBuffer); GraphicsExtensions.CheckGLError(); GL.RenderbufferStorage(GLRenderbuffer, GLDepth24Stencil8, this.width, this.height); GraphicsExtensions.CheckGLError(); } else { GL.BindRenderbuffer(GLRenderbuffer, this.glDepthBuffer); GraphicsExtensions.CheckGLError(); GL.RenderbufferStorage(GLRenderbuffer, glDepthFormat, this.width, this.height); GraphicsExtensions.CheckGLError(); #if GLES GL.GenRenderbuffers(1, ref glStencilBuffer); #else GL.GenRenderbuffers(1, out glStencilBuffer); #endif GraphicsExtensions.CheckGLError(); GL.BindRenderbuffer(GLRenderbuffer, this.glStencilBuffer); GraphicsExtensions.CheckGLError(); GL.RenderbufferStorage(GLRenderbuffer, glStencilFormat, this.width, this.height); GraphicsExtensions.CheckGLError(); } } else { GL.BindRenderbuffer(GLRenderbuffer, this.glDepthBuffer); GraphicsExtensions.CheckGLError(); GL.RenderbufferStorage(GLRenderbuffer, glDepthFormat, this.width, this.height); GraphicsExtensions.CheckGLError(); } #endif }
static SharpDX.DXGI.SampleDescription DetectSampleDescription(Device device, SharpDX.DXGI.Format format) { var desc = new SharpDX.DXGI.SampleDescription(); for (int multisample_count = Device.MultisampleCountMaximum; multisample_count > 0; --multisample_count) { int quality_levels = device.CheckMultisampleQualityLevels(format, multisample_count); if (quality_levels > 0) { desc.Count = multisample_count; desc.Quality = quality_levels - 1; break; } } Console.WriteLine("sample count {0} quality {1}", desc.Count, desc.Quality); return desc; }