protected override void DrawCore(RenderContext context, RenderFrame output) { var graphicsDevice = context.GraphicsDevice; // clear the targets if (output.DepthStencil != null && (ClearFlags == ClearRenderFrameFlags.ColorAndDepth || ClearFlags == ClearRenderFrameFlags.DepthOnly)) { const DepthStencilClearOptions ClearOptions = DepthStencilClearOptions.DepthBuffer | DepthStencilClearOptions.Stencil; graphicsDevice.Clear(output.DepthStencil, ClearOptions, Depth, Stencil); } if (ClearFlags == ClearRenderFrameFlags.ColorAndDepth || ClearFlags == ClearRenderFrameFlags.ColorOnly) { foreach (var renderTarget in output.RenderTargets) { if (renderTarget != null) { // If color is in GammeSpace and rendertarget is either SRgb or HDR, use a linear value to clear the buffer. // TODO: We will need to move this color transform code to a shareable component var color = Color.ToColorSpace(ColorSpace, (renderTarget.Format.IsSRgb() || renderTarget.Format.IsHDR()) ? ColorSpace.Linear : graphicsDevice.ColorSpace); graphicsDevice.Clear(renderTarget, color); } } } }
/// <summary> /// Clears the specified depth stencil buffer. See <see cref="Textures+and+render+targets"/> to learn how to use it. /// </summary> /// <param name="depthStencilBuffer">The depth stencil buffer.</param> /// <param name="options">The options.</param> /// <param name="depth">The depth.</param> /// <param name="stencil">The stencil.</param> /// <exception cref="System.InvalidOperationException"></exception> public void Clear(Texture depthStencilBuffer, DepthStencilClearOptions options, float depth = 1, byte stencil = 0) { if (depthStencilBuffer == null) { throw new ArgumentNullException("depthStencilBuffer"); } var flags = ((options & DepthStencilClearOptions.DepthBuffer) != 0) ? SharpDX.Direct3D11.DepthStencilClearFlags.Depth : 0; // Check that the DepthStencilBuffer has a Stencil if Clear Stencil is requested if ((options & DepthStencilClearOptions.Stencil) != 0) { if (!depthStencilBuffer.HasStencil) { throw new InvalidOperationException(string.Format(FrameworkResources.NoStencilBufferForDepthFormat, depthStencilBuffer.ViewFormat)); } flags |= SharpDX.Direct3D11.DepthStencilClearFlags.Stencil; } NativeDeviceContext.ClearDepthStencilView(depthStencilBuffer.NativeDepthStencilView, flags, depth, stencil); }
protected override void DrawCore(RenderContext context, RenderFrame output) { var graphicsDevice = context.GraphicsDevice; // clear the targets if (output.DepthStencil != null && (ClearFlags == ClearRenderFrameFlags.ColorAndDepth || ClearFlags == ClearRenderFrameFlags.DepthOnly)) { const DepthStencilClearOptions ClearOptions = DepthStencilClearOptions.DepthBuffer | DepthStencilClearOptions.Stencil; graphicsDevice.Clear(output.DepthStencil, ClearOptions, Depth, Stencil); } if (ClearFlags == ClearRenderFrameFlags.ColorAndDepth || ClearFlags == ClearRenderFrameFlags.ColorOnly) { foreach (var renderTarget in output.RenderTargets) { if (renderTarget != null) { graphicsDevice.Clear(renderTarget, Color); } } } }
/// <summary> /// Clears a depth stencil buffer. /// </summary> /// <param name="depthStencilBuffer">The depth stencil buffer.</param> /// <param name="options">Options for clearing a buffer.</param> /// <param name="depth">Set this depth value for the Depth buffer.</param> /// <param name="stencil">Set this stencil value for the Stencil buffer.</param> public void Clear(DepthStencilBuffer depthStencilBuffer, DepthStencilClearOptions options, float depth = 1, byte stencil = 0) { throw new NotImplementedException(); }
/// <summary> /// Clears the specified depth stencil buffer. See <see cref="Textures+and+render+targets"/> to learn how to use it. /// </summary> /// <param name="depthStencilBuffer">The depth stencil buffer.</param> /// <param name="options">The options.</param> /// <param name="depth">The depth.</param> /// <param name="stencil">The stencil.</param> /// <exception cref="System.InvalidOperationException"></exception> public void Clear(Texture depthStencilBuffer, DepthStencilClearOptions options, float depth = 1, byte stencil = 0) { NullHelper.ToImplement(); }
/// <summary> /// Clears the specified depth stencil buffer. See <see cref="Textures+and+render+targets"/> to learn how to use it. /// </summary> /// <param name="depthStencilBuffer">The depth stencil buffer.</param> /// <param name="options">The options.</param> /// <param name="depth">The depth.</param> /// <param name="stencil">The stencil.</param> /// <exception cref="System.InvalidOperationException"></exception> public void Clear(Texture depthStencilBuffer, DepthStencilClearOptions options, float depth = 1, byte stencil = 0) { NativeCommandList.ClearDepthStencilView(depthStencilBuffer.NativeDepthStencilView, (ClearFlags)options, depth, stencil); }
/// <summary> /// Clears the specified depth stencil buffer. See <see cref="Textures+and+render+targets"/> to learn how to use it. /// </summary> /// <param name="depthStencilBuffer">The depth stencil buffer.</param> /// <param name="options">The options.</param> /// <param name="depth">The depth.</param> /// <param name="stencil">The stencil.</param> /// <exception cref="System.InvalidOperationException"></exception> public void Clear(Texture depthStencilBuffer, DepthStencilClearOptions options, float depth = 1, byte stencil = 0) { if (depthStencilBuffer == null) throw new ArgumentNullException("depthStencilBuffer"); var flags = ((options & DepthStencilClearOptions.DepthBuffer) != 0) ? SharpDX.Direct3D11.DepthStencilClearFlags.Depth : 0; // Check that the DepthStencilBuffer has a Stencil if Clear Stencil is requested if ((options & DepthStencilClearOptions.Stencil) != 0) { if (!depthStencilBuffer.HasStencil) throw new InvalidOperationException(string.Format(FrameworkResources.NoStencilBufferForDepthFormat, depthStencilBuffer.ViewFormat)); flags |= SharpDX.Direct3D11.DepthStencilClearFlags.Stencil; } NativeDeviceContext.ClearDepthStencilView(depthStencilBuffer.NativeDepthStencilView, flags, depth, stencil); }
public void Clear(Texture depthStencilBuffer, DepthStencilClearOptions options, float depth = 1, byte stencil = 0) { #if DEBUG GraphicsDevice.EnsureContextActive(); #endif #if SILICONSTUDIO_PLATFORM_ANDROID // Device with no background loading context: check if some loading is pending if (GraphicsDevice.AsyncPendingTaskWaiting) GraphicsDevice.ExecutePendingTasks(); #endif var clearFBO = GraphicsDevice.FindOrCreateFBO(depthStencilBuffer); if (clearFBO != boundFBO) GL.BindFramebuffer(FramebufferTarget.Framebuffer, clearFBO); ClearBufferMask clearBufferMask = ((options & DepthStencilClearOptions.DepthBuffer) == DepthStencilClearOptions.DepthBuffer ? ClearBufferMask.DepthBufferBit : 0) | ((options & DepthStencilClearOptions.Stencil) == DepthStencilClearOptions.Stencil ? ClearBufferMask.StencilBufferBit : 0); GL.ClearDepth(depth); GL.ClearStencil(stencil); // Check if we need to change depth mask var currentDepthMask = DepthStencilBoundState.DepthBufferWriteEnable; if (!currentDepthMask) GL.DepthMask(true); GL.Clear(clearBufferMask); if (!currentDepthMask) GL.DepthMask(false); if (clearFBO != boundFBO) GL.BindFramebuffer(FramebufferTarget.Framebuffer, boundFBO); }