cgv
|
a shader code object holds a code fragment of a geometry vertex or fragment shader and can be added to a shader program. More...
#include <shader_code.h>
Public Member Functions | |
shader_code () | |
create shader a shader code object | |
~shader_code () | |
calls the destruct method | |
void | destruct (const context &ctx) |
destruct shader code | |
bool | read_code (const context &ctx, const std::string &file_name, ShaderType st=ST_DETECT, const shader_compile_options &options={}) |
read shader code from file that is searched for with find_file. | |
bool | set_code (const context &ctx, const std::string &source, ShaderType st) |
set shader code from string | |
ShaderType | get_shader_type () const |
return the shader type of this code | |
bool | compile (const context &ctx) |
compile attached source; returns true if successful | |
bool | read_and_compile (const context &ctx, const std::string &file_name, ShaderType st=ST_DETECT, const shader_compile_options &options={}, bool show_error=true) |
read shader code with read_code and compile. | |
bool | is_compiled () const |
return whether shader has been compiled successfully | |
![]() | |
render_component () | |
initialize members | |
virtual bool | is_created () const |
return whether component has been created | |
void | put_id_void (void *ptr) const |
copy the rendering api specific id the component to the memory location of the given pointer. | |
template<typename T > | |
void | put_id (T &id) const |
cast the refence to rendering api specific representation of component id to the specified type | |
Static Public Member Functions | |
template<typename T , typename std::enable_if<!std::is_enum< T >::value, bool >::type = true> | |
static void | set_define (shader_define_map &defines, const std::string &name, const T &value, const T &default_value) |
template<typename T , typename std::enable_if< std::is_enum< T >::value, bool >::type = true> | |
static void | set_define (shader_define_map &defines, const std::string &name, const T &value, const T &default_value) |
static void | set_define (shader_define_map &defines, const std::string &name, const std::string &value, const std::string &default_value) |
static void | set_define (shader_define_map &defines, const std::string &name, bool value, bool default_value) |
static void | decode_if_base64 (std::string &content) |
decode a string if it is base64 encoded | |
static std::string | find_file (const std::string &file_name, bool search_exhaustive=false) |
Find the full path to a shader by its file name. | |
static std::string | get_last_error (const std::string &file_name, const std::string &last_error) |
format given last error in a way that developer environments can locate errors in the source file | |
static std::string | read_code_file (const std::string &file_name, std::string *_last_error=0) |
read shader code from file and return string with content or empty string if read failed | |
static std::string | retrieve_code (const std::string &file_name, bool use_cache, std::string *_last_error) |
retreive shader code either by reading the file from disk or from the cache if enabled | |
static ShaderType | detect_shader_type (const std::string &file_name) |
detect the shader type from the extension of the given file_name, i.e. | |
Protected Attributes | |
ShaderType | st |
store the shader type | |
Static Protected Attributes | |
static std::map< std::string, std::string > | shader_file_name_map |
map that caches full shader file paths indexed by the shader file name | |
static bool | shader_file_name_map_initialized = false |
whether the shader file name map is initialized | |
static std::map< std::string, std::string > | code_cache |
map that caches shader file contents indexed by their file name | |
Additional Inherited Members | |
![]() | |
void * | handle |
void * | internal_format |
void * | user_data |
const context * | ctx_ptr |
keep pointer to my context | |
std::string | last_error |
a string that contains the last error | |
a shader code object holds a code fragment of a geometry vertex or fragment shader and can be added to a shader program.
Definition at line 103 of file shader_code.h.
cgv::render::shader_code::shader_code | ( | ) |
cgv::render::shader_code::~shader_code | ( | ) |
calls the destruct method
Definition at line 162 of file shader_code.cxx.
References cgv::render::render_component::ctx_ptr, and destruct().
compile attached source; returns true if successful
Definition at line 881 of file shader_code.cxx.
Referenced by cgv::render::shader_program::attach_code(), and read_and_compile().
|
static |
decode a string if it is base64 encoded
Definition at line 69 of file shader_code.cxx.
References cgv::utils::decode_base64().
Referenced by cgv::render::shader_program::collect_program(), cgv::render::shader_program::open_program_file(), and read_code_file().
destruct shader code
destruct shader
Definition at line 172 of file shader_code.cxx.
Referenced by set_code(), and ~shader_code().
|
static |
detect the shader type from the extension of the given file_name, i.e.
Definition at line 279 of file shader_code.cxx.
References st, and cgv::utils::to_lower().
Referenced by read_code().
|
static |
Find the full path to a shader by its file name.
Check if the file exists. If not, check if a resource file of this file_name has been registered. If not, search it in the shader_file_name_map that caches paths for file names based on a recursive search through the paths given in the shader_path of the shader_config. This avoids excessive queries to the file system. The shader_path is accessed by the get_shader_config() method. This path is initialized to the environment variable CGV_SHADER_PATH or empty if that is not defined. If search_exhaustive is true and the file has not been found yet, search recursively in the shader_path.
file_name | The shader file_name to search. |
search_exhaustive | If true, a full recursive search through the given shader_path will be performed if all other attempts have failed. |
Definition at line 180 of file shader_code.cxx.
References cgv::data::ref_ptr< T, is_ref_counted >::empty(), cgv::base::action::end(), cgv::render::get_shader_config(), cgv::base::ref_prog_name(), cgv::base::ref_resource_file_map(), shader_file_name_map, and shader_file_name_map_initialized.
Referenced by cgv::render::shader_program::build_program(), cgv::render::shader_program::collect_file(), cgv::render::shader_program::collect_files(), cgv::render::shader_program::collect_program(), get_last_error(), cgv::render::shader_program::open_program_file(), and read_code_file().
|
static |
format given last error in a way that developer environments can locate errors in the source file
query the last error in a way that developer environments can locate errors in the source file
Definition at line 93 of file shader_code.cxx.
References find_file(), cgv::render::get_shader_config(), cgv::utils::is_integer(), cgv::render::render_component::last_error, cgv::utils::tokenizer::set_sep(), cgv::utils::tokenizer::set_ws(), cgv::utils::split_to_lines(), cgv::utils::to_string(), and cgv::utils::to_upper().
Referenced by read_and_compile().
ShaderType cgv::render::shader_code::get_shader_type | ( | ) | const |
return the shader type of this code
Definition at line 443 of file shader_code.cxx.
References st.
Referenced by cgv::render::shader_program::attach_code(), and cgv::render::shader_program::detach_code().
bool cgv::render::shader_code::is_compiled | ( | ) | const |
return whether shader has been compiled successfully
Definition at line 908 of file shader_code.cxx.
Referenced by cgv::render::shader_program::attach_code().
bool cgv::render::shader_code::read_and_compile | ( | const context & | ctx, |
const std::string & | file_name, | ||
ShaderType | st = ST_DETECT , |
||
const shader_compile_options & | options = {} , |
||
bool | show_error = true |
||
) |
read shader code with read_code and compile.
read shader code from file, compile and print error message if necessary
If show_error is true print error messages formated with the get_last_error method in case an error arose.
Definition at line 893 of file shader_code.cxx.
References compile(), get_last_error(), cgv::render::render_component::last_error, read_code(), and st.
Referenced by cgv::render::shader_program::attach_file().
bool cgv::render::shader_code::read_code | ( | const context & | ctx, |
const std::string & | file_name, | ||
ShaderType | st = ST_DETECT , |
||
const shader_compile_options & | options = {} |
||
) |
read shader code from file that is searched for with find_file.
read shader code from file
If the shader type defaults to ST_DETECT, the detect_shader_type() method is applied to the file name.
Definition at line 492 of file shader_code.cxx.
References detect_shader_type(), cgv::render::context::get_gpu_vendor_id(), cgv::render::context::is_shader_file_cache_enabled(), cgv::render::render_component::last_error, retrieve_code(), set_code(), and st.
Referenced by read_and_compile().
|
static |
read shader code from file and return string with content or empty string if read failed
Definition at line 449 of file shader_code.cxx.
References decode_if_base64(), cgv::data::ref_ptr< T, is_ref_counted >::empty(), find_file(), cgv::render::get_shader_config(), cgv::render::render_component::last_error, and cgv::base::read_data_file().
Referenced by retrieve_code().
|
static |
retreive shader code either by reading the file from disk or from the cache if enabled
Definition at line 257 of file shader_code.cxx.
References code_cache, cgv::base::action::end(), and read_code_file().
Referenced by read_code().
bool cgv::render::shader_code::set_code | ( | const context & | ctx, |
const std::string & | source, | ||
ShaderType | st | ||
) |
set shader code from string
Definition at line 516 of file shader_code.cxx.
References cgv::render::render_component::ctx_ptr, destruct(), and st.
Referenced by cgv::render::shader_program::attach_code(), and read_code().
|
inlinestatic |
Definition at line 129 of file shader_code.h.
|
inlinestatic |
Definition at line 122 of file shader_code.h.
|
inlinestatic |
Definition at line 107 of file shader_code.h.
|
inlinestatic |
Definition at line 115 of file shader_code.h.
|
staticprotected |
map that caches shader file contents indexed by their file name
Definition at line 142 of file shader_code.h.
Referenced by retrieve_code().
|
staticprotected |
map that caches full shader file paths indexed by the shader file name
Definition at line 138 of file shader_code.h.
Referenced by find_file().
|
staticprotected |
whether the shader file name map is initialized
Definition at line 140 of file shader_code.h.
Referenced by find_file().
|
protected |
store the shader type
Definition at line 145 of file shader_code.h.
Referenced by detect_shader_type(), get_shader_type(), read_and_compile(), read_code(), set_code(), and shader_code().