Skip to content

Commit 6381be8

Browse files
authored
Merge pull request #16366 from fernandojsg/removecache
Remove cache on uniform arrays
2 parents 880abcf + f88e7fe commit 6381be8

File tree

1 file changed

+74
-108
lines changed

1 file changed

+74
-108
lines changed

src/renderers/webgl/WebGLUniforms.js

Lines changed: 74 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function allocTexUnits( textures, n ) {
156156

157157
// Single scalar
158158

159-
function setValue1f( gl, v ) {
159+
function setValueV1f( gl, v ) {
160160

161161
var cache = this.cache;
162162

@@ -168,21 +168,9 @@ function setValue1f( gl, v ) {
168168

169169
}
170170

171-
function setValue1i( gl, v ) {
172-
173-
var cache = this.cache;
174-
175-
if ( cache[ 0 ] === v ) return;
176-
177-
gl.uniform1i( this.addr, v );
178-
179-
cache[ 0 ] = v;
180-
181-
}
182-
183171
// Single float vector (from flat array or THREE.VectorN)
184172

185-
function setValue2fv( gl, v ) {
173+
function setValueV2f( gl, v ) {
186174

187175
var cache = this.cache;
188176

@@ -209,7 +197,7 @@ function setValue2fv( gl, v ) {
209197

210198
}
211199

212-
function setValue3fv( gl, v ) {
200+
function setValueV3f( gl, v ) {
213201

214202
var cache = this.cache;
215203

@@ -249,7 +237,7 @@ function setValue3fv( gl, v ) {
249237

250238
}
251239

252-
function setValue4fv( gl, v ) {
240+
function setValueV4f( gl, v ) {
253241

254242
var cache = this.cache;
255243

@@ -280,7 +268,7 @@ function setValue4fv( gl, v ) {
280268

281269
// Single matrix (from flat array or MatrixN)
282270

283-
function setValue2fm( gl, v ) {
271+
function setValueM2( gl, v ) {
284272

285273
var cache = this.cache;
286274
var elements = v.elements;
@@ -307,7 +295,7 @@ function setValue2fm( gl, v ) {
307295

308296
}
309297

310-
function setValue3fm( gl, v ) {
298+
function setValueM3( gl, v ) {
311299

312300
var cache = this.cache;
313301
var elements = v.elements;
@@ -334,7 +322,7 @@ function setValue3fm( gl, v ) {
334322

335323
}
336324

337-
function setValue4fm( gl, v ) {
325+
function setValueM4( gl, v ) {
338326

339327
var cache = this.cache;
340328
var elements = v.elements;
@@ -429,7 +417,19 @@ function setValueT6( gl, v, textures ) {
429417

430418
// Integer / Boolean vectors or arrays thereof (always flat arrays)
431419

432-
function setValue2iv( gl, v ) {
420+
function setValueV1i( gl, v ) {
421+
422+
var cache = this.cache;
423+
424+
if ( arraysEqual( cache, v ) ) return;
425+
426+
gl.uniform1iv( this.addr, v );
427+
428+
copyArray( cache, v );
429+
430+
}
431+
432+
function setValueV2i( gl, v ) {
433433

434434
var cache = this.cache;
435435

@@ -441,7 +441,7 @@ function setValue2iv( gl, v ) {
441441

442442
}
443443

444-
function setValue3iv( gl, v ) {
444+
function setValueV3i( gl, v ) {
445445

446446
var cache = this.cache;
447447

@@ -453,7 +453,7 @@ function setValue3iv( gl, v ) {
453453

454454
}
455455

456-
function setValue4iv( gl, v ) {
456+
function setValueV4i( gl, v ) {
457457

458458
var cache = this.cache;
459459

@@ -471,151 +471,123 @@ function getSingularSetter( type ) {
471471

472472
switch ( type ) {
473473

474-
case 0x1406: return setValue1f; // FLOAT
475-
case 0x8b50: return setValue2fv; // _VEC2
476-
case 0x8b51: return setValue3fv; // _VEC3
477-
case 0x8b52: return setValue4fv; // _VEC4
474+
case 0x1406: return setValueV1f; // FLOAT
475+
case 0x8b50: return setValueV2f; // _VEC2
476+
case 0x8b51: return setValueV3f; // _VEC3
477+
case 0x8b52: return setValueV4f; // _VEC4
478478

479-
case 0x8b5a: return setValue2fm; // _MAT2
480-
case 0x8b5b: return setValue3fm; // _MAT3
481-
case 0x8b5c: return setValue4fm; // _MAT4
479+
case 0x8b5a: return setValueM2; // _MAT2
480+
case 0x8b5b: return setValueM3; // _MAT3
481+
case 0x8b5c: return setValueM4; // _MAT4
482482

483483
case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
484484
case 0x8b5f: return setValueT3D1; // SAMPLER_3D
485485
case 0x8b60: return setValueT6; // SAMPLER_CUBE
486486
case 0x8DC1: return setValueT2DArray1; // SAMPLER_2D_ARRAY
487487

488-
case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
489-
case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
490-
case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
491-
case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
488+
case 0x1404: case 0x8b56: return setValueV1i; // INT, BOOL
489+
case 0x8b53: case 0x8b57: return setValueV2i; // _VEC2
490+
case 0x8b54: case 0x8b58: return setValueV3i; // _VEC3
491+
case 0x8b55: case 0x8b59: return setValueV4i; // _VEC4
492492

493493
}
494494

495495
}
496496

497497
// Array of scalars
498+
function setValueV1fArray( gl, v ) {
498499

499-
function setValue1fv( gl, v ) {
500+
gl.uniform1fv( this.addr, v );
500501

501-
var cache = this.cache;
502+
}
502503

503-
if ( arraysEqual( cache, v ) ) return;
504+
// Integer / Boolean vectors or arrays thereof (always flat arrays)
505+
function setValueV1iArray( gl, v ) {
504506

505-
gl.uniform1fv( this.addr, v );
507+
gl.uniform1iv( this.addr, v );
506508

507-
copyArray( cache, v );
509+
}
510+
511+
function setValueV2iArray( gl, v ) {
512+
513+
gl.uniform2iv( this.addr, v );
508514

509515
}
510-
function setValue1iv( gl, v ) {
511516

512-
var cache = this.cache;
517+
function setValueV3iArray( gl, v ) {
513518

514-
if ( arraysEqual( cache, v ) ) return;
519+
gl.uniform3iv( this.addr, v );
515520

516-
gl.uniform1iv( this.addr, v );
521+
}
517522

518-
copyArray( cache, v );
523+
function setValueV4iArray( gl, v ) {
524+
525+
gl.uniform4iv( this.addr, v );
519526

520527
}
521528

529+
522530
// Array of vectors (flat or from THREE classes)
523531

524-
function setValueV2a( gl, v ) {
532+
function setValueV2fArray( gl, v ) {
525533

526-
var cache = this.cache;
527534
var data = flatten( v, this.size, 2 );
528535

529-
if ( arraysEqual( cache, data ) ) return;
530-
531536
gl.uniform2fv( this.addr, data );
532537

533-
this.updateCache( data );
534-
535538
}
536539

537-
function setValueV3a( gl, v ) {
540+
function setValueV3fArray( gl, v ) {
538541

539-
var cache = this.cache;
540542
var data = flatten( v, this.size, 3 );
541543

542-
if ( arraysEqual( cache, data ) ) return;
543-
544544
gl.uniform3fv( this.addr, data );
545545

546-
this.updateCache( data );
547-
548546
}
549547

550-
function setValueV4a( gl, v ) {
548+
function setValueV4fArray( gl, v ) {
551549

552-
var cache = this.cache;
553550
var data = flatten( v, this.size, 4 );
554551

555-
if ( arraysEqual( cache, data ) ) return;
556-
557552
gl.uniform4fv( this.addr, data );
558553

559-
this.updateCache( data );
560-
561554
}
562555

563556
// Array of matrices (flat or from THREE clases)
564557

565-
function setValueM2a( gl, v ) {
558+
function setValueM2Array( gl, v ) {
566559

567-
var cache = this.cache;
568560
var data = flatten( v, this.size, 4 );
569561

570-
if ( arraysEqual( cache, data ) ) return;
571-
572562
gl.uniformMatrix2fv( this.addr, false, data );
573563

574-
this.updateCache( data );
575-
576564
}
577565

578-
function setValueM3a( gl, v ) {
566+
function setValueM3Array( gl, v ) {
579567

580-
var cache = this.cache;
581568
var data = flatten( v, this.size, 9 );
582569

583-
if ( arraysEqual( cache, data ) ) return;
584-
585570
gl.uniformMatrix3fv( this.addr, false, data );
586571

587-
this.updateCache( data );
588-
589572
}
590573

591-
function setValueM4a( gl, v ) {
574+
function setValueM4Array( gl, v ) {
592575

593-
var cache = this.cache;
594576
var data = flatten( v, this.size, 16 );
595577

596-
if ( arraysEqual( cache, data ) ) return;
597-
598578
gl.uniformMatrix4fv( this.addr, false, data );
599579

600-
this.updateCache( data );
601-
602580
}
603581

604582
// Array of textures (2D / Cube)
605583

606-
function setValueT1a( gl, v, textures ) {
584+
function setValueT1Array( gl, v, textures ) {
607585

608-
var cache = this.cache;
609586
var n = v.length;
610587

611588
var units = allocTexUnits( textures, n );
612589

613-
if ( arraysEqual( cache, units ) === false ) {
614-
615-
gl.uniform1iv( this.addr, units );
616-
copyArray( cache, units );
617-
618-
}
590+
gl.uniform1iv( this.addr, units );
619591

620592
for ( var i = 0; i !== n; ++ i ) {
621593

@@ -625,19 +597,13 @@ function setValueT1a( gl, v, textures ) {
625597

626598
}
627599

628-
function setValueT6a( gl, v, textures ) {
600+
function setValueT6Array( gl, v, textures ) {
629601

630-
var cache = this.cache;
631602
var n = v.length;
632603

633604
var units = allocTexUnits( textures, n );
634605

635-
if ( arraysEqual( cache, units ) === false ) {
636-
637-
gl.uniform1iv( this.addr, units );
638-
copyArray( cache, units );
639-
640-
}
606+
gl.uniform1iv( this.addr, units );
641607

642608
for ( var i = 0; i !== n; ++ i ) {
643609

@@ -653,22 +619,22 @@ function getPureArraySetter( type ) {
653619

654620
switch ( type ) {
655621

656-
case 0x1406: return setValue1fv; // FLOAT
657-
case 0x8b50: return setValueV2a; // _VEC2
658-
case 0x8b51: return setValueV3a; // _VEC3
659-
case 0x8b52: return setValueV4a; // _VEC4
622+
case 0x1406: return setValueV1fArray; // FLOAT
623+
case 0x8b50: return setValueV2fArray; // _VEC2
624+
case 0x8b51: return setValueV3fArray; // _VEC3
625+
case 0x8b52: return setValueV4fArray; // _VEC4
660626

661-
case 0x8b5a: return setValueM2a; // _MAT2
662-
case 0x8b5b: return setValueM3a; // _MAT3
663-
case 0x8b5c: return setValueM4a; // _MAT4
627+
case 0x8b5a: return setValueM2Array; // _MAT2
628+
case 0x8b5b: return setValueM3Array; // _MAT3
629+
case 0x8b5c: return setValueM4Array; // _MAT4
664630

665-
case 0x8b5e: return setValueT1a; // SAMPLER_2D
666-
case 0x8b60: return setValueT6a; // SAMPLER_CUBE
631+
case 0x8b5e: return setValueT1Array; // SAMPLER_2D
632+
case 0x8b60: return setValueT6Array; // SAMPLER_CUBE
667633

668-
case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
669-
case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
670-
case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
671-
case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
634+
case 0x1404: case 0x8b56: return setValueV1iArray; // INT, BOOL
635+
case 0x8b53: case 0x8b57: return setValueV2iArray; // _VEC2
636+
case 0x8b54: case 0x8b58: return setValueV3iArray; // _VEC3
637+
case 0x8b55: case 0x8b59: return setValueV4iArray; // _VEC4
672638

673639
}
674640

0 commit comments

Comments
 (0)