Skip to content

Commit

Permalink
Minor tweaks to the routines used for querying the existence of OpenG…
Browse files Browse the repository at this point in the history
…L extensions.

Don't use bit shifts when multiplying/dividing by a power of two in texture.c, leave the decision to optimize up to the compiler.

Further style updates to the drOpengl code.
  • Loading branch information
danij committed Jul 2, 2007
1 parent f4257ba commit a1d3652
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 170 deletions.
4 changes: 2 additions & 2 deletions doomsday/plugins/opengl/portable/include/dropengl.h
Expand Up @@ -143,7 +143,7 @@ extern rgba_t palette[256];
extern int usePalTex, dumpTextures, useCompr;
extern float grayMipmapFactor;

int Power2(int num);
int DG_Power2(int num);
int enablePalTexExt(int enable);
DGLuint DG_NewTexture(void);
int DG_TexImage(int format, int width, int height, int mipmap,
Expand Down Expand Up @@ -179,6 +179,6 @@ extern int extGenMip;
extern int extBlendSub;
extern int extS3TC;

void initExtensions(void);
void DG_InitExtensions(void);

#endif
48 changes: 28 additions & 20 deletions doomsday/plugins/opengl/portable/src/ext.c
Expand Up @@ -78,56 +78,64 @@ PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT;

/**
* @return Non-zero iff the extension string is found. This
* function is based on Mark J. Kilgard's tutorials
* about OpenGL extensions.
* function is based on the method used by David Blythe
* and Tom McReynolds in the book "Advanced Graphics
* Programming Using OpenGL" ISBN: 1-55860-659-9.
*/
int queryExtension(const char *name)
static int queryExtension(const char *name)
{
const GLubyte *extensions = glGetString(GL_EXTENSIONS);
const GLubyte *extensions = NULL;
const GLubyte *start;
GLubyte *where, *terminator;

if(!extensions)
return false;
GLubyte *c, *terminator;

// Extension names should not have spaces.
where = (GLubyte *) strchr(name, ' ');
if(where || *name == '\0')
c = (GLubyte *) strchr(name, ' ');
if(c || *name == '\0')
return false;

extensions = glGetString(GL_EXTENSIONS);

// It takes a bit of care to be fool-proof about parsing the
// OpenGL extensions string. Don't be fooled by sub-strings, etc.
start = extensions;

for(;;)
{
where = (GLubyte *) strstr((const char *) start, name);
if(!where)
c = (GLubyte *) strstr((const char *) start, name);
if(!c)
break;

terminator = where + strlen(name);
if(where == start || *(where - 1) == ' ')
terminator = c + strlen(name);
if(c == start || *(c - 1) == ' ')
if(*terminator == ' ' || *terminator == '\0')
{
return true;
}
start = terminator;
}

return false;
}

int query(const char *ext, int *var)
static int query(const char *ext, int *var)
{
if((*var = queryExtension(ext)) != DGL_FALSE)
int result = DGL_FALSE;

if(ext)
{
Con_Message("Checking OpenGL extension: %s\n", ext);
return true;
result = (queryExtension(ext)? DGL_TRUE : DGL_FALSE);
if(var)
*var = result;
}

return false;
return result;
}

void initExtensions(void)
/**
* Pre: A rendering context must be aquired and made current before this is
* called.
*/
void DG_InitExtensions(void)
{
int i;

Expand Down

0 comments on commit a1d3652

Please sign in to comment.