Antkeeper
0.0.1
|
Template used to for generating one or more shader variants from a single source. More...
#include <shader-template.hpp>
Public Types | |
using | dictionary_type = std::unordered_map< std::string, std::string > |
Container of definitions used to generate #pragma define <key> <value> directives. More... | |
Public Member Functions | |
shader_template (text_file &&source_code, std::vector< std::shared_ptr< text_file >> &&include_files) | |
Constructs a shader template and sets its source code. More... | |
constexpr | shader_template () noexcept=default |
Constructs an empty shader template. More... | |
std::string | configure (gl::shader_stage stage, const dictionary_type &definitions={}) const |
Configures shader object source code for a given shader stage and template dictionary. More... | |
std::unique_ptr< gl::shader_object > | compile (gl::shader_stage stage, const dictionary_type &definitions={}) const |
Configures and compiles a shader object. More... | |
std::unique_ptr< gl::shader_program > | build (const dictionary_type &definitions={}) const |
Configures and compiles shader objects, then links them into a shader program. More... | |
bool | has_vertex_directive () const noexcept |
Returns true if the template source contains one or more #pragma vertex directive. More... | |
bool | has_fragment_directive () const noexcept |
Returns true if the template source contains one or more #pragma fragment directive. More... | |
bool | has_geometry_directive () const noexcept |
Returns true if the template source contains one or more #pragma geometry directive. More... | |
bool | has_define_directive (const std::string &key) const |
Returns true if the template source contains one or more instance of #pragma define <key> . More... | |
constexpr std::size_t | hash () const noexcept |
Returns a hash of the template source code. More... | |
shader_template (const text_file &source_code) | |
Constructs a shader template and sets its source code. More... | |
shader_template (text_file &&source_code) | |
Constructs a shader template and sets its source code. More... | |
void | source (const text_file &source_code) |
Replaces the source code of the shader template. More... | |
void | source (text_file &&source_code) |
Replaces the source code of the shader template. More... | |
Template used to for generating one or more shader variants from a single source.
Shader templates support the following preprocessor directives:
#pragma vertex
: Replaced with #define __VERTEX__
when generating vertex shader objects.#pragma fragment
: Replaced with #define __FRAGMENT__
when generating fragment shader objects.#pragma geometry
: Replaced with #define __GEOMETRY__
when generating geometry shader objects.#pragma define <key>
: Will be replaced with #define <key> <value>
if its definition is passed to the shader template.Definition at line 49 of file shader-template.hpp.
using gl::shader_template::dictionary_type = std::unordered_map<std::string, std::string> |
Container of definitions used to generate #pragma define <key> <value>
directives.
Definition at line 53 of file shader-template.hpp.
|
explicit |
Constructs a shader template and sets its source code.
source_code | Shader template source code. |
Definition at line 33 of file shader-template.cpp.
|
explicit |
Constructs a shader template and sets its source code.
source_code | Shader template source code. |
Definition at line 40 of file shader-template.cpp.
gl::shader_template::shader_template | ( | text_file && | source_code, |
std::vector< std::shared_ptr< text_file >> && | include_files | ||
) |
Constructs a shader template and sets its source code.
source_code | Shader template source code. |
include_files | Shader template include files. |
Definition at line 47 of file shader-template.cpp.
|
constexprdefaultnoexcept |
Constructs an empty shader template.
std::unique_ptr< gl::shader_program > gl::shader_template::build | ( | const dictionary_type & | definitions = {} | ) | const |
Configures and compiles shader objects, then links them into a shader program.
Shader object stages are determined according to the presence of #pragma <stage>
directives.
definitions | Container of definitions used to replace #pragma define <key> <value> directives. |
std::runtime_error | Any exceptions thrown by gl::shader_object or gl::shader_program. |
Definition at line 104 of file shader-template.cpp.
std::unique_ptr< gl::shader_object > gl::shader_template::compile | ( | gl::shader_stage | stage, |
const dictionary_type & | definitions = {} |
||
) | const |
Configures and compiles a shader object.
stage | Shader stage of the shader object to generate. Instances of #pragma <stage> in the template source will be replaced with #define __<STAGE>__ . |
definitions | Container of definitions used to replace #pragma define <key> <value> directives. |
std::runtime_error | Any exceptions thrown by gl::shader_object. |
Definition at line 87 of file shader-template.cpp.
std::string gl::shader_template::configure | ( | gl::shader_stage | stage, |
const dictionary_type & | definitions = {} |
||
) | const |
Configures shader object source code for a given shader stage and template dictionary.
stage | Shader stage of the shader object to generate. Instances of #pragma <stage> in the template source will be replaced with #define __<STAGE>__ . |
definitions | Container of definitions used to replace #pragma define <key> <value> directives. |
Definition at line 71 of file shader-template.cpp.
bool gl::shader_template::has_define_directive | ( | const std::string & | key | ) | const |
Returns true
if the template source contains one or more instance of #pragma define <key>
.
key | Definition key. |
Definition at line 245 of file shader-template.cpp.
|
inlinenoexcept |
Returns true
if the template source contains one or more #pragma fragment
directive.
Definition at line 134 of file shader-template.hpp.
|
inlinenoexcept |
Returns true
if the template source contains one or more #pragma geometry
directive.
Definition at line 140 of file shader-template.hpp.
|
inlinenoexcept |
Returns true
if the template source contains one or more #pragma vertex
directive.
Definition at line 128 of file shader-template.hpp.
|
inlineconstexprnoexcept |
Returns a hash of the template source code.
Definition at line 153 of file shader-template.hpp.
void gl::shader_template::source | ( | const text_file & | source_code | ) |
Replaces the source code of the shader template.
source_code | Shader template source code. |
Definition at line 55 of file shader-template.cpp.
void gl::shader_template::source | ( | text_file && | source_code | ) |
Replaces the source code of the shader template.
source_code | Shader template source code. |
Definition at line 63 of file shader-template.cpp.