From ee834a83860e614d565f5bb38cdfb8681ffa5f16 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 17 Feb 2019 21:09:23 +0100 Subject: Add puglGetProcAddress for using OpenGL extensions --- pugl/pugl.h | 11 +++++++++++ pugl/pugl_osx.m | 16 ++++++++++++++++ pugl/pugl_win.cpp | 6 ++++++ pugl/pugl_x11_gl.c | 6 ++++++ 4 files changed, 39 insertions(+) diff --git a/pugl/pugl.h b/pugl/pugl.h index b2937e2..9e70100 100644 --- a/pugl/pugl.h +++ b/pugl/pugl.h @@ -629,6 +629,17 @@ puglProcessEvents(PuglView* view); @} */ +/** + OpenGL extension function. +*/ +typedef void (*PuglGlFunc)(); + +/** + Return the address of an OpenGL extension function. +*/ +PUGL_API PuglGlFunc +puglGetProcAddress(const char* name); + /** Request a redisplay on the next call to puglProcessEvents(). */ diff --git a/pugl/pugl_osx.m b/pugl/pugl_osx.m index 8e40907..e56a1a7 100644 --- a/pugl/pugl_osx.m +++ b/pugl/pugl_osx.m @@ -702,6 +702,22 @@ puglProcessEvents(PuglView* view) return PUGL_SUCCESS; } +PuglGlFunc +puglGetProcAddress(const char *name) +{ + CFBundleRef framework = + CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl")); + + CFStringRef symbol = CFStringCreateWithCString( + kCFAllocatorDefault, name, kCFStringEncodingASCII); + + PuglGlFunc func = CFBundleGetFunctionPointerForName(framework, symbol); + + CFRelease(symbol); + + return func; +} + void puglPostRedisplay(PuglView* view) { diff --git a/pugl/pugl_win.cpp b/pugl/pugl_win.cpp index 2c092eb..048c0c3 100644 --- a/pugl/pugl_win.cpp +++ b/pugl/pugl_win.cpp @@ -631,6 +631,12 @@ wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) } } +PuglGlFunc +puglGetProcAddress(const char* name) +{ + return (PuglGlFunc)wglGetProcAddress(name); +} + void puglPostRedisplay(PuglView* view) { diff --git a/pugl/pugl_x11_gl.c b/pugl/pugl_x11_gl.c index 6c007b1..f9e3ce2 100644 --- a/pugl/pugl_x11_gl.c +++ b/pugl/pugl_x11_gl.c @@ -186,6 +186,12 @@ puglX11GlGetHandle(PuglView* view) return NULL; } +PuglGlFunc +puglGetProcAddress(const char* name) +{ + return glXGetProcAddress((const GLubyte*)name); +} + PuglDrawContext puglGetX11GlDrawContext(void) { static const PuglDrawContext puglX11GlDrawContext = { -- cgit v1.2.1