I want to load some textures using glTexStorageXX()
, but also fall back to glTexImageXX()
if that feature isn't available to the platform.
Is there a way to check if those functions are available on a platform? I think glew.h
might try to load the GL_ARB_texture_storage
extensions into the same function pointer if using OpenGL 3.3, but I'm not sure how to check if it succeeded. Is it as simple as checking the function pointer, or is it more complicated?
(Also, I'm making some guesses at how glew.h
works that might be wrong, it might not use function pointers and this might not be a run-time check I can make? If so, would I just... need to compile executables for different versions of OpenGL?)
if (glTexStorage2D) {
// ... calls that assume all glTexStorageXX also exist,
// ... either as core functions or as ARB extensions
} else {
// ... calls that fallback to glTexImage2D() and such.
}
You need to check if the OpenGL extension is supported. The number of extensions supported by the GL implementation can be called up with
glGetIntegerv(GL_NUM_EXTENSIONS, ...)
. The name of an extension can be queried withglGetStringi(GL_EXTENSIONS, ...)
.Read the extensions into a
std::set
Check if an extension is supported:
glTexStorage2D
is in core since OpenGL version 4.2. So if you've created at least an OpenGL 4.2 context, there's no need to look for the extension.When an extension is supported, all of the features and functions specified in the extension specification are supported. (see GL_ARB_texture_storage)
GLEW makes this a little easier because it provides a Boolean state for each extension.
(see GLEW - Checking for Extensions) e.g.: