From: Mikko Rasa Date: Tue, 15 Mar 2011 06:47:41 +0000 (+0000) Subject: Support exporting separate arrays in mesh2c (as opposed to interleaved) X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=9a9d3517dcfdba5206d9c73ce211feac8e402bc2;p=libs%2Fgl.git Support exporting separate arrays in mesh2c (as opposed to interleaved) --- diff --git a/mesh2c.cpp b/mesh2c.cpp index c15b829e..170799c9 100644 --- a/mesh2c.cpp +++ b/mesh2c.cpp @@ -24,9 +24,11 @@ int main(int argc, char **argv) { string prefix; bool render_func = false; + bool separate_arrays = false; GetOpt getopt; getopt.add_option('p', "prefix", prefix, GetOpt::REQUIRED_ARG); getopt.add_option('r', "render-func", render_func, GetOpt::NO_ARG); + getopt.add_option('s', "separate-arrays", separate_arrays, GetOpt::NO_ARG); getopt(argc, argv); const vector &args = getopt.get_args(); @@ -37,22 +39,69 @@ int main(int argc, char **argv) } GL::Mesh mesh; + mesh.use_buffers(false); DataFile::load(mesh, args[0]); IO::print("/* Exported from %s */\n", args[0]); const GL::VertexArray &array = mesh.get_vertices(); const GL::VertexFormat &fmt = array.get_format(); - IO::print("float %svertex_data[] =\n{", prefix); unsigned stride = fmt.stride(); - for(unsigned i=0; i>2; + unsigned size = ((*i)&3)+1; + string name; + switch(kind) + { + case 0: + name = "vertex"; + break; + case 1: + name = "normal"; + break; + case 2: + name = "color"; + break; + case 3: + name = "texcoord"; + break; + default: + if(kind<11) + name = format("texcoord%d", kind-3); + else + name = format("attrib%d", kind-11); + break; + } + + IO::print("float %s%s_data[] =\n{", prefix, name); + for(unsigned j=0; j>2; unsigned size = ((*i)&3)+1; + string source = format("%svertex_data+%d", prefix, offset); switch((*i)>>2) { case 0: - IO::print("\tglVertexPointer(%d, GL_FLOAT, %d*sizeof(float), %svertex_data+%d);\n", - size, stride, prefix, offset); + if(separate_arrays) + source = prefix+"vertex_data"; + IO::print("\tglVertexPointer(%d, GL_FLOAT, %d*sizeof(float), %s);\n", + size, stride, source); IO::print("\tglEnableClientState(GL_VERTEX_ARRAY);\n"); break; case 1: - IO::print("\tglNormalPointer(GL_FLOAT, %d*sizeof(float), %svertex_data+%d);\n", - stride, prefix, offset); + if(separate_arrays) + source = prefix+"normal_data"; + IO::print("\tglNormalPointer(GL_FLOAT, %d*sizeof(float), %s);\n", + stride, source); IO::print("\tglEnableClientState(GL_NORMAL_ARRAY);\n"); break; case 2: - IO::print("\tglTexCoordPointer(%d, GL_FLOAT, %d*sizeof(float), %svertex_data+%d);\n", - size, stride, prefix, offset); - IO::print("\tglEnableClientState(GL_TEXTURE_COORD_ARRAY);\n"); + if(separate_arrays) + source = prefix+"color_data"; + IO::print("\tglColorPointer(%d, GL_FLOAT, %d*sizeof(float), %s);\n", + size, stride, source); + IO::print("\tglEnableClientState(GL_COLOR_ARRAY);\n"); break; case 3: - IO::print("\tglColorPointer(%d, GL_FLOAT, %d*sizeof(float), %svertex_data+%d);\n", - size, stride, prefix, offset); - IO::print("\tglEnableClientState(GL_COLOR_ARRAY);\n"); + if(separate_arrays) + source = prefix+"texcoord_data"; + IO::print("\tglTexCoordPointer(%d, GL_FLOAT, %d*sizeof(float), %s);\n", + size, stride, source); + IO::print("\tglEnableClientState(GL_TEXTURE_COORD_ARRAY);\n"); break; default: - IO::print("\tglVertexAttribPointer(%d, %d, GL_FLOAT, GL_FALSE, %d*sizeof(float), %svertex_data+%d);\n", - kind-4, size, stride, prefix, offset); - IO::print("\tglEnableVertexAttribArray(%d);\n", kind-4); + if(kind<11) + { + if(separate_arrays) + source = format("%stexcoord%d_data", prefix, kind-3); + IO::print("\tglClientActiveTexture(GL_TEXTURE%d);\n", kind-3); + IO::print("\tglTexCoordPointer(%d, GL_FLOAT, %d*sizeof(float), %s);\n", + size, stride, source); + IO::print("\tglEnableClientState(GL_TEXTURE_COORD_ARRAY);\n"); + } + else + { + if(separate_arrays) + source = format("%sattrib%d_data", prefix, kind-11); + IO::print("\tglVertexAttribPointer(%d, %d, GL_FLOAT, GL_FALSE, %d*sizeof(float), %s);\n", + kind-11, size, stride, source); + IO::print("\tglEnableVertexAttribArray(%d);\n", kind-11); + } break; } offset += size;