From a746167957f7902e1671c5eee5ec3d3c8161dd7c Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 19 Nov 2013 22:46:55 -0500 Subject: [PATCH] obj2d: generate flat arrays, use ushort for indices --- obj2d.rb | 19 +++++++++++++++---- src/logo.d | 9 +++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/obj2d.rb b/obj2d.rb index c81f3a2..27f38aa 100644 --- a/obj2d.rb +++ b/obj2d.rb @@ -7,10 +7,21 @@ float[2][] vertices = [ <%= vertices.map {|v| v[0, 2].inspect}.join(",\n ") %> ]; <% objects.each_pair do |obj_name, obj_array| %> + <% obj_array.each_with_index do |oa, index| %> -int[][][] <%= obj_name %> = [ - <%= obj_array.map {|oa| "[" + oa.map {|o| o.inspect}.join(",\n ") + "]"}.join(",\n ") %> -]; +ushort[<%= oa.size * oa.first.size %>] <%= obj_name %>_<%= index %> = [ + <%= oa.map {|indices| indices.join(", ")}.join(",\n ") %> + ]; + <% end %> + +ushort[][] get_<%= obj_name %>() +{ + return [ + <% obj_array.each_with_index do |oa, index| -%> + <%= obj_name %>_<%= index %>, + <% end -%> + ]; +} <% end %> EOF @@ -35,7 +46,7 @@ def main(obj_fname, d_fname) end end File.open(d_fname, "w") do |fh| - fh.puts ERB.new(TEMPLATE, nil, "<>").result(binding) + fh.puts ERB.new(TEMPLATE, nil, "<>-").result(binding) end end diff --git a/src/logo.d b/src/logo.d index ede1961..ec2ac0f 100644 --- a/src/logo.d +++ b/src/logo.d @@ -9,13 +9,14 @@ immutable enum int WIRE = 1; immutable enum int GENTEX = 0; immutable enum int CORPORATION = 1; -int[][][][][] object_indices; +ushort[][][2][2] object_indices; /* Indexed by: face/wire, word, character */ VAO[][2][2] object_vaos; void init() { - object_indices = [[logoobj.fg, logoobj.fc], [logoobj.lg, logoobj.lc]]; + object_indices = [[logoobj.get_fg(), logoobj.get_fc()], + [logoobj.get_lg(), logoobj.get_lc()]]; Buffer vertices_buffer = new Buffer(logoobj.vertices); for (int draw_type = FACE; draw_type <= WIRE; draw_type++) { @@ -45,7 +46,7 @@ void draw(int draw_type, int word, int character, GLint position_idx) glEnableVertexAttribArray(position_idx); glVertexAttribPointer(position_idx, 2, GL_FLOAT, GL_FALSE, 0, null); glDrawElements(draw_type == FACE ? GL_TRIANGLES : GL_LINES, - object_indices[draw_type][word].length, - GL_UNSIGNED_INT, + object_indices[draw_type][word][character].length, + GL_UNSIGNED_SHORT, null); }