Unit CastleGLShaders
Description
OpenGL shaders in GLSL language.
GLSL version:
For maximum portability, provide shader code that works with oldest GLSL versions, and do not declare "#version". This means targeting ancient GLSL 1.10 version for desktop OpenGL (introduced in OpenGL 2.0) and targeting GLSL 1.00 for OpenGLES (introduced in OpenGLES 2.0). This means using "attribute", "varying" keywords, and querying the textures using "texture2D", "textureCube" and so on.
When compiling the shader on modern OpenGL or OpenGLES, we will add a modern #version statement to the shader, and define a few macros that make it use modern keywords (e.g. "attribute" will be replaced with "in" in vertex shader; "texture2D" call will be replaced with "texture"). The resulting shader will not use any deprecated features, so it should be fine for OpenGL "core" profile (without compatibility) too.
As of now, this means we bump the #version for the desktop OpenGL 3.1 core profile (if OpenGL >= 3.1) and we bump the #version for the mobile OpenGLES 3 (if OpenGLES >= 3.0).
Note: If you know you want to target only newer OpenGL(ES) versions, you can also specify #version in shader code explicitly. We will not add another #version then. It is your responsibility then to provide proper alternatives for desktop OpenGL and mobile OpenGLES, as they use similar but not exactly compatible GLSL versions.
For geometry shaders, you can assume GLSL >= 1.50 (OpenGL 3.2). We do not support geometry shaders with older versions.
Set InternalUpgradeGlslVersion to
False
to test that shaders work also without it.Precision on OpenGLES:
We automatically add "precision mediump float;" to fragment shader on OpenGLES, if no declaration "precision mediump/lowp/highp float;" is found in the code. This is practically universally needed for OpenGLES fragment shader, that have no default precision.
Creating/destroying the TGLSLProgram instance immediately creates/destroys appropriate program on GPU. So be sure to create/destroy it only when you have OpenGL context available (for example, create in TCastleUserInterface.GLContextOpen, and destroy in TCastleUserInterface.GLContextClose).
Upon creation, we check current OpenGL context abilities.
Currently 2 support levels are possible: no support at all (ancient OpenGL) or support built-in (newer OpenGL versions, >= 2.0). The support for shaders using ARB extensions has been removed at 2023-01, as practically no GPU had it and we didn't really test it.
Both cases are automatically handled inside, so usually you do not have to care about these details.
Uses
- SysUtils
- Classes
- Generics.Collections
- CastleGL
- CastleGLUtils
- CastleUtils
- CastleVectors
- CastleRenderOptions
Overview
Classes, Interfaces, Objects and Records
Name | Description |
---|---|
Class EGLSLError |
Common class for exceptions related to GLSL programs. |
Class EGLSLShaderCompileError |
|
Class EGLSLProgramLinkError |
|
Class EGLSLAttributeNotFound |
|
Class EGLSLTransformFeedbackError |
|
Record TGLSLUniform |
GLSL uniform provides information to shader that is constant for a given shader execution. |
Record TGLSLAttribute |
GLSL attribute provides per-vertex information to the shader. |
Class TGLSLProgram |
Manage (build, use) a program in GLSL (OpenGL Shading Language). |
Functions and Procedures
function GetCurrentProgram: TGLSLProgram; deprecated 'use RenderContext.CurrentProgram'; |
procedure SetCurrentProgram(const Value: TGLSLProgram); deprecated 'use RenderContext.CurrentProgram'; |
Types
TGLuintList = TCardinalList; |
TGLSLAttributeList = specialize TList<TGLSLAttribute>; |
TLocationCache = specialize TDictionary<String, TGLint>; |
TGLSLProgramList = specialize TObjectList<TGLSLProgram>; |
Variables
LogShaders: boolean; |
property CurrentProgram: TGLSLProgram
read GetCurrentProgram write SetCurrentProgram; |
Description
Functions and Procedures
function GetCurrentProgram: TGLSLProgram; deprecated 'use RenderContext.CurrentProgram'; |
Warning: this symbol is deprecated: use RenderContext.CurrentProgram This item has no description. |
procedure SetCurrentProgram(const Value: TGLSLProgram); deprecated 'use RenderContext.CurrentProgram'; |
Warning: this symbol is deprecated: use RenderContext.CurrentProgram This item has no description. |
Types
TGLuintList = TCardinalList; |
This item has no description. |
TGLSLAttributeList = specialize TList<TGLSLAttribute>; |
This item has no description. |
TLocationCache = specialize TDictionary<String, TGLint>; |
This item has no description. |
TGLSLProgramList = specialize TObjectList<TGLSLProgram>; |
This item has no description. |
Variables
LogShaders: boolean; |
This item has no description. |
property CurrentProgram: TGLSLProgram
read GetCurrentProgram write SetCurrentProgram; |
Warning: this symbol is deprecated.
Currently enabled GLSL program. Use RenderContext.CurrentProgram |
Generated by PasDoc 0.16.0-snapshot.