obj2d: switch to flat array of indices
This commit is contained in:
parent
6f87666e14
commit
543006b3ec
54
obj2d.rb
54
obj2d.rb
@ -3,31 +3,38 @@
|
|||||||
require "erb"
|
require "erb"
|
||||||
|
|
||||||
TEMPLATE = <<EOF
|
TEMPLATE = <<EOF
|
||||||
float[2][] vertices = [
|
struct indices_range_t
|
||||||
<%= 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 %>()
|
|
||||||
{
|
{
|
||||||
return [
|
int start;
|
||||||
<% obj_array.each_with_index do |oa, index| -%>
|
int length;
|
||||||
<%= obj_name %>_<%= index %>,
|
};
|
||||||
<% end -%>
|
|
||||||
];
|
float[<%= vertices.size %>] vertices = [
|
||||||
}
|
<% vertices.each do |coord| -%>
|
||||||
<% end %>
|
<%= coord %>,
|
||||||
|
<% 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
|
EOF
|
||||||
|
|
||||||
def main(obj_fname, d_fname)
|
def main(obj_fname, d_fname)
|
||||||
objects = {}
|
objects = {}
|
||||||
|
object_ranges = {}
|
||||||
vertices = []
|
vertices = []
|
||||||
|
indices = []
|
||||||
cur_obj = nil
|
cur_obj = nil
|
||||||
File.read(obj_fname).each_line do |line|
|
File.read(obj_fname).each_line do |line|
|
||||||
if line =~ /^v\s+(\S+)\s+(\S+)/
|
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}
|
cur_obj << [$1, $2].map {|v| v.to_i - 1}
|
||||||
end
|
end
|
||||||
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|
|
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
|
||||||
|
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 GENTEX = 0;
|
||||||
immutable enum int CORPORATION = 1;
|
immutable enum int CORPORATION = 1;
|
||||||
|
|
||||||
ushort[][][2][2] object_indices;
|
logoobj.indices_range_t [][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.get_fg(), logoobj.get_fc()],
|
object_indices = [[logoobj.fg, logoobj.fc],
|
||||||
[logoobj.get_lg(), logoobj.get_lc()]];
|
[logoobj.lg, logoobj.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++)
|
||||||
{
|
{
|
||||||
@ -31,7 +31,9 @@ void init()
|
|||||||
vao.bind();
|
vao.bind();
|
||||||
|
|
||||||
vertices_buffer.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();
|
ibo.bind();
|
||||||
|
|
||||||
object_vaos[draw_type][word][char_index] = vao;
|
object_vaos[draw_type][word][char_index] = vao;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user