Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
aardgoose committed Sep 21, 2023
1 parent bd3a27d commit 786bcff
Showing 1 changed file with 62 additions and 24 deletions.
86 changes: 62 additions & 24 deletions examples/jsm/renderers/webgl/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ const debugHandler = {

const value = target[ name ];

if (value instanceof Function ) {
if ( value instanceof Function ) {

return function (...args) {

const e = target.getError();
if ( e == 0 ) {

if ( e !== 0 ) console.warn( `[${debugHandler.lastCommand} ] error: ${e}` );
e = target.getError();
if ( e !== 0 ) console.warn( `[${debugHandler.lastCommand} ] error: ${e}` );

}

debugHandler.lastCommand = name;

Expand Down Expand Up @@ -59,8 +62,8 @@ class WebGLBackend extends Backend {

const glContext = ( parameters.context !== undefined ) ? parameters.context : renderer.domElement.getContext( 'webgl2' );

// this.gl = new Proxy( glContext, debugHandler );
this.gl = glContext;
this.gl = new Proxy( glContext, debugHandler );
// this.gl = glContext;

this.extensions = new WebGLExtensions( this );
this.attributeUtils = new WebGLAttributeUtils( this );
Expand Down Expand Up @@ -130,9 +133,25 @@ class WebGLBackend extends Backend {

}

finishRender( /*renderContext*/ ) {
finishRender( renderContext ) {

console.log( renderContext );
const gl = this.gl;

const fb = this.get( renderContext ).framebuffer;

if ( fb === undefined ) return;

//console.warn( 'Abstract class.' );
gl.bindFramebuffer( gl.DRAW_FRAMEBUFFER, fb );

if ( renderContext.depthTexture !== null ) {

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

gl.framebufferTexture2D( gl.DRAW_FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, null, 0 );

}

}

Expand Down Expand Up @@ -205,7 +224,16 @@ class WebGLBackend extends Backend {
gl.bindBufferBase( gl.UNIFORM_BUFFER, index, bindingData.bufferGPU );

} else if ( binding.isSampledTexture ) {
console.log( 'binding', binding.texture.id );

const t = this.get( bindingData.textureGPU );

// if ( t.fb ) {

// gl.bindFramebuffer( gl.READ_FRAMEBUFFER, t.fb );
// gl.framebufferTexture2D( gl.READ_FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, null, 0 );

// }

gl.activeTexture( gl.TEXTURE0 + index );
gl.bindTexture( bindingData.glTextureType, bindingData.textureGPU );

Expand Down Expand Up @@ -431,7 +459,7 @@ console.log( 'binding', binding.texture.id );
gl.bindTexture( glTextureType, textureGPU );

if ( texture.isCubeTexture ) {
console.log( texture.id );

const images = options.images;

for ( let i = 0; i < 6; i ++ ) {
Expand Down Expand Up @@ -707,7 +735,7 @@ console.log( texture.id );
gl.bufferData( gl.UNIFORM_BUFFER, data, gl.DYNAMIC_DRAW );

}
if ( binding.isSampledTexture ) console.log( 'wwww');

}

// attributes
Expand Down Expand Up @@ -765,9 +793,9 @@ console.log( texture.id );
const { textureGPU } = this.get( texture );

this._setFramebuffer( renderContext );
console.log( 'ccc');

gl.bindTexture( gl.TEXTURE_2D, textureGPU );
//if ( error < 100 ) { console.log( this.get( texture ), texture ); error++ }
if ( error < 100 ) { console.log( this.get( texture ), texture ); error++ }

// 6408 = 0x1908 = gl.DEPTH_COMPONENT
// 5125 = 0x1405 = gl.UNSIGNED_INT (glType)
Expand All @@ -786,23 +814,21 @@ console.log( 'ccc');

const { gl } = this;

if ( renderContext.textures !== null ) {
const renderContextData = this.get( renderContext );

const renderContextData = this.get( renderContext );
if ( renderContext.textures !== null ) {

let fb;
let cubeFace = 0;
const cubeFace = this.renderer._activeCubeFace;

if ( renderContext.isCube ) {

if ( renderContextData.cubeFramebuffers === undefined ) {

renderContextData.cubeFramebuffers = [];
console.log( 'fb cube', renderContext.textures[ 0 ].id );

}

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

} else {
Expand All @@ -811,13 +837,15 @@ console.log( 'ccc');

}

const textures = renderContext.textures;

if ( fb === undefined ) {
console.log( 'setup=fb', renderContext );

fb = gl.createFramebuffer();

gl.bindFramebuffer( gl.FRAMEBUFFER, fb );
gl.bindFramebuffer( gl.DRAW_FRAMEBUFFER, fb );

const textures = renderContext.textures;

let drawBuffers = [];

Expand Down Expand Up @@ -847,27 +875,37 @@ console.log( 'ccc');

}

}
if ( renderContext.depthTexture !== null ) {

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

const { textureGPU } = this.get( renderContext.depthTexture );
gl.framebufferTexture2D( gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, textureGPU, 0 );

gl.framebufferTexture2D( gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, textureGPU, 0 );
this.set( textureGPU, { fb: fb } );

}

}

gl.drawBuffers( drawBuffers );

} else {

gl.bindFramebuffer( gl.FRAMEBUFFER, fb );
gl.bindFramebuffer( gl.DRAW_FRAMEBUFFER, fb );

if ( renderContext.depthTexture !== null ) {
console.log( 'rebind');
const { textureGPU } = this.get( renderContext.depthTexture );

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

}

}

} else {

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

}

Expand Down

0 comments on commit 786bcff

Please sign in to comment.