David Catuhe 9 年之前
父節點
當前提交
b7937b24e5

文件差異過大導致無法顯示
+ 2 - 2
dist/preview release/babylon.core.js


文件差異過大導致無法顯示
+ 3910 - 3911
dist/preview release/babylon.d.ts


文件差異過大導致無法顯示
+ 15 - 15
dist/preview release/babylon.js


+ 46 - 57
dist/preview release/babylon.max.js

@@ -6213,6 +6213,7 @@ var BABYLON;
             this._maxTextureChannels = 16;
             this._activeTexturesCache = new Array(this._maxTextureChannels);
             this._compiledEffects = {};
+            this._vertexAttribArraysEnabled = [];
             this._uintIndicesCurrentlySet = false;
             this._currentBoundBuffer = new Array();
             this._currentBufferPointers = [];
@@ -6269,6 +6270,7 @@ var BABYLON;
             this._caps.maxTextureSize = this._gl.getParameter(this._gl.MAX_TEXTURE_SIZE);
             this._caps.maxCubemapTextureSize = this._gl.getParameter(this._gl.MAX_CUBE_MAP_TEXTURE_SIZE);
             this._caps.maxRenderTextureSize = this._gl.getParameter(this._gl.MAX_RENDERBUFFER_SIZE);
+            this._caps.maxVertexAttribs = this._gl.getParameter(this._gl.MAX_VERTEX_ATTRIBS);
             // Infos
             this._glVersion = this._gl.getParameter(this._gl.VERSION);
             var rendererInfo = this._gl.getExtension("WEBGL_debug_renderer_info");
@@ -7003,13 +7005,28 @@ var BABYLON;
             if (this._cachedVertexBuffers !== vertexBuffer || this._cachedEffectForVertexBuffers !== effect) {
                 this._cachedVertexBuffers = vertexBuffer;
                 this._cachedEffectForVertexBuffers = effect;
+                var attributesCount = effect.getAttributesCount();
                 var offset = 0;
-                for (var index = 0; index < vertexDeclaration.length; index++) {
-                    var order = effect.getAttributeLocation(index);
-                    if (order >= 0) {
-                        this.vertexAttribPointer(vertexBuffer, order, vertexDeclaration[index], this._gl.FLOAT, false, vertexStrideSize, offset);
+                for (var index = 0; index < attributesCount; index++) {
+                    if (index < vertexDeclaration.length) {
+                        var order = effect.getAttributeLocation(index);
+                        if (order >= 0) {
+                            if (!this._vertexAttribArraysEnabled[order]) {
+                                this._gl.enableVertexAttribArray(order);
+                                this._vertexAttribArraysEnabled[order] = true;
+                            }
+                            this.vertexAttribPointer(vertexBuffer, order, vertexDeclaration[index], this._gl.FLOAT, false, vertexStrideSize, offset);
+                        }
+                        offset += vertexDeclaration[index] * 4;
+                    }
+                    else {
+                        //disable effect attributes that have no data
+                        var order = effect.getAttributeLocation(index);
+                        if (this._vertexAttribArraysEnabled[order]) {
+                            this._gl.disableVertexAttribArray(order);
+                            this._vertexAttribArraysEnabled[order] = false;
+                        }
                     }
-                    offset += vertexDeclaration[index] * 4;
                 }
             }
             if (this._cachedIndexBuffer !== indexBuffer) {
@@ -7028,8 +7045,16 @@ var BABYLON;
                     if (order >= 0) {
                         var vertexBuffer = vertexBuffers[attributes[index]];
                         if (!vertexBuffer) {
+                            if (this._vertexAttribArraysEnabled[order]) {
+                                this._gl.disableVertexAttribArray(order);
+                                this._vertexAttribArraysEnabled[order] = false;
+                            }
                             continue;
                         }
+                        if (!this._vertexAttribArraysEnabled[order]) {
+                            this._gl.enableVertexAttribArray(order);
+                            this._vertexAttribArraysEnabled[order] = true;
+                        }
                         var buffer = vertexBuffer.getBuffer();
                         this.vertexAttribPointer(buffer, order, vertexBuffer.getSize(), this._gl.FLOAT, false, vertexBuffer.getStrideSize() * 4, vertexBuffer.getOffset() * 4);
                         if (vertexBuffer.getIsInstanced()) {
@@ -7091,7 +7116,10 @@ var BABYLON;
                 }
                 for (var i = 0; i < offsetLocations.length; i++) {
                     var ai = offsetLocations[i];
-                    this._gl.enableVertexAttribArray(ai.index);
+                    if (!this._vertexAttribArraysEnabled[ai.index]) {
+                        this._gl.enableVertexAttribArray(ai.index);
+                        this._vertexAttribArraysEnabled[ai.index] = true;
+                    }
                     this.vertexAttribPointer(instancesBuffer, ai.index, ai.attributeSize, ai.attribyteType || this._gl.FLOAT, ai.normalized || false, stride, ai.offset);
                     this._caps.instancedArrays.vertexAttribDivisorANGLE(ai.index, 1);
                     this._currentInstanceLocations.push(ai.index);
@@ -7101,7 +7129,10 @@ var BABYLON;
             else {
                 for (var index = 0; index < 4; index++) {
                     var offsetLocation = offsetLocations[index];
-                    this._gl.enableVertexAttribArray(offsetLocation);
+                    if (!this._vertexAttribArraysEnabled[offsetLocation]) {
+                        this._gl.enableVertexAttribArray(offsetLocation);
+                        this._vertexAttribArraysEnabled[offsetLocation] = true;
+                    }
                     this.vertexAttribPointer(instancesBuffer, offsetLocation, 4, this._gl.FLOAT, false, 64, index * 16);
                     this._caps.instancedArrays.vertexAttribDivisorANGLE(offsetLocation, 1);
                     this._currentInstanceLocations.push(offsetLocation);
@@ -7222,35 +7253,8 @@ var BABYLON;
                 }
                 return;
             }
-            this._vertexAttribArraysToUse = this._vertexAttribArraysToUse || [];
-            this._vertexAttribArraysEnabled = this._vertexAttribArraysEnabled || [];
             // Use program
             this.setProgram(effect.getProgram());
-            var i, ul;
-            for (i = 0, ul = this._vertexAttribArraysToUse.length; i < ul; i++) {
-                this._vertexAttribArraysToUse[i] = false;
-            }
-            var attributesCount = effect.getAttributesCount();
-            for (i = 0; i < attributesCount; i++) {
-                // Attributes
-                var order = effect.getAttributeLocation(i);
-                if (order >= 0) {
-                    this._vertexAttribArraysToUse[order] = true;
-                }
-            }
-            for (i = 0, ul = this._vertexAttribArraysEnabled.length; i < ul; i++) {
-                if (i > this._gl.VERTEX_ATTRIB_ARRAY_ENABLED || !this._vertexAttribArraysEnabled[i] || this._vertexAttribArraysToUse[i]) {
-                    continue;
-                }
-                this._vertexAttribArraysEnabled[i] = false;
-                this._gl.disableVertexAttribArray(i);
-            }
-            for (i = 0, ul = this._vertexAttribArraysToUse.length; i < ul; i++) {
-                if (this._vertexAttribArraysToUse[i] && !this._vertexAttribArraysEnabled[i]) {
-                    this._vertexAttribArraysEnabled[i] = true;
-                    this._gl.enableVertexAttribArray(i);
-                }
-            }
             this._currentEffect = effect;
             if (effect.onBind) {
                 effect.onBind(effect);
@@ -8320,13 +8324,11 @@ var BABYLON;
                 this._gl.deleteProgram(this._compiledEffects[name]._program);
             }
             // Unbind
-            if (this._vertexAttribArraysEnabled) {
-                for (var i = 0, ul = this._vertexAttribArraysEnabled.length; i < ul; i++) {
-                    if (i > this._gl.VERTEX_ATTRIB_ARRAY_ENABLED || !this._vertexAttribArraysEnabled[i]) {
-                        continue;
-                    }
-                    this._gl.disableVertexAttribArray(i);
+            for (var i = 0, ul = this._vertexAttribArraysEnabled.length; i < ul; i++) {
+                if (i >= this._caps.maxVertexAttribs || !this._vertexAttribArraysEnabled[i]) {
+                    continue;
                 }
+                this._gl.disableVertexAttribArray(i);
             }
             this._gl = null;
             // Events
@@ -42149,7 +42151,7 @@ var BABYLON;
             this.groupInsanceInfo = null;
             this.startZ = 0;
             this.endZ = 0;
-            this.startDataIndex = 0;
+            this.startDataIndex = BABYLON.Prim2DBase._bigInt;
             this.endDataIndex = 0;
             this.partBuffers = null;
         }
@@ -43005,21 +43007,8 @@ var BABYLON;
                         minOff = Math.min(minOff, el.offset);
                         maxOff = Math.max(maxOff, el.offset);
                     }
-                    ts.startDataIndex = minOff / part.dataBuffer.stride;
-                    ts.endDataIndex = (maxOff / part.dataBuffer.stride) + 1; // +1 for exclusive
-                }
-            }
-        };
-        RenderablePrim2D.prototype._getPrimitiveLastIndex = function () {
-            var maxOff = 0;
-            for (var _i = 0, _a = this._instanceDataParts; _i < _a.length; _i++) {
-                var part = _a[_i];
-                if (part) {
-                    for (var _b = 0, _c = part.dataElements; _b < _c.length; _b++) {
-                        var el = _c[_b];
-                        maxOff = Math.max(maxOff, el.offset);
-                    }
-                    return (maxOff / part.dataBuffer.stride) + 1; // +1 for exclusive
+                    ts.startDataIndex = Math.min(ts.startDataIndex, minOff / part.dataBuffer.stride);
+                    ts.endDataIndex = Math.max(ts.endDataIndex, (maxOff / part.dataBuffer.stride) + 1); // +1 for exclusive
                 }
             }
         };
@@ -43924,7 +43913,7 @@ var BABYLON;
                 //let tpiZ = tpi._primitive.actualZOffset;
                 // We've made it so far, the tpi can be part of the segment, add it
                 tpi._transparentSegment = seg;
-                seg.endDataIndex = tpi._primitive._getPrimitiveLastIndex();
+                tpi._primitive._updateTransparentSegmentIndices(seg);
                 return true;
             };
             // Free the existing TransparentSegments

文件差異過大導致無法顯示
+ 15 - 15
dist/preview release/babylon.noworker.js


+ 1 - 1
src/Canvas2d/babylon.group2d.js

@@ -463,7 +463,7 @@ var BABYLON;
                 //let tpiZ = tpi._primitive.actualZOffset;
                 // We've made it so far, the tpi can be part of the segment, add it
                 tpi._transparentSegment = seg;
-                seg.endDataIndex = tpi._primitive._getPrimitiveLastIndex();
+                tpi._primitive._updateTransparentSegmentIndices(seg);
                 return true;
             };
             // Free the existing TransparentSegments

+ 1 - 1
src/Canvas2d/babylon.modelRenderCache.js

@@ -128,7 +128,7 @@ var BABYLON;
             this.groupInsanceInfo = null;
             this.startZ = 0;
             this.endZ = 0;
-            this.startDataIndex = 0;
+            this.startDataIndex = BABYLON.Prim2DBase._bigInt;
             this.endDataIndex = 0;
             this.partBuffers = null;
         }

+ 2 - 15
src/Canvas2d/babylon.renderablePrim2d.js

@@ -676,21 +676,8 @@ var BABYLON;
                         minOff = Math.min(minOff, el.offset);
                         maxOff = Math.max(maxOff, el.offset);
                     }
-                    ts.startDataIndex = minOff / part.dataBuffer.stride;
-                    ts.endDataIndex = (maxOff / part.dataBuffer.stride) + 1; // +1 for exclusive
-                }
-            }
-        };
-        RenderablePrim2D.prototype._getPrimitiveLastIndex = function () {
-            var maxOff = 0;
-            for (var _i = 0, _a = this._instanceDataParts; _i < _a.length; _i++) {
-                var part = _a[_i];
-                if (part) {
-                    for (var _b = 0, _c = part.dataElements; _b < _c.length; _b++) {
-                        var el = _c[_b];
-                        maxOff = Math.max(maxOff, el.offset);
-                    }
-                    return (maxOff / part.dataBuffer.stride) + 1; // +1 for exclusive
+                    ts.startDataIndex = Math.min(ts.startDataIndex, minOff / part.dataBuffer.stride);
+                    ts.endDataIndex = Math.max(ts.endDataIndex, (maxOff / part.dataBuffer.stride) + 1); // +1 for exclusive
                 }
             }
         };

+ 42 - 40
src/babylon.engine.js

@@ -157,6 +157,7 @@ var BABYLON;
             this._maxTextureChannels = 16;
             this._activeTexturesCache = new Array(this._maxTextureChannels);
             this._compiledEffects = {};
+            this._vertexAttribArraysEnabled = [];
             this._uintIndicesCurrentlySet = false;
             this._currentBoundBuffer = new Array();
             this._currentBufferPointers = [];
@@ -213,6 +214,7 @@ var BABYLON;
             this._caps.maxTextureSize = this._gl.getParameter(this._gl.MAX_TEXTURE_SIZE);
             this._caps.maxCubemapTextureSize = this._gl.getParameter(this._gl.MAX_CUBE_MAP_TEXTURE_SIZE);
             this._caps.maxRenderTextureSize = this._gl.getParameter(this._gl.MAX_RENDERBUFFER_SIZE);
+            this._caps.maxVertexAttribs = this._gl.getParameter(this._gl.MAX_VERTEX_ATTRIBS);
             // Infos
             this._glVersion = this._gl.getParameter(this._gl.VERSION);
             var rendererInfo = this._gl.getExtension("WEBGL_debug_renderer_info");
@@ -947,13 +949,28 @@ var BABYLON;
             if (this._cachedVertexBuffers !== vertexBuffer || this._cachedEffectForVertexBuffers !== effect) {
                 this._cachedVertexBuffers = vertexBuffer;
                 this._cachedEffectForVertexBuffers = effect;
+                var attributesCount = effect.getAttributesCount();
                 var offset = 0;
-                for (var index = 0; index < vertexDeclaration.length; index++) {
-                    var order = effect.getAttributeLocation(index);
-                    if (order >= 0) {
-                        this.vertexAttribPointer(vertexBuffer, order, vertexDeclaration[index], this._gl.FLOAT, false, vertexStrideSize, offset);
+                for (var index = 0; index < attributesCount; index++) {
+                    if (index < vertexDeclaration.length) {
+                        var order = effect.getAttributeLocation(index);
+                        if (order >= 0) {
+                            if (!this._vertexAttribArraysEnabled[order]) {
+                                this._gl.enableVertexAttribArray(order);
+                                this._vertexAttribArraysEnabled[order] = true;
+                            }
+                            this.vertexAttribPointer(vertexBuffer, order, vertexDeclaration[index], this._gl.FLOAT, false, vertexStrideSize, offset);
+                        }
+                        offset += vertexDeclaration[index] * 4;
+                    }
+                    else {
+                        //disable effect attributes that have no data
+                        var order = effect.getAttributeLocation(index);
+                        if (this._vertexAttribArraysEnabled[order]) {
+                            this._gl.disableVertexAttribArray(order);
+                            this._vertexAttribArraysEnabled[order] = false;
+                        }
                     }
-                    offset += vertexDeclaration[index] * 4;
                 }
             }
             if (this._cachedIndexBuffer !== indexBuffer) {
@@ -972,8 +989,16 @@ var BABYLON;
                     if (order >= 0) {
                         var vertexBuffer = vertexBuffers[attributes[index]];
                         if (!vertexBuffer) {
+                            if (this._vertexAttribArraysEnabled[order]) {
+                                this._gl.disableVertexAttribArray(order);
+                                this._vertexAttribArraysEnabled[order] = false;
+                            }
                             continue;
                         }
+                        if (!this._vertexAttribArraysEnabled[order]) {
+                            this._gl.enableVertexAttribArray(order);
+                            this._vertexAttribArraysEnabled[order] = true;
+                        }
                         var buffer = vertexBuffer.getBuffer();
                         this.vertexAttribPointer(buffer, order, vertexBuffer.getSize(), this._gl.FLOAT, false, vertexBuffer.getStrideSize() * 4, vertexBuffer.getOffset() * 4);
                         if (vertexBuffer.getIsInstanced()) {
@@ -1035,7 +1060,10 @@ var BABYLON;
                 }
                 for (var i = 0; i < offsetLocations.length; i++) {
                     var ai = offsetLocations[i];
-                    this._gl.enableVertexAttribArray(ai.index);
+                    if (!this._vertexAttribArraysEnabled[ai.index]) {
+                        this._gl.enableVertexAttribArray(ai.index);
+                        this._vertexAttribArraysEnabled[ai.index] = true;
+                    }
                     this.vertexAttribPointer(instancesBuffer, ai.index, ai.attributeSize, ai.attribyteType || this._gl.FLOAT, ai.normalized || false, stride, ai.offset);
                     this._caps.instancedArrays.vertexAttribDivisorANGLE(ai.index, 1);
                     this._currentInstanceLocations.push(ai.index);
@@ -1045,7 +1073,10 @@ var BABYLON;
             else {
                 for (var index = 0; index < 4; index++) {
                     var offsetLocation = offsetLocations[index];
-                    this._gl.enableVertexAttribArray(offsetLocation);
+                    if (!this._vertexAttribArraysEnabled[offsetLocation]) {
+                        this._gl.enableVertexAttribArray(offsetLocation);
+                        this._vertexAttribArraysEnabled[offsetLocation] = true;
+                    }
                     this.vertexAttribPointer(instancesBuffer, offsetLocation, 4, this._gl.FLOAT, false, 64, index * 16);
                     this._caps.instancedArrays.vertexAttribDivisorANGLE(offsetLocation, 1);
                     this._currentInstanceLocations.push(offsetLocation);
@@ -1166,35 +1197,8 @@ var BABYLON;
                 }
                 return;
             }
-            this._vertexAttribArraysToUse = this._vertexAttribArraysToUse || [];
-            this._vertexAttribArraysEnabled = this._vertexAttribArraysEnabled || [];
             // Use program
             this.setProgram(effect.getProgram());
-            var i, ul;
-            for (i = 0, ul = this._vertexAttribArraysToUse.length; i < ul; i++) {
-                this._vertexAttribArraysToUse[i] = false;
-            }
-            var attributesCount = effect.getAttributesCount();
-            for (i = 0; i < attributesCount; i++) {
-                // Attributes
-                var order = effect.getAttributeLocation(i);
-                if (order >= 0) {
-                    this._vertexAttribArraysToUse[order] = true;
-                }
-            }
-            for (i = 0, ul = this._vertexAttribArraysEnabled.length; i < ul; i++) {
-                if (i > this._gl.VERTEX_ATTRIB_ARRAY_ENABLED || !this._vertexAttribArraysEnabled[i] || this._vertexAttribArraysToUse[i]) {
-                    continue;
-                }
-                this._vertexAttribArraysEnabled[i] = false;
-                this._gl.disableVertexAttribArray(i);
-            }
-            for (i = 0, ul = this._vertexAttribArraysToUse.length; i < ul; i++) {
-                if (this._vertexAttribArraysToUse[i] && !this._vertexAttribArraysEnabled[i]) {
-                    this._vertexAttribArraysEnabled[i] = true;
-                    this._gl.enableVertexAttribArray(i);
-                }
-            }
             this._currentEffect = effect;
             if (effect.onBind) {
                 effect.onBind(effect);
@@ -2264,13 +2268,11 @@ var BABYLON;
                 this._gl.deleteProgram(this._compiledEffects[name]._program);
             }
             // Unbind
-            if (this._vertexAttribArraysEnabled) {
-                for (var i = 0, ul = this._vertexAttribArraysEnabled.length; i < ul; i++) {
-                    if (i > this._gl.VERTEX_ATTRIB_ARRAY_ENABLED || !this._vertexAttribArraysEnabled[i]) {
-                        continue;
-                    }
-                    this._gl.disableVertexAttribArray(i);
+            for (var i = 0, ul = this._vertexAttribArraysEnabled.length; i < ul; i++) {
+                if (i >= this._caps.maxVertexAttribs || !this._vertexAttribArraysEnabled[i]) {
+                    continue;
                 }
+                this._gl.disableVertexAttribArray(i);
             }
             this._gl = null;
             // Events