obj2d: generate flat arrays, use ushort for indices
This commit is contained in:
parent
6985fe462b
commit
a746167957
19
obj2d.rb
19
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
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user