Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func void sorted_pass(s_m4 projection)
- {
- m_timed_function();
- qsort(rendering->sorted_elements.elements, rendering->sorted_elements.count, sizeof(*rendering->sorted_elements.elements), qsort_sorted_elements);
- u32 last_vao = c_max_u32;
- int last_shader = -1;
- int last_texture = -1;
- for(int i = 0; i < rendering->sorted_elements.count; i++)
- {
- s_sorted_element* element = arr_get(&rendering->sorted_elements, i);
- s_mesh* mesh = &rendering->meshes[element->mesh];
- if(at_least(1, element->instances) > mesh->data_vbo.max_elements)
- {
- mesh->data_vbo.set_max_elements(at_least(1, element->instances));
- last_vao = mesh->vao;
- }
- else if(last_vao != mesh->vao)
- {
- last_vao = mesh->vao;
- glBindVertexArray(mesh->vao);
- mesh->data_vbo.bind();
- }
- if(last_shader != element->shader)
- {
- last_shader = element->shader;
- rendering->shaders[element->shader].use();
- rendering->shaders[element->shader].set_matrix("projection", projection);
- if(g_shader_data[element->shader].noise64_index >= 0)
- {
- assert(g_shader_data[element->shader].noise64_index < 4);
- glActiveTexture(GL_TEXTURE0 + g_shader_data[element->shader].noise64_index);
- glBindTexture(GL_TEXTURE_2D, rendering->textures[e_texture_noise64].id);
- }
- else if(g_shader_data[element->shader].noise256_index >= 0)
- {
- assert(g_shader_data[element->shader].noise256_index < 4);
- glActiveTexture(GL_TEXTURE0 + g_shader_data[element->shader].noise256_index);
- glBindTexture(GL_TEXTURE_2D, rendering->textures[e_texture_noise256].id);
- }
- if(g_shader_data[element->shader].send_time)
- {
- rendering->shaders[element->shader].set_float("time", total_time);
- }
- else if(g_shader_data[element->shader].send_real_time)
- {
- rendering->shaders[element->shader].set_float("time", real_total_time);
- }
- }
- if(last_texture != element->texture)
- {
- last_texture = element->texture;
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, rendering->textures[element->texture].id);
- }
- glBufferSubData(
- GL_ARRAY_BUFFER,
- 0,
- mesh->data_vbo.stride * at_least(1, element->instances),
- (float*)element->data
- );
- if(element->clip_rect.w > 0)
- {
- glEnable(GL_SCISSOR_TEST);
- float y = c_world_size.y - (element->clip_rect.y + element->clip_rect.h);
- glScissor((int)element->clip_rect.x, (int)y, (int)element->clip_rect.w, (int)element->clip_rect.h);
- }
- if(element->instances > 1)
- {
- glDrawArraysInstanced(mesh->draw_type, 0, mesh->vertices_count, element->instances);
- }
- else
- {
- glDrawArrays(mesh->draw_type, 0, mesh->vertices_count);
- }
- if(element->clip_rect.w > 0)
- {
- glDisable(GL_SCISSOR_TEST);
- }
- }
- rendering->sorted_elements.count = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement