Detailed Description

GLSL shader program.

Can be used with Renderer backends that support GLSL, such as the StelQGL2Renderer.

Shader programs are created by StelRenderer. After creation, sources of used vertex and fragment shaders have to be added, and then the shader must be built using the build() member function. After that, the shader can be bound to be used for drawing. It can also be modified by calling the unlock() member function and adding more shaders, and even by disabling or reenabling them. Disabling/reenabling is only supported for vertex shaders, but fragment shader functions can be added when needed.

There is currently no geometry shader support, but it can be added when needed.

Uniform variables are set through the setUniformValue() member function. Only most commonly used data types are supported, but it is easy to add support for more types if needed. Some uniform variables are specified internally and need to be declared in the shader:

Vertex attributes can't be set through the API - they are set internally from vertex buffer during drawing.

Any shader that uses StelProjector projection (that is, any shader except of those working with 2D data) must declare and call the project() function to project the vertex position. If vertex projection is done on the CPU, this is a dummy function that simply returns its argument. If it's done on the GPU, it's done in this function.

The project() function must be declared (but not defined), as follows:

Named vertex shaders can be disabled and reenabled. (Unnamed shaders are always enabled.) This allows to dynamically exchange implementations of functions, making shaders modular. GLSL projection is an example of this.

Due to dynamic shader re-linking needed to support modular shaders, uniforms are cached internally and only uploaded at the draw call when the shader is used. Fixed amount of storage is allocated (currently 512 bytes, which is enough for 8 4x4 matrices). Also only a fixed number of uniforms is supported (currently 32). Both of these limits can be increased if needed (see StelQGLGLSLShader). This storage is written to with each setUniformValue() call, and freed on a call to release().

Parameters

name

Name of the uniform variable. Must match variable name in at least one of the used vertex/fragment shaders. For efficiency reasons, the name is not guaranteed to be copied within the shader backend. Therefore, the name string must exist until a call to release(). (This is easiest to achieve by simply using string literals.)