Kaydet (Commit) 51e953a3 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Tomaž Vajngerl

opengl: track the state of scissor test and the dimensions

For performance reasons we shouldn't set glScissors if it is not
necessary so we remember to what dimensions we set the glScissor
and don't set it again if this is not necessary. The same goes for
enabling/disabling the GL_SCISSOR_TEST.

Change-Id: I5e1383081b4e76bdded04525c780d3a724f9db5c
Reviewed-on: https://gerrit.libreoffice.org/24504Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
Tested-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst ba0a5708
...@@ -13,15 +13,73 @@ ...@@ -13,15 +13,73 @@
#include "opengl/TextureState.hxx" #include "opengl/TextureState.hxx"
class ScissorState
{
bool mbTest;
int mX;
int mY;
int mWidth;
int mHeight;
public:
ScissorState()
: mbTest(false)
, mX(0)
, mY(0)
, mWidth(0)
, mHeight(0)
{
glDisable(GL_SCISSOR_TEST);
CHECK_GL_ERROR();
}
void set(int x, int y, int width, int height)
{
if (x != mX || y != mY || width != mWidth || height != mHeight)
{
glScissor(x, y, width, height);
CHECK_GL_ERROR();
mX = x;
mY = y;
mWidth = width;
mHeight = height;
}
}
void enable()
{
if (!mbTest)
{
glEnable(GL_SCISSOR_TEST);
CHECK_GL_ERROR();
mbTest = true;
}
}
void disable()
{
if (mbTest)
{
glDisable(GL_SCISSOR_TEST);
CHECK_GL_ERROR();
mbTest = false;
}
}
};
class RenderState class RenderState
{ {
TextureState maTexture; TextureState maTexture;
ScissorState maScissor;
public: public:
RenderState() RenderState()
{} {}
TextureState& texture() { return maTexture; } TextureState& texture() { return maTexture; }
ScissorState& scissor() { return maScissor; }
}; };
#endif // INCLUDED_VCL_INC_OPENGL_RENDER_STATE_H #endif // INCLUDED_VCL_INC_OPENGL_RENDER_STATE_H
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "svdata.hxx" #include "svdata.hxx"
#include "opengl/zone.hxx" #include "opengl/zone.hxx"
#include "opengl/salbmp.hxx" #include "opengl/salbmp.hxx"
#include "opengl/RenderState.hxx"
#include <vector> #include <vector>
...@@ -233,11 +234,6 @@ void OpenGLSalGraphicsImpl::PostDraw() ...@@ -233,11 +234,6 @@ void OpenGLSalGraphicsImpl::PostDraw()
CHECK_GL_ERROR(); CHECK_GL_ERROR();
} }
if( mbUseScissor )
{
glDisable( GL_SCISSOR_TEST );
CHECK_GL_ERROR();
}
if( mbUseStencil ) if( mbUseStencil )
{ {
glDisable( GL_STENCIL_TEST ); glDisable( GL_STENCIL_TEST );
...@@ -274,6 +270,7 @@ void OpenGLSalGraphicsImpl::freeResources() ...@@ -274,6 +270,7 @@ void OpenGLSalGraphicsImpl::freeResources()
VCL_GL_INFO( "freeResources" ); VCL_GL_INFO( "freeResources" );
mpContext->makeCurrent(); mpContext->makeCurrent();
FlushDeferredDrawing(); FlushDeferredDrawing();
mpContext->state()->scissor().disable();
mpContext->ReleaseFramebuffer( maOffscreenTex ); mpContext->ReleaseFramebuffer( maOffscreenTex );
} }
ReleaseContext(); ReleaseContext();
...@@ -327,27 +324,27 @@ void OpenGLSalGraphicsImpl::ImplSetClipBit( const vcl::Region& rClip, GLuint nMa ...@@ -327,27 +324,27 @@ void OpenGLSalGraphicsImpl::ImplSetClipBit( const vcl::Region& rClip, GLuint nMa
void OpenGLSalGraphicsImpl::ImplInitClipRegion() void OpenGLSalGraphicsImpl::ImplInitClipRegion()
{ {
// make sure the context has the right clipping set // make sure the context has the right clipping set
if( maClipRegion != mpContext->maClipRegion ) if (maClipRegion != mpContext->maClipRegion)
{ {
mpContext->maClipRegion = maClipRegion; mpContext->maClipRegion = maClipRegion;
if( mbUseScissor ) if (mbUseStencil)
{
Rectangle aRect( maClipRegion.GetBoundRect() );
glScissor( aRect.Left(), GetHeight() - aRect.Bottom() - 1, aRect.GetWidth(), aRect.GetHeight() );
CHECK_GL_ERROR();
}
else if( !maClipRegion.IsEmpty() )
{ {
ImplSetClipBit( maClipRegion, 0x01 ); ImplSetClipBit(maClipRegion, 0x01);
} }
} }
if( mbUseScissor ) if (mbUseScissor)
{ {
glEnable( GL_SCISSOR_TEST ); Rectangle aRect(maClipRegion.GetBoundRect());
CHECK_GL_ERROR(); mpContext->state()->scissor().set(aRect.Left(), GetHeight() - aRect.Bottom() - 1, aRect.GetWidth(), aRect.GetHeight());
mpContext->state()->scissor().enable();
} }
if( mbUseStencil ) else
{
mpContext->state()->scissor().disable();
}
if (mbUseStencil)
{ {
glStencilFunc( GL_EQUAL, 1, 0x1 ); glStencilFunc( GL_EQUAL, 1, 0x1 );
CHECK_GL_ERROR(); CHECK_GL_ERROR();
...@@ -377,9 +374,9 @@ bool OpenGLSalGraphicsImpl::setClipRegion( const vcl::Region& rClip ) ...@@ -377,9 +374,9 @@ bool OpenGLSalGraphicsImpl::setClipRegion( const vcl::Region& rClip )
mbUseStencil = false; mbUseStencil = false;
mbUseScissor = false; mbUseScissor = false;
if( maClipRegion.IsRectangle() ) if (maClipRegion.IsRectangle())
mbUseScissor = true; mbUseScissor = true;
else if ( !maClipRegion.IsEmpty() ) else if (!maClipRegion.IsEmpty())
mbUseStencil = true; mbUseStencil = true;
return true; return true;
...@@ -1503,7 +1500,7 @@ void OpenGLSalGraphicsImpl::DrawTransformedTexture( ...@@ -1503,7 +1500,7 @@ void OpenGLSalGraphicsImpl::DrawTransformedTexture(
// The scissor area is set to the current window size in PreDraw, // The scissor area is set to the current window size in PreDraw,
// so if we do not disable the scissor test, the texture produced // so if we do not disable the scissor test, the texture produced
// by the first downscaling is clipped to the current window size. // by the first downscaling is clipped to the current window size.
glDisable(GL_SCISSOR_TEST); mpContext->state()->scissor().disable();
CHECK_GL_ERROR(); CHECK_GL_ERROR();
// Maybe it can give problems too. // Maybe it can give problems too.
...@@ -1529,10 +1526,8 @@ void OpenGLSalGraphicsImpl::DrawTransformedTexture( ...@@ -1529,10 +1526,8 @@ void OpenGLSalGraphicsImpl::DrawTransformedTexture(
// Re-enable scissor and stencil tests if needed. // Re-enable scissor and stencil tests if needed.
if (mbUseScissor) if (mbUseScissor)
{ mpContext->state()->scissor().enable();
glEnable(GL_SCISSOR_TEST);
CHECK_GL_ERROR();
}
if (mbUseStencil) if (mbUseStencil)
{ {
glEnable(GL_STENCIL_TEST); glEnable(GL_STENCIL_TEST);
...@@ -2511,6 +2506,8 @@ void OpenGLSalGraphicsImpl::flush() ...@@ -2511,6 +2506,8 @@ void OpenGLSalGraphicsImpl::flush()
{ {
FlushDeferredDrawing(); FlushDeferredDrawing();
mpContext->state()->scissor().disable();
if( IsOffscreen() ) if( IsOffscreen() )
return; return;
...@@ -2527,6 +2524,8 @@ void OpenGLSalGraphicsImpl::doFlush() ...@@ -2527,6 +2524,8 @@ void OpenGLSalGraphicsImpl::doFlush()
{ {
FlushDeferredDrawing(); FlushDeferredDrawing();
mpContext->state()->scissor().disable();
if( IsOffscreen() ) if( IsOffscreen() )
return; return;
...@@ -2570,6 +2569,8 @@ void OpenGLSalGraphicsImpl::doFlush() ...@@ -2570,6 +2569,8 @@ void OpenGLSalGraphicsImpl::doFlush()
glViewport( 0, 0, GetWidth(), GetHeight() ); glViewport( 0, 0, GetWidth(), GetHeight() );
CHECK_GL_ERROR(); CHECK_GL_ERROR();
mpWindowContext->state()->scissor().disable();
#if OSL_DEBUG_LEVEL > 0 // random background glClear #if OSL_DEBUG_LEVEL > 0 // random background glClear
glClearColor((float)rand()/RAND_MAX, (float)rand()/RAND_MAX, glClearColor((float)rand()/RAND_MAX, (float)rand()/RAND_MAX,
(float)rand()/RAND_MAX, 1.0); (float)rand()/RAND_MAX, 1.0);
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include "opengl/zone.hxx" #include "opengl/zone.hxx"
#include "opengl/program.hxx" #include "opengl/program.hxx"
#include "opengl/salbmp.hxx" #include "opengl/salbmp.hxx"
#include "opengl/RenderState.hxx"
#include "opengl/FixedTextureAtlas.hxx" #include "opengl/FixedTextureAtlas.hxx"
#if OSL_DEBUG_LEVEL > 0 #if OSL_DEBUG_LEVEL > 0
...@@ -539,6 +539,9 @@ bool OpenGLSalBitmap::ReadTexture() ...@@ -539,6 +539,9 @@ bool OpenGLSalBitmap::ReadTexture()
OpenGLVCLContextZone aContextZone; OpenGLVCLContextZone aContextZone;
rtl::Reference<OpenGLContext> xContext = OpenGLContext::getVCLContext();
xContext->state()->scissor().disable();
if (mnBits == 8 || mnBits == 16 || mnBits == 24 || mnBits == 32) if (mnBits == 8 || mnBits == 16 || mnBits == 24 || mnBits == 32)
{ {
determineTextureFormat(mnBits, nFormat, nType); determineTextureFormat(mnBits, nFormat, nType);
...@@ -620,6 +623,7 @@ bool OpenGLSalBitmap::calcChecksumGL(OpenGLTexture& rInputTexture, ChecksumType& ...@@ -620,6 +623,7 @@ bool OpenGLSalBitmap::calcChecksumGL(OpenGLTexture& rInputTexture, ChecksumType&
OUString FragShader("areaHashCRC64TFragmentShader"); OUString FragShader("areaHashCRC64TFragmentShader");
rtl::Reference< OpenGLContext > xContext = OpenGLContext::getVCLContext(); rtl::Reference< OpenGLContext > xContext = OpenGLContext::getVCLContext();
xContext->state()->scissor().disable();
static vcl::DeleteOnDeinit<OpenGLTexture> gCRCTableTexture( static vcl::DeleteOnDeinit<OpenGLTexture> gCRCTableTexture(
new OpenGLTexture(512, 1, GL_RGBA, GL_UNSIGNED_BYTE, new OpenGLTexture(512, 1, GL_RGBA, GL_UNSIGNED_BYTE,
...@@ -887,7 +891,8 @@ bool OpenGLSalBitmap::Replace( const Color& rSearchColor, const Color& rReplaceC ...@@ -887,7 +891,8 @@ bool OpenGLSalBitmap::Replace( const Color& rSearchColor, const Color& rReplaceC
VCL_GL_INFO("::Replace"); VCL_GL_INFO("::Replace");
OpenGLZone aZone; OpenGLZone aZone;
rtl::Reference< OpenGLContext > xContext = OpenGLContext::getVCLContext(); rtl::Reference<OpenGLContext> xContext = OpenGLContext::getVCLContext();
xContext->state()->scissor().disable();
OpenGLFramebuffer* pFramebuffer; OpenGLFramebuffer* pFramebuffer;
OpenGLProgram* pProgram; OpenGLProgram* pProgram;
...@@ -926,6 +931,7 @@ bool OpenGLSalBitmap::ConvertToGreyscale() ...@@ -926,6 +931,7 @@ bool OpenGLSalBitmap::ConvertToGreyscale()
OpenGLZone aZone; OpenGLZone aZone;
rtl::Reference<OpenGLContext> xContext = OpenGLContext::getVCLContext(); rtl::Reference<OpenGLContext> xContext = OpenGLContext::getVCLContext();
xContext->state()->scissor().disable();
OpenGLFramebuffer* pFramebuffer; OpenGLFramebuffer* pFramebuffer;
OpenGLProgram* pProgram; OpenGLProgram* pProgram;
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "opengl/salbmp.hxx" #include "opengl/salbmp.hxx"
#include "opengl/program.hxx" #include "opengl/program.hxx"
#include "opengl/texture.hxx" #include "opengl/texture.hxx"
#include "opengl/RenderState.hxx"
#include <ResampleKernel.hxx> #include <ResampleKernel.hxx>
...@@ -327,6 +328,7 @@ bool OpenGLSalBitmap::ImplScale( const double& rScaleX, const double& rScaleY, B ...@@ -327,6 +328,7 @@ bool OpenGLSalBitmap::ImplScale( const double& rScaleX, const double& rScaleY, B
mpUserBuffer.reset(); mpUserBuffer.reset();
OpenGLVCLContextZone aContextZone; OpenGLVCLContextZone aContextZone;
rtl::Reference<OpenGLContext> xContext = OpenGLContext::getVCLContext(); rtl::Reference<OpenGLContext> xContext = OpenGLContext::getVCLContext();
xContext->state()->scissor().disable();
if (rScaleX <= 1 && rScaleY <= 1) if (rScaleX <= 1 && rScaleY <= 1)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment