public void PostProcess() { int numberOfEffects = effectHandler.NumberOfEffects; if (numberOfEffects < 1) { // TODO: Implement some fallback Logger.Write(LogType.Error, "No post effects, Can not copy to backbuffer"); } for (int i = 0; i < effectHandler.NumberOfEffects; ++i) { D3D11.ShaderResourceView sourceRenderTarget = renderTargetHandler.GetRenderTargetResourceView(); D3D11.ShaderResourceView sourceDepthStencil = renderTargetHandler.GetDepthStencilResourceView(); D3D11.RenderTargetView destRenderTarget; // Only One effect Left, use Backbuffer if (i == effectHandler.NumberOfEffects - 1) { destRenderTarget = deviceResources.BackBufferRTV; } else { destRenderTarget = renderTargetHandler.GetRenderTargetView(); } ApplyPostEffect(sourceRenderTarget, sourceDepthStencil, destRenderTarget, effectHandler.GetEffectFromStack(i)); renderTargetHandler.Swap(); } renderTargetHandler.ResetToDefault(); }
internal MyTextureArray(TexId[] mergeList) { var srcDesc = MyTextures.GetView(mergeList[0]).Description; Size = MyTextures.GetSize(mergeList[0]); ArrayLen = mergeList.Length; Texture2DDescription desc = new Texture2DDescription(); desc.ArraySize = ArrayLen; desc.BindFlags = BindFlags.ShaderResource; desc.CpuAccessFlags = CpuAccessFlags.None; desc.Format = srcDesc.Format; desc.Height = (int)Size.Y; desc.Width = (int)Size.X; desc.MipLevels = 0; desc.SampleDescription.Count = 1; desc.SampleDescription.Quality = 0; desc.Usage = ResourceUsage.Default; m_resource = new Texture2D(MyRender11.Device, desc); // foreach mip var mipmaps = (int)Math.Log(Size.X, 2) + 1; for (int a = 0; a < ArrayLen; a++) { for (int m = 0; m < mipmaps; m++) { MyRender11.Context.CopySubresourceRegion(MyTextures.Textures.Data[mergeList[a].Index].Resource, Resource.CalculateSubResourceIndex(m, 0, mipmaps), null, Resource, Resource.CalculateSubResourceIndex(m, a, mipmaps)); } } ShaderView = new ShaderResourceView(MyRender11.Device, Resource); }
protected override void CreateDeviceDependentResources() { RemoveAndDispose(ref vertexBuffer); RemoveAndDispose(ref indexBuffer); // Retrieve our SharpDX.Direct3D11.Device1 instance var device = this.DeviceManager.Direct3DDevice; // Load texture (a DDS cube map) textureView = ShaderResourceView.FromFile(device, "CubeMap.dds"); // Create our sampler state samplerState = new SamplerState(device, new SamplerStateDescription() { AddressU = TextureAddressMode.Clamp, AddressV = TextureAddressMode.Clamp, AddressW = TextureAddressMode.Clamp, BorderColor = new Color4(0, 0, 0, 0), ComparisonFunction = Comparison.Never, Filter = Filter.MinMagMipLinear, MaximumLod = 9, // Our cube map has 10 mip map levels (0-9) MinimumLod = 0, MipLodBias = 0.0f }); Vertex[] vertices; int[] indices; GeometricPrimitives.GenerateSphere(out vertices, out indices, Color.Gray); vertexBuffer = ToDispose(Buffer.Create(device, BindFlags.VertexBuffer, vertices)); vertexBinding = new VertexBufferBinding(vertexBuffer, Utilities.SizeOf<Vertex>(), 0); indexBuffer = ToDispose(Buffer.Create(device, BindFlags.IndexBuffer, indices)); totalVertexCount = indices.Length; }
void ResizeSurface() { Math.Rectangle newBounds = surface.Bounds; SurfaceSize = newBounds.Size; SurfaceBounds = newBounds; deviceContext.OutputMerger.ResetTargets(); swapChain.ResizeBuffers(0, (int)newBounds.Width, (int)newBounds.Height, DXGI.Format.R8G8B8A8_UNorm, DXGI.SwapChainFlags.None); deviceContext.Rasterizer.SetViewport(0, 0, newBounds.Width, newBounds.Height); viewMatrix = Matrix.Transpose(Matrix.Scaling(2f / newBounds.Width, -2f / newBounds.Height, 1)); viewMatrix *= Matrix.Transpose(Matrix.Translation(-newBounds.Width / 2f, -newBounds.Height / 2f, 0)); UpdateMatrixBuffer(); depthStencilView?.Dispose(); depthStencilBuffer?.Dispose(); surfaceTarget?.Dispose(); surfaceView?.Dispose(); surfaceTexture?.Dispose(); depthStencilBuffer = device.CreateDepthStencilBuffer((int)newBounds.Width, (int)newBounds.Height, sampleDescription, out depthStencilView); surfaceTexture = device.CreateSurface((int)newBounds.Width, (int)newBounds.Height, sampleDescription, out surfaceTarget); deviceContext.OutputMerger.SetTargets(depthStencilView, surfaceTarget); surfaceView = new D3D11.ShaderResourceView(device, surfaceTexture); }
/// <summary> /// /// </summary> /// <param name="device"></param> internal protected ShaderResource( GraphicsDevice device, ShaderResourceView srv, int w, int h, int d ) : base(device) { this.SRV = srv; this.Width = w; this.Height = h; this.Depth = d; }
static public ShaderResourceView FromFile(Device device, string path, out Texture2D texture) { var srv = (SharpDX.Direct3D11.ShaderResourceView)null; using (var image = new System.Drawing.Bitmap(path)) { var imageRect = new System.Drawing.Rectangle(0, 0, image.Width, image.Height); using (var bitmap = image.Clone(imageRect, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { var locks = bitmap.LockBits(imageRect, System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat); var dataBox = new[] { new SharpDX.DataBox(locks.Scan0, bitmap.Width * 4, bitmap.Height) }; var textureDesc = new Texture2DDescription() { ArraySize = 1, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm, Height = bitmap.Height, Width = bitmap.Width, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0), Usage = ResourceUsage.Default }; texture = new Texture2D(device, textureDesc, dataBox); bitmap.UnlockBits(locks); srv = new SharpDX.Direct3D11.ShaderResourceView(device, texture); } } return(srv); }
public void ApplyPostEffect( D3D11.ShaderResourceView sourceRenderTarget, D3D11.ShaderResourceView sourceDepthStencil, D3D11.RenderTargetView destRenderTarget, PostProcessing.PostEffect effect) { D3D11.DeviceContext deviceContext = deviceResources.DeviceContext; // No rendering directly to DepthStencil deviceContext.OutputMerger.SetRenderTargets(null, destRenderTarget); deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip; deviceContext.InputAssembler.InputLayout = effect.Shader.InputLayout; deviceContext.VertexShader.Set(effect.Shader.VertexShader); deviceContext.PixelShader.Set(effect.Shader.PixelShader); deviceContext.PixelShader.SetShaderResource(0, sourceRenderTarget); deviceContext.PixelShader.SetShaderResource(1, sourceDepthStencil); deviceContext.PixelShader.SetSampler(0, sampler); deviceContext.Draw(4, 0); // Reset deviceContext.OutputMerger.SetRenderTargets( renderTargetHandler.GetDepthStencilView(), renderTargetHandler.GetRenderTargetView() ); }
/// <summary> /// Creates texture /// </summary> /// <param name="device"></param> public VolumeRWTexture(GraphicsDevice device, int width, int height, int depth, ColorFormat format, bool mips) : base(device) { this.Width = width; this.Height = height; this.Depth = depth; this.format = format; this.mipCount = mips ? ShaderResource.CalculateMipLevels(Width, Height, Depth) : 1; var texDesc = new Texture3DDescription(); texDesc.BindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess; texDesc.CpuAccessFlags = CpuAccessFlags.None; texDesc.Format = Converter.Convert(format); texDesc.Height = Height; texDesc.MipLevels = mipCount; texDesc.OptionFlags = ResourceOptionFlags.None; texDesc.Usage = ResourceUsage.Default; texDesc.Width = Width; texDesc.Depth = Depth; var uavDesc = new UnorderedAccessViewDescription(); uavDesc.Format = Converter.Convert(format); uavDesc.Dimension = UnorderedAccessViewDimension.Texture3D; uavDesc.Texture3D.FirstWSlice = 0; uavDesc.Texture3D.MipSlice = 0; uavDesc.Texture3D.WSize = depth; tex3D = new D3D.Texture3D(device.Device, texDesc); SRV = new D3D.ShaderResourceView(device.Device, tex3D); uav = new UnorderedAccessView(device.Device, tex3D, uavDesc); }
protected override void InitializeInternal() { var sourceTextures = _textures.Select(t => { var view = t.ShaderResourceView; if(view == null) throw new InvalidOperationException(string.Format("Texture array cannot be created because source texture '{0}' is not initialized", t.Id)); return view.Resource.QueryInterface<Texture2D>(); }).ToArray(); var descr = sourceTextures[0].Description; descr.ArraySize = _textures.Length; _textureArray = new Texture2D(DeviceManager.Device, descr); ShaderResourceView = new ShaderResourceView(DeviceManager.Device, _textureArray); var mipLevels = descr.MipLevels; for(var i = 0; i < mipLevels; i++) { for(var j = 0; j < _textures.Length; j++) { var texture = sourceTextures[j]; DeviceManager.Context.CopySubresourceRegion(texture, i, null, _textureArray, mipLevels * j + i); } } }
public Water(IContext context, IEnumerable<SeaProvince> provinces) { _bumpMapTexture = context.TextureManager.Create("OceanWater.png").TextureResource; _borderTexture = context.TextureManager.Create("Border.png").TextureResource; _shader = context.Shaders.Get<WaterShader>(); BuildBuffers(context, provinces); }
/// <summary> /// /// </summary> /// <param name="device"></param> /// <param name="size"></param> /// <param name="count"></param> /// <param name="format"></param> /// <param name="mips"></param> public TextureCubeArray ( GraphicsDevice device, int size, int count, ColorFormat format, bool mips ) : base(device) { if (count>2048/6) { throw new GraphicsException("Too much elements in texture array"); } this.Width = size; this.Depth = 1; this.Height = size; this.MipCount = mips ? ShaderResource.CalculateMipLevels(Width,Height) : 1; var texDesc = new Texture2DDescription(); texDesc.ArraySize = 6 * count; texDesc.BindFlags = BindFlags.ShaderResource; texDesc.CpuAccessFlags = CpuAccessFlags.None; texDesc.Format = MakeTypeless( Converter.Convert( format ) ); texDesc.Height = Height; texDesc.MipLevels = 0; texDesc.OptionFlags = ResourceOptionFlags.TextureCube; texDesc.SampleDescription.Count = 1; texDesc.SampleDescription.Quality = 0; texDesc.Usage = ResourceUsage.Default; texDesc.Width = Width; texCubeArray = new D3D.Texture2D( device.Device, texDesc ); SRV = new ShaderResourceView( device.Device, texCubeArray ); }
public RenderTexture(Device device, Vector2I screenSize) { var textureDesc = new Texture2DDescription() { Width = screenSize.X, Height = screenSize.Y, MipLevels = 1, ArraySize = 1, Format = Format.R32G32B32A32_Float, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None }; _renderTargetTexture = new Texture2D(device, textureDesc); _renderTargetView = new RenderTargetView(device, _renderTargetTexture, new RenderTargetViewDescription { Format = textureDesc.Format, Dimension = RenderTargetViewDimension.Texture2D, Texture2D = {MipSlice = 0}, }); // Create the render target view. ShaderResourceView = new ShaderResourceView(device, _renderTargetTexture, new ShaderResourceViewDescription { Format = textureDesc.Format, Dimension = ShaderResourceViewDimension.Texture2D, Texture2D = { MipLevels = 1, MostDetailedMip = 0 }, }); }
/// <summary> /// Loads the resource. /// </summary> protected override void LoadResourceInternal(EngineDevice device, ResourceDictionary resources) { if (m_texture == null) { #if DESKTOP // Load from GDI bitmap if (m_bitmap != null) { //Get source bitmap Bitmap bitmap = m_bitmap; m_texture = GraphicsHelper.LoadTextureFromBitmap(device, bitmap, 0); //Create the view targeting the texture m_textureView = new D3D11.ShaderResourceView(device.DeviceD3D11_1, m_texture); return; } #endif // Load from mapped texture if (m_mappedTexture != null) { m_texture = GraphicsHelper.LoadTexture2DFromMappedTexture(device, m_mappedTexture); m_textureView = new D3D11.ShaderResourceView(device.DeviceD3D11_1, m_texture); return; } throw new SeeingSharpException("Unable to load BitmapTextureResource: No resource loader implemented!"); } }
public void Draw(Matrix worldViewProjMatrix, D3D11.Texture2D texture) { // Set the shaders to use for the draw operation d3dDeviceContext.VertexShader.Set(vertexShader); d3dDeviceContext.PixelShader.Set(pixelShader); // Set the primitive topology to triangle list d3dDeviceContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList; // Set the input layout of the vertices d3dDeviceContext.InputAssembler.InputLayout = inputLayout; // Bind the texture resource to the pixel shader var textureView = new D3D11.ShaderResourceView(d3dDevice, texture); d3dDeviceContext.PixelShader.SetShaderResource(0, textureView); d3dDeviceContext.PixelShader.SetSampler(0, samplerState); textureView.Dispose(); // Pass the world view projection matrix to the vertex shader d3dDeviceContext.VertexShader.SetConstantBuffer(0, worldViewProjBuffer); d3dDeviceContext.UpdateSubresource(ref worldViewProjMatrix, worldViewProjBuffer); // Draw the rectangle d3dDeviceContext.InputAssembler.SetVertexBuffers(0, new D3D11.VertexBufferBinding(vertexBuffer, Utilities.SizeOf <VertexXYUV>(), 0)); d3dDeviceContext.Draw(numVertices, 0); }
public Bitmap(Device device, ShaderResourceView texture, Vector2I screenSize, Vector2I size, float depth = 0.0f) { Texture = texture; ScreenSize = screenSize; Size = size; _changed = true; Depth = depth; VertexCount = 4; IndexCount = 6; _vertices = new TranslateShader.Vertex[VertexCount]; UInt32[] indices = {0, 1, 2, 0, 3, 1}; VertexBuffer = Buffer.Create(device, _vertices, new BufferDescription { Usage = ResourceUsage.Dynamic, SizeInBytes = Utilities.SizeOf<TranslateShader.Vertex>() * VertexCount, BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None, StructureByteStride = 0 }); IndexBuffer = Buffer.Create(device, BindFlags.IndexBuffer, indices); }
/// <summary> /// Creates texture /// </summary> /// <param name="device"></param> public VolumeRWTexture ( GraphicsDevice device, int width, int height, int depth, ColorFormat format, bool mips ) : base( device ) { this.Width = width; this.Height = height; this.Depth = depth; this.format = format; this.mipCount = mips ? ShaderResource.CalculateMipLevels(Width,Height,Depth) : 1; var texDesc = new Texture3DDescription(); texDesc.BindFlags = BindFlags.ShaderResource | BindFlags.UnorderedAccess; texDesc.CpuAccessFlags = CpuAccessFlags.None; texDesc.Format = Converter.Convert( format ); texDesc.Height = Height; texDesc.MipLevels = mipCount; texDesc.OptionFlags = ResourceOptionFlags.None; texDesc.Usage = ResourceUsage.Default; texDesc.Width = Width; texDesc.Depth = Depth; var uavDesc = new UnorderedAccessViewDescription(); uavDesc.Format = Converter.Convert( format ); uavDesc.Dimension = UnorderedAccessViewDimension.Texture3D; uavDesc.Texture3D.FirstWSlice = 0; uavDesc.Texture3D.MipSlice = 0; uavDesc.Texture3D.WSize = depth; tex3D = new D3D.Texture3D( device.Device, texDesc ); SRV = new D3D.ShaderResourceView( device.Device, tex3D ); uav = new UnorderedAccessView( device.Device, tex3D, uavDesc ); }
/// <summary> /// Creates a texture from a file. /// Allowed file types are BMP, PNG, JPG and DDS. /// </summary> /// <param name="fileName">A path to a valid texture file.</param> /// <param name="loadAsync">Optional. Pass true if you want the texture to be loaded asynchronously. /// This can reduce frame drops but the texture might not be available immediately (see <see cref="Texture.IsReady"/> property).</param> /// <exception cref="InvalidOperationException">No renderer is registered.</exception> public Texture(string fileName, bool loadAsync = false) { IsAsync = loadAsync; var file = new FileInfo(fileName); Renderer renderer = GameEngine.TryQueryComponent<Renderer>(); if (renderer == null) throw new InvalidOperationException("A renderer must be registered before a texture can be created."); if (loadAsync) { Task.Run(() => renderer.CreateTexture(file.FullName)) .ContinueWith((t) => { var result = t.Result; texture = result.Texture; ResourceView = result.ResourceView; Width = texture.Width; Height = texture.Height; isReady = true; }); } else { var result = renderer.CreateTexture(file.FullName); texture = result.Texture; ResourceView = result.ResourceView; Width = texture.Width; Height = texture.Height; isReady = true; } }
/// <summary> /// Create texture inplace with new parameters. /// Old texture will be completely discarded /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="format"></param> /// <param name="mips"></param> void CreateFromFile(byte[] fileInMemory, string name, bool forceSRgb) { IntPtr resource = new IntPtr(0); IntPtr resourceView = new IntPtr(0); bool result; lock (device.DeviceContext) { if ((char)fileInMemory[0] == 'D' && (char)fileInMemory[1] == 'D' && (char)fileInMemory[2] == 'S' && (char)fileInMemory[3] == ' ') { result = DdsLoader.CreateTextureFromMemory(device.Device.NativePointer, fileInMemory, forceSRgb, ref resource, ref resourceView); } else { result = WicLoader.CreateTextureFromMemory(device.Device.NativePointer, fileInMemory, forceSRgb, ref resource, ref resourceView); } if (!result) { throw new GraphicsException("Failed to load texture: " + name); } tex2D = new D3D.Texture2D(resource); SRV = new D3D.ShaderResourceView(resourceView); } Width = tex2D.Description.Width; Height = tex2D.Description.Height; Depth = 1; mipCount = tex2D.Description.MipLevels; format = Converter.Convert(tex2D.Description.Format); }
private void BuildTexture(int width, int height) { // TODO: This should probably be a dynamic texture, with updates performed via mapping. Work it out. texture = new D3D11.Texture2D(DxHandler.Device, new D3D11.Texture2DDescription() { Width = width, Height = height, MipLevels = 1, ArraySize = 1, Format = DXGI.Format.B8G8R8A8_UNorm, SampleDescription = new DXGI.SampleDescription(1, 0), Usage = D3D11.ResourceUsage.Default, //Usage = D3D11.ResourceUsage.Dynamic, BindFlags = D3D11.BindFlags.ShaderResource, CpuAccessFlags = D3D11.CpuAccessFlags.None, //CpuAccessFlags = D3D11.CpuAccessFlags.Write, OptionFlags = D3D11.ResourceOptionFlags.None, }); var view = new D3D11.ShaderResourceView(DxHandler.Device, texture, new D3D11.ShaderResourceViewDescription() { Format = texture.Description.Format, Dimension = D3D.ShaderResourceViewDimension.Texture2D, Texture2D = { MipLevels = texture.Description.MipLevels }, }); textureWrap = new D3DTextureWrap(view, texture.Description.Width, texture.Description.Height); }
/// <summary> /// for unit testing purposes. Converts naked srv to TextureArray2D /// </summary> internal Texture3D ConvertFromRaw3D(SharpDX.Direct3D11.ShaderResourceView srv, Size3 size, SharpDX.DXGI.Format dstFormat) { var res = new Texture3D(1, size, dstFormat, false); var dev = DirectX.Device.Get(); quad.Bind(true); dev.Pixel.Set(convert3D.Pixel); dev.Pixel.SetShaderResource(0, srv); cbuffer.SetData(new LayerLevelOffsetData { Layer = 0, Level = 0, Xoffset = 0, Yoffset = 0, Multiplier = 1.0f }); dev.Pixel.SetConstantBuffer(0, cbuffer.Handle); dev.OutputMerger.SetRenderTargets(res.GetRtView(0, 0)); dev.SetViewScissors(size.Width, size.Height); dev.DrawFullscreenTriangle(size.Depth); // remove bindings dev.Pixel.SetShaderResource(0, null); dev.OutputMerger.SetRenderTargets((RenderTargetView)null); quad.Unbind(); return(res); }
public void Run(D3D11.ShaderResourceView srcSRV, D3D11.ShaderResourceView depthSRV, D3D11.RenderTargetView dstRTV, int width, int height, float time) { Viewport viewport = new Viewport(0, 0, width, height); //Viewport viewport = new Viewport(-width/2, -width/2, width*2, height*4); int positionSize = Utilities.SizeOf <Vector3>(); int texcoordSize = Utilities.SizeOf <Vector2>(); int vertexCount = trianglePositionVertexBuffer.Description.SizeInBytes / positionSize; deviceContext.InputAssembler.SetVertexBuffers(0, new D3D11.VertexBufferBinding(trianglePositionVertexBuffer, positionSize, 0)); deviceContext.InputAssembler.SetVertexBuffers(1, new D3D11.VertexBufferBinding(triangleTexcoordVertexBuffer, texcoordSize, 0)); deviceContext.InputAssembler.InputLayout = inputLayout; deviceContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList; deviceContext.VertexShader.Set(vertexShader); deviceContext.PixelShader.Set(pixelShader); deviceContext.PixelShader.SetSampler(0, samplerState); deviceContext.PixelShader.SetShaderResource(0, srcSRV); deviceContext.PixelShader.SetShaderResource(1, depthSRV); deviceContext.Rasterizer.SetViewport(viewport); deviceContext.OutputMerger.SetRenderTargets(dstRTV); UpdateConstantBuffer(time); deviceContext.Draw(vertexCount, 0); deviceContext.OutputMerger.SetRenderTargets(null, (D3D11.RenderTargetView)null); }
public RenderViews(D3D11.RenderTargetView rtv, D3D11.DepthStencilView dsv, D3D11.ShaderResourceView rtv_srvt, D3D11.ShaderResourceView dsv_srvt) : this(rtv, dsv) { this.RT_SRVT = rtv_srvt; this.DS_SRVT = dsv_srvt; }
public FleetMoveOrderRenderer(IContext context) { _shader = context.Shaders.Get<PathShader>(); _pathTexture = context.TextureManager.Create("Path.png").TextureResource; foreach (Fleet fleet in context.World.FleetManager.Fleets.Where(f=>f.HasMoveOrder)) NewMoveOrder(context, fleet); context.NotificationResolver.NewFleetMoveOrder += f => NewMoveOrder(context, f); }
/// <summary> /// Constructor /// </summary> /// <param name="device">Direct3D11 Device</param> public BodyCameraPositionBuffer(Device device) { if (device == null) throw new ArgumentNullException("device"); this.buffer = new SharpDX.Direct3D11.Buffer(device, JointBufferDescriptor.CameraSpacePositionBuffer); this.shaderView = new ShaderResourceView(device, this.buffer); }
/// <summary> /// Unloads the resource. /// </summary> protected override void UnloadResourceInternal(EngineDevice device, ResourceDictionary resources) { if (m_texture != null) { m_textureView = GraphicsHelper.DisposeObject(m_textureView); m_texture = GraphicsHelper.DisposeObject(m_texture); } }
/// <summary> /// Bind all the sub resources to view /// </summary> /// <param name="view"></param> public void SetViewsToResources(ShaderResourceView view) { // bind all the sub-resources with the same view foreach (var resource in ListWithResourceVariables) { resource.resource.SetResource(view); } }
/// <summary> /// Creates a dynamic color texture, allocates GPU resources /// </summary> /// <param name="device">Direct3D Device</param> public DynamicColorRGBATexture(Device device) { if (device == null) throw new ArgumentNullException("device"); this.texture = new Texture2D(device, ColorTextureDescriptors.DynamicRGBAResource); this.rawView = new ShaderResourceView(device,this.texture); }
void SetTextureInner(D3D11.ShaderResourceView texture) { if (texture != currentTexture) { currentTexture = texture; deviceContext.PixelShader.SetShaderResource(0, texture); } }
/// <summary> /// Creates a dynamic depth texture, allocates GPU resources /// </summary> /// <param name="device">Direct3D Device</param> public DynamicLongExposureInfraredTexture(Device device) { if (device == null) throw new ArgumentNullException("device"); this.texture = new Texture2D(device, InfraredTextureDescriptors.DynamicResource); this.shaderView = new ShaderResourceView(device, this.texture); }
/// <summary> /// Constructor /// </summary> /// <param name="device">Direct3D11 Device</param> public DynamicDepthToColorTexture(Device device) { if (device == null) throw new ArgumentNullException("device"); this.texture = new Texture2D(device, CoordinateMapTextureDescriptors.DynamicDepthToColor); this.shaderView = new ShaderResourceView(device, this.texture); }
public Shape(VertexBufferBinding vertexBinding, PrimitiveTopology topology, ShaderResourceView textureView, Style style, int vertexCount) { this.vertexBinding = vertexBinding; this.topology = topology; this.textureView = textureView; this.style = style; this.vertexCount = vertexCount; }
/// <summary> /// Unloads the resource. /// </summary> protected override void UnloadResourceInternal(EngineDevice device, ResourceDictionary resources) { m_textureView = GraphicsHelper.DisposeObject(m_textureView); m_texture = GraphicsHelper.DisposeObject(m_texture); m_isCubeTexture = false; m_isRenderTarget = false; }
/// <summary> /// Constructor /// </summary> /// <param name="device">Direct3D11 Device</param> public BodyJointStatusBuffer(Device device) { if (device == null) throw new ArgumentNullException("device"); this.buffer = new SharpDX.Direct3D11.Buffer(device, JointBufferDescriptor.DynamicBuffer(new BufferStride(4))); this.shaderView = new ShaderResourceView(device, this.buffer); }
public void Render(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView texture) { int stride = Utilities.SizeOf<VertexDefinition.PositionTexture>(); //Gets or sets the stride between vertex elements in the buffer (in bytes). deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(VertexBuffer, stride, 0)); deviceContext.InputAssembler.SetIndexBuffer(IndexBuffer, Format.R32_UInt, 0); deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; _shader.Render(deviceContext, IndexCount, worldMatrix, viewMatrix, projectionMatrix, texture ?? _texture); }
/// <summary> /// Creates render target /// </summary> /// <param name="rs"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="format"></param> public DepthStencilCube( GraphicsDevice device, DepthFormat format, int size, int samples, string debugName = "" ) : base(device) { bool msaa = samples > 1; CheckSamplesCount( samples ); SampleCount = samples; Format = format; SampleCount = samples; Width = size; Height = size; Depth = 1; var texDesc = new Texture2DDescription(); texDesc.Width = Width; texDesc.Height = Height; texDesc.ArraySize = 6; texDesc.BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource; texDesc.CpuAccessFlags = CpuAccessFlags.None; texDesc.Format = Converter.ConvertToTex( format ); texDesc.MipLevels = 1; texDesc.OptionFlags = ResourceOptionFlags.TextureCube; texDesc.SampleDescription = new DXGI.SampleDescription(samples, 0); texDesc.Usage = ResourceUsage.Default; texCube = new D3D.Texture2D( device.Device, texDesc ); var srvDesc = new ShaderResourceViewDescription(); srvDesc.Dimension = samples > 1 ? ShaderResourceViewDimension.Texture2DMultisampled : ShaderResourceViewDimension.Texture2D; srvDesc.Format = Converter.ConvertToSRV( format ); srvDesc.Texture2D.MostDetailedMip = 0; srvDesc.Texture2D.MipLevels = 1; SRV = new ShaderResourceView( device.Device, texCube ); // // Create surfaces : // surfaces = new DepthStencilSurface[ 6 ]; for ( int face=0; face<6; face++) { var rtvDesc = new DepthStencilViewDescription(); rtvDesc.Texture2DArray.MipSlice = 0; rtvDesc.Texture2DArray.FirstArraySlice = face; rtvDesc.Texture2DArray.ArraySize = 1; rtvDesc.Dimension = msaa ? DepthStencilViewDimension.Texture2DMultisampledArray : DepthStencilViewDimension.Texture2DArray; rtvDesc.Format = Converter.ConvertToDSV( format ); var dsv = new DepthStencilView( device.Device, texCube, rtvDesc ); int subResId = Resource.CalculateSubResourceIndex( 0, face, 1 ); surfaces[face] = new DepthStencilSurface( dsv, format, Width, Height, SampleCount ); } }
/// <summary> /// Create any device dependent resources here. /// This method will be called when the device is first /// initialized or recreated after being removed or reset. /// </summary> protected override void CreateDeviceDependentResources() { // Ensure that if already set the device resources // are correctly disposed of before recreating RemoveAndDispose(ref axisLinesVertices); // Retrieve our SharpDX.Direct3D11.Device1 instance var device = this.DeviceManager.Direct3DDevice; // Load texture textureView = ToDispose(ShaderResourceView.FromFile(device, "Texture.png")); // Create our sampler state samplerState = ToDispose(new SamplerState(device, new SamplerStateDescription() { AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, BorderColor = new Color4(0, 0, 0, 0), ComparisonFunction = Comparison.Never, Filter = Filter.MinMagMipLinear, MaximumAnisotropy = 16, MaximumLod = float.MaxValue, MinimumLod = 0, MipLodBias = 0.0f })); // Create xyz-axis arrows // X is Red, Y is Green, Z is Blue // The arrows point along the + for each axis axisLinesVertices = ToDispose(Buffer.Create(device, BindFlags.VertexBuffer, new[] { /* Vertex Position Texture UV */ // ~45x10 -1f, 0f, 0f, 1f, 0.1757f, 0.039f, // - x-axis 1f, 0f, 0f, 1f, 0.1757f, 0.039f, // + x-axis 0.9f, -0.05f, 0f, 1f, 0.1757f, 0.039f,// arrow head start 1f, 0f, 0f, 1f, 0.1757f, 0.039f, 0.9f, 0.05f, 0f, 1f, 0.1757f, 0.039f, 1f, 0f, 0f, 1f, 0.1757f, 0.039f, // arrow head end // ~135x35 0f, -1f, 0f, 1f, 0.5273f, 0.136f, // - y-axis 0f, 1f, 0f, 1f, 0.5273f, 0.136f, // + y-axis -0.05f, 0.9f, 0f, 1f, 0.5273f, 0.136f,// arrow head start 0f, 1f, 0f, 1f, 0.5273f, 0.136f, 0.05f, 0.9f, 0f, 1f, 0.5273f, 0.136f, 0f, 1f, 0f, 1f, 0.5273f, 0.136f, // arrow head end // ~220x250 0f, 0f, -1f, 1f, 0.859f, 0.976f, // - z-axis 0f, 0f, 1f, 1f, 0.859f, 0.976f, // + z-axis 0f, -0.05f, 0.9f, 1f, 0.859f, 0.976f,// arrow head start 0f, 0f, 1f, 1f, 0.859f, 0.976f, 0f, 0.05f, 0.9f, 1f, 0.859f, 0.976f, 0f, 0f, 1f, 1f, 0.859f, 0.976f, // arrow head end })); axisLinesBinding = new VertexBufferBinding(axisLinesVertices, Utilities.SizeOf<float>() * 6, 0); }
public WaveSolutionSwapChain(D3D11.ShaderResourceView currentSolutionSRV, D3D11.UnorderedAccessView currentSolutionUAV, D3D11.Buffer currentBuffer, D3D11.ShaderResourceView pastSolutionSRV, D3D11.UnorderedAccessView pastSolutionUAV, D3D11.Buffer pastBuffer) { this.currentSolutionSRV = currentSolutionSRV; this.pastSolutionSRV = pastSolutionSRV; this.currentSolutionUAV = currentSolutionUAV; this.pastSolutionUAV = pastSolutionUAV; this.currentBuffer = currentBuffer; this.pastBuffer = pastBuffer; }
internal WorldTerrain(IContext context) { _heightMap = context.TextureManager.Create("heightmap.bmp", "Data/Map/"); _normalMap = context.TextureManager.Create("normal.bmp", "Data/Map/").TextureResource; _provinceMap = context.TextureManager.Create("provinces.bmp", "Data/Map/").TextureResource; _terrainShader = context.Shaders.Get<WorldTerrainShader>(); BuildTerrainBuffers(context); BuildWaterBuffers(context); }
public virtual void Apply(DeviceContext context, ShaderResourceView source, RenderTargetView destination, float scale = 1f, float offset = 0f) { context.OutputMerger.SetTargets(destination); context.PixelShader.SetShaderResource(0, source); Texture2D tex2D = destination.ResourceAs<Texture2D>(); context.Rasterizer.SetViewport(0f, 0f, (float)tex2D.Description.Width, (float)tex2D.Description.Height, 0f, 1f); tex2D.Dispose(); ScreenQuad.Draw(context, scale, offset); }
public void Shutdown() { // Release the texture resource. if (TextureResource != null) { TextureResource.Dispose(); TextureResource = null; } }
/// <summary> /// Constructor /// </summary> /// <param name="device">Direct3D11 Device</param> /// <param name="maxFaceCount">Maximum body count</param> public DynamicHdFaceStructuredBuffer(Device device, int maxFaceCount) { if (device == null) throw new ArgumentNullException("device"); var desc = DescriptorUtils.DynamicStructuredBuffer(new BufferElementCount(maxFaceCount * (int)Microsoft.Kinect.Face.FaceModel.VertexCount), new BufferStride(12)); this.buffer = new SharpDX.Direct3D11.Buffer(device, desc); this.shaderView = new ShaderResourceView(device, this.buffer); }
/// <summary> /// Creates a dynamic depth texture, allocates GPU resources /// </summary> /// <param name="device">Direct3D Device</param> public DynamicDepthTexture(Device device) { if (device == null) throw new ArgumentNullException("device"); this.texture = new Texture2D(device, DepthTextureDescriptors.DynamicResource); this.rawView = new ShaderResourceView(device,this.texture, DepthTextureDescriptors.RawView); this.normalizedView = new ShaderResourceView(device,this.texture, DepthTextureDescriptors.NormalizedView); }
public DXImage(Device device, DeviceContext deviceContext): base("DXImage") { _device = device; _deviceContext = deviceContext; _tex = null; _texSRV = null; _texWidth = 0; _texHeight = 0; }
/// <summary> /// Constructor /// </summary> /// <param name="device">Direct3D11 Device</param> public AppendPointCloudBuffer(Device device) { if (device == null) throw new ArgumentNullException("device"); this.buffer = new SharpDX.Direct3D11.Buffer(device, PointCloudDescriptors.PositionBuffer); this.shaderView = new ShaderResourceView(device, this.buffer); this.unorderedView = new UnorderedAccessView(device, this.buffer, PointCloudDescriptors.AppendView); }
internal static void DisplayHistogram(RenderTargetView rtv, ShaderResourceView avgLumSrv) { RC.Context.PixelShader.SetShaderResources(0, m_histogram.ShaderView, avgLumSrv); RC.Context.PixelShader.Set(m_drawHistogram); RC.Context.OutputMerger.SetRenderTargets(rtv); MyScreenPass.DrawFullscreenQuad(new MyViewport(64, 64, 512, 64)); RC.Context.PixelShader.Set(m_drawTonemapping); MyScreenPass.DrawFullscreenQuad(new MyViewport(64, 128, 512, 64)); }
internal TextureCreationResult CreateTexture(Stream stream) { TK.Texture2D texture = TK.Texture2D.Load(tkDevice, stream); var resourceView = new D3D11.ShaderResourceView(device, texture); return(new TextureCreationResult() { Texture = texture, ResourceView = resourceView }); }
public ParticleSource(IGameComponentRoot root, IGameComponentContainer parent, Device device, ParticleEffectBase11 effect, ShaderResourceView texArraySRV, ShaderResourceView randomTexSRV, int maxParticles) : base(root, parent) { _firstRun = true; EmitDirW = new Vector3(0, 1, 0); _maxParticles = maxParticles; _fx = effect; _texArraySRV = texArraySRV; _randomTexSRV = randomTexSRV; _device = device; }
/// <summary> /// Копирует данные из неуправляемого ресурса ( Используемого в Компюте шейдере) в управляемый ресурс обычного шейдера. /// </summary> /// <param name="device">Устройстов используемое для отрисовки 3д</param> /// <param name="srv">ShaderResourceView с данными тестуры в который будем копировать данные UnorderedAccessView.</param> /// <param name="uav">UnorderedAccessView из которого будем брать данные</param> public static void CopyUAVToSRV(SharpDX.Direct3D11.Device device, ref SharpDX.Direct3D11.ShaderResourceView srv, SharpDX.Direct3D11.UnorderedAccessView uav) { using (var t = srv.ResourceAs <Texture2D>()) { using (var t2 = uav.ResourceAs <SharpDX.Direct3D11.Texture2D>()) { // Copy the texture for the resource to the typeless texture device.ImmediateContext.CopyResource(t2, t); } } }
/// <summary> /// Получает Bimap из ShaderResourceView (Ресурса с текстурой для шейдера). /// </summary> /// <param name="srv">Ресурс текстуры шейдера</param> /// <param name="renderTarger"> 2d рендертаргет который будет рисовать этот битмап</param> /// <returns>Битмапу с данными</returns> public static SharpDX.Direct2D1.Bitmap GetBitmapFromSRV(SharpDX.Direct3D11.ShaderResourceView srv, RenderTarget renderTarger) { using (var texture = srv.ResourceAs <Texture2D>()) using (var surface = texture.QueryInterface <Surface>()) { var bitmap = new SharpDX.Direct2D1.Bitmap(renderTarger, surface, new SharpDX.Direct2D1.BitmapProperties(new SharpDX.Direct2D1.PixelFormat( Format.R8G8B8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied))); return(bitmap); } }
public SharedTextureHandler(TextureHandleResponse response) { var texture = DxHandler.Device.OpenSharedResource <D3D11.Texture2D>(response.TextureHandle); var view = new D3D11.ShaderResourceView(DxHandler.Device, texture, new D3D11.ShaderResourceViewDescription() { Format = texture.Description.Format, Dimension = D3D.ShaderResourceViewDimension.Texture2D, Texture2D = { MipLevels = texture.Description.MipLevels }, }); textureWrap = new D3DTextureWrap(view, texture.Description.Width, texture.Description.Height); }
/// <summary> /// スキニングを実行する。 /// </summary> /// <param name="d3ddc"> /// 実行対象のDeviceContext。 /// </param> /// <param name="入力頂点数"> /// モデルの全頂点数。 /// </param> /// <param name="ボーンのモデルポーズ行列定数バッファ"> /// ボーンのモデルポーズ行列の配列を格納された定数バッファ。 /// 構造については <see cref="PMXモデル.D3DBoneTrans"/> 参照。 /// </param> /// <param name="ボーンのローカル位置定数バッファ"> /// ボーンのローカル位置の配列が格納された定数バッファ。 /// 構造については <see cref="PMXモデル.D3DBoneLocalPosition"/> 参照。 /// </param> /// <param name="ボーンの回転行列定数バッファ"> /// ボーンの回転行列の配列が格納された定数バッファ。 /// 構造については <see cref="PMXモデル.D3DBoneLocalPosition"/> 参照。 /// </param> /// <param name="変形前頂点データSRV"> /// スキニングの入力となる頂点データリソースのSRV。 /// 構造については <see cref="CS_INPUT"/> 参照。 /// </param> /// <param name="変形後頂点データUAV"> /// スキニングの出力を書き込む頂点データリソースのUAV。 /// 構造については <see cref="VS_INPUT"/> 参照。 /// </param> /// <remarks> /// このメソッドの呼び出し時には、<paramref name="d3ddc"/> には事前に以下のように設定される。 /// ComputeShader /// - slot( b1 ) …… <paramref name="ボーンのモデルポーズ行列定数バッファ"/> /// - slot( b2 ) …… <paramref name="ボーンのローカル位置定数バッファ"/> /// - slot( b3 ) …… <paramref name="ボーンの回転行列定数バッファ"/> /// - slot( t0 ) …… <paramref name="変形前頂点データSRV"/> /// - slot( u0 ) …… <paramref name="変形後頂点データUAV"/> /// </remarks> public void Run( SharpDX.Direct3D11.DeviceContext d3ddc, int 入力頂点数, SharpDX.Direct3D11.Buffer ボーンのモデルポーズ行列定数バッファ, SharpDX.Direct3D11.Buffer ボーンのローカル位置定数バッファ, SharpDX.Direct3D11.Buffer ボーンの回転行列定数バッファ, SharpDX.Direct3D11.ShaderResourceView 形前頂点データSRV, SharpDX.Direct3D11.UnorderedAccessView 形後頂点データUAV) { d3ddc.ComputeShader.Set(this.ComputeShader); d3ddc.Dispatch((入力頂点数 / 64) + 1, 1, 1); // 既定のシェーダー(DefaultSkinningComputeShader.hlsl)に合わせてある }
public void CreateResources(D3D11.Device device, int sampleCount, int sampleQuality, int width, int height) { FieldOfView = width / (float)height; // render target D3D11.Texture2DDescription targetTextureDesc = new D3D11.Texture2DDescription() { Format = DXGI.Format.R8G8B8A8_UNorm, ArraySize = 1, MipLevels = 1, Width = width, Height = height, SampleDescription = new DXGI.SampleDescription(sampleCount, sampleQuality), Usage = D3D11.ResourceUsage.Default, BindFlags = D3D11.BindFlags.RenderTarget | D3D11.BindFlags.ShaderResource, CpuAccessFlags = D3D11.CpuAccessFlags.None, OptionFlags = D3D11.ResourceOptionFlags.None }; using (D3D11.Texture2D target = new D3D11.Texture2D(device, targetTextureDesc)) { renderTargetResource = new D3D11.ShaderResourceView(device, target); renderTargetView = new D3D11.RenderTargetView(device, target); } // depth buffer D3D11.Texture2DDescription depthTextureDesc = new D3D11.Texture2DDescription() { Format = DXGI.Format.R32_Typeless, ArraySize = 1, MipLevels = 1, Width = width, Height = height, SampleDescription = new DXGI.SampleDescription(sampleCount, sampleQuality), Usage = D3D11.ResourceUsage.Default, BindFlags = D3D11.BindFlags.DepthStencil | D3D11.BindFlags.ShaderResource, CpuAccessFlags = D3D11.CpuAccessFlags.None, OptionFlags = D3D11.ResourceOptionFlags.None }; D3D11.DepthStencilViewDescription depthViewDesc = new D3D11.DepthStencilViewDescription() { Flags = D3D11.DepthStencilViewFlags.None, Dimension = D3D11.DepthStencilViewDimension.Texture2D, Format = DXGI.Format.D32_Float, }; D3D11.ShaderResourceViewDescription depthResourceDesc = new D3D11.ShaderResourceViewDescription() { Format = DXGI.Format.R32_Float, Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D }; depthResourceDesc.Texture2D.MipLevels = 1; using (D3D11.Texture2D depthTexture = new D3D11.Texture2D(device, depthTextureDesc)) { depthStencilView = new D3D11.DepthStencilView(device, depthTexture, depthViewDesc); depthStencilResource = new D3D11.ShaderResourceView(device, depthTexture, depthResourceDesc); } }
/// <summary> /// Loads all resources. /// </summary> /// <param name="device">The device on which to load all resources.</param> /// <param name="resources">The current ResourceDictionary.</param> protected override void LoadResourceInternal(EngineDevice device, ResourceDictionary resources) { // Prepare texture m_texture = GraphicsHelper.CreateCpuWritableTexture( device, m_videoWidth, m_videoHeight); m_textureView = new D3D11.ShaderResourceView(device.DeviceD3D11_1, m_texture); // Read the thumbnail m_videoReader.SetCurrentPosition(m_thumbnailTimestamp); m_thumbnailFrame = m_videoReader.ReadFrame(); m_thumbnailFrame.SetAllAlphaValuesToOne_ARGB(); }
/// <summary> /// Function to clean up the resources used by the view. /// </summary> protected override void OnCleanUp() { if (D3DView == null) { return; } Resource.Graphics.Shaders.Unbind(this); Gorgon.Log.Print("Destroying shader resource view for {0}.", LoggingLevel.Verbose, Resource.Name); D3DView.Dispose(); D3DView = null; }
/// <summary> /// Function to perform initialization of the shader view resource. /// </summary> protected override void OnInitialize() { D3D.ShaderResourceViewDescription desc; var texture = (GorgonTexture)Resource; Gorgon.Log.Print("Creating texture shader view for {0}.", LoggingLevel.Verbose, Resource.Name); // Build SRV description. switch (Resource.ResourceType) { case ResourceType.Texture1D: desc = GetDesc1D(texture); break; case ResourceType.Texture2D: desc = IsCube ? GetDesc2DCube(texture) : GetDesc2D(texture); break; case ResourceType.Texture3D: desc = GetDesc3D(); break; default: throw new GorgonException(GorgonResult.CannotCreate, string.Format(Resources.GORGFX_IMAGE_TYPE_INVALID, Resource.ResourceType)); } try { Gorgon.Log.Print("Gorgon resource view: Creating D3D 11 shader resource view.", LoggingLevel.Verbose); // Create our SRV. D3DView = new D3D.ShaderResourceView(Resource.Graphics.D3DDevice, Resource.D3DResource, desc) { DebugName = Resource.ResourceType + " '" + texture.Name + "' Shader Resource View" }; } catch (SharpDXException sDXEx) { if ((uint)sDXEx.ResultCode.Code == 0x80070057) { throw new GorgonException(GorgonResult.CannotCreate, string.Format(Resources.GORGFX_VIEW_CANNOT_CAST_FORMAT, texture.Settings.Format, Format)); } } }
/// <summary> /// Loads all resource. /// </summary> /// <param name="device">The device on which to load all resources.</param> /// <param name="resources">The current ResourceDictionary.</param> protected override void LoadResourceInternal(EngineDevice device, ResourceDictionary resources) { m_renderTargetTexture = GraphicsHelper.CreateRenderTargetTexture( device, m_width, m_height, new GraphicsViewConfiguration() { AntialiasingEnabled = false }); m_renderTargetTextureView = new D3D11.ShaderResourceView(device.DeviceD3D11_1, m_renderTargetTexture); m_overlayRenderer = new Direct2DOverlayRenderer( device, m_renderTargetTexture, m_width, m_height, DpiScaling.Default); m_graphics2D = new Graphics2D(device, m_overlayRenderer.RenderTarget2D, new Size2F(m_width, m_height)); }
/// <summary> /// Loads the resource. /// </summary> protected override void LoadResourceInternal(EngineDevice device, ResourceDictionary resources) { using (Bitmap drawingBitmap = new Bitmap(m_width, m_height)) { using (GDI.Graphics graphics = GDI.Graphics.FromImage(drawingBitmap)) { graphics.FillRectangle( m_drawingBrush, new GDI.Rectangle(0, 0, m_width, m_height)); graphics.Dispose(); } m_texture = GraphicsHelper.LoadTextureFromBitmap(device, drawingBitmap); m_textureView = new D3D11.ShaderResourceView(device.DeviceD3D11_1, m_texture); } }
public void Draw() { if (_Synchronised == false) { Synchronize(); } _Renderer.DeviceContext.InputAssembler.SetVertexBuffers(0, new D3D11.VertexBufferBinding(_VertexBuffer, Detail.Vertex2D.Size, 0)); _Renderer.DeviceContext.InputAssembler.SetIndexBuffer(_IndexBuffer, Format.R16_UInt, 0); int vertex_offset = 0; int index_offset = 0; D3D11.ShaderResourceView last_res = null; //RectangleF clip = new RectangleF(0f, 0f, _Renderer.ViewportSize.Width, _Renderer.ViewportSize.Height); foreach (var batch in _Batches) { if (batch.Texture != last_res) { _Renderer.DeviceContext.PixelShader.SetShaderResource(0, batch.Texture); last_res = batch.Texture; } _Renderer.DeviceContext.InputAssembler.PrimitiveTopology = batch.DrawMode; if (batch.IndexCount > 0) { _Renderer.DeviceContext.DrawIndexed(batch.IndexCount, index_offset, vertex_offset); index_offset += batch.IndexCount; } else { _Renderer.DeviceContext.Draw(batch.VertexCount, vertex_offset); } vertex_offset += batch.VertexCount; } if (AutoReset) { Reset(); } }
} //used to manipulate and introduce disturbances to water by code public void Swap() { var tempSRV = currentSolutionSRV; currentSolutionSRV = pastSolutionSRV; pastSolutionSRV = tempSRV; var tempUAV = currentSolutionUAV; currentSolutionUAV = pastSolutionUAV; pastSolutionUAV = tempUAV; var tempBuffer = currentBuffer; currentBuffer = pastBuffer; pastBuffer = tempBuffer; }
/// <summary> /// Loads the resource. /// </summary> protected override void LoadResourceInternal(EngineDevice device, ResourceDictionary resources) { // Select source texture ResourceLink source = m_resourceLinkLowQuality; if (device.Configuration.TextureQuality == TextureQuality.Hight) { source = m_resourceLinkHighQuality; } // Load the texture try { if (source != null) { using (Stream inStream = source.OpenInputStream()) using (SDXTK.Image rawImage = SDXTK.Image.Load(inStream)) { m_texture = GraphicsHelper.CreateTexture(device, rawImage); } } else if (m_inMemoryTexture != null) { m_texture = GraphicsHelper.LoadTexture2DFromMappedTexture(device, m_inMemoryTexture); } } catch (Exception) { #if DESKTOP // Load default texture from a bitmap m_texture = GraphicsHelper.LoadTextureFromBitmap(device, Properties.Resources.Blank_16x16); #else throw; #endif } // Create view for shaders m_textureView = new D3D11.ShaderResourceView(device.DeviceD3D11_1, m_texture); // Some checking.. m_isCubeTexture = (m_texture.Description.ArraySize == 6) && ((m_texture.Description.OptionFlags & D3D11.ResourceOptionFlags.TextureCube) == D3D11.ResourceOptionFlags.TextureCube); m_isRenderTarget = (m_texture.Description.BindFlags & D3D11.BindFlags.RenderTarget) == D3D11.BindFlags.RenderTarget; }