提交 d0b259b1 编写于 作者: A aardgoose 提交者: Mr.doob

capture bufferAttribute.array properties at first upload (#9972)

* save typed array info in attribute properties

* use saved attribute properties

* remove unused variable
上级 e3635edb
...@@ -933,46 +933,14 @@ function WebGLRenderer( parameters ) { ...@@ -933,46 +933,14 @@ function WebGLRenderer( parameters ) {
if ( geometryAttribute !== undefined ) { if ( geometryAttribute !== undefined ) {
var type = _gl.FLOAT;
var array = geometryAttribute.array;
var normalized = geometryAttribute.normalized; var normalized = geometryAttribute.normalized;
var size = geometryAttribute.itemSize;
if ( array instanceof Float32Array ) { var attributeProperties = objects.getAttributeProperties( geometryAttribute );
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 size = geometryAttribute.itemSize; var buffer = attributeProperties.__webglBuffer;
var buffer = objects.getAttributeBuffer( geometryAttribute ); var type = attributeProperties.type;
var bytesPerElement = attributeProperties.bytesPerElement;
if ( geometryAttribute.isInterleavedBufferAttribute ) { if ( geometryAttribute.isInterleavedBufferAttribute ) {
...@@ -997,7 +965,7 @@ function WebGLRenderer( parameters ) { ...@@ -997,7 +965,7 @@ function WebGLRenderer( parameters ) {
} }
_gl.bindBuffer( _gl.ARRAY_BUFFER, buffer ); _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 { } else {
...@@ -1018,7 +986,7 @@ function WebGLRenderer( parameters ) { ...@@ -1018,7 +986,7 @@ function WebGLRenderer( parameters ) {
} }
_gl.bindBuffer( _gl.ARRAY_BUFFER, buffer ); _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 );
} }
......
...@@ -85,6 +85,45 @@ function WebGLObjects( gl, properties, info ) { ...@@ -85,6 +85,45 @@ function WebGLObjects( gl, properties, info ) {
gl.bufferData( bufferType, data.array, usage ); 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; attributeProperties.version = data.version;
} }
...@@ -132,6 +171,18 @@ function WebGLObjects( gl, properties, info ) { ...@@ -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 ) { function getWireframeAttribute( geometry ) {
var property = properties.get( geometry ); var property = properties.get( geometry );
...@@ -197,6 +248,7 @@ function WebGLObjects( gl, properties, info ) { ...@@ -197,6 +248,7 @@ function WebGLObjects( gl, properties, info ) {
return { return {
getAttributeBuffer: getAttributeBuffer, getAttributeBuffer: getAttributeBuffer,
getAttributeProperties: getAttributeProperties,
getWireframeAttribute: getWireframeAttribute, getWireframeAttribute: getWireframeAttribute,
update: update update: update
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册