From 1023f11bceddaf14a80e1b1ccf971fc6bdfca8c3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Tue, 9 Feb 2016 21:37:56 -0500 Subject: [PATCH] lib/gamnit: intro draw_mode MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This is very useful to create optimized Mesh, using gl_TRIANGLE_STRIP and gl_TRIANGLE_FAN. Signed-off-by: Alexis Laferrière --- lib/gamnit/depth/depth_core.nit | 3 +++ lib/gamnit/depth/more_materials.nit | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/gamnit/depth/depth_core.nit b/lib/gamnit/depth/depth_core.nit index 03a3970..f1e5803 100644 --- a/lib/gamnit/depth/depth_core.nit +++ b/lib/gamnit/depth/depth_core.nit @@ -103,6 +103,9 @@ class Mesh # Coordinates on the texture per vertex var texture_coords = new Array[Float] is lazy, writable + # `GLDrawMode` used to display this mesh, defaults to `gl_TRIANGLES` + fun draw_mode: GLDrawMode do return gl_TRIANGLES + # Create an UV sphere of `radius` with `n_meridians` and `n_parallels` init uv_sphere(radius: Float, n_meridians, n_parallels: Int) do diff --git a/lib/gamnit/depth/more_materials.nit b/lib/gamnit/depth/more_materials.nit index 6117128..b77c85e 100644 --- a/lib/gamnit/depth/more_materials.nit +++ b/lib/gamnit/depth/more_materials.nit @@ -75,9 +75,9 @@ class SmoothMaterial # Execute draw if mesh.indices.is_empty then - glDrawArrays(gl_TRIANGLES, 0, mesh.vertices.length/3) + glDrawArrays(mesh.draw_mode, 0, mesh.vertices.length/3) else - glDrawElements(gl_TRIANGLES, mesh.indices.length, gl_UNSIGNED_SHORT, mesh.indices_c.native_array) + glDrawElements(mesh.draw_mode, mesh.indices.length, gl_UNSIGNED_SHORT, mesh.indices_c.native_array) end end end @@ -182,9 +182,9 @@ class TexturedMaterial program.camera.uniform(app.world_camera.position.x, app.world_camera.position.y, app.world_camera.position.z) if mesh.indices.is_empty then - glDrawArrays(gl_TRIANGLES, 0, mesh.vertices.length/3) + glDrawArrays(mesh.draw_mode, 0, mesh.vertices.length/3) else - glDrawElements(gl_TRIANGLES, mesh.indices.length, gl_UNSIGNED_SHORT, mesh.indices_c.native_array) + glDrawElements(mesh.draw_mode, mesh.indices.length, gl_UNSIGNED_SHORT, mesh.indices_c.native_array) end end end @@ -220,9 +220,9 @@ class NormalsMaterial program.normal.array(mesh.normals, 3) if mesh.indices.is_empty then - glDrawArrays(gl_TRIANGLES, 0, mesh.vertices.length/3) + glDrawArrays(mesh.draw_mode, 0, mesh.vertices.length/3) else - glDrawElements(gl_TRIANGLES, mesh.indices.length, gl_UNSIGNED_SHORT, mesh.indices_c.native_array) + glDrawElements(mesh.draw_mode, mesh.indices.length, gl_UNSIGNED_SHORT, mesh.indices_c.native_array) end end end -- 1.7.9.5