Create shader from given string, compile it and attach to current program.
For desktop OpenGL, you can attach more than one shader of given type, just make sure that only one main() function is among each type (otherwise link error will be raised later). For OpenGLES, this is not allowed, so don't use this if you want to work with OpenGLES too.
If you want to explicitly get rid of old shaders, use DetachAllShaders.
If the program will be linked successfully, but RequireRunningInHardware = True and the program will be detected to be running in software.
procedure Enable;
Enable (use) this program. Shortcut for CurrentProgram := Self.
class procedure Disable;
Disable this program (use the fixed function pipeline). Shortcut for CurrentProgram := nil.
function SetupUniforms(var BoundTextureUnits: Cardinal): boolean; virtual;
Override this to set uniform values, in particular to bind the textures used by this shader, right after each Enable call.
This is automatically called after every Enable by VRML renderer (when it renders shapes) or scene manager (when it renders screen effects). If you use this TGLSLProgram directly (if you call Enable yourself), then it's your responsibility to call this method explicitly, if you want shaders using it to work.
You can set any uniform values, and generally do anything you want to be done each time this shader is enabled. In particular, you can bind textures and set corresponding uniform variables of them. Increase BoundTextureUnits appropriately.
Returns False is some texture couldn't be bound.
function DebugInfo: string;
Returns multiline debug info about current program. Things like how it's supported (not at all ? ARB extension ? standard ?), names of active uniform and attribute variables etc.
fglrx (Radeon closed-source OpenGL drivers) are buggy (that's not news, I know...) and they report GL_INVALID_ENUM on some queries here. We detect this, and still produce nice debug message, without raising any exception (after all, we have to workaround fglrx bugs, and try to run our program anyway...). What's important for caller is that we have to check first whether there are any OpenGL errors pending, and raise exceptions on them.
This is program info log, given to you from OpenGL after the program is linked.
function RunningInHardware: boolean;
After the program is linked, you can check this.
Note that this is necessarily implemented in quite hacky way (by looking at ProgramInfoLog), there is no way currently (AFAIK ?) to get this information cleanly from OpenGL. In case of doubts, we try to "trust" OpenGL to execute shader in hardware. Return False only when we see clear indication in ProgramInfoLog that it'll run in software.
Set appropriate uniform variable value. The used type must match the type of this variable in GLSL program.
OpenGL forces some constraints on using this:
This should be used only after linking, and re-linking clears (sets to zero) all uniform variables values.
This can be used only when the program is currently used. So call Enable before doing SetUniform calls.
This is required by OpenGL glUniform* commands. glGetUniformLocation take program id as parameter, so they can operate on any program. But glUniform* operate only on active program.
Only active uniforms variables may be set. Active means, quoting OpenGL manpages, a variable that is determined during the link operation that it may be accessed during program execution. In other words, when linking GLSL program, unused variables may be eliminated, and you cannot set them by SetUniform.
Call DebugInfo to see what uniform variables are considered active for your shader.
Load and enable vertex attribute data. This calls glVertexAttribPointer and enables it by glEnableVertexAttribArray (or ARB extension equivalents), see OpenGL reference for details.
The attribute name is automatically resolved to a "location". We add LocationOffset (useful if you want to load matrix attributes, when you have to load matrix columns separately, with LocationOffset = column index).
Returns
Attribute location (with LocationOffset already applied). You can use it with DisableVertexAttribArray.
Set attribute variable value. The used type must match the type of this variable in GLSL program.
OpenGL forces some constraints on using this, see SetUniform. In short: use this only after linking and using the program. And note that attributes declared but not actually used in shader code may be eliminated, use DebugInfo to see which attributes are actually used (active in OpenGL terminology).
These should not be often useful. Usually, you should rather load attribute arrays, by VertexAttribPointer.
Note that this is only one of the many things that can go wrong. And on most cases we don't raise any error, instead OpenGL sets it's error state and you probably want to call CheckGLErrors from time to time to catch them.
What to do when GLSL uniform variable is set (SetUniform) but doesn't exist in the shader. Note that OpenGL aggresively removes unused code and variables from the shader when compiling/linking, so this also happens for "declared but detected to not used" variables.