4#include "element_traits.h"
5#include "shader_code.h"
6#include "textured_material.h"
11 struct surface_material;
33 static std::map<std::string, std::vector<std::string>> files_cache;
35 bool show_code_errors : 1;
37 bool state_out_of_date : 1;
38 int nr_attached_geometry_shaders : 13;
40 std::vector<shader_code*> managed_codes;
45 void update_state(
const context& ctx);
47 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);
51 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);
102 bool attach_files(
const context& ctx,
const std::string& base_name,
const shader_compile_options& options = {});
104 bool attach_dir(
const context& ctx,
const std::string& dir_name,
bool recursive,
const shader_compile_options& options = {});
106 bool attach_program(
const context& ctx, std::string file_name,
bool show_error =
false,
const shader_compile_options& options = {});
108 static std::vector<shader_compile_options> extract_instances(std::string file_name);
110 bool link(
const context& ctx,
bool show_error =
false);
112 bool is_linked()
const;
122 bool get_location =
true,
bool get_value =
true);
124 bool build_files(
const context& ctx,
const std::string& base_name,
bool show_error =
false);
126 bool build_dir(
const context& ctx,
const std::string& dir_name,
bool recursive =
false,
bool show_error =
false);
128 bool build_program(
const context& ctx,
const std::string& file_name,
bool show_error =
false);
130 bool build_files(
const context& ctx,
const std::string& base_name,
const shader_compile_options& options,
bool show_error =
false);
132 bool build_dir(
const context& ctx,
const std::string& dir_name,
const shader_compile_options& options,
bool recursive =
false,
bool show_error =
false);
134 bool build_program(
const context& ctx,
const std::string& file_name,
const shader_compile_options& options,
bool show_error =
false);
136 void set_geometry_shader_info(PrimitiveType input_type, PrimitiveType output_type,
int max_output_count = 0);
138 bool enable(context& ctx);
140 bool disable(context& ctx);
142 bool is_enabled()
const {
return shader_program_base::is_enabled; }
144 const std::map<std::string, int>& get_uniform_locations()
const;
146 int get_uniform_location(
const context& ctx,
const std::string& name)
const;
150 bool set_textured_material_uniform(
const context& ctx,
const std::string& name,
const textured_material& material,
bool generate_error =
false);
156 template <
typename T>
157 bool set_uniform(
const context& ctx,
const std::string& name,
const T& value,
bool generate_error =
false) {
158 int loc = get_uniform_location(ctx, name);
161 ctx.
error(std::string(
"shader_program::set_uniform() uniform <") + name +
"> not found",
this);
167 template <
typename T>
169 int loc = get_uniform_location(ctx, name);
171 ctx.
error(std::string(
"shader_program::set_uniform_array() uniform <") + name +
"> not found",
this);
177 template <
typename T>
178 bool set_uniform_array(
const context& ctx,
const std::string& name,
const T* array,
size_t nr_elements,
bool generate_error =
false) {
179 int loc = get_uniform_location(ctx, name);
182 ctx.
error(std::string(
"shader_program::set_uniform_array() uniform <") + name +
"> not found",
this);
190 template <
typename T>
195 template <
typename T>
200 template <
typename T>
208 return ctx.set_uniform_void(*
this, loc, value_type, value_ptr);
211 int get_attribute_location(
const context& ctx,
const std::string& name)
const;
213 template <
typename T>
215 int loc = ctx.get_attribute_location(*
this, name);
217 ctx.
error(std::string(
"shader_program::set_attribute() attribute <") + name +
"> not found",
this);
223 template <
typename T>
226 ctx.
error(
"shader_program::set_attribute() called with loc=-1",
this);
236#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...
Stores preprocessor options used for conditionally compiling shader programs.
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 location, where the type can be any of int, unsigned,...
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(const context &ctx, int loc, type_descriptor value_type, const void *value_ptr)
Set the value of a uniform by location, where the value is defined by a type descriptor and address.
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
ProgramVariableKind
enumerates different kinds of shader program variables
ShaderType
different shader types
this header is dependency free
compact type description of data that can be sent to the context; convertible to int