Kaydet (Commit) 877a4be0 authored tarafından Markus Mohrhard's avatar Markus Mohrhard

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
üst f446172d
...@@ -158,6 +158,12 @@ public: ...@@ -158,6 +158,12 @@ public:
bool init(vcl::Window* pParent = 0); bool init(vcl::Window* pParent = 0);
bool init(SystemChildWindow* pChildWindow); 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 makeCurrent();
void resetCurrent(); void resetCurrent();
void swapBuffers(); void swapBuffers();
......
...@@ -428,6 +428,30 @@ GLXFBConfig* getFBConfig(Display* dpy, Window win, int& nBestFBC) ...@@ -428,6 +428,30 @@ GLXFBConfig* getFBConfig(Display* dpy, Window win, int& nBestFBC)
return pFBC; 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 #endif
...@@ -458,6 +482,33 @@ bool OpenGLContext::init(SystemChildWindow* pChildWindow) ...@@ -458,6 +482,33 @@ bool OpenGLContext::init(SystemChildWindow* pChildWindow)
return ImplInit(); 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() bool OpenGLContext::ImplInit()
{ {
SAL_INFO("vcl.opengl", "OpenGLContext::ImplInit----start"); SAL_INFO("vcl.opengl", "OpenGLContext::ImplInit----start");
...@@ -828,34 +879,6 @@ SystemWindowData OpenGLContext::generateWinData(vcl::Window* /*pParent*/, bool b ...@@ -828,34 +879,6 @@ SystemWindowData OpenGLContext::generateWinData(vcl::Window* /*pParent*/, bool b
#elif defined( UNX ) #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 OpenGLContext::generateWinData(vcl::Window* pParent, bool)
{ {
SystemWindowData aWinData; SystemWindowData aWinData;
......
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