Skip to content

Commit ca3194a

Browse files
authored
WebGLBackend: Cache WebGL buffer when updating UBOs. (#31684)
* WebGLBackend: Cache WebGL buffer when updating UBOs. * WebGLBackend: Distinct between creation and updating UBOs.
1 parent e9f7c8b commit ca3194a

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

src/renderers/webgl-fallback/WebGLBackend.js

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,28 +1845,46 @@ class WebGLBackend extends Backend {
18451845

18461846
for ( const binding of bindGroup.bindings ) {
18471847

1848+
const map = this.get( binding );
1849+
18481850
if ( binding.isUniformsGroup || binding.isUniformBuffer ) {
18491851

18501852
const data = binding.buffer;
1851-
const bufferGPU = gl.createBuffer();
1853+
let { bufferGPU } = this.get( data );
18521854

1853-
gl.bindBuffer( gl.UNIFORM_BUFFER, bufferGPU );
1854-
gl.bufferData( gl.UNIFORM_BUFFER, data, gl.DYNAMIC_DRAW );
1855+
if ( bufferGPU === undefined ) {
18551856

1856-
this.set( binding, {
1857-
index: i ++,
1858-
bufferGPU
1859-
} );
1857+
// create
1858+
1859+
bufferGPU = gl.createBuffer();
1860+
gl.bindBuffer( gl.UNIFORM_BUFFER, bufferGPU );
1861+
gl.bufferData( gl.UNIFORM_BUFFER, data, gl.DYNAMIC_DRAW );
1862+
1863+
this.set( data, { bufferGPU } );
1864+
1865+
} else {
1866+
1867+
// update
1868+
1869+
gl.bindBuffer( gl.UNIFORM_BUFFER, bufferGPU );
1870+
gl.bufferSubData( gl.UNIFORM_BUFFER, 0, data );
1871+
1872+
}
1873+
1874+
map.index = i ++;
1875+
map.bufferGPU = bufferGPU;
1876+
1877+
this.set( binding, map );
18601878

18611879
} else if ( binding.isSampledTexture ) {
18621880

18631881
const { textureGPU, glTextureType } = this.get( binding.texture );
18641882

1865-
this.set( binding, {
1866-
index: t ++,
1867-
textureGPU,
1868-
glTextureType
1869-
} );
1883+
map.index = t ++;
1884+
map.textureGPU = textureGPU;
1885+
map.glTextureType = glTextureType;
1886+
1887+
this.set( binding, map );
18701888

18711889
}
18721890

0 commit comments

Comments
 (0)