diff options
author | Zou Nan hai <nanhai.zou@intel.com> | 2007-07-04 10:52:35 +0800 |
---|---|---|
committer | Zou Nan hai <nanhai.zou@intel.com> | 2007-07-04 10:52:35 +0800 |
commit | fb9ee9b323bff93973a39560b2bc007aace4bddd (patch) | |
tree | 05e1e72e8f4d321cde2c48b8518e6d9736c680dd /src/mesa/shader/prog_parameter.c | |
parent | 285b326c606e9b2f90e4fe177b15b3fa23239b86 (diff) | |
parent | 7ff4359a3be1278b26950f96ab23014a667af838 (diff) |
Merge branch 'master' of git+ssh://znh@git.freedesktop.org/git/mesa/mesa into 965-glsl
Diffstat (limited to 'src/mesa/shader/prog_parameter.c')
-rw-r--r-- | src/mesa/shader/prog_parameter.c | 79 |
1 files changed, 59 insertions, 20 deletions
diff --git a/src/mesa/shader/prog_parameter.c b/src/mesa/shader/prog_parameter.c index 2c8a340763..9e3d3fecf2 100644 --- a/src/mesa/shader/prog_parameter.c +++ b/src/mesa/shader/prog_parameter.c @@ -81,7 +81,7 @@ _mesa_free_parameter_list(struct gl_program_parameter_list *paramList) GLint _mesa_add_parameter(struct gl_program_parameter_list *paramList, enum register_file type, const char *name, - GLuint size, const GLfloat *values, + GLuint size, GLenum datatype, const GLfloat *values, const gl_state_index state[STATE_LENGTH]) { const GLuint oldNum = paramList->NumParameters; @@ -126,6 +126,7 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList, p->Name = name ? _mesa_strdup(name) : NULL; p->Type = type; p->Size = size; + p->DataType = datatype; if (values) { COPY_4V(paramList->ParameterValues[oldNum + i], values); values += 4; @@ -156,7 +157,7 @@ _mesa_add_named_parameter(struct gl_program_parameter_list *paramList, const char *name, const GLfloat values[4]) { return _mesa_add_parameter(paramList, PROGRAM_NAMED_PARAM, name, - 4, values, NULL); + 4, GL_NONE, values, NULL); } @@ -187,7 +188,7 @@ _mesa_add_named_constant(struct gl_program_parameter_list *paramList, #endif size = 4; /** XXX fix */ return _mesa_add_parameter(paramList, PROGRAM_CONSTANT, name, - size, values, NULL); + size, GL_NONE, values, NULL); } @@ -239,7 +240,7 @@ _mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList, /* add a new parameter to store this constant */ pos = _mesa_add_parameter(paramList, PROGRAM_CONSTANT, NULL, - size, values, NULL); + size, GL_NONE, values, NULL); if (pos >= 0 && swizzleOut) { if (size == 1) *swizzleOut = SWIZZLE_XXXX; @@ -250,37 +251,54 @@ _mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList, } +/** + * 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) + const char *name, GLuint size, GLenum datatype) { GLint i = _mesa_lookup_parameter_index(paramList, -1, name); + ASSERT(datatype != GL_NONE); if (i >= 0 && paramList->Parameters[i].Type == PROGRAM_UNIFORM) { + ASSERT(paramList->Parameters[i].Size == size); + ASSERT(paramList->Parameters[i].DataType == datatype); /* already in list */ return i; } else { i = _mesa_add_parameter(paramList, PROGRAM_UNIFORM, name, - size, NULL, NULL); - + size, datatype, NULL, NULL); return i; } } +/** + * Add a sampler to the parameter list. + * \param name uniform's name + * \param datatype GL_SAMPLER_2D, GL_SAMPLER_2D_RECT_ARB, etc. + */ GLint _mesa_add_sampler(struct gl_program_parameter_list *paramList, - const char *name) + 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; } else { - const GLint size = 1; + const GLint size = 1; /* a sampler is basically a texture unit number */ i = _mesa_add_parameter(paramList, PROGRAM_SAMPLER, name, - size, NULL, NULL); + size, datatype, NULL, NULL); return i; } } @@ -301,7 +319,7 @@ _mesa_add_varying(struct gl_program_parameter_list *paramList, else { assert(size == 4); i = _mesa_add_parameter(paramList, PROGRAM_VARYING, name, - size, NULL, NULL); + size, GL_NONE, NULL, NULL); return i; } } @@ -330,7 +348,7 @@ _mesa_add_attribute(struct gl_program_parameter_list *paramList, if (size < 0) size = 4; i = _mesa_add_parameter(paramList, PROGRAM_INPUT, name, - size, NULL, state); + size, GL_NONE, NULL, state); } return i; } @@ -396,7 +414,8 @@ _mesa_add_state_reference(struct gl_program_parameter_list *paramList, name = _mesa_program_state_string(stateTokens); index = _mesa_add_parameter(paramList, PROGRAM_STATE_VAR, name, - size, NULL, (gl_state_index *) stateTokens); + size, GL_NONE, + NULL, (gl_state_index *) stateTokens); paramList->StateFlags |= _mesa_program_state_flags(stateTokens); /* free name string here since we duplicated it in add_parameter() */ @@ -565,8 +584,8 @@ _mesa_clone_parameter_list(const struct gl_program_parameter_list *list) for (i = 0; i < list->NumParameters; i++) { struct gl_program_parameter *p = list->Parameters + i; GLuint size = MIN2(p->Size, 4); - GLint j = _mesa_add_parameter(clone, p->Type, p->Name, - size, list->ParameterValues[i], NULL); + GLint j = _mesa_add_parameter(clone, p->Type, p->Name, size, p->DataType, + list->ParameterValues[i], NULL); ASSERT(j >= 0); /* copy state indexes */ if (p->Type == PROGRAM_STATE_VAR) { @@ -586,19 +605,39 @@ _mesa_clone_parameter_list(const struct gl_program_parameter_list *list) /** - * Find longest name of any parameter in list. + * Find longest name of all uniform parameters in list. */ GLuint -_mesa_parameter_longest_name(const struct gl_program_parameter_list *list) +_mesa_longest_parameter_name(const struct gl_program_parameter_list *list, + enum register_file type) { GLuint i, maxLen = 0; if (!list) return 0; for (i = 0; i < list->NumParameters; i++) { - GLuint len = _mesa_strlen(list->Parameters[i].Name); - if (len > maxLen) - maxLen = len; + if (list->Parameters[i].Type == type) { + GLuint len = _mesa_strlen(list->Parameters[i].Name); + if (len > maxLen) + maxLen = len; + } } return maxLen; } + +/** + * Count the number of parameters in the last that match the given type. + */ +GLuint +_mesa_num_parameters_of_type(const struct gl_program_parameter_list *list, + enum register_file type) +{ + GLuint i, count = 0; + if (list) { + for (i = 0; i < list->NumParameters; i++) { + if (list->Parameters[i].Type == type) + count++; + } + } + return count; +} |