From d0b259b157647a6077b78610e006839f7a651451 Mon Sep 17 00:00:00 2001 From: aardgoose Date: Sat, 5 Nov 2016 22:06:11 +0000 Subject: [PATCH] capture bufferAttribute.array properties at first upload (#9972) * save typed array info in attribute properties * use saved attribute properties * remove unused variable --- src/renderers/WebGLRenderer.js | 46 ++++--------------------- src/renderers/webgl/WebGLObjects.js | 52 +++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 39 deletions(-) diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 38ba4a16cd..6416c30f1c 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -933,46 +933,14 @@ function WebGLRenderer( parameters ) { if ( geometryAttribute !== undefined ) { - var type = _gl.FLOAT; - var array = geometryAttribute.array; var normalized = geometryAttribute.normalized; + var size = geometryAttribute.itemSize; - if ( array instanceof Float32Array ) { - - type = _gl.FLOAT; - - } else if ( array instanceof Float64Array ) { - - console.warn( "Unsupported data buffer format: Float64Array" ); - - } else if ( array instanceof Uint16Array ) { - - type = _gl.UNSIGNED_SHORT; - - } else if ( array instanceof Int16Array ) { - - type = _gl.SHORT; - - } else if ( array instanceof Uint32Array ) { - - type = _gl.UNSIGNED_INT; - - } else if ( array instanceof Int32Array ) { - - type = _gl.INT; - - } else if ( array instanceof Int8Array ) { - - type = _gl.BYTE; - - } else if ( array instanceof Uint8Array ) { - - type = _gl.UNSIGNED_BYTE; - - } + var attributeProperties = objects.getAttributeProperties( geometryAttribute ); - var size = geometryAttribute.itemSize; - var buffer = objects.getAttributeBuffer( geometryAttribute ); + var buffer = attributeProperties.__webglBuffer; + var type = attributeProperties.type; + var bytesPerElement = attributeProperties.bytesPerElement; if ( geometryAttribute.isInterleavedBufferAttribute ) { @@ -997,7 +965,7 @@ function WebGLRenderer( parameters ) { } _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer ); - _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT ); + _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, ( startIndex * stride + offset ) * bytesPerElement ); } else { @@ -1018,7 +986,7 @@ function WebGLRenderer( parameters ) { } _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer ); - _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, startIndex * size * geometryAttribute.array.BYTES_PER_ELEMENT ); + _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, startIndex * size * bytesPerElement ); } diff --git a/src/renderers/webgl/WebGLObjects.js b/src/renderers/webgl/WebGLObjects.js index 79bbd24124..6ae541c45d 100644 --- a/src/renderers/webgl/WebGLObjects.js +++ b/src/renderers/webgl/WebGLObjects.js @@ -85,6 +85,45 @@ function WebGLObjects( gl, properties, info ) { gl.bufferData( bufferType, data.array, usage ); + var type = gl.FLOAT; + var array = data.array; + + if ( array instanceof Float32Array ) { + + type = gl.FLOAT; + + } else if ( array instanceof Float64Array ) { + + console.warn( "Unsupported data buffer format: Float64Array" ); + + } else if ( array instanceof Uint16Array ) { + + type = gl.UNSIGNED_SHORT; + + } else if ( array instanceof Int16Array ) { + + type = gl.SHORT; + + } else if ( array instanceof Uint32Array ) { + + type = gl.UNSIGNED_INT; + + } else if ( array instanceof Int32Array ) { + + type = gl.INT; + + } else if ( array instanceof Int8Array ) { + + type = gl.BYTE; + + } else if ( array instanceof Uint8Array ) { + + type = gl.UNSIGNED_BYTE; + + } + + attributeProperties.bytesPerElement = array.BYTES_PER_ELEMENT; + attributeProperties.type = type; attributeProperties.version = data.version; } @@ -132,6 +171,18 @@ function WebGLObjects( gl, properties, info ) { } + function getAttributeProperties( attribute ) { + + if ( attribute.isInterleavedBufferAttribute ) { + + return properties.get( attribute.data ); + + } + + return properties.get( attribute ); + + } + function getWireframeAttribute( geometry ) { var property = properties.get( geometry ); @@ -197,6 +248,7 @@ function WebGLObjects( gl, properties, info ) { return { getAttributeBuffer: getAttributeBuffer, + getAttributeProperties: getAttributeProperties, getWireframeAttribute: getWireframeAttribute, update: update -- GitLab