private void CreateStaging() { if (_staging == null) { D3D.Texture3DDescription oDesc = _texture3D.Description; D3D.Texture3DDescription desc = new D3D.Texture3DDescription(); desc.BindFlags = D3D.BindFlags.None; desc.CpuAccessFlags = D3D.CpuAccessFlags.Write | D3D.CpuAccessFlags.Read; desc.Format = D3D10Helper.ToD3DSurfaceFormat(base.Format); desc.Height = base.Height; desc.Width = base.Width; desc.Depth = base.Depth; desc.MipLevels = _mipCount; desc.Usage = D3D.ResourceUsage.Staging; _staging = new D3D.Texture3D(_graphicsDevice, desc); //Add to tracker _renderer.Resources.AddTrackedObject(_staging.ComPointer, this); } }
/// <summary> /// Creates a new instance of <see cref="D3D10Texture3DImplementation"/>. /// </summary> /// <param name="renderer">The D3D0 renderer.</param> /// <param name="width">The width of the texture.</param> /// <param name="height">The height of the texture.</param> /// <param name="depth">The depth of the texture.</param> /// <param name="genMipMaps">True if mip map subresources should be generated or not.</param> /// <param name="format">The surface format.</param> /// <param name="data">The initial data for the first mip map.</param> internal D3D10Texture3DImplementation(D3D10Renderer renderer, int width, int height, int depth, bool genMipMaps, SurfaceFormat format, DataBuffer data) : base(width, height, depth, format) { //Set common properties _renderer = renderer; _graphicsDevice = _renderer.GraphicsDevice; //Do we want to generate mip maps, and do we have the data to do so? (if not, cancel mip map generation) bool canGenMipmaps = (genMipMaps && (data != null)); D3D.Texture3DDescription descTex = new D3D.Texture3DDescription(); descTex.Width = width; descTex.Height = height; descTex.Depth = depth; descTex.Usage = _usage = D3D.ResourceUsage.Default; descTex.CpuAccessFlags = D3D.CpuAccessFlags.None; descTex.Format = D3D10Helper.ToD3DSurfaceFormat(format); descTex.MipLevels = (genMipMaps) ? 0 : 1; //Set mip map generation params if (canGenMipmaps) { descTex.BindFlags = D3D.BindFlags.ShaderResource | D3D.BindFlags.RenderTarget; descTex.OptionFlags = D3D.ResourceOptionFlags.GenerateMipMaps; } else { descTex.BindFlags = D3D.BindFlags.ShaderResource; descTex.OptionFlags = D3D.ResourceOptionFlags.None; } //Create the texture and shader view _texture3D = new D3D.Texture3D(_graphicsDevice, descTex); _shaderResourceView = new D3D.ShaderResourceView(_graphicsDevice, _texture3D); //Add to tracker _renderer.Resources.AddTrackedObject(_texture3D.ComPointer, this); _renderer.Resources.AddTrackedObject(_shaderResourceView.ComPointer, this); //Set the final mip count _mipCount = _texture3D.Description.MipLevels; //Now set the initial data if its present if (data != null) { try { this.SetData <byte>(data.ByteDataCopy, 0, 0, width, 0, height, 0, depth, 0, data.ElementSizeInBytes * data.Length); if (genMipMaps) { _graphicsDevice.GenerateMips(_shaderResourceView); } //Dispose of the staging texture if (_staging != null) { _staging.Dispose(); _staging = null; } } catch (Exception e) { Dispose(); throw new TeslaException("Error setting Texture data.", e); } } }