const GLubyte *start; /* start of program string */
const GLubyte *pos; /* current position */
const GLubyte *curLine;
- struct fragment_program *program; /* current program */
+ struct gl_fragment_program *program; /* current program */
- struct program_parameter_list *parameters;
+ struct gl_program_parameter_list *parameters;
GLuint numInst; /* number of instructions parsed */
GLuint inputsRead; /* bitmask of input registers used */
return result;
}
}
- result.opcode = (enum prog_opcode) -1;
+ result.opcode = MAX_OPCODE; /* i.e. invalid instruction */
return result;
}
srcReg->NegateAbs = (sign < 0.0F) ? GL_TRUE : GL_FALSE;
if (Parse_String(parseState, "-"))
- srcReg->NegateBase = 0xf;
+ srcReg->NegateBase = NEGATE_XYZW;
else if (Parse_String(parseState, "+"))
- srcReg->NegateBase = 0;
+ srcReg->NegateBase = NEGATE_NONE;
else
- srcReg->NegateBase = 0;
+ srcReg->NegateBase = NEGATE_NONE;
}
else {
srcReg->Abs = GL_FALSE;
srcReg->NegateAbs = GL_FALSE;
- srcReg->NegateBase = (sign < 0.0F) ? 0xf : 0x0;
+ srcReg->NegateBase = (sign < 0.0F) ? NEGATE_XYZW : NEGATE_NONE;
}
/* This should be the real src vector/register name */
srcReg->Index = idx;
}
else if (token[0] == 'f') {
- /* XXX this might be an identier! */
+ /* XXX this might be an identifier! */
srcReg->File = PROGRAM_INPUT;
if (!Parse_FragReg(parseState, &idx))
RETURN_ERROR;
srcReg->Index = idx;
}
else if (token[0] == 'p') {
- /* XXX this might be an identier! */
+ /* XXX this might be an identifier! */
srcReg->File = PROGRAM_LOCAL_PARAM;
if (!Parse_ProgramParamReg(parseState, &idx))
RETURN_ERROR;
GLuint paramIndex;
if (!Parse_ScalarConstant(parseState, values))
RETURN_ERROR;
- paramIndex = _mesa_add_unnamed_constant(parseState->parameters, values);
+ paramIndex = _mesa_add_unnamed_constant(parseState->parameters, values, 4);
srcReg->File = PROGRAM_NAMED_PARAM;
srcReg->Index = paramIndex;
}
(void) Parse_String(parseState, "{");
if (!Parse_VectorConstant(parseState, values))
RETURN_ERROR;
- paramIndex = _mesa_add_unnamed_constant(parseState->parameters, values);
+ paramIndex = _mesa_add_unnamed_constant(parseState->parameters, values, 4);
srcReg->File = PROGRAM_NAMED_PARAM;
srcReg->Index = paramIndex;
}
srcReg->NegateAbs = (sign < 0.0F) ? GL_TRUE : GL_FALSE;
if (Parse_String(parseState, "-"))
- srcReg->NegateBase = 0xf;
+ srcReg->NegateBase = NEGATE_XYZW;
else if (Parse_String(parseState, "+"))
- srcReg->NegateBase = 0x0;
+ srcReg->NegateBase = NEGATE_NONE;
else
- srcReg->NegateBase = 0x0;
+ srcReg->NegateBase = NEGATE_NONE;
}
else {
srcReg->Abs = GL_FALSE;
srcReg->NegateAbs = GL_FALSE;
- srcReg->NegateBase = (sign < 0.0F) ? 0xf : 0x0;
+ srcReg->NegateBase = (sign < 0.0F) ? NEGATE_XYZW : NEGATE_NONE;
}
if (!Peek_Token(parseState, token))
(void) Parse_String(parseState, "{");
if (!Parse_VectorConstant(parseState, values))
RETURN_ERROR;
- paramIndex = _mesa_add_unnamed_constant(parseState->parameters, values);
+ paramIndex = _mesa_add_unnamed_constant(parseState->parameters, values, 4);
+ srcReg->File = PROGRAM_NAMED_PARAM;
+ srcReg->Index = paramIndex;
+ }
+ else if (IsLetter(token[0])){
+ /* named param/constant */
+ GLubyte ident[100];
+ GLint paramIndex;
+ if (!Parse_Identifier(parseState, ident))
+ RETURN_ERROR;
+ paramIndex = _mesa_lookup_parameter_index(parseState->parameters,
+ -1, (const char *) ident);
+ if (paramIndex < 0) {
+ RETURN_ERROR2("Undefined constant or parameter: ", ident);
+ }
srcReg->File = PROGRAM_NAMED_PARAM;
srcReg->Index = paramIndex;
}
GLuint paramIndex;
if (!Parse_ScalarConstant(parseState, values))
RETURN_ERROR;
- paramIndex = _mesa_add_unnamed_constant(parseState->parameters, values);
+ paramIndex = _mesa_add_unnamed_constant(parseState->parameters, values, 4);
srcReg->Index = paramIndex;
srcReg->File = PROGRAM_NAMED_PARAM;
needSuffix = GL_FALSE;
for (len = 0; str[len] != '\''; len++) /* find closing quote */
;
parseState->pos += len + 1;
- msg = _mesa_malloc(len + 1);
+ msg = (GLubyte*) _mesa_malloc(len + 1);
_mesa_memcpy(msg, str, len);
msg[len] = 0;
}
inst->SrcReg[0].Swizzle = SWIZZLE_NOOP;
- inst->SrcReg[0].NegateBase = 0x0;
+ inst->SrcReg[0].NegateBase = NEGATE_NONE;
inst->SrcReg[0].Abs = GL_FALSE;
inst->SrcReg[0].NegateAbs = GL_FALSE;
GLubyte token[100];
/* Initialize the instruction */
- _mesa_init_instruction(inst);
+ _mesa_init_instructions(inst, 1);
/* special instructions */
if (Parse_String(parseState, "DEFINE")) {
/* try to find matching instuction */
instMatch = MatchInstruction(token);
- if (instMatch.opcode < 0) {
+ if (instMatch.opcode >= MAX_OPCODE) {
/* bad instruction name */
RETURN_ERROR2("Unexpected token: ", token);
}
inst->Opcode = instMatch.opcode;
inst->Precision = instMatch.suffixes & (_R | _H | _X);
- inst->Saturate = (instMatch.suffixes & (_S)) ? GL_TRUE : GL_FALSE;
+ inst->SaturateMode = (instMatch.suffixes & (_S))
+ ? SATURATE_ZERO_ONE : SATURATE_OFF;
inst->CondUpdate = (instMatch.suffixes & (_C)) ? GL_TRUE : GL_FALSE;
inst->StringPos = parseState->curLine - parseState->start;
assert(inst->StringPos >= 0);
void
_mesa_parse_nv_fragment_program(GLcontext *ctx, GLenum dstTarget,
const GLubyte *str, GLsizei len,
- struct fragment_program *program)
+ struct gl_fragment_program *program)
{
struct parse_state parseState;
struct prog_instruction instBuffer[MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS];
/* copy the compiled instructions */
assert(parseState.numInst <= MAX_NV_FRAGMENT_PROGRAM_INSTRUCTIONS);
- newInst = (struct prog_instruction *)
- MALLOC(parseState.numInst * sizeof(struct prog_instruction));
+ newInst = _mesa_alloc_instructions(parseState.numInst);
if (!newInst) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glLoadProgramNV");
return; /* out of memory */
}
- MEMCPY(newInst, instBuffer,
- parseState.numInst * sizeof(struct prog_instruction));
+ _mesa_memcpy(newInst, instBuffer,
+ parseState.numInst * sizeof(struct prog_instruction));
/* install the program */
program->Base.Target = target;
_mesa_free(program->Base.Instructions);
}
program->Base.Instructions = newInst;
+ program->Base.NumInstructions = parseState.numInst;
program->Base.InputsRead = parseState.inputsRead;
program->Base.OutputsWritten = parseState.outputsWritten;
for (u = 0; u < ctx->Const.MaxTextureImageUnits; u++)
static void
-PrintSrcReg(const struct fragment_program *program,
+PrintSrcReg(const struct gl_fragment_program *program,
const struct prog_src_register *src)
{
static const char comps[5] = "xyzw";
_mesa_printf("{%g, %g, %g, %g}", v[0], v[1], v[2], v[3]);
}
else {
- ASSERT(program->Parameters->Parameters[src->Index].Type
+ ASSERT(program->Base.Parameters->Parameters[src->Index].Type
== PROGRAM_NAMED_PARAM);
_mesa_printf("%s", program->Base.Parameters->Parameters[src->Index].Name);
}
* Print (unparse) the given vertex program. Just for debugging.
*/
void
-_mesa_print_nv_fragment_program(const struct fragment_program *program)
+_mesa_print_nv_fragment_program(const struct gl_fragment_program *program)
{
const struct prog_instruction *inst;
_mesa_printf("X");
if (inst->CondUpdate)
_mesa_printf("C");
- if (inst->Saturate)
+ if (inst->SaturateMode == SATURATE_ZERO_ONE)
_mesa_printf("_SAT");
_mesa_printf(" ");