Skip to content

Commit ff68238

Browse files
committed
refactor(slideshow): replace uniform cache with js Map
Signed-off-by: codewithvk <vivek.javiya@collabora.com> Change-Id: I7964916a8ddbc0e3efd6483e82cbf043209fbacb
1 parent 3cd053a commit ff68238

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

browser/src/slideshow/Transition2d.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ abstract class TransitionBase extends SlideChangeGl {
8383
class Transition2d extends TransitionBase {
8484
private static readonly DefaultFromColor = new Float32Array([0, 0, 0, 0]);
8585
private static readonly DefaultToColor = new Float32Array([0, 0, 0, 0]);
86-
private _uniformCache: Record<string, WebGLUniformLocation> = {};
86+
private _uniformCache = new Map<string, WebGLUniformLocation | null>();
8787

8888
constructor(transitionParameters: TransitionParameters) {
8989
super(transitionParameters);
@@ -140,15 +140,16 @@ class Transition2d extends TransitionBase {
140140
gl.bufferData(gl.ARRAY_BUFFER, positions, gl.STATIC_DRAW);
141141
}
142142

143-
private getUniformLocation(value: string) {
144-
if (this.program) {
145-
if (!this._uniformCache[value])
146-
this._uniformCache[value] = this.gl.getUniformLocation(
147-
this.program,
148-
value,
149-
);
150-
return this._uniformCache[value];
143+
private getUniformLocation(name: string): WebGLUniformLocation | null {
144+
if (!this.program) return null;
145+
146+
if (this._uniformCache.has(name)) {
147+
return this._uniformCache.get(name);
151148
}
149+
150+
const loc = this.gl.getUniformLocation(this.program, name);
151+
this._uniformCache.set(name, loc);
152+
return loc;
152153
}
153154

154155
public render(nT: number, properties?: AnimatedElementRenderProperties) {

0 commit comments

Comments
 (0)