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