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;
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))
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;
+ }
else if (IsDigit(token[0])) {
/* scalar literal */
GLfloat values[4];
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;
}
program->Base.String = programString;
program->Base.Format = GL_PROGRAM_FORMAT_ASCII_ARB;
- if (program->Instructions) {
- FREE(program->Instructions);
+ if (program->Base.Instructions) {
+ _mesa_free(program->Base.Instructions);
}
- program->Instructions = newInst;
- program->InputsRead = parseState.inputsRead;
- program->OutputsWritten = parseState.outputsWritten;
+ 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++)
program->TexturesUsed[u] = parseState.texturesUsed[u];
/* save program parameters */
- program->Parameters = parseState.parameters;
+ program->Base.Parameters = parseState.parameters;
/* allocate registers for declared program parameters */
#if 00
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("-");
}
if (src->File == PROGRAM_NAMED_PARAM) {
- if (program->Parameters->Parameters[src->Index].Type == PROGRAM_CONSTANT) {
- _mesa_printf("{%g, %g, %g, %g}",
- program->Parameters->ParameterValues[src->Index][0],
- program->Parameters->ParameterValues[src->Index][1],
- program->Parameters->ParameterValues[src->Index][2],
- program->Parameters->ParameterValues[src->Index][3]);
+ if (program->Base.Parameters->Parameters[src->Index].Type
+ == PROGRAM_CONSTANT) {
+ const GLfloat *v;
+ v = program->Base.Parameters->ParameterValues[src->Index];
+ _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->Parameters->Parameters[src->Index].Name);
+ _mesa_printf("%s", program->Base.Parameters->Parameters[src->Index].Name);
}
}
else if (src->File == PROGRAM_OUTPUT) {
* 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;
- for (inst = program->Instructions; inst->Opcode != OPCODE_END; inst++) {
+ for (inst = program->Base.Instructions; inst->Opcode != OPCODE_END; inst++) {
int i;
for (i = 0; Instructions[i].name; i++) {
if (inst->Opcode == Instructions[i].opcode) {
_mesa_printf("X");
if (inst->CondUpdate)
_mesa_printf("C");
- if (inst->Saturate)
+ if (inst->SaturateMode == SATURATE_ZERO_ONE)
_mesa_printf("_SAT");
_mesa_printf(" ");