Add scissor support to IFrameBuffer.
This commit is contained in:
@@ -111,6 +111,8 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
void Bind();
|
void Bind();
|
||||||
void Unbind();
|
void Unbind();
|
||||||
|
void EnableScissor(Rectangle rect);
|
||||||
|
void DisableScissor();
|
||||||
ITexture Texture { get; }
|
ITexture Texture { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ namespace OpenRA.Platforms.Default
|
|||||||
readonly Color clearColor;
|
readonly Color clearColor;
|
||||||
uint framebuffer, depth;
|
uint framebuffer, depth;
|
||||||
bool disposed;
|
bool disposed;
|
||||||
|
bool scissored;
|
||||||
|
|
||||||
public FrameBuffer(Size size, ITextureInternal texture, Color clearColor)
|
public FrameBuffer(Size size, ITextureInternal texture, Color clearColor)
|
||||||
{
|
{
|
||||||
@@ -100,6 +101,9 @@ namespace OpenRA.Platforms.Default
|
|||||||
|
|
||||||
public void Unbind()
|
public void Unbind()
|
||||||
{
|
{
|
||||||
|
if (scissored)
|
||||||
|
throw new InvalidOperationException("Attempting to unbind FrameBuffer with an active scissor region.");
|
||||||
|
|
||||||
VerifyThreadAffinity();
|
VerifyThreadAffinity();
|
||||||
OpenGL.glFlush();
|
OpenGL.glFlush();
|
||||||
OpenGL.CheckGLError();
|
OpenGL.CheckGLError();
|
||||||
@@ -109,6 +113,25 @@ namespace OpenRA.Platforms.Default
|
|||||||
OpenGL.CheckGLError();
|
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
|
public ITexture Texture
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|||||||
@@ -454,6 +454,8 @@ namespace OpenRA.Platforms.Default
|
|||||||
readonly Action bind;
|
readonly Action bind;
|
||||||
readonly Action unbind;
|
readonly Action unbind;
|
||||||
readonly Action dispose;
|
readonly Action dispose;
|
||||||
|
readonly Action<object> enableScissor;
|
||||||
|
readonly Action disableScissor;
|
||||||
|
|
||||||
public ThreadedFrameBuffer(ThreadedGraphicsContext device, IFrameBuffer frameBuffer)
|
public ThreadedFrameBuffer(ThreadedGraphicsContext device, IFrameBuffer frameBuffer)
|
||||||
{
|
{
|
||||||
@@ -462,6 +464,9 @@ namespace OpenRA.Platforms.Default
|
|||||||
bind = frameBuffer.Bind;
|
bind = frameBuffer.Bind;
|
||||||
unbind = frameBuffer.Unbind;
|
unbind = frameBuffer.Unbind;
|
||||||
dispose = frameBuffer.Dispose;
|
dispose = frameBuffer.Dispose;
|
||||||
|
|
||||||
|
enableScissor = rect => frameBuffer.EnableScissor((Rectangle)rect);
|
||||||
|
disableScissor = frameBuffer.DisableScissor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ITexture Texture
|
public ITexture Texture
|
||||||
@@ -482,6 +487,16 @@ namespace OpenRA.Platforms.Default
|
|||||||
device.Post(unbind);
|
device.Post(unbind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void EnableScissor(Rectangle rect)
|
||||||
|
{
|
||||||
|
device.Post(enableScissor, rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DisableScissor()
|
||||||
|
{
|
||||||
|
device.Post(disableScissor);
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
device.Post(dispose);
|
device.Post(dispose);
|
||||||
|
|||||||
Reference in New Issue
Block a user