diff options
author | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2014-10-24 17:03:39 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2014-10-24 17:03:39 +0200 |
commit | bafc045bccffd2314d246f93d84dbaf80bf6eacc (patch) | |
tree | 1e7f247f681af07cf69f0e2a9ca1aad422e8644b | |
parent | 2e24c7de8e185556fe7cb2bf013ff9019b08ca0c (diff) |
add a OpenGLContext::init for unix backend
That one does not need the indirection through a Window instance to get
to the X resources that are necessary for a GLX context.
Change-Id: I3195a5f2b447172434881bd9b0b230c8992c1c87
-rw-r--r-- | include/vcl/opengl/OpenGLContext.hxx | 6 | ||||
-rw-r--r-- | vcl/source/opengl/OpenGLContext.cxx | 79 |
2 files changed, 57 insertions, 28 deletions
diff --git a/include/vcl/opengl/OpenGLContext.hxx b/include/vcl/opengl/OpenGLContext.hxx index 2c9210366f0f..a99e6c343b2e 100644 --- a/include/vcl/opengl/OpenGLContext.hxx +++ b/include/vcl/opengl/OpenGLContext.hxx @@ -158,6 +158,12 @@ public: bool init(vcl::Window* pParent = 0); bool init(SystemChildWindow* pChildWindow); +// these methods are for the deep platform layer, don't use them in normal code +// only in vcl's platform code +#if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID + bool init(Display* dpy, Window win, int screen); +#endif + void makeCurrent(); void resetCurrent(); void swapBuffers(); diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx index e5b75c611855..b29c7a1bacb6 100644 --- a/vcl/source/opengl/OpenGLContext.cxx +++ b/vcl/source/opengl/OpenGLContext.cxx @@ -428,6 +428,30 @@ GLXFBConfig* getFBConfig(Display* dpy, Window win, int& nBestFBC) 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 = (GLXFBConfig*(*)(Display *dpy, int screen, const int *attrib_list, int *nelements))glXGetProcAddressARB((GLubyte*)"glXChooseFBConfig"); + glXGetVisualFromFBConfig = (XVisualInfo*(*)(Display *dpy, GLXFBConfig config))glXGetProcAddressARB((GLubyte*)"glXGetVisualFromFBConfig"); // try to find a visual for the current set of attributes + glXGetFBConfigAttrib = (int(*)(Display *dpy, GLXFBConfig config, int attribute, int* value))glXGetProcAddressARB((GLubyte*)"glXGetFBConfigAttrib"); + glXCreateContextAttribsARB = (GLXContext(*) (Display*, GLXFBConfig, GLXContext, Bool, const int*)) glXGetProcAddressARB((const GLubyte *) "glXCreateContextAttribsARB");; +} + +XVisualInfo* getVisualInfo(Display* dpy, Window win) +{ + initOpenGLFunctionPointers(); + + int best_fbc = -1; + GLXFBConfig* pFBC = getFBConfig(dpy, win, best_fbc); + + XVisualInfo* vi = glXGetVisualFromFBConfig( dpy, pFBC[best_fbc] ); + + XFree(pFBC); + + return vi; +} + } #endif @@ -458,6 +482,33 @@ bool OpenGLContext::init(SystemChildWindow* pChildWindow) return ImplInit(); } +#if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID +bool OpenGLContext::init(Display* dpy, Window win, int screen) +{ + if(mbInitialized) + return true; + + if (!dpy) + return false; + + m_aGLWin.dpy = dpy; + m_aGLWin.win = win; + m_aGLWin.screen = screen; + + XVisualInfo* vi = getVisualInfo(dpy, win); + Visual* pVisual = NULL; + + if( vi ) + { + SAL_INFO("vcl.opengl", "using VisualID " << vi->visualid); + pVisual = vi->visual; + } + initGLWindow(pVisual); + + return ImplInit(); +} +#endif + bool OpenGLContext::ImplInit() { SAL_INFO("vcl.opengl", "OpenGLContext::ImplInit----start"); @@ -828,34 +879,6 @@ SystemWindowData OpenGLContext::generateWinData(vcl::Window* /*pParent*/, bool b #elif defined( UNX ) -namespace { - -// we need them before glew can initialize them -// glew needs an OpenGL context so we need to get the address manually -void initOpenGLFunctionPointers() -{ - glXChooseFBConfig = (GLXFBConfig*(*)(Display *dpy, int screen, const int *attrib_list, int *nelements))glXGetProcAddressARB((GLubyte*)"glXChooseFBConfig"); - glXGetVisualFromFBConfig = (XVisualInfo*(*)(Display *dpy, GLXFBConfig config))glXGetProcAddressARB((GLubyte*)"glXGetVisualFromFBConfig"); // try to find a visual for the current set of attributes - glXGetFBConfigAttrib = (int(*)(Display *dpy, GLXFBConfig config, int attribute, int* value))glXGetProcAddressARB((GLubyte*)"glXGetFBConfigAttrib"); - glXCreateContextAttribsARB = (GLXContext(*) (Display*, GLXFBConfig, GLXContext, Bool, const int*)) glXGetProcAddressARB((const GLubyte *) "glXCreateContextAttribsARB");; -} - -} - -XVisualInfo* getVisualInfo(Display* dpy, Window win) -{ - initOpenGLFunctionPointers(); - - int best_fbc = -1; - GLXFBConfig* pFBC = getFBConfig(dpy, win, best_fbc); - - XVisualInfo* vi = glXGetVisualFromFBConfig( dpy, pFBC[best_fbc] ); - - XFree(pFBC); - - return vi; -} - SystemWindowData OpenGLContext::generateWinData(vcl::Window* pParent, bool) { SystemWindowData aWinData; |