Created
August 15, 2016 20:32
-
-
Save FelixK15/a013f0a49762e6a8b9f55ba60f25351a to your computer and use it in GitHub Desktop.
OpenGL get extension function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//kglGetProcAddress = (wglGetProcAddress/glxGetProcAddress/eglGetProcAddress) | |
/*********************************************************************************/ | |
/* - p_GLExtensionFunctionName = The name of the function whose pointer you want to retrieve. e.g. glGenVertexArray) | |
- p_ReviewBoardAbbreveration = Abbreveration of the review board that implemented the extension (e.g. ARB, KHR, INTEL, etc.) | |
- p_Buffer = An external buffer we can write stuff into | |
*/ | |
char* ConstructGLExtensionFunctionString(const char* p_GLExtensionFunctionName, | |
char* p_ReviewBoardAbbreveration, | |
char* p_Buffer) | |
{ | |
size_t extensionStringLength = strlen(p_ExtensionsPointerString); | |
size_t reviewBoardStringLength = strlen(p_ReviewBoardAbbreveration); | |
memcpy(p_Buffer, p_ExtensionsPointerString, extensionStringLength); | |
memcpy(p_Buffer + extensionStringLength, p_ReviewBoardAbbreveration, reviewBoardStringLength); | |
return p_Buffer; | |
} | |
/*********************************************************************************/ | |
/*********************************************************************************/ | |
/* - p_GLExtensionFunctionName = The name of the function whose pointer you want to retrieve. e.g. glGenVertexArray) | |
- p_ReviewBoardAbbreveration = Abbreveration of the review board that implemented the extension (e.g. ARB, KHR, INTEL, etc.) | |
- p_Buffer = An external buffer we can write stuff into | |
*/ | |
void* GetGLExtensionFunctionPointer(const char* p_GLExtensionFunctionName, | |
char* p_ReviewBoardAbbreveration) | |
{ | |
void* functionPointer = kglGetProcAddress(p_GLExtensionFunctionName); | |
if (!functionPointer) | |
{ | |
char* glFunctionNameExt = ConstructGLExtensionFunctionString(p_GLExtensionFunctionName, | |
p_ReviewBoardAbbreveration, | |
(char*)alloca(128)); | |
functionPointer = kglGetProcAddress(glFunctionNameExt); | |
} | |
return functionPointer; | |
} | |
/*********************************************************************************/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment