diff options
Diffstat (limited to 'vcl/opengl')
-rw-r--r-- | vcl/opengl/win/gdiimpl.cxx | 34 | ||||
-rw-r--r-- | vcl/opengl/x11/gdiimpl.cxx | 31 |
2 files changed, 43 insertions, 22 deletions
diff --git a/vcl/opengl/win/gdiimpl.cxx b/vcl/opengl/win/gdiimpl.cxx index 1704a19a7234..0d0159d25500 100644 --- a/vcl/opengl/win/gdiimpl.cxx +++ b/vcl/opengl/win/gdiimpl.cxx @@ -16,9 +16,10 @@ #include <win/saldata.hxx> #include <win/salframe.h> #include <win/salinst.h> -#include <GL/wglew.h> +#include <epoxy/wgl.h> static std::vector<HGLRC> g_vShareList; +static bool g_bAnyCurrent; class GLWinWindow : public GLWindow { @@ -70,6 +71,7 @@ void WinOpenGLContext::resetCurrent() OpenGLZone aZone; wglMakeCurrent(nullptr, nullptr); + g_bAnyCurrent = false; } bool WinOpenGLContext::isCurrent() @@ -81,7 +83,7 @@ bool WinOpenGLContext::isCurrent() bool WinOpenGLContext::isAnyCurrent() { - return wglGetCurrentContext() != nullptr; + return g_bAnyCurrent && wglGetCurrentContext() != nullptr; } void WinOpenGLContext::makeCurrent() @@ -95,10 +97,13 @@ void WinOpenGLContext::makeCurrent() if (!wglMakeCurrent(m_aGLWin.hDC, m_aGLWin.hRC)) { + g_bAnyCurrent = false; SAL_WARN("vcl.opengl", "wglMakeCurrent failed: " << WindowsErrorString(GetLastError())); return; } + g_bAnyCurrent = true; + registerAsCurrent(); } @@ -140,7 +145,10 @@ void WinOpenGLContext::destroyCurrentContext() g_vShareList.erase(itr); if (wglGetCurrentContext() != nullptr) + { wglMakeCurrent(nullptr, nullptr); + g_bAnyCurrent = false; + } wglDeleteContext( m_aGLWin.hRC ); ReleaseDC( m_aGLWin.hWnd, m_aGLWin.hDC ); m_aGLWin.hRC = nullptr; @@ -208,11 +216,13 @@ bool InitTempWindow(HWND& hwnd, int width, int height, const PIXELFORMATDESCRIPT if(!ret) { wglMakeCurrent(nullptr, nullptr); + g_bAnyCurrent = false; wglDeleteContext(glWin.hRC); ReleaseDC(hwnd, glWin.hDC); DestroyWindow(hwnd); return false; } + g_bAnyCurrent = false; return true; } @@ -275,6 +285,7 @@ bool InitMultisample(const PIXELFORMATDESCRIPTOR& pfd, int& rPixelFormat, { SAL_WARN("vcl.opengl", "Device doesn't support multisample"); wglMakeCurrent(nullptr, nullptr); + g_bAnyCurrent = false; wglDeleteContext(glWin.hRC); ReleaseDC(hWnd, glWin.hDC); DestroyWindow(hWnd); @@ -285,6 +296,7 @@ bool InitMultisample(const PIXELFORMATDESCRIPTOR& pfd, int& rPixelFormat, if (!fn_wglChoosePixelFormatARB) { wglMakeCurrent(nullptr, nullptr); + g_bAnyCurrent = false; wglDeleteContext(glWin.hRC); ReleaseDC(hWnd, glWin.hDC); DestroyWindow(hWnd); @@ -341,6 +353,7 @@ bool InitMultisample(const PIXELFORMATDESCRIPTOR& pfd, int& rPixelFormat, bArbMultisampleSupported = true; rPixelFormat = pixelFormat; wglMakeCurrent(nullptr, nullptr); + g_bAnyCurrent = false; wglDeleteContext(glWin.hRC); ReleaseDC(hWnd, glWin.hDC); DestroyWindow(hWnd); @@ -355,6 +368,7 @@ bool InitMultisample(const PIXELFORMATDESCRIPTOR& pfd, int& rPixelFormat, bArbMultisampleSupported = true; rPixelFormat = pixelFormat; wglMakeCurrent(nullptr, nullptr); + g_bAnyCurrent = false; wglDeleteContext(glWin.hRC); ReleaseDC(hWnd, glWin.hDC); DestroyWindow(hWnd); @@ -362,6 +376,7 @@ bool InitMultisample(const PIXELFORMATDESCRIPTOR& pfd, int& rPixelFormat, } // Return the valid format wglMakeCurrent(nullptr, nullptr); + g_bAnyCurrent = false; wglDeleteContext(glWin.hRC); ReleaseDC(hWnd, glWin.hDC); DestroyWindow(hWnd); @@ -542,13 +557,17 @@ bool WinOpenGLContext::ImplInit() if (!wglMakeCurrent(m_aGLWin.hDC, hTempRC)) { + g_bAnyCurrent = false; SAL_WARN("vcl.opengl", "wglMakeCurrent failed: "<< WindowsErrorString(GetLastError())); return false; } - if (!InitGLEW()) + g_bAnyCurrent = true; + + if (!InitGL()) { wglMakeCurrent(NULL, NULL); + g_bAnyCurrent = false; wglDeleteContext(hTempRC); return false; } @@ -560,6 +579,7 @@ bool WinOpenGLContext::ImplInit() if (!wglCreateContextAttribsARB) { wglMakeCurrent(nullptr, nullptr); + g_bAnyCurrent = false; wglDeleteContext(hTempRC); return false; } @@ -578,6 +598,7 @@ bool WinOpenGLContext::ImplInit() { SAL_WARN("vcl.opengl", "wglCreateContextAttribsARB failed: "<< WindowsErrorString(GetLastError())); wglMakeCurrent(nullptr, nullptr); + g_bAnyCurrent = false; wglDeleteContext(hTempRC); return false; } @@ -585,19 +606,24 @@ bool WinOpenGLContext::ImplInit() if (!compiledShaderBinariesWork()) { wglMakeCurrent(nullptr, nullptr); + g_bAnyCurrent = false; wglDeleteContext(hTempRC); return false; } wglMakeCurrent(nullptr, nullptr); + g_bAnyCurrent = false; wglDeleteContext(hTempRC); if (!wglMakeCurrent(m_aGLWin.hDC, m_aGLWin.hRC)) { + g_bAnyCurrent = false; SAL_WARN("vcl.opengl", "wglMakeCurrent failed: " << WindowsErrorString(GetLastError())); return false; } + g_bAnyCurrent = true; + if (bFirstCall) { // Checking texture size @@ -629,7 +655,7 @@ bool WinOpenGLContext::ImplInit() } } - InitGLEWDebugging(); + InitGLDebugging(); g_vShareList.push_back(m_aGLWin.hRC); diff --git a/vcl/opengl/x11/gdiimpl.cxx b/vcl/opengl/x11/gdiimpl.cxx index 82f8bc9f14bd..292dd14e7318 100644 --- a/vcl/opengl/x11/gdiimpl.cxx +++ b/vcl/opengl/x11/gdiimpl.cxx @@ -32,6 +32,7 @@ #include <o3tl/lru_map.hxx> static std::vector<GLXContext> g_vShareList; +static bool g_bAnyCurrent; class X11OpenGLContext : public OpenGLContext { @@ -184,23 +185,10 @@ namespace return pFBC; } - // we need them before glew can initialize them - // glew needs an OpenGL context so we need to get the address manually - void initOpenGLFunctionPointers() - { - glXChooseFBConfig = reinterpret_cast<GLXFBConfig*(*)(Display *dpy, int screen, const int *attrib_list, int *nelements)>(glXGetProcAddressARB(reinterpret_cast<GLubyte const *>("glXChooseFBConfig"))); - glXGetVisualFromFBConfig = reinterpret_cast<XVisualInfo*(*)(Display *dpy, GLXFBConfig config)>(glXGetProcAddressARB(reinterpret_cast<GLubyte const *>("glXGetVisualFromFBConfig"))); // try to find a visual for the current set of attributes - glXGetFBConfigAttrib = reinterpret_cast<int(*)(Display *dpy, GLXFBConfig config, int attribute, int* value)>(glXGetProcAddressARB(reinterpret_cast<GLubyte const *>("glXGetFBConfigAttrib"))); - glXCreateContextAttribsARB = reinterpret_cast<GLXContext(*)(Display*, GLXFBConfig, GLXContext, Bool, const int*)>(glXGetProcAddressARB(reinterpret_cast<const GLubyte *>("glXCreateContextAttribsARB"))); - glXCreatePixmap = reinterpret_cast<GLXPixmap(*)(Display*, GLXFBConfig, Pixmap, const int*)>(glXGetProcAddressARB(reinterpret_cast<const GLubyte *>("glXCreatePixmap"))); - } - Visual* getVisual(Display* dpy, Window win) { OpenGLZone aZone; - initOpenGLFunctionPointers(); - XWindowAttributes xattr; if( !XGetWindowAttributes( dpy, win, &xattr ) ) { @@ -235,7 +223,10 @@ void X11OpenGLContext::resetCurrent() OpenGLZone aZone; if (m_aGLWin.dpy) + { glXMakeCurrent(m_aGLWin.dpy, None, nullptr); + g_bAnyCurrent = false; + } } bool X11OpenGLContext::isCurrent() @@ -247,7 +238,7 @@ bool X11OpenGLContext::isCurrent() bool X11OpenGLContext::isAnyCurrent() { - return glXGetCurrentContext() != None; + return g_bAnyCurrent && glXGetCurrentContext() != None; } SystemWindowData X11OpenGLContext::generateWinData(vcl::Window* pParent, bool /*bRequestLegacyContext*/) @@ -266,8 +257,6 @@ SystemWindowData X11OpenGLContext::generateWinData(vcl::Window* pParent, bool /* if( dpy == nullptr || !glXQueryExtension( dpy, nullptr, nullptr ) ) return aWinData; - initOpenGLFunctionPointers(); - int best_fbc = -1; GLXFBConfig* pFBC = getFBConfig(dpy, win, best_fbc, true, false); @@ -355,10 +344,13 @@ bool X11OpenGLContext::ImplInit() if( !glXMakeCurrent( m_aGLWin.dpy, m_aGLWin.win, m_aGLWin.ctx ) ) { + g_bAnyCurrent = false; SAL_WARN("vcl.opengl", "unable to select current GLX context"); return false; } + g_bAnyCurrent = true; + int glxMinor, glxMajor; double nGLXVersion = 0; if( glXQueryVersion( m_aGLWin.dpy, &glxMajor, &glxMinor ) ) @@ -400,8 +392,8 @@ bool X11OpenGLContext::ImplInit() } } - bool bRet = InitGLEW(); - InitGLEWDebugging(); + bool bRet = InitGL(); + InitGLDebugging(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); @@ -427,10 +419,12 @@ void X11OpenGLContext::makeCurrent() { if (!glXMakeCurrent( m_aGLWin.dpy, m_aGLWin.win, m_aGLWin.ctx )) { + g_bAnyCurrent = false; SAL_WARN("vcl.opengl", "OpenGLContext::makeCurrent failed " "on drawable " << m_aGLWin.win); return; } + g_bAnyCurrent = true; } registerAsCurrent(); @@ -445,6 +439,7 @@ void X11OpenGLContext::destroyCurrentContext() g_vShareList.erase(itr); glXMakeCurrent(m_aGLWin.dpy, None, nullptr); + g_bAnyCurrent = false; if( glGetError() != GL_NO_ERROR ) { SAL_WARN("vcl.opengl", "glError: " << glGetError()); |