1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 10:48:51 -05:00

Moved OpenGL init and terminate to opengl module.

This commit is contained in:
Camilla Berglund 2012-04-23 13:00:49 +02:00
parent 49dfbe86b2
commit 9614b9b22f
3 changed files with 74 additions and 54 deletions

View File

@ -36,33 +36,6 @@
#include <limits.h> #include <limits.h>
//========================================================================
// Dynamically load libraries
//========================================================================
static void initLibraries(void)
{
#ifdef _GLFW_DLOPEN_LIBGL
int i;
char* libGL_names[ ] =
{
"libGL.so",
"libGL.so.1",
"/usr/lib/libGL.so",
"/usr/lib/libGL.so.1",
NULL
};
for (i = 0; libGL_names[i] != NULL; i++)
{
_glfwLibrary.GLX.libGL = dlopen(libGL_names[i], RTLD_LAZY | RTLD_GLOBAL);
if (_glfwLibrary.GLX.libGL)
break;
}
#endif
}
//======================================================================== //========================================================================
// Translate an X11 key code to a GLFW key code. // Translate an X11 key code to a GLFW key code.
//======================================================================== //========================================================================
@ -561,22 +534,6 @@ static GLboolean initDisplay(void)
_glfwLibrary.X11.RandR.available = GL_FALSE; _glfwLibrary.X11.RandR.available = GL_FALSE;
#endif /*_GLFW_HAS_XRANDR*/ #endif /*_GLFW_HAS_XRANDR*/
// Check if GLX is supported on this display
if (!glXQueryExtension(_glfwLibrary.X11.display, NULL, NULL))
{
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: GLX supported not found");
return GL_FALSE;
}
if (!glXQueryVersion(_glfwLibrary.X11.display,
&_glfwLibrary.GLX.majorVersion,
&_glfwLibrary.GLX.minorVersion))
{
_glfwSetError(GLFW_OPENGL_UNAVAILABLE,
"X11/GLX: Failed to query GLX version");
return GL_FALSE;
}
// Check if Xkb is supported on this display // Check if Xkb is supported on this display
#if defined(_GLFW_HAS_XKB) #if defined(_GLFW_HAS_XKB)
_glfwLibrary.X11.Xkb.majorVersion = 1; _glfwLibrary.X11.Xkb.majorVersion = 1;
@ -739,15 +696,15 @@ int _glfwPlatformInit(void)
if (!initDisplay()) if (!initDisplay())
return GL_FALSE; return GL_FALSE;
if (!_glfwInitOpenGL())
return GL_FALSE;
initGammaRamp(); initGammaRamp();
initEWMH(); initEWMH();
_glfwLibrary.X11.cursor = createNULLCursor(); _glfwLibrary.X11.cursor = createNULLCursor();
// Try to load libGL.so if necessary
initLibraries();
_glfwInitJoysticks(); _glfwInitJoysticks();
// Start the timer // Start the timer
@ -773,14 +730,7 @@ int _glfwPlatformTerminate(void)
_glfwTerminateJoysticks(); _glfwTerminateJoysticks();
// Unload libGL.so if necessary _glfwTerminateOpenGL();
#ifdef _GLFW_DLOPEN_LIBGL
if (_glfwLibrary.GLX.libGL != NULL)
{
dlclose(_glfwLibrary.GLX.libGL);
_glfwLibrary.GLX.libGL = NULL;
}
#endif
// Free clipboard memory // Free clipboard memory
if (_glfwLibrary.X11.selection.string) if (_glfwLibrary.X11.selection.string)

View File

@ -529,6 +529,74 @@ static int createContext(_GLFWwindow* window,
////// GLFW internal API ////// ////// GLFW internal API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
//========================================================================
// Initialize GLX
//========================================================================
int _glfwInitOpenGL(void)
{
#ifdef _GLFW_DLOPEN_LIBGL
int i;
char* libGL_names[ ] =
{
"libGL.so",
"libGL.so.1",
"/usr/lib/libGL.so",
"/usr/lib/libGL.so.1",
NULL
};
for (i = 0; libGL_names[i] != NULL; i++)
{
_glfwLibrary.GLX.libGL = dlopen(libGL_names[i], RTLD_LAZY | RTLD_GLOBAL);
if (_glfwLibrary.GLX.libGL)
break;
}
if (!_glfwLibrary.GLX.libGL)
{
_glfwSetError(GLFW_PLATFORM_ERROR, "X11/GLX: Failed to find libGL");
return GL_FALSE;
}
#endif
// Check if GLX is supported on this display
if (!glXQueryExtension(_glfwLibrary.X11.display, NULL, NULL))
{
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: GLX supported not found");
return GL_FALSE;
}
if (!glXQueryVersion(_glfwLibrary.X11.display,
&_glfwLibrary.GLX.majorVersion,
&_glfwLibrary.GLX.minorVersion))
{
_glfwSetError(GLFW_OPENGL_UNAVAILABLE,
"X11/GLX: Failed to query GLX version");
return GL_FALSE;
}
return GL_TRUE;
}
//========================================================================
// Terminate GLX
//========================================================================
void _glfwTerminateOpenGL(void)
{
// Unload libGL.so if necessary
#ifdef _GLFW_DLOPEN_LIBGL
if (_glfwLibrary.GLX.libGL != NULL)
{
dlclose(_glfwLibrary.GLX.libGL);
_glfwLibrary.GLX.libGL = NULL;
}
#endif
}
//======================================================================== //========================================================================
// Prepare for creation of the OpenGL context // Prepare for creation of the OpenGL context
//======================================================================== //========================================================================

View File

@ -283,6 +283,8 @@ GLFWGLOBAL struct {
void _glfwInitTimer(void); void _glfwInitTimer(void);
// OpenGL support // OpenGL support
int _glfwInitOpenGL(void);
void _glfwTerminateOpenGL(void);
int _glfwCreateContext(_GLFWwindow* window, int _glfwCreateContext(_GLFWwindow* window,
const _GLFWwndconfig* wndconfig, const _GLFWwndconfig* wndconfig,
const _GLFWfbconfig* fbconfig); const _GLFWfbconfig* fbconfig);