Advertisement
Tkap1

Untitled

Dec 9th, 2023
768
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv     particle compute shader start       vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  2. {
  3.     u32 curr_index = rendering->curr_particle_ssbo_index;
  4.     u32 next_index = (rendering->curr_particle_ssbo_index + 1) % 2;
  5.  
  6.     glBindVertexArray(rendering->particle_vao);
  7.     glUseProgram(rendering->compute_shaders[e_compute_particle]);
  8.     set_shader_float(rendering->compute_shaders[e_compute_particle], "delta", render_delta);
  9.  
  10.     // @Note(tkap, 04/12/2023): Copy the CPU particle data in the ssbo
  11.     glBindBuffer(GL_SHADER_STORAGE_BUFFER, rendering->new_particles_ssbo);
  12.     glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, 4, &game->world_particles.count);
  13.     glBufferSubData(GL_SHADER_STORAGE_BUFFER, 16, sizeof(s_particle) * game->world_particles.count, game->world_particles.elements);
  14.  
  15.     // @Note(tkap, 04/12/2023): Set the ssbo particle count to 0
  16.     glBindBuffer(GL_SHADER_STORAGE_BUFFER, rendering->particles_indirect_ssbo);
  17.     int one_zero = 0;
  18.     glBufferSubData(GL_SHADER_STORAGE_BUFFER, 4, 4, &one_zero);
  19.     glBindBuffer(GL_SHADER_STORAGE_BUFFER, rendering->particle_in_ssbo[next_index]);
  20.     glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, 4, &one_zero);
  21.  
  22.     static_assert(max_world_particles % 64 == 0);
  23.     glDispatchCompute(max_world_particles / 64, 1, 1);
  24.  
  25.     game->world_particles.count = 0;
  26.  
  27.     rendering->curr_particle_ssbo_index = next_index;
  28.     glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, rendering->particle_in_ssbo[curr_index]);
  29.     glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, rendering->particle_in_ssbo[next_index]);
  30. }
  31. // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^     particle compute shader end     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  32.  
  33. // ...
  34. // ...
  35. // ...
  36.  
  37. // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv     draw gpu particles start        vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  38. {
  39.     rendering->shaders[e_shader_particle].use();
  40.     rendering->shaders[e_shader_particle].set_matrix("projection", get_camera_matrix(get_camera()));
  41.     glBindBuffer(GL_DRAW_INDIRECT_BUFFER, rendering->particles_indirect_ssbo);
  42.     glDrawArraysIndirect(GL_TRIANGLES, 0);
  43. }
  44. // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^     draw gpu particles end      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement