diff options
author | Tor Lillqvist <tml@collabora.com> | 2015-11-17 09:20:25 +0200 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2015-11-17 09:28:02 +0200 |
commit | da11e337441f747155fa75c19263df70bfe6c543 (patch) | |
tree | 6e9741d41bcfe6b446bd2cfc930584667dd4742c | |
parent | e1d88a574562b5c36b01eafdaa0670e5cc1a7c39 (diff) |
Check for OpenGL errors right where an error might be generated
CHECK_GL_ERROR() is now zero-cost in a production build, so no reason
to avoid it.
Don't check for OpenGL errors after glX or wgl calls. They don't
generate OpenGL errors but use the X and Win32 error mechanisms, as
far as I see.
Change-Id: I8f97ef434cbdc89d6e345a247456cfc4a1a82bb6
-rw-r--r-- | vcl/opengl/framebuffer.cxx | 11 | ||||
-rw-r--r-- | vcl/opengl/gdiimpl.cxx | 60 | ||||
-rw-r--r-- | vcl/opengl/program.cxx | 31 | ||||
-rw-r--r-- | vcl/opengl/texture.cxx | 61 | ||||
-rw-r--r-- | vcl/opengl/x11/gdiimpl.cxx | 4 | ||||
-rw-r--r-- | vcl/source/opengl/OpenGLContext.cxx | 2 |
6 files changed, 123 insertions, 46 deletions
diff --git a/vcl/opengl/framebuffer.cxx b/vcl/opengl/framebuffer.cxx index 0c2cca920ed9..842c4279829a 100644 --- a/vcl/opengl/framebuffer.cxx +++ b/vcl/opengl/framebuffer.cxx @@ -22,12 +22,14 @@ OpenGLFramebuffer::OpenGLFramebuffer() : mpNextFramebuffer( nullptr ) { glGenFramebuffers( 1, &mnId ); + CHECK_GL_ERROR(); VCL_GL_INFO( "vcl.opengl", "Created framebuffer " << (int)mnId ); } OpenGLFramebuffer::~OpenGLFramebuffer() { glDeleteFramebuffers( 1, &mnId ); + CHECK_GL_ERROR(); } void OpenGLFramebuffer::Bind() @@ -40,8 +42,8 @@ void OpenGLFramebuffer::Bind() void OpenGLFramebuffer::Unbind() { glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - VCL_GL_INFO( "vcl.opengl", "Binding default framebuffer" ); CHECK_GL_ERROR(); + VCL_GL_INFO( "vcl.opengl", "Binding default framebuffer" ); } bool OpenGLFramebuffer::IsFree() const @@ -69,18 +71,19 @@ void OpenGLFramebuffer::AttachTexture( const OpenGLTexture& rTexture ) mnWidth = rTexture.GetWidth(); mnHeight = rTexture.GetHeight(); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mnAttachedTexture, 0); - if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) + CHECK_GL_ERROR(); + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + CHECK_GL_ERROR(); + if (status != GL_FRAMEBUFFER_COMPLETE) { SAL_WARN("vcl.opengl", "Framebuffer incomplete"); } - CHECK_GL_ERROR(); } void OpenGLFramebuffer::DetachTexture() { if( mnAttachedTexture != 0 ) { - CHECK_GL_ERROR(); mnAttachedTexture = 0; glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0 ); CHECK_GL_ERROR(); diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx index 51dbc5ae8b56..f954a01700c5 100644 --- a/vcl/opengl/gdiimpl.cxx +++ b/vcl/opengl/gdiimpl.cxx @@ -177,6 +177,7 @@ void OpenGLSalGraphicsImpl::PreDraw() CHECK_GL_ERROR(); glViewport( 0, 0, GetWidth(), GetHeight() ); + CHECK_GL_ERROR(); ImplInitClipRegion(); CHECK_GL_ERROR(); @@ -187,9 +188,15 @@ void OpenGLSalGraphicsImpl::PostDraw() if( !mbOffscreen && mpContext->mnPainting == 0 ) glFlush(); if( mbUseScissor ) + { glDisable( GL_SCISSOR_TEST ); - if( mbUseStencil ) + CHECK_GL_ERROR(); + } + if( mbUseStencil ) + { glDisable( GL_STENCIL_TEST ); + CHECK_GL_ERROR(); + } if( mpProgram ) { mpProgram->Clean(); @@ -198,8 +205,6 @@ void OpenGLSalGraphicsImpl::PostDraw() mProgramIsSolidColor = false; #endif } - - CHECK_GL_ERROR(); OpenGLZone::leave(); } @@ -222,12 +227,18 @@ void OpenGLSalGraphicsImpl::freeResources() void OpenGLSalGraphicsImpl::ImplSetClipBit( const vcl::Region& rClip, GLuint nMask ) { glEnable( GL_STENCIL_TEST ); + CHECK_GL_ERROR(); glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE ); + CHECK_GL_ERROR(); glStencilMask( nMask ); + CHECK_GL_ERROR(); glStencilFunc( GL_NEVER, nMask, 0xFF ); + CHECK_GL_ERROR(); glStencilOp( GL_REPLACE, GL_KEEP, GL_KEEP ); + CHECK_GL_ERROR(); glClear( GL_STENCIL_BUFFER_BIT ); + CHECK_GL_ERROR(); if( UseSolid( MAKE_SALCOLOR( 0xFF, 0xFF, 0xFF ) ) ) { if( rClip.getRegionBand() ) @@ -237,9 +248,10 @@ void OpenGLSalGraphicsImpl::ImplSetClipBit( const vcl::Region& rClip, GLuint nMa } glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE ); + CHECK_GL_ERROR(); glStencilMask( 0x00 ); + CHECK_GL_ERROR(); glDisable( GL_STENCIL_TEST ); - CHECK_GL_ERROR(); } @@ -253,6 +265,7 @@ void OpenGLSalGraphicsImpl::ImplInitClipRegion() { Rectangle aRect( maClipRegion.GetBoundRect() ); glScissor( aRect.Left(), GetHeight() - aRect.Bottom() - 1, aRect.GetWidth() + 1, aRect.GetHeight() + 1 ); + CHECK_GL_ERROR(); } else if( !maClipRegion.IsEmpty() ) { @@ -261,14 +274,17 @@ void OpenGLSalGraphicsImpl::ImplInitClipRegion() } if( mbUseScissor ) + { glEnable( GL_SCISSOR_TEST ); + CHECK_GL_ERROR(); + } if( mbUseStencil ) { glStencilFunc( GL_EQUAL, 1, 0x1 ); + CHECK_GL_ERROR(); glEnable( GL_STENCIL_TEST ); + CHECK_GL_ERROR(); } - - CHECK_GL_ERROR(); } const vcl::Region& OpenGLSalGraphicsImpl::getClipRegion() const @@ -477,7 +493,6 @@ void OpenGLSalGraphicsImpl::DrawPoint( long nX, long nY ) ApplyProgramMatrices(0.5f); mpProgram->SetVertices( pPoint ); glDrawArrays( GL_POINTS, 0, 1 ); - CHECK_GL_ERROR(); } @@ -495,7 +510,6 @@ void OpenGLSalGraphicsImpl::DrawLine( double nX1, double nY1, double nX2, double ApplyProgramMatrices(0.5f); mpProgram->SetVertices( pPoints ); glDrawArrays( GL_LINES, 0, 2 ); - CHECK_GL_ERROR(); } @@ -517,8 +531,6 @@ void OpenGLSalGraphicsImpl::DrawLineAA( double nX1, double nY1, double nX2, doub return; } ImplDrawLineAA( nX1, nY1, nX2, nY2 ); - - CHECK_GL_ERROR(); } void OpenGLSalGraphicsImpl::ImplDrawLineAA( double nX1, double nY1, double nX2, double nY2, bool edge ) @@ -655,7 +667,6 @@ void OpenGLSalGraphicsImpl::ImplDrawLineAA( double nX1, double nY1, double nX2, mpProgram->SetTextureCoord( aTexCoord ); mpProgram->SetVertices( vertices ); glDrawArrays(GL_TRIANGLE_STRIP, 0, 8); - CHECK_GL_ERROR(); } @@ -692,6 +703,7 @@ void OpenGLSalGraphicsImpl::DrawConvexPolygon( sal_uInt32 nPoints, const SalPoin ApplyProgramMatrices(); mpProgram->SetVertices( &aVertices[0] ); glDrawArrays( GL_TRIANGLE_FAN, 0, nPoints ); + CHECK_GL_ERROR(); if( !blockAA && mrParent.getAntiAliasB2DDraw()) { @@ -715,8 +727,6 @@ void OpenGLSalGraphicsImpl::DrawConvexPolygon( sal_uInt32 nPoints, const SalPoin UseSolid( lastSolidColor, lastSolidTransparency ); } } - - CHECK_GL_ERROR(); } void OpenGLSalGraphicsImpl::DrawConvexPolygon( const tools::Polygon& rPolygon, bool blockAA ) @@ -737,6 +747,7 @@ void OpenGLSalGraphicsImpl::DrawConvexPolygon( const tools::Polygon& rPolygon, b ApplyProgramMatrices(); mpProgram->SetVertices( &aVertices[0] ); glDrawArrays( GL_TRIANGLE_FAN, 0, nPoints ); + CHECK_GL_ERROR(); if( !blockAA && mrParent.getAntiAliasB2DDraw()) { @@ -760,8 +771,6 @@ void OpenGLSalGraphicsImpl::DrawConvexPolygon( const tools::Polygon& rPolygon, b UseSolid( lastSolidColor, lastSolidTransparency ); } } - - CHECK_GL_ERROR(); } void OpenGLSalGraphicsImpl::DrawTrapezoid( const basegfx::B2DTrapezoid& trapezoid, bool blockAA ) @@ -789,6 +798,7 @@ void OpenGLSalGraphicsImpl::DrawTrapezoid( const basegfx::B2DTrapezoid& trapezoi ApplyProgramMatrices(); mpProgram->SetVertices( &aVertices[0] ); glDrawArrays( GL_TRIANGLE_FAN, 0, nPoints ); + CHECK_GL_ERROR(); if( !blockAA && mrParent.getAntiAliasB2DDraw()) { @@ -812,8 +822,6 @@ void OpenGLSalGraphicsImpl::DrawTrapezoid( const basegfx::B2DTrapezoid& trapezoi UseSolid( lastSolidColor, lastSolidTransparency ); } } - - CHECK_GL_ERROR(); } void OpenGLSalGraphicsImpl::DrawRect( long nX, long nY, long nWidth, long nHeight ) @@ -904,7 +912,6 @@ void OpenGLSalGraphicsImpl::DrawRegionBand( const RegionBand& rRegion ) ApplyProgramMatrices(); mpProgram->SetVertices( &aVertices[0] ); glDrawArrays( GL_TRIANGLES, 0, aVertices.size() / 2 ); - CHECK_GL_ERROR(); } @@ -1026,9 +1033,8 @@ void OpenGLSalGraphicsImpl::DrawTransformedTexture( mpProgram->SetTextureCoord( aTexCoord ); mpProgram->SetVertices( &aVertices[0] ); glDrawArrays( GL_TRIANGLE_FAN, 0, 4 ); - mpProgram->Clean(); - CHECK_GL_ERROR(); + mpProgram->Clean(); } void OpenGLSalGraphicsImpl::DrawAlphaTexture( OpenGLTexture& rTexture, const SalTwoRect& rPosAry, bool bInverted, bool bPremultiplied ) @@ -1293,6 +1299,7 @@ void OpenGLSalGraphicsImpl::drawRect( long nX, long nY, long nWidth, long nHeigh ApplyProgramMatrices(0.5f); mpProgram->SetVertices(pPoints); glDrawArrays(GL_LINE_LOOP, 0, 4); + CHECK_GL_ERROR(); } PostDraw(); @@ -1614,9 +1621,9 @@ SalColor OpenGLSalGraphicsImpl::getPixel( long nX, long nY ) PreDraw(); nY = GetHeight() - nY - 1; glReadPixels( nX, nY, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, pixel); + CHECK_GL_ERROR(); PostDraw(); - CHECK_GL_ERROR(); return MAKE_SALCOLOR( pixel[0], pixel[1], pixel[2] ); } @@ -1689,9 +1696,12 @@ bool OpenGLSalGraphicsImpl::blendBitmap( VCL_GL_INFO( "vcl.opengl", "::blendBitmap" ); PreDraw(); glEnable( GL_BLEND ); + CHECK_GL_ERROR(); glBlendFunc( GL_ZERO, GL_SRC_COLOR ); + CHECK_GL_ERROR(); DrawTexture( rTexture, rPosAry ); glDisable( GL_BLEND ); + CHECK_GL_ERROR(); PostDraw(); return true; } @@ -1820,12 +1830,16 @@ bool OpenGLSalGraphicsImpl::drawGradient(const tools::PolyPolygon& rPolyPoly, if( mbUseStencil ) { glEnable( GL_STENCIL_TEST ); + CHECK_GL_ERROR(); glStencilFunc( GL_EQUAL, 3, 0xFF ); + CHECK_GL_ERROR(); } else { glEnable( GL_STENCIL_TEST ); + CHECK_GL_ERROR(); glStencilFunc( GL_EQUAL, 2, 0xFF ); + CHECK_GL_ERROR(); } #endif @@ -1854,11 +1868,13 @@ bool OpenGLSalGraphicsImpl::drawGradient(const tools::PolyPolygon& rPolyPoly, #if FIXME_BROKEN_STENCIL_FOR_GRADIENTS if( !mbUseStencil ) + { glDisable( GL_STENCIL_TEST ); + CHECK_GL_ERROR(); + } #endif PostDraw(); - CHECK_GL_ERROR(); return true; } diff --git a/vcl/opengl/program.cxx b/vcl/opengl/program.cxx index 0919c1ac8b09..588700b537d9 100644 --- a/vcl/opengl/program.cxx +++ b/vcl/opengl/program.cxx @@ -33,7 +33,10 @@ OpenGLProgram::~OpenGLProgram() { maUniformLocations.clear(); if( mnId != 0 ) + { glDeleteProgram( mnId ); + CHECK_GL_ERROR(); + } } bool OpenGLProgram::Load( const OUString& rVertexShader, @@ -51,6 +54,7 @@ bool OpenGLProgram::Use() return false; glUseProgram( mnId ); + CHECK_GL_ERROR(); return true; } @@ -64,6 +68,7 @@ bool OpenGLProgram::Clean() while( it != maTextures.rend() ) { glActiveTexture( GL_TEXTURE0 + nIndex-- ); + CHECK_GL_ERROR(); it->Unbind(); ++it; } @@ -76,7 +81,10 @@ bool OpenGLProgram::Clean() for( int i = 0; i < 32; i++ ) { if( mnEnabledAttribs & ( 1 << i ) ) + { glDisableVertexAttribArray( i ); + CHECK_GL_ERROR(); + } } mnEnabledAttribs = 0; } @@ -86,22 +94,27 @@ bool OpenGLProgram::Clean() { mbBlending = false; glDisable( GL_BLEND ); + CHECK_GL_ERROR(); } - CHECK_GL_ERROR(); return true; } void OpenGLProgram::SetVertexAttrib( GLuint& rAttrib, const OString& rName, const GLvoid* pData ) { if( rAttrib == SAL_MAX_UINT32 ) + { rAttrib = glGetAttribLocation( mnId, rName.getStr() ); + CHECK_GL_ERROR(); + } if( (mnEnabledAttribs & ( 1 << rAttrib )) == 0 ) { glEnableVertexAttribArray( rAttrib ); + CHECK_GL_ERROR(); mnEnabledAttribs |= ( 1 << rAttrib ); } glVertexAttribPointer( rAttrib, 2, GL_FLOAT, GL_FALSE, 0, pData ); + CHECK_GL_ERROR(); } void OpenGLProgram::SetVertices( const GLvoid* pData ) @@ -130,6 +143,7 @@ GLuint OpenGLProgram::GetUniformLocation( const OString& rName ) if( it == maUniformLocations.end() ) { GLuint nLocation = glGetUniformLocation( mnId, rName.getStr() ); + CHECK_GL_ERROR(); maUniformLocations[rName] = nLocation; return nLocation; } @@ -141,30 +155,35 @@ void OpenGLProgram::SetUniform1f( const OString& rName, GLfloat v1 ) { GLuint nUniform = GetUniformLocation( rName ); glUniform1f( nUniform, v1 ); + CHECK_GL_ERROR(); } void OpenGLProgram::SetUniform2f( const OString& rName, GLfloat v1, GLfloat v2 ) { GLuint nUniform = GetUniformLocation( rName ); glUniform2f( nUniform, v1, v2 ); + CHECK_GL_ERROR(); } void OpenGLProgram::SetUniform1fv( const OString& rName, GLsizei nCount, GLfloat* aValues ) { GLuint nUniform = GetUniformLocation( rName ); glUniform1fv( nUniform, nCount, aValues ); + CHECK_GL_ERROR(); } void OpenGLProgram::SetUniform2fv( const OString& rName, GLsizei nCount, GLfloat* aValues ) { GLuint nUniform = GetUniformLocation( rName ); glUniform2fv( nUniform, nCount, aValues ); + CHECK_GL_ERROR(); } void OpenGLProgram::SetUniform1i( const OString& rName, GLint v1 ) { GLuint nUniform = GetUniformLocation( rName ); glUniform1i( nUniform, v1 ); + CHECK_GL_ERROR(); } void OpenGLProgram::SetColor( const OString& rName, SalColor nColor, sal_uInt8 nTransparency ) @@ -175,6 +194,7 @@ void OpenGLProgram::SetColor( const OString& rName, SalColor nColor, sal_uInt8 n ((float) SALCOLOR_GREEN( nColor )) / 255, ((float) SALCOLOR_BLUE( nColor )) / 255, (100 - nTransparency) * (1.0 / 100) ); + CHECK_GL_ERROR(); if( nTransparency > 0 ) SetBlendMode( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); @@ -188,6 +208,7 @@ void OpenGLProgram::SetColorf( const OString& rName, SalColor nColor, double fTr ((float) SALCOLOR_GREEN( nColor )) / 255, ((float) SALCOLOR_BLUE( nColor )) / 255, (1.0f - fTransparency) ); + CHECK_GL_ERROR(); if( fTransparency > 0.0 ) SetBlendMode( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); @@ -201,6 +222,7 @@ void OpenGLProgram::SetColor( const OString& rName, const Color& rColor ) ((float) rColor.GetGreen()) / 255, ((float) rColor.GetBlue()) / 255, 1.0f - ((float) rColor.GetTransparency()) / 255 ); + CHECK_GL_ERROR(); if( rColor.GetTransparency() > 0 ) SetBlendMode( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); @@ -214,6 +236,7 @@ void OpenGLProgram::SetColorWithIntensity( const OString& rName, const Color& rC ((float) rColor.GetGreen()) * nFactor / 25500.0, ((float) rColor.GetBlue()) * nFactor / 25500.0, 1.0f ); + CHECK_GL_ERROR(); } void OpenGLProgram::SetTexture( const OString& rName, OpenGLTexture& rTexture ) @@ -222,7 +245,9 @@ void OpenGLProgram::SetTexture( const OString& rName, OpenGLTexture& rTexture ) int nIndex = maTextures.size(); glUniform1i( nUniform, nIndex ); + CHECK_GL_ERROR(); glActiveTexture( GL_TEXTURE0 + nIndex ); + CHECK_GL_ERROR(); rTexture.Bind(); maTextures.push_back( rTexture ); } @@ -249,6 +274,7 @@ void OpenGLProgram::SetTransform( (float) rNull.getX(), (float) rNull.getY(), 0, 1 }; glm::mat4 mMatrix = glm::make_mat4( aValues ); glUniformMatrix4fv( nUniform, 1, GL_FALSE, glm::value_ptr( mMatrix ) ); + CHECK_GL_ERROR(); } void OpenGLProgram::ApplyMatrix(float fWidth, float fHeight, float fPixelOffset) @@ -270,12 +296,15 @@ void OpenGLProgram::ApplyMatrix(float fWidth, float fHeight, float fPixelOffset) mMVP = glm::translate(mMVP, glm::vec3(fPixelOffset, fPixelOffset, 0.0f)); glUniformMatrix4fv(nUniform, 1, GL_FALSE, glm::value_ptr(mMVP)); + CHECK_GL_ERROR(); } void OpenGLProgram::SetBlendMode( GLenum nSFactor, GLenum nDFactor ) { glEnable( GL_BLEND ); + CHECK_GL_ERROR(); glBlendFunc( nSFactor, nDFactor ); + CHECK_GL_ERROR(); mbBlending = true; } diff --git a/vcl/opengl/texture.cxx b/vcl/opengl/texture.cxx index 909532682b7e..35984b9dd0c5 100644 --- a/vcl/opengl/texture.cxx +++ b/vcl/opengl/texture.cxx @@ -38,18 +38,26 @@ ImplOpenGLTexture::ImplOpenGLTexture( int nWidth, int nHeight, bool bAllocate ) mnFreeSlots(-1) { glGenTextures( 1, &mnTexture ); + CHECK_GL_ERROR(); glBindTexture( GL_TEXTURE_2D, mnTexture ); + CHECK_GL_ERROR(); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); + CHECK_GL_ERROR(); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); + CHECK_GL_ERROR(); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); + CHECK_GL_ERROR(); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); + CHECK_GL_ERROR(); if( bAllocate ) + { glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, nWidth, nHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr ); + CHECK_GL_ERROR(); + } glBindTexture( GL_TEXTURE_2D, 0 ); + CHECK_GL_ERROR(); VCL_GL_INFO( "vcl.opengl", "OpenGLTexture " << mnTexture << " " << nWidth << "x" << nHeight << " allocate" ); - - CHECK_GL_ERROR(); } // texture with content retrieved from FBO @@ -65,18 +73,23 @@ ImplOpenGLTexture::ImplOpenGLTexture( int nX, int nY, int nWidth, int nHeight ) // nY = GetHeight() - nHeight - nY; glGenTextures( 1, &mnTexture ); + CHECK_GL_ERROR(); glBindTexture( GL_TEXTURE_2D, mnTexture ); + CHECK_GL_ERROR(); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); + CHECK_GL_ERROR(); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); + CHECK_GL_ERROR(); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); + CHECK_GL_ERROR(); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); + CHECK_GL_ERROR(); glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, nX, nY, nWidth, nHeight, 0 ); CHECK_GL_ERROR(); glBindTexture( GL_TEXTURE_2D, 0 ); + CHECK_GL_ERROR(); VCL_GL_INFO( "vcl.opengl", "OpenGLTexture " << mnTexture << " " << nWidth << "x" << nHeight << " from x" << nX << ", y" << nY ); - - CHECK_GL_ERROR(); } // texture from buffer data @@ -89,19 +102,28 @@ ImplOpenGLTexture::ImplOpenGLTexture( int nWidth, int nHeight, int nFormat, int mnFreeSlots(-1) { if( !mnTexture ) + { glGenTextures( 1, &mnTexture ); + CHECK_GL_ERROR(); + } glBindTexture( GL_TEXTURE_2D, mnTexture ); + CHECK_GL_ERROR(); glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); + CHECK_GL_ERROR(); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); + CHECK_GL_ERROR(); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); + CHECK_GL_ERROR(); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); + CHECK_GL_ERROR(); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); + CHECK_GL_ERROR(); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, mnWidth, mnHeight, 0, nFormat, nType, pData ); + CHECK_GL_ERROR(); glBindTexture( GL_TEXTURE_2D, 0 ); + CHECK_GL_ERROR(); VCL_GL_INFO( "vcl.opengl", "OpenGLTexture " << mnTexture << " " << nWidth << "x" << nHeight << " from data" ); - - CHECK_GL_ERROR(); } ImplOpenGLTexture::~ImplOpenGLTexture() @@ -126,13 +148,16 @@ bool ImplOpenGLTexture::InsertBuffer(int nX, int nY, int nWidth, int nHeight, in if (!pData || mnTexture == 0) return false; glBindTexture(GL_TEXTURE_2D, mnTexture); + CHECK_GL_ERROR(); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + CHECK_GL_ERROR(); glTexSubImage2D(GL_TEXTURE_2D, 0, nX, mnHeight - nY - nHeight, nWidth, nHeight, nFormat, nType, pData); + CHECK_GL_ERROR(); glBindTexture(GL_TEXTURE_2D, 0); + CHECK_GL_ERROR(); VCL_GL_INFO( "vcl.opengl", "OpenGLTexture " << mnTexture << " Insert buff. to " << nX << " " << nY << " size " << nWidth << "x" << nHeight << " from data" ); - CHECK_GL_ERROR(); return true; } @@ -311,26 +336,28 @@ void OpenGLTexture::SetFilter( GLenum nFilter ) { mpImpl->mnFilter = nFilter; glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, nFilter ); + CHECK_GL_ERROR(); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, nFilter ); + CHECK_GL_ERROR(); } - - CHECK_GL_ERROR(); } void OpenGLTexture::Bind() { if( mpImpl ) + { glBindTexture( GL_TEXTURE_2D, mpImpl->mnTexture ); - - CHECK_GL_ERROR(); + CHECK_GL_ERROR(); + } } void OpenGLTexture::Unbind() { if( mpImpl ) + { glBindTexture( GL_TEXTURE_2D, 0 ); - - CHECK_GL_ERROR(); + CHECK_GL_ERROR(); + } } void OpenGLTexture::SaveToFile(const OUString& rFileName) @@ -349,8 +376,6 @@ void OpenGLTexture::SaveToFile(const OUString& rFileName) { SAL_WARN("vcl.opengl", "Error writing png to " << rFileName); } - - CHECK_GL_ERROR(); } void OpenGLTexture::Read( GLenum nFormat, GLenum nType, sal_uInt8* pData ) @@ -367,8 +392,10 @@ void OpenGLTexture::Read( GLenum nFormat, GLenum nType, sal_uInt8* pData ) { Bind(); glPixelStorei( GL_PACK_ALIGNMENT, 1 ); + CHECK_GL_ERROR(); // XXX: Call not available with GLES 2.0 glGetTexImage( GL_TEXTURE_2D, 0, nFormat, nType, pData ); + CHECK_GL_ERROR(); Unbind(); } else @@ -383,11 +410,11 @@ void OpenGLTexture::Read( GLenum nFormat, GLenum nType, sal_uInt8* pData ) rtl::Reference<OpenGLContext> pContext = pSVData->maGDIData.mpLastContext; OpenGLFramebuffer* pFramebuffer = pContext->AcquireFramebuffer(*this); glPixelStorei(GL_PACK_ALIGNMENT, 1); + CHECK_GL_ERROR(); glReadPixels(nX, nY, nWidth, nHeight, nFormat, nType, pData); + CHECK_GL_ERROR(); OpenGLContext::ReleaseFramebuffer(pFramebuffer); } - - CHECK_GL_ERROR(); } OpenGLTexture::operator bool() const diff --git a/vcl/opengl/x11/gdiimpl.cxx b/vcl/opengl/x11/gdiimpl.cxx index 20c45ffe108b..2418bc62f60e 100644 --- a/vcl/opengl/x11/gdiimpl.cxx +++ b/vcl/opengl/x11/gdiimpl.cxx @@ -96,8 +96,10 @@ bool X11OpenGLSalGraphicsImpl::FillPixmapFromScreen( X11Pixmap* pPixmap, int nX, // TODO: lfrb: What if offscreen? pData = static_cast<char*>(malloc( pPixmap->GetWidth() * pPixmap->GetHeight() * 4 )); glPixelStorei( GL_PACK_ALIGNMENT, 1 ); + CHECK_GL_ERROR(); glReadPixels( nX, GetHeight() - nY, pPixmap->GetWidth(), pPixmap->GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, pData ); + CHECK_GL_ERROR(); pImage = XCreateImage( pDisplay, aVisualInfo.visual, 24, ZPixmap, 0, pData, pPixmap->GetWidth(), pPixmap->GetHeight(), 8, 0 ); @@ -108,7 +110,6 @@ bool X11OpenGLSalGraphicsImpl::FillPixmapFromScreen( X11Pixmap* pPixmap, int nX, XFreeGC( pDisplay, aGC ); XDestroyImage( pImage ); - CHECK_GL_ERROR(); return true; } @@ -154,6 +155,7 @@ bool X11OpenGLSalGraphicsImpl::RenderPixmap(X11Pixmap* pPixmap, X11Pixmap* pMask rCombo.mpTexture.reset(new OpenGLTexture(pPixmap->GetWidth(), pPixmap->GetHeight(), false)); glActiveTexture( GL_TEXTURE0 ); + CHECK_GL_ERROR(); rCombo.mpTexture->Bind(); glXBindTexImageEXT( pDisplay, pGlxPixmap, GLX_FRONT_LEFT_EXT, nullptr ); rCombo.mpTexture->Unbind(); diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx index 6670489efce1..0c58120b8d78 100644 --- a/vcl/source/opengl/OpenGLContext.cxx +++ b/vcl/source/opengl/OpenGLContext.cxx @@ -197,7 +197,6 @@ int InitTempWindow(HWND *hwnd, int width, int height, const PIXELFORMATDESCRIPTO return -1; } - CHECK_GL_ERROR(); return 0; } @@ -1612,6 +1611,7 @@ OpenGLFramebuffer* OpenGLContext::AcquireFramebuffer( const OpenGLTexture& rText BindFramebuffer( pFramebuffer ); pFramebuffer->AttachTexture( rTexture ); glViewport( 0, 0, rTexture.GetWidth(), rTexture.GetHeight() ); + CHECK_GL_ERROR(); return pFramebuffer; } |