Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGLGeometries: Simplify code. #21077

Merged
merged 1 commit into from
Jan 13, 2021
Merged
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
WebGLGeoemtries: Simplify code.
Mugen87 committed Jan 13, 2021
commit 386cef3f3222e2f1f84d1883e94714658594ea5f
37 changes: 12 additions & 25 deletions src/renderers/webgl/WebGLGeometries.js
Original file line number Diff line number Diff line change
@@ -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;

}