Skip to content

Commit 0d96487

Browse files
mvaligurskyMartin Valigursky
andauthored
Enable debug warning if the required uniform is null or undefined (playcanvas#7582)
Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
1 parent bc41103 commit 0d96487

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

src/platform/graphics/webgl/webgl-graphics-device.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,14 +1720,10 @@ class WebglGraphicsDevice extends GraphicsDevice {
17201720
return;
17211721
}
17221722

1723-
let sampler, samplerValue, texture, numTextures; // Samplers
1724-
let uniform, scopeId, uniformVersion, programVersion; // Uniforms
17251723
const shader = this.shader;
17261724
if (!shader) {
17271725
return;
17281726
}
1729-
const samplers = shader.impl.samplers;
1730-
const uniforms = shader.impl.uniforms;
17311727

17321728
// vertex buffers
17331729
if (!keepBuffers) {
@@ -1738,10 +1734,10 @@ class WebglGraphicsDevice extends GraphicsDevice {
17381734

17391735
// Commit the shader program variables
17401736
let textureUnit = 0;
1741-
1737+
const samplers = shader.impl.samplers;
17421738
for (let i = 0, len = samplers.length; i < len; i++) {
1743-
sampler = samplers[i];
1744-
samplerValue = sampler.scopeId.value;
1739+
const sampler = samplers[i];
1740+
let samplerValue = sampler.scopeId.value;
17451741
if (!samplerValue) {
17461742

17471743
const samplerName = sampler.scopeId.name;
@@ -1765,7 +1761,7 @@ class WebglGraphicsDevice extends GraphicsDevice {
17651761
}
17661762

17671763
if (samplerValue instanceof Texture) {
1768-
texture = samplerValue;
1764+
const texture = samplerValue;
17691765
this.setTexture(texture, textureUnit);
17701766

17711767
// #if _DEBUG
@@ -1788,9 +1784,9 @@ class WebglGraphicsDevice extends GraphicsDevice {
17881784
textureUnit++;
17891785
} else { // Array
17901786
sampler.array.length = 0;
1791-
numTextures = samplerValue.length;
1787+
const numTextures = samplerValue.length;
17921788
for (let j = 0; j < numTextures; j++) {
1793-
texture = samplerValue[j];
1789+
const texture = samplerValue[j];
17941790
this.setTexture(texture, textureUnit);
17951791

17961792
sampler.array[j] = textureUnit;
@@ -1801,23 +1797,24 @@ class WebglGraphicsDevice extends GraphicsDevice {
18011797
}
18021798

18031799
// Commit any updated uniforms
1800+
const uniforms = shader.impl.uniforms;
18041801
for (let i = 0, len = uniforms.length; i < len; i++) {
1805-
uniform = uniforms[i];
1806-
scopeId = uniform.scopeId;
1807-
uniformVersion = uniform.version;
1808-
programVersion = scopeId.versionObject.version;
1802+
const uniform = uniforms[i];
1803+
const scopeId = uniform.scopeId;
1804+
const uniformVersion = uniform.version;
1805+
const programVersion = scopeId.versionObject.version;
18091806

18101807
// Check the value is valid
18111808
if (uniformVersion.globalId !== programVersion.globalId || uniformVersion.revision !== programVersion.revision) {
18121809
uniformVersion.globalId = programVersion.globalId;
18131810
uniformVersion.revision = programVersion.revision;
18141811

18151812
// Call the function to commit the uniform value
1816-
if (scopeId.value !== null) {
1817-
this.commitFunction[uniform.dataType](uniform, scopeId.value);
1813+
const value = scopeId.value;
1814+
if (value !== null && value !== undefined) {
1815+
this.commitFunction[uniform.dataType](uniform, value);
18181816
} else {
1819-
// commented out till engine issue #4971 is sorted out
1820-
// Debug.warnOnce(`Shader [${shader.label}] requires uniform [${uniform.scopeId.name}] which has not been set, while rendering [${DebugGraphics.toString()}]`);
1817+
Debug.warnOnce(`Shader [${shader.label}] requires uniform [${uniform.scopeId.name}] which has not been set, while rendering [${DebugGraphics.toString()}]`);
18211818
}
18221819
}
18231820
}

0 commit comments

Comments
 (0)