From d13e3a60b2ac43e41d835007de7de8c6c0af79d8 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 24 Apr 2011 22:19:24 -0400 Subject: [PATCH] fill in client-side data --- WFObj.cc | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/WFObj.cc b/WFObj.cc index 8234c42..f9afc5d 100644 --- a/WFObj.cc +++ b/WFObj.cc @@ -472,7 +472,8 @@ bool WFObj::buildVBO() } if (vf.texture != 0) texture_ref_count++; - flat_vertices[vf] = vid++; + if (flat_vertices.find(vf) == flat_vertices.end()) + flat_vertices[vf] = vid++; } } } @@ -480,9 +481,27 @@ bool WFObj::buildVBO() do_textures = false; size_t n_floats_per_vref = 3 + /* vertex coordinates */ - (do_textures ? 2 : 0) + /* texture coordinates */ - 3; /* normal coordinates */ + 3 + /* normal coordinates */ + (do_textures ? 2 : 0); /* texture coordinates */ GLfloat * data = new GLfloat[n_floats_per_vref * flat_vertices.size()]; + for (map::iterator it = flat_vertices.begin(); + it != flat_vertices.end(); + it++) + { + int base = n_floats_per_vref * it->second; + VertexRef vr = it->first; + data[base + 0] = m_vertices[VERTEX][vr.vertex - 1][0]; + data[base + 1] = m_vertices[VERTEX][vr.vertex - 1][1]; + data[base + 2] = m_vertices[VERTEX][vr.vertex - 1][2]; + data[base + 3] = m_vertices[VERTEX_NORMAL][vr.normal - 1][0]; + data[base + 4] = m_vertices[VERTEX_NORMAL][vr.normal - 1][1]; + data[base + 5] = m_vertices[VERTEX_NORMAL][vr.normal - 1][2]; + if (do_textures && vr.texture > 0) + { + data[base + 6] = m_vertices[VERTEX_TEXTURE][vr.texture - 1][0]; + data[base + 7] = m_vertices[VERTEX_TEXTURE][vr.texture - 1][1]; + } + } delete[] data; return true; }