Use buffer objects for iqm vertex arrays and elements.

This commit is contained in:
Bill Currie 2012-05-15 08:22:31 +09:00
parent 5740dba467
commit 111377f1be
4 changed files with 40 additions and 2 deletions

View file

@ -126,8 +126,10 @@ typedef struct {
char *text;
int num_meshes;
iqmmesh *meshes;
int num_verts;
byte *vertices;
int stride;
int num_elements;
uint16_t *elements;
int num_arrays;
iqmvertexarray *vertexarrays;

View file

@ -72,19 +72,26 @@ glsl_iqm_clear (model_t *mod)
{
iqm_t *iqm = (iqm_t *) mod->aliashdr;
glsliqm_t *glsl = (glsliqm_t *) iqm->extra_data;
GLuint bufs[2];
int i;
mod->needload = true;
bufs[0] = glsl->vertex_array;
bufs[1] = glsl->element_array;
qfeglDeleteBuffers (2, bufs);
for (i = 0; i < iqm->num_meshes; i++) {
GLSL_ReleaseTexture (glsl->textures[i]);
GLSL_ReleaseTexture (glsl->normmaps[i]);
}
free (glsl);
free (iqm->text);
free (iqm->vertices);
if (iqm->vertices)
free (iqm->vertices);
free (iqm->vertexarrays);
free (iqm->elements);
if (iqm->elements)
free (iqm->elements);
free (iqm->meshes);
free (iqm->joints);
free (iqm->baseframe);
@ -122,6 +129,30 @@ glsl_iqm_load_textures (iqm_t *iqm)
dstring_delete (str);
}
static void
glsl_iqm_load_arrays (iqm_t *iqm)
{
glsliqm_t *glsl = (glsliqm_t *) iqm->extra_data;
GLuint bufs[2];
qfeglGenBuffers (2, bufs);
glsl->vertex_array = bufs[0];
glsl->element_array = bufs[1];
qfeglBindBuffer (GL_ARRAY_BUFFER, glsl->vertex_array);
qfeglBindBuffer (GL_ELEMENT_ARRAY_BUFFER, glsl->element_array);
qfeglBufferData (GL_ARRAY_BUFFER, iqm->num_verts * iqm->stride,
iqm->vertices, GL_STATIC_DRAW);
qfeglBufferData (GL_ELEMENT_ARRAY_BUFFER,
iqm->num_elements * sizeof (uint16_t), iqm->elements,
GL_STATIC_DRAW);
qfeglBindBuffer (GL_ARRAY_BUFFER, 0);
qfeglBindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0);
free (iqm->vertices);
iqm->vertices = 0;
free (iqm->elements);
iqm->elements = 0;
}
void
glsl_Mod_IQMFinish (model_t *mod)
{
@ -129,4 +160,5 @@ glsl_Mod_IQMFinish (model_t *mod)
mod->clear = glsl_iqm_clear;
iqm->extra_data = calloc (1, sizeof (glsliqm_t));
glsl_iqm_load_textures (iqm);
glsl_iqm_load_arrays (iqm);
}

View file

@ -294,6 +294,7 @@ load_iqm_vertex_arrays (model_t *mod, const iqmheader *hdr, byte *buffer)
}
iqm->vertexarrays = realloc (iqm->vertexarrays,
iqm->num_arrays * sizeof (iqmvertexarray));
iqm->num_verts = hdr->num_vertexes;
iqm->vertices = malloc (hdr->num_vertexes * bytes);
iqm->stride = bytes;
for (i = 0; i < hdr->num_vertexes; i++) {
@ -344,6 +345,7 @@ load_iqm_meshes (model_t *mod, const iqmheader *hdr, byte *buffer)
return false;
if (!(tris = get_triangles (hdr, buffer)))
return false;
iqm->num_elements = hdr->num_triangles * 3;
iqm->elements = malloc (hdr->num_triangles * 3 * sizeof (uint16_t));
for (i = 0; i < hdr->num_triangles; i++)
VectorCopy (tris[i].vertex, iqm->elements + i * 3);

View file

@ -248,6 +248,8 @@ glsl_R_DrawIQM (void)
qfeglUniform4fv (l->position.location, 1, quat_origin);
qfeglUniform4fv (l->color.location, 1, quat_origin);
}
qfeglBindBuffer (GL_ARRAY_BUFFER, glsl->vertex_array);
qfeglBindBuffer (GL_ELEMENT_ARRAY_BUFFER, glsl->element_array);
qfeglUniformMatrix4fv (iqm_shader.mvp_matrix.location, 1, false, mvp_mat);
qfeglUniformMatrix3fv (iqm_shader.norm_matrix.location, 1, false,