/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (!IsDisposed) { //Dispose of managed resources if (disposing) { if (_shaderResourceView != null) { if (_renderer != null) { _renderer.Resources.RemoveTrackedObject(_shaderResourceView.ComPointer); } _shaderResourceView.Dispose(); _shaderResourceView = null; } if (_renderTargetView != null) { if (_renderer != null) { _renderer.Resources.RemoveTrackedObject(_renderTargetView.ComPointer); } _renderTargetView.Dispose(); _renderTargetView = null; } if (_depthStencilView != null) { if (_renderer != null) { _renderer.Resources.RemoveTrackedObject(_depthStencilView.ComPointer); } _depthStencilView.Dispose(); _depthStencilView = null; } if (_texture2D != null) { if (_renderer != null) { _renderer.Resources.RemoveTrackedObject(_texture2D.ComPointer); } _texture2D.Dispose(); _texture2D = null; } if (_staging != null) { if (_renderer != null) { _renderer.Resources.RemoveTrackedObject(_staging.ComPointer); } _staging.Dispose(); _staging = null; } } base.Dispose(disposing); } }
/// <summary> /// Flushes the collection's state to the device, only textures that have been /// changed since the last draw call will get sent. /// </summary> internal void FlushState() { //Return if we haven't even touched these states, so we don't have to loop over them. if (!_shortCircuitUpdate) { return; } for (int i = 0; i < _maxTextures; i++) { //If state is dirty, grab the contents and send to the device if (_dirtyMark[i]) { //Clear the dirty bit _dirtyMark[i] = false; D3D.ShaderResourceView shaderResource = null; Texture value = _textures[i]; //Get shader resource if (value != null) { D3D10Helper.CheckDisposed(value); switch (value.Dimensions) { case TextureDimensions.One: D3D10Texture1DImplementation impl1D = value.Implementation as D3D10Texture1DImplementation; shaderResource = impl1D.D3D10ShaderResourceView; break; case TextureDimensions.Two: D3D10Texture2DImplementation impl2D = value.Implementation as D3D10Texture2DImplementation; shaderResource = impl2D.D3D10ShaderResourceView; break; case TextureDimensions.Three: D3D10Texture3DImplementation impl3D = value.Implementation as D3D10Texture3DImplementation; shaderResource = impl3D.D3D10ShaderResourceView; break; case TextureDimensions.Cube: D3D10TextureCubeImplementation implCube = value.Implementation as D3D10TextureCubeImplementation; shaderResource = implCube.D3D10ShaderResourceView; break; } } //Set shader resource (or null) if (_vertexTex) { _graphicsDevice.VertexShader.SetShaderResource(shaderResource, i); } else { _graphicsDevice.PixelShader.SetShaderResource(shaderResource, i); } } } _shortCircuitUpdate = false; }
public RenderTarget(D3D.Device device, D3D.Texture2DDescription rdesc) : base(device) { rdesc.BindFlags |= D3D.BindFlags.ShaderResource; D3D.Texture2D te = new D3D.Texture2D(device, rdesc); Resource = te; RenderView = new D3D.RenderTargetView(device, te); View = new D3D.ShaderResourceView(device, Resource); }
/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (!IsDisposed) { //Dispose of managed resources if (disposing) { if (_shaderResourceView != null) { if (_renderer != null) { _renderer.Resources.RemoveTrackedObject(_shaderResourceView.ComPointer); } _shaderResourceView.Dispose(); _shaderResourceView = null; } if (_renderTargetView != null) { for (int i = 0; i < 6; i++) { D3D.RenderTargetView rt = _renderTargetView[i]; if (_renderer != null) { _renderer.Resources.RemoveTrackedObject(rt.ComPointer); } rt.Dispose(); _renderTargetView[i] = null; } } if (_depthStencilView != null) { if (_renderer != null) { _renderer.Resources.RemoveTrackedObject(_depthStencilView.ComPointer); } _depthStencilView.Dispose(); _depthStencilView = null; } if (_texture2D != null) { if (_renderer != null) { _renderer.Resources.RemoveTrackedObject(_texture2D.ComPointer); } _texture2D.Dispose(); _texture2D = null; } } base.Dispose(disposing); } }
public RenderTarget(D3D.Device device, int width, int height) : base(device) { D3D.Texture2DDescription rdesc = new D3D.Texture2DDescription() { Width = width, Height = height, MipLevels = 1, ArraySize = 1, Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm, SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0), Usage = D3D.ResourceUsage.Default, BindFlags = D3D.BindFlags.RenderTarget | D3D.BindFlags.ShaderResource, CpuAccessFlags = D3D.CpuAccessFlags.None, OptionFlags = D3D.ResourceOptionFlags.None }; Resource = new D3D.Texture2D(device, rdesc); RenderView = new D3D.RenderTargetView(device, Texture); View = new D3D.ShaderResourceView(device, Resource); }
public RenderTarget( D3D10.Device device, int width, int height, DXGI.Format format ) { this.device = device; D3D10.Texture2DDescription desc = new D3D10.Texture2DDescription(); desc.Width = width; desc.Height = height; desc.ArraySize = 1; desc.BindFlags = D3D10.BindFlags.RenderTarget | D3D10.BindFlags.ShaderResource; desc.CpuAccessFlags = D3D10.CpuAccessFlags.None; desc.Format = format; desc.MipLevels = 1; desc.OptionFlags = D3D10.ResourceOptionFlags.None; desc.SampleDescription = new SlimDX.DXGI.SampleDescription( 1, 0 ); desc.Usage = D3D10.ResourceUsage.Default; Resource = new D3D10.Texture2D( device, desc ); RenderTargetView = new D3D10.RenderTargetView( device, Resource ); ShaderResourceView = new D3D10.ShaderResourceView( device, Resource ); }
public SpriteTexture(D3D.Device device, string filename) : base(device) { D3D.ImageLoadInformation iml = new D3D.ImageLoadInformation() { BindFlags = D3D.BindFlags.ShaderResource, CpuAccessFlags = D3D.CpuAccessFlags.None, Depth = 1, FilterFlags = D3D.FilterFlags.None, FirstMipLevel = 0, Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm, MipFilterFlags = D3D.FilterFlags.None, MipLevels = 1, OptionFlags = D3D.ResourceOptionFlags.None, Usage = D3D.ResourceUsage.Default }; Resource = D3D.Texture2D.FromFile(device, filename, iml); View = new D3D.ShaderResourceView(device, Resource); Instance = new D3D.SpriteInstance(this.View, new Vector2(0, 0), new Vector2(1, 1)); UpdateTransform(); }
public Texture( D3D10.Device device, string filename ) { Resource = D3D10.Texture2D.FromFile( device, filename ); View = new D3D10.ShaderResourceView( device, Resource ); }
void Create( D3D10.Device device, D3D10.Texture2DDescription desc ) { Resource = new D3D10.Texture2D( device, desc ); View = new D3D10.ShaderResourceView( device, Resource ); }
/// <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="D3D10Texture2DImplementation"/>, for Texture2D. /// </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="data">The data to initialize the first mip map level.</param> /// <exception cref="Tesla.Core.TeslaException">Thrown if there was an error writing to the texture.</exception> internal D3D10Texture2DImplementation(D3D10Renderer renderer, int width, int height, bool genMipMaps, SurfaceFormat format, DataBuffer data) : base(width, height, 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)); //Setup texture description D3D.Texture2DDescription descTex = new D3D.Texture2DDescription(); descTex.ArraySize = 1; descTex.Width = width; descTex.Height = height; descTex.Usage = _usage = D3D.ResourceUsage.Default; descTex.CpuAccessFlags = D3D.CpuAccessFlags.None; descTex.Format = D3D10Helper.ToD3DSurfaceFormat(format); descTex.SampleDescription = new DXGI.SampleDescription(1, 0); //Default sample desc 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 _texture2D = new D3D.Texture2D(_graphicsDevice, descTex); _shaderResourceView = new D3D.ShaderResourceView(_graphicsDevice, _texture2D); //Add to tracker _renderer.Resources.AddTrackedObject(_texture2D.ComPointer, this); _renderer.Resources.AddTrackedObject(_shaderResourceView.ComPointer, this); //Set the final mip count _mipCount = _texture2D.Description.MipLevels; //Now set the initial data if its present if (data != null) { try { this.SetData <byte>(data.ByteDataCopy, 0, null, 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); } } }
public Sky(Vector3 lightDir, StreamReader file) { /// // outerRadius = innerRadius * 1.0157313f; // atmScale = 1f / (outerRadius - innerRadius); dome.CreateDome((int)size.X, (int)size.Y); // waveLength4 = new Vector3((float)Math.Pow(waveLength.X, 4), (float)Math.Pow(waveLength.Y, 4), (float)Math.Pow(waveLength.Z, 4)); // double pow = -0.84; // waveLength084 = new Vector3((float)Math.Pow(waveLength.X, pow), (float)Math.Pow(waveLength.Y, pow), (float)Math.Pow(waveLength.Z, pow)); effect = ResourceManager.mainManager.LoadEffect("Resources\\Effects\\Sky.fx", ResourceManager.mainManager.GetDefaultEffectPool()); pass = effect.GetTechniqueByName("Render").GetPassByIndex(0); updatePass = effect.GetTechniqueByName("Update").GetPassByIndex(0); D3D10.InputElement[] elements = new SlimDX.Direct3D10.InputElement[2]; elements[0] = new SlimDX.Direct3D10.InputElement("POSITION", 0, SlimDX.DXGI.Format.R32G32B32_Float, 0, 0); elements[1] = new D3D10.InputElement("TEXCOORD", 0, SlimDX.DXGI.Format.R32G32_Float, 12, 0); layout = new SlimDX.Direct3D10.InputLayout(Game.gameClass.GetDevice(), elements, pass.Description.Signature); layoutUpdate = Quad.GetLayout(updatePass); translation = effect.GetVariableByName("translation").AsVector(); sunPosition = effect.GetVariableByName("sunPos").AsVector(); // Vector4 mieTemps = new Vector4((3 * (1 - g * g)) / (2 * (2 + g * g)), 1 + g * g, g, 1); mieTemps = effect.GetVariableByName("mieTemps").AsVector(); K = effect.GetVariableByName("K").AsVector(); waveLengthRay = effect.GetVariableByName("waveLengthRay").AsVector(); waveLengthMie = effect.GetVariableByName("waveLengthMie").AsVector(); scaleDepth = effect.GetVariableByName("scaleDepth").AsVector(); sunIntensity = effect.GetVariableByName("sunIntensity").AsScalar(); //textures D3D10.Texture2DDescription desc = new SlimDX.Direct3D10.Texture2DDescription(); desc.ArraySize = 1; desc.BindFlags = D3D10.BindFlags.ShaderResource | SlimDX.Direct3D10.BindFlags.RenderTarget; desc.CpuAccessFlags = D3D10.CpuAccessFlags.None; desc.Format = SlimDX.DXGI.Format.R16G16B16A16_Float; desc.Height = (int)size.Y; desc.MipLevels = 1; desc.OptionFlags = D3D10.ResourceOptionFlags.None; desc.Usage = D3D10.ResourceUsage.Default; desc.Width = (int)size.X; SlimDX.DXGI.SampleDescription sampleDescription = new SlimDX.DXGI.SampleDescription(); sampleDescription.Count = 1; sampleDescription.Quality = 0; desc.SampleDescription = sampleDescription; rayLookupTexture = new D3D10.Texture2D(Game.gameClass.GetDevice(), desc); mieLookupTexture = new D3D10.Texture2D(Game.gameClass.GetDevice(), desc); /* desc.BindFlags = D3D10.BindFlags.None; desc.CpuAccessFlags = D3D10.CpuAccessFlags.Write; desc.Usage = D3D10.ResourceUsage.Staging; mieUpdateTexture = new D3D10.Texture2D(Game.gameClass.GetDevice(), desc); rayUpdateTexture = new D3D10.Texture2D(Game.gameClass.GetDevice(), desc); mieUpdateTextureMap = mieUpdateTexture.Map(0, D3D10.MapMode.Write, D3D10.MapFlags.DoNotWait); mieUpdateTexture.Unmap(0); rayUpdateTextureMap = rayUpdateTexture.Map(0, D3D10.MapMode.Write, D3D10.MapFlags.DoNotWait); rayUpdateTexture.Unmap(0);*/ using (D3D10.ShaderResourceView view = new SlimDX.Direct3D10.ShaderResourceView(Game.gameClass.GetDevice(), rayLookupTexture)) effect.GetVariableByName("rayLookupTex").AsResource().SetResource(view); using (D3D10.ShaderResourceView view = new SlimDX.Direct3D10.ShaderResourceView(Game.gameClass.GetDevice(), mieLookupTexture)) effect.GetVariableByName("mieLookupTex").AsResource().SetResource(view); viewPort = new Viewport(); viewPort.Height = (int)size.Y; viewPort.Width = (int)size.X; viewPort.MaxZ = 1.0f; viewPort.MinZ = 0.0f; viewPort.X = 0; viewPort.Y = 0; renderTargets[0] = new SlimDX.Direct3D10.RenderTargetView(Game.gameClass.GetDevice(), rayLookupTexture); renderTargets[1] = new SlimDX.Direct3D10.RenderTargetView(Game.gameClass.GetDevice(), mieLookupTexture); Load(file); CalculateLookupOnGPU(-lightDir); }
public override void Init(D3DDevice device) { base.Init(device); texture = D3D.Texture2D.FromFile(device.Device, @"C:\Users\adrianj\Documents\Visual Studio 2010\Projects\Direct3D-Testing\ImageTiler_Test\bin\Debug\Images\test_google.bmp"); D3D.ShaderResourceView textureResourceView = new D3D.ShaderResourceView(device.Device, texture); D3D.EffectResourceVariable textureResource = effect.GetVariableByName("Texture_0").AsResource(); device.Device.PixelShader.SetShaderResource(textureResourceView, 0); textureResource.SetResource(textureResourceView); texture.Dispose(); textureResourceView.Dispose(); zoomEffect = effect.GetVariableByName("TextureZoomLevel").AsScalar(); }
protected override void RecreateTexture(int width, int height) { base.RecreateTexture(width, height); if (View != null) View.Dispose(); View = new D3D.ShaderResourceView(device, Resource); Instance = new D3D.SpriteInstance(this.View, new Vector2(0, 0), new Vector2(1, 1)); //Instance.Color = new Color4(AlphaBlend, 1, 1, 1); UpdateTransform(); }
/// <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); } } }
/// <summary> /// Creates a new instance of <see cref="D3D10TextureCubeImplementation"/>. /// </summary> /// <param name="renderer">D3D10 renderer</param> /// <param name="size">The size (width/height) of each cube face.</param> /// <param name="genMipMaps">True if mip levels should be generated.</param> /// <param name="format">The surface format.</param> /// <param name="data">The initial data for the first mip level.</param> /// <exception cref="System.ArgumentException">Thrown if the data buffery array does not correspond to a valid cube map (6 faces, all the same size)</exception> /// <exception cref="Tesla.Core.TeslaException">Thrown if there was an error writing to the texture.</exception> internal D3D10TextureCubeImplementation(D3D10Renderer renderer, int size, bool genMipMaps, SurfaceFormat format, DataBuffer[] data) : base(size, format) { //Set the 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)); //Setup texture description D3D.Texture2DDescription descTex = new D3D.Texture2DDescription(); descTex.ArraySize = 6; descTex.Width = size; descTex.Height = size; descTex.Usage = _usage = D3D.ResourceUsage.Default; descTex.CpuAccessFlags = D3D.CpuAccessFlags.None; descTex.Format = D3D10Helper.ToD3DSurfaceFormat(format); descTex.SampleDescription = new DXGI.SampleDescription(1, 0); 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 | D3D.ResourceOptionFlags.TextureCube; } else { descTex.BindFlags = D3D.BindFlags.ShaderResource; descTex.OptionFlags = D3D.ResourceOptionFlags.TextureCube; } //Create the texture and shader view _texture2D = new D3D.Texture2D(_graphicsDevice, descTex); _shaderResourceView = new D3D.ShaderResourceView(_graphicsDevice, _texture2D); //Add to tracker _renderer.Resources.AddTrackedObject(_texture2D.ComPointer, this); _renderer.Resources.AddTrackedObject(_shaderResourceView.ComPointer, this); //Set the final mip count _mipCount = _texture2D.Description.MipLevels; //Now set the initial data if its present if (data != null) { if (data.Length != 6) { Dispose(); throw new ArgumentException("Initial data array must have six data buffers, one for each cube face."); } int num = data[0].Length; for (int i = 1; i < 6; i++) { if (data[i].Length != num) { Dispose(); throw new ArgumentException("All data buffers must be of same length"); } } try { for (int i = 0; i < 6; i++) { DataBuffer db = data[i]; this.SetData <byte>((CubeMapFace)i, db.ByteDataCopy, 0, null, 0, db.ElementSizeInBytes * db.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); } } }
void DisposeUnmanaged() { if (Resource != null) Resource.Dispose(); Resource = null; if (View != null) View.Dispose(); View = null; }
//creation functions public Terrain(int q, StreamReader file) { quadSize = q; //loading effect effect = ResourceManager.mainManager.LoadEffect("Resources\\Effects\\Terrain.fx", ResourceManager.mainManager.GetDefaultEffectPool()); technique = effect.GetTechniqueByName("Render"); pass = technique.GetPassByIndex(0); //creating layout D3D10.InputElement[] elements = new SlimDX.Direct3D10.InputElement[1]; elements[0] = new SlimDX.Direct3D10.InputElement("TEXCOORD", 0, SlimDX.DXGI.Format.R32G32_Float, 0, 0, D3D10.InputClassification.PerVertexData, 0); layout = new SlimDX.Direct3D10.InputLayout(Game.gameClass.GetDevice(), elements, pass.Description.Signature); //loading texture D3D10.ImageLoadInformation load = new SlimDX.Direct3D10.ImageLoadInformation(); load.BindFlags = D3D10.BindFlags.ShaderResource; load.CpuAccessFlags = D3D10.CpuAccessFlags.None; load.MipLevels = 1; load.Usage=D3D10.ResourceUsage.Default; load.OptionFlags = D3D10.ResourceOptionFlags.None; load.FilterFlags = D3D10.FilterFlags.Point; load.Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm; normalTexture = D3D10.Texture2D.FromFile(Game.gameClass.GetDevice(), Path.GetDirectoryName(Game.gameClass.GetLvLFilePath()) + "\\normals.png", load); Globals.mapSize = normalTexture.Description.Width; if (Game.gameClass.GetEngineState() != EngineState.play) { D3D10.Texture2DDescription desc = new SlimDX.Direct3D10.Texture2DDescription(); desc.ArraySize = 1; desc.BindFlags = D3D10.BindFlags.None; desc.CpuAccessFlags = D3D10.CpuAccessFlags.Write; desc.Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm; desc.Height = Globals.mapSize; desc.Width = Globals.mapSize; desc.Usage = D3D10.ResourceUsage.Staging; desc.MipLevels = 1; SlimDX.DXGI.SampleDescription sampleDescription = new SlimDX.DXGI.SampleDescription(); sampleDescription.Count = 1; sampleDescription.Quality = 0; desc.SampleDescription = sampleDescription; normalTexUpdater = new SlimDX.Direct3D10.Texture2D(Game.gameClass.GetDevice(), desc); normalData = normalTexUpdater.Map(0, D3D10.MapMode.Write, D3D10.MapFlags.DoNotWait); normalTexUpdater.Unmap(0); } // LoadTextureArray(file); //setting up vertices and creating vertex buffer LoadVertexInfo(); CreateVertexBuffer(); //constant buffer variables effect.GetVariableByName("mapSize").AsScalar().Set(Globals.mapSize); using(D3D10.ShaderResourceView normalView=new D3D10.ShaderResourceView(Game.gameClass.GetDevice(),normalTexture)) effect.GetVariableByName("normalMap").AsResource().SetResource(normalView); // using (D3D10.ShaderResourceView texturesView = new D3D10.ShaderResourceView(Game.gameClass.GetDevice(), textures)) // effect.GetVariableByName("textures").AsResource().SetResource(texturesView); orientations=effect.GetVariableByName("orientations").AsVector(); // effect.GetVariableByName("texCoordMul").AsScalar().Set(TextureInfo.texCoordMul); heightMul = effect.GetVariableByName("heightMul").AsScalar(); heightMul.Set(Globals.heightMultiplier); //handles edit mode if (Game.gameClass.GetEngineState() != EngineState.play) { techniqueEdit = effect.GetTechniqueByName("Edit"); passEdit = techniqueEdit.GetPassByIndex(0); mousePick = effect.GetVariableByName("mousePick").AsVector(); pickOptions = effect.GetVariableByName("pickOpt").AsVector(); } Globals.SetMap(map); }