From f3c532042eb74d0877ba8bd9ce083f20d2e0209f Mon Sep 17 00:00:00 2001 From: lindsay Date: Fri, 13 Oct 2023 04:30:55 +0200 Subject: [PATCH] Eager-create various renderers for faster initial interaction #1175 --- .../TrianglesDataTextureRenderers.js | 26 +++++++++++++++++++ .../scene/model/vbo/VBOSceneModelRenderers.js | 2 +- .../vbo/snapBatching/SnapBatchingRenderers.js | 16 ++++++++++++ .../snapInstancing/SnapInstancingRenderers.js | 16 ++++++++++++ .../TrianglesBatchingRenderers.js | 19 ++++++++++++++ .../TrianglesInstancingRenderers.js | 19 ++++++++++++++ src/viewer/scene/webgl/Program.js | 2 +- 7 files changed, 98 insertions(+), 2 deletions(-) diff --git a/src/viewer/scene/model/dtx/triangles/TrianglesDataTextureRenderers.js b/src/viewer/scene/model/dtx/triangles/TrianglesDataTextureRenderers.js index f598c40d26..594a8cd6fc 100644 --- a/src/viewer/scene/model/dtx/triangles/TrianglesDataTextureRenderers.js +++ b/src/viewer/scene/model/dtx/triangles/TrianglesDataTextureRenderers.js @@ -92,6 +92,30 @@ class TrianglesDataTextureRenderers { } } + eagerCreateRenders() { + + // Pre-initialize certain renderers that would otherwise be lazy-initialised + // on user interaction, such as picking or emphasis, so that there is no delay + // when user first begins interacting with the viewer. + + if (!this._silhouetteRenderer) { // Used for highlighting and selection + this._silhouetteRenderer = new TrianglesDataTextureSilhouetteRenderer(this._scene); + } + if (!this._pickMeshRenderer) { + this._pickMeshRenderer = new TrianglesDataTexturePickMeshRenderer(this._scene); + } + if (!this._pickDepthRenderer) { + this._pickDepthRenderer = new TrianglesDataTexturePickDepthRenderer(this._scene); + } + if (!this._vertexDepthRenderer) { + this._vertexDepthRenderer = new TrianglesDataTextureSnapDepthRenderer(this._scene); + } + if (!this._snapDepthBufInitRenderer) { + this._snapDepthBufInitRenderer = new TrianglesDataTextureSnapDepthBufInitRenderer(this._scene); + } + } + + get colorRenderer() { if (!this._colorRenderer) { this._colorRenderer = new TrianglesDataTextureColorRenderer(this._scene, false); @@ -264,8 +288,10 @@ function getDataTextureRenderers(scene) { dataTextureRenderers = new TrianglesDataTextureRenderers(scene); cachdRenderers[sceneId] = dataTextureRenderers; dataTextureRenderers._compile(); + dataTextureRenderers.eagerCreateRenders(); scene.on("compile", () => { dataTextureRenderers._compile(); + dataTextureRenderers.eagerCreateRenders(); }); scene.on("destroyed", () => { delete cachdRenderers[sceneId]; diff --git a/src/viewer/scene/model/vbo/VBOSceneModelRenderers.js b/src/viewer/scene/model/vbo/VBOSceneModelRenderers.js index 0594b6a110..e819f16a51 100644 --- a/src/viewer/scene/model/vbo/VBOSceneModelRenderers.js +++ b/src/viewer/scene/model/vbo/VBOSceneModelRenderers.js @@ -660,7 +660,7 @@ class VBOSceneModelTriangleBatchingEdgesRenderer extends VBOSceneModelTriangleBa class VBOSceneModelTriangleInstancingRenderer extends VBOSceneModelRenderer { - constructor(scene, withSAO, {edges = false} = {}) { + constructor(scene, withSAO, { edges = false} = {}) { super(scene, withSAO, {instancing: true, edges}); } diff --git a/src/viewer/scene/model/vbo/snapBatching/SnapBatchingRenderers.js b/src/viewer/scene/model/vbo/snapBatching/SnapBatchingRenderers.js index 7fca4c8b80..e936d43d2c 100644 --- a/src/viewer/scene/model/vbo/snapBatching/SnapBatchingRenderers.js +++ b/src/viewer/scene/model/vbo/snapBatching/SnapBatchingRenderers.js @@ -21,6 +21,20 @@ class SnapBatchingRenderers { } } + eagerCreateRenders() { + + // Pre-initialize renderers that would otherwise be lazy-initialised + // on user interaction, such as picking or emphasis, so that there is no delay + // when user first begins interacting with the viewer. + + if (!this._snapDepthBufInitRenderer) { + this._snapDepthBufInitRenderer = new SnapBatchingDepthBufInitRenderer(this._scene, false); + } + if (!this._snapDepthRenderer) { + this._snapDepthRenderer = new SnapBatchingDepthRenderer(this._scene); + } + } + get snapDepthBufInitRenderer() { if (!this._snapDepthBufInitRenderer) { this._snapDepthBufInitRenderer = new SnapBatchingDepthBufInitRenderer(this._scene, false); @@ -57,8 +71,10 @@ function getSnapBatchingRenderers(scene) { batchingRenderers = new SnapBatchingRenderers(scene); cachedRenderers[sceneId] = batchingRenderers; batchingRenderers._compile(); + batchingRenderers.eagerCreateRenders(); scene.on("compile", () => { batchingRenderers._compile(); + batchingRenderers.eagerCreateRenders(); }); scene.on("destroyed", () => { delete cachedRenderers[sceneId]; diff --git a/src/viewer/scene/model/vbo/snapInstancing/SnapInstancingRenderers.js b/src/viewer/scene/model/vbo/snapInstancing/SnapInstancingRenderers.js index 2a973ab8ea..5f676172b7 100644 --- a/src/viewer/scene/model/vbo/snapInstancing/SnapInstancingRenderers.js +++ b/src/viewer/scene/model/vbo/snapInstancing/SnapInstancingRenderers.js @@ -21,6 +21,20 @@ class SnapInstancingRenderers { } } + eagerCreateRenders() { + + // Pre-initialize renderers that would otherwise be lazy-initialised + // on user interaction, such as picking or emphasis, so that there is no delay + // when user first begins interacting with the viewer. + + if (!this._snapDepthBufInitRenderer) { + this._snapDepthBufInitRenderer = new SnapInstancingDepthBufInitRenderer(this._scene, false); + } + if (!this._snapDepthRenderer) { + this._snapDepthRenderer = new SnapInstancingDepthRenderer(this._scene); + } + } + get snapDepthBufInitRenderer() { if (!this._snapDepthBufInitRenderer) { this._snapDepthBufInitRenderer = new SnapInstancingDepthBufInitRenderer(this._scene, false); @@ -57,8 +71,10 @@ function getSnapInstancingRenderers(scene) { instancingRenderers = new SnapInstancingRenderers(scene); cachedRenderers[sceneId] = instancingRenderers; instancingRenderers._compile(); + instancingRenderers.eagerCreateRenders(); scene.on("compile", () => { instancingRenderers._compile(); + instancingRenderers.eagerCreateRenders(); }); scene.on("destroyed", () => { delete cachedRenderers[sceneId]; diff --git a/src/viewer/scene/model/vbo/trianglesBatching/TrianglesBatchingRenderers.js b/src/viewer/scene/model/vbo/trianglesBatching/TrianglesBatchingRenderers.js index 45f9fb9de7..602ebb228d 100644 --- a/src/viewer/scene/model/vbo/trianglesBatching/TrianglesBatchingRenderers.js +++ b/src/viewer/scene/model/vbo/trianglesBatching/TrianglesBatchingRenderers.js @@ -102,6 +102,23 @@ class TrianglesBatchingRenderers { } } + eagerCreateRenders() { + + // Pre-initialize certain renderers that would otherwise be lazy-initialised + // on user interaction, such as picking or emphasis, so that there is no delay + // when user first begins interacting with the viewer. + + if (!this._silhouetteRenderer) { // Used for highlighting and selection + this._silhouetteRenderer = new TrianglesBatchingSilhouetteRenderer(this._scene); + } + if (!this._pickMeshRenderer) { + this._pickMeshRenderer = new TrianglesBatchingPickMeshRenderer(this._scene); + } + if (!this._pickDepthRenderer) { + this._pickDepthRenderer = new TrianglesBatchingPickDepthRenderer(this._scene); + } + } + get colorRenderer() { if (!this._colorRenderer) { this._colorRenderer = new TrianglesBatchingColorRenderer(this._scene, false); @@ -308,8 +325,10 @@ function getBatchingRenderers(scene) { batchingRenderers = new TrianglesBatchingRenderers(scene); cachdRenderers[sceneId] = batchingRenderers; batchingRenderers._compile(); + batchingRenderers.eagerCreateRenders(); scene.on("compile", () => { batchingRenderers._compile(); + batchingRenderers.eagerCreateRenders(); }); scene.on("destroyed", () => { delete cachdRenderers[sceneId]; diff --git a/src/viewer/scene/model/vbo/trianglesInstancing/TrianglesInstancingRenderers.js b/src/viewer/scene/model/vbo/trianglesInstancing/TrianglesInstancingRenderers.js index 06d16d333a..dc055d2804 100644 --- a/src/viewer/scene/model/vbo/trianglesInstancing/TrianglesInstancingRenderers.js +++ b/src/viewer/scene/model/vbo/trianglesInstancing/TrianglesInstancingRenderers.js @@ -102,6 +102,23 @@ class TrianglesInstancingRenderers { } } + eagerCreateRenders() { + + // Pre-initialize certain renderers that would otherwise be lazy-initialised + // on user interaction, such as picking or emphasis, so that there is no delay + // when user first begins interacting with the viewer. + + if (!this._silhouetteRenderer) { // Used for highlighting and selection + this._silhouetteRenderer = new TrianglesInstancingSilhouetteRenderer(this._scene); + } + if (!this._pickMeshRenderer) { + this._pickMeshRenderer = new TrianglesInstancingPickMeshRenderer(this._scene); + } + if (!this._pickDepthRenderer) { + this._pickDepthRenderer = new TrianglesInstancingPickDepthRenderer(this._scene); + } + } + get colorRenderer() { if (!this._colorRenderer) { this._colorRenderer = new TrianglesInstancingColorRenderer(this._scene, false); @@ -308,8 +325,10 @@ function getInstancingRenderers(scene) { instancingRenderers = new TrianglesInstancingRenderers(scene); cachedRenderers[sceneId] = instancingRenderers; instancingRenderers._compile(); + instancingRenderers.eagerCreateRenders(); scene.on("compile", () => { instancingRenderers._compile(); + instancingRenderers.eagerCreateRenders(); }); scene.on("destroyed", () => { delete cachedRenderers[sceneId]; diff --git a/src/viewer/scene/webgl/Program.js b/src/viewer/scene/webgl/Program.js index be1d8693c6..1eb80071ee 100644 --- a/src/viewer/scene/webgl/Program.js +++ b/src/viewer/scene/webgl/Program.js @@ -86,7 +86,7 @@ class Program { gl.attachShader(this.handle, this._fragmentShader.handle); gl.linkProgram(this.handle); this.linked = gl.getProgramParameter(this.handle, gl.LINK_STATUS); - // HACK: Disable validation temporarily: https://github.com/xeolabs/xeokit/issues/5 + // HACK: Disable validation temporarily // Perhaps we should defer validation until render-time, when the program has values set for all inputs? this.validated = true; if (!this.linked || !this.validated) {