4#include "element_traits.h"
5#include "shader_code.h"
6#include "textured_material.h"
11 struct 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;
44 void update_state(
const context& ctx);
46 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);
53 static bool collect_file(
const std::string& file_name,
bool use_cache, std::vector<std::string>& file_names);
56 static bool collect_files(
const std::string& base_name,
bool use_cache, std::vector<std::string>& file_names);
61 static bool collect_dir(
const std::string& dir_name,
bool recursive, std::vector<std::string>& file_names);
80 static bool collect_program(
const std::string& file_name,
bool use_cache, std::vector<std::string>& file_names);
82 static unsigned int get_max_nr_geometry_shader_output_vertices(
const context& ctx);
89 bool create(
const context& ctx);
91 void destruct(
const context& ctx);
101 bool attach_files(
const context& ctx,
const std::string& base_name,
const shader_compile_options& options = {});
103 bool attach_dir(
const context& ctx,
const std::string& dir_name,
bool recursive,
const shader_compile_options& options = {});
105 bool attach_program(
const context& ctx, std::string file_name,
bool show_error =
false,
const shader_compile_options& options = {});
107 static std::vector<shader_compile_options> extract_instances(std::string file_name);
109 bool link(
const context& ctx,
bool show_error =
false);
111 bool is_linked()
const;
113 bool build_files(
const context& ctx,
const std::string& base_name,
bool show_error =
false);
115 bool build_dir(
const context& ctx,
const std::string& dir_name,
bool recursive =
false,
bool show_error =
false);
117 bool build_program(
const context& ctx,
const std::string& file_name,
bool show_error =
false);
119 bool build_files(
const context& ctx,
const std::string& base_name,
const shader_compile_options& options,
bool show_error =
false);
121 bool build_dir(
const context& ctx,
const std::string& dir_name,
const shader_compile_options& options,
bool recursive =
false,
bool show_error =
false);
123 bool build_program(
const context& ctx,
const std::string& file_name,
const shader_compile_options& options,
bool show_error =
false);
125 void set_geometry_shader_info(PrimitiveType input_type, PrimitiveType output_type,
int max_output_count = 0);
127 bool enable(context& ctx);
129 bool disable(context& ctx);
131 bool is_enabled()
const {
return shader_program_base::is_enabled; }
133 const std::map<std::string, int>& get_uniform_locations()
const;
135 int get_uniform_location(
const context& ctx,
const std::string& name)
const;
139 bool set_textured_material_uniform(
const context& ctx,
const std::string& name,
const textured_material& material,
bool generate_error =
false);
145 template <
typename T>
146 bool set_uniform(
const context& ctx,
const std::string& name,
const T& value,
bool generate_error =
false) {
147 int loc = get_uniform_location(ctx, name);
150 ctx.
error(std::string(
"shader_program::set_uniform() uniform <") + name +
"> not found",
this);
156 template <
typename T>
158 int loc = get_uniform_location(ctx, name);
160 ctx.
error(std::string(
"shader_program::set_uniform_array() uniform <") + name +
"> not found",
this);
166 template <
typename T>
167 bool set_uniform_array(
const context& ctx,
const std::string& name,
const T* array,
size_t nr_elements,
bool generate_error =
false) {
168 int loc = get_uniform_location(ctx, name);
171 ctx.
error(std::string(
"shader_program::set_uniform_array() uniform <") + name +
"> not found",
this);
179 template <
typename T>
184 template <
typename T>
189 template <
typename T>
197 return ctx.set_uniform_void(*
this, loc, value_type, value_ptr);
200 int get_attribute_location(
const context& ctx,
const std::string& name)
const;
202 template <
typename T>
204 int loc = ctx.get_attribute_location(*
this, name);
206 ctx.
error(std::string(
"shader_program::set_attribute() attribute <") + name +
"> not found",
this);
212 template <
typename T>
215 ctx.
error(
"shader_program::set_attribute() called with loc=-1",
this);
225#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
ShaderType
different shader types
compact type description of data that can be sent to the context; convertible to int