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); } } }
public Texture( D3D10.Device device, int width, int height, DXGI.Format format, D3D10.ResourceUsage usage, int miplevels ) { D3D10.Texture2DDescription desc = new D3D10.Texture2DDescription(); desc.Width = width; desc.Height = height; D3D10.BindFlags bindflags = D3D10.BindFlags.ShaderResource; D3D10.ResourceOptionFlags optionflags = D3D10.ResourceOptionFlags.None; if( miplevels != 1 ) { bindflags |= D3D10.BindFlags.RenderTarget; optionflags |= D3D10.ResourceOptionFlags.GenerateMipMaps; } desc.ArraySize = 1; desc.BindFlags = bindflags; desc.CpuAccessFlags = D3D10.CpuAccessFlags.None; desc.Format = format; desc.MipLevels = miplevels; desc.OptionFlags = optionflags; desc.SampleDescription = new SlimDX.DXGI.SampleDescription( 1, 0 ); desc.Usage = usage; Create( device, desc ); }
private Texture2D CreateTexture(int width, int height, bool multiSampling) { var description = new SlimDX.Direct3D10.Texture2DDescription(); description.ArraySize = 1; description.BindFlags = SlimDX.Direct3D10.BindFlags.RenderTarget | SlimDX.Direct3D10.BindFlags.ShaderResource; description.CpuAccessFlags = CpuAccessFlags.None; description.Format = Format.B8G8R8A8_UNorm; description.MipLevels = 1; //description.MiscellaneousResourceOptions = D3D10.MiscellaneousResourceOptions.Shared; // Multi-sample anti-aliasing //description.MiscellaneousResourceOptions = D3D10.MiscellaneousResourceOptions.Shared; int count; if (multiSampling) { count = 8; } else { count = 1; } int quality = device.CheckMultisampleQualityLevels(description.Format, count); if (count == 1) { quality = 1; } // Multi-sample anti-aliasing SampleDescription sampleDesc = new SampleDescription(count, 0); description.SampleDescription = sampleDesc; RasterizerStateDescription rastDesc = new RasterizerStateDescription(); rastDesc.CullMode = CullMode.Back; rastDesc.FillMode = FillMode.Solid; rastDesc.IsMultisampleEnabled = false; rastDesc.IsAntialiasedLineEnabled = false; //rastDesc.DepthBias = 0; //rastDesc.DepthBiasClamp = 0; //rastDesc.IsDepthClipEnabled = true; //rastDesc.IsFrontCounterclockwise = false; //rastDesc.IsScissorEnabled = true; //rastDesc.SlopeScaledDepthBias = 0; device.Rasterizer.State = RasterizerState.FromDescription(device, rastDesc); description.Usage = ResourceUsage.Default; description.OptionFlags = ResourceOptionFlags.Shared; description.Height = (int)height; description.Width = (int)width; return(new Texture2D(device, description)); }
private void CreateStaging() { if (_staging == null) { D3D.Texture2DDescription desc = _backBuffer.Description; desc.BindFlags = D3D.BindFlags.None; desc.CpuAccessFlags = D3D.CpuAccessFlags.Write | D3D.CpuAccessFlags.Read; desc.Usage = D3D.ResourceUsage.Staging; _staging = new D3D.Texture2D(_graphicsDevice, desc); //Add to tracker _renderer.Resources.AddTrackedObject(_staging.ComPointer, this); } }
public WriteTexture( D3D10.Device device, int width, int height, DXGI.Format format ) { D3D10.Texture2DDescription desc = new D3D10.Texture2DDescription(); desc.Width = width; desc.Height = height; desc.ArraySize = 1; desc.BindFlags = D3D10.BindFlags.None; desc.CpuAccessFlags = D3D10.CpuAccessFlags.Write; desc.Format = format; desc.MipLevels = 1; desc.OptionFlags = D3D10.ResourceOptionFlags.None; desc.SampleDescription = new SlimDX.DXGI.SampleDescription( 1, 0 ); desc.Usage = D3D10.ResourceUsage.Staging; Resource = new D3D10.Texture2D( device, desc ); }
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 StagingTexturePool( D3D10.Device device, int width, int height, DXGI.Format format, int count, D3D10.CpuAccessFlags cpuaccess ) { D3D10.Texture2DDescription desc = new D3D10.Texture2DDescription(); desc.Width = width; desc.Height = height; desc.ArraySize = 1; desc.BindFlags = D3D10.BindFlags.None; desc.CpuAccessFlags = cpuaccess; desc.Format = format; desc.MipLevels = 1; desc.OptionFlags = D3D10.ResourceOptionFlags.None; desc.SampleDescription = new SlimDX.DXGI.SampleDescription( 1, 0 ); desc.Usage = D3D10.ResourceUsage.Staging; resources = new D3D10.Texture2D[count]; for( int i = 0; i < count; ++i ) resources[i] = new D3D10.Texture2D( device, desc ); }
public DepthBuffer( 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.DepthStencil; 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 ); View = new D3D10.DepthStencilView( device, Resource ); }
private void CreateStaging() { if (_staging == null) { D3D.Texture2DDescription desc = new D3D.Texture2DDescription(); desc.ArraySize = 6; desc.BindFlags = D3D.BindFlags.None; desc.CpuAccessFlags = D3D.CpuAccessFlags.Write | D3D.CpuAccessFlags.Read; desc.Format = D3D10Helper.ToD3DSurfaceFormat(base.Format); desc.Height = base.Size; desc.Width = base.Size; desc.MipLevels = _mipCount; desc.SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0); desc.Usage = D3D.ResourceUsage.Staging; desc.OptionFlags = D3D.ResourceOptionFlags.TextureCube; _staging = new D3D.Texture2D(_graphicsDevice, desc); //Add to tracker _renderer.Resources.AddTrackedObject(_staging.ComPointer, this); } }
public D3D10.Texture2D AddToTexture2D(String name, D3D10.Texture2D file, int nr ,int maxTextures) { D3D10.Texture2D temp; if (textures.ContainsKey(name)) temp = textures[name]; else { D3D10.Texture2DDescription desc = new SlimDX.Direct3D10.Texture2DDescription(); desc.ArraySize = maxTextures; desc.BindFlags = D3D10.BindFlags.ShaderResource; desc.CpuAccessFlags = D3D10.CpuAccessFlags.None; desc.Format = file.Description.Format; desc.Height = file.Description.Height; desc.Width = file.Description.Width; desc.MipLevels = file.Description.MipLevels; desc.OptionFlags = D3D10.ResourceOptionFlags.None; SlimDX.DXGI.SampleDescription sampleDesc = new SlimDX.DXGI.SampleDescription(); sampleDesc.Count = 1; sampleDesc.Quality = 0; desc.SampleDescription = sampleDesc; desc.Usage = D3D10.ResourceUsage.Default; temp = new SlimDX.Direct3D10.Texture2D(Game.gameClass.GetDevice(), desc); textures.Add(name, temp); } D3D10.ResourceRegion region = new SlimDX.Direct3D10.ResourceRegion(); region.Back = 1; region.Front = 0; region.Left = region.Top = 0; region.Right = file.Description.Width; region.Bottom = file.Description.Height; for (int i = 0, q = 1; i < file.Description.MipLevels; i++, q *= 2) { region.Right /= q; region.Bottom /= q; Game.gameClass.GetDevice().CopySubresourceRegion(file, i, region, temp, i + (nr * file.Description.MipLevels), 0, 0, 0); } return temp; }
protected override D3D.Texture2DDescription CreateDescription(int width, int height) { D3D.Texture2DDescription texDesc = new D3D.Texture2DDescription() { ArraySize = 1, MipLevels = 1, SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0), Format = format, CpuAccessFlags = D3D.CpuAccessFlags.Write, OptionFlags = D3D.ResourceOptionFlags.None, BindFlags = D3D.BindFlags.ShaderResource, Usage = D3D.ResourceUsage.Dynamic, Height = height, Width = width }; return texDesc; }
/// <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 void SetSize(int width, int height) { if (DepthBuffer != null) DepthBuffer.Dispose(); if (DepthBufferView != null) DepthBufferView.Dispose(); if (RenderTarget != null) RenderTarget.Dispose(); SwapChain.ResizeBuffers(1, width, height, DXGI.Format.R8G8B8A8_UNorm, DXGI.SwapChainFlags.None); RenderTarget = new Texturing.RenderTarget(this, width, height); D3D.Texture2DDescription depthbufferdesc = new D3D.Texture2DDescription() { Width = width, Height = height, MipLevels = 1, ArraySize = 1, Format = SlimDX.DXGI.Format.D24_UNorm_S8_UInt, SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0), Usage = D3D.ResourceUsage.Default, BindFlags = D3D.BindFlags.DepthStencil, CpuAccessFlags = D3D.CpuAccessFlags.None, OptionFlags = D3D.ResourceOptionFlags.None }; DepthBuffer = new D3D.Texture2D(Device, depthbufferdesc); DepthBufferView = new D3D.DepthStencilView(Device, DepthBuffer); Viewport = new D3D.Viewport() { X = 0, Y = 0, Width = width, Height = height, MinZ = 0.0f, MaxZ = 1.0f }; Device.Rasterizer.SetViewports(Viewport); SetOutputTargets(); }
private void CreateDepthStencil() { DXGI.SampleDescription sampleDesc = new SlimDX.DXGI.SampleDescription(); sampleDesc.Count = 1; sampleDesc.Quality = 0; D3D10.Texture2DDescription texDesc = new SlimDX.Direct3D10.Texture2DDescription(); texDesc.Width = width; texDesc.Height = height; texDesc.MipLevels = 1; texDesc.ArraySize = 1; texDesc.BindFlags = D3D10.BindFlags.DepthStencil; texDesc.CpuAccessFlags = D3D10.CpuAccessFlags.None; texDesc.Format = DXGI.Format.D32_Float; texDesc.SampleDescription = sampleDesc; texDesc.Usage = D3D10.ResourceUsage.Default; texDesc.OptionFlags = D3D10.ResourceOptionFlags.None; D3D10.DepthStencilViewDescription stencilViewDesc = new SlimDX.Direct3D10.DepthStencilViewDescription(); stencilViewDesc.Dimension = D3D10.DepthStencilViewDimension.Texture2D; stencilViewDesc.Format = texDesc.Format; stencilViewDesc.MipSlice = 0; stencilViewDesc.FirstArraySlice = 0; stencilViewDesc.ArraySize = 1; using (D3D10.Texture2D stencilTex = new SlimDX.Direct3D10.Texture2D(device, texDesc)) { depthStencilView = new SlimDX.Direct3D10.DepthStencilView(device, stencilTex,stencilViewDesc); } }
/// <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); } } }
private Texture2D CreateTexture(int width, int height, bool multiSampling) { var description = new SlimDX.Direct3D10.Texture2DDescription(); description.ArraySize = 1; description.BindFlags = SlimDX.Direct3D10.BindFlags.RenderTarget | SlimDX.Direct3D10.BindFlags.ShaderResource; description.CpuAccessFlags = CpuAccessFlags.None; description.Format = Format.B8G8R8A8_UNorm; description.MipLevels = 1; //description.MiscellaneousResourceOptions = D3D10.MiscellaneousResourceOptions.Shared; // Multi-sample anti-aliasing //description.MiscellaneousResourceOptions = D3D10.MiscellaneousResourceOptions.Shared; int count; if (multiSampling) count = 8; else count = 1; int quality = device.CheckMultisampleQualityLevels(description.Format, count); if (count == 1) quality = 1; // Multi-sample anti-aliasing SampleDescription sampleDesc = new SampleDescription(count, 0); description.SampleDescription = sampleDesc; RasterizerStateDescription rastDesc = new RasterizerStateDescription(); rastDesc.CullMode = CullMode.Back; rastDesc.FillMode = FillMode.Solid; rastDesc.IsMultisampleEnabled = false; rastDesc.IsAntialiasedLineEnabled = false; //rastDesc.DepthBias = 0; //rastDesc.DepthBiasClamp = 0; //rastDesc.IsDepthClipEnabled = true; //rastDesc.IsFrontCounterclockwise = false; //rastDesc.IsScissorEnabled = true; //rastDesc.SlopeScaledDepthBias = 0; device.Rasterizer.State = RasterizerState.FromDescription(device, rastDesc); description.Usage = ResourceUsage.Default; description.OptionFlags = ResourceOptionFlags.Shared; description.Height = (int)height; description.Width = (int)width; return new Texture2D(device, description); }
//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); }
/// <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); } } }