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

Discard attribute typed arrays for buffered geometries that are not modified...

Discard attribute typed arrays for buffered geometries that are not modified after initial rendering (#9512)

* add setDiscardBuffer method to BufferGeometry

* added discard support to BufferAttribute

* add mechanism for discard of BufferAttribute TypedArrays

* use more elegant method for creating dummy typed array.

* fix typo

* Update BufferGeometry.js

fix brain fade

* rework to use callbacks (phase 1)

* rework part 2

* remove build file

* support setting onUploadCallback from Geometry

* remove repeated calculation from renderer

* remove now redundant getter

* remove geoemtry interface

* document discard mechanism.

* merge fixes

* restore return.this

* drop unneeded call()

* rename discard() method to disposeArray()
上级 d0b259b1
......@@ -54,6 +54,11 @@
A version number, incremented every time the needsUpdate property is set to true.
</div>
<h3>[property:Function onUploadCallback]</h3>
<div>
A callback function that is executed after the Renderer has transfered the attribute array data to the GPU.
The callback is executed with a single parameter "name", the name of the buffer attribute, and "this" set to the BufferAttribute object.
</div>
<h2>Methods</h2>
......@@ -108,6 +113,12 @@
Copies this attribute.
</div>
<h3>[method:null disposeArray]() </h3>
<div>
Discards the typed array containing the attribute data. This can be executed after the data has been transfered to the GPU to allow the memory to be reclaimed.
For use where the attribute will not be changed after the discard method is called.
</div>
<h2>Source</h2>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
......
......@@ -27,6 +27,7 @@ function BufferAttribute( array, itemSize, normalized ) {
this.updateRange = { offset: 0, count: - 1 };
this.version = 0;
this.onUploadCallback = null;
}
......@@ -323,6 +324,14 @@ BufferAttribute.prototype = {
return new this.constructor().copy( this );
},
disposeArray: function () {
var oldArray = this.array;
this.array = new oldArray.constructor( 1 ); // create dummy minimal length TypedArray
}
};
......
......@@ -34,7 +34,7 @@ function WebGLObjects( gl, properties, info ) {
for ( var name in attributes ) {
updateAttribute( attributes[ name ], gl.ARRAY_BUFFER );
updateAttribute( attributes[ name ], gl.ARRAY_BUFFER, name );
}
......@@ -58,7 +58,7 @@ function WebGLObjects( gl, properties, info ) {
}
function updateAttribute( attribute, bufferType ) {
function updateAttribute( attribute, bufferType, name ) {
var data = ( attribute.isInterleavedBufferAttribute ) ? attribute.data : attribute;
......@@ -66,7 +66,7 @@ function WebGLObjects( gl, properties, info ) {
if ( attributeProperties.__webglBuffer === undefined ) {
createBuffer( attributeProperties, data, bufferType );
createBuffer( attributeProperties, data, bufferType, name );
} else if ( attributeProperties.version !== data.version ) {
......@@ -76,7 +76,7 @@ function WebGLObjects( gl, properties, info ) {
}
function createBuffer( attributeProperties, data, bufferType ) {
function createBuffer( attributeProperties, data, bufferType, name ) {
attributeProperties.__webglBuffer = gl.createBuffer();
gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
......@@ -126,6 +126,12 @@ function WebGLObjects( gl, properties, info ) {
attributeProperties.type = type;
attributeProperties.version = data.version;
if ( data.onUploadCallback ) {
data.onUploadCallback( name );
}
}
function updateBuffer( attributeProperties, data, bufferType ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册