23 TP( ) :
App(1024, 640)
34 m_objet.bounds(pmin, pmax);
35 m_camera.lookat(pmin -
Vector(20, 20, 0), pmax +
Vector(20, 20, 0));
42 m_vertex_count= m_objet.vertex_count();
49 glBindBuffer(GL_ARRAY_BUFFER, 0);
52 glGenQueries(1, &m_time_query);
58 glClearColor(0.2f, 0.2f, 0.2f, 1.f);
62 glEnable(GL_DEPTH_TEST);
69 glDeleteQueries(1, &m_time_query);
73 glDeleteTextures(1, &m_texture);
78 int update(
const float time,
const float delta )
86 update_camera( m_camera );
88 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
91 glBeginQuery(GL_TIME_ELAPSED, m_time_query);
95 std::chrono::high_resolution_clock::time_point cpu_start= std::chrono::high_resolution_clock::now();
101 mode= (mode + 1) % 3;
107 draw(m_objet, m_model, m_camera, m_texture);
112 for(
int y= -2; y <= 2; y++)
113 for(
int x= -2; x <= 2; x++)
116 draw(m_objet, t * m_model, m_camera, m_texture);
123 glBindVertexArray(m_vao);
124 glUseProgram(m_program);
132 program_uniform(m_program,
"mvpMatrix", mvp);
133 program_uniform(m_program,
"normalMatrix", mv.
normal());
136 glDrawArraysInstanced(GL_TRIANGLES, 0, m_vertex_count, 25);
139 std::chrono::high_resolution_clock::time_point cpu_stop= std::chrono::high_resolution_clock::now();
141 int cpu_time= std::chrono::duration_cast<std::chrono::microseconds>(cpu_stop - cpu_start).count();
143 glEndQuery(GL_TIME_ELAPSED);
148 std::chrono::high_resolution_clock::time_point wait_start= std::chrono::high_resolution_clock::now();
152 glGetQueryObjecti64v(m_time_query, GL_QUERY_RESULT, &gpu_time);
154 std::chrono::high_resolution_clock::time_point wait_stop= std::chrono::high_resolution_clock::now();
155 int wait_time= std::chrono::duration_cast<std::chrono::microseconds>(wait_stop - wait_start).count();
159 if(mode == 0)
printf(m_console, 0, 0,
"mode 0 : 1 draw");
160 if(mode == 1)
printf(m_console, 0, 0,
"mode 1 : 25 draws");
161 if(mode == 2)
printf(m_console, 0, 0,
"mode 2 : 1 draw / 25 instances");
162 printf(m_console, 0, 1,
"cpu %02dms %03dus",
int(cpu_time / 1000),
int(cpu_time % 1000));
163 printf(m_console, 0, 2,
"gpu %02dms %03dus",
int(gpu_time / 1000000),
int((gpu_time / 1000) % 1000));
164 printf(m_console, 0, 3,
"wait %02dms %03dus",
int(wait_time / 1000),
int(wait_time % 1000));
170 printf(
"cpu %02dms %03dus ",
int(cpu_time / 1000),
int(cpu_time % 1000));
171 printf(
"gpu %02dms %03dus\n",
int(gpu_time / 1000000),
int((gpu_time / 1000) % 1000));
187 GLuint m_vertex_buffer;
188 unsigned int m_vertex_count;
192int main(
int argc,
char **argv )
int run()
execution de l'application.
App(const int width, const int height, const int major=3, const int minor=3)
constructeur, dimensions de la fenetre et version d'openGL.
representation d'un objet / maillage.
representation de la camera, type orbiter, placee sur une sphere autour du centre de l'objet.
int render()
a deriver pour afficher les objets. renvoie 1 pour continuer, 0 pour fermer l'application.
int quit()
a deriver pour detruire les objets openGL. renvoie -1 pour indiquer une erreur, 0 sinon.
int update(const float time, const float delta)
a deriver et redefinir pour animer les objets en fonction du temps.
int init()
a deriver pour creer les objets openGL. renvoie -1 pour indiquer une erreur, 0 sinon.
void clear(Text &text)
efface le contenu de la console.
int window_height()
renvoie la hauteur de la fenetre de l'application.
void clear_key_state(const SDL_Keycode key)
desactive une touche du clavier.
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().
Text create_text()
cree une console. a detruire avec release_text( ).
int key_state(const SDL_Keycode key)
renvoie l'etat d'une touche du clavier. cf la doc SDL2 pour les codes.
void release_text(Text &text)
detruit une console.
int window_width()
renvoie la largeur de la fenetre de l'application.
Transform RotationY(const float a)
renvoie la matrice representation une rotation de a degree autour de l'axe Y.
Transform Translation(const Vector &v)
renvoie la matrice representant une translation par un vecteur.
Mesh read_mesh(const char *filename)
charge un fichier wavefront .obj et renvoie un mesh compose de triangles non indexes....
@ USE_POSITION
inclut l'attribut position dans les buffers.
@ USE_TEXCOORD
inclut l'attribut coordonnees de texture dans les buffers.
@ USE_NORMAL
inclut l'attribut normale dans les buffers.
GLuint read_program(const char *filename, const char *definitions)
int program_print_errors(const GLuint program, const char *filename)
affiche les erreurs de compilation.
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,...
GLuint read_texture(const int unit, const char *filename, const GLenum texel_type)
representation d'un point 3d.
representation d'un vecteur 3d.