Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/renderers/webgl-fallback/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -991,14 +991,28 @@ class WebGLBackend extends Backend {
* @param {number} firstVertex - The first vertex to render.
* @param {number} vertexCount - The vertex count.
* @param {number} instanceCount - The intance count.
* @param {WebGLProgram} programGPU - The raw WebGL shader program.
*/
_draw( object, renderer, firstVertex, vertexCount, instanceCount ) {
_draw( object, renderer, firstVertex, vertexCount, instanceCount, programGPU ) {

if ( object.isBatchedMesh ) {

if ( this.hasFeature( 'WEBGL_multi_draw' ) === false ) {

warnOnce( 'WebGLBackend: WEBGL_multi_draw not supported.' );
const { gl } = this;

const drawIdLocation = gl.getUniformLocation( programGPU, 'nodeUniformDrawId' );

const starts = object._multiDrawStarts;
const counts = object._multiDrawCounts;
const drawCount = object._multiDrawCount;

for ( let i = 0; i < drawCount; i ++ ) {

gl.uniform1ui( drawIdLocation, i );
renderer.render( starts[ i ], counts[ i ] );

}

} else {

Expand Down Expand Up @@ -1267,7 +1281,7 @@ class WebGLBackend extends Backend {

state.bindBufferBase( gl.UNIFORM_BUFFER, cameraIndexBufferIndex, cameraData.indexesGPU[ i ] );

this._draw( object, renderer, firstVertex, vertexCount, instanceCount );
this._draw( object, renderer, firstVertex, vertexCount, instanceCount, programGPU );

}

Expand All @@ -1278,7 +1292,7 @@ class WebGLBackend extends Backend {

} else {

this._draw( object, renderer, firstVertex, vertexCount, instanceCount );
this._draw( object, renderer, firstVertex, vertexCount, instanceCount, programGPU );

}

Expand Down
20 changes: 18 additions & 2 deletions src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1145,9 +1145,11 @@ ${ flowData.code }

return 'uint( gl_DrawID )';

}
} else {

return null;
return 'nodeUniformDrawId'; // fallback to uniform

}

}

Expand Down Expand Up @@ -1556,6 +1558,20 @@ void main() {
stageData.transforms = this.getTransforms( shaderStage );
stageData.flow = flow;

// fallbacks

if ( shaderStage === 'vertex' ) {

const ext = this.renderer.backend.extensions;

if ( this.object.isBatchedMesh && ext.has( 'WEBGL_multi_draw' ) === false ) {

stageData.uniforms += '\nuniform uint nodeUniformDrawId;\n';

}

}

}

if ( this.material !== null ) {
Expand Down
Loading