提交 118e1c47 编写于 作者: M Mr.doob

Clean up.

上级 c31b30a1
......@@ -545,13 +545,13 @@ Object.assign( Object3D.prototype, EventDispatcher.prototype, {
if ( this.matrixWorldNeedsUpdate || force ) {
if ( this.parent ) {
if ( this.parent === null ) {
this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
this.matrixWorld.copy( this.matrix );
} else {
this.matrixWorld.copy( this.matrix );
this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
}
......
......@@ -191,6 +191,11 @@ function WebGLRenderer( parameters ) {
// info
_infoMemory = {
geometries: 0,
textures: 0
},
_infoRender = {
frame: 0,
......@@ -204,12 +209,7 @@ function WebGLRenderer( parameters ) {
this.info = {
render: _infoRender,
memory: {
geometries: 0,
textures: 0
},
memory: _infoMemory,
programs: null
};
......@@ -287,9 +287,9 @@ function WebGLRenderer( parameters ) {
var state = new WebGLState( _gl, extensions, paramThreeToGL );
var properties = new WebGLProperties();
var textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, paramThreeToGL, this.info );
var textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, paramThreeToGL, _infoMemory );
var attributes = new WebGLAttributes( _gl );
var geometries = new WebGLGeometries( _gl, attributes, this.info );
var geometries = new WebGLGeometries( _gl, attributes, _infoMemory );
var objects = new WebGLObjects( _gl, geometries, _infoRender );
var programCache = new WebGLPrograms( this, capabilities );
var lightCache = new WebGLLights();
......@@ -1150,6 +1150,7 @@ function WebGLRenderer( parameters ) {
//
_infoRender.frame ++;
_infoRender.calls = 0;
_infoRender.vertices = 0;
_infoRender.faces = 0;
......@@ -1416,7 +1417,8 @@ function WebGLRenderer( parameters ) {
if ( sortObjects ) {
_vector3.setFromMatrixPosition( object.matrixWorld ).applyMatrix4( _projScreenMatrix );
_vector3.setFromMatrixPosition( object.matrixWorld )
.applyMatrix4( _projScreenMatrix );
}
......@@ -1434,7 +1436,8 @@ function WebGLRenderer( parameters ) {
if ( sortObjects ) {
_vector3.setFromMatrixPosition( object.matrixWorld ).applyMatrix4( _projScreenMatrix );
_vector3.setFromMatrixPosition( object.matrixWorld )
.applyMatrix4( _projScreenMatrix );
}
......
......@@ -8,13 +8,12 @@ function WebGLAttributes( gl ) {
function createBuffer( attribute, bufferType ) {
var buffer = gl.createBuffer();
gl.bindBuffer( bufferType, buffer );
var array = attribute.array;
var usage = attribute.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
var buffer = gl.createBuffer();
gl.bindBuffer( bufferType, buffer );
gl.bufferData( bufferType, array, usage );
attribute.onUploadCallback();
......@@ -66,33 +65,34 @@ function WebGLAttributes( gl ) {
function updateBuffer( buffer, attribute, bufferType ) {
var array = attribute.array;
var updateRange = attribute.updateRange;
gl.bindBuffer( bufferType, buffer );
if ( attribute.dynamic === false ) {
gl.bufferData( bufferType, attribute.array, gl.STATIC_DRAW );
gl.bufferData( bufferType, array, gl.STATIC_DRAW );
} else if ( attribute.updateRange.count === - 1 ) {
} else if ( updateRange.count === - 1 ) {
// Not using update ranges
gl.bufferSubData( bufferType, 0, attribute.array );
gl.bufferSubData( bufferType, 0, array );
} else if ( attribute.updateRange.count === 0 ) {
} else if ( updateRange.count === 0 ) {
console.error( 'THREE.WebGLObjects.updateBuffer: dynamic THREE.BufferAttribute marked as needsUpdate but updateRange.count is 0, ensure you are using set methods or updating manually.' );
} else {
gl.bufferSubData( bufferType, attribute.updateRange.offset * attribute.array.BYTES_PER_ELEMENT,
attribute.array.subarray( attribute.updateRange.offset, attribute.updateRange.offset + attribute.updateRange.count ) );
gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
attribute.updateRange.count = 0; // reset range
updateRange.count = 0; // reset range
}
}
//
......@@ -129,9 +129,10 @@ function WebGLAttributes( gl ) {
buffers[ attribute.id ] = createBuffer( attribute, bufferType );
} else if ( data.version !== attribute.version ) {
} else if ( data.version < attribute.version ) {
updateBuffer( data.buffer, attribute, bufferType );
data.version = attribute.version;
}
......
......@@ -6,7 +6,7 @@ import { Uint16BufferAttribute, Uint32BufferAttribute } from '../../core/BufferA
import { BufferGeometry } from '../../core/BufferGeometry';
import { arrayMax } from '../../utils';
function WebGLGeometries( gl, attributes, info ) {
function WebGLGeometries( gl, attributes, infoMemory ) {
var geometries = {};
var wireframeAttributes = {};
......@@ -54,13 +54,12 @@ function WebGLGeometries( gl, attributes, info ) {
//
info.memory.geometries --;
infoMemory.geometries --;
}
function get( object ) {
function get( object, geometry ) {
var geometry = object.geometry;
var buffergeometry = geometries[ geometry.id ];
if ( buffergeometry ) return buffergeometry;
......@@ -85,12 +84,47 @@ function WebGLGeometries( gl, attributes, info ) {
geometries[ geometry.id ] = buffergeometry;
info.memory.geometries ++;
infoMemory.geometries ++;
return buffergeometry;
}
function update( geometry ) {
var index = geometry.index;
var geometryAttributes = geometry.attributes;
if ( index !== null ) {
attributes.update( index, gl.ELEMENT_ARRAY_BUFFER );
}
for ( var name in geometryAttributes ) {
attributes.update( geometryAttributes[ name ], gl.ARRAY_BUFFER );
}
// morph targets
var morphAttributes = geometry.morphAttributes;
for ( var name in morphAttributes ) {
var array = morphAttributes[ name ];
for ( var i = 0, l = array.length; i < l; i ++ ) {
attributes.update( array[ i ], gl.ARRAY_BUFFER );
}
}
}
function getWireframeAttribute( geometry ) {
var attribute = wireframeAttributes[ geometry.id ];
......@@ -146,46 +180,12 @@ function WebGLGeometries( gl, attributes, info ) {
}
function update( geometry ) {
var index = geometry.index;
var geometryAttributes = geometry.attributes;
if ( index !== null ) {
attributes.update( index, gl.ELEMENT_ARRAY_BUFFER );
}
for ( var name in geometryAttributes ) {
attributes.update( geometryAttributes[ name ], gl.ARRAY_BUFFER );
}
// morph targets
var morphAttributes = geometry.morphAttributes;
for ( var name in morphAttributes ) {
var array = morphAttributes[ name ];
for ( var i = 0, l = array.length; i < l; i ++ ) {
attributes.update( array[ i ], gl.ARRAY_BUFFER );
}
}
}
return {
get: get,
getWireframeAttribute: getWireframeAttribute,
update: update
update: update,
getWireframeAttribute: getWireframeAttribute
};
......
......@@ -5,9 +5,8 @@
import { LinearFilter, NearestFilter, RGBFormat, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, ClampToEdgeWrapping, NearestMipMapLinearFilter, NearestMipMapNearestFilter } from '../../constants';
import { _Math } from '../../math/Math';
function WebGLTextures( _gl, extensions, state, properties, capabilities, paramThreeToGL, info ) {
function WebGLTextures( _gl, extensions, state, properties, capabilities, paramThreeToGL, infoMemory ) {
var _infoMemory = info.memory;
var _isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof WebGL2RenderingContext );
//
......@@ -96,7 +95,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, paramT
deallocateTexture( texture );
_infoMemory.textures --;
infoMemory.textures --;
}
......@@ -109,7 +108,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, paramT
deallocateRenderTarget( renderTarget );
_infoMemory.textures --;
infoMemory.textures --;
}
......@@ -228,7 +227,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, paramT
textureProperties.__image__webglTextureCube = _gl.createTexture();
_infoMemory.textures ++;
infoMemory.textures ++;
}
......@@ -399,7 +398,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, paramT
textureProperties.__webglTexture = _gl.createTexture();
_infoMemory.textures ++;
infoMemory.textures ++;
}
......@@ -700,7 +699,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, paramT
textureProperties.__webglTexture = _gl.createTexture();
_infoMemory.textures ++;
infoMemory.textures ++;
var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册