Hatch Game Engine Documentation v1.4.0
The documentation for the Hatch Game Engine
Loading...
Searching...
No Matches
Shader Class Reference

Representation of a GPU shader. More...

Public Member Functions

boolean HasStage (SHADERSTAGE stage)
 Checks if the shader program has a shader stage.
boolean CanCompile ()
 Checks if the shader can be compiled.
boolean IsValid ()
 Checks if the shader can be used.
void AddStage (SHADERSTAGE stage, string shader)
 Adds a stage to the shader program. This should not be called multiple times for the same stage.
void AddStage (SHADERSTAGE stage, stream shader)
 Adds a stage to the shader program. This should not be called multiple times for the same stage.
void AddStageFromString (SHADERSTAGE stage, string shader)
 Adds a stage to the shader program, from a String containing the shader code. This should not be called multiple times for the same stage.
void AssignTextureUnit (string uniform)
 Assigns a texture unit to a texture uniform. This is safe to call multiple times for the same uniform name.
integer GetTextureUnit (string uniform)
 Gets the texture unit assigned to a texture uniform.
boolean Compile ()
 Compiles a shader.
boolean HasUniform (string uniform)
 Checks if the shader has an uniform with the given name. This can only be called after the shader has been compiled.
SHADERSTAGE GetUniformType (string uniform)
 Gets the type of the uniform with the given name. This can only be called after the shader has been compiled.
void SetUniform (string uniform, number value, SHADERDATATYPE dataType)
 Sets the value of an uniform variable. The value passed to the uniform persists between different invocations, and can be set at any time, as long as the shader is valid. This can only be called after the shader has been compiled.
void SetUniform (string uniform, array value, SHADERDATATYPE dataType)
 Sets the value of an uniform variable. The value passed to the uniform persists between different invocations, and can be set at any time, as long as the shader is valid. This can only be called after the shader has been compiled.
void SetTexture (string uniform, integer image)
 Assigns an Image to a specific texture unit linked to an uniform variable. The texture unit must have been defined using Shader.AssignTextureUnit for this function to succeed.
void Delete ()
 Deletes a shader. It can no longer be used after this function is called.
 Shader ()
 Creates a shader program.

Detailed Description

Representation of a GPU shader.

Not all devices will support shaders. Use Device.GetCapability("graphics_shaders") to verify if that's the case.
The software renderer does not support shaders.

Member Function Documentation

◆ AddStage() [1/2]

void Shader.AddStage ( SHADERSTAGE stage,
stream shader )

Adds a stage to the shader program. This should not be called multiple times for the same stage.

Parameters
stageThe shader stage.
shaderA stream containing shader code.

◆ AddStage() [2/2]

void Shader.AddStage ( SHADERSTAGE stage,
string shader )

Adds a stage to the shader program. This should not be called multiple times for the same stage.

Parameters
stageThe shader stage.
shaderFilename of the resource containing shader code.

◆ AddStageFromString()

void Shader.AddStageFromString ( SHADERSTAGE stage,
string shader )

Adds a stage to the shader program, from a String containing the shader code. This should not be called multiple times for the same stage.

Parameters
stageThe shader stage.
shaderA String that contains shader code.

◆ AssignTextureUnit()

void Shader.AssignTextureUnit ( string uniform)

Assigns a texture unit to a texture uniform. This is safe to call multiple times for the same uniform name.

Parameters
uniformThe name of the uniform.

◆ CanCompile()

boolean Shader.CanCompile ( )

Checks if the shader can be compiled.

Returns
Returns whether the shader can be compiled.

◆ Compile()

boolean Shader.Compile ( )

Compiles a shader.

Returns
Returns whether the shader was compiled.

◆ GetTextureUnit()

integer Shader.GetTextureUnit ( string uniform)

Gets the texture unit assigned to a texture uniform.

Parameters
uniformThe name of the uniform.
Returns
Returns an integer value, or null if no texture unit was assigned.

◆ GetUniformType()

SHADERSTAGE Shader.GetUniformType ( string uniform)

Gets the type of the uniform with the given name. This can only be called after the shader has been compiled.

Parameters
uniformThe name of the uniform.
Returns
Returns the data type of the uniform, or null if there is no uniform with that name.

◆ HasStage()

boolean Shader.HasStage ( SHADERSTAGE stage)

Checks if the shader program has a shader stage.

Parameters
stageThe shader stage.
Returns
Returns whether there is a shader stage of the given type.

◆ HasUniform()

boolean Shader.HasUniform ( string uniform)

Checks if the shader has an uniform with the given name. This can only be called after the shader has been compiled.

Parameters
uniformThe name of the uniform.
Returns
Returns whether there is an uniform with the given name.

◆ IsValid()

boolean Shader.IsValid ( )

Checks if the shader can be used.

Returns
Returns whether the shader can be used.

◆ SetTexture()

void Shader.SetTexture ( string uniform,
integer image )

Assigns an Image to a specific texture unit linked to an uniform variable. The texture unit must have been defined using Shader.AssignTextureUnit for this function to succeed.

Parameters
uniformThe name of the uniform.
imageThe image index to bind to the uniform.

◆ SetUniform() [1/2]

void Shader.SetUniform ( string uniform,
array value,
SHADERDATATYPE dataType )

Sets the value of an uniform variable. The value passed to the uniform persists between different invocations, and can be set at any time, as long as the shader is valid. This can only be called after the shader has been compiled.

Parameters
uniformThe name of the uniform.
valueThe value.
dataTypeThe data type of the value being sent. This is required if the value being passed is an array.

◆ SetUniform() [2/2]

void Shader.SetUniform ( string uniform,
number value,
SHADERDATATYPE dataType )

Sets the value of an uniform variable. The value passed to the uniform persists between different invocations, and can be set at any time, as long as the shader is valid. This can only be called after the shader has been compiled.

Parameters
uniformThe name of the uniform.
valueThe value.
dataTypeThe data type of the value being sent. This is required if the value being passed is an array.