From 0c8a47b5af871211fae15cee04b96c4be44dbdd4 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 3 Nov 2019 17:25:41 +0000 Subject: [PATCH] Add scissor support to IFrameBuffer. --- OpenRA.Game/Graphics/PlatformInterfaces.cs | 2 ++ OpenRA.Platforms.Default/FrameBuffer.cs | 23 +++++++++++++++++++ .../ThreadedGraphicsContext.cs | 15 ++++++++++++ 3 files changed, 40 insertions(+) diff --git a/OpenRA.Game/Graphics/PlatformInterfaces.cs b/OpenRA.Game/Graphics/PlatformInterfaces.cs index a1e941f678..0dd6db0fce 100644 --- a/OpenRA.Game/Graphics/PlatformInterfaces.cs +++ b/OpenRA.Game/Graphics/PlatformInterfaces.cs @@ -111,6 +111,8 @@ namespace OpenRA { void Bind(); void Unbind(); + void EnableScissor(Rectangle rect); + void DisableScissor(); ITexture Texture { get; } } diff --git a/OpenRA.Platforms.Default/FrameBuffer.cs b/OpenRA.Platforms.Default/FrameBuffer.cs index 4388701953..224c4dd9d7 100644 --- a/OpenRA.Platforms.Default/FrameBuffer.cs +++ b/OpenRA.Platforms.Default/FrameBuffer.cs @@ -23,6 +23,7 @@ namespace OpenRA.Platforms.Default readonly Color clearColor; uint framebuffer, depth; bool disposed; + bool scissored; public FrameBuffer(Size size, ITextureInternal texture, Color clearColor) { @@ -100,6 +101,9 @@ namespace OpenRA.Platforms.Default public void Unbind() { + if (scissored) + throw new InvalidOperationException("Attempting to unbind FrameBuffer with an active scissor region."); + VerifyThreadAffinity(); OpenGL.glFlush(); OpenGL.CheckGLError(); @@ -109,6 +113,25 @@ namespace OpenRA.Platforms.Default OpenGL.CheckGLError(); } + public void EnableScissor(Rectangle rect) + { + VerifyThreadAffinity(); + + OpenGL.glScissor(rect.X, rect.Y, Math.Max(rect.Width, 0), Math.Max(rect.Height, 0)); + OpenGL.CheckGLError(); + OpenGL.glEnable(OpenGL.GL_SCISSOR_TEST); + OpenGL.CheckGLError(); + scissored = true; + } + + public void DisableScissor() + { + VerifyThreadAffinity(); + OpenGL.glDisable(OpenGL.GL_SCISSOR_TEST); + OpenGL.CheckGLError(); + scissored = false; + } + public ITexture Texture { get diff --git a/OpenRA.Platforms.Default/ThreadedGraphicsContext.cs b/OpenRA.Platforms.Default/ThreadedGraphicsContext.cs index f4fae71f93..da6aee2fa1 100644 --- a/OpenRA.Platforms.Default/ThreadedGraphicsContext.cs +++ b/OpenRA.Platforms.Default/ThreadedGraphicsContext.cs @@ -454,6 +454,8 @@ namespace OpenRA.Platforms.Default readonly Action bind; readonly Action unbind; readonly Action dispose; + readonly Action enableScissor; + readonly Action disableScissor; public ThreadedFrameBuffer(ThreadedGraphicsContext device, IFrameBuffer frameBuffer) { @@ -462,6 +464,9 @@ namespace OpenRA.Platforms.Default bind = frameBuffer.Bind; unbind = frameBuffer.Unbind; dispose = frameBuffer.Dispose; + + enableScissor = rect => frameBuffer.EnableScissor((Rectangle)rect); + disableScissor = frameBuffer.DisableScissor; } public ITexture Texture @@ -482,6 +487,16 @@ namespace OpenRA.Platforms.Default device.Post(unbind); } + public void EnableScissor(Rectangle rect) + { + device.Post(enableScissor, rect); + } + + public void DisableScissor() + { + device.Post(disableScissor); + } + public void Dispose() { device.Post(dispose);