obj2d: generate flat arrays, use ushort for indices
This commit is contained in:
parent
6985fe462b
commit
a746167957
17
obj2d.rb
17
obj2d.rb
@ -7,11 +7,22 @@ float[2][] vertices = [
|
|||||||
<%= vertices.map {|v| v[0, 2].inspect}.join(",\n ") %>
|
<%= vertices.map {|v| v[0, 2].inspect}.join(",\n ") %>
|
||||||
];
|
];
|
||||||
<% objects.each_pair do |obj_name, obj_array| %>
|
<% objects.each_pair do |obj_name, obj_array| %>
|
||||||
|
<% obj_array.each_with_index do |oa, index| %>
|
||||||
|
|
||||||
int[][][] <%= obj_name %> = [
|
ushort[<%= oa.size * oa.first.size %>] <%= obj_name %>_<%= index %> = [
|
||||||
<%= obj_array.map {|oa| "[" + oa.map {|o| o.inspect}.join(",\n ") + "]"}.join(",\n ") %>
|
<%= oa.map {|indices| indices.join(", ")}.join(",\n ") %>
|
||||||
];
|
];
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
ushort[][] get_<%= obj_name %>()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
<% obj_array.each_with_index do |oa, index| -%>
|
||||||
|
<%= obj_name %>_<%= index %>,
|
||||||
|
<% end -%>
|
||||||
|
];
|
||||||
|
}
|
||||||
|
<% end %>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
def main(obj_fname, d_fname)
|
def main(obj_fname, d_fname)
|
||||||
@ -35,7 +46,7 @@ def main(obj_fname, d_fname)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
File.open(d_fname, "w") do |fh|
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -9,13 +9,14 @@ immutable enum int WIRE = 1;
|
|||||||
immutable enum int GENTEX = 0;
|
immutable enum int GENTEX = 0;
|
||||||
immutable enum int CORPORATION = 1;
|
immutable enum int CORPORATION = 1;
|
||||||
|
|
||||||
int[][][][][] object_indices;
|
ushort[][][2][2] object_indices;
|
||||||
/* Indexed by: face/wire, word, character */
|
/* Indexed by: face/wire, word, character */
|
||||||
VAO[][2][2] object_vaos;
|
VAO[][2][2] object_vaos;
|
||||||
|
|
||||||
void init()
|
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);
|
Buffer vertices_buffer = new Buffer(logoobj.vertices);
|
||||||
for (int draw_type = FACE; draw_type <= WIRE; draw_type++)
|
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);
|
glEnableVertexAttribArray(position_idx);
|
||||||
glVertexAttribPointer(position_idx, 2, GL_FLOAT, GL_FALSE, 0, null);
|
glVertexAttribPointer(position_idx, 2, GL_FLOAT, GL_FALSE, 0, null);
|
||||||
glDrawElements(draw_type == FACE ? GL_TRIANGLES : GL_LINES,
|
glDrawElements(draw_type == FACE ? GL_TRIANGLES : GL_LINES,
|
||||||
object_indices[draw_type][word].length,
|
object_indices[draw_type][word][character].length,
|
||||||
GL_UNSIGNED_INT,
|
GL_UNSIGNED_SHORT,
|
||||||
null);
|
null);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user