a deriver pour afficher les objets.
94 {
95 static bool zinit= false;
97 {
99 zinit= !zinit;
100
101 if(zinit)
103 else
104 printf(
"Z prepass off\n");
105 }
106
107
108 static bool cull= true;
110 {
112
113 cull= !cull;
114 if(cull)
115 glEnable(GL_CULL_FACE);
116 else
117 glDisable(GL_CULL_FACE);
118
119 if(cull)
120 printf(
"face culling ON\n");
121 else
122 printf(
"face culling off\n");
123 }
124
125 static bool early_tests= false;
126 static const char *early_tests_definition= "";
127 static bool reload= false;
129 {
131
132 early_tests= !early_tests;
133 if(early_tests)
134 early_tests_definition= "#define EARLY_TESTS";
135 else
136 early_tests_definition= "#undef EARLY_TESTS";
137 reload= true;
138
139 if(early_tests)
140 printf(
"early fragment tests ON\n");
141 else
142 printf(
"early fragment test off\n");
143 }
144
146 {
147 reload= false;
149
150 reload_program(m_program, early_tests_definition);
152
153 reload_program(m_program_count);
155
156 reload_program(m_program_display);
158 }
159
160
161
162 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_framebuffer);
163 glViewport(0, 0, 8192, 8192);
164
165 float one[]= { 1 };
166 glClearBufferfv(GL_DEPTH, 0, one);
167 GLuint zero[]= { 0, 0, 0, 0 };
168 glClearBufferuiv(GL_COLOR, 0, zero);
169
170
171 Transform view= m_camera.view();
172 Transform projection= m_camera.projection(8192, 8192, 60);
173
174 Transform model;
177
178 Transform mv= view * model;
179 Transform mvp= projection * mv;
180
181
182 if(zinit)
183 {
184 draw(m_mesh, model, view, projection);
185 }
186
187 glUseProgram(m_program);
188 program_uniform(m_program, "mvpMatrix", mvp);
189
190 m_mesh.draw(m_program);
191
192
193 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
195 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
196
197 glClearTexImage(m_texture, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, zero);
198
199 {
200
201 glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
202 glUseProgram(m_program_count);
203
204 glBindImageTexture(0, m_texture, 0, GL_TRUE, 0, GL_WRITE_ONLY, GL_R32UI);
205 program_uniform(m_program, "counters", 0);
206
207 glBindImageTexture(1, m_aatexture, 0, GL_TRUE, 0, GL_READ_ONLY, GL_R32UI);
208 program_uniform(m_program, "primitives", 1);
209
210 glDispatchCompute(1024, 1024, 1);
211
212
213 glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
214 glUseProgram(m_program_display);
215
216 program_uniform(m_program_display, "image", 0);
217
218 glDrawArrays(GL_TRIANGLES, 0, 3);
219 }
220
221
222 update_camera( m_camera );
223
224 return 1;
225 }
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().
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.
float global_time()
renvoie le temps ecoule depuis le lancement de l'application, en millisecondes.
Transform RotationY(const float a)
renvoie la matrice representation une rotation de a degree autour de l'axe Y.