public void OnReset(Context glContext, int width, int height, ref SwapChainDescription implicitSwapChainDescription) { if (backBuffer != null) { backBuffer.Dispose(); backBuffer = null; } if (autoDepthStencil != null) { autoDepthStencil.Dispose(); autoDepthStencil = null; } texture2DDescription.Width = width; texture2DDescription.Height = height; texture2DDescription.Sampling = implicitSwapChainDescription.Sampling; texture2DDescription.FormatID = implicitSwapChainDescription.ColorBufferFormatID; texture2DDescription.BindFlags = BindFlags.RenderTarget; backBuffer = new CBackBuffer(device, ref texture2DDescription); if (implicitSwapChainDescription.EnableAutoDepthStencil) { texture2DDescription.FormatID = implicitSwapChainDescription.DepthStencilFormatID; texture2DDescription.BindFlags = BindFlags.DepthStencil; autoDepthStencil = new CAutoDepthStencil(device, ref texture2DDescription); } }
public void OnEndScene(Context glImmediateContext, CBackBuffer backBuffer) { var boundProgram = glPipeline.Program; var boundVertexArray = glPipeline.VertexArray; var boundTexture = glPipeline.Textures[0]; var boundSampler = glPipeline.Samplers[0]; var boundFramebuffer = glPipeline.Framebuffer; var boundViewportCount = glPipeline.Viewports.EnabledViewportCount; if (tempViewports == null || tempViewports.Length < boundViewportCount) tempViewports = new Viewport[boundViewportCount]; for (int i = 0; i < boundViewportCount; i++) { var glViewport = glPipeline.Viewports[i]; tempViewports[i] = new Viewport { Left = glViewport.X, Top = glViewport.Y, Width = glViewport.Width, Height = glViewport.Height, MinDepth = glViewport.Near, MaxDepth = glViewport.Far }; } var boundCullFaceEnable = glPipeline.Rasterizer.CullFaceEnable; var boundPolyginModeFront = glPipeline.Rasterizer.PolygonModeFront; var boundPolygonModeBack = glPipeline.Rasterizer.PolygonModeBack; var boundScissorEnable = glPipeline.Rasterizer.ScissorEnable; var boundMultisampleEnable = glPipeline.Rasterizer.MultisampleEnable; var boundLineSmoothEnable = glPipeline.Rasterizer.LineSmoothEnable; var boundDepthTestEnable = glPipeline.DepthStencil.DepthTestEnable; var boundDepthMask = glPipeline.DepthStencil.DepthMask; var boundStencilTestEnable = glPipeline.DepthStencil.StencilTestEnable; var boundBlendEnable = glPipeline.Blend.BlendEnable; var boundAlphaToCoverageEnable = glPipeline.Blend.AlphaToCoverageEnable; var boundSampleMask = glPipeline.Blend.SampleMask; glPipeline.Program = program; glPipeline.VertexArray = vertexArray; if (backBuffer.Sampling != Sampling.NoMultisampling) { sourceFramebuffer.AttachTextureImage(glContext, FramebufferAttachmentPoint.Color0, (Texture2DMultisample)backBuffer.GLTexture); destinationFramebuffer.AttachTextureImage(glContext, FramebufferAttachmentPoint.Color0, backBuffer.GLResolveTexture, 0); glContext.BlitFramebuffer( sourceFramebuffer, 0, 0, backBuffer.Width, backBuffer.Height, destinationFramebuffer, 0, 0, backBuffer.Width, backBuffer.Height, ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Nearest); glPipeline.Textures[0] = backBuffer.GLResolveTexture; } else { glPipeline.Textures[0] = backBuffer.GLTexture; } glPipeline.Samplers[0] = sampler; glPipeline.Framebuffer = null; glPipeline.Viewports.EnabledViewportCount = 1; glPipeline.Viewports[0].Set(backBuffer.Width, backBuffer.Height); glPipeline.Rasterizer.CullFaceEnable = false; glPipeline.Rasterizer.PolygonModeFront = PolygonMode.Fill; glPipeline.Rasterizer.PolygonModeBack = PolygonMode.Fill; glPipeline.Rasterizer.ScissorEnable = false; glPipeline.Rasterizer.MultisampleEnable = false; glPipeline.Rasterizer.LineSmoothEnable = false; glPipeline.DepthStencil.DepthTestEnable = false; glPipeline.DepthStencil.DepthMask = false; glPipeline.DepthStencil.StencilTestEnable = false; glPipeline.Blend.BlendEnable = false; glPipeline.Blend.AlphaToCoverageEnable = false; glPipeline.Blend.SampleMask = 0xffffffff; glImmediateContext.DrawElements(BeginMode.Triangles, 6, DrawElementsType.UnsignedShort, 0); glPipeline.Program = boundProgram; glPipeline.VertexArray = boundVertexArray; glPipeline.Textures[0] = boundTexture; glPipeline.Samplers[0] = boundSampler; glPipeline.Framebuffer = boundFramebuffer; for (int i = 0; i < boundViewportCount; i++) { glPipeline.Viewports[i].Set( tempViewports[i].Left, tempViewports[i].Top, tempViewports[i].Width, tempViewports[i].Height, tempViewports[i].MinDepth, tempViewports[i].MaxDepth); } glPipeline.Viewports.EnabledViewportCount = boundViewportCount; glPipeline.Rasterizer.CullFaceEnable = boundCullFaceEnable; glPipeline.Rasterizer.PolygonModeFront = boundPolyginModeFront; glPipeline.Rasterizer.PolygonModeBack = boundPolygonModeBack; glPipeline.Rasterizer.ScissorEnable = boundScissorEnable; glPipeline.Rasterizer.MultisampleEnable = boundMultisampleEnable; glPipeline.Rasterizer.LineSmoothEnable = boundLineSmoothEnable; glPipeline.DepthStencil.DepthTestEnable = boundDepthTestEnable; glPipeline.DepthStencil.DepthMask = boundDepthMask; glPipeline.DepthStencil.StencilTestEnable = boundStencilTestEnable; glPipeline.Blend.BlendEnable = boundBlendEnable; glPipeline.Blend.AlphaToCoverageEnable = boundAlphaToCoverageEnable; glPipeline.Blend.SampleMask = boundSampleMask; }
public void Dispose() { if (backBuffer != null) { backBuffer.Dispose(); backBuffer = null; } if (autoDepthStencil != null) { autoDepthStencil.Dispose(); autoDepthStencil = null; } }
void CreateBackBufferAndDepthStencil() { implicitBackBuffer = new CBackBuffer(this, primaryWindow.SwapChainWidth, primaryWindow.SwapChainHeight, implicitSwapChainDesc.ColorBufferFormatID, implicitSwapChainDesc.Sampling); implicitBackBuffer.UpdateSurface(d3dDevice.GetBackBuffer(0, 0)); implicitDepthStencilBuffer = new CAutoDepthStencil(this, primaryWindow.SwapChainWidth, primaryWindow.SwapChainHeight, implicitSwapChainDesc.DepthStencilFormatID, implicitSwapChainDesc.Sampling); if (implicitSwapChainDesc.EnableAutoDepthStencil) implicitDepthStencilBuffer.UpdateSurface(d3dDevice.DepthStencilSurface); }