Add scissor support to IFrameBuffer.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user