Make descriptor access faster
This commit is contained in:
parent
7a7273c2be
commit
4f726ddac2
6 changed files with 54 additions and 65 deletions
|
|
@ -2,9 +2,8 @@ import { mat2d, vec2 } from 'gl-matrix';
|
||||||
import { DrawableDescriptor } from './drawable-descriptor';
|
import { DrawableDescriptor } from './drawable-descriptor';
|
||||||
|
|
||||||
export abstract class Drawable {
|
export abstract class Drawable {
|
||||||
static get descriptor(): DrawableDescriptor {
|
// This should be overriden by inherited classes
|
||||||
throw new Error('This getter should be overriden');
|
public static readonly descriptor: DrawableDescriptor;
|
||||||
}
|
|
||||||
|
|
||||||
public abstract distance(target: vec2): number;
|
public abstract distance(target: vec2): number;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,12 @@ import { Drawable } from '../drawable';
|
||||||
import { DrawableDescriptor } from '../drawable-descriptor';
|
import { DrawableDescriptor } from '../drawable-descriptor';
|
||||||
|
|
||||||
export class CircleLight extends Drawable {
|
export class CircleLight extends Drawable {
|
||||||
public static get descriptor(): DrawableDescriptor {
|
public static readonly descriptor: DrawableDescriptor = {
|
||||||
return {
|
uniformName: 'circleLights',
|
||||||
uniformName: 'circleLights',
|
uniformCountMacroName: 'CIRCLE_LIGHT_COUNT',
|
||||||
uniformCountMacroName: 'CIRCLE_LIGHT_COUNT',
|
shaderCombinationSteps: [0, 1, 2, 4],
|
||||||
shaderCombinationSteps: [0, 1, 2, 4],
|
empty: new CircleLight(vec2.fromValues(0, 0), vec3.fromValues(0, 0, 0), 0),
|
||||||
empty: new CircleLight(vec2.fromValues(0, 0), vec3.fromValues(0, 0, 0), 0),
|
};
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(public center: vec2, public color: vec3, public intensity: number) {
|
constructor(public center: vec2, public color: vec3, public intensity: number) {
|
||||||
super();
|
super();
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,17 @@ import { Drawable } from '../drawable';
|
||||||
import { DrawableDescriptor } from '../drawable-descriptor';
|
import { DrawableDescriptor } from '../drawable-descriptor';
|
||||||
|
|
||||||
export class Flashlight extends Drawable {
|
export class Flashlight extends Drawable {
|
||||||
public static get descriptor(): DrawableDescriptor {
|
public static readonly descriptor: DrawableDescriptor = {
|
||||||
return {
|
uniformName: 'flashlights',
|
||||||
uniformName: 'flashlights',
|
uniformCountMacroName: 'FLASHLIGHT_COUNT',
|
||||||
uniformCountMacroName: 'FLASHLIGHT_COUNT',
|
shaderCombinationSteps: [0, 1, 2, 4],
|
||||||
shaderCombinationSteps: [0, 1, 2, 4],
|
empty: new Flashlight(
|
||||||
empty: new Flashlight(
|
vec2.fromValues(0, 0),
|
||||||
vec2.fromValues(0, 0),
|
vec2.fromValues(0, 0),
|
||||||
vec2.fromValues(0, 0),
|
vec3.fromValues(0, 0, 0),
|
||||||
vec3.fromValues(0, 0, 0),
|
0
|
||||||
0
|
),
|
||||||
),
|
};
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
public center: vec2,
|
public center: vec2,
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,9 @@ import { Drawable } from '../drawable';
|
||||||
import { DrawableDescriptor } from '../drawable-descriptor';
|
import { DrawableDescriptor } from '../drawable-descriptor';
|
||||||
|
|
||||||
export class Circle extends Drawable {
|
export class Circle extends Drawable {
|
||||||
public static get descriptor(): DrawableDescriptor {
|
public static descriptor: DrawableDescriptor = {
|
||||||
return {
|
sdf: {
|
||||||
sdf: {
|
shader: `
|
||||||
shader: `
|
|
||||||
uniform struct {
|
uniform struct {
|
||||||
vec2 center;
|
vec2 center;
|
||||||
float radius;
|
float radius;
|
||||||
|
|
@ -25,14 +24,13 @@ export class Circle extends Drawable {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
distanceFunctionName: 'circleMinDistance',
|
distanceFunctionName: 'circleMinDistance',
|
||||||
},
|
},
|
||||||
uniformName: 'circles',
|
uniformName: 'circles',
|
||||||
uniformCountMacroName: 'CIRCLE_COUNT',
|
uniformCountMacroName: 'CIRCLE_COUNT',
|
||||||
shaderCombinationSteps: [0, 1, 2, 3, 16, 32],
|
shaderCombinationSteps: [0, 1, 2, 3, 16, 32],
|
||||||
empty: new Circle(vec2.fromValues(0, 0), 0),
|
empty: new Circle(vec2.fromValues(0, 0), 0),
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
constructor(public center: vec2, public radius: number) {
|
constructor(public center: vec2, public radius: number) {
|
||||||
super();
|
super();
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,9 @@ import { Drawable } from '../drawable';
|
||||||
import { DrawableDescriptor } from '../drawable-descriptor';
|
import { DrawableDescriptor } from '../drawable-descriptor';
|
||||||
|
|
||||||
export class InvertedTunnel extends Drawable {
|
export class InvertedTunnel extends Drawable {
|
||||||
public static get descriptor(): DrawableDescriptor {
|
public static descriptor: DrawableDescriptor = {
|
||||||
return {
|
sdf: {
|
||||||
sdf: {
|
shader: `
|
||||||
shader: `
|
|
||||||
uniform struct InvertedTunnel {
|
uniform struct InvertedTunnel {
|
||||||
vec2 from;
|
vec2 from;
|
||||||
vec2 toFromDelta;
|
vec2 toFromDelta;
|
||||||
|
|
@ -44,14 +43,13 @@ export class InvertedTunnel extends Drawable {
|
||||||
minDistance = -myMinDistance;
|
minDistance = -myMinDistance;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
distanceFunctionName: 'invertedTunnelMinDistance',
|
distanceFunctionName: 'invertedTunnelMinDistance',
|
||||||
},
|
},
|
||||||
uniformName: 'invertedTunnels',
|
uniformName: 'invertedTunnels',
|
||||||
uniformCountMacroName: 'INVERTED_TUNNEL_COUNT',
|
uniformCountMacroName: 'INVERTED_TUNNEL_COUNT',
|
||||||
shaderCombinationSteps: [0, 1, 4, 16, 32],
|
shaderCombinationSteps: [0, 1, 4, 16, 32],
|
||||||
empty: new InvertedTunnel(vec2.fromValues(0, 0), vec2.fromValues(0, 0), 0, 0),
|
empty: new InvertedTunnel(vec2.fromValues(0, 0), vec2.fromValues(0, 0), 0, 0),
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public readonly from: vec2,
|
public readonly from: vec2,
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,9 @@ import { Drawable } from '../drawable';
|
||||||
import { DrawableDescriptor } from '../drawable-descriptor';
|
import { DrawableDescriptor } from '../drawable-descriptor';
|
||||||
|
|
||||||
export class Tunnel extends Drawable {
|
export class Tunnel extends Drawable {
|
||||||
public static get descriptor(): DrawableDescriptor {
|
public static descriptor: DrawableDescriptor = {
|
||||||
return {
|
sdf: {
|
||||||
sdf: {
|
shader: `
|
||||||
shader: `
|
|
||||||
uniform struct Tunnel {
|
uniform struct Tunnel {
|
||||||
vec2 from;
|
vec2 from;
|
||||||
vec2 toFromDelta;
|
vec2 toFromDelta;
|
||||||
|
|
@ -44,19 +43,18 @@ export class Tunnel extends Drawable {
|
||||||
minDistance = min(minDistance, myMinDistance);
|
minDistance = min(minDistance, myMinDistance);
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
distanceFunctionName: 'tunnelMinDistance',
|
distanceFunctionName: 'tunnelMinDistance',
|
||||||
},
|
},
|
||||||
uniformName: 'tunnels',
|
uniformName: 'tunnels',
|
||||||
uniformCountMacroName: 'TUNNEL_COUNT',
|
uniformCountMacroName: 'TUNNEL_COUNT',
|
||||||
shaderCombinationSteps: [0, 1, 4, 16, 32],
|
shaderCombinationSteps: [0, 1, 4, 16, 32],
|
||||||
empty: new Tunnel(
|
empty: new Tunnel(
|
||||||
vec2.fromValues(-100000, -100000),
|
vec2.fromValues(-100000, -100000),
|
||||||
vec2.fromValues(-100000, -100000),
|
vec2.fromValues(-100000, -100000),
|
||||||
0,
|
0,
|
||||||
0
|
0
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public readonly from: vec2,
|
public readonly from: vec2,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue