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

vcl: Read back OpenGL FBO to create offscreen X11 pixmap

Change-Id: I330e7d62bf31b4a90b5866d9531f073f7c69c92a
üst c7a5ce27
...@@ -86,8 +86,8 @@ protected: ...@@ -86,8 +86,8 @@ protected:
void DrawRect( long nX, long nY, long nWidth, long nHeight ); void DrawRect( long nX, long nY, long nWidth, long nHeight );
void DrawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry ); void DrawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry );
void DrawPolyPolygon( const basegfx::B2DPolyPolygon& rPolyPolygon ); void DrawPolyPolygon( const basegfx::B2DPolyPolygon& rPolyPolygon );
void DrawTextureRect( const Size& rSize, const SalTwoRect& rPosAry ); void DrawTextureRect( const Size& rSize, const SalTwoRect& rPosAry, bool bInverted = false );
void DrawTexture( GLuint nTexture, const Size& rSize, const SalTwoRect& rPosAry ); void DrawTexture( GLuint nTexture, const Size& rSize, const SalTwoRect& rPosAry, bool bInverted = false );
void DrawTextureWithMask( GLuint nTexture, GLuint nMask, const Size& rSize, const SalTwoRect& rPosAry ); void DrawTextureWithMask( GLuint nTexture, GLuint nMask, const Size& rSize, const SalTwoRect& rPosAry );
void DrawMask( GLuint nMask, SalColor nMaskColor, const SalTwoRect& rPosAry ); void DrawMask( GLuint nMask, SalColor nMaskColor, const SalTwoRect& rPosAry );
void DrawLinearGradient( const Gradient& rGradient, const Rectangle& rRect ); void DrawLinearGradient( const Gradient& rGradient, const Rectangle& rRect );
......
...@@ -503,14 +503,23 @@ void OpenGLSalGraphicsImpl::DrawPolyPolygon( const basegfx::B2DPolyPolygon& rPol ...@@ -503,14 +503,23 @@ void OpenGLSalGraphicsImpl::DrawPolyPolygon( const basegfx::B2DPolyPolygon& rPol
glDisableVertexAttribArray( GL_ATTRIB_POS ); glDisableVertexAttribArray( GL_ATTRIB_POS );
} }
void OpenGLSalGraphicsImpl::DrawTextureRect( const Size& rSize, const SalTwoRect& rPosAry ) void OpenGLSalGraphicsImpl::DrawTextureRect( const Size& rSize, const SalTwoRect& rPosAry, bool bInverted )
{ {
GLfloat aTexCoord[8]; GLfloat aTexCoord[8];
aTexCoord[0] = aTexCoord[2] = rPosAry.mnSrcX / (double) rSize.Width(); aTexCoord[0] = aTexCoord[2] = rPosAry.mnSrcX / (double) rSize.Width();
aTexCoord[4] = aTexCoord[6] = (rPosAry.mnSrcX + rPosAry.mnSrcWidth) / (double) rSize.Width(); aTexCoord[4] = aTexCoord[6] = (rPosAry.mnSrcX + rPosAry.mnSrcWidth) / (double) rSize.Width();
aTexCoord[3] = aTexCoord[5] = (rSize.Height() - rPosAry.mnSrcY) / (double) rSize.Height();
aTexCoord[1] = aTexCoord[7] = (rSize.Height() - rPosAry.mnSrcY - rPosAry.mnSrcHeight) / (double) rSize.Height(); if( !bInverted )
{
aTexCoord[3] = aTexCoord[5] = (rSize.Height() - rPosAry.mnSrcY) / (double) rSize.Height();
aTexCoord[1] = aTexCoord[7] = (rSize.Height() - rPosAry.mnSrcY - rPosAry.mnSrcHeight) / (double) rSize.Height();
}
else
{
aTexCoord[1] = aTexCoord[7] = (rSize.Height() - rPosAry.mnSrcY) / (double) rSize.Height();
aTexCoord[3] = aTexCoord[5] = (rSize.Height() - rPosAry.mnSrcY - rPosAry.mnSrcHeight) / (double) rSize.Height();
}
glEnableVertexAttribArray( GL_ATTRIB_TEX ); glEnableVertexAttribArray( GL_ATTRIB_TEX );
glVertexAttribPointer( GL_ATTRIB_TEX, 2, GL_FLOAT, GL_FALSE, 0, aTexCoord ); glVertexAttribPointer( GL_ATTRIB_TEX, 2, GL_FLOAT, GL_FALSE, 0, aTexCoord );
...@@ -520,7 +529,7 @@ void OpenGLSalGraphicsImpl::DrawTextureRect( const Size& rSize, const SalTwoRect ...@@ -520,7 +529,7 @@ void OpenGLSalGraphicsImpl::DrawTextureRect( const Size& rSize, const SalTwoRect
glDisableVertexAttribArray( GL_ATTRIB_TEX ); glDisableVertexAttribArray( GL_ATTRIB_TEX );
} }
void OpenGLSalGraphicsImpl::DrawTexture( GLuint nTexture, const Size& rSize, const SalTwoRect& pPosAry ) void OpenGLSalGraphicsImpl::DrawTexture( GLuint nTexture, const Size& rSize, const SalTwoRect& pPosAry, bool bInverted )
{ {
if( mnTextureProgram == 0 ) if( mnTextureProgram == 0 )
{ {
...@@ -534,7 +543,7 @@ void OpenGLSalGraphicsImpl::DrawTexture( GLuint nTexture, const Size& rSize, con ...@@ -534,7 +543,7 @@ void OpenGLSalGraphicsImpl::DrawTexture( GLuint nTexture, const Size& rSize, con
CHECK_GL_ERROR(); CHECK_GL_ERROR();
glBindTexture( GL_TEXTURE_2D, nTexture ); glBindTexture( GL_TEXTURE_2D, nTexture );
DrawTextureRect( rSize, pPosAry ); DrawTextureRect( rSize, pPosAry, bInverted );
CHECK_GL_ERROR(); CHECK_GL_ERROR();
glBindTexture( GL_TEXTURE_2D, 0 ); glBindTexture( GL_TEXTURE_2D, 0 );
......
...@@ -83,9 +83,38 @@ X11Pixmap* X11OpenGLSalGraphicsImpl::GetPixmapFromScreen( const Rectangle& rRect ...@@ -83,9 +83,38 @@ X11Pixmap* X11OpenGLSalGraphicsImpl::GetPixmapFromScreen( const Rectangle& rRect
{ {
Display* pDisplay = mrParent.GetXDisplay(); Display* pDisplay = mrParent.GetXDisplay();
SalX11Screen nScreen = mrParent.GetScreenNumber(); SalX11Screen nScreen = mrParent.GetScreenNumber();
XVisualInfo aVisualInfo;
X11Pixmap* pPixmap;
XImage* pImage;
sal_uInt8* pData;
SAL_INFO( "vcl.opengl", "GetPixmapFromScreen" ); SAL_INFO( "vcl.opengl", "GetPixmapFromScreen" );
return new X11Pixmap( pDisplay, nScreen, rRect.GetWidth(), rRect.GetHeight(), 24 ); // TODO: lfrb: Use context depth
pPixmap = new X11Pixmap( pDisplay, nScreen, rRect.GetWidth(), rRect.GetHeight(), 24 );
if( !OpenGLHelper::GetVisualInfo( pDisplay, nScreen.getXScreen(), aVisualInfo ) )
return pPixmap;
// make sure everything is synced up before reading back
maContext.makeCurrent();
glXWaitX();
// TODO: lfrb: What if offscreen?
pData = new sal_uInt8[rRect.GetWidth() * rRect.GetHeight() * 4];
glPixelStorei( GL_PACK_ALIGNMENT, 1 );
glReadPixels( rRect.Left(), GetHeight() - rRect.Top(), rRect.GetWidth(), rRect.GetHeight(),
GL_RGBA, GL_UNSIGNED_BYTE, pData );
pImage = XCreateImage( pDisplay, aVisualInfo.visual, 24, ZPixmap, 0, (char*) pData,
rRect.GetWidth(), rRect.GetHeight(), 8, 0 );
XInitImage( pImage );
GC aGC = XCreateGC( pDisplay, pPixmap->GetPixmap(), 0, NULL );
XPutImage( pDisplay, pPixmap->GetDrawable(), aGC, pImage,
0, 0, 0, 0, rRect.GetWidth(), rRect.GetHeight() );
XFreeGC( pDisplay, aGC );
XDestroyImage( pImage );
return pPixmap;
} }
bool X11OpenGLSalGraphicsImpl::RenderPixmapToScreen( X11Pixmap* pPixmap, int nX, int nY ) bool X11OpenGLSalGraphicsImpl::RenderPixmapToScreen( X11Pixmap* pPixmap, int nX, int nY )
...@@ -128,7 +157,7 @@ bool X11OpenGLSalGraphicsImpl::RenderPixmapToScreen( X11Pixmap* pPixmap, int nX, ...@@ -128,7 +157,7 @@ bool X11OpenGLSalGraphicsImpl::RenderPixmapToScreen( X11Pixmap* pPixmap, int nX,
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
DrawTexture( nTexture, pPixmap->GetSize(), aPosAry ); DrawTexture( nTexture, pPixmap->GetSize(), aPosAry, !bInverted );
glXReleaseTexImageEXT( pDisplay, pGlxPixmap, GLX_FRONT_LEFT_EXT ); glXReleaseTexImageEXT( pDisplay, pGlxPixmap, GLX_FRONT_LEFT_EXT );
glDeleteTextures( 1, &nTexture ); glDeleteTextures( 1, &nTexture );
......
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