@@ -66100,6 +66100,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
6610066100 const _customShaders = new WebGLShaderCache();
6610166101 const _activeChannels = new Set();
6610266102 const programs = [];
66103+ const programsMap = new Map();
6610366104
6610466105 const logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
6610566106
@@ -66676,29 +66677,19 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
6667666677
6667766678 function acquireProgram( parameters, cacheKey ) {
6667866679
66679- let program;
66680+ let program = programsMap.get( cacheKey ) ;
6668066681
66681- // Check if code has been already compiled
66682- for ( let p = 0, pl = programs.length; p < pl; p ++ ) {
66682+ if ( program !== undefined ) {
6668366683
66684- const preexistingProgram = programs[ p ] ;
66684+ ++ program.usedTimes ;
6668566685
66686- if ( preexistingProgram.cacheKey === cacheKey ) {
66687-
66688- program = preexistingProgram;
66689- ++ program.usedTimes;
66690-
66691- break;
66692-
66693- }
66694-
66695- }
66696-
66697- if ( program === undefined ) {
66686+ } else {
6669866687
6669966688 program = new WebGLProgram( renderer, cacheKey, parameters, bindingStates );
6670066689 programs.push( program );
6670166690
66691+ programsMap.set( cacheKey, program );
66692+
6670266693 }
6670366694
6670466695 return program;
@@ -66714,6 +66705,9 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
6671466705 programs[ i ] = programs[ programs.length - 1 ];
6671566706 programs.pop();
6671666707
66708+ // Remove from map
66709+ programsMap.delete( program.cacheKey );
66710+
6671766711 // Free WebGL resources
6671866712 program.destroy();
6671966713
0 commit comments