Advertisement
Tkap1

Untitled

Dec 16th, 2023
651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1. glUseProgram(rendering->compute_shaders[e_compute_particle]);
  2. for(int particle_type_i = 0; particle_type_i < e_particle_type_count; particle_type_i++) {
  3.     int* particle_count = particle_counts[particle_type_i];
  4.     u32 curr_index = rendering->curr_particle_ssbo_index[particle_type_i];
  5.     u32 next_index = (rendering->curr_particle_ssbo_index[particle_type_i] + 1) % 2;
  6.  
  7.     glBindVertexArray(rendering->particle_vao[particle_type_i]);
  8.  
  9.     glUniform1f(0, render_delta);
  10.     glUniform1f(1, multiplied_render_delta);
  11.     glUniformMatrix4fv(2, 1, GL_FALSE, &view_projection_arr[particle_type_i].all[0]);
  12.  
  13.     glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, rendering->particle_in_ssbo[particle_type_i][curr_index]);
  14.     glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, rendering->particle_in_ssbo[particle_type_i][next_index]);
  15.     glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, rendering->particle_draw_ssbo[particle_type_i]);
  16.     glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, rendering->new_particles_ssbo[particle_type_i]);
  17.     glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, rendering->particles_indirect_ssbo[particle_type_i]);
  18.  
  19.     // @Note(tkap, 04/12/2023): Copy the CPU particle data in the ssbo
  20.     glBindBuffer(GL_SHADER_STORAGE_BUFFER, rendering->new_particles_ssbo[particle_type_i]);
  21.     glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, 4, particle_count);
  22.     glBufferSubData(GL_SHADER_STORAGE_BUFFER, 16, sizeof(s_particle) * *particle_count, particle_data[particle_type_i]);
  23.  
  24.     // @Note(tkap, 04/12/2023): Set the ssbo particle count to 0
  25.     glBindBuffer(GL_SHADER_STORAGE_BUFFER, rendering->particles_indirect_ssbo[particle_type_i]);
  26.     int one_zero = 0;
  27.     glBufferSubData(GL_SHADER_STORAGE_BUFFER, 4, 4, &one_zero);
  28.     glBindBuffer(GL_SHADER_STORAGE_BUFFER, rendering->particle_in_ssbo[particle_type_i][next_index]);
  29.     glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, 4, &one_zero);
  30.  
  31.     // GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
  32.     // glClientWaitSync(sync, 0, c_max_u64);
  33.     // glDeleteSync(sync);
  34.     glDispatchCompute(c_max_particles / 64, 1, 1);
  35.     // glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL_SHADER_STORAGE_BARRIER_BIT | GL_BUFFER_UPDATE_BARRIER_BIT);
  36.     // glMemoryBarrier(GL_ALL_BARRIER_BITS);
  37.  
  38.     *particle_count = 0;
  39.     rendering->curr_particle_ssbo_index[particle_type_i] = next_index;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement