Created
April 17, 2025 10:09
-
-
Save ayamflow/3b23c3abc5d45f2719c8c826bb0ab0f1 to your computer and use it in GitHub Desktop.
blit threejs framebuffer / renderTarget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function blit(renderer: WebGLRenderer, source: WebGLRenderTarget, dest: WebGLRenderTarget) { | |
const gl = renderer.getContext() as WebGL2RenderingContext; | |
const prop = renderer.properties; | |
const readBuffer = (prop.get(source) as any).__webglFramebuffer; | |
const readTexture = (prop.get(source.texture) as any).__webglTexture; | |
const writeBuffer = (prop.get(dest) as any).__webglFramebuffer; | |
const writeTexture = (prop.get(dest.texture) as any).__webglTexture; | |
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, readBuffer); | |
gl.framebufferTexture2D(gl.READ_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, readTexture, 0); | |
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, writeBuffer); | |
gl.framebufferTexture2D(gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, writeTexture, 0); | |
gl.blitFramebuffer( | |
0, | |
0, | |
source.width, | |
source.height, | |
0, | |
0, | |
source.width, | |
source.height, | |
gl.COLOR_BUFFER_BIT, | |
gl.NEAREST, | |
); | |
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, null); | |
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment