edit fixed the unrolled loop for drawing 16,000 sprites in one draw call.
void variable_render(double alpha) {
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
cg_sprite_back_2_front_tex_id(sprites, sc);
//this code path performs terribly
//cg_spritebatch_begin(sb, ce_get_default_camera());
//for (int i = 0; i < sc; i++) {
// cg_spritebatch_draw(sb, sprites[i]);
//}
//cg_spritebatch_end(sb);
//doing this everythingidx is= fine0;
for (int i = 0; i < sc; i++) {
//--------------- start update vertex data ---------------------
sp = sprites[i];
/* printf("%d %d\n",sp->texture_id, sp->z_index); */
vmathT3MakeIdentity(&rot);
vmathT3MakeIdentity(&scal);
vmathT3MakeIdentity(&trns);
vmathT3MakeIdentity(&tmp);
vmathT3MakeScale(&scal, &sp->scale);
vmathT3MakeRotationZYX(&rot, &sp->angl);
vmathT3MakeTranslation(&trns, &sp->pos);
vmathT3Mul(&tmp, &trns, &scal); // scale then trnslate
vmathT3Mul(&tmp, &tmp, &rot); // scale then translate then rotate
vmathM4MakeFromT3(&sprites[i]->m_mat, &tmp);
cg_quad_getquadverts(&sp->iv0, &sp->iv1, &sp->iv2, &sp->iv3, sp->quad);
vmathM4MulV4(&sp->ov0, &sp->m_mat, &sp->iv0);
vmathM4MulV4(&sp->ov1, &sp->m_mat, &sp->iv1);
vmathM4MulV4(&sp->ov2, &sp->m_mat, &sp->iv2);
vmathM4MulV4(&sp->ov3, &sp->m_mat, &sp->iv3);
}
/* --------------- finish update vertex data --------------------- */
/* --------------- start packing data into buffers--------------------- */
for (int i = 0; i < sc; i++) {
/* sp = sprites[i];
idx = 0;*/
// v0
v_buff[idx++] = sp->ov0.x;
v_buff[idx++] = sp->ov0.y;
v_buff[idx++] = sp->ov0.z;
v_buff[idx++] = sp->quad->colors[0];
v_buff[idx++] = sp->quad->colors[1];
v_buff[idx++] = sp->quad->colors[2];
v_buff[idx++] = sp->quad->colors[3];
v_buff[idx++] = sp->quad->tex_coords[0];
v_buff[idx++] = sp->quad->tex_coords[1];
// v1
v_buff[idx++] = sp->ov1.x;
v_buff[idx++] = sp->ov1.y;
v_buff[idx++] = sp->ov1.z;
v_buff[idx++] = sp->quad->colors[4];
v_buff[idx++] = sp->quad->colors[5];
v_buff[idx++] = sp->quad->colors[6];
v_buff[idx++] = sp->quad->colors[7];
v_buff[idx++] = sp->quad->tex_coords[2];
v_buff[idx++] = sp->quad->tex_coords[3];
// v2
v_buff[idx++] = sp->ov2.x;
v_buff[idx++] = sp->ov2.y;
v_buff[idx++] = sp->ov2.z;
v_buff[idx++] = sp->quad->colors[8];
v_buff[idx++] = sp->quad->colors[9];
v_buff[idx++] = sp->quad->colors[10];
v_buff[idx++] = sp->quad->colors[11];
v_buff[idx++] = sp->quad->tex_coords[4];
v_buff[idx++] = sp->quad->tex_coords[5];
// v3
v_buff[idx++] = sp->ov3.x;
v_buff[idx++] = sp->ov3.y;
v_buff[idx++] = sp->ov3.z;
v_buff[idx++] = sp->quad->colors[12];
v_buff[idx++] = sp->quad->colors[13];
v_buff[idx++] = sp->quad->colors[14];
v_buff[idx++] = sp->quad->colors[15];
v_buff[idx++] = sp->quad->tex_coords[6];
v_buff[idx++] = sp->quad->tex_coords[7];
/* printf("my idx:%d\n",idx*sc); */
}
/* //--------------- finish packing data into
* buffers- -------------------- */
glUseProgram(ce_get_default_shader()->shader_program);
glBindVertexArray(vao);
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);
glUniform1i(tex_loc, 0);
glBindTexture(GL_TEXTURE_2D, sp->texture_id);
cg_cam_get_matrices(&v_mat, &p_mat, &mvp_mat, ce_get_default_camera());
// projection * view * model * vertex_pos;
glUniformMatrix4fv(model_mat_loc, 1, GL_FALSE,
vmathM4GetData(&sp->m_mat));
glUniformMatrix4fv(view_mat_loc, 1, GL_FALSE, vmathM4GetData(v_mat));
glUniformMatrix4fv(proj_mat_loc, 1, GL_FALSE, vmathM4GetData(p_mat));
glUniformMatrix4fv(mvp_matrix_loc, 1, GL_FALSE,
vmathM4GetData(mvp_mat));
glBindBuffer(GL_ARRAY_BUFFER, vert_buff);
glBufferData(GL_ARRAY_BUFFER, (vbo_size_in_bytes), v_buff,
GL_STREAM_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ind_buff);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sc * cg_sprite_get_sizeof_ind(),
i_buff, GL_STREAM_DRAW);
glDrawElements(GL_TRIANGLES, sc * cg_sprite_get_vert_count(),
GL_UNSIGNED_SHORT, 0);
glBindVertexArray(0);
debug_opengl("render loop");
}
}
ok the above code on my machine can render 16000 sprites in 1 draw call but of course they all need to use the same texture.
I have 4 total textures which should be able to draw the 16000 sprites with their own unique texture instead of being forced to use only one like I am doing right now.

