Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize particles instance buffer in case it is used before being updated #78852

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions drivers/gles3/storage/particles_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,12 +820,11 @@ void ParticlesStorage::_particles_update_buffers(Particles *particles) {
particles->num_attrib_arrays_cache = 5 + userdata_count + (xform_size - 2);
particles->process_buffer_stride_cache = sizeof(float) * 4 * particles->num_attrib_arrays_cache;

int process_data_amount = 4 * particles->num_attrib_arrays_cache * total_amount;
float *data = memnew_arr(float, process_data_amount);
PackedByteArray data;
data.resize_zeroed(particles->process_buffer_stride_cache * total_amount);

for (int i = 0; i < process_data_amount; i++) {
data[i] = 0;
}
PackedByteArray instance_data;
instance_data.resize_zeroed(particles->instance_buffer_size_cache);

{
glGenVertexArrays(1, &particles->front_vertex_array);
Expand All @@ -834,7 +833,7 @@ void ParticlesStorage::_particles_update_buffers(Particles *particles) {
glGenBuffers(1, &particles->front_instance_buffer);

glBindBuffer(GL_ARRAY_BUFFER, particles->front_process_buffer);
GLES3::Utilities::get_singleton()->buffer_allocate_data(GL_ARRAY_BUFFER, particles->front_process_buffer, particles->process_buffer_stride_cache * total_amount, data, GL_DYNAMIC_COPY, "Particles front process buffer");
GLES3::Utilities::get_singleton()->buffer_allocate_data(GL_ARRAY_BUFFER, particles->front_process_buffer, particles->process_buffer_stride_cache * total_amount, data.ptr(), GL_DYNAMIC_COPY, "Particles front process buffer");

for (uint32_t j = 0; j < particles->num_attrib_arrays_cache; j++) {
glEnableVertexAttribArray(j);
Expand All @@ -843,7 +842,7 @@ void ParticlesStorage::_particles_update_buffers(Particles *particles) {
glBindVertexArray(0);

glBindBuffer(GL_ARRAY_BUFFER, particles->front_instance_buffer);
GLES3::Utilities::get_singleton()->buffer_allocate_data(GL_ARRAY_BUFFER, particles->front_instance_buffer, particles->instance_buffer_size_cache, nullptr, GL_DYNAMIC_COPY, "Particles front instance buffer");
GLES3::Utilities::get_singleton()->buffer_allocate_data(GL_ARRAY_BUFFER, particles->front_instance_buffer, particles->instance_buffer_size_cache, instance_data.ptr(), GL_DYNAMIC_COPY, "Particles front instance buffer");
}

{
Expand All @@ -853,7 +852,7 @@ void ParticlesStorage::_particles_update_buffers(Particles *particles) {
glGenBuffers(1, &particles->back_instance_buffer);

glBindBuffer(GL_ARRAY_BUFFER, particles->back_process_buffer);
GLES3::Utilities::get_singleton()->buffer_allocate_data(GL_ARRAY_BUFFER, particles->back_process_buffer, particles->process_buffer_stride_cache * total_amount, data, GL_DYNAMIC_COPY, "Particles back process buffer");
GLES3::Utilities::get_singleton()->buffer_allocate_data(GL_ARRAY_BUFFER, particles->back_process_buffer, particles->process_buffer_stride_cache * total_amount, data.ptr(), GL_DYNAMIC_COPY, "Particles back process buffer");

for (uint32_t j = 0; j < particles->num_attrib_arrays_cache; j++) {
glEnableVertexAttribArray(j);
Expand All @@ -862,11 +861,9 @@ void ParticlesStorage::_particles_update_buffers(Particles *particles) {
glBindVertexArray(0);

glBindBuffer(GL_ARRAY_BUFFER, particles->back_instance_buffer);
GLES3::Utilities::get_singleton()->buffer_allocate_data(GL_ARRAY_BUFFER, particles->back_instance_buffer, particles->instance_buffer_size_cache, nullptr, GL_DYNAMIC_COPY, "Particles back instance buffer");
GLES3::Utilities::get_singleton()->buffer_allocate_data(GL_ARRAY_BUFFER, particles->back_instance_buffer, particles->instance_buffer_size_cache, instance_data.ptr(), GL_DYNAMIC_COPY, "Particles back instance buffer");
}
glBindBuffer(GL_ARRAY_BUFFER, 0);

memdelete_arr(data);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,10 @@ void ParticlesStorage::_particles_update_buffers(Particles *particles) {

particles->userdata_count = userdata_count;

particles->particle_instance_buffer = RD::get_singleton()->storage_buffer_create(sizeof(float) * 4 * (xform_size + 1 + 1) * total_amount);
PackedByteArray data;
data.resize_zeroed(sizeof(float) * 4 * (xform_size + 1 + 1) * total_amount);

particles->particle_instance_buffer = RD::get_singleton()->storage_buffer_create(sizeof(float) * 4 * (xform_size + 1 + 1) * total_amount, data);
//needs to clear it

{
Expand Down