mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-04-26 00:26:32 +00:00
[client] egl: use vertex array objects in model.c
This eliminates the need to bind the buffers and set up the vertices on every frame.
This commit is contained in:
parent
d4f8426ae4
commit
061b9ba6c2
@ -38,6 +38,7 @@ struct EGL_Model
|
|||||||
bool finish;
|
bool finish;
|
||||||
|
|
||||||
GLuint buffer;
|
GLuint buffer;
|
||||||
|
GLuint vao;
|
||||||
|
|
||||||
EGL_Shader * shader;
|
EGL_Shader * shader;
|
||||||
EGL_Texture * texture;
|
EGL_Texture * texture;
|
||||||
@ -85,6 +86,9 @@ void egl_model_free(EGL_Model ** model)
|
|||||||
if ((*model)->buffer)
|
if ((*model)->buffer)
|
||||||
glDeleteBuffers(1, &(*model)->buffer);
|
glDeleteBuffers(1, &(*model)->buffer);
|
||||||
|
|
||||||
|
if ((*model)->vao)
|
||||||
|
glDeleteVertexArrays(1, &(*model)->vao);
|
||||||
|
|
||||||
free(*model);
|
free(*model);
|
||||||
*model = NULL;
|
*model = NULL;
|
||||||
}
|
}
|
||||||
@ -139,6 +143,11 @@ void egl_model_render(EGL_Model * model)
|
|||||||
if (model->buffer)
|
if (model->buffer)
|
||||||
glDeleteBuffers(1, &model->buffer);
|
glDeleteBuffers(1, &model->buffer);
|
||||||
|
|
||||||
|
if (!model->vao)
|
||||||
|
glGenVertexArrays(1, &model->vao);
|
||||||
|
|
||||||
|
glBindVertexArray(model->vao);
|
||||||
|
|
||||||
/* create a buffer large enough */
|
/* create a buffer large enough */
|
||||||
glGenBuffers(1, &model->buffer);
|
glGenBuffers(1, &model->buffer);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, model->buffer);
|
glBindBuffer(GL_ARRAY_BUFFER, model->buffer);
|
||||||
@ -161,16 +170,18 @@ void egl_model_render(EGL_Model * model)
|
|||||||
offset += sizeof(GLfloat) * fl->count * 2;
|
offset += sizeof(GLfloat) * fl->count * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* set up vertex arrays in the VAO */
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glEnableVertexAttribArray(1);
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
|
||||||
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)(sizeof(GLfloat) * model->vertexCount * 3));
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindVertexArray(0);
|
||||||
model->rebuild = false;
|
model->rebuild = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* bind the model buffer and setup the pointers */
|
glBindVertexArray(model->vao);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, model->buffer);
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glEnableVertexAttribArray(1);
|
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
|
|
||||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)(sizeof(GLfloat) * model->vertexCount * 3));
|
|
||||||
|
|
||||||
if (model->shader)
|
if (model->shader)
|
||||||
egl_shader_use(model->shader);
|
egl_shader_use(model->shader);
|
||||||
@ -189,8 +200,7 @@ void egl_model_render(EGL_Model * model)
|
|||||||
|
|
||||||
/* unbind and cleanup */
|
/* unbind and cleanup */
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
glDisableVertexAttribArray(0);
|
glBindVertexArray(0);
|
||||||
glDisableVertexAttribArray(1);
|
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user