Build the shProg->Uniforms list. This is basically a list/index of all uniforms found in either/both of the vertex and fragment shaders.
About uniforms: Each uniform has two indexes, one that points into the vertex program's parameter array and another that points into the fragment program's parameter array. When the user changes a uniform's value we have to change the value in the vertex and/or fragment program's parameter array.
This function will be called twice to set up the two uniform->parameter mappings.
If a uniform is only present in the vertex program OR fragment program then the fragment/vertex parameter index, respectively, will be -1.
Definition at line 225 of file slang_link.c.
Referenced by _slang_link().
{
GLuint samplerMap[200];
GLuint i;
for (i = 0; i < prog->Parameters->NumParameters; i++) {
const struct gl_program_parameter *p = prog->Parameters->Parameters + i;
if ((p->Type == PROGRAM_UNIFORM || p->Type == PROGRAM_SAMPLER)
&& p->Used) {
struct gl_uniform *uniform =
_mesa_append_uniform(shProg->Uniforms, p->Name, prog->Target, i);
if (uniform)
uniform->Initialized = p->Initialized;
}
if (p->Type == PROGRAM_SAMPLER && p->Used) {
GLuint oldSampNum = (GLuint) prog->Parameters->ParameterValues[i][0];
GLuint newSampNum = *numSamplers;
if (newSampNum >= ctx->Const.MaxTextureImageUnits) {
char s[100];
_mesa_sprintf(s, "Too many texture samplers (%u, max is %u)",
newSampNum, ctx->Const.MaxTextureImageUnits);
link_error(shProg, s);
return GL_FALSE;
}
if (oldSampNum < Elements(samplerMap))
samplerMap[oldSampNum] = newSampNum;
prog->Parameters->ParameterValues[i][0] = (GLfloat) newSampNum;
(*numSamplers)++;
}
}
prog->SamplersUsed = 0x0;
for (i = 0; i < prog->NumInstructions; i++) {
struct prog_instruction *inst = prog->Instructions + i;
if (_mesa_is_tex_instruction(inst->Opcode)) {
const GLint oldSampNum = inst->TexSrcUnit;
#if 0
printf("====== remap sampler from %d to %d\n",
inst->TexSrcUnit, samplerMap[ inst->TexSrcUnit ]);
#endif
if (oldSampNum < Elements(samplerMap)) {
const GLuint newSampNum = samplerMap[oldSampNum];
inst->TexSrcUnit = newSampNum;
prog->SamplerTargets[newSampNum] = inst->TexSrcTarget;
prog->SamplersUsed |= (1 << newSampNum);
}
}
}
return GL_TRUE;
}