3#include <cgv/render/context.h>
40 std::string get_type_name()
const;
75 using string_map = std::map<std::string, std::string>;
79 return defines.empty() && snippets.empty();
100 defines[identifier] =
"";
114 template<
typename T,
typename std::enable_if<std::is_arithmetic_v<T>,
bool>::type = true>
116 defines[identifier] = std::to_string(value);
119 template<
typename T,
typename std::enable_if<std::is_enum_v<T>,
bool>::type = true>
120 void define_macro(
const std::string& identifier,
const T& value) {
121 defines[identifier] = std::to_string(
static_cast<std::underlying_type_t<T>
>(value));
124 void define_macro(
const std::string& identifier,
bool value) {
125 defines[identifier] = value ?
"1" :
"0";
128 void define_macro(
const std::string& identifier,
const std::string& value) {
129 defines[identifier] = value;
147 template<
typename T,
typename std::enable_if<std::is_arithmetic_v<T>,
bool>::type = true>
149 if(value != default_value)
150 defines[identifier] = std::to_string(value);
152 defines.erase(identifier);
155 template<
typename T,
typename std::enable_if<std::is_enum_v<T>,
bool>::type = true>
157 if(value != default_value)
158 defines[identifier] = std::to_string(
static_cast<std::underlying_type_t<T>
>(value));
160 defines.erase(identifier);
164 if(value != default_value)
165 defines[identifier] = value ?
"1" :
"0";
167 defines.erase(identifier);
171 if(value != default_value)
172 defines[identifier] = value;
174 defines.erase(identifier);
194 defines.erase(identifier);
200 void define_snippet(
const std::string& identifier,
const std::string& replacement_text) {
201 snippets[identifier] = replacement_text;
207 snippets.erase(identifier);
218 for(
const auto& define : other.defines)
219 defines[define.first] = define.second;
221 for(
const auto& snippet : other.snippets)
222 snippets[snippet.first] = snippet.second;
224 defines.insert(other.defines.begin(), other.defines.end());
225 snippets.insert(other.snippets.begin(), other.snippets.end());
231 return defines == other.defines && snippets == other.snippets;
236 return !(*
this == other);
257 static void decode_if_base64(std::string& content);
272 static std::string find_file(
const std::string& file_name,
bool search_exhaustive =
false);
274 static std::string get_last_error(
const std::string& file_name,
const std::string& last_error);
276 static std::string read_code_file(
const std::string &file_name, std::string* _last_error = 0);
278 static std::string retrieve_code(
const std::string& file_name,
bool use_cache, std::string* _last_error);
286 static ShaderType detect_shader_type(
const std::string& file_name);
288 void destruct(
const context& ctx);
298 bool compile(
const context& ctx);
304 bool is_compiled()
const;
319 static std::string resolve_includes(
const std::string& source,
bool use_cache, std::set<std::string>& included_file_names, std::string* _last_error = 0);
321 static std::string resolve_includes(
const std::string& source,
bool use_cache, std::string* _last_error = 0);
323 static void resolve_version_and_extensions(std::string& source);
327 static void set_vertex_attrib_locations(std::string& source);
334#include <cgv/config/lib_end.h>
base class for all classes that can be registered with support for dynamic properties (see also secti...
reference counted pointer, which can work together with types that are derived from ref_counted,...
the self reflection handler is passed to the virtual self_reflect() method of cgv::base::base.
base class for all drawables, which is independent of the used rendering API.
base interface for all render components
a shader code object holds a code fragment of a geometry vertex or fragment shader and can be added t...
static bool shader_file_name_map_initialized
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
ShaderType st
store the shader type
static std::map< std::string, std::string > shader_file_name_map
map that caches full shader file paths indexed by the shader file name
Stores preprocessor options used for conditionally compiling shader programs.
bool operator==(const shader_compile_options &other) const
Compare two shader_compile_options for equality.
void define_macro_if_true(bool predicate, const std::string &identifier)
Conditionally define identifier as a macro with replacement text 1.
void define_macro(const std::string &identifier)
Define a macro as identifier and no replacement text.
void clear()
Clear everything, i.e. remove all defines and snippets.
void undefine_macro(const std::string &identifier)
Remove (undefine) the macro with the given identifier.
void undefine_snippet(const std::string &identifier)
Remove (undefine) the snippet with the given identifier.
const string_map & get_macros() const
Return const reference to defined macros.
void define_snippet(const std::string &identifier, const std::string &replacement_text)
Define a text replacement snippet.
void define_macro(const std::string &identifier, const T &value)
Define identifier as a macro with value as replacement text.
void define_macro_if_not_default(const std::string &identifier, const T &value, const T &default_value)
Conditionally define identifier as a macro with value as replacement text.
bool empty() const
Return true if no options are set.
void extend(const shader_compile_options &other, bool overwrite)
Extend options by content of other shader_compile_options via merging.
const string_map & get_snippets() const
Return const reference to defined snippets.
bool operator!=(const shader_compile_options &other) const
Compare two shader_compile_options for inequality.
shader_config_ptr get_shader_config()
return a reference to the current shader configuration
cgv::data::ref_ptr< shader_config > shader_config_ptr
type of ref counted pointer to shader configuration
ShaderType
different shader types
a globally unique shader config is registered by default when the cgv library is used.
std::vector< std::string > shader_file_names
mapping of shader index to file name
bool show_file_paths
whether to output full paths of read shaders
bool trace_file_names
whether to keep track of file names
std::string shader_path
the path used to find shaders with the cgv::utils::file::find_in_paths function
std::vector< std::string > inserted_shader_file_names
mapping of shader index to inserted files name