Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
aardgoose committed Sep 22, 2023
1 parent 4779160 commit 48d0500
Showing 1 changed file with 72 additions and 43 deletions.
115 changes: 72 additions & 43 deletions examples/jsm/renderers/webgl/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,9 @@ class WebGLBackend extends Backend {
_setFramebuffer( renderContext ) {

const { gl } = this;

if ( renderContext.textures !== null ) {

const renderContextData = this.get( renderContext );

let fb = renderContextData.framebuffer;
Expand Down Expand Up @@ -739,53 +739,82 @@ _setFramebuffer( renderContext ) {
let drawBuffers = [];

if ( renderContext.isCube ) {

if ( renderContextData.cubeFramebuffers === undefined ) {

renderContextData.cubeFramebuffers[ cubeFace ] = fb;
const { textureGPU } = this.get( textures[ 0 ] );

gl.framebufferTexture2D( gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + cubeFace, textureGPU, 0 );

drawBuffers.push( gl.COLOR_ATTACHMENT0 );

} else {

renderContextData.framebuffer = fb;

for ( let i = 0; i < textures.length; i ++ ) {

const texture = textures[ i ];
const { textureGPU } = this.get( texture );

const attachment = gl.COLOR_ATTACHMENT0 + i;

gl.framebufferTexture2D( gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, textureGPU, 0 );

drawBuffers.push( attachment );

renderContextData.cubeFramebuffers = [];

}


cubeFace = this.renderer._activeCubeFace;
fb = renderContextData.cubeFramebuffers[ cubeFace ]

} else {

fb = renderContextData.framebuffer;

}

if ( renderContext.depthTexture !== null ) {

const { textureGPU } = this.get( renderContext.depthTexture );

gl.framebufferTexture2D( gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, textureGPU, 0 );


if ( fb === undefined ) {

fb = gl.createFramebuffer();

gl.bindFramebuffer( gl.FRAMEBUFFER, fb );

const textures = renderContext.textures;

let drawBuffers = [];

if ( renderContext.isCube ) {

renderContextData.cubeFramebuffers[ cubeFace ] = fb;
const { textureGPU } = this.get( textures[ 0 ] );

gl.framebufferTexture2D( gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + cubeFace, textureGPU, 0 );

drawBuffers.push( gl.COLOR_ATTACHMENT0 );

} else {

renderContextData.framebuffer = fb;

for ( let i = 0; i < textures.length; i ++ ) {

const texture = textures[ i ];
const { textureGPU } = this.get( texture );

const attachment = gl.COLOR_ATTACHMENT0 + i;

gl.framebufferTexture2D( gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, textureGPU, 0 );

drawBuffers.push( attachment );

}

}

if ( renderContext.depthTexture !== null ) {

const { textureGPU } = this.get( renderContext.depthTexture );

gl.framebufferTexture2D( gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, textureGPU, 0 );

}

gl.drawBuffers( drawBuffers );

} else {

gl.bindFramebuffer( gl.FRAMEBUFFER, fb );

}

gl.drawBuffers( drawBuffers );


} else {

gl.bindFramebuffer( gl.FRAMEBUFFER, fb );

gl.bindFramebuffer( gl.FRAMEBUFFER, null );
}

} else {

gl.bindFramebuffer( gl.FRAMEBUFFER, null );


}

}
Expand Down

0 comments on commit 48d0500

Please sign in to comment.