Kaydet (Commit) a6fee2ca authored tarafından Louis-Francis Ratté-Boulianne's avatar Louis-Francis Ratté-Boulianne Kaydeden (comit) Markus Mohrhard

vcl: Use scissor or stencil for clipping in OpenGL backend

Change-Id: Ib6620572391999d5f8124a1a8695909d6c48643d
üst c4e494bc
...@@ -102,6 +102,8 @@ public: ...@@ -102,6 +102,8 @@ public:
void SetEmpty(); void SetEmpty();
void SetNull(); void SetNull();
bool IsRectangle() const;
Rectangle GetBoundRect() const; Rectangle GetBoundRect() const;
bool HasPolyPolygonOrB2DPolyPolygon() const { return (getB2DPolyPolygon() || getPolyPolygon()); } bool HasPolyPolygonOrB2DPolyPolygon() const { return (getB2DPolyPolygon() || getPolyPolygon()); }
void GetRegionRectangles(RectangleVector& rTarget) const; void GetRegionRectangles(RectangleVector& rTarget) const;
...@@ -144,9 +146,7 @@ inline std::basic_ostream<charT, traits> & operator <<( ...@@ -144,9 +146,7 @@ inline std::basic_ostream<charT, traits> & operator <<(
<< *rRegion.getB2DPolyPolygon() << *rRegion.getB2DPolyPolygon()
<< ")"; << ")";
if (rRegion.getPolyPolygon()) if (rRegion.getPolyPolygon())
return stream << "PolyPolygon(" return stream << "unimplemented";
<< *rRegion.getPolyPolygon()
<< ")";
if (rRegion.getRegionBand()) if (rRegion.getRegionBand())
{ // inlined because RegionBand is private to vcl { // inlined because RegionBand is private to vcl
stream << "RegionBand("; stream << "RegionBand(";
......
...@@ -40,6 +40,10 @@ protected: ...@@ -40,6 +40,10 @@ protected:
SalVirtualDevice* mpVDev; SalVirtualDevice* mpVDev;
int mnPainting; int mnPainting;
// clipping
bool mbUseScissor;
bool mbUseStencil;
bool mbOffscreen; bool mbOffscreen;
GLuint mnFramebufferId; GLuint mnFramebufferId;
OpenGLTextureSharedPtr mpOffscreenTex; OpenGLTextureSharedPtr mpOffscreenTex;
......
...@@ -61,6 +61,8 @@ ...@@ -61,6 +61,8 @@
OpenGLSalGraphicsImpl::OpenGLSalGraphicsImpl() OpenGLSalGraphicsImpl::OpenGLSalGraphicsImpl()
: mpFrame(NULL) : mpFrame(NULL)
, mnPainting(0) , mnPainting(0)
, mbUseScissor(false)
, mbUseStencil(false)
, mbOffscreen(false) , mbOffscreen(false)
, mnFramebufferId(0) , mnFramebufferId(0)
, mpOffscreenTex(nullptr) , mpOffscreenTex(nullptr)
...@@ -97,6 +99,10 @@ void OpenGLSalGraphicsImpl::PreDraw() ...@@ -97,6 +99,10 @@ void OpenGLSalGraphicsImpl::PreDraw()
if( mbOffscreen ) if( mbOffscreen )
glBindFramebuffer( GL_FRAMEBUFFER, mnFramebufferId ); glBindFramebuffer( GL_FRAMEBUFFER, mnFramebufferId );
glViewport( 0, 0, GetWidth(), GetHeight() ); glViewport( 0, 0, GetWidth(), GetHeight() );
if( mbUseScissor )
glEnable( GL_SCISSOR_TEST );
if( mbUseStencil )
glEnable( GL_STENCIL_TEST );
CHECK_GL_ERROR(); CHECK_GL_ERROR();
} }
...@@ -105,8 +111,12 @@ void OpenGLSalGraphicsImpl::PostDraw() ...@@ -105,8 +111,12 @@ void OpenGLSalGraphicsImpl::PostDraw()
{ {
if( mbOffscreen ) if( mbOffscreen )
glBindFramebuffer( GL_FRAMEBUFFER, 0 ); glBindFramebuffer( GL_FRAMEBUFFER, 0 );
if( mnPainting == 0 ) else if( mnPainting == 0 )
glFlush(); glFlush();
if( mbUseScissor )
glDisable( GL_SCISSOR_TEST );
if( mbUseStencil )
glDisable( GL_STENCIL_TEST );
CHECK_GL_ERROR(); CHECK_GL_ERROR();
} }
...@@ -117,28 +127,46 @@ void OpenGLSalGraphicsImpl::freeResources() ...@@ -117,28 +127,46 @@ void OpenGLSalGraphicsImpl::freeResources()
bool OpenGLSalGraphicsImpl::setClipRegion( const vcl::Region& rClip ) bool OpenGLSalGraphicsImpl::setClipRegion( const vcl::Region& rClip )
{ {
const basegfx::B2DPolyPolygon aClip( rClip.GetAsB2DPolyPolygon() ); SAL_INFO( "vcl.opengl", "::setClipRegion " << rClip );
SAL_INFO( "vcl.opengl", "::setClipRegion" ); if( rClip.IsEmpty() )
{
ResetClipRegion();
return true;
}
/*maContext.makeCurrent(); if( false ) //rClip.IsRectangle() )
glViewport( 0, 0, GetWidth(), GetHeight() ); {
Rectangle aRect( rClip.GetBoundRect() );
glEnable( GL_STENCIL_TEST ); mbUseStencil = false;
mbUseScissor = true;
maContext.makeCurrent();
glScissor( aRect.Left(), GetHeight() - aRect.Top(), aRect.GetWidth(), aRect.GetHeight() );
}
else
{
mbUseStencil = true;
mbUseScissor = false;
maContext.makeCurrent();
glViewport( 0, 0, GetWidth(), GetHeight() );
glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE ); glEnable( GL_STENCIL_TEST );
glStencilMask( 0xFF ); glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
glStencilFunc( GL_NEVER, 1, 0xFF ); glStencilMask( 0xFF );
glStencilOp( GL_REPLACE, GL_KEEP, GL_KEEP ); glStencilFunc( GL_NEVER, 1, 0xFF );
glStencilOp( GL_REPLACE, GL_KEEP, GL_KEEP );
glClear( GL_STENCIL_BUFFER_BIT ); glClear( GL_STENCIL_BUFFER_BIT );
BeginSolid( SALCOLOR_NONE ); BeginSolid( SALCOLOR_NONE );
DrawPolyPolygon( aClip ); DrawPolyPolygon( rClip.GetAsB2DPolyPolygon() );
EndSolid(); EndSolid();
glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE ); glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
glStencilMask( 0x00 ); glStencilMask( 0x00 );
glStencilFunc( GL_EQUAL, 1, 0xFF );*/ glStencilFunc( GL_EQUAL, 1, 0xFF );
glDisable( GL_STENCIL_TEST );
}
return true; return true;
} }
...@@ -147,10 +175,8 @@ bool OpenGLSalGraphicsImpl::setClipRegion( const vcl::Region& rClip ) ...@@ -147,10 +175,8 @@ bool OpenGLSalGraphicsImpl::setClipRegion( const vcl::Region& rClip )
void OpenGLSalGraphicsImpl::ResetClipRegion() void OpenGLSalGraphicsImpl::ResetClipRegion()
{ {
SAL_INFO( "vcl.opengl", "::ResetClipRegion" ); SAL_INFO( "vcl.opengl", "::ResetClipRegion" );
maContext.makeCurrent(); mbUseScissor = false;
glDisable(GL_STENCIL_TEST); mbUseStencil = false;
CHECK_GL_ERROR();
} }
// get the depth of the device // get the depth of the device
......
...@@ -1434,6 +1434,23 @@ bool vcl::Region::IsOver( const Rectangle& rRect ) const ...@@ -1434,6 +1434,23 @@ bool vcl::Region::IsOver( const Rectangle& rRect ) const
return !aRegion.IsEmpty(); return !aRegion.IsEmpty();
} }
bool vcl::Region::IsRectangle() const
{
if( IsEmpty() || IsNull() )
return false;
if( getB2DPolyPolygon() )
return basegfx::tools::isRectangle( *getB2DPolyPolygon() );
if( getPolyPolygon() )
return getPolyPolygon()->IsRect();
if( getRegionBand() )
return (getRegionBand()->getRectangleCount() == 1);
return false;
}
void vcl::Region::SetNull() void vcl::Region::SetNull()
{ {
// reset all content // reset all content
......
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