Skip to content

Commit

Permalink
Merge pull request mrdoob#17748 from higharc/rename-program-code
Browse files Browse the repository at this point in the history
Rename WebGLProgram "code" to "cacheKey"
  • Loading branch information
mrdoob authored Oct 21, 2019
2 parents 3eb84a5 + 91d02e7 commit a6b2e37
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
10 changes: 5 additions & 5 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ function WebGLRenderer( parameters ) {
var parameters = programCache.getParameters(
material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );

var code = programCache.getProgramCode( material, parameters );
var programCacheKey = programCache.getProgramCacheKey( material, parameters );

var program = materialProperties.program;
var programChange = true;
Expand All @@ -1507,7 +1507,7 @@ function WebGLRenderer( parameters ) {
// new material
material.addEventListener( 'dispose', onMaterialDispose );

} else if ( program.code !== code ) {
} else if ( program.cacheKey !== programCacheKey ) {

// changed glsl or parameters
releaseMaterialProgramReference( material );
Expand Down Expand Up @@ -1556,10 +1556,10 @@ function WebGLRenderer( parameters ) {

material.onBeforeCompile( materialProperties.shader, _this );

// Computing code again as onBeforeCompile may have changed the shaders
code = programCache.getProgramCode( material, parameters );
// Computing cache key again as onBeforeCompile may have changed the shaders
programCacheKey = programCache.getProgramCacheKey( material, parameters );

program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
program = programCache.acquireProgram( material, materialProperties.shader, parameters, programCacheKey );

materialProperties.program = program;
material.program = program;
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/webgl/WebGLProgram.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ export class WebGLProgram {
constructor(
renderer: WebGLRenderer,
extensions: WebGLExtensions,
code: string,
cacheKey: string,
material: ShaderMaterial,
shader: WebGLShader,
parameters: WebGLRendererParameters
);

id: number;
code: string;
cacheKey: string; // unique identifier for this program, used for looking up compiled programs from cache.
usedTimes: number;
program: any;
vertexShader: WebGLShader;
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/webgl/WebGLProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ function generateEnvMapBlendingDefine( parameters ) {

}

function WebGLProgram( renderer, extensions, code, material, shader, parameters ) {
function WebGLProgram( renderer, extensions, cacheKey, material, shader, parameters ) {

var gl = renderer.getContext();

Expand Down Expand Up @@ -884,7 +884,7 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters

this.name = shader.name;
this.id = programIdCount ++;
this.code = code;
this.cacheKey = cacheKey;
this.usedTimes = 1;
this.program = program;
this.vertexShader = glVertexShader;
Expand Down
10 changes: 5 additions & 5 deletions src/renderers/webgl/WebGLPrograms.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { WebGLRenderer } from './../WebGLRenderer';
import { WebGLProgram } from './WebGLProgram';
import { WebGLCapabilities } from './WebGLCapabilities';
import { WebGLExtensions } from './WebGLExtensions';
import { ShaderMaterial } from './../../materials/ShaderMaterial';
import { Material } from './../../materials/Material';

export class WebGLPrograms {

Expand All @@ -11,17 +11,17 @@ export class WebGLPrograms {
programs: WebGLProgram[];

getParameters(
material: ShaderMaterial,
material: Material,
lights: any,
fog: any,
nClipPlanes: number,
object: any
): any;
getProgramCode( material: ShaderMaterial, parameters: any ): string;
getProgramCacheKey( material: Material, parameters: any ): string;
acquireProgram(
material: ShaderMaterial,
material: Material,
parameters: any,
code: string
cacheKey: string
): WebGLProgram;
releaseProgram( program: WebGLProgram ): void;

Expand Down
12 changes: 6 additions & 6 deletions src/renderers/webgl/WebGLPrograms.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) {

};

this.getProgramCode = function ( material, parameters ) {
this.getProgramCacheKey = function ( material, parameters ) {

var array = [];

Expand Down Expand Up @@ -282,18 +282,18 @@ function WebGLPrograms( renderer, extensions, capabilities ) {

};

this.acquireProgram = function ( material, shader, parameters, code ) {
this.acquireProgram = function ( material, shader, parameters, cacheKey ) {

var program;

// Check if code has been already compiled
for ( var p = 0, pl = programs.length; p < pl; p ++ ) {

var programInfo = programs[ p ];
var preexistingProgram = programs[ p ];

if ( programInfo.code === code ) {
if ( preexistingProgram.cacheKey === cacheKey ) {

program = programInfo;
program = preexistingProgram;
++ program.usedTimes;

break;
Expand All @@ -304,7 +304,7 @@ function WebGLPrograms( renderer, extensions, capabilities ) {

if ( program === undefined ) {

program = new WebGLProgram( renderer, extensions, code, material, shader, parameters );
program = new WebGLProgram( renderer, extensions, cacheKey, material, shader, parameters );
programs.push( program );

}
Expand Down

0 comments on commit a6b2e37

Please sign in to comment.