OpenGL Extensions

Hello,

I noticed in panda_glext.h that if an extension is already defined, then the new tokens introduced by the extension will not be defined by Panda3D. Same for the typedefs: if GL_GLEXT_PROTOTYPES is defined then they will not be defined.

For example:

#ifndef GL_EXT_texture3D
#define GL_PACK_SKIP_IMAGES_EXT           0x806B
#define GL_PACK_IMAGE_HEIGHT_EXT          0x806C
#define GL_UNPACK_SKIP_IMAGES_EXT         0x806D
#define GL_UNPACK_IMAGE_HEIGHT_EXT        0x806E
#define GL_TEXTURE_3D_EXT                 0x806F
#define GL_PROXY_TEXTURE_3D_EXT           0x8070
#define GL_TEXTURE_DEPTH_EXT              0x8071
#define GL_TEXTURE_WRAP_R_EXT             0x8072
#define GL_MAX_3D_TEXTURE_SIZE_EXT        0x8073
#endif

...

#ifndef GL_EXT_texture3D
#define GL_EXT_texture3D 1
#ifdef GL_GLEXT_PROTOTYPES
GLAPI void APIENTRY glTexImage3DEXT (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *);
GLAPI void APIENTRY glTexSubImage3DEXT (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *);

...

I don’t have that much experience with GL extensions and I was wondering:
1 - It is 100% safe make these assumptions?
2 - Where and when is defined GL_GLEXT_PROTOTYPES?

Thanks a lot,
Federico

panda_glext.h is actually a copy of glext.h, which is provided by the OpenGL consortium. So this is “official” OpenGL code.

The whole point of glext.h is to ensure that all of the known extensions are available to the code at compilation time. It’s possible that some of the extensions have already been defined by the system OpenGL headers, in which case it’s not necessary to redefine them here. But if your system’s OpenGL headers happen to be more out-of-date than Panda’s code, that’s where panda_glext.h takes over and defines them appropriately.

There’s no danger in defining them this way because the extensions are designed not to be redefined once they have been formally encoded. (If they do need to be redefined later, the necessary changes will be introduced as a new and different extension.) So, all headers that define a particular OpenGL extension should define it in exactly the same way.

It’s necessary to define all extensions that Panda3D code attempts to use, or the code won’t compile. However, this has nothing to do with whether the extensions are available at runtime or not. Panda makes the appropriate runtime checks to ensure a particular extension is available before it attempts to make use of it.

Also note that the set of extensions that are provided by the system OpenGL headers isn’t necessarily the same set as the set of extensions that are available at runtime.

Edit: oh, and GL_GLEXT_PROTOTYPES is intended to be defined by user code prior to including this file, if the code wants to define the actual function prototypes for calling the extension functions directly. Panda doesn’t do this, because to do so may force the resulting code to run only with an OpenGL library that actually provides all of the defined extension functions. Instead, Panda uses the standard runtime functions to get a runtime pointer to the extension functions, rather than relying on the linker to link in the reference.

David

Sorry I got rid of the third question as I answered by myself (compiler…) while you were replying. Sorry I should have add an “EDIT:”.

Ah ok, now I understand it better. So, can I update panda_glext.h to a newer glext.h revision in order to have access to GL_EXT_texture_array? I could just edit the current version otherwise. Just let me know what is better.

Thanks for you help.

I think that upgrading the file to a more recent version of glext.h should work fine. I do believe it needs to be an OpenGL 2.x header file, though.

GL_EXT_texture_array is already defined in the current panda_glext.h… :blush:

This is because the set of extensiond depends on my graphics card drivers right? Thus the OpenGL version supported by the system depends entirely on the drivers?

EDIT:
Ah, one more question: glext.h is included also when OPENGLES is defined? I am asking this because I am not sure how to proceed in the glGraphicsStateGuardian: OpenGL ES doesn’t support texture arrays, so should I:

if (_supports_2d_texture_arrays){
#ifndef OPENGLES
... do something with text arrays
#endif 
}


if (_supports_2d_texture_arrays){
... do something with text arrays
}

Right. Also the set of extensions provided.

I don’t honestly remember. We’ve gone back and forth on that. I think the answer is no, so you have to protect code that relies on critical symbols.

David

Ok I’ll enclose all the critical symbols in the #ifndef/#endif.

Thanks a lot,
Federico