Add scissor support to IFrameBuffer.

This commit is contained in:
Paul Chote
2019-11-03 17:25:41 +00:00
committed by reaperrr
parent e7de7b4c05
commit 0c8a47b5af
3 changed files with 40 additions and 0 deletions

View File

@@ -111,6 +111,8 @@ namespace OpenRA
{
void Bind();
void Unbind();
void EnableScissor(Rectangle rect);
void DisableScissor();
ITexture Texture { get; }
}

View File

@@ -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

View File

@@ -454,6 +454,8 @@ namespace OpenRA.Platforms.Default
readonly Action bind;
readonly Action unbind;
readonly Action dispose;
readonly Action<object> 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);