@@ -199,21 +199,40 @@ void PathOCLBaseOCLRenderThread::InitLights() {
199199 } else
200200 intersectionDevice->FreeBuffer (&envLightIndicesBuff);
201201
202- intersectionDevice->AllocBufferRO (&lightIndexOffsetByMeshIndexBuff, &cscene->lightIndexOffsetByMeshIndex [0 ],
203- sizeof (u_int) * cscene->lightIndexOffsetByMeshIndex .size (), " Light offsets (Part I)" );
204- intersectionDevice->AllocBufferRO (&lightIndexByTriIndexBuff, &cscene->lightIndexByTriIndex [0 ],
205- sizeof (u_int) * cscene->lightIndexByTriIndex .size (), " Light offsets (Part II)" );
202+ if (cscene->lightIndexOffsetByMeshIndex .size () > 0 ) {
203+ intersectionDevice->AllocBufferRO (&lightIndexOffsetByMeshIndexBuff, &cscene->lightIndexOffsetByMeshIndex [0 ],
204+ sizeof (u_int) * cscene->lightIndexOffsetByMeshIndex .size (), " Light offsets (Part I)" );
205+ } else {
206+ intersectionDevice->FreeBuffer (&lightIndexOffsetByMeshIndexBuff);
207+ }
208+ if (cscene->lightIndexByTriIndex .size () > 0 ) {
209+ intersectionDevice->AllocBufferRO (&lightIndexByTriIndexBuff, &cscene->lightIndexByTriIndex [0 ],
210+ sizeof (u_int) * cscene->lightIndexByTriIndex .size (), " Light offsets (Part II)" );
211+ } else {
212+ intersectionDevice->FreeBuffer (&lightIndexByTriIndexBuff);
213+ }
214+
206215
207216 if (cscene->envLightDistributions .size () > 0 ) {
208217 intersectionDevice->AllocBufferRO (&envLightDistributionsBuff, &cscene->envLightDistributions [0 ],
209218 sizeof (float ) * cscene->envLightDistributions .size (), " Env. light distributions" );
210219 } else
211220 intersectionDevice->FreeBuffer (&envLightDistributionsBuff);
212221
213- intersectionDevice->AllocBufferRO (&lightsDistributionBuff, cscene->lightsDistribution ,
214- cscene->lightsDistributionSize , " LightsDistribution" );
215- intersectionDevice->AllocBufferRO (&infiniteLightSourcesDistributionBuff, cscene->infiniteLightSourcesDistribution ,
216- cscene->infiniteLightSourcesDistributionSize , " InfiniteLightSourcesDistribution" );
222+ if (cscene->lightsDistributionSize > 0 ) {
223+ intersectionDevice->AllocBufferRO (&lightsDistributionBuff, cscene->lightsDistribution ,
224+ cscene->lightsDistributionSize , " LightsDistribution" );
225+ } else {
226+ intersectionDevice->FreeBuffer (&lightsDistributionBuff);
227+ }
228+
229+ if (cscene->infiniteLightSourcesDistributionSize > 0 ) {
230+ intersectionDevice->AllocBufferRO (&infiniteLightSourcesDistributionBuff, cscene->infiniteLightSourcesDistribution ,
231+ cscene->infiniteLightSourcesDistributionSize , " InfiniteLightSourcesDistribution" );
232+ } else {
233+ intersectionDevice->FreeBuffer (&infiniteLightSourcesDistributionBuff);
234+ }
235+
217236 if (cscene->dlscAllEntries .size () > 0 ) {
218237 intersectionDevice->AllocBufferRO (&dlscAllEntriesBuff, &cscene->dlscAllEntries [0 ],
219238 cscene->dlscAllEntries .size () * sizeof (slg::ocl::DLSCacheEntry), " DLSC all entries" );
0 commit comments