Skip to content

Commit

Permalink
Eager-create various renderers for faster initial interaction #1175
Browse files Browse the repository at this point in the history
  • Loading branch information
xeolabs committed Oct 13, 2023
1 parent 5d66989 commit f3c5320
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/viewer/scene/model/vbo/VBOSceneModelRenderers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}

Expand Down
16 changes: 16 additions & 0 deletions src/viewer/scene/model/vbo/snapBatching/SnapBatchingRenderers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/viewer/scene/webgl/Program.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f3c5320

Please sign in to comment.