Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv particle compute shader start vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
- {
- u32 curr_index = rendering->curr_particle_ssbo_index;
- u32 next_index = (rendering->curr_particle_ssbo_index + 1) % 2;
- glBindVertexArray(rendering->particle_vao);
- glUseProgram(rendering->compute_shaders[e_compute_particle]);
- set_shader_float(rendering->compute_shaders[e_compute_particle], "delta", render_delta);
- // @Note(tkap, 04/12/2023): Copy the CPU particle data in the ssbo
- glBindBuffer(GL_SHADER_STORAGE_BUFFER, rendering->new_particles_ssbo);
- glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, 4, &game->world_particles.count);
- glBufferSubData(GL_SHADER_STORAGE_BUFFER, 16, sizeof(s_particle) * game->world_particles.count, game->world_particles.elements);
- // @Note(tkap, 04/12/2023): Set the ssbo particle count to 0
- glBindBuffer(GL_SHADER_STORAGE_BUFFER, rendering->particles_indirect_ssbo);
- int one_zero = 0;
- glBufferSubData(GL_SHADER_STORAGE_BUFFER, 4, 4, &one_zero);
- glBindBuffer(GL_SHADER_STORAGE_BUFFER, rendering->particle_in_ssbo[next_index]);
- glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, 4, &one_zero);
- static_assert(max_world_particles % 64 == 0);
- glDispatchCompute(max_world_particles / 64, 1, 1);
- game->world_particles.count = 0;
- rendering->curr_particle_ssbo_index = next_index;
- glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, rendering->particle_in_ssbo[curr_index]);
- glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, rendering->particle_in_ssbo[next_index]);
- }
- // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ particle compute shader end ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- // ...
- // ...
- // ...
- // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv draw gpu particles start vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
- {
- rendering->shaders[e_shader_particle].use();
- rendering->shaders[e_shader_particle].set_matrix("projection", get_camera_matrix(get_camera()));
- glBindBuffer(GL_DRAW_INDIRECT_BUFFER, rendering->particles_indirect_ssbo);
- glDrawArraysIndirect(GL_TRIANGLES, 0);
- }
- // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ draw gpu particles end ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement