Skip to content

Commit

Permalink
WebGLGeoemtries: Simplify code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed Jan 13, 2021
1 parent af5414c commit 386cef3
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 386cef3

Please sign in to comment.