@@ -83,6 +83,7 @@ abstract class TransitionBase extends SlideChangeGl {
83
83
class Transition2d extends TransitionBase {
84
84
private static readonly DefaultFromColor = new Float32Array ( [ 0 , 0 , 0 , 0 ] ) ;
85
85
private static readonly DefaultToColor = new Float32Array ( [ 0 , 0 , 0 , 0 ] ) ;
86
+ private _uniformCache : Record < string , WebGLUniformLocation > = { } ;
86
87
87
88
constructor ( transitionParameters : TransitionParameters ) {
88
89
super ( transitionParameters ) ;
@@ -139,6 +140,17 @@ class Transition2d extends TransitionBase {
139
140
gl . bufferData ( gl . ARRAY_BUFFER , positions , gl . STATIC_DRAW ) ;
140
141
}
141
142
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 ] ;
151
+ }
152
+ }
153
+
142
154
public render ( nT : number , properties ?: AnimatedElementRenderProperties ) {
143
155
if ( this . context . isDisposed ( ) ) return ;
144
156
@@ -170,7 +182,6 @@ class Transition2d extends TransitionBase {
170
182
0 ,
171
183
) ;
172
184
} else {
173
- // jscpd:ignore-start
174
185
let bounds : BoundsType = null ;
175
186
let alpha = 1.0 ;
176
187
let fromFillColor = Transition2d . DefaultFromColor ;
@@ -195,27 +206,17 @@ class Transition2d extends TransitionBase {
195
206
console . debug ( `Transition2d.render: alpha: ${ alpha } ` ) ;
196
207
197
208
this . setPositionBuffer ( bounds ) ;
198
- this . gl . uniform1f (
199
- this . gl . getUniformLocation ( this . program , 'alpha' ) ,
200
- alpha ,
201
- ) ;
209
+ this . gl . uniform1f ( this . getUniformLocation ( 'alpha' ) , alpha ) ;
202
210
this . gl . uniform4fv (
203
- this . gl . getUniformLocation ( this . program , 'fromFillColor' ) ,
211
+ this . getUniformLocation ( 'fromFillColor' ) ,
204
212
fromFillColor ,
205
213
) ;
214
+ this . gl . uniform4fv ( this . getUniformLocation ( 'toFillColor' ) , toFillColor ) ;
206
215
this . gl . uniform4fv (
207
- this . gl . getUniformLocation ( this . program , 'toFillColor' ) ,
208
- toFillColor ,
209
- ) ;
210
- this . gl . uniform4fv (
211
- this . gl . getUniformLocation ( this . program , 'fromLineColor' ) ,
216
+ this . getUniformLocation ( 'fromLineColor' ) ,
212
217
fromLineColor ,
213
218
) ;
214
- this . gl . uniform4fv (
215
- this . gl . getUniformLocation ( this . program , 'toLineColor' ) ,
216
- toLineColor ,
217
- ) ;
218
- // jscpd:ignore-end
219
+ this . gl . uniform4fv ( this . getUniformLocation ( 'toLineColor' ) , toLineColor ) ;
219
220
}
220
221
221
222
gl . activeTexture ( gl . TEXTURE1 ) ;
0 commit comments