This shows you the differences between two versions of the page.
spg:laboratoare:02 [2023/08/30 13:25] andrei.lambru |
spg:laboratoare:02 [2023/09/29 13:39] (current) andrei.lambru [Diferite tipuri de instanțiere] |
||
---|---|---|---|
Line 17: | Line 17: | ||
Pentru a instanția implict geometrie, există comanda: | Pentru a instanția implict geometrie, există comanda: | ||
- | <code> | + | <code cpp> |
glDrawElementsInstanced(topologie, nr_indecsi, tip_data, offset, instante). | glDrawElementsInstanced(topologie, nr_indecsi, tip_data, offset, instante). | ||
</code> | </code> | ||
Line 23: | Line 23: | ||
De exemplu, dacă aș dori să desenez de 1540 de ori (instanțe) un obiect cu 99 de indecși, format din triunghiuri din buffer-ul de indecși, legat curent la banda grafică, atunci comanda ar fi: | De exemplu, dacă aș dori să desenez de 1540 de ori (instanțe) un obiect cu 99 de indecși, format din triunghiuri din buffer-ul de indecși, legat curent la banda grafică, atunci comanda ar fi: | ||
- | <code> | + | <code cpp> |
glDrawElementsInstanced(GL_TRIANGLES, 99, GL_UNSIGNED_INT, 0, 1540); | glDrawElementsInstanced(GL_TRIANGLES, 99, GL_UNSIGNED_INT, 0, 1540); | ||
</code> | </code> | ||
Instanțierea explicită se face în shader, generând geometrie nouă prin comenzi glsl, în acest caz prin comenzi de geometry shader: | Instanțierea explicită se face în shader, generând geometrie nouă prin comenzi glsl, în acest caz prin comenzi de geometry shader: | ||
- | <code> | + | <code cpp> |
gl_Position = P*V*M*vec4(p1, 1); EmitVertex(); | gl_Position = P*V*M*vec4(p1, 1); EmitVertex(); | ||
gl_Position = P*V*M*vec4(p2, 1); EmitVertex(); | gl_Position = P*V*M*vec4(p2, 1); EmitVertex(); |