diff --git a/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs b/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs index ae7c76df0c..ec82cff24e 100755 --- a/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs +++ b/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs @@ -53,6 +53,9 @@ namespace OpenRA.FileFormats.Graphics void EnableDepthBuffer(); void DisableDepthBuffer(); + + void EnableStencilBuffer(); + void DisableStencilBuffer(); } public interface IVertexBuffer diff --git a/OpenRA.Game/Graphics/Renderer.cs b/OpenRA.Game/Graphics/Renderer.cs index e129851745..3be7b230f7 100644 --- a/OpenRA.Game/Graphics/Renderer.cs +++ b/OpenRA.Game/Graphics/Renderer.cs @@ -198,5 +198,17 @@ namespace OpenRA.Graphics Flush(); Device.DisableDepthBuffer(); } + + public void EnableStencilBuffer() + { + Flush(); + Device.EnableStencilBuffer(); + } + + public void DisableStencilBuffer() + { + Flush(); + Device.DisableStencilBuffer(); + } } } diff --git a/OpenRA.Renderer.Null/NullGraphicsDevice.cs b/OpenRA.Renderer.Null/NullGraphicsDevice.cs index 61c7878caf..cc8dd57233 100644 --- a/OpenRA.Renderer.Null/NullGraphicsDevice.cs +++ b/OpenRA.Renderer.Null/NullGraphicsDevice.cs @@ -41,6 +41,9 @@ namespace OpenRA.Renderer.Null public void EnableDepthBuffer() { } public void DisableDepthBuffer() { } + public void EnableStencilBuffer() { } + public void DisableStencilBuffer() { } + public void Clear() { } public void Present() { } diff --git a/OpenRA.Renderer.SdlCommon/SdlGraphics.cs b/OpenRA.Renderer.SdlCommon/SdlGraphics.cs index ccd7ca08aa..0cf17f2d3e 100644 --- a/OpenRA.Renderer.SdlCommon/SdlGraphics.cs +++ b/OpenRA.Renderer.SdlCommon/SdlGraphics.cs @@ -49,6 +49,7 @@ namespace OpenRA.Renderer.SdlCommon Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_GREEN_SIZE, 8 ); Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_BLUE_SIZE, 8 ); Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_ALPHA_SIZE, 0 ); + Sdl.SDL_GL_SetAttribute( Sdl.SDL_GL_STENCIL_SIZE, 1 ); int windowFlags = 0; switch (window) @@ -133,6 +134,24 @@ namespace OpenRA.Renderer.SdlCommon ErrorHandler.CheckGlError(); } + public void EnableStencilBuffer() + { + Gl.glClear(Gl.GL_STENCIL_BUFFER_BIT); + ErrorHandler.CheckGlError(); + Gl.glEnable(Gl.GL_STENCIL_TEST); + ErrorHandler.CheckGlError(); + Gl.glStencilFunc(Gl.GL_NOTEQUAL, 1, 1); + ErrorHandler.CheckGlError(); + Gl.glStencilOp(Gl.GL_KEEP, Gl.GL_KEEP, Gl.GL_INCR); + ErrorHandler.CheckGlError(); + } + + public void DisableStencilBuffer() + { + Gl.glDisable(Gl.GL_STENCIL_TEST); + ErrorHandler.CheckGlError(); + } + public void EnableDepthBuffer() { Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT);