Kaydet (Commit) 3b450b17 authored tarafından Michael Meeks's avatar Michael Meeks Kaydeden (comit) Andras Timar

tdf#93772 - handle framebuffer unbinding on GL context switch.

Also start gl tests in vcldemo:
    $ SAL_FORCEGL=1 vcldemo --gltests

Change-Id: I8f0022770d57cd60c830659e3f7fcc0721320a10
Reviewed-on: https://gerrit.libreoffice.org/18135Reviewed-by: 's avatarJan Holesovsky <kendy@collabora.com>
Tested-by: 's avatarJan Holesovsky <kendy@collabora.com>
üst 0582c764
...@@ -63,6 +63,7 @@ class OpenGLFramebuffer; ...@@ -63,6 +63,7 @@ class OpenGLFramebuffer;
class OpenGLProgram; class OpenGLProgram;
class OpenGLTexture; class OpenGLTexture;
class SalGraphicsImpl; class SalGraphicsImpl;
class OpenGLTests;
/// Holds the information of our new child window /// Holds the information of our new child window
struct GLWindow struct GLWindow
...@@ -166,6 +167,7 @@ struct GLWindow ...@@ -166,6 +167,7 @@ struct GLWindow
class VCL_DLLPUBLIC OpenGLContext class VCL_DLLPUBLIC OpenGLContext
{ {
friend class OpenGLTests;
public: public:
OpenGLContext(); OpenGLContext();
~OpenGLContext(); ~OpenGLContext();
......
...@@ -15,7 +15,12 @@ $(eval $(call gb_Executable_use_api,vcldemo,\ ...@@ -15,7 +15,12 @@ $(eval $(call gb_Executable_use_api,vcldemo,\
udkapi \ udkapi \
)) ))
$(eval $(call gb_Executable_use_external,vcldemo,boost_headers)) $(eval $(call gb_Executable_use_externals,vcldemo,\
boost_headers \
glew \
glm_headers \
mesa_headers \
))
$(eval $(call gb_Executable_set_include,vcldemo,\ $(eval $(call gb_Executable_set_include,vcldemo,\
$$(INCLUDE) \ $$(INCLUDE) \
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include <opengl/texture.hxx> #include <opengl/texture.hxx>
class VCL_PLUGIN_PUBLIC OpenGLFramebuffer class VCL_DLLPUBLIC OpenGLFramebuffer
{ {
private: private:
GLuint mnId; GLuint mnId;
......
...@@ -79,7 +79,7 @@ public: ...@@ -79,7 +79,7 @@ public:
int FindFreeSlot(); int FindFreeSlot();
}; };
class VCL_PLUGIN_PUBLIC OpenGLTexture class VCL_DLLPUBLIC OpenGLTexture
{ {
private: private:
// if the rect size doesn't match the mpImpl one, this instance // if the rect size doesn't match the mpImpl one, this instance
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
class SalFrame; class SalFrame;
class SalVirtualDevice; class SalVirtualDevice;
class OpenGLTests;
namespace basegfx namespace basegfx
{ {
...@@ -46,8 +47,9 @@ struct TextureCombo ...@@ -46,8 +47,9 @@ struct TextureCombo
std::unique_ptr<OpenGLTexture> mpMask; std::unique_ptr<OpenGLTexture> mpMask;
}; };
class VCL_PLUGIN_PUBLIC OpenGLSalGraphicsImpl : public SalGraphicsImpl class VCL_DLLPUBLIC OpenGLSalGraphicsImpl : public SalGraphicsImpl
{ {
friend class OpenGLTests;
protected: protected:
OpenGLContext* mpContext; OpenGLContext* mpContext;
......
...@@ -32,8 +32,8 @@ OpenGLFramebuffer::~OpenGLFramebuffer() ...@@ -32,8 +32,8 @@ OpenGLFramebuffer::~OpenGLFramebuffer()
void OpenGLFramebuffer::Bind() void OpenGLFramebuffer::Bind()
{ {
glBindFramebuffer( GL_FRAMEBUFFER, mnId );
VCL_GL_INFO( "vcl.opengl", "Binding framebuffer " << (int)mnId ); VCL_GL_INFO( "vcl.opengl", "Binding framebuffer " << (int)mnId );
glBindFramebuffer( GL_FRAMEBUFFER, mnId );
CHECK_GL_ERROR(); CHECK_GL_ERROR();
} }
......
...@@ -1654,6 +1654,7 @@ void OpenGLContext::ReleaseFramebuffer( OpenGLFramebuffer* pFramebuffer ) ...@@ -1654,6 +1654,7 @@ void OpenGLContext::ReleaseFramebuffer( OpenGLFramebuffer* pFramebuffer )
void OpenGLContext::ReleaseFramebuffer( const OpenGLTexture& rTexture ) void OpenGLContext::ReleaseFramebuffer( const OpenGLTexture& rTexture )
{ {
OpenGLZone aZone; OpenGLZone aZone;
OpenGLFramebuffer* pFramebuffer = mpLastFramebuffer; OpenGLFramebuffer* pFramebuffer = mpLastFramebuffer;
while( pFramebuffer ) while( pFramebuffer )
...@@ -1662,6 +1663,8 @@ void OpenGLContext::ReleaseFramebuffer( const OpenGLTexture& rTexture ) ...@@ -1662,6 +1663,8 @@ void OpenGLContext::ReleaseFramebuffer( const OpenGLTexture& rTexture )
{ {
BindFramebuffer( pFramebuffer ); BindFramebuffer( pFramebuffer );
pFramebuffer->DetachTexture(); pFramebuffer->DetachTexture();
if (mpCurrentFramebuffer == pFramebuffer)
BindFramebuffer( NULL );
} }
pFramebuffer = pFramebuffer->mpPrevFramebuffer; pFramebuffer = pFramebuffer->mpPrevFramebuffer;
} }
...@@ -1670,6 +1673,7 @@ void OpenGLContext::ReleaseFramebuffer( const OpenGLTexture& rTexture ) ...@@ -1670,6 +1673,7 @@ void OpenGLContext::ReleaseFramebuffer( const OpenGLTexture& rTexture )
void OpenGLContext::ReleaseFramebuffers() void OpenGLContext::ReleaseFramebuffers()
{ {
OpenGLZone aZone; OpenGLZone aZone;
OpenGLFramebuffer* pFramebuffer = mpLastFramebuffer; OpenGLFramebuffer* pFramebuffer = mpLastFramebuffer;
while( pFramebuffer ) while( pFramebuffer )
{ {
...@@ -1680,6 +1684,7 @@ void OpenGLContext::ReleaseFramebuffers() ...@@ -1680,6 +1684,7 @@ void OpenGLContext::ReleaseFramebuffers()
} }
pFramebuffer = pFramebuffer->mpPrevFramebuffer; pFramebuffer = pFramebuffer->mpPrevFramebuffer;
} }
BindFramebuffer( NULL );
} }
OpenGLProgram* OpenGLContext::GetProgram( const OUString& rVertexShader, const OUString& rFragmentShader, const OString& preamble ) OpenGLProgram* OpenGLContext::GetProgram( const OUString& rVertexShader, const OUString& rFragmentShader, const OString& preamble )
......
...@@ -43,6 +43,14 @@ ...@@ -43,6 +43,14 @@
#include <vcldemo-debug.hxx> #include <vcldemo-debug.hxx>
#include <opengl/zone.hxx> #include <opengl/zone.hxx>
// internal headers for OpenGLTests class.
#include "salgdi.hxx"
#include "salframe.hxx"
#include "openglgdiimpl.hxx"
#include "opengl/texture.hxx"
#include "opengl/framebuffer.hxx"
#include <vcl/opengl/OpenGLHelper.hxx>
#include <rtl/math.hxx> #include <rtl/math.hxx>
#define FIXME_SELF_INTERSECTING_WORKING 0 #define FIXME_SELF_INTERSECTING_WORKING 0
...@@ -1627,6 +1635,71 @@ class DemoPopup : public FloatingWindow ...@@ -1627,6 +1635,71 @@ class DemoPopup : public FloatingWindow
} }
}; };
class OpenGLTests
{
VclPtr<WorkWindow> mxWinA;
VclPtr<WorkWindow> mxWinB;
OpenGLSalGraphicsImpl *mpImplA;
OpenGLSalGraphicsImpl *mpImplB;
OpenGLContext *mpA;
OpenGLContext *mpB;
OpenGLSalGraphicsImpl *getImpl(const VclPtr<WorkWindow> &xWin)
{
SalGraphics *pGraphics = xWin->GetGraphics();
return dynamic_cast<OpenGLSalGraphicsImpl *>(pGraphics->GetImpl());
}
public:
OpenGLTests() :
mxWinA(VclPtr<WorkWindow>::Create(nullptr, WB_APP | WB_STDWORK)),
mxWinB(VclPtr<WorkWindow>::Create(nullptr, WB_APP | WB_STDWORK))
{
if (!OpenGLHelper::isVCLOpenGLEnabled())
{
fprintf (stderr, "OpenGL is not enabled: try SAL_FORCEGL=1\n");
return;
}
mpImplA = getImpl(mxWinA);
mpImplB = getImpl(mxWinB);
assert (mpImplA && mpImplB);
mpA = mpImplA->GetOpenGLContext();
mpB = mpImplB->GetOpenGLContext();
assert (mpA && mpB);
}
~OpenGLTests()
{
mxWinB.disposeAndClear();
mxWinA.disposeAndClear();
}
void testCurrentFramebuffer()
{
fprintf(stderr,"test OpenGLContext's framebuffer association.\n");
mpA->makeCurrent();
OpenGLFramebuffer *pBuffer;
{
OpenGLTexture aTexture(256,128);
pBuffer = mpA->AcquireFramebuffer(aTexture);
pBuffer->DetachTexture(); // TESTME - remove this line too ...
}
assert (pBuffer->IsFree());
mpB->makeCurrent();
assert (mpA->mpCurrentFramebuffer == NULL);
}
int execute()
{
if (!OpenGLHelper::isVCLOpenGLEnabled())
return 1;
testCurrentFramebuffer();
return 0;
}
};
class DemoApp : public Application class DemoApp : public Application
{ {
static int showHelp(DemoRenderer &rRenderer) static int showHelp(DemoRenderer &rRenderer)
...@@ -1640,6 +1713,7 @@ class DemoApp : public Application ...@@ -1640,6 +1713,7 @@ class DemoApp : public Application
fprintf(stderr," --test <iterCount> - create benchmark data\n"); fprintf(stderr," --test <iterCount> - create benchmark data\n");
fprintf(stderr," --widgets - launch the widget test.\n"); fprintf(stderr," --widgets - launch the widget test.\n");
fprintf(stderr," --threads - render from multiple threads.\n"); fprintf(stderr," --threads - render from multiple threads.\n");
fprintf(stderr," --gltest - run openGL regression tests.\n");
fprintf(stderr, "\n"); fprintf(stderr, "\n");
return 0; return 0;
} }
...@@ -1651,7 +1725,8 @@ public: ...@@ -1651,7 +1725,8 @@ public:
{ {
try try
{ {
bool bWidgets = false, bThreads = false, bPopup = false; bool bWidgets = false, bThreads = false;
bool bPopup = false, bGLTest = false;
DemoRenderer aRenderer; DemoRenderer aRenderer;
for (sal_Int32 i = 0; i < GetCommandLineParamCount(); i++) for (sal_Int32 i = 0; i < GetCommandLineParamCount(); i++)
...@@ -1678,6 +1753,8 @@ public: ...@@ -1678,6 +1753,8 @@ public:
bWidgets = true; bWidgets = true;
else if (aArg == "--popup") else if (aArg == "--popup")
bPopup = true; bPopup = true;
else if (aArg == "--gltest")
bGLTest = true;
else if (aArg == "--threads") else if (aArg == "--threads")
bThreads = true; bThreads = true;
else if (aArg.startsWith("--")) else if (aArg.startsWith("--"))
...@@ -1694,7 +1771,12 @@ public: ...@@ -1694,7 +1771,12 @@ public:
aMainWin->SetText("Interactive VCL demo #1"); aMainWin->SetText("Interactive VCL demo #1");
if (bWidgets) if (bGLTest)
{
OpenGLTests aTests;
return aTests.execute();
}
else if (bWidgets)
xWidgets = VclPtr< DemoWidgets >::Create (); xWidgets = VclPtr< DemoWidgets >::Create ();
else if (bPopup) else if (bPopup)
xPopup = VclPtrInstance< DemoPopup> (); xPopup = VclPtrInstance< DemoPopup> ();
......
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