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

capture bufferAttribute.array properties at first upload #9972

Merged
merged 3 commits into from
Nov 5, 2016
Merged
Show file tree
Hide file tree
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
46 changes: 7 additions & 39 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -945,46 +945,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 ) {

Expand All @@ -1009,7 +977,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 {

Expand All @@ -1030,7 +998,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 );

}

Expand Down
52 changes: 52 additions & 0 deletions src/renderers/webgl/WebGLObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Expand Down Expand Up @@ -128,6 +167,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 );
Expand Down Expand Up @@ -193,6 +244,7 @@ function WebGLObjects( gl, properties, info ) {
return {

getAttributeBuffer: getAttributeBuffer,
getAttributeProperties: getAttributeProperties,
getWireframeAttribute: getWireframeAttribute,

update: update
Expand Down