JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
ShaderProgram Class Reference

Linked vertex and fragment shaders. More...

#include <jngl/ShaderProgram.hpp>

Classes

struct  Context
 Lifetime object when the ShaderProgram is in use. More...
 

Public Member Functions

 ShaderProgram (const Shader &vertex, const Shader &fragment)
 Not supported by the Direct3D 12 and Metal renderers and the Vulkan renderer on Android, which need the program's ShaderBytecode.
 
 ShaderProgram (const ShaderBytecode &)
 Creates the program from what jngl-shaderc has compiled it to.
 
 ShaderProgram (const ShaderProgram &)=delete
 
 ShaderProgram (ShaderProgram &&) noexcept
 
ShaderProgram & operator= (const ShaderProgram &)=delete
 
ShaderProgram & operator= (ShaderProgram &&) noexcept
 
Context use () const
 
int getAttribLocation (const std::string &name) const
 
int getUniformLocation (const std::string &name) const
 Returns the location of a uniform variable for use with Context::setUniform.
 

Detailed Description

Linked vertex and fragment shaders.

Definition at line 18 of file ShaderProgram.hpp.

Constructor & Destructor Documentation

◆ ShaderProgram()

ShaderProgram ( const ShaderBytecode & )
explicit

Creates the program from what jngl-shaderc has compiled it to.

Only supported by the Vulkan, Direct3D 12 and Metal renderers, and the bytecode has to be for the one that's compiled in.

Member Function Documentation

◆ getUniformLocation()

int getUniformLocation ( const std::string & name) const
nodiscard

Returns the location of a uniform variable for use with Context::setUniform.

The returned location is stable for the lifetime of the ShaderProgram and is typically queried once (e.g. in a constructor) and then cached.

Parameters
namename of the uniform variable as declared in the GLSL source. Note that GLSL compilers strip away uniforms that aren't actually read by the shader, so this may fail even if the variable appears in the source.
Returns
a non-negative location identifying the uniform
Exceptions
std::runtime_errorif no active uniform with the given name exists in the linked shader program.

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