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

Split shader into two compilation units & better clean up #2821

Merged
merged 3 commits into from
Jun 29, 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
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ class ArbitraryController extends React.PureComponent<Props> {
}

this.arbitraryView.stop();
this.plane.destroy();

this.isStarted = false;
}
Expand Down
15 changes: 11 additions & 4 deletions app/assets/javascripts/oxalis/geometries/arbitrary_plane.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,23 @@ import PlaneMaterialFactory from "oxalis/geometries/materials/plane_material_fac
class ArbitraryPlane {
mesh: THREE.Mesh;
isDirty: boolean;
textureMaterial: THREE.RawShaderMaterial;
stopStoreListening: () => void;
materialFactory: PlaneMaterialFactory;

constructor() {
this.isDirty = true;
this.mesh = this.createMesh();

Store.subscribe(() => {
this.stopStoreListening = Store.subscribe(() => {
this.isDirty = true;
});
}

destroy() {
this.stopStoreListening();
this.materialFactory.stopListening();
}

updateAnchorPoints(anchorPoint: ?Vector4, fallbackAnchorPoint: ?Vector4): void {
if (anchorPoint) {
this.mesh.material.setAnchorPoint(anchorPoint);
Expand Down Expand Up @@ -92,11 +98,12 @@ class ArbitraryPlane {
}

createMesh() {
this.textureMaterial = new PlaneMaterialFactory(OrthoViews.PLANE_XY, 4).setup().getMaterial();
this.materialFactory = new PlaneMaterialFactory(OrthoViews.PLANE_XY, false, 4);
const textureMaterial = this.materialFactory.setup().getMaterial();

const plane = new THREE.Mesh(
new THREE.PlaneGeometry(constants.VIEWPORT_WIDTH, constants.VIEWPORT_WIDTH, 1, 1),
this.textureMaterial,
textureMaterial,
);
plane.rotation.x = Math.PI;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import { listenToStoreProperty } from "oxalis/model/helpers/listener_helpers";
import shaderEditor from "oxalis/model/helpers/shader_editor";
import { getColorLayers } from "oxalis/model/accessors/dataset_accessor";

export type TextureMapType = {
[key: string]: THREE.DataTexture,
};

export type UniformsType = {
[key: string]: {
type: "f" | "i" | "t" | "v2" | "v3" | "tv",
Expand Down Expand Up @@ -105,10 +101,10 @@ class AbstractPlaneMaterialFactory {
material: THREE.ShaderMaterial;
uniforms: UniformsType;
attributes: Object;
textures: TextureMapType;
minFilter: THREE.NearestFilter;
maxFilter: THREE.NearestFilter;
shaderId: number;
storePropertyUnsubscribers: Array<() => void> = [];

constructor(shaderId: number) {
this.minFilter = THREE.NearestFilter;
Expand All @@ -119,13 +115,12 @@ class AbstractPlaneMaterialFactory {
setup() {
this.setupUniforms();
this.makeMaterial();
this.attachTextures(this.textures);
this.attachTextures();
this.setupChangeListeners();
return this;
}

/* eslint-disable no-unused-vars */
attachTextures(textures: TextureMapType): void {}
attachTextures(): void {}

setupUniforms(): void {
this.uniforms = {};
Expand Down Expand Up @@ -153,15 +148,6 @@ class AbstractPlaneMaterialFactory {
);

shaderEditor.addMaterial(this.shaderId, this.material);

this.material.setData = (name, data) => {
const textureName = sanitizeName(name);
const texture = this.textures[textureName];
if (texture) {
texture.image.data = data;
texture.needsUpdate = true;
}
};
}

setupChangeListeners(): void {
Expand Down
Loading