I need to render a scene on a specific location inside a render target (for creating texture atlas).
So I memorize the current viewport then switch targets, render and put the old viewport back, like so:
const renderRTVP = (rend, scene, camera, outputRT, vp, clear = true) => {
const bool = !clear && rend.autoClear;
if (bool) rend.autoClear = false;
const vp_old = new THREE.Vector4();
rend.getCurrentViewport(vp_old);
rend.setRenderTarget(outputRT);
rend.setViewport(vp);
rend.render(scene, camera);
rend.setViewport(vp_old);
rend.setRenderTarget(null);
if(bool) rend.autoClear = true;
};
is this the right code?
it works under Windows 10 but doesn’t work on Android mobile and probably other OS.
This is what I see when I press both buttons:
-
What’s the difference between getCurrentViewport and getViewport, I see different sizes on mobile?
-
Does the order of calling setRenderTarget and setViewport matter?