/** * Make sure there are enough unused parameter slots. Reallocate the list * if needed. * * \param paramList where to reserve parameter slots * \param reserve_slots number of slots to reserve */ void _mesa_reserve_parameter_storage(struct gl_program_parameter_list *paramList, unsigned reserve_slots) { const GLuint oldNum = paramList->NumParameters; if (oldNum + reserve_slots > paramList->Size) { /* Need to grow the parameter list array (alloc some extra) */ paramList->Size = paramList->Size + 4 * reserve_slots; /* realloc arrays */ paramList->Parameters = realloc(paramList->Parameters, paramList->Size * sizeof(struct gl_program_parameter)); paramList->ParameterValueOffset = realloc(paramList->ParameterValueOffset, paramList->Size * sizeof(unsigned)); paramList->ParameterValues = (gl_constant_value *) _mesa_align_realloc(paramList->ParameterValues, /* old buf */ oldNum * 4 * sizeof(gl_constant_value),/* old sz */ paramList->Size*4*sizeof(gl_constant_value),/*new*/ 16); } }
/** * Add a new parameter to a parameter list. * Note that parameter values are usually 4-element GLfloat vectors. * When size > 4 we'll allocate a sequential block of parameters to * store all the values (in blocks of 4). * * \param paramList the list to add the parameter to * \param type type of parameter, such as * \param name the parameter name, will be duplicated/copied! * \param size number of elements in 'values' vector (1..4, or more) * \param values initial parameter value, up to 4 GLfloats, or NULL * \param state state indexes, or NULL * \return index of new parameter in the list, or -1 if error (out of mem) */ GLint _mesa_add_parameter(struct gl_program_parameter_list *paramList, enum register_file type, const char *name, GLuint size, GLenum datatype, const GLfloat *values, const gl_state_index state[STATE_LENGTH]) { const GLuint oldNum = paramList->NumParameters; const GLuint sz4 = (size + 3) / 4; /* no. of new param slots needed */ assert(size > 0); if (oldNum + sz4 > paramList->Size) { /* Need to grow the parameter list array (alloc some extra) */ paramList->Size = paramList->Size + 4 * sz4; /* realloc arrays */ paramList->Parameters = (struct gl_program_parameter *) _mesa_realloc(paramList->Parameters, oldNum * sizeof(struct gl_program_parameter), paramList->Size * sizeof(struct gl_program_parameter)); paramList->ParameterValues = (GLfloat (*)[4]) _mesa_align_realloc(paramList->ParameterValues, /* old buf */ oldNum * 4 * sizeof(GLfloat), /* old size */ paramList->Size * 4 *sizeof(GLfloat), /* new sz */ 16); } if (!paramList->Parameters || !paramList->ParameterValues) { /* out of memory */ paramList->NumParameters = 0; paramList->Size = 0; return -1; } else { GLuint i; paramList->NumParameters = oldNum + sz4; _mesa_memset(¶mList->Parameters[oldNum], 0, sz4 * sizeof(struct gl_program_parameter)); for (i = 0; i < sz4; i++) { struct gl_program_parameter *p = paramList->Parameters + oldNum + i; 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; } else { /* silence valgrind */ ASSIGN_4V(paramList->ParameterValues[oldNum + i], 0, 0, 0, 0); } size -= 4; } if (state) { for (i = 0; i < STATE_LENGTH; i++) paramList->Parameters[oldNum].StateIndexes[i] = state[i]; } return (GLint) oldNum; } }