4 #include "element_traits.h"
5 #include "shader_code.h"
6 #include "textured_material.h"
11 class surface_material;
17 #include "lib_begin.h"
27 bool show_code_errors : 1;
29 bool state_out_of_date : 1;
30 int nr_attached_geometry_shaders : 13;
32 std::vector<shader_code*> managed_codes;
34 bool attach_files(
const context& ctx,
const std::vector<std::string>& file_names, std::string defines =
"");
36 void update_state(
const context& ctx);
39 static bool collect_file(
const std::string& file_name, std::vector<std::string>& file_names);
42 static bool collect_files(
const std::string& base_name, std::vector<std::string>& file_names);
47 static bool collect_dir(
const std::string& dir_name,
bool recursive, std::vector<std::string>& file_names);
66 static bool collect_program(
const std::string& file_name, std::vector<std::string>& file_names);
68 static unsigned int get_max_nr_geometry_shader_output_vertices(
const context& ctx);
75 bool create(
const context& ctx);
77 void destruct(
const context& ctx);
85 bool attach_file(
const context& ctx,
const std::string& file_name,
ShaderType st = ST_DETECT, std::string defines =
"");
87 bool attach_files(
const context& ctx,
const std::string& base_name, std::string defines =
"");
89 bool attach_dir(
const context& ctx,
const std::string& dir_name,
bool recursive);
91 bool attach_program(
const context& ctx,
const std::string& file_name,
bool show_error =
false, std::string defines =
"");
93 bool link(
const context& ctx,
bool show_error =
false);
95 bool is_linked()
const;
97 bool build_files(
const context& ctx,
const std::string& base_name,
bool show_error =
false);
99 bool build_dir(
const context& ctx,
const std::string& dir_name,
bool recursive =
false,
bool show_error =
false);
101 bool build_program(
const context& ctx,
const std::string& file_name,
bool show_error =
false, std::string defines =
"");
109 bool is_enabled()
const {
return shader_program_base::is_enabled; }
111 int get_uniform_location(
const context& ctx,
const std::string& name)
const;
115 bool set_textured_material_uniform(
const context& ctx,
const std::string& name,
const textured_material& material,
bool generate_error =
false);
121 template <
typename T>
122 bool set_uniform(
const context& ctx,
const std::string& name,
const T& value,
bool generate_error =
false) {
123 int loc = ctx.get_uniform_location(*
this, name);
124 if (loc == -1 && generate_error) {
125 ctx.
error(std::string(
"shader_program::set_uniform() uniform <") + name +
"> not found",
this);
128 return ctx.set_uniform_void(*
this, loc, element_descriptor_traits<T>::get_type_descriptor(value), element_descriptor_traits<T>::get_address(value));
131 template <
typename T>
133 int loc = ctx.get_uniform_location(*
this, name);
135 ctx.
error(std::string(
"shader_program::set_uniform_array() uniform <") + name +
"> not found",
this);
138 return ctx.set_uniform_array_void(*
this, loc, array_descriptor_traits<T>::get_type_descriptor(array), array_descriptor_traits<T>::get_address(array), array_descriptor_traits<T>::get_nr_elements(array));
141 template <
typename T>
142 bool set_uniform_array(
const context& ctx,
const std::string& name,
const T* array,
size_t nr_elements,
bool generate_error =
false) {
143 int loc = ctx.get_uniform_location(*
this, name);
144 if (loc == -1 && generate_error) {
145 ctx.
error(std::string(
"shader_program::set_uniform_array() uniform <") + name +
"> not found",
this);
148 return ctx.set_uniform_array_void(*
this, loc,
type_descriptor(element_descriptor_traits<T>::get_type_descriptor(array[0]),
true), array, nr_elements);
153 template <
typename T>
155 return ctx.set_uniform_void(*
this, loc, element_descriptor_traits<T>::get_type_descriptor(value), element_descriptor_traits<T>::get_address(value));
158 template <
typename T>
160 return ctx.set_uniform_array_void(*
this, loc, array_descriptor_traits<T>::get_type_descriptor(), array_descriptor_traits<T>::get_address(array), array_descriptor_traits<T>::get_nr_elements(array));
163 template <
typename T>
165 return ctx.set_uniform_array_void(*
this, loc,
type_descriptor(element_descriptor_traits<T>::get_type_descriptor(array),
true), array, nr_elements);
168 int get_attribute_location(
const context& ctx,
const std::string& name)
const;
170 template <
typename T>
172 int loc = ctx.get_attribute_location(*
this, name);
174 ctx.
error(std::string(
"shader_program::set_attribute() attribute <") + name +
"> not found",
this);
177 return ctx.set_attribute_void(*
this, loc, element_descriptor_traits<T>::get_type_descriptor(value), element_descriptor_traits<T>::get_address(value));
180 template <
typename T>
183 ctx.
error(
"shader_program::set_attribute() called with loc=-1",
this);
186 return ctx.set_attribute_void(*
this, loc, element_descriptor_traits<T>::get_type_descriptor(value), element_descriptor_traits<T>::get_address(value));
193 #include <cgv/config/lib_end.h>
bool set_uniform(const context &ctx, const std::string &name, const T &value, bool generate_error=false)
Definition: shader_program.h:122
compact type description of data that can be sent to the context; convertible to int
Definition: context.h:36
ShaderType
different shader types
Definition: context.h:391
bool set_attribute(const context &ctx, const std::string &name, const T &value)
set constant default value of a vertex attribute by attribute name, if name does not specify an attri...
Definition: shader_program.h:171
bool is_enabled() const
check whether program is currently enabled
Definition: shader_program.h:109
bool set_uniform_array(const context &ctx, const std::string &name, const T &array)
set uniform array from array array where number elements can be derived from array through array_desc...
Definition: shader_program.h:132
class that extends obj_material with the management of textures
Definition: textured_material.h:13
bool set_uniform_array(const context &ctx, const std::string &name, const T *array, size_t nr_elements, bool generate_error=false)
set uniform array from an array with nr_elements elements of type T pointed to by array
Definition: shader_program.h:142
bool set_uniform(const context &ctx, int loc, const T &value)
Definition: shader_program.h:154
Definition: shader_program.h:25
bool set_attribute(const context &ctx, int loc, const T &value)
set constant default value of a vertex attribute by location index
Definition: shader_program.h:181
Definition: shader_code.h:54
base interface for shader programs
Definition: context.h:290
bool set_uniform_array(const context &ctx, int loc, const T &array)
set uniform array from array array where number elements can be derived from array through array_desc...
Definition: shader_program.h:159
bool set_uniform_array(const context &ctx, int loc, const T *array, size_t nr_elements)
set uniform array from an array with nr_elements elements of type T pointed to by array
Definition: shader_program.h:164
the cgv namespace
Definition: vr_calib.cxx:9
Definition: context.h:525
PrimitiveType
different primitive types
Definition: context.h:177
virtual void error(const std::string &message, const render_component *rc=0) const
error handling
Definition: context.cxx:183