Procházet zdrojové kódy

WebGLBackend: Cache WebGL buffer when updating UBOs. (#31684)

* WebGLBackend: Cache WebGL buffer when updating UBOs.

* WebGLBackend: Distinct between creation and updating UBOs.
Michael Herzog před 4 měsíci
rodič
revize
ca3194a347
1 změnil soubory, kde provedl 30 přidání a 12 odebrání
  1. 30 12
      src/renderers/webgl-fallback/WebGLBackend.js

+ 30 - 12
src/renderers/webgl-fallback/WebGLBackend.js

@@ -1845,28 +1845,46 @@ class WebGLBackend extends Backend {
 
 
 		for ( const binding of bindGroup.bindings ) {
 		for ( const binding of bindGroup.bindings ) {
 
 
+			const map = this.get( binding );
+
 			if ( binding.isUniformsGroup || binding.isUniformBuffer ) {
 			if ( binding.isUniformsGroup || binding.isUniformBuffer ) {
 
 
 				const data = binding.buffer;
 				const data = binding.buffer;
-				const bufferGPU = gl.createBuffer();
+				let { bufferGPU } = this.get( data );
 
 
-				gl.bindBuffer( gl.UNIFORM_BUFFER, bufferGPU );
-				gl.bufferData( gl.UNIFORM_BUFFER, data, gl.DYNAMIC_DRAW );
+				if ( bufferGPU === undefined ) {
 
 
-				this.set( binding, {
-					index: i ++,
-					bufferGPU
-				} );
+					// create
+
+					bufferGPU = gl.createBuffer();
+					gl.bindBuffer( gl.UNIFORM_BUFFER, bufferGPU );
+					gl.bufferData( gl.UNIFORM_BUFFER, data, gl.DYNAMIC_DRAW );
+
+					this.set( data, { bufferGPU } );
+
+				} else {
+
+					// update
+
+					gl.bindBuffer( gl.UNIFORM_BUFFER, bufferGPU );
+					gl.bufferSubData( gl.UNIFORM_BUFFER, 0, data );
+
+				}
+
+				map.index = i ++;
+				map.bufferGPU = bufferGPU;
+
+				this.set( binding, map );
 
 
 			} else if ( binding.isSampledTexture ) {
 			} else if ( binding.isSampledTexture ) {
 
 
 				const { textureGPU, glTextureType } = this.get( binding.texture );
 				const { textureGPU, glTextureType } = this.get( binding.texture );
 
 
-				this.set( binding, {
-					index: t ++,
-					textureGPU,
-					glTextureType
-				} );
+				map.index = t ++;
+				map.textureGPU = textureGPU;
+				map.glTextureType = glTextureType;
+
+				this.set( binding, map );
 
 
 			}
 			}
 
 

粤ICP备19079148号