40#ifndef GEOGRAM_GFX_BASIC_GLSL
41#define GEOGRAM_GFX_BASIC_GLSL
62 auto last = std::find_if(
64 [](
const char* p) { return p != nullptr; }
66 v.erase(last.base(), v.end());
95 const char*
what() const GEO_NOEXCEPT override;
135 Source(
const std::string& src) : text_string_(src) {
136 text_ = text_string_.c_str();
173 if(rhs.text_string_ !=
"") {
174 text_string_ = rhs.text_string_;
175 text_ = text_string_.c_str();
183 std::string text_string_;
222 const std::string& name,
const char* source
248 const std::string& name
286 const std::vector<const char*>& shaders
301 template <
typename... Args>
inline
305 std::vector<const char*> shaders_vec { shaders... };
332 GLenum target,
const char** sources,
index_t nb_sources
355 GLenum target,
const std::vector<const char*>& sources
380 template <
typename... Args>
inline
382 std::vector<const char*> args_vec { args... };
443 const char*
string,
bool copy_string =
true
455 const std::string& filename
468 GLuint shader_id,
const char* name, T val
477 template<>
inline bool set_program_uniform_by_name(
478 GLuint shader_id,
const char* name,
bool val
480 GLint location = glGetUniformLocation(shader_id, name) ;
484 glUseProgram(shader_id);
485 glUniform1i(location, val ? 1 : 0) ;
491 GLuint shader_id,
const char* name,
float val
493 GLint location = glGetUniformLocation(shader_id, name) ;
497 glUseProgram(shader_id);
498 glUniform1f(location, val) ;
504 GLuint shader_id,
const char* name,
double val
506 GLint location = glGetUniformLocation(shader_id, name) ;
510 glUseProgram(shader_id);
511 glUniform1f(location,
float(val)) ;
517 GLuint shader_id,
const char* name,
int val
519 GLint location = glGetUniformLocation(shader_id, name) ;
523 glUseProgram(shader_id);
524 glUniform1i(location, val) ;
531 GLuint shader_id,
const char* name,
unsigned int val
533 GLint location = glGetUniformLocation(shader_id, name) ;
537 glUseProgram(shader_id);
539 glUniform1ui(location, val) ;
541 glUniform1i(location, GLint(val)) ;
556 GLuint shader_id,
const char* name,
index_t count,
float* values
558 GLint location = glGetUniformLocation(shader_id, name) ;
562 glUseProgram(shader_id);
563 glUniform1fv(location, GLsizei(count), values) ;
568 inline bool set_program_uniform_by_name(
569 GLuint shader_id,
const char* name,
float x,
float y
571 GLint location = glGetUniformLocation(shader_id, name) ;
575 glUseProgram(shader_id);
576 glUniform2f(location, x, y);
590 GLuint program,
const char* varname
602 GLuint program,
const char* varname
GLuint GEOGRAM_GFX_API compile_program_with_includes_no_link(PseudoFileProvider *provider, const std::vector< const char * > &shaders)
Compiles a program from shader sources.
GLuint GEOGRAM_GFX_API create_program_from_shaders(GLuint shader,...)
Creates a GLSL program from a zero-terminated list of shaders.
GLuint GEOGRAM_GFX_API create_program_from_file_no_link(const std::string &filename)
Creates a GLSL program from a file.
double GEOGRAM_GFX_API supported_language_version()
Gets the supported GLSL language version.
void(* PseudoFile)(PseudoFileProvider *provider, std::vector< Source > &sources)
A pointer to a function registered as a pseudo file in the GLSL pseudo file system.
const char * get_GLSL_include_file(const std::string &name)
Gets a GLSL include file by file name.
void strip_trailing_null_entries(std::vector< const char * > &v)
Removes all trailing nullptr entries in a vector of strings.
void GEOGRAM_GFX_API introspect_program(GLuint program)
Outputs to the logger everything that can be queried about a program using OpenGL introspection APIs.
void GEOGRAM_GFX_API initialize()
Initializes some GLSL functions and objects.
GLuint GEOGRAM_GFX_API compile_shader(GLenum target, const char **sources, index_t nb_sources)
Compiles a shader for a specific target.
GLuint GEOGRAM_GFX_API compile_shader_with_includes(GLenum target, const char *source, PseudoFileProvider *provider)
Compiles a shader for a specific target.
GLuint GEOGRAM_GFX_API create_program_from_shaders_no_link(GLuint shader,...)
Creates a GLSL program from a zero-terminated list of shaders.
GLuint GEOGRAM_GFX_API create_program_from_string_no_link(const char *string, bool copy_string=true)
Creates a GLSL program from a string.
void GEOGRAM_GFX_API terminate()
Terminates GLSL functions and objects.
size_t GEOGRAM_GFX_API get_uniform_variable_array_stride(GLuint program, const char *varname)
Queries array stride for a variable in a GLSL program using introspection.
void GEOGRAM_GFX_API link_program(GLuint program)
Links a program.
GLint GEOGRAM_GFX_API get_uniform_variable_offset(GLuint program, const char *varname)
Gets the offset of a uniform variable relative to the uniform block it is declared in.
bool set_program_uniform_by_name(GLuint shader_id, const char *name, T val)
Sets a uniform variable in a shader by name.
void GEOGRAM_GFX_API register_GLSL_include_file(const std::string &name, const char *source)
Registers a file in the GLSL pseudo file system.
#define geo_assert_not_reached
Sets a non reachable point in the program.
#define geo_assert(x)
Verifies that a condition is met.
A class that can register functions to the GLSL pseudo file system.
virtual ~PseudoFileProvider()
PseudoFileProvider destructor.
Source & operator=(const Source &rhs)
Source assignment operator.
const char * text()
Gets the text.
void copy(const Source &rhs)
Copies a Source.
Source()
Source constructor.
Source(const Source &rhs)
Source copy constructor.
Source(const std::string &src)
Source constructor from a string.
Source(const char *src)
Source constructor from a char pointer.
#define GEOGRAM_GFX_API
Linkage declaration for geogram symbols.
Common include file, providing basic definitions. Should be included before anything else by all head...
Global Vorpaline namespace.
void geo_argused(const T &)
Suppresses compiler warnings about unused parameters.
geo_index_t index_t
The type for storing and manipulating indices.
Types and functions for numbers manipulation.
Exception thrown when a GLSL shader fails to compiled.
const char * what() const GEO_NOEXCEPT override
Gets the string identifying the exception.