obj2d: switch to flat array of indices
This commit is contained in:
parent
6f87666e14
commit
543006b3ec
50
obj2d.rb
50
obj2d.rb
@ -3,31 +3,38 @@
|
||||
require "erb"
|
||||
|
||||
TEMPLATE = <<EOF
|
||||
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| %>
|
||||
|
||||
ushort[<%= oa.size * oa.first.size %>] <%= obj_name %>_<%= index %> = [
|
||||
<%= oa.map {|indices| indices.join(", ")}.join(",\n ") %>
|
||||
];
|
||||
<% end %>
|
||||
|
||||
ushort[][] get_<%= obj_name %>()
|
||||
struct indices_range_t
|
||||
{
|
||||
return [
|
||||
<% obj_array.each_with_index do |oa, index| -%>
|
||||
<%= obj_name %>_<%= index %>,
|
||||
int start;
|
||||
int length;
|
||||
};
|
||||
|
||||
float[<%= vertices.size %>] vertices = [
|
||||
<% vertices.each do |coord| -%>
|
||||
<%= coord %>,
|
||||
<% end -%>
|
||||
];
|
||||
}
|
||||
<% end %>
|
||||
|
||||
ushort[<%= indices.size %>] indices = [
|
||||
<% indices.each do |index| -%>
|
||||
<%= index %>,
|
||||
<% end -%>
|
||||
];
|
||||
|
||||
<% object_ranges.each_pair do |obj_name, obj_ranges| -%>
|
||||
indices_range_t[] <%= obj_name %> = [
|
||||
<% obj_ranges.each do |obj_range| -%>
|
||||
{<%= obj_range[0] %>, <%= obj_range[1] %>},
|
||||
<% end -%>
|
||||
];
|
||||
<% end -%>
|
||||
EOF
|
||||
|
||||
def main(obj_fname, d_fname)
|
||||
objects = {}
|
||||
object_ranges = {}
|
||||
vertices = []
|
||||
indices = []
|
||||
cur_obj = nil
|
||||
File.read(obj_fname).each_line do |line|
|
||||
if line =~ /^v\s+(\S+)\s+(\S+)/
|
||||
@ -45,6 +52,15 @@ def main(obj_fname, d_fname)
|
||||
cur_obj << [$1, $2].map {|v| v.to_i - 1}
|
||||
end
|
||||
end
|
||||
vertices.flatten!
|
||||
objects.each_pair do |obj_name, obj_array|
|
||||
object_ranges[obj_name] = obj_array.map do |obj_indices|
|
||||
obj_indices.flatten!
|
||||
base_index = indices.size
|
||||
indices += obj_indices
|
||||
[base_index, obj_indices.size]
|
||||
end
|
||||
end
|
||||
File.open(d_fname, "w") do |fh|
|
||||
fh.puts ERB.new(TEMPLATE, nil, "<>-").result(binding)
|
||||
end
|
||||
|
10
src/logo.d
10
src/logo.d
@ -9,14 +9,14 @@ immutable enum int WIRE = 1;
|
||||
immutable enum int GENTEX = 0;
|
||||
immutable enum int CORPORATION = 1;
|
||||
|
||||
ushort[][][2][2] object_indices;
|
||||
logoobj.indices_range_t [][2][2] object_indices;
|
||||
/* Indexed by: face/wire, word, character */
|
||||
VAO[][2][2] object_vaos;
|
||||
|
||||
void init()
|
||||
{
|
||||
object_indices = [[logoobj.get_fg(), logoobj.get_fc()],
|
||||
[logoobj.get_lg(), logoobj.get_lc()]];
|
||||
object_indices = [[logoobj.fg, logoobj.fc],
|
||||
[logoobj.lg, logoobj.lc]];
|
||||
Buffer vertices_buffer = new Buffer(logoobj.vertices);
|
||||
for (int draw_type = FACE; draw_type <= WIRE; draw_type++)
|
||||
{
|
||||
@ -31,7 +31,9 @@ void init()
|
||||
vao.bind();
|
||||
|
||||
vertices_buffer.bind();
|
||||
ElementBuffer ibo = new ElementBuffer(object_indices[draw_type][word][char_index]);
|
||||
int start = object_indices[draw_type][word][char_index].start;
|
||||
int length = object_indices[draw_type][word][char_index].length;
|
||||
ElementBuffer ibo = new ElementBuffer(logoobj.indices[start .. (start + length)]);
|
||||
ibo.bind();
|
||||
|
||||
object_vaos[draw_type][word][char_index] = vao;
|
||||
|
Loading…
x
Reference in New Issue
Block a user