|
@@ -71,26 +71,13 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
this.autoScaleCubemaps = true;
|
|
|
|
|
|
- // info
|
|
|
+ // info (see below for details)
|
|
|
|
|
|
this.info = {
|
|
|
|
|
|
- memory: {
|
|
|
-
|
|
|
- programs: 0,
|
|
|
- geometries: 0,
|
|
|
- textures: 0
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- render: {
|
|
|
-
|
|
|
- calls: 0,
|
|
|
- vertices: 0,
|
|
|
- faces: 0,
|
|
|
- points: 0
|
|
|
-
|
|
|
- }
|
|
|
+ render: null,
|
|
|
+ memory: null,
|
|
|
+ programs: null
|
|
|
|
|
|
};
|
|
|
|
|
@@ -141,8 +128,30 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
spot: { length: 0, colors: [], positions: [], distances: [], directions: [], anglesCos: [], exponents: [], decays: [] },
|
|
|
hemi: { length: 0, skyColors: [], groundColors: [], positions: [] }
|
|
|
|
|
|
+ },
|
|
|
+
|
|
|
+ _infoMemory = {
|
|
|
+
|
|
|
+ programs: 0,
|
|
|
+ geometries: 0,
|
|
|
+ textures: 0
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ _infoRender = {
|
|
|
+
|
|
|
+ calls: 0,
|
|
|
+ vertices: 0,
|
|
|
+ faces: 0,
|
|
|
+ points: 0
|
|
|
+
|
|
|
};
|
|
|
|
|
|
+ this.info.render = _infoRender;
|
|
|
+ this.info.memory = _infoMemory;
|
|
|
+ this.info.programs = _programs;
|
|
|
+
|
|
|
+
|
|
|
// initialize
|
|
|
|
|
|
var _gl;
|
|
@@ -612,7 +621,7 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
deallocateTexture( texture );
|
|
|
|
|
|
- _this.info.memory.textures --;
|
|
|
+ _infoMemory.textures --;
|
|
|
|
|
|
|
|
|
};
|
|
@@ -625,7 +634,7 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
deallocateRenderTarget( renderTarget );
|
|
|
|
|
|
- _this.info.memory.textures --;
|
|
|
+ _infoMemory.textures --;
|
|
|
|
|
|
};
|
|
|
|
|
@@ -696,6 +705,15 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
var deallocateMaterial = function ( material ) {
|
|
|
|
|
|
+ releaseMaterialProgramReference( material );
|
|
|
+
|
|
|
+ properties.delete( material );
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ function releaseMaterialProgramReference ( material ) {
|
|
|
+
|
|
|
var program = properties.get( material ).program.program;
|
|
|
|
|
|
if ( program === undefined ) return;
|
|
@@ -731,33 +749,19 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
if ( deleteProgram === true ) {
|
|
|
|
|
|
- // avoid using array.splice, this is costlier than creating new array from scratch
|
|
|
-
|
|
|
- var newPrograms = [];
|
|
|
-
|
|
|
- for ( i = 0, il = _programs.length; i < il; i ++ ) {
|
|
|
-
|
|
|
- programInfo = _programs[ i ];
|
|
|
+ // avoid using array.splice, instead replace with last and pop
|
|
|
|
|
|
- if ( programInfo.program !== program ) {
|
|
|
-
|
|
|
- newPrograms.push( programInfo );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ _programs[ i ] = _programs[ il - 1 ];
|
|
|
+ _programs.pop();
|
|
|
|
|
|
- _programs = newPrograms;
|
|
|
|
|
|
_gl.deleteProgram( program );
|
|
|
|
|
|
- _this.info.memory.programs --;
|
|
|
+ _infoMemory.programs --;
|
|
|
|
|
|
}
|
|
|
|
|
|
- properties.delete( material );
|
|
|
-
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
// Buffer rendering
|
|
|
|
|
@@ -1101,9 +1105,9 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
_gl.drawElements( mode, index.array.length, type, 0 );
|
|
|
|
|
|
}
|
|
|
- _this.info.render.calls ++;
|
|
|
- _this.info.render.vertices += index.array.length; // not really true, here vertices can be shared
|
|
|
- _this.info.render.faces += index.array.length / 3;
|
|
|
+ _infoRender.calls ++;
|
|
|
+ _infoRender.vertices += index.array.length; // not really true, here vertices can be shared
|
|
|
+ _infoRender.faces += index.array.length / 3;
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -1145,9 +1149,9 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- _this.info.render.calls ++;
|
|
|
- _this.info.render.vertices += offsets[ i ].count; // not really true, here vertices can be shared
|
|
|
- _this.info.render.faces += offsets[ i ].count / 3;
|
|
|
+ _infoRender.calls ++;
|
|
|
+ _infoRender.vertices += offsets[ i ].count; // not really true, here vertices can be shared
|
|
|
+ _infoRender.faces += offsets[ i ].count / 3;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1206,9 +1210,9 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- _this.info.render.calls++;
|
|
|
- _this.info.render.vertices += position.count;
|
|
|
- _this.info.render.faces += position.count / 3;
|
|
|
+ _infoRender.calls++;
|
|
|
+ _infoRender.vertices += position.count;
|
|
|
+ _infoRender.faces += position.array.length / 3;
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -1237,9 +1241,9 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- _this.info.render.calls++;
|
|
|
- _this.info.render.vertices += offsets[ i ].count;
|
|
|
- _this.info.render.faces += ( offsets[ i ].count ) / 3;
|
|
|
+ _infoRender.calls++;
|
|
|
+ _infoRender.vertices += offsets[ i ].count;
|
|
|
+ _infoRender.faces += ( offsets[ i ].count ) / 3;
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -1291,8 +1295,8 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
_gl.drawElements( mode, index.array.length, type, 0 ); // 2 bytes per Uint16Array
|
|
|
|
|
|
- _this.info.render.calls ++;
|
|
|
- _this.info.render.vertices += index.array.length; // not really true, here vertices can be shared
|
|
|
+ _infoRender.calls ++;
|
|
|
+ _infoRender.vertices += index.array.length; // not really true, here vertices can be shared
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -1317,8 +1321,8 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
_gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size ); // 2 bytes per Uint16Array
|
|
|
|
|
|
- _this.info.render.calls ++;
|
|
|
- _this.info.render.vertices += offsets[ i ].count; // not really true, here vertices can be shared
|
|
|
+ _infoRender.calls ++;
|
|
|
+ _infoRender.vertices += offsets[ i ].count; // not really true, here vertices can be shared
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1341,8 +1345,8 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
_gl.drawArrays( mode, 0, position.array.length / 3 );
|
|
|
|
|
|
- _this.info.render.calls ++;
|
|
|
- _this.info.render.vertices += position.array.length / 3;
|
|
|
+ _infoRender.calls ++;
|
|
|
+ _infoRender.vertices += position.array.length / 3;
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -1350,8 +1354,8 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
_gl.drawArrays( mode, offsets[ i ].index, offsets[ i ].count );
|
|
|
|
|
|
- _this.info.render.calls ++;
|
|
|
- _this.info.render.vertices += offsets[ i ].count;
|
|
|
+ _infoRender.calls ++;
|
|
|
+ _infoRender.vertices += offsets[ i ].count;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1400,8 +1404,8 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
_gl.drawElements( mode, index.array.length, type, 0);
|
|
|
|
|
|
- _this.info.render.calls ++;
|
|
|
- _this.info.render.points += index.array.length;
|
|
|
+ _infoRender.calls ++;
|
|
|
+ _infoRender.points += index.array.length;
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -1426,8 +1430,8 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
_gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size );
|
|
|
|
|
|
- _this.info.render.calls ++;
|
|
|
- _this.info.render.points += offsets[ i ].count;
|
|
|
+ _infoRender.calls ++;
|
|
|
+ _infoRender.points += offsets[ i ].count;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1450,8 +1454,8 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
_gl.drawArrays( mode, 0, position.array.length / 3 );
|
|
|
|
|
|
- _this.info.render.calls ++;
|
|
|
- _this.info.render.points += position.array.length / 3;
|
|
|
+ _infoRender.calls ++;
|
|
|
+ _infoRender.points += position.array.length / 3;
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -1459,8 +1463,8 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
_gl.drawArrays( mode, offsets[ i ].index, offsets[ i ].count );
|
|
|
|
|
|
- _this.info.render.calls ++;
|
|
|
- _this.info.render.points += offsets[ i ].count;
|
|
|
+ _infoRender.calls ++;
|
|
|
+ _infoRender.points += offsets[ i ].count;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1570,10 +1574,10 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
//
|
|
|
|
|
|
- _this.info.render.calls = 0;
|
|
|
- _this.info.render.vertices = 0;
|
|
|
- _this.info.render.faces = 0;
|
|
|
- _this.info.render.points = 0;
|
|
|
+ _infoRender.calls = 0;
|
|
|
+ _infoRender.vertices = 0;
|
|
|
+ _infoRender.faces = 0;
|
|
|
+ _infoRender.points = 0;
|
|
|
|
|
|
this.setRenderTarget( renderTarget );
|
|
|
|
|
@@ -1932,6 +1936,7 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
}
|
|
|
|
|
|
var code = chunks.join();
|
|
|
+ var programChange = true;
|
|
|
|
|
|
if ( !materialProperties.program ) {
|
|
|
|
|
@@ -1941,17 +1946,17 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
} else if ( materialProperties.program.code !== code ) {
|
|
|
|
|
|
// changed glsl or parameters
|
|
|
- deallocateMaterial( material );
|
|
|
+ releaseMaterialProgramReference( material );
|
|
|
|
|
|
} else if ( shaderID !== undefined ) {
|
|
|
|
|
|
- // same glsl
|
|
|
+ // same glsl and uniform list
|
|
|
return;
|
|
|
|
|
|
- } else if ( materialProperties.__webglShader.uniforms === material.uniforms ) {
|
|
|
+ } else {
|
|
|
|
|
|
- // same uniforms (container object)
|
|
|
- return;
|
|
|
+ // only rebuild uniform list
|
|
|
+ programChange = false;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1988,7 +1993,12 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
if ( programInfo.code === code ) {
|
|
|
|
|
|
program = programInfo;
|
|
|
- program.usedTimes ++;
|
|
|
+
|
|
|
+ if ( programChange ) {
|
|
|
+
|
|
|
+ program.usedTimes ++;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
break;
|
|
|
|
|
@@ -2002,7 +2012,7 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
program = new THREE.WebGLProgram( _this, code, material, parameters );
|
|
|
_programs.push( program );
|
|
|
|
|
|
- _this.info.memory.programs = _programs.length;
|
|
|
+ _infoMemory.programs = _programs.length;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -3246,7 +3256,7 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
textureProperties.__webglTexture = _gl.createTexture();
|
|
|
|
|
|
- _this.info.memory.textures ++;
|
|
|
+ _infoMemory.textures ++;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -3427,7 +3437,7 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
textureProperties.__image__webglTextureCube = _gl.createTexture();
|
|
|
|
|
|
- _this.info.memory.textures ++;
|
|
|
+ _infoMemory.textures ++;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -3588,7 +3598,7 @@ THREE.WebGLRenderer = function ( parameters ) {
|
|
|
|
|
|
renderTargetProperties.__webglTexture = _gl.createTexture();
|
|
|
|
|
|
- _this.info.memory.textures ++;
|
|
|
+ _infoMemory.textures ++;
|
|
|
|
|
|
// Setup texture, create render and frame buffers
|
|
|
|