PDA

View Full Version : Newbie extension question



Bode
06-11-2002, 12:14 AM
Hi...

In my attempt to deal with extensions I'm confused as to how to declare my function pointer variables. The examples that I see do something like this to declare the function prototypes:

#ifdef _WIN32
typedef void (APIENTRY * PFNGLPOINTPARAMETERFEXTPROC)(GLenum pname, GLfloat param);
typedef void (APIENTRY * PFNGLPOINTPARAMETERFVEXTPROC)(GLenum pname, const GLfloat *params);
#endif

Then, define the variables like:

#ifdef _WIN32
PFNGLPOINTPARAMETERFEXTPROC glPointParameterfEXT;
PFNGLPOINTPARAMETERFVEXTPROC glPointParameterfvEXT;
#endif


The problem that I can't get is determining the function name of glPointParameterfvEXT. I see that I could extract it from PFNGLPOINTPARAMETERFVEXTPROC, but that would be terribly tedious if I have a lot of extensions.

So I'm wondering if there is an .h file that will have the gl* extension function defined somewhere? Or does everybody know to call the PFNGLPOINTPARAMETERFVEXTPROC function pointer to glPointParameterfvEXT? Or is this in some other file besides gl.h/glext.h?

Thanks a bunch...

Bode

JML
06-11-2002, 02:10 AM
Originally posted by Bode:
Hi...

In my attempt to deal with extensions I'm confused as to how to declare my function pointer variables. The examples that I see do something like this to declare the function prototypes:

#ifdef _WIN32
typedef void (APIENTRY * PFNGLPOINTPARAMETERFEXTPROC)(GLenum pname, GLfloat param);
typedef void (APIENTRY * PFNGLPOINTPARAMETERFVEXTPROC)(GLenum pname, const GLfloat *params);
#endif

Then, define the variables like:

#ifdef _WIN32
PFNGLPOINTPARAMETERFEXTPROC glPointParameterfEXT;
PFNGLPOINTPARAMETERFVEXTPROC glPointParameterfvEXT;
#endif


The problem that I can't get is determining the function name of glPointParameterfvEXT. I see that I could extract it from PFNGLPOINTPARAMETERFVEXTPROC, but that would be terribly tedious if I have a lot of extensions.

So I'm wondering if there is an .h file that will have the gl* extension function defined somewhere? Or does everybody know to call the PFNGLPOINTPARAMETERFVEXTPROC function pointer to glPointParameterfvEXT? Or is this in some other file besides gl.h/glext.h?

Thanks a bunch...

Bode

Bode,

The glext.h file will define the PFNGLBLABLABLAEXTPROC pointers. It's up to you to declare a pointer of that type and call the platform specific function to fill the pointer with the correct address. For windows this is:

(PFNGLBLABLABLAEXTPROC)wglGetProcAddress( "glBlaBlaBlaEXT")

For other platforms there are corresponding calls.

AFAIK there is no .h file around that declares the required character strings to pass to wglGetProcAddress, but they are quite easy to derive from the PFNGLBLABLABLA definition: small caps gl, capitalise each word and an all caps finish like 'EXT', 'NV' etc.

You could search around the net for classes/files that implement a bunch of extensions for you, but as I said it's relatively simple to code for yourself (just a lot of repetetive work if you want to use a lot of extensions).

I'm assuming you are familiar with the following:
- verify extension support during compile-time with #ifdef ExtensionName
- verify extension support during runtime by querying glGetString(GL_EXTENSIONS) for the ExtensionName
- only use the extension functions if support is available and wglGetProcAddress returned a valid pointer

HTH

Jean-Marc.

Deiussum
06-11-2002, 04:23 AM
Just thought I'd add a quick point. It sounds like you think that the instance of the function pointer needs to be named something specific. This isn't the case. You could do this if you wanted.

PFNGLPOINTPARAMETERFEXTPROC glICanNameThisFunctionWhateverIWant;

It will still be a pointer to a function of the same type. How it actually points to the function it needs in the DLL is by assigning it with wglGetProcAddress the way that JML described.

Granted, it's not very practical to give the function pointers odd names, but there's technically nothing that stops you from doing so. http://www.opengl.org/discussion_boards/ubb/smile.gif

Bode
06-11-2002, 09:13 AM
Thanks Guys...

It's starting to make more sense now.

But I have just one more question. I see that a lot of programs use glGetString(GL_EXTENSIONS) to determine available extensions, then call wglGetProcAddress().
Why don't they just call wglGetProcAddress() to determine if the extension is available, and if it returns a NULL, then use your software implementation? Is wglGetProcAddress() such a heavy function that it should only be used sparingly? (hence the reason to pretest with glGetString() )

Bode

JML
06-11-2002, 09:02 PM
Originally posted by Bode:
Thanks Guys...

Why don't they just call wglGetProcAddress() to determine if the extension is available, and if it returns a NULL, then use your software implementation? Is wglGetProcAddress() such a heavy function that it should only be used sparingly? (hence the reason to pretest with glGetString() )

Bode

You could do that, however for quite a few extensions testing for a single occurrence in GL_EXTENSIONS is cheaper than calling a zillion wglGetProcAdresses.
Besides, the 'official' rules say you should check the GL_EXTENSIONS first, and then get the addresses. There is no guarantee that a successful wglGetProcAddress gives you an officially supported extension.

Jean-Marc.