fill indices VBO

This commit is contained in:
Josh Holtrop 2011-04-24 23:16:13 -04:00
parent 02a3f85fc1
commit fea2100741

View File

@ -172,9 +172,8 @@ bool WFObj::load(const WFObj::Buffer &buff)
updateAABB();
buildVBO();
m_valid = true;
return true;
m_valid = buildVBO();
return m_valid;
}
string WFObj::getLine(const Buffer & buff, size_t idx, size_t *update_idx)
@ -447,15 +446,13 @@ bool WFObj::loadfile(const char *path, Buffer & buff)
bool WFObj::buildVBO()
{
map<VertexRef, int> flat_vertices;
int vid = 0, texture_ref_count = 0;
int vid = 0, texture_ref_count = 0, n_vrefs = 0;
bool do_textures = m_loadtexture != NULL
&& m_vertices[VERTEX_TEXTURE].size() > 0;
for (map<string, vector<Face> >::iterator it = m_faces.begin();
it != m_faces.end();
it++)
{
int first = vid;
int num = 0;
for (vector<Face>::iterator fit = it->second.begin();
fit != it->second.end();
fit++)
@ -480,11 +477,10 @@ bool WFObj::buildVBO()
if (flat_vertices.find(vf) == flat_vertices.end())
{
flat_vertices[vf] = vid++;
num++;
}
n_vrefs++;
}
}
m_face_indices[it->first] = make_pair(first, num);
}
if (texture_ref_count == 0)
do_textures = false;
@ -512,12 +508,37 @@ bool WFObj::buildVBO()
data[base + 7] = m_vertices[VERTEX_TEXTURE][vr.texture - 1][1];
}
}
GLshort * indices = new GLshort[n_vrefs];
vid = 0;
for (map<string, vector<Face> >::iterator it = m_faces.begin();
it != m_faces.end();
it++)
{
int first = vid;
int num = 0;
for (vector<Face>::iterator fit = it->second.begin();
fit != it->second.end();
fit++)
{
for (int i = 0; i < 3; i++)
{
VertexRef vf = fit->vertices[i];
indices[vid] = flat_vertices[vf];
num++;
vid++;
}
}
m_face_indices[it->first] = make_pair(first, num);
}
glGenBuffers(1, &m_data_vbo);
glGenBuffers(1, &m_index_vbo);
/* move data from client side to GL */
glBufferData(m_data_vbo, sizeof(GLfloat) * n_data_elements, data,
GL_STATIC_DRAW);
glBufferData(m_index_vbo, sizeof(GLshort) * n_vrefs, indices,
GL_STATIC_DRAW);
delete[] data;
delete[] indices;
return true;
}