Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure texture is not updated too early since these updates get lost silently #3262

Merged
merged 5 commits into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.md).
### Fixed

- Fixed a bug which caused data to not be displayed correctly if adjacent data does not exist.[#3270](https://github.com/scalableminds/webknossos/pull/3270)
- Fixed a bug which caused initial rendering to sometimes miss some buckets. [#3262](https://github.com/scalableminds/webknossos/pull/3262)

### Removed

Expand Down
23 changes: 15 additions & 8 deletions app/assets/javascripts/libs/UpdatableTexture.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,24 @@ UpdatableTexture.prototype.constructor = UpdatableTexture;

UpdatableTexture.prototype.isUpdatableTexture = true;

UpdatableTexture.prototype.setRenderer = function(renderer) {
UpdatableTexture.prototype.setRenderer = function setRenderer(renderer) {
this.renderer = renderer;
this.gl = this.renderer.getContext();
this.utils = THREE.WebGLUtils(this.gl, this.renderer.extensions);
};

UpdatableTexture.prototype.setSize = function(width, height) {
UpdatableTexture.prototype.setSize = function setSize(width, height) {
if (width === this.width && height === this.height) return;

const textureProperties = this.renderer.properties.get(this);
if (!textureProperties.__webglTexture) return;
if (!this.isInitialized()) return;

this.width = width;
this.height = height;

const activeTexture = this.gl.getParameter(this.gl.TEXTURE_BINDING_2D);
const textureProperties = this.renderer.properties.get(this);
this.gl.bindTexture(this.gl.TEXTURE_2D, textureProperties.__webglTexture);
if (!textureProperties.__webglTexture) this.width = null;
if (!this.isInitialized()) this.width = null;
this.gl.texImage2D(
this.gl.TEXTURE_2D,
0,
Expand All @@ -81,12 +81,19 @@ UpdatableTexture.prototype.setSize = function(width, height) {
this.gl.bindTexture(this.gl.TEXTURE_2D, activeTexture);
};

UpdatableTexture.prototype.update = function(src, x, y, width, height) {
UpdatableTexture.prototype.isInitialized = function isInitialized() {
return this.renderer.properties.get(this).__webglTexture != null;
};

UpdatableTexture.prototype.update = function update(src, x, y, width, height) {
this.setSize(width, width);
const textureProperties = this.renderer.properties.get(this);
if (!textureProperties.__webglTexture) return;
if (!this.isInitialized()) {
console.warn("Update called before texture was initialized. This update is discarded");
return;
}

const activeTexture = this.gl.getParameter(this.gl.TEXTURE_BINDING_2D);
const textureProperties = this.renderer.properties.get(this);
this.gl.bindTexture(this.gl.TEXTURE_2D, textureProperties.__webglTexture);
this.gl.texSubImage2D(
this.gl.TEXTURE_2D,
Expand Down
11 changes: 11 additions & 0 deletions app/assets/javascripts/libs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,17 @@ export function sortArray8(arr: Array<number>): void {
swap(arr, 3, 4);
}

export function waitForCondition(pred: () => boolean): Promise<void> {
const tryToResolve = resolve => {
if (pred()) {
resolve();
} else {
window.requestAnimationFrame(() => tryToResolve(resolve));
}
};
return new Promise(tryToResolve);
}

export function waitForSelector(selector: string): Promise<*> {
const tryToResolve = resolve => {
const el = document.querySelector(selector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import UpdatableTexture from "libs/UpdatableTexture";
import window from "libs/window";
import { createUpdatableTexture } from "oxalis/geometries/materials/abstract_plane_material_factory";
import { getRenderer } from "oxalis/controller/renderer";
import { waitForCondition } from "libs/utils";

// A TextureBucketManager instance is responsible for making buckets available
// to the GPU.
Expand Down Expand Up @@ -74,6 +75,12 @@ export default class TextureBucketManager {
this.freeIndexSet = new Set(_.range(this.maximumCapacity));

this.dataTextures = [];
}

async startRAFLoops() {
await waitForCondition(
() => this.lookUpTexture.isInitialized() && this.dataTextures[0].isInitialized(),
);

this.keepLookUpBufferUpToDate();
this.processWriterQueue();
Expand Down Expand Up @@ -207,6 +214,8 @@ export default class TextureBucketManager {
getRenderer(),
);
this.lookUpTexture = lookUpTexture;

this.startRAFLoops();
}

getLookUpBuffer() {
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/oxalis/model/data_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
getLayerBoundaries,
getBitDepth,
} from "oxalis/model/accessors/dataset_accessor";
import ErrorHandling from "libs/error_handling";

// TODO: Non-reactive
class DataLayer {
Expand All @@ -37,6 +38,8 @@ class DataLayer {
const { dataset } = Store.getState();
const bitDepth = getBitDepth(getLayerByName(dataset, this.name));

ErrorHandling.assert(layerInfo.resolutions.length > 0, "Resolutions for layer cannot be empty");

this.cube = new DataCube(
getLayerBoundaries(dataset, this.name).upperBoundary,
layerInfo.resolutions.length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ mock(
this.width = width;
this.height = height;
}

isInitialized() {
return true;
}
},
);

Expand Down