Skip to content

Commit 9100963

Browse files
committed
Do not use the index of the max value of an unsigned short. Fixing tests WIP.
1 parent 0f6a5b9 commit 9100963

8 files changed

+26
-24
lines changed

Source/Core/GeometryPipeline.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ define([
510510
// If there's an index list and more than 64K attributes, it is possible that
511511
// some indices are outside the range of unsigned short [0, 64K - 1]
512512
var numberOfVertices = Geometry.computeNumberOfVertices(geometry);
513-
if (defined(geometry.indices) && (numberOfVertices > CesiumMath.SIXTY_FOUR_KILOBYTES)) {
513+
if (defined(geometry.indices) && (numberOfVertices >= CesiumMath.SIXTY_FOUR_KILOBYTES)) {
514514
var oldToNewIndex = [];
515515
var newIndices = [];
516516
var currentIndex = 0;
@@ -541,7 +541,7 @@ define([
541541
newIndices.push(i);
542542
}
543543

544-
if (currentIndex + indicesPerPrimitive > CesiumMath.SIXTY_FOUR_KILOBYTES) {
544+
if (currentIndex + indicesPerPrimitive >= CesiumMath.SIXTY_FOUR_KILOBYTES) {
545545
geometries.push(new Geometry({
546546
attributes : newAttributes,
547547
indices : newIndices,

Source/Core/IndexDatatype.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ define([
110110
}
111111
//>>includeEnd('debug');
112112

113-
if (numberOfVertices > CesiumMath.SIXTY_FOUR_KILOBYTES) {
113+
if (numberOfVertices >= CesiumMath.SIXTY_FOUR_KILOBYTES) {
114114
return new Uint32Array(indicesLengthOrArray);
115115
}
116116

@@ -141,7 +141,7 @@ define([
141141
}
142142
//>>includeEnd('debug');
143143

144-
if (numberOfVertices > CesiumMath.SIXTY_FOUR_KILOBYTES) {
144+
if (numberOfVertices >= CesiumMath.SIXTY_FOUR_KILOBYTES) {
145145
return new Uint32Array(sourceArray, byteOffset, length);
146146
}
147147

Source/Core/TerrainProvider.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ define([
104104
*/
105105
TerrainProvider.getRegularGridIndices = function(width, height) {
106106
//>>includeStart('debug', pragmas.debug);
107-
if (width * height > 64 * 1024) {
108-
throw new DeveloperError('The total number of vertices (width * height) must be less than or equal to 65536.');
107+
if (width * height >= 64 * 1024) {
108+
throw new DeveloperError('The total number of vertices (width * height) must be less than 65536.');
109109
}
110110
//>>includeEnd('debug');
111111

Source/Renderer/VertexArray.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ define([
615615
var indexBuffer;
616616
var indices = geometry.indices;
617617
if (defined(indices)) {
618-
if ((Geometry.computeNumberOfVertices(geometry) > CesiumMath.SIXTY_FOUR_KILOBYTES) && context.elementIndexUint) {
618+
if ((Geometry.computeNumberOfVertices(geometry) >= CesiumMath.SIXTY_FOUR_KILOBYTES) && context.elementIndexUint) {
619619
indexBuffer = Buffer.createIndexBuffer({
620620
context : context,
621621
typedArray : new Uint32Array(indices),

Source/Renderer/VertexArrayFacade.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,12 @@ define([
315315
destroyVA(this);
316316
var va = this.va = [];
317317

318-
var numberOfVertexArrays = defined(indexBuffer) ? Math.ceil(this._size / CesiumMath.SIXTY_FOUR_KILOBYTES) : 1;
318+
var numberOfVertexArrays = defined(indexBuffer) ? Math.ceil(this._size / (CesiumMath.SIXTY_FOUR_KILOBYTES - 1)) : 1;
319319
for ( var k = 0; k < numberOfVertexArrays; ++k) {
320320
var attributes = [];
321321
for (i = 0, length = allBuffers.length; i < length; ++i) {
322322
buffer = allBuffers[i];
323-
var offset = k * (buffer.vertexSizeInBytes * CesiumMath.SIXTY_FOUR_KILOBYTES);
323+
var offset = k * (buffer.vertexSizeInBytes * (CesiumMath.SIXTY_FOUR_KILOBYTES - 1));
324324
VertexArrayFacade._appendAttributes(attributes, buffer, offset, this._instanced);
325325
}
326326

@@ -332,7 +332,7 @@ define([
332332
attributes : attributes,
333333
indexBuffer : indexBuffer
334334
}),
335-
indicesCount : 1.5 * ((k !== (numberOfVertexArrays - 1)) ? CesiumMath.SIXTY_FOUR_KILOBYTES : (this._size % CesiumMath.SIXTY_FOUR_KILOBYTES))
335+
indicesCount : 1.5 * ((k !== (numberOfVertexArrays - 1)) ? (CesiumMath.SIXTY_FOUR_KILOBYTES - 1) : (this._size % (CesiumMath.SIXTY_FOUR_KILOBYTES - 1)))
336336
// TODO: not hardcode 1.5, this assumes 6 indices per 4 vertices (as for Billboard quads).
337337
});
338338
}

Source/Scene/BillboardCollection.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,9 @@ define([
552552
return indexBuffer;
553553
}
554554

555-
var length = sixteenK * 6;
555+
// Subtract 6 because the last index is reserverd for primitive restart.
556+
// https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.18
557+
var length = sixteenK * 6 - 6;
556558
var indices = new Uint16Array(length);
557559
for (var i = 0, j = 0; i < length; i += 6, j += 4) {
558560
indices[i] = j;

Source/Scene/PolylineCollection.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -787,14 +787,14 @@ define([
787787

788788
vbo += vertexBufferOffset[k];
789789

790-
var positionHighOffset = 6 * (k * (positionSizeInBytes * CesiumMath.SIXTY_FOUR_KILOBYTES) - vbo * positionSizeInBytes);//componentsPerAttribute(3) * componentDatatype(4)
790+
var positionHighOffset = 6 * (k * (positionSizeInBytes * (CesiumMath.SIXTY_FOUR_KILOBYTES - 1)) - vbo * positionSizeInBytes);//componentsPerAttribute(3) * componentDatatype(4)
791791
var positionLowOffset = positionSizeInBytes + positionHighOffset;
792792
var prevPositionHighOffset = positionSizeInBytes + positionLowOffset;
793793
var prevPositionLowOffset = positionSizeInBytes + prevPositionHighOffset;
794794
var nextPositionHighOffset = positionSizeInBytes + prevPositionLowOffset;
795795
var nextPositionLowOffset = positionSizeInBytes + nextPositionHighOffset;
796-
var vertexPickColorBufferOffset = k * (pickColorSizeInBytes * CesiumMath.SIXTY_FOUR_KILOBYTES) - vbo * pickColorSizeInBytes;
797-
var vertexTexCoordExpandWidthAndShowBufferOffset = k * (texCoordExpandWidthAndShowSizeInBytes * CesiumMath.SIXTY_FOUR_KILOBYTES) - vbo * texCoordExpandWidthAndShowSizeInBytes;
796+
var vertexPickColorBufferOffset = k * (pickColorSizeInBytes * (CesiumMath.SIXTY_FOUR_KILOBYTES - 1)) - vbo * pickColorSizeInBytes;
797+
var vertexTexCoordExpandWidthAndShowBufferOffset = k * (texCoordExpandWidthAndShowSizeInBytes * (CesiumMath.SIXTY_FOUR_KILOBYTES - 1)) - vbo * texCoordExpandWidthAndShowSizeInBytes;
798798

799799
var attributes = [{
800800
index : attributeLocations.position3DHigh,
@@ -1323,7 +1323,7 @@ define([
13231323
for ( var j = 0; j < numberOfSegments; ++j) {
13241324
var segmentLength = segments[j] - 1.0;
13251325
for ( var k = 0; k < segmentLength; ++k) {
1326-
if (indicesCount + 4 >= CesiumMath.SIXTY_FOUR_KILOBYTES - 1) {
1326+
if (indicesCount + 4 >= CesiumMath.SIXTY_FOUR_KILOBYTES - 2) {
13271327
polyline._locatorBuckets.push({
13281328
locator : bucketLocator,
13291329
count : segmentIndexCount
@@ -1355,7 +1355,7 @@ define([
13551355
count : segmentIndexCount
13561356
});
13571357

1358-
if (indicesCount + 4 >= CesiumMath.SIXTY_FOUR_KILOBYTES - 1) {
1358+
if (indicesCount + 4 >= CesiumMath.SIXTY_FOUR_KILOBYTES - 2) {
13591359
vertexBufferOffset.push(0);
13601360
indices = [];
13611361
totalIndices.push(indices);

Specs/Core/GeometryPipelineSpec.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -492,11 +492,11 @@ defineSuite([
492492

493493
expect(geometries.length).toEqual(2);
494494

495-
expect(geometries[0].attributes.position.values.length).toEqual(positions.length - 6); // Two vertices are not copied (0, 1)
496-
expect(geometries[0].indices.length).toEqual(indices.length - 2); // One line is not copied (0, 1)
495+
expect(geometries[0].attributes.position.values.length).toEqual(positions.length - 12); // Four vertices are not copied
496+
expect(geometries[0].indices.length).toEqual(indices.length - 4); // Two lines are not copied
497497

498-
expect(geometries[1].attributes.position.values.length).toEqual(6);
499-
expect(geometries[1].indices.length).toEqual(2);
498+
expect(geometries[1].attributes.position.values.length).toEqual(9);
499+
expect(geometries[1].indices.length).toEqual(4);
500500
});
501501

502502
it('fitToUnsignedShortIndices creates two point geometries', function() {
@@ -525,11 +525,11 @@ defineSuite([
525525

526526
expect(geometries.length).toEqual(2);
527527

528-
expect(geometries[0].attributes.position.values.length).toEqual(positions.length - 3); // One vertex is not copied
529-
expect(geometries[0].indices.length).toEqual(indices.length - 1); // One point is not copied
528+
expect(geometries[0].attributes.position.values.length).toEqual(positions.length - 6); // Two vertices are not copied
529+
expect(geometries[0].indices.length).toEqual(indices.length - 2); // Two points are not copied
530530

531-
expect(geometries[1].attributes.position.values.length).toEqual(3);
532-
expect(geometries[1].indices.length).toEqual(1);
531+
expect(geometries[1].attributes.position.values.length).toEqual(6);
532+
expect(geometries[1].indices.length).toEqual(2);
533533
});
534534

535535
it('fitToUnsignedShortIndices throws without a geometry', function() {

0 commit comments

Comments
 (0)