1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-26 20:28:49 -05:00

Make all client API functions dynamically loaded

This commit is contained in:
Camilla Berglund 2015-08-12 00:59:26 +02:00
parent 84b512c62c
commit 6b8d490249
4 changed files with 24 additions and 9 deletions

View File

@ -64,6 +64,7 @@ GLFW bundles a number of dependencies in the `deps/` directory.
## Changelog ## Changelog
- Made all client API functions dynamically loaded
- Changed minimum required CMake version to 2.8.12 - Changed minimum required CMake version to 2.8.12
- Replaced GLU with [linmath.h](https://github.com/datenwolf/linmath.h) in - Replaced GLU with [linmath.h](https://github.com/datenwolf/linmath.h) in
example programs example programs

View File

@ -38,6 +38,7 @@
static GLboolean parseVersionString(int* api, int* major, int* minor, int* rev) static GLboolean parseVersionString(int* api, int* major, int* minor, int* rev)
{ {
int i; int i;
_GLFWwindow* window;
const char* version; const char* version;
const char* prefixes[] = const char* prefixes[] =
{ {
@ -49,7 +50,9 @@ static GLboolean parseVersionString(int* api, int* major, int* minor, int* rev)
*api = GLFW_OPENGL_API; *api = GLFW_OPENGL_API;
version = (const char*) glGetString(GL_VERSION); window = _glfwPlatformGetCurrentContext();
version = (const char*) window->GetString(GL_VERSION);
if (!version) if (!version)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
@ -352,6 +355,10 @@ GLboolean _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig)
{ {
_GLFWwindow* window = _glfwPlatformGetCurrentContext(); _GLFWwindow* window = _glfwPlatformGetCurrentContext();
window->GetIntegerv = (PFNGLGETINTEGERVPROC) glfwGetProcAddress("glGetIntegerv");
window->GetString = (PFNGLGETSTRINGPROC) glfwGetProcAddress("glGetString");
window->Clear = (PFNGLCLEARPROC) glfwGetProcAddress("glClear");
if (!parseVersionString(&window->context.api, if (!parseVersionString(&window->context.api,
&window->context.major, &window->context.major,
&window->context.minor, &window->context.minor,
@ -382,7 +389,7 @@ GLboolean _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig)
if (window->context.major >= 3) if (window->context.major >= 3)
{ {
GLint flags; GLint flags;
glGetIntegerv(GL_CONTEXT_FLAGS, &flags); window->GetIntegerv(GL_CONTEXT_FLAGS, &flags);
if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT) if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)
window->context.forward = GL_TRUE; window->context.forward = GL_TRUE;
@ -404,7 +411,7 @@ GLboolean _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig)
(window->context.major == 3 && window->context.minor >= 2)) (window->context.major == 3 && window->context.minor >= 2))
{ {
GLint mask; GLint mask;
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask); window->GetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)
window->context.profile = GLFW_OPENGL_COMPAT_PROFILE; window->context.profile = GLFW_OPENGL_COMPAT_PROFILE;
@ -427,7 +434,7 @@ GLboolean _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig)
// only present from 3.0 while the extension applies from 1.1 // only present from 3.0 while the extension applies from 1.1
GLint strategy; GLint strategy;
glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &strategy); window->GetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &strategy);
if (strategy == GL_LOSE_CONTEXT_ON_RESET_ARB) if (strategy == GL_LOSE_CONTEXT_ON_RESET_ARB)
window->context.robustness = GLFW_LOSE_CONTEXT_ON_RESET; window->context.robustness = GLFW_LOSE_CONTEXT_ON_RESET;
@ -444,7 +451,7 @@ GLboolean _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig)
// one, so we can reuse them here // one, so we can reuse them here
GLint strategy; GLint strategy;
glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &strategy); window->GetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &strategy);
if (strategy == GL_LOSE_CONTEXT_ON_RESET_ARB) if (strategy == GL_LOSE_CONTEXT_ON_RESET_ARB)
window->context.robustness = GLFW_LOSE_CONTEXT_ON_RESET; window->context.robustness = GLFW_LOSE_CONTEXT_ON_RESET;
@ -456,7 +463,7 @@ GLboolean _glfwRefreshContextAttribs(const _GLFWctxconfig* ctxconfig)
if (glfwExtensionSupported("GL_KHR_context_flush_control")) if (glfwExtensionSupported("GL_KHR_context_flush_control"))
{ {
GLint behavior; GLint behavior;
glGetIntegerv(GL_CONTEXT_RELEASE_BEHAVIOR, &behavior); window->GetIntegerv(GL_CONTEXT_RELEASE_BEHAVIOR, &behavior);
if (behavior == GL_NONE) if (behavior == GL_NONE)
window->context.release = GLFW_RELEASE_BEHAVIOR_NONE; window->context.release = GLFW_RELEASE_BEHAVIOR_NONE;
@ -581,7 +588,7 @@ GLFWAPI int glfwExtensionSupported(const char* extension)
// Check if extension is in the modern OpenGL extensions string list // Check if extension is in the modern OpenGL extensions string list
glGetIntegerv(GL_NUM_EXTENSIONS, &count); window->GetIntegerv(GL_NUM_EXTENSIONS, &count);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
@ -602,7 +609,7 @@ GLFWAPI int glfwExtensionSupported(const char* extension)
{ {
// Check if extension is in the old style OpenGL extensions string // Check if extension is in the old style OpenGL extensions string
const char* extensions = (const char*) glGetString(GL_EXTENSIONS); const char* extensions = (const char*) window->GetString(GL_EXTENSIONS);
if (!extensions) if (!extensions)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,

View File

@ -69,6 +69,10 @@
#include "../deps/GL/glext.h" #include "../deps/GL/glext.h"
#endif #endif
typedef void (APIENTRY * PFNGLCLEARPROC)(GLbitfield);
typedef const GLubyte* (APIENTRY * PFNGLGETSTRINGPROC)(GLenum);
typedef void (APIENTRY * PFNGLGETINTEGERVPROC)(GLenum,GLint*);
typedef struct _GLFWwndconfig _GLFWwndconfig; typedef struct _GLFWwndconfig _GLFWwndconfig;
typedef struct _GLFWctxconfig _GLFWctxconfig; typedef struct _GLFWctxconfig _GLFWctxconfig;
typedef struct _GLFWfbconfig _GLFWfbconfig; typedef struct _GLFWfbconfig _GLFWfbconfig;
@ -261,6 +265,9 @@ struct _GLFWwindow
#if defined(_GLFW_USE_OPENGL) #if defined(_GLFW_USE_OPENGL)
PFNGLGETSTRINGIPROC GetStringi; PFNGLGETSTRINGIPROC GetStringi;
#endif #endif
PFNGLGETINTEGERVPROC GetIntegerv;
PFNGLGETSTRINGPROC GetString;
PFNGLCLEARPROC Clear;
struct { struct {
GLFWwindowposfun pos; GLFWwindowposfun pos;

View File

@ -202,7 +202,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
// Clearing the front buffer to black to avoid garbage pixels left over // Clearing the front buffer to black to avoid garbage pixels left over
// from previous uses of our bit of VRAM // from previous uses of our bit of VRAM
glClear(GL_COLOR_BUFFER_BIT); window->Clear(GL_COLOR_BUFFER_BIT);
_glfwPlatformSwapBuffers(window); _glfwPlatformSwapBuffers(window);
// Restore the previously current context (or NULL) // Restore the previously current context (or NULL)