📄 prog_parameter.c
字号:
/** * Add parameter representing a vertex program attribute. * \param size size of attribute (in floats), may be -1 if unknown * \param attrib the attribute index, or -1 if unknown */GLint_mesa_add_attribute(struct gl_program_parameter_list *paramList, const char *name, GLint size, GLenum datatype, GLint attrib){ GLint i = _mesa_lookup_parameter_index(paramList, -1, name); if (i >= 0) { /* replace */ if (attrib < 0) attrib = i; paramList->Parameters[i].StateIndexes[0] = attrib; } else { /* add */ gl_state_index state[STATE_LENGTH]; state[0] = (gl_state_index) attrib; if (size < 0) size = 4; i = _mesa_add_parameter(paramList, PROGRAM_INPUT, name, size, datatype, NULL, state); } return i;}#if 0 /* not used yet *//** * Returns the number of 4-component registers needed to store a piece * of GL state. For matrices this may be as many as 4 registers, * everything else needs * just 1 register. */static GLuintsizeof_state_reference(const GLint *stateTokens){ if (stateTokens[0] == STATE_MATRIX) { GLuint rows = stateTokens[4] - stateTokens[3] + 1; assert(rows >= 1); assert(rows <= 4); return rows; } else { return 1; }}#endif/** * Add a new state reference to the parameter list. * This will be used when the program contains something like this: * PARAM ambient = state.material.front.ambient; * * \param paramList the parameter list * \param stateTokens an array of 5 (STATE_LENGTH) state tokens * \return index of the new parameter. */GLint_mesa_add_state_reference(struct gl_program_parameter_list *paramList, const gl_state_index stateTokens[STATE_LENGTH]){ const GLuint size = 4; /* XXX fix */ const char *name; GLint index; /* Check if the state reference is already in the list */ for (index = 0; index < (GLint) paramList->NumParameters; index++) { GLuint i, match = 0; for (i = 0; i < STATE_LENGTH; i++) { if (paramList->Parameters[index].StateIndexes[i] == stateTokens[i]) { match++; } else { break; } } if (match == STATE_LENGTH) { /* this state reference is already in the parameter list */ return index; } } name = _mesa_program_state_string(stateTokens); index = _mesa_add_parameter(paramList, PROGRAM_STATE_VAR, name, 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() */ _mesa_free((void *) name); return index;}/** * Lookup a parameter value by name in the given parameter list. * \return pointer to the float[4] values. */GLfloat *_mesa_lookup_parameter_value(const struct gl_program_parameter_list *paramList, GLsizei nameLen, const char *name){ GLuint i = _mesa_lookup_parameter_index(paramList, nameLen, name); if (i < 0) return NULL; else return paramList->ParameterValues[i];}/** * Given a program parameter name, find its position in the list of parameters. * \param paramList the parameter list to search * \param nameLen length of name (in chars). * If length is negative, assume that name is null-terminated. * \param name the name to search for * \return index of parameter in the list. */GLint_mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList, GLsizei nameLen, const char *name){ GLint i; if (!paramList) return -1; if (nameLen == -1) { /* name is null-terminated */ for (i = 0; i < (GLint) paramList->NumParameters; i++) { if (paramList->Parameters[i].Name && _mesa_strcmp(paramList->Parameters[i].Name, name) == 0) return i; } } else { /* name is not null-terminated, use nameLen */ for (i = 0; i < (GLint) paramList->NumParameters; i++) { if (paramList->Parameters[i].Name && _mesa_strncmp(paramList->Parameters[i].Name, name, nameLen) == 0 && _mesa_strlen(paramList->Parameters[i].Name) == (size_t)nameLen) return i; } } return -1;}/** * Look for a float vector in the given parameter list. The float vector * may be of length 1, 2, 3 or 4. If swizzleOut is non-null, we'll try * swizzling to find a match. * \param list the parameter list to search * \param v the float vector to search for * \param size number of element in v * \param posOut returns the position of the constant, if found * \param swizzleOut returns a swizzle mask describing location of the * vector elements if found. * \return GL_TRUE if found, GL_FALSE if not found */GLboolean_mesa_lookup_parameter_constant(const struct gl_program_parameter_list *list, const GLfloat v[], GLuint vSize, GLint *posOut, GLuint *swizzleOut){ GLuint i; assert(vSize >= 1); assert(vSize <= 4); if (!list) return -1; for (i = 0; i < list->NumParameters; i++) { if (list->Parameters[i].Type == PROGRAM_CONSTANT) { if (!swizzleOut) { /* swizzle not allowed */ GLuint j, match = 0; for (j = 0; j < vSize; j++) { if (v[j] == list->ParameterValues[i][j]) match++; } if (match == vSize) { *posOut = i; return GL_TRUE; } } else { /* try matching w/ swizzle */ if (vSize == 1) { /* look for v[0] anywhere within float[4] value */ GLuint j; for (j = 0; j < 4; j++) { if (list->ParameterValues[i][j] == v[0]) { /* found it */ *posOut = i; *swizzleOut = MAKE_SWIZZLE4(j, j, j, j); return GL_TRUE; } } } else if (vSize <= list->Parameters[i].Size) { /* see if we can match this constant (with a swizzle) */ GLuint swz[4]; GLuint match = 0, j, k; for (j = 0; j < vSize; j++) { if (v[j] == list->ParameterValues[i][j]) { swz[j] = j; match++; } else { for (k = 0; k < list->Parameters[i].Size; k++) { if (v[j] == list->ParameterValues[i][k]) { swz[j] = k; match++; break; } } } } /* smear last value to remaining positions */ for (; j < 4; j++) swz[j] = swz[j-1]; if (match == vSize) { *posOut = i; *swizzleOut = MAKE_SWIZZLE4(swz[0], swz[1], swz[2], swz[3]); return GL_TRUE; } } } } } *posOut = -1; return GL_FALSE;}struct gl_program_parameter_list *_mesa_clone_parameter_list(const struct gl_program_parameter_list *list){ struct gl_program_parameter_list *clone; GLuint i; clone = _mesa_new_parameter_list(); if (!clone) return NULL; /** 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; for (k = 0; k < STATE_LENGTH; 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. */GLuint_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++) { 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;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -