From: Alexis Laferrière Date: Wed, 10 Feb 2016 02:37:56 +0000 (-0500) Subject: lib/gamnit: intro draw_mode X-Git-Url: http://nitlanguage.org lib/gamnit: intro draw_mode This is very useful to create optimized Mesh, using gl_TRIANGLE_STRIP and gl_TRIANGLE_FAN. Signed-off-by: Alexis Laferrière --- 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