glee-developers Mailing List for glee
Brought to you by:
elf-stone
You can subscribe to this list here.
2011 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
---|
From: <ric...@gm...> - 2011-03-07 21:23:28
|
Is this the right place to send suggested changes? What diff format do the developers prefer? I understand that much of GLee is autogenerated from the extension list files. Is someone more familiar with those willing to port C code changes back to the sources, or should I be submitting diffs against the extension list? Here are the improvements I've made locally for my project: 1. Add an additional const to the parameter of glShaderSource, since it shouldn't be changing the input. This allows passing an address in initialized constant memory. 2. Fix return type of __GLeeGetProcAddress. The C language doesn't guarantee that data pointers and function pointers are the same size, and even on architectures where they are, compilers tend to generate nasty warnings. 3. Use sprintf_s to eliminate static analysis warnings. `sprintf_s` is the Win32 name, other OSes use `snprintf` with an identical signature. 4. Simplify extension string parsing code. At the same time, remove the arbitrary limitation of extension name length. The extension table should also use a better growth algorithm to reduce the number of realloc calls, each of which potentially requires a copy. I haven't changed this yet. Best wishes, and thanks for making such an easy-to-use OpenGL extension loader. Ben Voigt --- old/GLee.h Sat Feb 7 13:46:21 2009 +++ new/GLee.h Sun Feb 27 23:30:06 2011 @@ -85,6 +85,8 @@ #define GLEE_LINK_PARTIAL 1 #define GLEE_LINK_COMPLETE 2 +typedef void (*GLEE_FUNC)(void); + /* Extension querying variables */ GLEE_EXTERN GLboolean _GLEE_VERSION_1_2; @@ -2417,7 +2419,7 @@ #endif #ifndef GLEE_H_DEFINED_glShaderSource #define GLEE_H_DEFINED_glShaderSource - typedef void (APIENTRYP GLEEPFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar* * string, const GLint * length); + typedef void (APIENTRYP GLEEPFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar* const* string, const GLint * length); GLEE_EXTERN GLEEPFNGLSHADERSOURCEPROC GLeeFuncPtr_glShaderSource; #define glShaderSource GLeeFuncPtr_glShaderSource #endif --- old/GLee.c Sat Feb 7 13:46:21 2009 +++ new/GLee.c Sun Feb 27 23:30:27 2011 @@ -54,10 +54,10 @@ #define __stdcall /* nothing */ #endif -void * __GLeeGetProcAddress(const char *extname) +GLEE_FUNC __GLeeGetProcAddress(const char *extname) { #ifdef WIN32 - return (void*)wglGetProcAddress(extname); + return (GLEE_FUNC)wglGetProcAddress(extname); #elif defined(__APPLE__) || defined(__APPLE_CC__) CFBundleRef bundle; CFURLRef bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR("/System/Library/Frameworks/OpenGL.framework"), kCFURLPOSIXPathStyle, true); @@ -1677,7 +1677,7 @@ #endif #ifndef GLEE_C_DEFINED_glShaderSource #define GLEE_C_DEFINED_glShaderSource - void __stdcall GLee_Lazy_glShaderSource(GLuint shader, GLsizei count, const GLchar* * string, const GLint * length) {if (GLeeInit()) glShaderSource(shader, count, string, length);} + void __stdcall GLee_Lazy_glShaderSource(GLuint shader, GLsizei count, const GLchar* const* string, const GLint * length) {if (GLeeInit()) glShaderSource(shader, count, string, length);} GLEEPFNGLSHADERSOURCEPROC GLeeFuncPtr_glShaderSource=GLee_Lazy_glShaderSource; #endif #ifndef GLEE_C_DEFINED_glUseProgram @@ -15919,8 +15919,7 @@ extList->lengths=(int *)realloc((void *)extList->lengths, n*sizeof(int)); extList->names=(char **)realloc((void *)extList->names, n*sizeof(char *)); } - extList->names[i]=(char *)malloc(length*sizeof(char)); - strcpy(extList->names[i],extName); + extList->names[i]=_strdup(extName); extList->lengths[i]=length; extList->numNames++; } @@ -15967,16 +15966,14 @@ const char * platExtStr; const char * glExtStr; char * extStr; - char emptyString[1] = ""; - char extensionName[1024]; - int a,b; - int totalExtStrLen; - int platExtStrLen; + char * p; + int totalExtStrLen = 0; int addASpace; /* read the platform specific extension string */ platExtStr=__GLeeGetExtStrPlat(); - if (!platExtStr) platExtStr=emptyString; + if (!platExtStr) platExtStr=""; + else totalExtStrLen = strlen(platExtStr); glExtStr=(const char *)glGetString(GL_EXTENSIONS); if (glExtStr==0) @@ -15985,52 +15982,33 @@ return GL_FALSE; } - /* allocate the extension string */ - platExtStrLen = strlen(platExtStr); - totalExtStrLen = platExtStrLen + strlen(glExtStr); - extStr=(char *)malloc( (totalExtStrLen+2) * sizeof(char) ); /* we add 2 to allow for an extra space and a null terminator */ /* If the last character of platExtStr is not a space, we need to add one when we concatenate the extension strings*/ addASpace = 0; - if ( platExtStrLen > 2 ) + if ( totalExtStrLen ) { - if ( platExtStr[ platExtStrLen-1 ] != ' ') + if ( platExtStr[ totalExtStrLen-1 ] != ' ') { addASpace = 1; + totalExtStrLen++; } } - + + /* allocate the extension string */ + totalExtStrLen += strlen(glExtStr); + extStr=(char *)malloc( totalExtStrLen+1 ); /* allow for a null terminator */ + /* concatenate the two extension strings */ - if ( addASpace ) - { - sprintf(extStr,"%s %s",platExtStr,glExtStr); - } - else - { - sprintf(extStr,"%s%s",platExtStr,glExtStr); - } + sprintf_s(extStr,totalExtStrLen+1,addASpace?"%s %s":"%s%s",platExtStr,glExtStr); /* extract the extensions */ - for ( a=0;a<totalExtStrLen;a++ ) - { - b=0; - while (extStr[a]!=' ' && a<totalExtStrLen && b<1022) - { - extensionName[b]=extStr[a]; - b++; a++; + for (p = extStr + totalExtStrLen; p > extStr; --p) { + if (*p == ' ') { + __GLeeExtList_add(extList,p+1); + *p = 0; } - if (b==1023) - { - __GLeeWriteError("Extension name exceeds 1023 characters."); - free((void *)extStr); - return GL_FALSE; - } - - extensionName[b]='\0'; - - /* add the extension */ - __GLeeExtList_add(extList,extensionName); } + __GLeeExtList_add(extList,extStr); free((void *)extStr); return GL_TRUE; } |