private void CreateViews() { _backBuffer = D3D.Resource.FromSwapChain <D3D.Texture2D>(_swapChain, 0); _renderTargetView = new D3D.RenderTargetView(_graphicsDevice, _backBuffer); //Add resources to tracker _renderer.Resources.AddTrackedObject(_backBuffer.ComPointer, this); _renderer.Resources.AddTrackedObject(_renderTargetView.ComPointer, this); if (_presentParams.DepthStencilFormat != DepthFormat.None) { D3D.Texture2DDescription depthBufferDesc = new D3D.Texture2DDescription { ArraySize = 1, BindFlags = D3D.BindFlags.DepthStencil, CpuAccessFlags = D3D.CpuAccessFlags.None, Format = D3D10Helper.ToD3DDepthFormat(_presentParams.DepthStencilFormat), Height = _presentParams.BackBufferHeight, Width = _presentParams.BackBufferWidth, MipLevels = 1, OptionFlags = D3D.ResourceOptionFlags.None, SampleDescription = _backBuffer.Description.SampleDescription, Usage = D3D.ResourceUsage.Default }; using (var depthBuffer = new D3D.Texture2D(_graphicsDevice, depthBufferDesc)) { _depthStencilView = new D3D.DepthStencilView(_graphicsDevice, depthBuffer); //Add resource to tracker _renderer.Resources.AddTrackedObject(_depthStencilView.ComPointer, this); } } }
/// <summary> /// Creates a new instance of <see cref="D3D10Texture2DImplementation"/>, for RenderTarget2D. /// </summary> /// <param name="renderer">The D3D10 renderer.</param> /// <param name="width">The texture width in pixels.</param> /// <param name="height">The texture height in pixels.</param> /// <param name="genMipMaps">True if a mipmap chain should be generated or not.</param> /// <param name="format">The surface format.</param> /// <param name="depthFormat">The depth-stencil format.</param> /// <param name="multiSampleCount">The multisample count.</param> /// <param name="usage">The target usage.</param> /// <exception cref="System.ArgumentException">Thrown if the formats are invalid to be used in a render target.</exception> internal D3D10Texture2DImplementation(D3D10Renderer renderer, int width, int height, bool genMipMaps, SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount, RenderTargetUsage usage) : base(width, height, format, depthFormat, multiSampleCount, usage) { _renderer = renderer; _graphicsDevice = _renderer.GraphicsDevice; if (!renderer.Adapter.QueryRenderTargetFormat(format, depthFormat, multiSampleCount)) { throw new ArgumentException("Format combination not supported."); } D3D.Texture2DDescription desc2D = new D3D.Texture2DDescription(); desc2D.ArraySize = 1; desc2D.BindFlags = D3D.BindFlags.ShaderResource | D3D.BindFlags.RenderTarget; desc2D.CpuAccessFlags = D3D.CpuAccessFlags.None; desc2D.Format = D3D10Helper.ToD3DSurfaceFormat(format); desc2D.Height = height; desc2D.Width = width; desc2D.Usage = _usage = D3D.ResourceUsage.Default; if (genMipMaps) { desc2D.OptionFlags = D3D.ResourceOptionFlags.GenerateMipMaps; } else { desc2D.OptionFlags = D3D.ResourceOptionFlags.None; } desc2D.MipLevels = (genMipMaps) ? 0 : 1; if (multiSampleCount > 1) { desc2D.SampleDescription = new SlimDX.DXGI.SampleDescription(multiSampleCount, 0); } else { desc2D.SampleDescription = new DXGI.SampleDescription(1, 0); } _texture2D = new D3D.Texture2D(_graphicsDevice, desc2D); _shaderResourceView = new D3D.ShaderResourceView(_graphicsDevice, _texture2D); _renderTargetView = new D3D.RenderTargetView(_graphicsDevice, _texture2D); _graphicsDevice.ClearRenderTargetView(_renderTargetView, new SDX.Color4(1.0f, 0, 0, 0)); //Add to tracker _renderer.Resources.AddTrackedObject(_texture2D.ComPointer, this); _renderer.Resources.AddTrackedObject(_shaderResourceView.ComPointer, this); _renderer.Resources.AddTrackedObject(_renderTargetView.ComPointer, this); _mipCount = _texture2D.Description.MipLevels; if (depthFormat != DepthFormat.None) { D3D.Texture2DDescription dbdesc = new D3D.Texture2DDescription(); dbdesc.ArraySize = 1; dbdesc.BindFlags = D3D.BindFlags.DepthStencil; dbdesc.CpuAccessFlags = D3D.CpuAccessFlags.None; dbdesc.Format = D3D10Helper.ToD3DDepthFormat(depthFormat); dbdesc.Height = height; dbdesc.Width = width; dbdesc.Usage = D3D.ResourceUsage.Default; dbdesc.OptionFlags = D3D.ResourceOptionFlags.None; dbdesc.MipLevels = 1; if (multiSampleCount > 1) { dbdesc.SampleDescription = new SlimDX.DXGI.SampleDescription(multiSampleCount, 0); } else { dbdesc.SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0); } using (D3D.Texture2D depthBuffer = new D3D.Texture2D(_graphicsDevice, dbdesc)) { _depthStencilView = new D3D.DepthStencilView(_graphicsDevice, depthBuffer); if (depthFormat == Tesla.Graphics.DepthFormat.Depth24Stencil8) { _graphicsDevice.ClearDepthStencilView(_depthStencilView, D3D.DepthStencilClearFlags.Depth | D3D.DepthStencilClearFlags.Stencil, 1.0f, 0); } else { _graphicsDevice.ClearDepthStencilView(_depthStencilView, D3D.DepthStencilClearFlags.Depth, 1.0f, 0); } //Add to tracker _renderer.Resources.AddTrackedObject(_depthStencilView.ComPointer, this); } } }
/// <summary> /// Creates a new instance of <see cref="D3D10TextureCubeImplementation"/>. /// </summary> /// <param name="renderer">The D3D10 renderer.</param> /// <param name="size">The size (width/height) of each cube face.</param> /// <param name="genMipMaps">True if a mipmap chain should be generated or not.</param> /// <param name="format">The surface format.</param> /// <param name="depthFormat">The depth-stencil format.</param> /// <param name="multiSampleCount">The number of sample locations for multisampling</param> /// <param name="usage">Sets the render target's behavior.</param> internal D3D10TextureCubeImplementation(D3D10Renderer renderer, int size, bool genMipMaps, SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount, RenderTargetUsage usage) : base(size, format, depthFormat, multiSampleCount, usage) { _renderer = renderer; _graphicsDevice = _renderer.GraphicsDevice; if (!renderer.Adapter.QueryRenderTargetFormat(format, depthFormat, multiSampleCount)) { throw new ArgumentException("Format combination not supported."); } D3D.Texture2DDescription desc2D = new D3D.Texture2DDescription(); desc2D.ArraySize = 6; desc2D.BindFlags = D3D.BindFlags.ShaderResource | D3D.BindFlags.RenderTarget; desc2D.CpuAccessFlags = D3D.CpuAccessFlags.None; desc2D.Format = D3D10Helper.ToD3DSurfaceFormat(format); desc2D.Height = size; desc2D.Width = size; desc2D.Usage = D3D.ResourceUsage.Default; if (genMipMaps) { desc2D.OptionFlags = D3D.ResourceOptionFlags.GenerateMipMaps | D3D.ResourceOptionFlags.TextureCube; } else { desc2D.OptionFlags = D3D.ResourceOptionFlags.TextureCube; } desc2D.MipLevels = (genMipMaps) ? 0 : 1; if (multiSampleCount > 1) { desc2D.SampleDescription = new SlimDX.DXGI.SampleDescription(multiSampleCount, 0); } else { desc2D.SampleDescription = new DXGI.SampleDescription(1, 0); } //Create the resources _texture2D = new D3D.Texture2D(_graphicsDevice, desc2D); _shaderResourceView = new D3D.ShaderResourceView(_graphicsDevice, _texture2D); _renderTargetView = new D3D.RenderTargetView[6]; //Add to tracker _renderer.Resources.AddTrackedObject(_texture2D.ComPointer, this); _renderer.Resources.AddTrackedObject(_shaderResourceView.ComPointer, this); //Setup each render target view for each face for (int i = 0; i < 6; i++) { D3D.RenderTargetViewDescription rtDesc = new D3D.RenderTargetViewDescription(); rtDesc.ArraySize = 1; rtDesc.FirstArraySlice = i; if (multiSampleCount > 1) { rtDesc.Dimension = D3D.RenderTargetViewDimension.Texture2DMultisampledArray; } else { rtDesc.Dimension = D3D.RenderTargetViewDimension.Texture2DArray; } rtDesc.Format = desc2D.Format; _renderTargetView[i] = new D3D.RenderTargetView(_graphicsDevice, _texture2D, rtDesc); _graphicsDevice.ClearRenderTargetView(_renderTargetView[i], new SDX.Color4(1.0f, 0, 0, 0)); _renderer.Resources.AddTrackedObject(_renderTargetView[i].ComPointer, this); } _mipCount = _texture2D.Description.MipLevels; if (depthFormat != DepthFormat.None) { D3D.Texture2DDescription dbdesc = new D3D.Texture2DDescription(); dbdesc.ArraySize = 6; dbdesc.BindFlags = D3D.BindFlags.DepthStencil; dbdesc.CpuAccessFlags = D3D.CpuAccessFlags.None; dbdesc.Format = D3D10Helper.ToD3DDepthFormat(depthFormat); dbdesc.Height = size; dbdesc.Width = size; dbdesc.Usage = D3D.ResourceUsage.Default; dbdesc.OptionFlags = D3D.ResourceOptionFlags.None; dbdesc.MipLevels = 1; if (multiSampleCount > 1) { dbdesc.SampleDescription = new SlimDX.DXGI.SampleDescription(multiSampleCount, 0); } else { dbdesc.SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0); } using (D3D.Texture2D depthBuffer = new D3D.Texture2D(_graphicsDevice, dbdesc)) { _depthStencilView = new D3D.DepthStencilView(_graphicsDevice, depthBuffer); if (depthFormat == Tesla.Graphics.DepthFormat.Depth24Stencil8) { _graphicsDevice.ClearDepthStencilView(_depthStencilView, D3D.DepthStencilClearFlags.Depth | D3D.DepthStencilClearFlags.Stencil, 1.0f, 0); } else { _graphicsDevice.ClearDepthStencilView(_depthStencilView, D3D.DepthStencilClearFlags.Depth, 1.0f, 0); } //Add to tracker _renderer.Resources.AddTrackedObject(_depthStencilView.ComPointer, this); } } }