From b8a598a24043bc5e1f24c5330271be78ca8a590e Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Sat, 26 Oct 2019 23:07:46 -0400 Subject: [PATCH] Fix webgl errors when rendering over 64k billboards --- CHANGES.md | 1 + Source/Renderer/VertexArrayFacade.js | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index df53b18c7959..6a9f0155e7ac 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,6 +19,7 @@ We’ve consolidated all of our website content from cesiumjs.org and cesium.com * Fixed a bug where `scene.sampleHeightMostDetailed` and `scene.clampToHeightMostDetailed` would not resolve in request render mode. [#8281](https://github.com/AnalyticalGraphicsInc/cesium/issues/8281) * Fixed seam artifacts when log depth is disabled, `scene.globe.depthTestAgainstTerrain` is false, and primitives are under the globe. [#8205](https://github.com/AnalyticalGraphicsInc/cesium/pull/8205) * Fix dynamic ellipsoids using `innerRadii`, `minimumClock`, `maximumClock`, `minimumCone` or `maximumCone`. [#8277](https://github.com/AnalyticalGraphicsInc/cesium/pull/8277) +* Fixed rendering billboard collections containing more than 65536 billboards. ##### Deprecated :hourglass_flowing_sand: * `OrthographicFrustum.getPixelDimensions`, `OrthographicOffCenterFrustum.getPixelDimensions`, `PerspectiveFrustum.getPixelDimensions`, and `PerspectiveOffCenterFrustum.getPixelDimensions` now take a `pixelRatio` argument before the `result` argument. The previous function definition will no longer work in 1.65. [#8237](https://github.com/AnalyticalGraphicsInc/cesium/pull/8237) diff --git a/Source/Renderer/VertexArrayFacade.js b/Source/Renderer/VertexArrayFacade.js index bf4b3d38be87..d88cb0bd6836 100644 --- a/Source/Renderer/VertexArrayFacade.js +++ b/Source/Renderer/VertexArrayFacade.js @@ -304,12 +304,13 @@ import VertexArray from './VertexArray.js'; destroyVA(this); var va = this.va = []; - var numberOfVertexArrays = defined(indexBuffer) ? Math.ceil(this._size / (CesiumMath.SIXTY_FOUR_KILOBYTES - 1)) : 1; + var chunkSize = CesiumMath.SIXTY_FOUR_KILOBYTES - 4; // The 65535 index is reserved for primitive restart. Reserve the last 4 indices so that billboard quads are not broken up. + var numberOfVertexArrays = (defined(indexBuffer) && !this._instanced) ? Math.ceil(this._size / chunkSize) : 1; for ( var k = 0; k < numberOfVertexArrays; ++k) { var attributes = []; for (i = 0, length = allBuffers.length; i < length; ++i) { buffer = allBuffers[i]; - var offset = k * (buffer.vertexSizeInBytes * (CesiumMath.SIXTY_FOUR_KILOBYTES - 1)); + var offset = k * (buffer.vertexSizeInBytes * chunkSize); VertexArrayFacade._appendAttributes(attributes, buffer, offset, this._instanced); } @@ -321,7 +322,7 @@ import VertexArray from './VertexArray.js'; attributes : attributes, indexBuffer : indexBuffer }), - indicesCount : 1.5 * ((k !== (numberOfVertexArrays - 1)) ? (CesiumMath.SIXTY_FOUR_KILOBYTES - 1) : (this._size % (CesiumMath.SIXTY_FOUR_KILOBYTES - 1))) + indicesCount : 1.5 * ((k !== (numberOfVertexArrays - 1)) ? chunkSize : (this._size % chunkSize)) // TODO: not hardcode 1.5, this assumes 6 indices per 4 vertices (as for Billboard quads). }); }