Permalink
Browse files

Removed surprising bottleneck in WebGLRenderer.

I knew for loops iterating over properties were slower than numerical for loops but I didn't realize how bad it was.

Gained about 10 fps in performance test, and that was for for loop iterating over single property.

Also fixed broken examples with postprocessing.
  • Loading branch information...
1 parent 7595221 commit ca05c86fc5d7c9fdefb00d45c5d9c0ae8fee3720 @alteredq alteredq committed Sep 2, 2011
Showing with 430 additions and 420 deletions.
  1. +266 −266 build/Three.js
  2. +147 −147 build/custom/ThreeWebGL.js
  3. +2 −0 examples/webgl_geometry_text.html
  4. +1 −0 examples/webgl_materials_video.html
  5. +14 −7 src/renderers/WebGLRenderer.js
View
532 build/Three.js
266 additions, 266 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
294 build/custom/ThreeWebGL.js
147 additions, 147 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
2 examples/webgl_geometry_text.html
@@ -45,6 +45,8 @@
<script type="text/javascript" src="js/postprocessing/EffectComposer.js"></script>
<script type="text/javascript" src="js/postprocessing/RenderPass.js"></script>
+ <script type="text/javascript" src="js/postprocessing/ShaderPass.js"></script>
+ <script type="text/javascript" src="js/postprocessing/MaskPass.js"></script>
<script type="text/javascript" src="js/postprocessing/BloomPass.js"></script>
<script type="text/javascript" src="js/postprocessing/FilmPass.js"></script>
View
1 examples/webgl_materials_video.html
@@ -42,6 +42,7 @@
<script type="text/javascript" src="js/postprocessing/EffectComposer.js"></script>
<script type="text/javascript" src="js/postprocessing/RenderPass.js"></script>
+ <script type="text/javascript" src="js/postprocessing/MaskPass.js"></script>
<script type="text/javascript" src="js/postprocessing/BloomPass.js"></script>
<script type="text/javascript" src="js/postprocessing/ShaderPass.js"></script>
View
21 src/renderers/WebGLRenderer.js
@@ -4207,7 +4207,6 @@ THREE.WebGLRenderer = function ( parameters ) {
}
-
return false;
};
@@ -4246,9 +4245,9 @@ THREE.WebGLRenderer = function ( parameters ) {
// check all geometry groups
- for ( g in geometry.geometryGroups ) {
+ for( var i = 0, il = geometry.geometryGroupsList.length; i < il; i ++ ) {
- geometryGroup = geometry.geometryGroups[ g ];
+ geometryGroup = geometry.geometryGroupsList[ i ];
customAttributeDirty = areCustomAttributesDirty( geometryGroup );
@@ -4400,7 +4399,7 @@ THREE.WebGLRenderer = function ( parameters ) {
var hash_array = [];
- for ( i = 0, l = material.length; i < l; i++ ) {
+ for ( i = 0, l = material.length; i < l; i ++ ) {
if ( material[ i ] == undefined ) {
@@ -4418,7 +4417,7 @@ THREE.WebGLRenderer = function ( parameters ) {
}
- for ( f = 0, fl = geometry.faces.length; f < fl; f++ ) {
+ for ( f = 0, fl = geometry.faces.length; f < fl; f ++ ) {
face = geometry.faces[ f ];
materials = face.materials;
@@ -4459,6 +4458,14 @@ THREE.WebGLRenderer = function ( parameters ) {
}
+ geometry.geometryGroupsList = [];
+
+ for ( var g in geometry.geometryGroups ) {
+
+ geometry.geometryGroupsList.push( geometry.geometryGroups[ g ] );
+
+ }
+
};
function addBuffer( objlist, buffer, object ) {
@@ -5420,13 +5427,13 @@ THREE.WebGLRenderer = function ( parameters ) {
material, meshMaterial,
materials = [];
- for ( m = 0, ml = object.materials.length; m < ml; m++ ) {
+ for ( m = 0, ml = object.materials.length; m < ml; m ++ ) {
meshMaterial = object.materials[ m ];
if ( meshMaterial instanceof THREE.MeshFaceMaterial ) {
- for ( i = 0, l = geometryGroup.materials.length; i < l; i++ ) {
+ for ( i = 0, l = geometryGroup.materials.length; i < l; i ++ ) {
material = geometryGroup.materials[ i ];

0 comments on commit ca05c86

Please sign in to comment.