Skip to content

Commit

Permalink
Merge pull request #21077 from Mugen87/dev2
Browse files Browse the repository at this point in the history
WebGLGeometries: Simplify code.
  • Loading branch information
mrdoob authored Jan 13, 2021
2 parents df9c96e + 386cef3 commit f77dadb
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions src/renderers/webgl/WebGLGeometries.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,39 @@ import { arrayMax } from '../../utils.js';

function WebGLGeometries( gl, attributes, info, bindingStates ) {

const geometries = new WeakMap();
const geometries = {};
const wireframeAttributes = new WeakMap();

function onGeometryDispose( event ) {

const geometry = event.target;
const buffergeometry = geometries.get( geometry );

if ( buffergeometry.index !== null ) {
if ( geometry.index !== null ) {

attributes.remove( buffergeometry.index );
attributes.remove( geometry.index );

}

for ( const name in buffergeometry.attributes ) {
for ( const name in geometry.attributes ) {

attributes.remove( buffergeometry.attributes[ name ] );
attributes.remove( geometry.attributes[ name ] );

}

geometry.removeEventListener( 'dispose', onGeometryDispose );

geometries.delete( geometry );
delete geometries[ geometry.id ];

const attribute = wireframeAttributes.get( buffergeometry );
const attribute = wireframeAttributes.get( geometry );

if ( attribute ) {

attributes.remove( attribute );
wireframeAttributes.delete( buffergeometry );
wireframeAttributes.delete( geometry );

}

bindingStates.releaseStatesOfGeometry( buffergeometry );
bindingStates.releaseStatesOfGeometry( geometry );

if ( geometry.isInstancedBufferGeometry === true ) {

Expand All @@ -52,27 +51,15 @@ function WebGLGeometries( gl, attributes, info, bindingStates ) {

function get( object, geometry ) {

let buffergeometry = geometries.get( geometry );

if ( buffergeometry ) return buffergeometry;
if ( geometries[ geometry.id ] === true ) return geometry;

geometry.addEventListener( 'dispose', onGeometryDispose );

if ( geometry.isBufferGeometry ) {

buffergeometry = geometry;

} else {

console.log( 'TODO: Remove this', geometry );

}

geometries.set( geometry, buffergeometry );
geometries[ geometry.id ] = true;

info.memory.geometries ++;

return buffergeometry;
return geometry;

}

Expand Down

0 comments on commit f77dadb

Please sign in to comment.