Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
oe::render::ShaderBase Class Reference

Shader class. More...

#include <OxygenEngine/render/shader_base.h>

Inheritance diagram for oe::render::ShaderBase:
[legend]
Collaboration diagram for oe::render::ShaderBase:
[legend]

Public Member Functions

 ShaderBase (const std::string &name="")
 Create a new shader instance.
 
template<typename T >
void define (const std::string &name, const T &value)
 Define a shader constant.
 
void define (const std::string &name, const char *value)
 Define a shader constant.
 
void define (const std::string &name, const std::string &value)
 Define a shader constant.
 
void define (const std::string &name)
 Define a shader constant without value.
 
const std::string & getName () const
 Get shader name.
 
void compile (const GeometryPass vertex_pass, const RenderingPass fragment_pass)
 Compile / link the shader using the graphic API.
 
void bind (const GeometryPass vertex_pass, const RenderingPass fragment_pass)
 Use the shader in graphic API.
 
void fillFromCamera (const scene::Camera &camera) noexcept
 Fill uniforms from camera (mainly position + transform matrices)
 
void fillTextures (const std::map< std::string, std::pair< uint32_t, std::shared_ptr< oe::render::Texture > > > &textures)
 Fill textures uniforms + bind textures.
 
void fillCubemaps (const std::map< std::string, std::pair< uint32_t, std::shared_ptr< oe::render::Cubemap > > > &cubemaps)
 Fill cubemaps uniforms + bind cubemaps.
 
void fillFromMaterial (const scene::Material *material)
 Fill uniforms from material.
 
void unbind ()
 Tell the graphic API to release this shader.
 
void setInt (const std::string &name, const int32_t &value)
 Send an int uniform to the shader.
 
void setUInt (const std::string &name, const uint32_t &value)
 Send an unsigned int uniform to the shader.
 
void setFloat (const std::string &name, const float &value)
 Send a float uniform to the shader.
 
void setDouble (const std::string &name, const double &value)
 Send a double uniform to the shader.
 
void setMat3 (const std::string &name, const glm::mat3 &value)
 Send a 3x3 matrix uniform to the shader.
 
void setMat4 (const std::string &name, const glm::mat4 &value)
 Send a 4x4 matrix uniform to the shader.
 
void setVec2i (const std::string &name, const glm::ivec2 &value)
 Send an ivec2 uniform to the shader.
 
void setVec2 (const std::string &name, const glm::vec2 &value)
 Send a vec2 uniform to the shader.
 
void setVec3 (const std::string &name, const glm::vec3 &value)
 Send a vec3 uniform to the shader.
 
void setVec4 (const std::string &name, const glm::vec4 &value)
 Send a vec4 uniform to the shader.
 
void setIntArray (const std::string &name, const std::vector< int32_t > &values)
 Send an array of int uniforms to the shader.
 
void setUIntArray (const std::string &name, const std::vector< uint32_t > &values)
 Send a array of unsigned int uniforms to the shader.
 
void setFloatArray (const std::string &name, const std::vector< float > &values)
 Send an array of float uniforms to the shader.
 
void setDoubleArray (const std::string &name, const std::vector< double > &values)
 Send an array of double uniforms to the shader.
 
void setVec2iArray (const std::string &name, const std::vector< glm::ivec2 > &values)
 Send an array of ivec2 uniforms to the shader.
 
void setVec2Array (const std::string &name, const std::vector< glm::vec2 > &values)
 Send an array of vec2 uniforms to the shader.
 
void setVec3Array (const std::string &name, const std::vector< glm::vec3 > &values)
 Send an array of vec3 uniforms to the shader.
 
void setVec4Array (const std::string &name, const std::vector< glm::vec4 > &values)
 Send an array of vec4 uniforms to the shader.
 
void setMat4Array (const std::string &name, const std::vector< glm::mat4 > &values)
 Send an array of matrix uniforms to the shader.
 

Protected Attributes

std::unordered_map< GeometryPass, std::string > _vertex_shader_sources
 
std::unordered_map< RenderingPass, std::string > _fragment_shader_sources
 
std::string _header
 

Detailed Description

Shader class.

Note
No graphic API calls done in functions before compilation

Constructor & Destructor Documentation

◆ ShaderBase()

oe::render::ShaderBase::ShaderBase ( const std::string &  name = "")

Create a new shader instance.

Parameters
nameName of the shader (will be used in error messages)

Member Function Documentation

◆ bind()

void oe::render::ShaderBase::bind ( const GeometryPass  vertex_pass,
const RenderingPass  fragment_pass 
)

Use the shader in graphic API.

Note
will try to compile if the pass is not already compiled

◆ compile()

void oe::render::ShaderBase::compile ( const GeometryPass  vertex_pass,
const RenderingPass  fragment_pass 
)

Compile / link the shader using the graphic API.

Exceptions
Exceptionif compilation / linking failed or pass combination not available
Note
will silently fail if specified pass are already compiled

◆ define() [1/4]

void oe::render::ShaderBase::define ( const std::string &  name)
inline

Define a shader constant without value.

Same behavior as if you added #define MY_CONSTANT in the shader code

Parameters
nameConstant name

◆ define() [2/4]

void oe::render::ShaderBase::define ( const std::string &  name,
const char *  value 
)
inline

Define a shader constant.

Overload for a C-style string

◆ define() [3/4]

void oe::render::ShaderBase::define ( const std::string &  name,
const std::string &  value 
)
inline

Define a shader constant.

Overload for string

◆ define() [4/4]

template<typename T >
void oe::render::ShaderBase::define ( const std::string &  name,
const T &  value 
)
inline

Define a shader constant.

Same behavior as if you added #define MY_CONSTANT VALUE in the shader code

Note
Any value type accepted as long as it can be converted to a string
Parameters
nameConstant name
valueConstant value

◆ fillFromCamera()

void oe::render::ShaderBase::fillFromCamera ( const scene::Camera camera)
noexcept

Fill uniforms from camera (mainly position + transform matrices)

These uniforms will be filled from the camera:

  • vec3 uEyePos : World space camera position
  • mat4 uTransform : Matrix to conert from world space to clip space

◆ fillFromMaterial()

void oe::render::ShaderBase::fillFromMaterial ( const scene::Material material)

Fill uniforms from material.

Uniform name Description
float uAlphaCutoff Alpha threshold
vec2 uTextureUVTilling Texture tiling data
vec2 uTextureUVOffset Texture offset
float uTransmission Transmissive factor
float uThickness Thickness
Note
Additional uniforms will be filled from the custom properties

◆ getName()

const std::string & oe::render::ShaderBase::getName ( ) const
inline

Get shader name.

Returns
Name of the shader

◆ setDouble()

void oe::render::ShaderBase::setDouble ( const std::string &  name,
const double &  value 
)

Send a double uniform to the shader.

Parameters
nameUniform name in shader
valueUniform value to send

◆ setDoubleArray()

void oe::render::ShaderBase::setDoubleArray ( const std::string &  name,
const std::vector< double > &  values 
)

Send an array of double uniforms to the shader.

Parameters
nameUniform name in shader
valuesUniform values to send

◆ setFloat()

void oe::render::ShaderBase::setFloat ( const std::string &  name,
const float &  value 
)

Send a float uniform to the shader.

Parameters
nameUniform name in shader
valueUniform value to send

◆ setFloatArray()

void oe::render::ShaderBase::setFloatArray ( const std::string &  name,
const std::vector< float > &  values 
)

Send an array of float uniforms to the shader.

Parameters
nameUniform name in shader
valuesUniform values to send

◆ setInt()

void oe::render::ShaderBase::setInt ( const std::string &  name,
const int32_t &  value 
)

Send an int uniform to the shader.

Parameters
nameUniform name in shader
valueUniform value to send

◆ setIntArray()

void oe::render::ShaderBase::setIntArray ( const std::string &  name,
const std::vector< int32_t > &  values 
)

Send an array of int uniforms to the shader.

Parameters
nameUniform name in shader
valuesUniform values to send

◆ setMat3()

void oe::render::ShaderBase::setMat3 ( const std::string &  name,
const glm::mat3 &  value 
)

Send a 3x3 matrix uniform to the shader.

Parameters
nameUniform name in shader
valueUniform value to send

◆ setMat4()

void oe::render::ShaderBase::setMat4 ( const std::string &  name,
const glm::mat4 &  value 
)

Send a 4x4 matrix uniform to the shader.

Parameters
nameUniform name in shader
valueUniform value to send

◆ setMat4Array()

void oe::render::ShaderBase::setMat4Array ( const std::string &  name,
const std::vector< glm::mat4 > &  values 
)

Send an array of matrix uniforms to the shader.

Parameters
nameUniform name in shader
valuesUniform values to send

◆ setUInt()

void oe::render::ShaderBase::setUInt ( const std::string &  name,
const uint32_t &  value 
)

Send an unsigned int uniform to the shader.

Parameters
nameUniform name in shader
valueUniform value to send

◆ setUIntArray()

void oe::render::ShaderBase::setUIntArray ( const std::string &  name,
const std::vector< uint32_t > &  values 
)

Send a array of unsigned int uniforms to the shader.

Parameters
nameUniform name in shader
valuesUniform values to send

◆ setVec2()

void oe::render::ShaderBase::setVec2 ( const std::string &  name,
const glm::vec2 &  value 
)

Send a vec2 uniform to the shader.

Parameters
nameUniform name in shader
valueUniform value to send

◆ setVec2Array()

void oe::render::ShaderBase::setVec2Array ( const std::string &  name,
const std::vector< glm::vec2 > &  values 
)

Send an array of vec2 uniforms to the shader.

Parameters
nameUniform name in shader
valuesUniform values to send

◆ setVec2i()

void oe::render::ShaderBase::setVec2i ( const std::string &  name,
const glm::ivec2 &  value 
)

Send an ivec2 uniform to the shader.

Parameters
nameUniform name in shader
valueUniform value to send

◆ setVec2iArray()

void oe::render::ShaderBase::setVec2iArray ( const std::string &  name,
const std::vector< glm::ivec2 > &  values 
)

Send an array of ivec2 uniforms to the shader.

Parameters
nameUniform name in shader
valuesUniform values to send

◆ setVec3()

void oe::render::ShaderBase::setVec3 ( const std::string &  name,
const glm::vec3 &  value 
)

Send a vec3 uniform to the shader.

Parameters
nameUniform name in shader
valueUniform value to send

◆ setVec3Array()

void oe::render::ShaderBase::setVec3Array ( const std::string &  name,
const std::vector< glm::vec3 > &  values 
)

Send an array of vec3 uniforms to the shader.

Parameters
nameUniform name in shader
valuesUniform values to send

◆ setVec4()

void oe::render::ShaderBase::setVec4 ( const std::string &  name,
const glm::vec4 &  value 
)

Send a vec4 uniform to the shader.

Parameters
nameUniform name in shader
valueUniform value to send

◆ setVec4Array()

void oe::render::ShaderBase::setVec4Array ( const std::string &  name,
const std::vector< glm::vec4 > &  values 
)

Send an array of vec4 uniforms to the shader.

Parameters
nameUniform name in shader
valuesUniform values to send

The documentation for this class was generated from the following file: