23 draw(m, model, view, projection, texture);
28 draw(m,
Identity(), camera, texture);
47 draw(m, model, view, projection);
72 draw(group, m, model, view, projection);
97 draw(group, m, model, view, projection, texture);
102 draw(group, m,
Identity(), camera, texture);
112GLuint
DrawParam::create_program(
const GLenum primitives,
const bool use_texcoord,
const bool use_normal,
const bool use_color,
const bool use_light,
const bool use_alpha_test )
114 std::string definitions;
117 definitions.append(
"#define USE_TEXCOORD\n");
119 definitions.append(
"#define USE_NORMAL\n");
121 definitions.append(
"#define USE_COLOR\n");
123 definitions.append(
"#define USE_LIGHT\n");
124 if(use_texcoord && use_alpha_test)
125 definitions.append(
"#define USE_ALPHATEST\n");
128 const char *filename=
smart_path(
"data/shaders/mesh.glsl");
129 bool use_mesh_color= (primitives == GL_POINTS || primitives == GL_LINES || primitives == GL_LINE_STRIP || primitives == GL_LINE_LOOP);
131 filename=
smart_path(
"data/shaders/mesh_color.glsl");
134 return program->program;
137GLuint DrawParam::create_debug_normals_program(
const GLenum primitives,
const bool use_texcoord,
const bool use_normal,
const bool use_color,
const bool use_light,
const bool use_alpha_test )
139 const char *filename=
smart_path(
"data/shaders/normals.glsl");
140 bool use_mesh_color= (primitives == GL_POINTS || primitives == GL_LINES || primitives == GL_LINE_STRIP || primitives == GL_LINE_LOOP);
146 return program->program;
149GLuint DrawParam::create_debug_texcoords_program(
const GLenum primitives,
const bool use_texcoord,
const bool use_normal,
const bool use_color,
const bool use_light,
const bool use_alpha_test )
151 const char *filename=
smart_path(
"data/shaders/texcoords.glsl");
153 return program->program;
159 bool use_texcoord= m_use_texture && m_texture > 0 && mesh.has_texcoord();
160 bool use_normal= mesh.has_normal();
161 bool use_color= mesh.has_color();
167 if(m_debug_texcoords)
169 program= create_debug_texcoords_program(mesh.primitives(), use_texcoord, use_normal, use_color, m_use_light, m_use_alpha_test);
171 m_use_texture=
false;
172 m_use_alpha_test=
false;
177 glUseProgram(program);
179 program_uniform(program,
"mvpMatrix", mvp);
180 program_uniform(program,
"mvMatrix", mv);
186 program=
create_program(mesh.primitives(), use_texcoord, use_normal, use_color, m_use_light, m_use_alpha_test);
188 glUseProgram(program);
190 program_uniform(program,
"mesh_color", mesh.default_color());
192 program_uniform(program,
"mvpMatrix", mvp);
194 program_uniform(program,
"normalMatrix", mv.
normal());
196 program_uniform(program,
"mvMatrix", mv);
199 if(use_texcoord && m_texture > 0)
204 program_uniform(program,
"light", m_view(m_light));
205 program_uniform(program,
"light_color", m_light_color);
206 program_uniform(program,
"mvMatrix", mv);
210 program_uniform(program,
"alpha_min", m_alpha_min);
217 program= create_debug_normals_program(mesh.primitives(), use_texcoord, use_normal, use_color, m_use_light, m_use_alpha_test);
219 m_use_texture=
false;
220 m_use_alpha_test=
false;
225 static float scale= 1;
233 glUseProgram(program);
234 program_uniform(program,
"mvpMatrix", mvp);
235 program_uniform(program,
"normalMatrix", mv.
normal());
236 program_uniform(program,
"scale", scale * m_normals_scale);
244 bool use_texcoord= m_use_texture && m_texture > 0 && mesh.has_texcoord();
245 bool use_normal= mesh.has_normal();
246 bool use_color= mesh.has_color();
249 GLuint program=
create_program(mesh.primitives(), use_texcoord, use_normal, use_color, m_use_light, m_use_alpha_test);
251 glUseProgram(program);
252 if(group.
index != -1 && group.
index < mesh.materials().count())
253 program_uniform(program,
"mesh_color", mesh.materials().material(group.
index).diffuse);
255 program_uniform(program,
"mesh_color", mesh.materials().default_material().diffuse);
260 program_uniform(program,
"mvpMatrix", mvp);
262 program_uniform(program,
"normalMatrix", mv.
normal());
264 program_uniform(program,
"mvMatrix", mv);
267 if(use_texcoord && m_texture > 0)
272 program_uniform(program,
"light", m_view(m_light));
273 program_uniform(program,
"light_color", m_light_color);
274 program_uniform(program,
"mvMatrix", mv);
278 program_uniform(program,
"alpha_min", m_alpha_min);
void draw(Mesh &mesh)
dessine l'objet avec l'ensemble des parametres definis.
DrawParam & model(const Transform &m)
modifie la transformation model utilisee pour afficher l'objet.
DrawParam & view(const Transform &m)
modifie la transformation view utilisee pour afficher l'objet.
GLuint create_program(const GLenum primitives, const bool use_texcoord, const bool use_normal, const bool use_color, const bool use_light, const bool use_alpha_test)
DrawParam & projection(const Transform &m)
modifie la transformation projection utilisee pour afficher l'objet.
DrawParam & texture(const GLuint t)
plaque une texture opaque a la surface de l'objet.
representation d'un objet / maillage.
void draw(const GLuint program)
dessine l'objet avec un shader program.
representation de la camera, type orbiter, placee sur une sphere autour du centre de l'objet.
PipelineProgram * find(const char *filename, const char *definitions="")
renvoie un shader program compile.
static PipelineCache & manager()
access au singleton.
description d'un shader program compile.
const char * smart_path(const char *filename)
renvoie le chemin(path) vers le fichier 'filename' apres l'avoir cherche dans un repertoire standard....
int window_height()
renvoie la hauteur de la fenetre de l'application.
int key_state(const SDL_Keycode key)
renvoie l'etat d'une touche du clavier. cf la doc SDL2 pour les codes.
int window_width()
renvoie la largeur de la fenetre de l'application.
Transform Identity()
construit la transformation identite.
int first
premier triangle du groupe
int index
indice de la "propriete"du groupe de triangles, par defaut : indice de la matiere
int n
nombre de triangles du groupe
representation d'un ensemble de triangles de meme matiere.
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,...