From 87489e324cf3d1be41915371e1d6f7cab00b294d Mon Sep 17 00:00:00 2001 From: aardgoose Date: Mon, 29 May 2017 11:55:14 +0100 Subject: [PATCH] allow index attribute typed arrays to be dropped from javascript memory after upload to GPU. --- src/renderers/WebGLRenderer.js | 7 +++++-- .../webgl/WebGLIndexedBufferRenderer.js | 20 +++---------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 1ca721664f8e9e..4b98c2ed5e8b5f 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -784,11 +784,14 @@ function WebGLRenderer( parameters ) { } var renderer = bufferRenderer; + var indexProperties; if ( index !== null ) { + indexProperties = attributes.get( index ); + renderer = indexedBufferRenderer; - renderer.setIndex( index ); + renderer.setIndex( indexProperties ); } @@ -798,7 +801,7 @@ function WebGLRenderer( parameters ) { if ( index !== null ) { - _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, attributes.get( index ).buffer ); + _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexProperties.buffer ); } diff --git a/src/renderers/webgl/WebGLIndexedBufferRenderer.js b/src/renderers/webgl/WebGLIndexedBufferRenderer.js index ff987db2187d77..b029f9c77f7403 100644 --- a/src/renderers/webgl/WebGLIndexedBufferRenderer.js +++ b/src/renderers/webgl/WebGLIndexedBufferRenderer.js @@ -14,24 +14,10 @@ function WebGLIndexedBufferRenderer( gl, extensions, infoRender ) { var type, size; - function setIndex( index ) { + function setIndex( indexProperties ) { - if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) { - - type = gl.UNSIGNED_INT; - size = 4; - - } else if ( index.array instanceof Uint16Array ) { - - type = gl.UNSIGNED_SHORT; - size = 2; - - } else { - - type = gl.UNSIGNED_BYTE; - size = 1; - - } + type = indexProperties.type; + size = indexProperties.bytesPerElement; }