From 6dab4e48a6c51f4e52174df5e95ce60f2ec488bc Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 24 Apr 2011 19:14:07 -0400 Subject: [PATCH] build flat_vertices collection for VBO --- WFObj.cc | 18 +++++++++++++++++- WFObj.h | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/WFObj.cc b/WFObj.cc index 88a8f10..7be41ad 100644 --- a/WFObj.cc +++ b/WFObj.cc @@ -442,12 +442,28 @@ bool WFObj::loadfile(const char *path, Buffer & buff) void WFObj::buildVBO() { + map flat_vertices; + int vid = 0; glGenBuffers(1, &m_vbo); bool do_textures = m_loadtexture != NULL && m_vertices[VERTEX_TEXTURE].size() > 0; + for (map >::iterator it = m_faces.begin(); + it != m_faces.end(); + it++) + { + for (vector::iterator fit = it->second.begin(); + fit != it->second.end(); + fit++) + { + for (int i = 0; i < 3; i++) + { + flat_vertices[fit->vertices[i]] = vid++; + } + } + } } -bool WFObj::VertexRef::operator<(const VertexRef & other) +bool WFObj::VertexRef::operator<(const VertexRef & other) const { if (vertex != other.vertex) return vertex < other.vertex; diff --git a/WFObj.h b/WFObj.h index 51568fa..b4c8ab4 100644 --- a/WFObj.h +++ b/WFObj.h @@ -61,7 +61,7 @@ protected: int vertex; int texture; int normal; - bool operator<(const VertexRef & other); + bool operator<(const VertexRef & other) const; }; class Face