*/
-#include "glheader.h"
-#include "imports.h"
-#include "macros.h"
+#include "main/glheader.h"
+#include "main/imports.h"
+#include "main/macros.h"
#include "prog_instruction.h"
#include "prog_parameter.h"
#include "prog_statevars.h"
struct gl_program_parameter_list *
_mesa_new_parameter_list(void)
{
- return (struct gl_program_parameter_list *)
- _mesa_calloc(sizeof(struct gl_program_parameter_list));
+ return CALLOC_STRUCT(gl_program_parameter_list);
}
}
-
/**
* Add a new parameter to a parameter list.
* Note that parameter values are usually 4-element GLfloat vectors.
if (values) {
COPY_4V(paramList->ParameterValues[oldNum + i], values);
values += 4;
+ p->Initialized = GL_TRUE;
}
else {
/* silence valgrind */
}
+/**
+ * Add a uniform to the parameter list.
+ * Note that if the uniform is an array, size may be greater than
+ * what's implied by the datatype.
+ * \param name uniform's name
+ * \param size number of floats to allocate
+ * \param datatype GL_FLOAT_VEC3, GL_FLOAT_MAT4, etc.
+ */
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;
}
}
+/**
+ * Mark the named uniform as 'used'.
+ */
+void
+_mesa_use_uniform(struct gl_program_parameter_list *paramList,
+ const char *name)
+{
+ GLuint i;
+ for (i = 0; i < paramList->NumParameters; i++) {
+ struct gl_program_parameter *p = paramList->Parameters + i;
+ if (p->Type == PROGRAM_UNIFORM && _mesa_strcmp(p->Name, name) == 0) {
+ p->Used = GL_TRUE;
+ /* Note that large uniforms may occupy several slots so we're
+ * not done searching yet.
+ */
+ }
+ }
+}
+
+
+/**
+ * Add a sampler to the parameter list.
+ * \param name uniform's name
+ * \param datatype GL_SAMPLER_2D, GL_SAMPLER_2D_RECT_ARB, etc.
+ * \param index the sampler number (as seen in TEX instructions)
+ * \return sampler index (starting at zero) or -1 if error
+ */
GLint
_mesa_add_sampler(struct gl_program_parameter_list *paramList,
const char *name, GLenum datatype)
{
GLint i = _mesa_lookup_parameter_index(paramList, -1, name);
if (i >= 0 && paramList->Parameters[i].Type == PROGRAM_SAMPLER) {
+ ASSERT(paramList->Parameters[i].Size == 1);
+ ASSERT(paramList->Parameters[i].DataType == datatype);
/* already in list */
- return i;
+ return (GLint) paramList->ParameterValues[i][0];
}
else {
- const GLint size = 1;
- i = _mesa_add_parameter(paramList, PROGRAM_SAMPLER, name,
- size, datatype, NULL, NULL);
- return i;
+ GLuint i;
+ const GLint size = 1; /* a sampler is basically a texture unit number */
+ GLfloat value;
+ GLint numSamplers = 0;
+ for (i = 0; i < paramList->NumParameters; i++) {
+ if (paramList->Parameters[i].Type == PROGRAM_SAMPLER)
+ numSamplers++;
+ }
+ value = (GLfloat) numSamplers;
+ (void) _mesa_add_parameter(paramList, PROGRAM_SAMPLER, name,
+ size, datatype, &value, NULL);
+ return numSamplers;
}
}
return i;
}
else {
- assert(size == 4);
+ /*assert(size == 4);*/
i = _mesa_add_parameter(paramList, PROGRAM_VARYING, name,
size, GL_NONE, NULL, NULL);
return i;
*/
GLint
_mesa_add_attribute(struct gl_program_parameter_list *paramList,
- const char *name, GLint size, GLint attrib)
+ const char *name, GLint size, GLenum datatype, GLint attrib)
{
GLint i = _mesa_lookup_parameter_index(paramList, -1, name);
if (i >= 0) {
if (size < 0)
size = 4;
i = _mesa_add_parameter(paramList, PROGRAM_INPUT, name,
- size, GL_NONE, NULL, state);
+ size, datatype, NULL, state);
}
return i;
}
* PARAM ambient = state.material.front.ambient;
*
* \param paramList the parameter list
- * \param state an array of 6 (STATE_LENGTH) state tokens
+ * \param stateTokens an array of 5 (STATE_LENGTH) state tokens
* \return index of the new parameter.
*/
GLint
const gl_state_index stateTokens[STATE_LENGTH])
{
const GLuint size = 4; /* XXX fix */
- const char *name;
+ char *name;
GLint index;
/* Check if the state reference is already in the list */
paramList->StateFlags |= _mesa_program_state_flags(stateTokens);
/* free name string here since we duplicated it in add_parameter() */
- _mesa_free((void *) name);
+ _mesa_free(name);
return index;
}
/** Not too efficient, but correct */
for (i = 0; i < list->NumParameters; i++) {
struct gl_program_parameter *p = list->Parameters + i;
+ struct gl_program_parameter *pCopy;
GLuint size = MIN2(p->Size, 4);
GLint j = _mesa_add_parameter(clone, p->Type, p->Name, size, p->DataType,
list->ParameterValues[i], NULL);
ASSERT(j >= 0);
+ pCopy = clone->Parameters + j;
+ pCopy->Used = p->Used;
/* copy state indexes */
if (p->Type == PROGRAM_STATE_VAR) {
GLint k;
- struct gl_program_parameter *q = clone->Parameters + j;
for (k = 0; k < STATE_LENGTH; k++) {
- q->StateIndexes[k] = p->StateIndexes[k];
+ pCopy->StateIndexes[k] = p->StateIndexes[k];
}
}
else {
clone->Parameters[j].Size = p->Size;
}
+
}
+ clone->StateFlags = list->StateFlags;
+
return clone;
}
+/**
+ * Return a new parameter list which is listA + listB.
+ */
+struct gl_program_parameter_list *
+_mesa_combine_parameter_lists(const struct gl_program_parameter_list *listA,
+ const struct gl_program_parameter_list *listB)
+{
+ struct gl_program_parameter_list *list;
+
+ if (listA) {
+ list = _mesa_clone_parameter_list(listA);
+ if (list && listB) {
+ GLuint i;
+ for (i = 0; i < listB->NumParameters; i++) {
+ struct gl_program_parameter *param = listB->Parameters + i;
+ _mesa_add_parameter(list, param->Type, param->Name, param->Size,
+ param->DataType,
+ listB->ParameterValues[i],
+ param->StateIndexes);
+ }
+ }
+ }
+ else if (listB) {
+ list = _mesa_clone_parameter_list(listB);
+ }
+ else {
+ list = NULL;
+ }
+ return list;
+}
+
+
+
/**
* Find longest name of all uniform parameters in list.
*/