This might be a simple question but I am stuck.
I have this data structure
typedef struct quad_2d {
float angle_in_rad;
GLshort vertex_count;
GLfloat vertices[12];
GLfloat colors[16];
GLshort indices[6];
GLfloat tex_coords[8];
}sprite;
init code looks like this
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glGenBuffers(1, &vert_buff);
glBindBuffer(GL_ARRAY_BUFFER, vert_buff);
glBufferData(GL_ARRAY_BUFFER, sizeof(sprite->vertices),
sprite->vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat),
(GLvoid*)0);
glEnableVertexAttribArray(0);
glGenBuffers(1, &col_buff);
glBindBuffer(GL_ARRAY_BUFFER, col_buff);
glBufferData(GL_ARRAY_BUFFER, sizeof(sprite->colors),
sprite->colors, GL_STATIC_DRAW);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat),
(GLvoid*)0);
glEnableVertexAttribArray(1);
glGenBuffers(1, &tex_buff);
glBindBuffer(GL_ARRAY_BUFFER, tex_buff);
glBufferData(GL_ARRAY_BUFFER, sizeof(sprite->tex_coords),
sprite->tex_coords, GL_STATIC_DRAW);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat),
(GLvoid*)0);
glEnableVertexAttribArray(2);
glGenBuffers(1, &ind_buff);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ind_buff);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(sprite->indices),
sprite->indices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
render code looks like this
glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glClearDepth(1.0f);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex_id);
glUniform1i(tex_loc, 0);
glUseProgram(ce_get_default_shader()->shader_program);
glBindVertexArray(vao);
glBindTexture(GL_TEXTURE_2D, tex_id);
glUniform1i(tex_loc, 0);
mat4_multi(&mmvp_mat, &vview_mat, model_mat);
mat4_multi(&mmvp_mat, &pproj_mat, &mmvp_mat);
glUniformMatrix4fv(mvp_matrix_loc, 1, GL_FALSE, mmvp_mat->data);
glUniformMatrix4fv(model_mat_loc, 1, GL_FALSE, model_mat->data); //model matrix data that changes
glUniformMatrix4fv(view_mat_loc, 1, GL_FALSE, vview_mat->data);
glUniformMatrix4fv(proj_matrix_loc, 1, GL_FALSE, pproj_mat->data);
glDrawElements(GL_TRIANGLES, 6,
GL_UNSIGNED_SHORT, 0);
glBindVertexArray(vao);
this renders one sprite to the screen. Now I don’t need to update the vbo since all the sprites are the same, only thing that changes is the model matrix that renders their position on screen which I commented above.
Since the vbo doesn’t change at all how can I pack these into a bigger buffer to render say 10 in one draw call?
Anyone can help me solve this?