|
|
@@ -63,6 +63,8 @@ class WebGLBackend extends Backend {
|
|
|
this.disjoint = this.extensions.get( 'EXT_disjoint_timer_query_webgl2' );
|
|
|
this.parallel = this.extensions.get( 'KHR_parallel_shader_compile' );
|
|
|
|
|
|
+ this._knownBindings = new WeakSet();
|
|
|
+
|
|
|
this._currentContext = null;
|
|
|
|
|
|
}
|
|
|
@@ -1125,33 +1127,45 @@ class WebGLBackend extends Backend {
|
|
|
|
|
|
createBindings( bindGroup, bindings ) {
|
|
|
|
|
|
- this.updateBindings( bindGroup, bindings );
|
|
|
+ if ( this._knownBindings.has( bindings ) === false ) {
|
|
|
|
|
|
- }
|
|
|
+ this._knownBindings.add( bindings );
|
|
|
|
|
|
- updateBindings( bindGroup, bindings ) {
|
|
|
+ let uniformBuffers = 0;
|
|
|
+ let textures = 0;
|
|
|
|
|
|
- if ( ! bindGroup ) return;
|
|
|
+ for ( const bindGroup of bindings ) {
|
|
|
|
|
|
- const { gl } = this;
|
|
|
+ this.set( bindGroup, {
|
|
|
+ textures: textures,
|
|
|
+ uniformBuffers: uniformBuffers
|
|
|
+ } );
|
|
|
|
|
|
- const bindingsData = this.get( bindings );
|
|
|
- const bindGroupData = this.get( bindGroup );
|
|
|
+ for ( const binding of bindGroup.bindings ) {
|
|
|
|
|
|
- if ( bindingsData.textureIndex === undefined ) bindingsData.textureIndex = 0;
|
|
|
+ if ( binding.isUniformBuffer ) uniformBuffers ++;
|
|
|
+ if ( binding.isSampledTexture ) textures ++;
|
|
|
|
|
|
- if ( bindGroupData.textureIndex === undefined ) {
|
|
|
+ }
|
|
|
|
|
|
- bindGroupData.textureIndex = bindingsData.textureIndex;
|
|
|
+ }
|
|
|
|
|
|
- } else {
|
|
|
+ }
|
|
|
|
|
|
- // reset textureIndex to match previous mappimgs when rebuilt
|
|
|
- bindingsData.textureIndex = bindGroupData.textureIndex;
|
|
|
+ this.updateBindings( bindGroup, bindings );
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ updateBindings( bindGroup /*, bindings*/ ) {
|
|
|
+
|
|
|
+ if ( bindGroup === null ) return;
|
|
|
+
|
|
|
+ const { gl } = this;
|
|
|
+
|
|
|
+ const bindGroupData = this.get( bindGroup );
|
|
|
|
|
|
- let i = 0;
|
|
|
+ let i = bindGroupData.uniformBuffers;
|
|
|
+ let t = bindGroupData.textures;
|
|
|
|
|
|
for ( const binding of bindGroup.bindings ) {
|
|
|
|
|
|
@@ -1164,7 +1178,7 @@ class WebGLBackend extends Backend {
|
|
|
gl.bufferData( gl.UNIFORM_BUFFER, data, gl.DYNAMIC_DRAW );
|
|
|
|
|
|
this.set( binding, {
|
|
|
- index: bindGroup.index * 2 + i ++,
|
|
|
+ index: i ++,
|
|
|
bufferGPU
|
|
|
} );
|
|
|
|
|
|
@@ -1173,7 +1187,7 @@ class WebGLBackend extends Backend {
|
|
|
const { textureGPU, glTextureType } = this.get( binding.texture );
|
|
|
|
|
|
this.set( binding, {
|
|
|
- index: bindingsData.textureIndex ++,
|
|
|
+ index: t ++,
|
|
|
textureGPU,
|
|
|
glTextureType
|
|
|
} );
|