Class TGLSLProgram
Unit
Declaration
type TGLSLProgram = class(TObject)
Description
Easily handle program in GLSL (OpenGL Shading Language).
Hierarchy
- TObject
- TGLSLProgram
Overview
Methods
constructor Create; |
|
destructor Destroy; override; |
|
procedure AttachVertexShader(const S: string); |
|
procedure AttachGeometryShader(const S: string); |
|
procedure AttachFragmentShader(const S: string); |
|
procedure AttachShader(const ShaderType: TShaderType; const S: string); overload; |
|
procedure AttachShader(const ShaderType: TShaderType; const Parts: TStrings); overload; |
|
procedure DetachAllShaders; |
|
procedure SetTransformFeedbackVaryings(const Varyings: array of PChar; const IsSingleBufferMode: Boolean = True); |
|
procedure Link; overload; virtual; |
|
procedure Link(Ignored: boolean); overload; deprecated 'use parameterless Link method'; |
|
procedure Enable; |
|
class procedure Disable; |
|
function SetupUniforms(var BoundTextureUnits: Cardinal): boolean; virtual; |
|
function DebugInfo: string; |
|
function ProgramInfoLog: string; |
|
function RunningInHardware: boolean; |
|
class function ClassSupport: TGLSupport; deprecated 'use GLFeatures.Shaders'; |
|
function Uniform(const Name: string): TGLSLUniform; overload; |
|
function Uniform(const Name: string; const AUniformMissing: TUniformMissing): TGLSLUniform; overload; |
|
procedure SetUniform(const Name: string; const Value: boolean ; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TGLint ; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector2Integer; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector3Integer; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector4Integer; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TGLfloat ; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector2 ; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector3 ; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector4 ; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TMatrix2 ; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TMatrix3 ; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TMatrix4 ; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TBooleanList; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TLongIntList; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TSingleList ; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector2List; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector3List; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector4List; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TMatrix3List; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TMatrix4List; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: boolean ); overload; |
|
procedure SetUniform(const Name: string; const Value: TGLint ); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector2Integer); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector3Integer); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector4Integer); overload; |
|
procedure SetUniform(const Name: string; const Value: TGLfloat ); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector2 ); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector3 ); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector4 ); overload; |
|
procedure SetUniform(const Name: string; const Value: TMatrix2 ); overload; |
|
procedure SetUniform(const Name: string; const Value: TMatrix3 ); overload; |
|
procedure SetUniform(const Name: string; const Value: TMatrix4 ); overload; |
|
procedure SetUniform(const Name: string; const Value: TBooleanList); overload; |
|
procedure SetUniform(const Name: string; const Value: TLongIntList); overload; |
|
procedure SetUniform(const Name: string; const Value: TSingleList ); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector2List); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector3List); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector4List); overload; |
|
procedure SetUniform(const Name: string; const Value: TMatrix3List); overload; |
|
procedure SetUniform(const Name: string; const Value: TMatrix4List); overload; |
|
function Attribute(const Name: string): TGLSLAttribute; |
|
function AttributeOptional(const Name: string): TGLSLAttribute; |
|
function VertexAttribPointer(const Name: string; LocationOffset: TGLSLAttribute.TLocationOffset; Size: TGLint; AType: TGLenum; Normalized: TGLboolean; Stride: TGLsizei; Ptr: Pointer): TGLint; deprecated 'use TGLSLAttribute.EnableArray'; |
|
class procedure DisableVertexAttribArray(Location: TGLint); deprecated 'use TGLSLAttribute.DisableArray'; |
|
procedure SetAttribute(const Name: string; const Value: TGLfloat); overload; deprecated 'use TGLSLAttribute.SetValue'; |
|
procedure SetAttribute(const Name: string; const Value: TVector2); overload; deprecated 'use TGLSLAttribute.SetValue'; |
|
procedure SetAttribute(const Name: string; const Value: TVector3); overload; deprecated 'use TGLSLAttribute.SetValue'; |
|
procedure SetAttribute(const Name: string; const Value: TVector4); overload; deprecated 'use TGLSLAttribute.SetValue'; |
|
procedure SetAttribute(const Name: string; const Value: TMatrix3); overload; deprecated 'use TGLSLAttribute.SetValue'; |
|
procedure SetAttribute(const Name: string; const Value: TMatrix4); overload; deprecated 'use TGLSLAttribute.SetValue'; |
|
procedure SetAttribute(const Name: string; const Value: TVector4Integer); overload; deprecated 'use TGLSLAttribute.SetValue'; |
|
procedure SetAttribute(const Name: string; const Value: TVector4Byte); overload; deprecated 'use TGLSLAttribute.SetValue'; |
|
procedure SetAttribute(const Name: string; const Value: TGLdouble); overload; deprecated 'use TGLSLAttribute.SetValue'; |
Properties
property Support: TGLSupport read FSupport; deprecated 'use GLFeatures.Shaders'; |
|
property UniformMissing: TUniformMissing
read FUniformMissing write FUniformMissing
default umWarning; |
|
class property Current: TGLSLProgram read GetCurrent write SetCurrent; deprecated 'use RenderContext.CurrentProgram'; |
Description
Methods
constructor Create; |
|
destructor Destroy; override; |
|
procedure AttachVertexShader(const S: string); |
|
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.
Exceptions raised
|
procedure AttachGeometryShader(const S: string); |
|
procedure AttachFragmentShader(const S: string); |
|
procedure AttachShader(const ShaderType: TShaderType; const S: string); overload; |
|
procedure AttachShader(const ShaderType: TShaderType; const Parts: TStrings); overload; |
|
Attach multiple shader parts for given type. For normal OpenGL, we can use GLSL separate compilation units. So this is equivalent to just calling For OpenGL ES, this is unfortunately not possible, you can only attach a single shader of a given type (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glAttachShader.xml ). So we simply concatenate the shaders into one. |
procedure DetachAllShaders; |
|
procedure SetTransformFeedbackVaryings(const Varyings: array of PChar; const IsSingleBufferMode: Boolean = True); |
|
Specify values to record in transform feedback buffers. This must be called before Link method. |
procedure Link; overload; virtual; |
|
Link the program, this should be done after attaching all shaders and before actually using the program. Exceptions raised
|
procedure Link(Ignored: boolean); overload; deprecated 'use parameterless Link method'; |
|
Warning: this symbol is deprecated: use parameterless Link method |
procedure Enable; |
|
Enable (use) this program. Shortcut for |
class procedure Disable; |
|
Disable this program (use the fixed function pipeline). Shortcut for |
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 our renderer (when it renders shapes) or TCastleScreenEffect (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 |
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. Exceptions raised
|
function ProgramInfoLog: string; |
|
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 |
class function ClassSupport: TGLSupport; deprecated 'use GLFeatures.Shaders'; |
|
Warning: this symbol is deprecated: use GLFeatures.Shaders What support do we get from current OpenGL context ? This is much like Support, but it's a class function. |
function Uniform(const Name: string): TGLSLUniform; overload; |
|
Get the uniform instance. It can be used to make repeated TGLSLUniform.SetValue calls. You must link the program first. If the uniform doesn't exist (or is unused), the action we take depends on UniformMissing property (by default – umWarning). The overloaded version with extra |
function Uniform(const Name: string; const AUniformMissing: TUniformMissing): TGLSLUniform; overload; |
|
procedure SetUniform(const Name: string; const Value: boolean ; const AUniformMissing: TUniformMissing); overload; |
|
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 will make warning if the variable is not found within the program and UniformMissing = umWarning. The overloaded version with explicit AUniformMissing parameter uses that to decide whether to show warning. |
procedure SetUniform(const Name: string; const Value: TGLint ; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector2Integer; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector3Integer; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector4Integer; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TGLfloat ; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector2 ; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector3 ; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector4 ; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TMatrix2 ; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TMatrix3 ; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TMatrix4 ; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TBooleanList; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TLongIntList; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TSingleList ; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector2List; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector3List; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector4List; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TMatrix3List; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: TMatrix4List; const AUniformMissing: TUniformMissing); overload; |
|
procedure SetUniform(const Name: string; const Value: boolean ); overload; |
|
procedure SetUniform(const Name: string; const Value: TGLint ); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector2Integer); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector3Integer); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector4Integer); overload; |
|
procedure SetUniform(const Name: string; const Value: TGLfloat ); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector2 ); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector3 ); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector4 ); overload; |
|
procedure SetUniform(const Name: string; const Value: TMatrix2 ); overload; |
|
procedure SetUniform(const Name: string; const Value: TMatrix3 ); overload; |
|
procedure SetUniform(const Name: string; const Value: TMatrix4 ); overload; |
|
procedure SetUniform(const Name: string; const Value: TBooleanList); overload; |
|
procedure SetUniform(const Name: string; const Value: TLongIntList); overload; |
|
procedure SetUniform(const Name: string; const Value: TSingleList ); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector2List); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector3List); overload; |
|
procedure SetUniform(const Name: string; const Value: TVector4List); overload; |
|
procedure SetUniform(const Name: string; const Value: TMatrix3List); overload; |
|
procedure SetUniform(const Name: string; const Value: TMatrix4List); overload; |
|
function Attribute(const Name: string): TGLSLAttribute; |
|
Get the attribute instance. It can be used to make repeated TGLSLAttribute.SetValue and TGLSLAttribute.EnableArray. Exceptions raised
|
function AttributeOptional(const Name: string): TGLSLAttribute; |
|
Get the attribute instance. It can be used to make repeated TGLSLAttribute.SetValue and TGLSLAttribute.EnableArray. Returned attribute has TGLSLAttribute.Location equal to -1. All the calls to TGLSLAttribute.SetValue or TGLSLAttribute.EnableArray or TGLSLAttribute.DisableArray methods are silently ignored. |
function VertexAttribPointer(const Name: string; LocationOffset: TGLSLAttribute.TLocationOffset; Size: TGLint; AType: TGLenum; Normalized: TGLboolean; Stride: TGLsizei; Ptr: Pointer): TGLint; deprecated 'use TGLSLAttribute.EnableArray'; |
|
Warning: this symbol is deprecated: use TGLSLAttribute.EnableArray 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). For repeated usage, it's better to use Attribute method, and repeatedly call TGLSLAttribute.EnableArray on the same TGLSLAttribute instance.
ReturnsAttribute location (with LocationOffset already applied). You can use it with DisableVertexAttribArray. Exceptions raised
|
class procedure DisableVertexAttribArray(Location: TGLint); deprecated 'use TGLSLAttribute.DisableArray'; |
|
Warning: this symbol is deprecated: use TGLSLAttribute.DisableArray |
procedure SetAttribute(const Name: string; const Value: TGLfloat); overload; deprecated 'use TGLSLAttribute.SetValue'; |
|
Warning: this symbol is deprecated: use TGLSLAttribute.SetValue 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 the program. The program is automatically enabled (set as RenderContext.CurrentProgram) by this. 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 used. Usually, you should rather load attribute arrays, by VertexAttribPointer. You should also get attribute by the Attribute method, as TGLSLAttribute, and then call TGLSLAttribute.SetValue or TGLSLAttribute.EnableArray.
Exceptions raised
|
procedure SetAttribute(const Name: string; const Value: TVector2); overload; deprecated 'use TGLSLAttribute.SetValue'; |
|
Warning: this symbol is deprecated: use TGLSLAttribute.SetValue |
procedure SetAttribute(const Name: string; const Value: TVector3); overload; deprecated 'use TGLSLAttribute.SetValue'; |
|
Warning: this symbol is deprecated: use TGLSLAttribute.SetValue |
procedure SetAttribute(const Name: string; const Value: TVector4); overload; deprecated 'use TGLSLAttribute.SetValue'; |
|
Warning: this symbol is deprecated: use TGLSLAttribute.SetValue |
procedure SetAttribute(const Name: string; const Value: TMatrix3); overload; deprecated 'use TGLSLAttribute.SetValue'; |
|
Warning: this symbol is deprecated: use TGLSLAttribute.SetValue |
procedure SetAttribute(const Name: string; const Value: TMatrix4); overload; deprecated 'use TGLSLAttribute.SetValue'; |
|
Warning: this symbol is deprecated: use TGLSLAttribute.SetValue |
procedure SetAttribute(const Name: string; const Value: TVector4Integer); overload; deprecated 'use TGLSLAttribute.SetValue'; |
|
Warning: this symbol is deprecated: use TGLSLAttribute.SetValue |
procedure SetAttribute(const Name: string; const Value: TVector4Byte); overload; deprecated 'use TGLSLAttribute.SetValue'; |
|
Warning: this symbol is deprecated: use TGLSLAttribute.SetValue |
procedure SetAttribute(const Name: string; const Value: TGLdouble); overload; deprecated 'use TGLSLAttribute.SetValue'; |
|
Warning: this symbol is deprecated: use TGLSLAttribute.SetValue |
Properties
property Support: TGLSupport read FSupport; deprecated 'use GLFeatures.Shaders'; |
|
Warning: this symbol is deprecated: use GLFeatures.Shaders |
property UniformMissing: TUniformMissing
read FUniformMissing write FUniformMissing
default umWarning; |
|
What to do when GLSL uniform variable is accessed (by SetUniform or Uniform) 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 unused" variables. This is only the default value, each Uniform method call may explicitly use other TUniformMissing. See also
|
class property Current: TGLSLProgram read GetCurrent write SetCurrent; deprecated 'use RenderContext.CurrentProgram'; |
|
Warning: this symbol is deprecated: use RenderContext.CurrentProgram
Currently enabled GLSL program. |
Generated by PasDoc 0.16.0.