Fix binding __webglFramebuffer when mipmaps are used #30746
Draft
+33
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #30745
Related issue: #29779
Description
It's possible render into specific mipmap levels when we set the target.texture.mipmaps array. This works great for color-only render targets, however if we give this target a depth buffer (either through depthBuffer: true or an explicit depthTexture), rendering will fail with a crash when rendering
The crash is caused by three.js assuming .__webglFramebuffer is a single framebuffer, however, when .mipmaps is set it becomes an array:
This causes a crash on this line
three.js/src/renderers/webgl/WebGLTextures.js
Line 1663 in fc4ef55
And
three.js/src/renderers/webgl/WebGLTextures.js
Line 1532 in fc4ef55
Maybe other places too
This PR resolves this by instead setting the depth attachment for only mipmap 0.
I will also think about setting a depth attachment for each mip level
I've tried to use idomatic three.js style which comes out quite verbose but let me know if we want something tidier!