/*
* Mesa 3-D graphics library
- * Version: 5.1
+ * Version: 6.0
*
- * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* \author Brian Paul
*/
+/*
+ * Regarding GL_NV_fragment_program:
+ *
+ * Portions of this software may use or implement intellectual
+ * property owned and licensed by NVIDIA Corporation. NVIDIA disclaims
+ * any and all warranties with respect to such intellectual property,
+ * including any use thereof or modifications thereto.
+ */
+
#include "glheader.h"
#include "context.h"
#include "hash.h"
#include "nvfragprog.h"
#include "nvfragparse.h"
#include "nvprogram.h"
+#include "program.h"
#define INPUT_1V 1
const GLubyte *curLine;
struct fragment_program *program; /* current program */
- GLuint numParameters;
- struct program_parameter *parameters; /* DECLARE */
-
- GLuint numConstants;
- struct program_parameter *constants; /* DEFINE */
+ struct program_parameter_list *parameters;
GLuint numInst; /* number of instructions parsed */
GLuint inputsRead; /* bitmask of input registers used */
};
-/**
- * Add a new program parameter (via DEFINE statement)
- * \return index of the new entry in the parameter list
- */
-static GLuint
-add_parameter(struct parse_state *parseState,
- const char *name, const GLfloat values[4], GLboolean constant)
-{
- const GLuint n = parseState->numParameters;
-
- parseState->parameters = _mesa_realloc(parseState->parameters,
- n * sizeof(struct program_parameter),
- (n + 1) * sizeof(struct program_parameter));
- parseState->numParameters = n + 1;
- parseState->parameters[n].Name = _mesa_strdup(name);
- COPY_4V(parseState->parameters[n].Values, values);
- parseState->parameters[n].Constant = constant;
- return n;
-}
-
-
-/**
- * Add a new unnamed constant to the parameter lists.
- * \param parseState parsing state
- * \param values four float values
- * \return index of the new parameter.
- */
-static GLuint
-add_unnamed_constant(struct parse_state *parseState, const GLfloat values[4])
-{
- /* generate a new dummy name */
- static GLuint n = 0;
- char name[20];
- _mesa_sprintf(name, "constant%d", n);
- n++;
- /* store it */
- return add_parameter(parseState, name, values, GL_TRUE);
-}
-
-
-static const GLfloat *
-lookup_parameter(struct parse_state *parseState, const char *name)
-{
- GLuint i;
- for (i = 0; i < parseState->numParameters; i++) {
- if (_mesa_strcmp(parseState->parameters[i].Name, name) == 0)
- return parseState->parameters[i].Values;
- }
- return NULL;
-}
-
-
-static const GLint
-lookup_parameter_index(struct parse_state *parseState, const char *name)
-{
- GLuint i;
- for (i = 0; i < parseState->numParameters; i++) {
- if (_mesa_strcmp(parseState->parameters[i].Name, name) == 0)
- return i;
- }
- return -1;
-}
-
/*
* Called whenever we find an error during parsing.
const GLfloat *constant;
if (!Parse_Identifier(parseState, ident))
RETURN_ERROR1("Expected an identifier");
- constant = lookup_parameter(parseState, (const char *) ident);
+ constant = _mesa_lookup_parameter_value(parseState->parameters,
+ -1, (const char *) ident);
/* XXX Check that it's a constant and not a parameter */
if (!constant) {
RETURN_ERROR1("Undefined symbol");
GLint paramIndex;
if (!Parse_Identifier(parseState, ident))
RETURN_ERROR;
- paramIndex = lookup_parameter_index(parseState, (const char *) ident);
+ paramIndex = _mesa_lookup_parameter_index(parseState->parameters,
+ -1, (const char *) ident);
if (paramIndex < 0) {
RETURN_ERROR2("Undefined constant or parameter: ", ident);
}
GLuint paramIndex;
if (!Parse_ScalarConstant(parseState, values))
RETURN_ERROR;
- paramIndex = add_unnamed_constant(parseState, values);
+ paramIndex = _mesa_add_unnamed_constant(parseState->parameters, values);
srcReg->File = PROGRAM_NAMED_PARAM;
srcReg->Index = paramIndex;
}
(void) Parse_String(parseState, "{");
if (!Parse_VectorConstant(parseState, values))
RETURN_ERROR;
- paramIndex = add_unnamed_constant(parseState, values);
+ paramIndex = _mesa_add_unnamed_constant(parseState->parameters, values);
srcReg->File = PROGRAM_NAMED_PARAM;
srcReg->Index = paramIndex;
}
(void) Parse_String(parseState, "{");
if (!Parse_VectorConstant(parseState, values))
RETURN_ERROR;
- paramIndex = add_unnamed_constant(parseState, values);
+ paramIndex = _mesa_add_unnamed_constant(parseState->parameters, values);
srcReg->File = PROGRAM_NAMED_PARAM;
srcReg->Index = paramIndex;
}
GLuint paramIndex;
if (!Parse_ScalarConstant(parseState, values))
RETURN_ERROR;
- paramIndex = add_unnamed_constant(parseState, values);
+ paramIndex = _mesa_add_unnamed_constant(parseState->parameters, values);
srcReg->Index = paramIndex;
srcReg->File = PROGRAM_NAMED_PARAM;
needSuffix = GL_FALSE;
RETURN_ERROR;
if (!Parse_String(parseState, ";"))
RETURN_ERROR1("Expected ;");
- if (lookup_parameter(parseState, (const char *) id)) {
+ if (_mesa_lookup_parameter_index(parseState->parameters,
+ -1, (const char *) id) >= 0) {
RETURN_ERROR2(id, "already defined");
}
- add_parameter(parseState, (const char *) id, value, GL_TRUE);
+ _mesa_add_named_parameter(parseState->parameters,
+ (const char *) id, value);
}
else if (Parse_String(parseState, "DECLARE")) {
GLubyte id[100];
}
if (!Parse_String(parseState, ";"))
RETURN_ERROR1("Expected ;");
- if (lookup_parameter(parseState, (const char *) id)) {
+ if (_mesa_lookup_parameter_index(parseState->parameters,
+ -1, (const char *) id) >= 0) {
RETURN_ERROR2(id, "already declared");
}
- add_parameter(parseState, (const char *) id, value, GL_FALSE);
+ _mesa_add_named_parameter(parseState->parameters,
+ (const char *) id, value);
}
else if (Parse_String(parseState, "END")) {
inst->Opcode = FP_OPCODE_END;
parseState.program = program;
parseState.numInst = 0;
parseState.curLine = programString;
+ parseState.parameters = _mesa_new_parameter_list();
/* Reset error state */
_mesa_set_program_error(ctx, -1, NULL);
program->TexturesUsed[u] = parseState.texturesUsed[u];
/* save program parameters */
- if (program->Parameters) {
- GLuint i;
- for (i = 0; i < program->NumParameters; i++)
- _mesa_free((void *) program->Parameters[i].Name);
- _mesa_free(program->Parameters);
- }
- program->NumParameters = parseState.numParameters;
program->Parameters = parseState.parameters;
- /* free program constants */
- if (parseState.constants) {
- GLuint i;
- for (i = 0; i < parseState.numConstants; i++)
- _mesa_free((void *) parseState.constants[i].Name);
- _mesa_free(parseState.constants);
- }
-
-
/* allocate registers for declared program parameters */
#if 00
_mesa_assign_program_registers(&(program->SymbolTable));
_mesa_printf("-");
}
if (src->File == PROGRAM_NAMED_PARAM) {
- if (program->Parameters[src->Index].Constant) {
+ if (program->Parameters->Parameters[src->Index].Type == CONSTANT) {
printf("{%g, %g, %g, %g}",
- program->Parameters[src->Index].Values[0],
- program->Parameters[src->Index].Values[1],
- program->Parameters[src->Index].Values[2],
- program->Parameters[src->Index].Values[3]);
+ program->Parameters->Parameters[src->Index].Values[0],
+ program->Parameters->Parameters[src->Index].Values[1],
+ program->Parameters->Parameters[src->Index].Values[2],
+ program->Parameters->Parameters[src->Index].Values[3]);
}
else {
- printf("%s", program->Parameters[src->Index].Name);
+ ASSERT(program->Parameters->Parameters[src->Index].Type
+ == NAMED_PARAMETER);
+ printf("%s", program->Parameters->Parameters[src->Index].Name);
}
}
else if (src->File == PROGRAM_OUTPUT) {