41#ifndef EASY3D_RENDERER_SHADER_PROGRAM_H
42#define EASY3D_RENDERER_SHADER_PROGRAM_H
44#include <unordered_map>
88 typedef std::pair<ShaderProgram::AttribType, std::string> Attribute;
101 static bool is_supported();
111 void set_name(
const std::string& name) { name_ = name; }
112 const std::string& name()
const {
return name_; }
133 bool load_shader_from_file(ShaderType st,
const std::string& file_name,
const std::string& inc_id =
"#include");
150 void set_attrib_name(ShaderProgram::AttribType at,
const std::string& name)
const;
151 void set_attrib_names(
const std::vector<ShaderProgram::Attribute>& attributes)
const;
185 ShaderProgram* set_uniform(
const std::string& name,
const void *value);
188 ShaderProgram* set_uniform(
const std::string& name,
int value);
191 ShaderProgram* set_uniform(
const std::string& name,
unsigned int value);
194 ShaderProgram* set_uniform(
const std::string& name,
float value);
221 ShaderProgram* bind_texture(
const std::string& name,
unsigned int tex_id,
int unit,
unsigned int tex_target = 0x0DE1);
222 ShaderProgram* release_texture(
unsigned int tex_target = 0x0DE1);
229 int get_attribute_location(
const std::string& name)
const;
234 bool is_uniform_used(
const std::string& name);
235 bool is_attribute_used(
const std::string& name);
241 bool is_program_valid()
const;
259 void print_active_attributes();
260 void print_active_uniforms();
261 void print_active_uniform_blocks();
266 bool load_binary(
const std::string& file_name);
267 bool save_binary(
const std::string& file_name);
275 static std::string
load_shader_source(
const std::string& file_name,
const std::string& inc_id =
"#include");
291 struct BlockUniform {
296 unsigned int arrayStride;
302 struct UniformBlock {
309 unsigned int bindingIndex;
313 std::unordered_map<std::string, BlockUniform> uniformOffsets;
319 static int spBlockCount;
324 static std::unordered_map<std::string, UniformBlock> spBlocks;
327 static unsigned int spGLShaderTypes[ShaderProgram::NUM_SHADER_TYPES];
330 static std::string spStringShaderTypes[ShaderProgram::NUM_SHADER_TYPES];
333 unsigned int program_;
338 std::unordered_map<std::string, Uniform> pUniforms;
343 void _add_uniforms();
346 void _add_uniform(
const std::string& name,
unsigned int type,
unsigned int size);
352 int _type_size(
unsigned int type)
const;
354 std::string _type_string(
unsigned int type)
const;
357 std::string _read_linked_program(
const std::string& file);
368 friend class ShaderManager;
OpenGL Shader Compilation.
Definition: shader_program.h:78
bool program_info_log(std::string &log) const
returns a string with the program's infolog
Definition: shader_program.cpp:294
bool load_shader_from_file(ShaderType st, const std::string &file_name, const std::string &inc_id="#include")
Definition: shader_program.cpp:199
bool load_shader_from_code(ShaderType st, const std::string &code)
Definition: shader_program.cpp:209
void bind() const
Starts using the program.
Definition: shader_program.cpp:678
unsigned int get_program() const
Returns the program index.
Definition: shader_program.cpp:337
void set_program_output(int index, const std::string &name) const
Definition: shader_program.cpp:311
void set_attrib_name(ShaderProgram::AttribType at, const std::string &name) const
Definition: shader_program.cpp:321
bool is_program_linked() const
Returns true if program linked, false otherwise.
Definition: shader_program.cpp:669
void release() const
Ends using the program.
Definition: shader_program.cpp:689
bool shader_info_log(std::string &log, unsigned int shader) const
returns a string with a shader's infolog
Definition: shader_program.cpp:276
bool link_program()
Definition: shader_program.cpp:247
ShaderProgram(const std::string &name="unknown")
Definition: shader_program.cpp:91
void set_verbose(bool v)
Sets true to log any issues found.
Definition: shader_program.h:115
ShaderProgram * set_block(const std::string &name, const void *value)
Definition: shader_program.cpp:342
static std::string load_shader_source(const std::string &file_name, const std::string &inc_id="#include")
Definition: shader_program.cpp:124
ShaderProgram * set_block_uniform_array_element(const std::string &blockName, const std::string &uniformName, int arrayIndex, const void *value)
Definition: shader_program.cpp:376
int program_output(const std::string &name) const
Definition: shader_program.cpp:316
void clear()
Removes (deletes) all shaders.
Definition: shader_program.cpp:113
bool is_bound() const
Returns true if the program is being used (i.e., between bind() and release()).
Definition: shader_program.cpp:662
ShaderProgram * set_block_uniform(const std::string &blockName, const std::string &uniformName, const void *value)
Definition: shader_program.cpp:355
Definition: collider.cpp:182