Extention paths
I was wondering if anyone had some useful tips on coding various extention paths. Perhaps a good tutorial on NeHe would be worthwhile.
While I understand the principal of extentions, I wanted some tips or warnings of common pitfalls when implementing them.
I like pie! - weebl.
Oneiric - Another graphics engine in the works.
Oneiric - Another graphics engine in the works.
the simplest extension path:
common pitfall:
assuming an extension is supported..
| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - |
[edited by - RipTorn on January 23, 2003 4:36:00 PM]
if (extensionSupported) glExtension()...else glBogStandard()...
common pitfall:
assuming an extension is supported..
| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - |
[edited by - RipTorn on January 23, 2003 4:36:00 PM]
Heres a handy dandy thing I noticed (other people may of noticed too but I''ll say it anyway)
Instead of having to keep track of a IsXXXExtension supported variable, just initialize your function pointer to NULL, and before actually using it, do
if(glExtension)
glExtension();
You can do this because FALSE and NULL = 0 and any nonzero value is true. So, if the function was found the pointer won''t be NULL, and the statement will evaluate to true. Got it?
Instead of having to keep track of a IsXXXExtension supported variable, just initialize your function pointer to NULL, and before actually using it, do
if(glExtension)
glExtension();
You can do this because FALSE and NULL = 0 and any nonzero value is true. So, if the function was found the pointer won''t be NULL, and the statement will evaluate to true. Got it?
Hawkeye3, I'm not 100% sure I understand you.
I get the idea that a non NULL pointer will evaluate to TRUE, but I'm unsure about the way you'd use a pointer to a function to support multiple extentions.
The reason I ask is that I'm planning on getting my grubby hands on a GeForce FX when they show up and I'll be making my engine take advantage of the obviously better shaders and a whole load of other tricks while still supporting older cards and extentions.
[Edit] Correcting terrible spelling mistakes
[edited by - Juicy on January 24, 2003 5:37:25 AM]
I get the idea that a non NULL pointer will evaluate to TRUE, but I'm unsure about the way you'd use a pointer to a function to support multiple extentions.
The reason I ask is that I'm planning on getting my grubby hands on a GeForce FX when they show up and I'll be making my engine take advantage of the obviously better shaders and a whole load of other tricks while still supporting older cards and extentions.
[Edit] Correcting terrible spelling mistakes

[edited by - Juicy on January 24, 2003 5:37:25 AM]
I like pie! - weebl.
Oneiric - Another graphics engine in the works.
Oneiric - Another graphics engine in the works.
The only real problem I see with my logic is that if you don''t want the person to use the extension, even if it is supported.
Remember when you call wglGetProcAddress? That returns the address that your function pointer points to if the procedure is found, otherwise it is NULL(0).
Perhaps I wasn''t clear enough with my example...
// During Init
// These return NULL if the function isn''t found
glLockArraysEXT = (PFNGLLOCKARRAYSEXTPROC)wglGetProcAddress("glLockArraysEXT");
glUnlockArraysEXT = (PFNGLUNLOCKARRAYSEXTPROC) wglGetProcAddress ("glUnlockArraysEXT");
// When you want to use them
if(glLockArraysEXT) // If the function is valid (not NULL)
glLockArraysEXT(x, GL_x) // Its safe to use it
...
if(glUnlockArraysEXT)
glUnlockArraysEXT()
Remember when you call wglGetProcAddress? That returns the address that your function pointer points to if the procedure is found, otherwise it is NULL(0).
Perhaps I wasn''t clear enough with my example...
// During Init
// These return NULL if the function isn''t found
glLockArraysEXT = (PFNGLLOCKARRAYSEXTPROC)wglGetProcAddress("glLockArraysEXT");
glUnlockArraysEXT = (PFNGLUNLOCKARRAYSEXTPROC) wglGetProcAddress ("glUnlockArraysEXT");
// When you want to use them
if(glLockArraysEXT) // If the function is valid (not NULL)
glLockArraysEXT(x, GL_x) // Its safe to use it
...
if(glUnlockArraysEXT)
glUnlockArraysEXT()
ps, that last post was me. Got logged out for some reason and I can''t edit it

I like pie! - weebl.
Oneiric - Another graphics engine in the works.
Oneiric - Another graphics engine in the works.
It''s not always that simple.
The EXT_compiled_vertex_array is pretty easy for that, but almost all extensions really need different path, not *just* forgetting the function call.
Generally, in the initialization function, you get which extensions are available, for instance :
Then use different path for either case :
The EXT_compiled_vertex_array is pretty easy for that, but almost all extensions really need different path, not *just* forgetting the function call.
Generally, in the initialization function, you get which extensions are available, for instance :
bool is_multitexture_supported = false; /* global */void initGL(){...is_multitexture_supported = strstr((const char*)glGetString(GL_EXTENSIONS), "GL_ARB_multitexture") != 0;...}
Then use different path for either case :
void renderGL(){...if (is_multitexture_supported){ /* path #1 : multitexture is supported : we can use all texture units available */}else{ /* path #2 : multitexture is not supported : we have to do it in multipass or forget the nice effect that multitexture could perform */}...}
Eh I don''t get what your saying? I can just slap an else on my if statement and it works exactly like your code.
if(glxxxExt) // Valid to use
// Use it
else
// Do some work-around
It was just meant to be pseudo code anyway :|
if(glxxxExt) // Valid to use
// Use it
else
// Do some work-around
It was just meant to be pseudo code anyway :|
quote:
if(glxxxExt) // Valid to use
// Use it
else
// Do some work-around
yup. thats the way.
quote:
Original post by Juicy
The reason I ask is that I'm planning on getting my grubby hands on a GeForce FX when they show up and I'll be making my engine take advantage of the obviously better shaders and a whole load of other tricks while still supporting older cards and extentions.
hehe. geforce FX. hmm. Course a month or so later ati will release their next semi-secret chip, putting nvidia in their place again. hehe.
| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - |
[edited by - RipTorn on January 27, 2003 7:19:17 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement