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
2 changes: 1 addition & 1 deletion examples/jsm/physics/JoltPhysics.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async function JoltPhysics() {

if ( Jolt === null ) {

const { default: initJolt } = await import( `${JOLT_PATH}` );
const { default: initJolt } = await import( JOLT_PATH /* @vite-ignore */ );
Jolt = await initJolt();

}
Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/physics/RapierPhysics.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async function RapierPhysics() {

if ( RAPIER === null ) {

RAPIER = await import( `${RAPIER_PATH}` );
RAPIER = await import( RAPIER_PATH /* @vite-ignore */ );
await RAPIER.init();

}
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ class WebGLRenderer {
attributes = new WebGLAttributes( _gl );
bindingStates = new WebGLBindingStates( _gl, attributes );
geometries = new WebGLGeometries( _gl, attributes, info, bindingStates );
objects = new WebGLObjects( _gl, geometries, attributes, info );
objects = new WebGLObjects( _gl, geometries, attributes, bindingStates, info );
morphtargets = new WebGLMorphtargets( _gl, capabilities, textures );
clipping = new WebGLClipping( properties );
programCache = new WebGLPrograms( _this, cubemaps, cubeuvmaps, extensions, capabilities, bindingStates, clipping );
Expand Down
126 changes: 99 additions & 27 deletions src/renderers/webgl/WebGLBindingStates.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function WebGLBindingStates( gl, attributes ) {

let updateBuffers = false;

const state = getBindingState( geometry, program, material );
const state = getBindingState( object, geometry, program, material );

if ( currentState !== state ) {

Expand Down Expand Up @@ -67,16 +67,28 @@ function WebGLBindingStates( gl, attributes ) {

}

function getBindingState( geometry, program, material ) {
function getBindingState( object, geometry, program, material ) {

const wireframe = ( material.wireframe === true );

let programMap = bindingStates[ geometry.id ];
let objectMap = bindingStates[ geometry.id ];

if ( objectMap === undefined ) {

objectMap = {};
bindingStates[ geometry.id ] = objectMap;

}

// Each InstancedMesh requires unique binding states because it contains instanced attributes.
const objectId = ( object.isInstancedMesh === true ) ? object.id : 0;

let programMap = objectMap[ objectId ];

if ( programMap === undefined ) {

programMap = {};
bindingStates[ geometry.id ] = programMap;
objectMap[ objectId ] = programMap;

}

Expand Down Expand Up @@ -477,21 +489,27 @@ function WebGLBindingStates( gl, attributes ) {

for ( const geometryId in bindingStates ) {

const programMap = bindingStates[ geometryId ];
const objectMap = bindingStates[ geometryId ];

for ( const programId in programMap ) {
for ( const objectId in objectMap ) {

const stateMap = programMap[ programId ];
const programMap = objectMap[ objectId ];

for ( const wireframe in stateMap ) {
for ( const programId in programMap ) {

deleteVertexArrayObject( stateMap[ wireframe ].object );
const stateMap = programMap[ programId ];

delete stateMap[ wireframe ];
for ( const wireframe in stateMap ) {

}
deleteVertexArrayObject( stateMap[ wireframe ].object );

delete programMap[ programId ];
delete stateMap[ wireframe ];

}

delete programMap[ programId ];

}

}

Expand All @@ -505,21 +523,27 @@ function WebGLBindingStates( gl, attributes ) {

if ( bindingStates[ geometry.id ] === undefined ) return;

const programMap = bindingStates[ geometry.id ];
const objectMap = bindingStates[ geometry.id ];

for ( const programId in programMap ) {
for ( const objectId in objectMap ) {

const stateMap = programMap[ programId ];
const programMap = objectMap[ objectId ];

for ( const wireframe in stateMap ) {
for ( const programId in programMap ) {

deleteVertexArrayObject( stateMap[ wireframe ].object );
const stateMap = programMap[ programId ];

delete stateMap[ wireframe ];
for ( const wireframe in stateMap ) {

}
deleteVertexArrayObject( stateMap[ wireframe ].object );

delete programMap[ programId ];
delete stateMap[ wireframe ];

}

delete programMap[ programId ];

}

}

Expand All @@ -531,26 +555,73 @@ function WebGLBindingStates( gl, attributes ) {

for ( const geometryId in bindingStates ) {

const programMap = bindingStates[ geometryId ];
const objectMap = bindingStates[ geometryId ];

for ( const objectId in objectMap ) {

const programMap = objectMap[ objectId ];

if ( programMap[ program.id ] === undefined ) continue;

const stateMap = programMap[ program.id ];

for ( const wireframe in stateMap ) {

deleteVertexArrayObject( stateMap[ wireframe ].object );

delete stateMap[ wireframe ];

}

delete programMap[ program.id ];

}

}

}

function releaseStatesOfObject( object ) {

for ( const geometryId in bindingStates ) {

const objectMap = bindingStates[ geometryId ];

if ( programMap[ program.id ] === undefined ) continue;
const objectId = ( object.isInstancedMesh === true ) ? object.id : 0;

const stateMap = programMap[ program.id ];
const programMap = objectMap[ objectId ];

for ( const wireframe in stateMap ) {
if ( programMap === undefined ) continue;

deleteVertexArrayObject( stateMap[ wireframe ].object );
for ( const programId in programMap ) {

delete stateMap[ wireframe ];
const stateMap = programMap[ programId ];

for ( const wireframe in stateMap ) {

deleteVertexArrayObject( stateMap[ wireframe ].object );

delete stateMap[ wireframe ];

}

delete programMap[ programId ];

}

delete programMap[ program.id ];
delete objectMap[ objectId ];

if ( Object.keys( objectMap ).length === 0 ) {

delete bindingStates[ geometryId ];

}

}

}


function reset() {

resetDefaultState();
Expand Down Expand Up @@ -580,6 +651,7 @@ function WebGLBindingStates( gl, attributes ) {
resetDefaultState: resetDefaultState,
dispose: dispose,
releaseStatesOfGeometry: releaseStatesOfGeometry,
releaseStatesOfObject: releaseStatesOfObject,
releaseStatesOfProgram: releaseStatesOfProgram,

initAttributes: initAttributes,
Expand Down
4 changes: 3 additions & 1 deletion src/renderers/webgl/WebGLObjects.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function WebGLObjects( gl, geometries, attributes, info ) {
function WebGLObjects( gl, geometries, attributes, bindingStates, info ) {

let updateMap = new WeakMap();

Expand Down Expand Up @@ -73,6 +73,8 @@ function WebGLObjects( gl, geometries, attributes, info ) {

instancedMesh.removeEventListener( 'dispose', onInstancedMeshDispose );

bindingStates.releaseStatesOfObject( instancedMesh );

attributes.remove( instancedMesh.instanceMatrix );

if ( instancedMesh.instanceColor !== null ) attributes.remove( instancedMesh.instanceColor );
Expand Down