if (values) {
COPY_4V(paramList->ParameterValues[oldNum + i], values);
values += 4;
+ p->Initialized = GL_TRUE;
}
else {
/* silence valgrind */
*/
GLint
_mesa_add_uniform(struct gl_program_parameter_list *paramList,
- const char *name, GLuint size, GLenum datatype)
+ const char *name, GLuint size, GLenum datatype,
+ const GLfloat *values)
{
GLint i = _mesa_lookup_parameter_index(paramList, -1, name);
ASSERT(datatype != GL_NONE);
}
else {
i = _mesa_add_parameter(paramList, PROGRAM_UNIFORM, name,
- size, datatype, NULL, NULL);
+ size, datatype, values, NULL);
return i;
}
}
GLenum DataType; /**< GL_FLOAT, GL_FLOAT_VEC2, etc */
GLuint Size; /**< Number of components (1..4) */
GLboolean Used; /**< Helper flag for GLSL uniform tracking */
+ GLboolean Initialized; /**< Has the ParameterValue[] been set? */
/**
* A sequence of STATE_* tokens and integers to identify GL state.
*/
extern GLint
_mesa_add_uniform(struct gl_program_parameter_list *paramList,
- const char *name, GLuint size, GLenum datatype);
+ const char *name, GLuint size, GLenum datatype,
+ const GLfloat *values);
extern void
_mesa_use_uniform(struct gl_program_parameter_list *paramList,
}
-GLboolean
+struct gl_uniform *
_mesa_append_uniform(struct gl_uniform_list *list,
const char *name, GLenum target, GLuint progPos)
{
const GLuint oldNum = list->NumUniforms;
+ struct gl_uniform *uniform;
GLint index;
assert(target == GL_VERTEX_PROGRAM_ARB ||
return GL_FALSE;
}
- list->Uniforms[oldNum].Name = _mesa_strdup(name);
- list->Uniforms[oldNum].VertPos = -1;
- list->Uniforms[oldNum].FragPos = -1;
- list->Uniforms[oldNum].Initialized = GL_FALSE;
- index = oldNum;
+ uniform = list->Uniforms + oldNum;
+
+ uniform->Name = _mesa_strdup(name);
+ uniform->VertPos = -1;
+ uniform->FragPos = -1;
+ uniform->Initialized = GL_FALSE;
+
list->NumUniforms++;
}
+ else {
+ /* found */
+ uniform = list->Uniforms + index;
+ }
/* update position for the vertex or fragment program */
if (target == GL_VERTEX_PROGRAM_ARB) {
- if (list->Uniforms[index].VertPos != -1) {
+ if (uniform->VertPos != -1) {
/* this uniform is already in the list - that shouldn't happen */
return GL_FALSE;
}
- list->Uniforms[index].VertPos = progPos;
+ uniform->VertPos = progPos;
}
else {
- if (list->Uniforms[index].FragPos != -1) {
+ if (uniform->FragPos != -1) {
/* this uniform is already in the list - that shouldn't happen */
return GL_FALSE;
}
- list->Uniforms[index].FragPos = progPos;
+ uniform->FragPos = progPos;
}
- return GL_TRUE;
+ return uniform;
}
extern void
_mesa_free_uniform_list(struct gl_uniform_list *list);
-extern GLboolean
+extern struct gl_uniform *
_mesa_append_uniform(struct gl_uniform_list *list,
const char *name, GLenum target, GLuint progPos);
const GLvoid *values, GLenum type)
{
struct gl_shader_program *shProg = ctx->Shader.CurrentProgram;
+ struct gl_uniform *uniform;
GLint elems, offset;
if (!shProg || !shProg->LinkStatus) {
FLUSH_VERTICES(ctx, _NEW_PROGRAM);
+ uniform = &shProg->Uniforms->Uniforms[location];
+
/* A uniform var may be used by both a vertex shader and a fragment
* shader. We may need to update one or both shader's uniform here:
*/
if (shProg->VertexProgram) {
/* convert uniform location to program parameter index */
- GLint index = shProg->Uniforms->Uniforms[location].VertPos;
+ GLint index = uniform->VertPos;
if (index >= 0) {
set_program_uniform(ctx, &shProg->VertexProgram->Base,
index, offset, type, count, elems, values);
if (shProg->FragmentProgram) {
/* convert uniform location to program parameter index */
- GLint index = shProg->Uniforms->Uniforms[location].FragPos;
+ GLint index = uniform->FragPos;
if (index >= 0) {
set_program_uniform(ctx, &shProg->FragmentProgram->Base,
index, offset, type, count, elems, values);
}
}
- shProg->Uniforms->Uniforms[location].Initialized = GL_TRUE;
+ uniform->Initialized = GL_TRUE;
}
GLenum matrixType, GLint location, GLsizei count,
GLboolean transpose, const GLfloat *values)
{
- GLint offset;
struct gl_shader_program *shProg = ctx->Shader.CurrentProgram;
+ struct gl_uniform *uniform;
+ GLint offset;
if (!shProg || !shProg->LinkStatus) {
_mesa_error(ctx, GL_INVALID_OPERATION,
FLUSH_VERTICES(ctx, _NEW_PROGRAM);
+ uniform = &shProg->Uniforms->Uniforms[location];
+
if (shProg->VertexProgram) {
/* convert uniform location to program parameter index */
- GLint index = shProg->Uniforms->Uniforms[location].VertPos;
+ GLint index = uniform->VertPos;
if (index >= 0) {
set_program_uniform_matrix(ctx, &shProg->VertexProgram->Base,
index, offset,
if (shProg->FragmentProgram) {
/* convert uniform location to program parameter index */
- GLint index = shProg->Uniforms->Uniforms[location].FragPos;
+ GLint index = uniform->FragPos;
if (index >= 0) {
set_program_uniform_matrix(ctx, &shProg->FragmentProgram->Base,
index, offset,
}
}
- shProg->Uniforms->Uniforms[location].Initialized = GL_TRUE;
+ uniform->Initialized = GL_TRUE;
}
/* temporary work-around */
GLenum datatype = GL_FLOAT;
GLint uniformLoc = _mesa_add_uniform(prog->Parameters, varName,
- totalSize, datatype);
+ totalSize, datatype, NULL);
store = _slang_new_ir_storage_swz(PROGRAM_UNIFORM, uniformLoc,
totalSize, swizzle);
}
}
else {
- GLint uniformLoc = _mesa_add_uniform(prog->Parameters, varName,
- totalSize, datatype);
- store = _slang_new_ir_storage_swz(PROGRAM_UNIFORM, uniformLoc,
- totalSize, swizzle);
+ GLint uniformLoc;
+ const GLfloat *initialValues = NULL;
if (var->initializer) {
_slang_simplify(var->initializer, &A->space, A->atoms);
if (var->initializer->type == SLANG_OPER_LITERAL_FLOAT ||
var->initializer->type == SLANG_OPER_LITERAL_INT) {
/* simple float/vector initializer */
- GLfloat *uniformValue =
- prog->Parameters->ParameterValues[uniformLoc];
- COPY_4V(uniformValue, var->initializer->literal);
+ initialValues = var->initializer->literal;
}
else {
/* complex initializer */
return GL_FALSE;
}
}
+
+ uniformLoc = _mesa_add_uniform(prog->Parameters, varName,
+ totalSize, datatype, initialValues);
+ store = _slang_new_ir_storage_swz(PROGRAM_UNIFORM, uniformLoc,
+ totalSize, swizzle);
}
}
else {
if ((p->Type == PROGRAM_UNIFORM && p->Used) ||
p->Type == PROGRAM_SAMPLER) {
- _mesa_append_uniform(shProg->Uniforms, p->Name, prog->Target, i);
+ 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) {