Skip to content

Commit

Permalink
Rename WebGLProgram "code" to "hash"
Browse files Browse the repository at this point in the history
This name is clearer since "code" can be easily confused to mean shader code in this context.

Settling on a good name here is important because we want to expose the ability to customize the hash through the API.
  • Loading branch information
Oletus committed Oct 17, 2019
1 parent 33ebb86 commit f964ded
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 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 programHash = programCache.getProgramHash( 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.hash !== programHash ) {

// 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 hash again as onBeforeCompile may have changed the shaders
programHash = programCache.getProgramHash( material, parameters );

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

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,
hash: string,
material: ShaderMaterial,
shader: WebGLShader,
parameters: WebGLRendererParameters
);

id: number;
code: string;
hash: string; // unique hash 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, hash, 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.hash = hash;
this.usedTimes = 1;
this.program = program;
this.vertexShader = glVertexShader;
Expand Down
8 changes: 4 additions & 4 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,15 +11,15 @@ 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;
getProgramHash( material: Material, parameters: any ): string;
acquireProgram(
material: ShaderMaterial,
material: Material,
parameters: any,
code: string
): WebGLProgram;
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.getProgramHash = 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, hash ) {

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.hash === hash ) {

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, hash, material, shader, parameters );
programs.push( program );

}
Expand Down

0 comments on commit f964ded

Please sign in to comment.