From 40c37dacb2ed1b8587ad491c511b5341b766d7a4 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 24 Apr 2011 19:54:51 -0400 Subject: [PATCH] working on buildVBO() --- WFObj.cc | 24 +++++++++++++++++++++--- WFObj.h | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/WFObj.cc b/WFObj.cc index 7be41ad..56eaae1 100644 --- a/WFObj.cc +++ b/WFObj.cc @@ -440,10 +440,10 @@ bool WFObj::loadfile(const char *path, Buffer & buff) return false; } -void WFObj::buildVBO() +bool WFObj::buildVBO() { map flat_vertices; - int vid = 0; + int vid = 0, texture_ref_count = 0; glGenBuffers(1, &m_vbo); bool do_textures = m_loadtexture != NULL && m_vertices[VERTEX_TEXTURE].size() > 0; @@ -457,10 +457,28 @@ void WFObj::buildVBO() { for (int i = 0; i < 3; i++) { - flat_vertices[fit->vertices[i]] = vid++; + VertexRef vf = fit->vertices[i]; + if ( (vf.vertex < 1) + || (vf.texture < 0) + || (vf.normal < 1) + || (vf.vertex > m_vertices[VERTEX].size()) + || (vf.normal > m_vertices[VERTEX_NORMAL].size()) + || (vf.texture > m_vertices[VERTEX_TEXTURE].size()) ) + { + cerr << "WFObj: error: invalid vertex reference (<" + << vf.vertex << ", " << vf.texture << ", " + << vf.normal << ">)" << endl; + return false; + } + if (vf.texture != 0) + texture_ref_count++; + flat_vertices[vf] = vid++; } } } + if (texture_ref_count == 0) + do_textures = false; + return true; } bool WFObj::VertexRef::operator<(const VertexRef & other) const diff --git a/WFObj.h b/WFObj.h index b4c8ab4..a5d4379 100644 --- a/WFObj.h +++ b/WFObj.h @@ -99,7 +99,7 @@ protected: static bool loadfile(const char *path, Buffer & buff); std::string getLine(const Buffer & buff, size_t idx, size_t *update_idx); void loadMaterial(const std::string & name); - void buildVBO(); + bool buildVBO(); /* variables */ std::vector m_vertices[VERTEX_TYPES];