summaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/mtypes.h3
-rw-r--r--src/mesa/main/nvfragparse.c83
-rw-r--r--src/mesa/main/nvfragprog.h4
-rw-r--r--src/mesa/main/nvprogram.c33
4 files changed, 73 insertions, 50 deletions
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index a1c8dac03fe..75117902e16 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1,4 +1,4 @@
-/* $Id: mtypes.h,v 1.108 2003/03/29 17:01:00 brianp Exp $ */
+/* $Id: mtypes.h,v 1.109 2003/04/05 00:38:09 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -1213,6 +1213,7 @@ struct program_parameter
{
const char *Name;
GLfloat Values[4];
+ GLboolean Constant;
};
diff --git a/src/mesa/main/nvfragparse.c b/src/mesa/main/nvfragparse.c
index 75f4e84db3d..03c20608566 100644
--- a/src/mesa/main/nvfragparse.c
+++ b/src/mesa/main/nvfragparse.c
@@ -1,4 +1,4 @@
-/* $Id: nvfragparse.c,v 1.16 2003/04/01 16:17:03 brianp Exp $ */
+/* $Id: nvfragparse.c,v 1.17 2003/04/05 00:38:09 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -158,9 +158,13 @@ struct parse_state {
};
-static void
+/**
+ * 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])
+ const char *name, const GLfloat values[4], GLboolean constant)
{
const GLuint n = parseState->numParameters;
@@ -170,6 +174,27 @@ add_parameter(struct parse_state *parseState,
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);
}
@@ -185,30 +210,15 @@ lookup_parameter(struct parse_state *parseState, const char *name)
}
-static void
-add_constant(struct parse_state *parseState,
- const char *name, const GLfloat values[4])
+static const GLint
+lookup_parameter_index(struct parse_state *parseState, const char *name)
{
- const GLuint n = parseState->numConstants;
-
- parseState->constants = _mesa_realloc(parseState->constants,
- n * sizeof(struct program_parameter),
- (n + 1) * sizeof(struct program_parameter));
- parseState->numConstants = n + 1;
- parseState->constants[n].Name = _mesa_strdup(name);
- COPY_4V(parseState->constants[n].Values, values);
-}
-
-
-static const GLfloat *
-lookup_constant(struct parse_state *parseState, const char *name)
-{
- GLuint i;
- for (i = 0; i < parseState->numConstants; i++) {
- if (_mesa_strcmp(parseState->constants[i].Name, name) == 0)
- return parseState->constants[i].Values;
+ GLint i;
+ for (i = 0; i < parseState->numParameters; i++) {
+ if (_mesa_strcmp(parseState->parameters[i].Name, name) == 0)
+ return i;
}
- return NULL;
+ return -1;
}
@@ -571,7 +581,8 @@ Parse_ScalarConstant(struct parse_state *parseState, GLfloat *number)
const GLfloat *constant;
if (!Parse_Identifier(parseState, ident))
RETURN_ERROR1("Expected an identifier");
- constant = lookup_constant(parseState, (const char *) ident);
+ constant = lookup_parameter(parseState, (const char *) ident);
+ /* XXX Check that it's a constant and not a parameter */
if (!constant) {
RETURN_ERROR1("Undefined symbol");
}
@@ -1106,11 +1117,16 @@ Parse_VectorSrc(struct parse_state *parseState,
RETURN_ERROR;
}
else if (IsLetter(token[0])){
- /* XXX named constant */
GLubyte ident[100];
+ GLint paramIndex;
if (!Parse_Identifier(parseState, ident))
RETURN_ERROR;
- srcReg->Register = 0; /* XXX fix */
+ paramIndex = lookup_parameter_index(parseState, (const char *) ident);
+ if (paramIndex < 0) {
+ RETURN_ERROR2("Undefined constant or parameter: ", ident);
+ }
+ srcReg->IsParameter = GL_TRUE;
+ srcReg->Register = paramIndex;
}
else if (IsDigit(token[0]) || token[0] == '-' || token[0] == '+'){
/* XXX literal scalar constant */
@@ -1122,10 +1138,13 @@ Parse_VectorSrc(struct parse_state *parseState,
else if (token[0] == '{'){
/* XXX literal vector constant */
GLfloat values[4];
+ GLuint paramIndex;
(void) Parse_String(parseState, "{");
if (!Parse_VectorConstant(parseState, values))
RETURN_ERROR;
- srcReg->Register = 0; /* XXX fix */
+ paramIndex = add_unnamed_constant(parseState, values);
+ srcReg->IsParameter = GL_TRUE;
+ srcReg->Register = paramIndex;
}
else {
RETURN_ERROR2("Invalid source register name", token);
@@ -1247,7 +1266,7 @@ Parse_InstructionSequence(struct parse_state *parseState,
if (lookup_parameter(parseState, (const char *) id)) {
RETURN_ERROR2(id, "already defined");
}
- add_parameter(parseState, (const char *) id, value);
+ add_parameter(parseState, (const char *) id, value, GL_TRUE);
}
else if (Parse_String(parseState, "DECLARE")) {
GLubyte id[100];
@@ -1266,10 +1285,10 @@ Parse_InstructionSequence(struct parse_state *parseState,
}
if (!Parse_String(parseState, ";"))
RETURN_ERROR1("Expected ;");
- if (lookup_constant(parseState, (const char *) id)) {
+ if (lookup_parameter(parseState, (const char *) id)) {
RETURN_ERROR2(id, "already declared");
}
- add_constant(parseState, (const char *) id, value);
+ add_parameter(parseState, (const char *) id, value, GL_FALSE);
}
else if (Parse_String(parseState, "END")) {
inst->Opcode = FP_OPCODE_END;
diff --git a/src/mesa/main/nvfragprog.h b/src/mesa/main/nvfragprog.h
index 8d1ed13f217..2e9d82975c3 100644
--- a/src/mesa/main/nvfragprog.h
+++ b/src/mesa/main/nvfragprog.h
@@ -1,4 +1,4 @@
-/* $Id: nvfragprog.h,v 1.5 2003/03/15 17:33:26 brianp Exp $ */
+/* $Id: nvfragprog.h,v 1.6 2003/04/05 00:38:09 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -134,8 +134,8 @@ enum fp_opcode {
struct fp_src_register
{
- GLint RegType; /* constant, param, temp or attribute register */
GLint Register; /* or the offset from the address register */
+ GLboolean IsParameter; /* true if register refers to a param or constant */
GLuint Swizzle[4];
GLboolean NegateBase; /* negate before absolute value? */
GLboolean Abs; /* take absolute value? */
diff --git a/src/mesa/main/nvprogram.c b/src/mesa/main/nvprogram.c
index ef0f4795b8b..ae0a9081edc 100644
--- a/src/mesa/main/nvprogram.c
+++ b/src/mesa/main/nvprogram.c
@@ -1,4 +1,4 @@
-/* $Id: nvprogram.c,v 1.10 2003/03/29 16:37:08 brianp Exp $ */
+/* $Id: nvprogram.c,v 1.11 2003/04/05 00:38:09 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -1043,7 +1043,7 @@ _mesa_ProgramNamedParameter4fNV(GLuint id, GLsizei len, const GLubyte *name,
{
struct program *prog;
struct fragment_program *fragProg;
- GLint reg;
+ GLint i;
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END(ctx);
@@ -1059,12 +1059,14 @@ _mesa_ProgramNamedParameter4fNV(GLuint id, GLsizei len, const GLubyte *name,
}
fragProg = (struct fragment_program *) prog;
- for (reg = 0; reg < fragProg->NumParameters; reg++) {
- if (!_mesa_strcmp(fragProg->Parameters[reg].Name, (const char *) name)) {
- fragProg->Parameters[reg].Values[0] = x;
- fragProg->Parameters[reg].Values[1] = y;
- fragProg->Parameters[reg].Values[2] = z;
- fragProg->Parameters[reg].Values[3] = w;
+ for (i = 0; i < fragProg->NumParameters; i++) {
+ printf("test %d %s\n", i, fragProg->Parameters[i].Name);
+ if (!_mesa_strcmp(fragProg->Parameters[i].Name, (const char *) name)) {
+ ASSERT(!fragProg->Parameters[i].Constant);
+ fragProg->Parameters[i].Values[0] = x;
+ fragProg->Parameters[i].Values[1] = y;
+ fragProg->Parameters[i].Values[2] = z;
+ fragProg->Parameters[i].Values[3] = w;
return;
}
}
@@ -1105,7 +1107,7 @@ _mesa_GetProgramNamedParameterfvNV(GLuint id, GLsizei len, const GLubyte *name,
{
struct program *prog;
struct fragment_program *fragProg;
- GLint reg;
+ GLint i;
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END(ctx);
@@ -1121,12 +1123,13 @@ _mesa_GetProgramNamedParameterfvNV(GLuint id, GLsizei len, const GLubyte *name,
}
fragProg = (struct fragment_program *) prog;
- for (reg = 0; reg < fragProg->NumParameters; reg++) {
- if (!_mesa_strcmp(fragProg->Parameters[reg].Name, (const char *) name)) {
- params[0] = fragProg->Parameters[reg].Values[0];
- params[1] = fragProg->Parameters[reg].Values[1];
- params[2] = fragProg->Parameters[reg].Values[2];
- params[3] = fragProg->Parameters[reg].Values[3];
+ for (i = 0; i < fragProg->NumParameters; i++) {
+ if (!_mesa_strcmp(fragProg->Parameters[i].Name, (const char *) name)) {
+ ASSERT(!fragProg->Parameters[i].Constant);
+ params[0] = fragProg->Parameters[i].Values[0];
+ params[1] = fragProg->Parameters[i].Values[1];
+ params[2] = fragProg->Parameters[i].Values[2];
+ params[3] = fragProg->Parameters[i].Values[3];
return;
}
}