#include "arbparse.h"
#include "arbfragparse.h"
-static void
-debug_fp_inst(GLint num, struct fp_instruction *fp)
+void
+_mesa_debug_fp_inst(GLint num, struct fp_instruction *fp)
{
GLint a;
case FP_OPCODE_X2D:
fprintf(stderr, "FP_OPCODE_XPD"); break;
+
+ default:
+ _mesa_warning(NULL, "Bad opcode in debug_fg_inst()");
}
fprintf(stderr, " D(0x%x:%d:%d%d%d%d) ",
const GLubyte * str, GLsizei len,
struct fragment_program *program)
{
- GLuint retval;
+ GLuint a, retval;
struct arb_program ap;
retval = _mesa_parse_arb_program(ctx, str, len, &ap);
+ /* copy the relvant contents of the arb_program struct into the
+ * fragment_program struct
+ */
+ program->Base.NumInstructions = ap.Base.NumInstructions;
+ program->Base.NumTemporaries = ap.Base.NumTemporaries;
+ program->Base.NumParameters = ap.Base.NumParameters;
+ program->Base.NumAttributes = ap.Base.NumAttributes;
+ program->Base.NumAddressRegs = ap.Base.NumAddressRegs;
+
+ program->InputsRead = ap.InputsRead;
+ program->OutputsWritten = ap.OutputsWritten;
+ for (a=0; a<MAX_TEXTURE_IMAGE_UNITS; a++)
+ program->TexturesUsed[a] = ap.TexturesUsed[a];
+ program->NumAluInstructions = ap.NumAluInstructions;
+ program->NumTexInstructions = ap.NumTexInstructions;
+ program->NumTexIndirections = ap.NumTexIndirections;
+ program->Parameters = ap.Parameters;
+
/* XXX: Parse error. Cleanup things and return */
if (retval)
{
+ program->Instructions = (struct fp_instruction *) _mesa_malloc (
+ sizeof(struct fp_instruction) );
+ program->Instructions[0].Opcode = FP_OPCODE_END;
return;
}
/* XXX: Eh.. we parsed something that wasn't a fragment program. doh! */
if (ap.type != GL_FRAGMENT_PROGRAM_ARB)
{
+ program->Instructions = (struct fp_instruction *) _mesa_malloc (
+ sizeof(struct fp_instruction) );
+ program->Instructions[0].Opcode = FP_OPCODE_END;
+
+ _mesa_error (ctx, GL_INVALID_OPERATION, "Parsed a non-fragment program as a fragment program");
return;
}
#if DEBUG_FP
- debug_fp_inst(ap.Base.NumInstructions, ap.FPInstructions);
+ _mesa_debug_fp_inst(ap.Base.NumInstructions, ap.FPInstructions);
#endif
- /* copy the relvant contents of the arb_program struct into the
- * fragment_program struct
- */
- program->Base.NumInstructions = ap.Base.NumInstructions;
- program->Base.NumTemporaries = ap.Base.NumTemporaries;
- program->Base.NumParameters = ap.Base.NumParameters;
- program->Base.NumAttributes = ap.Base.NumAttributes;
- program->Base.NumAddressRegs = ap.Base.NumAddressRegs;
-
program->Instructions = ap.FPInstructions;
- program->InputsRead = ap.InputsRead;
- program->OutputsWritten = ap.OutputsWritten;
- for (retval=0; retval<MAX_TEXTURE_IMAGE_UNITS; retval++)
- program->TexturesUsed[retval] = ap.TexturesUsed[retval];
- program->NumAluInstructions = ap.NumAluInstructions;
- program->NumTexInstructions = ap.NumTexInstructions;
- program->NumTexIndirections = ap.NumTexIndirections;
- program->Parameters = ap.Parameters;
}