working on buildVBO()

This commit is contained in:
Josh Holtrop 2011-04-24 19:54:51 -04:00
parent 6dab4e48a6
commit 40c37dacb2
2 changed files with 22 additions and 4 deletions

View File

@ -440,10 +440,10 @@ bool WFObj::loadfile(const char *path, Buffer & buff)
return false;
}
void WFObj::buildVBO()
bool WFObj::buildVBO()
{
map<VertexRef, int> 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

View File

@ -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<Vertex> m_vertices[VERTEX_TYPES];