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

Standard shader class. More...

#include <OxygenEngine/render/shader.h>

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

Public Member Functions

 Shader (const std::string &name="")
 Create a new shader instance.
 
void compile ()
 Compile / link the shader using the graphic API.
 
void bind ()
 Tell the graphic API to use this shader for the next renderings.
 
void setVertexShader (const std::string &contents)
 Set source code for the vertex stage.
 
void setFragmentShader (const std::string &contents)
 Set source code for the fragment stage.
 
- Public Member Functions inherited from oe::render::ShaderBase
 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.
 

Static Public Member Functions

static const std::shared_ptr< ShadergeneratePostProcessingShader (const std::string &fragment_code, const bool compile=true)
 Generate a shader ready for post-processing effects.
 

Additional Inherited Members

- Protected Attributes inherited from oe::render::ShaderBase
std::unordered_map< GeometryPass, std::string > _vertex_shader_sources
 
std::unordered_map< RenderingPass, std::string > _fragment_shader_sources
 
std::string _header
 

Detailed Description

Standard shader class.

You need to provide both vertex and fragment programs

Note
No graphic API calls done in functions before compilation
See also
SurfaceShader if you want a simpler interface

Constructor & Destructor Documentation

◆ Shader()

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

Create a new shader instance.

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

Member Function Documentation

◆ compile()

void oe::render::Shader::compile ( )

Compile / link the shader using the graphic API.

Exceptions
Exceptionif compilation / linking failed or pass combination not available

◆ generatePostProcessingShader()

static const std::shared_ptr< Shader > oe::render::Shader::generatePostProcessingShader ( const std::string &  fragment_code,
const bool  compile = true 
)
static

Generate a shader ready for post-processing effects.

Parameters
fragment_codecode of the fragment shader
compileToggle if the shader need to be compiled. Set to false if you need adjustements before compilation (example: adding constants)
Returns
A ready to use shader where vertex program is based on ScreenQuad render and fragment program is the sent one

◆ setFragmentShader()

void oe::render::Shader::setFragmentShader ( const std::string &  contents)

Set source code for the fragment stage.

Parameters
contentsFragment shader contents

◆ setVertexShader()

void oe::render::Shader::setVertexShader ( const std::string &  contents)

Set source code for the vertex stage.

Parameters
contentsVertex shader contents

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