MCPcopy
hub / github.com/processing/p5.js / setUniform

Method setUniform

src/webgl/p5.Shader.js:1098–1140  ·  view source on GitHub ↗

* Sets the shader’s uniform (global) variables. * * Shader programs run on the computer’s graphics processing unit (GPU). * They live in part of the computer’s memory that’s completely separate * from the sketch that runs them. Uniforms are global variables within a * shader program.

(uniformName, data)

Source from the content-addressed store, hash-verified

1096 * }
1097 */
1098 setUniform(uniformName, data) {
1099 this.init();
1100
1101 const uniform = this.uniforms[uniformName];
1102 if (!uniform) {
1103 return;
1104 }
1105
1106 // In p5.strands-related code, where some of the code may be in
1107 // p5.webgpu.js instead of the main p5.js build, we generally use
1108 // duck typing instead of instanceof to avoid accidentally importing
1109 // and comparing against a separate copy of p5 classes
1110 if (data?.isVector) {
1111 data = data.values.length !== data.dimensions ? data.values.slice(0, data.dimensions) : data.values;
1112 } else if (data?.isColor) {
1113 data = data._getRGBA([1, 1, 1, 1]);
1114 }
1115
1116 if (uniform.isArray) {
1117 if (
1118 uniform._cachedData &&
1119 this._renderer._arraysEqual(uniform._cachedData, data)
1120 ) {
1121 return;
1122 } else {
1123 uniform._cachedData = data.slice(0);
1124 }
1125 } else if (uniform._cachedData && uniform._cachedData === data) {
1126 return;
1127 } else {
1128 if (Array.isArray(data) || data instanceof TypedArray) {
1129 if (uniform._cachedData && this._renderer._arraysEqual(uniform._cachedData, data)) {
1130 return;
1131 }
1132 uniform._cachedData = data.slice(0);
1133 } else {
1134 if (uniform._cachedData === data) return;
1135 uniform._cachedData = data;
1136 }
1137 }
1138
1139 this._renderer.updateUniformValue(this, uniform, data);
1140 }
1141
1142 /**
1143 * @chainable

Callers 15

setDefaultUniformsMethod · 0.95
drawBlobMethod · 0.80
drawFunction · 0.80
drawFunction · 0.80
setupFunction · 0.80
drawFunction · 0.80
p5.Shader.jsFile · 0.80
p5.RendererGL.jsFile · 0.80
p5.Shader.jsFile · 0.80
webgpu.jsFile · 0.80
webgl.jsFile · 0.80

Calls 5

initMethod · 0.95
sliceMethod · 0.80
_getRGBAMethod · 0.80
_arraysEqualMethod · 0.80
updateUniformValueMethod · 0.45

Tested by

no test coverage detected