When to use #extension in GLSL?

In my fragment program, how do I know whether I need to explicitly enable some extension using #extension? I presume it depends on what OpenGL core version the graphics card driver implements. So the NPOT textures extension, which became part of 2.0 core, should probably be explicitly enabled on a machine with older driver (let’s assume that I couldn’t update the driver). Could someone confirm my speculations?

Bad example. Shaders don’t know about texture sizes. They just work with samplers and texture coodinates. If that is slow or fast depends on the HW capability. If the extension or OpenGL 2.0 is not exported you will get an OpenGL error as soon as you download a NPOT image.

What you need to do in the shader source for example is to enable ARB_draw_buffers when using gl_FragData[], etc.
The compiler should tell you what’s required when you use non-core functionality.
Similarly for the #version tag.

Originally posted by dobradusa:
In my fragment program, how do I know whether I need to explicitly enable some extension using #extension?
You need to enable extensions that are not part of the core of the language version (not OGL version) you are targeting with the #version directive.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.