Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- glUseProgram(rendering->compute_shaders[e_compute_particle]);
- for(int particle_type_i = 0; particle_type_i < e_particle_type_count; particle_type_i++) {
- int* particle_count = particle_counts[particle_type_i];
- u32 curr_index = rendering->curr_particle_ssbo_index[particle_type_i];
- u32 next_index = (rendering->curr_particle_ssbo_index[particle_type_i] + 1) % 2;
- glBindVertexArray(rendering->particle_vao[particle_type_i]);
- glUniform1f(0, render_delta);
- glUniform1f(1, multiplied_render_delta);
- glUniformMatrix4fv(2, 1, GL_FALSE, &view_projection_arr[particle_type_i].all[0]);
- glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, rendering->particle_in_ssbo[particle_type_i][curr_index]);
- glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, rendering->particle_in_ssbo[particle_type_i][next_index]);
- glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, rendering->particle_draw_ssbo[particle_type_i]);
- glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, rendering->new_particles_ssbo[particle_type_i]);
- glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, rendering->particles_indirect_ssbo[particle_type_i]);
- // @Note(tkap, 04/12/2023): Copy the CPU particle data in the ssbo
- glBindBuffer(GL_SHADER_STORAGE_BUFFER, rendering->new_particles_ssbo[particle_type_i]);
- glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, 4, particle_count);
- glBufferSubData(GL_SHADER_STORAGE_BUFFER, 16, sizeof(s_particle) * *particle_count, particle_data[particle_type_i]);
- // @Note(tkap, 04/12/2023): Set the ssbo particle count to 0
- glBindBuffer(GL_SHADER_STORAGE_BUFFER, rendering->particles_indirect_ssbo[particle_type_i]);
- int one_zero = 0;
- glBufferSubData(GL_SHADER_STORAGE_BUFFER, 4, 4, &one_zero);
- glBindBuffer(GL_SHADER_STORAGE_BUFFER, rendering->particle_in_ssbo[particle_type_i][next_index]);
- glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, 4, &one_zero);
- // GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
- // glClientWaitSync(sync, 0, c_max_u64);
- // glDeleteSync(sync);
- glDispatchCompute(c_max_particles / 64, 1, 1);
- // glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL_SHADER_STORAGE_BARRIER_BIT | GL_BUFFER_UPDATE_BARRIER_BIT);
- // glMemoryBarrier(GL_ALL_BARRIER_BITS);
- *particle_count = 0;
- rendering->curr_particle_ssbo_index[particle_type_i] = next_index;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement