12 int location(
const GLuint program,
const char *uniform,
const int array_size= 0 )
18 char error[4096]= { 0 };
19 GLint location= glGetUniformLocation(program, uniform);
25 glGetObjectLabel(GL_PROGRAM, program,
sizeof(
label),
nullptr,
label);
27 sprintf(error,
"uniform( %s %u, '%s' ): not found.",
label, program, uniform);
30 sprintf(error,
"uniform( program %u, '%s'): not found.", program, uniform);
33 static std::set<std::string> log;
34 if(log.insert(error).second ==
true)
44 glGetIntegerv(GL_CURRENT_PROGRAM, (GLint *) ¤t);
45 if(current != program)
50 glGetObjectLabel(GL_PROGRAM, program,
sizeof(
label),
nullptr,
label);
52 glGetObjectLabel(GL_PROGRAM, current,
sizeof(labelc),
nullptr, labelc);
54 sprintf(error,
"uniform( %s %u, '%s' ): invalid current shader program( %s %u )",
label, program, uniform, labelc, current);
57 sprintf(error,
"uniform( program %u, '%s' ): invalid current shader program( %u )...", program, uniform, current);
61 glUseProgram(program);
64 if(location >= 0 && array_size > 0)
68 GLuint index= glGetProgramResourceIndex(program, GL_UNIFORM, uniform);
69 if(index != GL_INVALID_INDEX)
71 GLenum props[]= { GL_ARRAY_SIZE };
73 glGetProgramResourceiv(program, GL_UNIFORM, index, 1, props, 1,
nullptr, &
value);
74 if(
value != array_size)
77 glGetObjectLabel(GL_PROGRAM, program,
sizeof(
label),
nullptr,
label);
79 printf(
"uniform( %s %u, '%s' array [%d] ): invalid array size [%d]...\n",
label, location, uniform,
value, array_size);
89 void program_uniform(
const GLuint program,
const char *uniform,
const unsigned int v )
91 glUniform1ui( location(program, uniform), v );
94 void program_uniform(
const GLuint program,
const char *uniform,
const std::vector<unsigned>& v )
97 glUniform1uiv( location(program, uniform, v.size()), v.size(), v.data() );
102 glUniform1i( location(program, uniform), v );
105 void program_uniform(
const GLuint program,
const char *uniform,
const std::vector<int>& v )
108 glUniform1iv( location(program, uniform, v.size()), v.size(), v.data() );
113 glUniform1f( location(program, uniform), v );
116 void program_uniform(
const GLuint program,
const char *uniform,
const std::vector<float>& v )
119 glUniform1fv( location(program, uniform, v.size()), v.size(), v.data() );
124 glUniform2fv( location(program, uniform), 1, &v.x );
127 void program_uniform(
const GLuint program,
const char *uniform,
const std::vector<vec2>& v )
130 glUniform2fv( location(program, uniform, v.size()), v.size(), &v[0].x );
135 glUniform3fv( location(program, uniform), 1, &v.x );
138 void program_uniform(
const GLuint program,
const char *uniform,
const std::vector<vec3>& v )
141 glUniform3fv( location(program, uniform, v.size()), v.size(), &v[0].x );
146 glUniform3fv( location(program, uniform), 1, &a.x );
149 void program_uniform(
const GLuint program,
const char *uniform,
const std::vector<Point>& a )
152 glUniform3fv( location(program, uniform, a.size()), a.size(), &a[0].x );
157 glUniform3fv( location(program, uniform), 1, &v.x );
160 void program_uniform(
const GLuint program,
const char *uniform,
const std::vector<Vector>& v )
163 glUniform3fv( location(program, uniform, v.size()), v.size(), &v[0].x );
168 glUniform4fv( location(program, uniform), 1, &v.x );
171 void program_uniform(
const GLuint program,
const char *uniform,
const std::vector<vec4>& v )
174 glUniform4fv( location(program, uniform, v.size()), v.size(), &v[0].x );
179 glUniform4fv( location(program, uniform), 1, &c.r );
182 void program_uniform(
const GLuint program,
const char *uniform,
const std::vector<Color>& c )
185 glUniform4fv( location(program, uniform, c.size()), c.size(), &c[0].r );
190 glUniformMatrix4fv( location(program, uniform), 1, GL_TRUE, v.
data() );
193 void program_uniform(
const GLuint program,
const char *uniform,
const std::vector<Transform>& v )
195 glUniformMatrix4fv( location(program, uniform, v.size()), v.size(), GL_TRUE, v[0].data() );
198 void program_use_texture(
const GLuint program,
const char *uniform,
const int unit,
const GLuint texture,
const GLuint sampler )
201 int id= location(program, uniform);
206 glActiveTexture(GL_TEXTURE0 + unit);
208 glBindTexture(GL_TEXTURE_2D, texture);
211 glBindSampler(unit, sampler);
214 glUniform1i(
id, unit);
void label(Widgets &w, const char *format,...)
cree un texte. meme fonctionnement que printf().
bool value(Widgets &w, const char *label, int &value, const int value_min, const int value_max, const int value_step)
valeur editable par increment.
void printf(Text &text, const int px, const int py, const char *format,...)
affiche un texte a la position x, y. meme utilisation que printf().
void program_uniform(const GLuint program, const char *uniform, const std::vector< unsigned > &v)
affecte un tableau de valeurs a un uniform du shader program.
void program_use_texture(const GLuint program, const char *uniform, const int unit, const GLuint texture, const GLuint sampler)
configure le pipeline et le shader program pour utiliser une texture, et des parametres de filtrage,...
representation d'une couleur (rgba) transparente ou opaque.
representation d'un point 3d.
representation d'un vecteur 3d.
vecteur generique, utilitaire.
vecteur generique, utilitaire.
vecteur generique 4d, ou 3d homogene, utilitaire.