MCPcopy Index your code
hub / github.com/processing/p5.js / getWebGLUniformMetadata

Function getWebGLUniformMetadata

src/webgl/utils.js:331–376  ·  view source on GitHub ↗
(shader, gl)

Source from the content-addressed store, hash-verified

329}
330
331export function getWebGLUniformMetadata(shader, gl) {
332 const program = shader._glProgram;
333
334 const numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
335 const result = [];
336
337 let samplerIndex = 0;
338
339 for (let i = 0; i < numUniforms; ++i) {
340 const uniformInfo = gl.getActiveUniform(program, i);
341 const uniform = {};
342 uniform.location = gl.getUniformLocation(program, uniformInfo.name);
343 uniform.size = uniformInfo.size;
344 let uniformName = uniformInfo.name;
345 //uniforms that are arrays have their name returned as
346 //someUniform[0] which is a bit silly so we trim it
347 //off here. The size property tells us that its an array
348 //so we dont lose any information by doing this
349 if (uniformInfo.size > 1) {
350 uniformName = uniformName.substring(0, uniformName.indexOf("[0]"));
351 }
352 uniform.name = uniformName;
353 uniform.type = uniformInfo.type;
354 uniform._cachedData = undefined;
355 if (uniform.type === gl.SAMPLER_2D) {
356 uniform.isSampler = true;
357 uniform.samplerIndex = samplerIndex;
358 samplerIndex++;
359 }
360
361 uniform.isArray =
362 uniformInfo.size > 1 ||
363 uniform.type === gl.FLOAT_MAT3 ||
364 uniform.type === gl.FLOAT_MAT4 ||
365 uniform.type === gl.FLOAT_VEC2 ||
366 uniform.type === gl.FLOAT_VEC3 ||
367 uniform.type === gl.FLOAT_VEC4 ||
368 uniform.type === gl.INT_VEC2 ||
369 uniform.type === gl.INT_VEC4 ||
370 uniform.type === gl.INT_VEC3;
371
372 result.push(uniform);
373 }
374
375 return result;
376}
377
378export function getWebGLShaderAttributes(shader, gl) {
379 const attributes = {};

Callers 2

constructorMethod · 0.90
getUniformMetadataMethod · 0.90

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected