createUniformSetters static method
Creates uniform setters.
glthe OpenGlES context.programthe program id
Implementation
static createUniformSetters(OpenGLContextES gl, int program) {
var textureUnit = 0;
createUniformSetter(int program, ActiveInfo uniformInfo) {
int location = gl.getUniformLocation(program, uniformInfo.name);
bool isArray = uniformInfo.size > 1 &&
uniformInfo.name.substring(uniformInfo.name.length - 3, uniformInfo.name.length) == "[0]";
int type = uniformInfo.type;
var typeInfo = flutter3DUtils.typeMap[type];
if (typeInfo == null) {
throw "unknown type: 0x" + type.toString(); // we should never get here.
}
if (typeInfo['bindPoint'] != null) {
// it's a sampler
var unit = textureUnit;
textureUnit += uniformInfo.size;
if (isArray) {
return typeInfo['arraySetter'](gl, type, unit, location, uniformInfo.size);
} else {
return typeInfo['setter'](gl, type, unit, location, uniformInfo.size);
}
} else {
if (typeInfo['arraySetter'] != null && isArray) {
return typeInfo['arraySetter'](gl, location);
} else {
return typeInfo['setter'](gl, location);
}
}
}
Map<String, dynamic> uniformSetters = {};
int numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
for (var ii = 0; ii < numUniforms; ++ii) {
ActiveInfo uniformInfo = gl.getActiveUniform(program, ii); // or use ActiveInfo
if (uniformInfo == null) {
break;
}
var name = uniformInfo.name;
// remove the array suffix.
if (name.substring(name.length - 3, name.length) == "[0]") {
name = name.substring(0, name.length - 3);
}
var setter = createUniformSetter(program, uniformInfo);
uniformSetters[name] = setter;
}
return uniformSetters;
}