| 274 | } |
| 275 | |
| 276 | static void WriteLightInstanceData(HRenderContext render_context) |
| 277 | { |
| 278 | // The light count has changed, we need to write that separately |
| 279 | if (render_context->m_LightBufferDirtyCount) |
| 280 | { |
| 281 | // ... but only if it is actually different from last write. |
| 282 | float count = (float) render_context->m_RenderLightsIndices.Size(); |
| 283 | if (count != render_context->m_LightBufferLastWrittenCount) |
| 284 | { |
| 285 | dmGraphics::SetUniformBuffer(render_context->m_GraphicsContext, render_context->m_LightUniformBuffer, 0, sizeof(float), &count); |
| 286 | } |
| 287 | render_context->m_LightBufferLastWrittenCount = count; |
| 288 | } |
| 289 | |
| 290 | // Write the light data from the scratch buffer |
| 291 | if (render_context->m_LightBufferDirtyEnd > render_context->m_LightBufferDirtyStart) |
| 292 | { |
| 293 | // Convert indices to byte offsets |
| 294 | uint32_t write_light_data_start = render_context->m_LightBufferDataWriteStart; |
| 295 | uint32_t write_start = write_light_data_start + render_context->m_LightBufferDirtyStart * sizeof(LightSTD140); |
| 296 | uint32_t write_end = write_light_data_start + render_context->m_LightBufferDirtyEnd * sizeof(LightSTD140); |
| 297 | uint32_t write_size = write_end - write_start; |
| 298 | LightSTD140* write_ptr_start = &render_context->m_LightBufferScratch[render_context->m_LightBufferDirtyStart]; |
| 299 | |
| 300 | dmGraphics::SetUniformBuffer(render_context->m_GraphicsContext, render_context->m_LightUniformBuffer, write_start, write_size, (void*) write_ptr_start); |
| 301 | } |
| 302 | |
| 303 | // Reset all dirty flags |
| 304 | render_context->m_LightBufferDirtyStart = render_context->m_LightBufferScratch.Size(); |
| 305 | render_context->m_LightBufferDirtyEnd = 0; |
| 306 | render_context->m_LightBufferDirtyCount = 0; |
| 307 | } |
| 308 | |
| 309 | static inline bool IsLightBufferDirty(HRenderContext render_context) |
| 310 | { |
no test coverage detected