Skip to content

Commit

Permalink
[Fix] Fix compatibility with deprecated Layer.renderTarget (#5877)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
  • Loading branch information
mvaligursky and Martin Valigursky committed Dec 4, 2023
1 parent d4ccbc4 commit ee38a8f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/scene/renderer/renderer.js
Expand Up @@ -1074,9 +1074,8 @@ class Renderer {
for (let i = 0; i < numCameras; i++) {
const camera = comp.cameras[i];

// update camera and frustum
camera.frameUpdate(camera.renderTarget);
this.updateCameraFrustum(camera.camera);
let currentRenderTarget;
let cameraChanged = true;
this._camerasRendered++;

// for all of its enabled layers
Expand All @@ -1085,6 +1084,17 @@ class Renderer {
const layer = comp.getLayerById(layerIds[j]);
if (layer && layer.enabled) {

// update camera and frustum when the render target changes
// TODO: This is done here to handle the backwards compatibility with the deprecated Layer.renderTarget,
// when this is no longer needed, this code can be moved up to execute once per camera.
const renderTarget = camera.renderTarget ?? layer.renderTarget;
if (cameraChanged || renderTarget !== currentRenderTarget) {
cameraChanged = false;
currentRenderTarget = renderTarget;
camera.frameUpdate(renderTarget);
this.updateCameraFrustum(camera.camera);
}

// cull each layer's non-directional lights once with each camera
// lights aren't collected anywhere, but marked as visible
this.cullLights(camera.camera, layer._lights);
Expand Down

0 comments on commit ee38a8f

Please sign in to comment.