@@ -47,6 +47,51 @@ class UniformsGroup extends UniformBuffer {
4747 */
4848 this . uniforms = [ ] ;
4949
50+ /**
51+ * A cache for the uniform update ranges.
52+ *
53+ * @private
54+ * @type {Map<number, {start: number, count: number}> }
55+ */
56+ this . _updateRangeCache = new Map ( ) ;
57+
58+ }
59+
60+ /**
61+ * Adds a uniform's update range to this buffer.
62+ *
63+ * @param {Uniform } uniform - The uniform.
64+ */
65+ addUniformUpdateRange ( uniform ) {
66+
67+ const index = uniform . index ;
68+
69+ if ( this . _updateRangeCache . has ( index ) !== true ) {
70+
71+ const updateRanges = this . updateRanges ;
72+
73+ const start = uniform . offset ;
74+ const count = uniform . itemSize ;
75+
76+ const range = { start, count } ;
77+
78+ updateRanges . push ( range ) ;
79+
80+ this . _updateRangeCache . set ( index , range ) ;
81+
82+ }
83+
84+ }
85+
86+ /**
87+ * Clears all update ranges of this buffer.
88+ */
89+ clearUpdateRanges ( ) {
90+
91+ this . _updateRangeCache . clear ( ) ;
92+
93+ super . clearUpdateRanges ( ) ;
94+
5095 }
5196
5297 /**
@@ -156,6 +201,7 @@ class UniformsGroup extends UniformBuffer {
156201 }
157202
158203 uniform . offset = offset / bytesPerElement ;
204+ uniform . index = i ;
159205
160206 offset += itemSize ;
161207
@@ -235,7 +281,7 @@ class UniformsGroup extends UniformBuffer {
235281 b [ offset ] = a [ offset ] = v ;
236282 updated = true ;
237283
238- this . addUpdateRange ( offset , 1 ) ;
284+ this . addUniformUpdateRange ( uniform ) ;
239285
240286 }
241287
@@ -267,7 +313,7 @@ class UniformsGroup extends UniformBuffer {
267313
268314 updated = true ;
269315
270- this . addUpdateRange ( offset , 2 ) ;
316+ this . addUniformUpdateRange ( uniform ) ;
271317
272318 }
273319
@@ -300,7 +346,7 @@ class UniformsGroup extends UniformBuffer {
300346
301347 updated = true ;
302348
303- this . addUpdateRange ( offset , 3 ) ;
349+ this . addUniformUpdateRange ( uniform ) ;
304350
305351 }
306352
@@ -334,7 +380,7 @@ class UniformsGroup extends UniformBuffer {
334380
335381 updated = true ;
336382
337- this . addUpdateRange ( offset , 4 ) ;
383+ this . addUniformUpdateRange ( uniform ) ;
338384
339385 }
340386
@@ -366,7 +412,7 @@ class UniformsGroup extends UniformBuffer {
366412
367413 updated = true ;
368414
369- this . addUpdateRange ( offset , 3 ) ;
415+ this . addUniformUpdateRange ( uniform ) ;
370416
371417 }
372418
@@ -406,7 +452,7 @@ class UniformsGroup extends UniformBuffer {
406452
407453 updated = true ;
408454
409- this . addUpdateRange ( offset , 12 ) ;
455+ this . addUniformUpdateRange ( uniform ) ;
410456
411457 }
412458
@@ -435,7 +481,7 @@ class UniformsGroup extends UniformBuffer {
435481 setArray ( a , e , offset ) ;
436482 updated = true ;
437483
438- this . addUpdateRange ( offset , 16 ) ;
484+ this . addUniformUpdateRange ( uniform ) ;
439485
440486 }
441487
0 commit comments