4#include "element_traits.h"
5#include "shader_code.h"
6#include "textured_material.h"
11 class surface_material;
32 static std::map<std::string, std::vector<std::string>> files_cache;
34 bool show_code_errors : 1;
36 bool state_out_of_date : 1;
37 int nr_attached_geometry_shaders : 13;
39 std::vector<shader_code*> managed_codes;
43 void update_state(
const context& ctx);
45 static bool open_program_file(std::string& file_name,
bool use_cache, std::string& content, std::vector<cgv::utils::line>& lines, std::string* last_error_ptr = 0);
50 static bool collect_files_from_cache(
const std::string& name, std::vector<std::string>& file_names,
bool& added_files);
54 static bool collect_file(
const std::string& file_name,
bool use_cache, std::vector<std::string>& file_names);
57 static bool collect_files(
const std::string& base_name,
bool use_cache, std::vector<std::string>& file_names);
62 static bool collect_dir(
const std::string& dir_name,
bool recursive, std::vector<std::string>& file_names);
81 static bool collect_program(
const std::string& file_name,
bool use_cache, std::vector<std::string>& file_names);
83 static unsigned int get_max_nr_geometry_shader_output_vertices(
const context& ctx);
90 bool create(
const context& ctx);
92 void destruct(
const context& ctx);
104 bool attach_dir(
const context& ctx,
const std::string& dir_name,
bool recursive);
108 static std::vector<shader_define_map> extract_instances(std::string file_name);
110 bool link(
const context& ctx,
bool show_error =
false);
112 bool is_linked()
const;
116 bool build_dir(
const context& ctx,
const std::string& dir_name,
bool recursive =
false,
bool show_error =
false);
126 bool is_enabled()
const {
return shader_program_base::is_enabled; }
128 int get_uniform_location(
const context& ctx,
const std::string& name)
const;
132 bool set_textured_material_uniform(
const context& ctx,
const std::string& name,
const textured_material& material,
bool generate_error =
false);
138 template <
typename T>
139 bool set_uniform(
const context& ctx,
const std::string& name,
const T& value,
bool generate_error =
false) {
140 int loc = ctx.get_uniform_location(*
this, name);
141 if (loc == -1 && generate_error) {
142 ctx.
error(std::string(
"shader_program::set_uniform() uniform <") + name +
"> not found",
this);
148 template <
typename T>
150 int loc = ctx.get_uniform_location(*
this, name);
152 ctx.
error(std::string(
"shader_program::set_uniform_array() uniform <") + name +
"> not found",
this);
158 template <
typename T>
159 bool set_uniform_array(
const context& ctx,
const std::string& name,
const T* array,
size_t nr_elements,
bool generate_error =
false) {
160 int loc = ctx.get_uniform_location(*
this, name);
161 if (loc == -1 && generate_error) {
162 ctx.
error(std::string(
"shader_program::set_uniform_array() uniform <") + name +
"> not found",
this);
170 template <
typename T>
175 template <
typename T>
180 template <
typename T>
185 int get_attribute_location(
const context& ctx,
const std::string& name)
const;
187 template <
typename T>
189 int loc = ctx.get_attribute_location(*
this, name);
191 ctx.
error(std::string(
"shader_program::set_attribute() attribute <") + name +
"> not found",
this);
197 template <
typename T>
200 ctx.
error(
"shader_program::set_attribute() called with loc=-1",
this);
210#include <cgv/config/lib_end.h>
base class for all drawables, which is independent of the used rendering API.
virtual void error(const std::string &message, const render_component *rc=0) const
error handling
a shader code object holds a code fragment of a geometry vertex or fragment shader and can be added t...
base interface for shader programs
a shader program combines several shader code fragments to a complete definition of the shading pipel...
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
static std::map< std::string, std::string > program_file_cache
maps used to cache program file contents and valid file names indexed by their respective file name
bool set_uniform(const context &ctx, const std::string &name, const T &value, bool generate_error=false)
Set the value of a uniform by name, where the type can be any of int, unsigned, float,...
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...
bool set_uniform(const context &ctx, int loc, const T &value)
Set the value of a uniform by name, where the type can be any of int, unsigned, float,...
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...
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...
bool is_enabled() const
check whether program is currently enabled
bool set_attribute(const context &ctx, int loc, const T &value)
set constant default value of a vertex attribute by location index
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
class that extends obj_material with the management of textures
std::map< std::string, std::string > shader_define_map
typedef for shader define map data structure
ShaderType
different shader types
PrimitiveType
different primitive types
compact type description of data that can be sent to the context; convertible to int