mirror of
https://github.com/glfw/glfw.git
synced 2024-11-26 14:24:35 +00:00
Moved OpenGL init and terminate to opengl module.
This commit is contained in:
parent
49dfbe86b2
commit
9614b9b22f
@ -36,33 +36,6 @@
|
||||
#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.
|
||||
//========================================================================
|
||||
@ -561,22 +534,6 @@ static GLboolean initDisplay(void)
|
||||
_glfwLibrary.X11.RandR.available = GL_FALSE;
|
||||
#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
|
||||
#if defined(_GLFW_HAS_XKB)
|
||||
_glfwLibrary.X11.Xkb.majorVersion = 1;
|
||||
@ -739,15 +696,15 @@ int _glfwPlatformInit(void)
|
||||
if (!initDisplay())
|
||||
return GL_FALSE;
|
||||
|
||||
if (!_glfwInitOpenGL())
|
||||
return GL_FALSE;
|
||||
|
||||
initGammaRamp();
|
||||
|
||||
initEWMH();
|
||||
|
||||
_glfwLibrary.X11.cursor = createNULLCursor();
|
||||
|
||||
// Try to load libGL.so if necessary
|
||||
initLibraries();
|
||||
|
||||
_glfwInitJoysticks();
|
||||
|
||||
// Start the timer
|
||||
@ -773,14 +730,7 @@ int _glfwPlatformTerminate(void)
|
||||
|
||||
_glfwTerminateJoysticks();
|
||||
|
||||
// Unload libGL.so if necessary
|
||||
#ifdef _GLFW_DLOPEN_LIBGL
|
||||
if (_glfwLibrary.GLX.libGL != NULL)
|
||||
{
|
||||
dlclose(_glfwLibrary.GLX.libGL);
|
||||
_glfwLibrary.GLX.libGL = NULL;
|
||||
}
|
||||
#endif
|
||||
_glfwTerminateOpenGL();
|
||||
|
||||
// Free clipboard memory
|
||||
if (_glfwLibrary.X11.selection.string)
|
||||
|
@ -529,6 +529,74 @@ static int createContext(_GLFWwindow* window,
|
||||
////// 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
|
||||
//========================================================================
|
||||
|
@ -283,6 +283,8 @@ GLFWGLOBAL struct {
|
||||
void _glfwInitTimer(void);
|
||||
|
||||
// OpenGL support
|
||||
int _glfwInitOpenGL(void);
|
||||
void _glfwTerminateOpenGL(void);
|
||||
int _glfwCreateContext(_GLFWwindow* window,
|
||||
const _GLFWwndconfig* wndconfig,
|
||||
const _GLFWfbconfig* fbconfig);
|
||||
|
Loading…
Reference in New Issue
Block a user