提交 55c5baf6 编写于 作者: D dubejf

Extract createBuffer and updateBuffer

上级 e29f28d6
......@@ -167,8 +167,7 @@ THREE.WebGLObjects = function ( gl, properties, info ) {
for ( var name in attributes ) {
var attribute = attributes[ name ];
updateAttribute( attribute, name );
updateAttribute( attributes[ name ], name );
}
......@@ -184,64 +183,74 @@ THREE.WebGLObjects = function ( gl, properties, info ) {
if ( attributeProperties.__webglBuffer === undefined ) {
attributeProperties.__webglBuffer = gl.createBuffer();
gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
createBuffer( attributeProperties, data, bufferType );
var usage = gl.STATIC_DRAW;
} else if ( data.needsUpdate === true ) {
if ( data instanceof THREE.DynamicBufferAttribute
|| ( data instanceof THREE.InstancedBufferAttribute && data.dynamic === true )
|| ( data instanceof THREE.InterleavedBuffer && data.dynamic === true ) ) {
updateBuffer( attributeProperties, data, bufferType );
usage = gl.DYNAMIC_DRAW;
}
}
}
gl.bufferData( bufferType, data.array, usage );
function createBuffer ( attributeProperties, data, bufferType ) {
data.needsUpdate = false;
attributeProperties.__webglBuffer = gl.createBuffer();
gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
} else if ( data.needsUpdate === true ) {
var usage = gl.STATIC_DRAW;
gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
if ( data instanceof THREE.DynamicBufferAttribute
|| ( data instanceof THREE.InstancedBufferAttribute && data.dynamic === true )
|| ( data instanceof THREE.InterleavedBuffer && data.dynamic === true ) ) {
if ( data.updateRange === undefined || data.updateRange.count === -1 ) { // Not using update ranges
usage = gl.DYNAMIC_DRAW;
gl.bufferSubData( bufferType, 0, data.array );
}
} else if ( data.updateRange.count === 0 ) {
gl.bufferData( bufferType, data.array, usage );
console.error( 'THREE.WebGLRenderer.updateObject: using updateRange for THREE.DynamicBufferAttribute and marked as needsUpdate but count is 0, ensure you are using set methods or updating manually.' );
data.needsUpdate = false;
} else {
}
gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
function updateBuffer( attributeProperties, data, bufferType ) {
data.updateRange.count = 0; // reset range
gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
}
if ( data.updateRange === undefined || data.updateRange.count === -1 ) { // Not using update ranges
data.needsUpdate = false;
gl.bufferSubData( bufferType, 0, data.array );
}
} else if ( data.updateRange.count === 0 ) {
}
console.error( 'THREE.WebGLRenderer.updateObject: using updateRange for THREE.DynamicBufferAttribute and marked as needsUpdate but count is 0, ensure you are using set methods or updating manually.' );
} else {
gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
data.updateRange.count = 0; // reset range
}
data.needsUpdate = false;
}
// returns the webgl buffer for a specified attribute
this.getAttributeBuffer = function ( attribute ) {
if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
return properties.get( attribute.data ).__webglBuffer
return properties.get( attribute.data ).__webglBuffer;
}
return properties.get( attribute ).__webglBuffer;
}
};
this.update = function ( renderList ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册