cgv
shader_code.h
1 #pragma once
2 
3 #include <cgv/render/context.h>
4 
5 #include "lib_begin.h"
6 
7 namespace cgv {
8  namespace render {
9 
24 struct CGV_API shader_config : public cgv::base::base
25 {
27  std::string shader_path;
33  std::vector<std::string> shader_file_names;
35  std::vector<std::string> inserted_shader_file_names;
37  shader_config();
39  std::string get_type_name() const;
41  bool self_reflect(cgv::reflect::reflection_handler& srh);
42 };
43 
46 
48 extern CGV_API shader_config_ptr get_shader_config();
49 
53 class CGV_API shader_code : public render_component
54 {
55 protected:
58 
59 public:
61  shader_code();
63  ~shader_code();
70  static std::string find_file(const std::string& file_name);
72  static std::string get_last_error(const std::string& file_name, const std::string& last_error);
74  static std::string read_code_file(const std::string &file_name, std::string* _last_error = 0);
82  static ShaderType detect_shader_type(const std::string& file_name);
84  void destruct(const context& ctx);
88  bool read_code(const context& ctx, const std::string &file_name, ShaderType st = ST_DETECT, std::string defines = "");
90  bool set_code(const context& ctx, const std::string &source, ShaderType st);
92  void set_defines(std::string& source, const std::string& defines);
94  ShaderType get_shader_type() const;
96  bool compile(const context& ctx);
100  bool read_and_compile(const context& ctx, const std::string &file_name, ShaderType st = ST_DETECT, bool show_error = true, std::string defines = "");
102  bool is_compiled() const;
103 };
104 
105 
106  }
107 }
108 
109 #include <cgv/config/lib_end.h>
cgv::render::render_component
base interface for all render components
Definition: context.h:246
cgv::render::shader_config::inserted_shader_file_names
std::vector< std::string > inserted_shader_file_names
mapping of shader index to inserted files name
Definition: shader_code.h:35
cgv::render::shader_config::shader_file_names
std::vector< std::string > shader_file_names
mapping of shader index to file name
Definition: shader_code.h:33
cgv::render::shader_config_ptr
cgv::data::ref_ptr< shader_config > shader_config_ptr
type of ref counted pointer to shader configuration
Definition: shader_code.h:45
cgv::render::ShaderType
ShaderType
different shader types
Definition: context.h:391
cgv::render::shader_code::st
ShaderType st
store the shader type
Definition: shader_code.h:57
cgv::render::shader_config::show_file_paths
bool show_file_paths
whether to output full paths of read shaders
Definition: shader_code.h:31
cgv::data::ref_ptr
Definition: ref_ptr.h:19
cgv::reflect::reflection_handler
Definition: reflection_handler.h:63
cgv::render::get_shader_config
shader_config_ptr get_shader_config()
return a reference to the current shader configuration
Definition: shader_code.cxx:43
cgv::render::shader_config::trace_file_names
bool trace_file_names
whether to keep track of file names
Definition: shader_code.h:29
cgv::render::shader_config::shader_path
std::string shader_path
the path used to find shaders with the cgv::utils::file::find_in_paths function
Definition: shader_code.h:27
cgv::base::base
Definition: base.h:57
cgv::render::shader_code
Definition: shader_code.h:54
cgv::type::info::get_type_name
const char * get_type_name(TypeId tid)
function that returns the name of a type specified through TypeId
Definition: type_id.cxx:117
cgv
the cgv namespace
Definition: vr_calib.cxx:9
cgv::render::context
Definition: context.h:525
cgv::render::shader_config
Definition: shader_code.h:25