@@ -193,51 +193,40 @@ namespace OpenGL
193
193
194
194
void PhongRenderer::update_light_data (System::Scene& p_scene)
195
195
{
196
+ // TODO: Seperate the light storage blocks into meta data and data, so we can push the entire light data in one go per instance.
197
+
196
198
{ // Set DirectonalLight buffer data
197
199
GLuint directional_light_count = static_cast <GLuint>(p_scene.m_entities .count_components <Component::DirectionalLight>());
198
- {
199
- const GLsizeiptr required_size = m_directional_light_fixed_size + (m_directional_light_array_stride * directional_light_count);
200
- { // Resize the buffer to accomodate at least the directional_light_count
201
- if (required_size > m_directional_lights_buffer.size ())
202
- {
203
- OpenGL::Buffer new_buffer{{OpenGL::BufferStorageFlag::DynamicStorageBit}};
204
- new_buffer.resize (required_size);
205
- m_directional_lights_buffer = std::move (new_buffer);
206
- LOG (" [OPENGL][PHONG] DirectionalLight count changed ({}), resized the directional light buffer to {}B" , directional_light_count, required_size);
207
- }
208
- }
209
- m_directional_lights_buffer.buffer_sub_data (m_directional_light_count_offset, directional_light_count);
210
200
211
- GLuint i = 0 ;
212
- p_scene.m_entities .foreach ([&](Component::DirectionalLight& p_directional_light)
213
- {
214
- const glm::vec3 diffuse = p_directional_light.m_colour * p_directional_light.m_diffuse_intensity ;
215
- const glm::vec3 ambient = p_directional_light.m_colour * p_directional_light.m_ambient_intensity ;
216
- const glm::vec3 specular = glm::vec3 (p_directional_light.m_specular_intensity );
201
+ const GLsizeiptr required_capacity = m_directional_light_fixed_size + (m_directional_light_array_stride * directional_light_count);
202
+ if (required_capacity > m_directional_lights_buffer.capacity ())
203
+ m_directional_lights_buffer.reserve (required_capacity);
217
204
218
- m_directional_lights_buffer.buffer_sub_data (m_directional_light_direction_offset + (m_directional_light_array_stride * i), p_directional_light.m_direction );
219
- m_directional_lights_buffer.buffer_sub_data (m_directional_light_ambient_offset + (m_directional_light_array_stride * i), ambient);
220
- m_directional_lights_buffer.buffer_sub_data (m_directional_light_diffuse_offset + (m_directional_light_array_stride * i), diffuse);
221
- m_directional_lights_buffer.buffer_sub_data (m_directional_light_specular_offset + (m_directional_light_array_stride * i), specular);
205
+ m_directional_lights_buffer.set_data (directional_light_count, m_directional_light_count_offset);
222
206
223
- i++;
224
- });
225
- }
207
+ GLuint i = 0 ;
208
+ p_scene.m_entities .foreach ([&](Component::DirectionalLight& p_directional_light)
209
+ {
210
+ const glm::vec3 diffuse = p_directional_light.m_colour * p_directional_light.m_diffuse_intensity ;
211
+ const glm::vec3 ambient = p_directional_light.m_colour * p_directional_light.m_ambient_intensity ;
212
+ const glm::vec3 specular = glm::vec3 (p_directional_light.m_specular_intensity );
213
+
214
+ m_directional_lights_buffer.set_data (p_directional_light.m_direction , m_directional_light_direction_offset + (m_directional_light_array_stride * i));
215
+ m_directional_lights_buffer.set_data (ambient, m_directional_light_ambient_offset + (m_directional_light_array_stride * i));
216
+ m_directional_lights_buffer.set_data (diffuse, m_directional_light_diffuse_offset + (m_directional_light_array_stride * i));
217
+ m_directional_lights_buffer.set_data (specular, m_directional_light_specular_offset + (m_directional_light_array_stride * i));
218
+
219
+ i++;
220
+ });
226
221
}
227
222
{ // Set PointLight buffer data
228
223
GLuint point_light_count = static_cast <GLuint>(p_scene.m_entities .count_components <Component::PointLight>());
229
224
{
230
- const GLsizeiptr required_size = m_point_light_fixed_size + (m_point_light_array_stride * point_light_count);
231
- { // Resize the buffer to accomodate at least the point_light_count
232
- if (required_size > m_point_lights_buffer.size ())
233
- {
234
- OpenGL::Buffer new_buffer{{OpenGL::BufferStorageFlag::DynamicStorageBit}};
235
- new_buffer.resize (required_size);
236
- m_point_lights_buffer = std::move (new_buffer);
237
- LOG (" [OPENGL][PHONG] PointLight count changed ({}), resized the point light buffer to {}B" , point_light_count, required_size);
238
- }
239
- }
240
- m_point_lights_buffer.buffer_sub_data (m_point_light_count_offset, point_light_count);
225
+ const GLsizeiptr required_capacity = m_point_light_fixed_size + (m_point_light_array_stride * point_light_count);
226
+ if (required_capacity > m_point_lights_buffer.capacity ())
227
+ m_point_lights_buffer.reserve (required_capacity);
228
+
229
+ m_point_lights_buffer.set_data (point_light_count, m_point_light_count_offset);
241
230
242
231
GLuint i = 0 ;
243
232
p_scene.m_entities .foreach ([&](Component::PointLight& p_point_light)
@@ -246,13 +235,13 @@ namespace OpenGL
246
235
const glm::vec3 ambient = p_point_light.m_colour * p_point_light.m_ambient_intensity ;
247
236
const glm::vec3 specular = glm::vec3 (p_point_light.m_specular_intensity );
248
237
249
- m_point_lights_buffer.buffer_sub_data ( m_point_light_position_offset + (m_point_light_array_stride * i), p_point_light. m_position );
250
- m_point_lights_buffer.buffer_sub_data ( m_point_light_constant_offset + (m_point_light_array_stride * i), p_point_light. m_constant );
251
- m_point_lights_buffer.buffer_sub_data ( m_point_light_linear_offset + (m_point_light_array_stride * i), p_point_light. m_linear );
252
- m_point_lights_buffer.buffer_sub_data ( m_point_light_quadratic_offset + (m_point_light_array_stride * i), p_point_light. m_quadratic );
253
- m_point_lights_buffer.buffer_sub_data ( m_point_light_ambient_offset + (m_point_light_array_stride * i), ambient );
254
- m_point_lights_buffer.buffer_sub_data ( m_point_light_diffuse_offset + (m_point_light_array_stride * i), diffuse );
255
- m_point_lights_buffer.buffer_sub_data ( m_point_light_specular_offset + (m_point_light_array_stride * i), specular );
238
+ m_point_lights_buffer.set_data (p_point_light. m_position , m_point_light_position_offset + (m_point_light_array_stride * i));
239
+ m_point_lights_buffer.set_data (p_point_light. m_constant , m_point_light_constant_offset + (m_point_light_array_stride * i));
240
+ m_point_lights_buffer.set_data (p_point_light. m_linear , m_point_light_linear_offset + (m_point_light_array_stride * i));
241
+ m_point_lights_buffer.set_data (p_point_light. m_quadratic , m_point_light_quadratic_offset + (m_point_light_array_stride * i));
242
+ m_point_lights_buffer.set_data (ambient, m_point_light_ambient_offset + (m_point_light_array_stride * i));
243
+ m_point_lights_buffer.set_data (diffuse, m_point_light_diffuse_offset + (m_point_light_array_stride * i));
244
+ m_point_lights_buffer.set_data (specular, m_point_light_specular_offset + (m_point_light_array_stride * i));
256
245
257
246
i++;
258
247
});
@@ -261,18 +250,11 @@ namespace OpenGL
261
250
{ // Set Spotlight buffer data
262
251
GLuint spot_light_count = static_cast <GLuint>(p_scene.m_entities .count_components <Component::SpotLight>());
263
252
{
264
- const GLsizeiptr required_size = m_spot_light_fixed_size + (m_spot_light_array_stride * spot_light_count);
265
- { // Resize the buffer to accomodate at least the spot_light_count
266
- if (required_size > m_spot_lights_buffer.size ())
267
- {
268
- OpenGL::Buffer new_buffer{{OpenGL::BufferStorageFlag::DynamicStorageBit}};
269
- new_buffer.resize (required_size);
270
- m_spot_lights_buffer = std::move (new_buffer);
271
- LOG (" [OPENGL][PHONG] SpotLight count changed ({}), resized the spot light buffer to {}B" , spot_light_count, required_size);
272
- }
273
- }
274
-
275
- m_spot_lights_buffer.buffer_sub_data (m_spot_light_count_offset, spot_light_count);
253
+ const GLsizeiptr required_capacity = m_spot_light_fixed_size + (m_spot_light_array_stride * spot_light_count);
254
+ if (required_capacity > m_spot_lights_buffer.capacity ())
255
+ m_spot_lights_buffer.reserve (required_capacity);
256
+
257
+ m_spot_lights_buffer.set_data (spot_light_count, m_spot_light_count_offset);
276
258
277
259
GLuint i = 0 ;
278
260
p_scene.m_entities .foreach ([&](Component::SpotLight& p_spotlight)
@@ -281,16 +263,16 @@ namespace OpenGL
281
263
const glm::vec3 ambient = p_spotlight.m_colour * p_spotlight.m_ambient_intensity ;
282
264
const glm::vec3 specular = glm::vec3 (p_spotlight.m_specular_intensity );
283
265
284
- m_spot_lights_buffer.buffer_sub_data ( m_spot_light_position_offset + (m_spot_light_array_stride * i), p_spotlight. m_position );
285
- m_spot_lights_buffer.buffer_sub_data ( m_spot_light_direction_offset + (m_spot_light_array_stride * i), p_spotlight. m_direction );
286
- m_spot_lights_buffer.buffer_sub_data ( m_spot_light_cutoff_offset + (m_spot_light_array_stride * i), p_spotlight. m_cutoff );
287
- m_spot_lights_buffer.buffer_sub_data ( m_spot_light_outer_cutoff_offset + (m_spot_light_array_stride * i), p_spotlight. m_outer_cutoff );
288
- m_spot_lights_buffer.buffer_sub_data ( m_spot_light_constant_offset + (m_spot_light_array_stride * i), p_spotlight. m_constant );
289
- m_spot_lights_buffer.buffer_sub_data ( m_spot_light_linear_offset + (m_spot_light_array_stride * i), p_spotlight. m_linear );
290
- m_spot_lights_buffer.buffer_sub_data ( m_spot_light_quadratic_offset + (m_spot_light_array_stride * i), p_spotlight. m_quadratic );
291
- m_spot_lights_buffer.buffer_sub_data ( m_spot_light_ambient_offset + (m_spot_light_array_stride * i), ambient );
292
- m_spot_lights_buffer.buffer_sub_data ( m_spot_light_diffuse_offset + (m_spot_light_array_stride * i), diffuse );
293
- m_spot_lights_buffer.buffer_sub_data ( m_spot_light_specular_offset + (m_spot_light_array_stride * i), specular );
266
+ m_spot_lights_buffer.set_data (p_spotlight. m_position , m_spot_light_position_offset + (m_spot_light_array_stride * i));
267
+ m_spot_lights_buffer.set_data (p_spotlight. m_direction , m_spot_light_direction_offset + (m_spot_light_array_stride * i));
268
+ m_spot_lights_buffer.set_data (p_spotlight. m_cutoff , m_spot_light_cutoff_offset + (m_spot_light_array_stride * i));
269
+ m_spot_lights_buffer.set_data (p_spotlight. m_outer_cutoff , m_spot_light_outer_cutoff_offset + (m_spot_light_array_stride * i));
270
+ m_spot_lights_buffer.set_data (p_spotlight. m_constant , m_spot_light_constant_offset + (m_spot_light_array_stride * i));
271
+ m_spot_lights_buffer.set_data (p_spotlight. m_linear , m_spot_light_linear_offset + (m_spot_light_array_stride * i));
272
+ m_spot_lights_buffer.set_data (p_spotlight. m_quadratic , m_spot_light_quadratic_offset + (m_spot_light_array_stride * i));
273
+ m_spot_lights_buffer.set_data (ambient, m_spot_light_ambient_offset + (m_spot_light_array_stride * i));
274
+ m_spot_lights_buffer.set_data (diffuse, m_spot_light_diffuse_offset + (m_spot_light_array_stride * i));
275
+ m_spot_lights_buffer.set_data (specular, m_spot_light_specular_offset + (m_spot_light_array_stride * i));
294
276
i++;
295
277
});
296
278
}
0 commit comments