moggle.core.shader
- enum ShaderType: uint;
- The type of a Shader.
- vertex
- A vertex shader (GL_VERTEX_SHADER).
- fragment
- A fragment shader (GL_FRAGMENT_SHADER).
- struct Shader;
- An OpenGL shader.
This is a wrapper around a GLuint created by glCreateShader(type).
- const @property GLuint id();
- Ths id of this Shader, or 0 if it is not yet created in OpenGL.
- const @property bool created();
const bool opCast(T : bool)();
- Check if this Shader is already created in OpenGL.
- this(ShaderType t);
void create(ShaderType t);
- Create a shader of the specified type.
If the shader is already created, nothing will happen
if it is of the same type, or it is destroyed and (re)created
if it is of a different type.
- static Shader fromSource(ShaderType t, in char[] source_code);
- Create, load, and compile a shader directly from source code.
- static Shader fromFile(ShaderType t, in char[] file_name);
- Create, load, and compile a shader directly from a file.
- void destroy();
- Destroy the OpenGL Shader and reset the id back to 0.
- const ShaderType type();
- The type of this shader.
- void load(in char[] source_code);
- Load the source code for the shader.
- void try_compile();
- Try to compile the Shader, check compiled() to see if it succeeded.
- void compile();
- Try to compile, and throw if it didn't succeed.
Throws:
ShaderCompilationError containing the error log on failure.
- const bool compiled();
- Check if the Shader is succesfully compiled.
- const string log();
- The log of errors for when compilation fails.
- struct ShaderProgram;
- An OpenGL shader program.
This is a wrapper around a GLuint created by glCreateProgram().
Initially, this id is 0.
glCreateProgram is automatically called the first time anything is done with the object.
- const @property GLuint id();
- Ths id of this ShaderProgram, or 0 if it is not yet created in OpenGL.
- const @property bool created();
const bool opCast(T : bool)();
- Check if this ShaderProgram is already created in OpenGL.
- void create();
- Force the creation of a OpenGL ShaderProgram, or do nothing if already created. (Calls glCreateProgram.)
- void destroy();
- Destroy the OpenGL Vao and reset the id back to 0. (Calls glDeleteProgram.)
- void clear();
- destroy() and create().
- void attach(ref const Shader shader);
- Attach a Shader to this program. (Calls glAttachShader.)
- void bindAttribute(GLuint attribute, const(char)[] name);
- Bind an attribute name to a location. (Calls glBindAttribLocation.)
- void tryLink();
- Try to link the ShaderProgram, check linked() to see if it succeeded. (Calls glLinkProgram.)
- void link();
- Try to link, and throw if it didn't succeed.
Throws:
ShaderCompilationError containing the error log on failure.
- const bool linked();
- Check if the ShaderProgram is succesfully linked. (Calls glGetProgramiv with GL_LINK_STATUS.)
- const string log();
- The log of errors for when linking fails. (Calls glGetProgramInfoLog.)
- void use();
- Use this ShaderProgram. (Calls glUseProgram.)
- Uniform!T uniform(T)(const(char)* name);
- Look up a uniform variable by its name. (Calls glGetUniformLocation.)
- struct Uniform(T);
- OpenGL uniform variable.
This is a wrapper around a GLuint generated by glGetUniformLocation(program, name).
An object of this type is returned by ShaderProgram.uniform(name).
- const @property GLuint location();
- The location of this Uniform.
- void set(in T value);
- Calls the correct glUniform function, based on the type T.
(It calls one of:
glUniform1f, glUniform1i, glUniform1ui, glUniform1fv, glUniform2fv,
glUniform3fv, glUniform4fv, glUniform1iv, glUniform2iv, glUniform3iv,
glUniform4iv, glUniform1uiv, glUniform2uiv, glUniform3uiv, glUniform4uiv,
glUniformMatrix2fv, glUniformMatrix3fv, glUniformMatrix4fv,
glUniformMatrix3x2fv, glUniformMatrix2x3fv, glUniformMatrix4x2fv,
glUniformMatrix2x4fv, glUniformMatrix4x3fv, and glUniformMatrix3x4fv.)
Works for GLfloat, GLint, GLuint, Matrices/Vectors/HVectors of GLfloat,
both static and dynamic arrays of GLfloat, GLint and GLuint,
and both static and dynamic arrays of Matrices/Vectors/Hvectors of GLfloat.
- class ShaderCompilationError: object.Exception;
- The error that is thrown when Shader.compile() or ShaderProgram.link() fail.