From 386cef3f3222e2f1f84d1883e94714658594ea5f Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Wed, 13 Jan 2021 13:28:59 +0100 Subject: [PATCH] WebGLGeoemtries: Simplify code. --- src/renderers/webgl/WebGLGeometries.js | 37 +++++++++----------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/src/renderers/webgl/WebGLGeometries.js b/src/renderers/webgl/WebGLGeometries.js index 77355b7984a0d6..07984a742c679c 100644 --- a/src/renderers/webgl/WebGLGeometries.js +++ b/src/renderers/webgl/WebGLGeometries.js @@ -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 ) { @@ -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; }