summaryrefslogtreecommitdiff
path: root/src/mesa/main
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2003-07-22 03:34:54 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>2003-07-22 03:34:54 +0000
commitf7fda86c6dcb7894157bd35a0cf15d003d48b441 (patch)
tree3eec84c3e740c313d0dc4639bbab75435b503aba /src/mesa/main
parent389858ee7b5207d356c9211386024af8ff9797f5 (diff)
Implement debugger callback, etc for vertex programs. Misc clean-ups.
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/arbprogram.c19
-rw-r--r--src/mesa/main/get.c50
-rw-r--r--src/mesa/main/mtypes.h1
-rw-r--r--src/mesa/main/nvprogram.c120
-rw-r--r--src/mesa/main/nvvertexec.c25
-rw-r--r--src/mesa/main/nvvertparse.c24
-rw-r--r--src/mesa/main/nvvertprog.h3
7 files changed, 97 insertions, 145 deletions
diff --git a/src/mesa/main/arbprogram.c b/src/mesa/main/arbprogram.c
index 20118d45a1..24ab8a1035 100644
--- a/src/mesa/main/arbprogram.c
+++ b/src/mesa/main/arbprogram.c
@@ -304,7 +304,9 @@ _mesa_GetProgramEnvParameterfvARB(GLenum target, GLuint index,
GLfloat *params)
{
GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (!ctx->_CurrentProgram)
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
if (target == GL_FRAGMENT_PROGRAM_ARB
&& ctx->Extensions.ARB_fragment_program) {
@@ -477,7 +479,9 @@ _mesa_GetProgramivARB(GLenum target, GLenum pname, GLint *params)
{
struct program *prog;
GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (!ctx->_CurrentProgram)
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
if (target == GL_VERTEX_PROGRAM_ARB
&& ctx->Extensions.ARB_vertex_program) {
@@ -682,7 +686,9 @@ _mesa_GetProgramStringARB(GLenum target, GLenum pname, GLvoid *string)
{
struct program *prog;
GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (!ctx->_CurrentProgram)
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
if (target == GL_VERTEX_PROGRAM_ARB) {
prog = &(ctx->VertexProgram.Current->Base);
@@ -741,7 +747,7 @@ _mesa_ProgramCallbackMESA(GLenum target, GLprogramcallbackMESA callback,
break;
case GL_VERTEX_PROGRAM_ARB: /* == GL_VERTEX_PROGRAM_NV */
if (!ctx->Extensions.ARB_vertex_program &&
- !ctx->Extensions.ARB_vertex_program) {
+ !ctx->Extensions.NV_vertex_program) {
_mesa_error(ctx, GL_INVALID_ENUM, "glProgramCallbackMESA(target)");
return;
}
@@ -815,7 +821,10 @@ _mesa_GetProgramRegisterfvMESA(GLenum target,
GLint i;
for (i = 0; i < ctx->Const.MaxVertexProgramAttribs; i++) {
const char *name = _mesa_nv_vertex_input_register_name(i);
- if (_mesa_strncmp(reg + 2, name, 4) == 0) {
+ char number[10];
+ sprintf(number, "%d", i);
+ if (_mesa_strncmp(reg + 2, name, 4) == 0 ||
+ _mesa_strncmp(reg + 2, number, _mesa_strlen(number)) == 0) {
COPY_4V(v, ctx->VertexProgram.Machine.Registers
[VP_INPUT_REG_START + i]);
return;
diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
index 3cf8453c78..3e02c99c48 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -136,14 +136,16 @@ _mesa_GetBooleanv( GLenum pname, GLboolean *params )
if (!params)
return;
- /* We need this in order to get correct results for
- * GL_OCCLUSION_TEST_RESULT_HP. There might be other important cases.
- */
- FLUSH_VERTICES(ctx, 0);
-
if (MESA_VERBOSE & VERBOSE_API)
_mesa_debug(ctx, "glGetBooleanv %s\n", _mesa_lookup_enum_by_nr(pname));
+ if (!ctx->_CurrentProgram) {
+ /* We need this in order to get correct results for
+ * GL_OCCLUSION_TEST_RESULT_HP. There might be other important cases.
+ */
+ FLUSH_VERTICES(ctx, 0);
+ }
+
if (ctx->Driver.GetBooleanv
&& (*ctx->Driver.GetBooleanv)(ctx, pname, params))
return;
@@ -1679,14 +1681,16 @@ _mesa_GetDoublev( GLenum pname, GLdouble *params )
if (!params)
return;
- /* We need this in order to get correct results for
- * GL_OCCLUSION_TEST_RESULT_HP. There might be other important cases.
- */
- FLUSH_VERTICES(ctx, 0);
-
if (MESA_VERBOSE & VERBOSE_API)
_mesa_debug(ctx, "glGetDoublev %s\n", _mesa_lookup_enum_by_nr(pname));
+ if (!ctx->_CurrentProgram) {
+ /* We need this in order to get correct results for
+ * GL_OCCLUSION_TEST_RESULT_HP. There might be other important cases.
+ */
+ FLUSH_VERTICES(ctx, 0);
+ }
+
if (ctx->Driver.GetDoublev && (*ctx->Driver.GetDoublev)(ctx, pname, params))
return;
@@ -3216,14 +3220,16 @@ _mesa_GetFloatv( GLenum pname, GLfloat *params )
if (!params)
return;
- /* We need this in order to get correct results for
- * GL_OCCLUSION_TEST_RESULT_HP. There might be other important cases.
- */
- FLUSH_VERTICES(ctx, 0);
-
if (MESA_VERBOSE & VERBOSE_API)
_mesa_debug(ctx, "glGetFloatv %s\n", _mesa_lookup_enum_by_nr(pname));
+ if (!ctx->_CurrentProgram) {
+ /* We need this in order to get correct results for
+ * GL_OCCLUSION_TEST_RESULT_HP. There might be other important cases.
+ */
+ FLUSH_VERTICES(ctx, 0);
+ }
+
if (ctx->Driver.GetFloatv && (*ctx->Driver.GetFloatv)(ctx, pname, params))
return;
@@ -4729,19 +4735,19 @@ _mesa_GetIntegerv( GLenum pname, GLint *params )
if (!params)
return;
-#if 0
- /* We need this in order to get correct results for
- * GL_OCCLUSION_TEST_RESULT_HP. There might be other important cases.
- */
- FLUSH_VERTICES(ctx, 0);
-
if (MESA_VERBOSE & VERBOSE_API)
_mesa_debug(ctx, "glGetIntegerv %s\n", _mesa_lookup_enum_by_nr(pname));
+ if (!ctx->_CurrentProgram) {
+ /* We need this in order to get correct results for
+ * GL_OCCLUSION_TEST_RESULT_HP. There might be other important cases.
+ */
+ FLUSH_VERTICES(ctx, 0);
+ }
+
if (ctx->Driver.GetIntegerv
&& (*ctx->Driver.GetIntegerv)(ctx, pname, params))
return;
-#endif
switch (pname) {
case GL_ACCUM_RED_BITS:
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index cb408293d0..27b01eee08 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2143,6 +2143,7 @@ struct __GLcontextRec {
GLuint _NeedEyeCoords;
GLuint _ForceEyeCoords;
GLboolean _RotateMode;
+ GLenum _CurrentProgram; /* currently executing program */
struct gl_shine_tab *_ShineTable[2]; /**< Active shine tables */
struct gl_shine_tab *_ShineTabList; /**< MRU list of inactive shine tables */
diff --git a/src/mesa/main/nvprogram.c b/src/mesa/main/nvprogram.c
index 6c5c15a3ca..1175e09617 100644
--- a/src/mesa/main/nvprogram.c
+++ b/src/mesa/main/nvprogram.c
@@ -571,7 +571,9 @@ _mesa_GetProgramivNV(GLuint id, GLenum pname, GLint *params)
{
struct program *prog;
GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (!ctx->_CurrentProgram)
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
if (!prog) {
@@ -606,16 +608,18 @@ _mesa_GetProgramStringNV(GLuint id, GLenum pname, GLubyte *program)
{
struct program *prog;
GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (!ctx->_CurrentProgram)
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
if (pname != GL_PROGRAM_STRING_NV) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivNV(pname)");
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramStringNV(pname)");
return;
}
prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
if (!prog) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramivNV");
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramStringNV");
return;
}
@@ -1165,7 +1169,9 @@ _mesa_GetProgramNamedParameterfvNV(GLuint id, GLsizei len, const GLubyte *name,
struct fragment_program *fragProg;
GLint i;
GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+ if (!ctx->_CurrentProgram)
+ ASSERT_OUTSIDE_BEGIN_END(ctx);
prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
if (!prog || prog->Target != GL_FRAGMENT_PROGRAM_NV) {
@@ -1204,107 +1210,3 @@ _mesa_GetProgramNamedParameterdvNV(GLuint id, GLsizei len, const GLubyte *name,
_mesa_GetProgramNamedParameterfvNV(id, len, name, floatParams);
COPY_4V(params, floatParams);
}
-
-
-#if 000
-void
-_mesa_ProgramLocalParameter4fARB(GLenum target, GLuint index,
- GLfloat x, GLfloat y, GLfloat z, GLfloat w)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (target == GL_FRAGMENT_PROGRAM_NV) {
- struct fragment_program *fprog = ctx->FragmentProgram.Current;
- if (!fprog) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameterARB");
- return;
- }
- if (index >= MAX_NV_FRAGMENT_PROGRAM_PARAMS) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameterARB");
- return;
- }
- fprog->Base.LocalParams[index][0] = x;
- fprog->Base.LocalParams[index][1] = y;
- fprog->Base.LocalParams[index][2] = z;
- fprog->Base.LocalParams[index][3] = w;
- }
- else {
- _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameterARB");
- return;
- }
-}
-
-
-/* XXX move into arbprogram.c */
-void
-_mesa_ProgramLocalParameter4fvARB(GLenum target, GLuint index,
- const GLfloat *params)
-{
- _mesa_ProgramLocalParameter4fARB(target, index, params[0], params[1],
- params[2], params[3]);
-}
-
-
-/* XXX move into arbprogram.c */
-void
-_mesa_ProgramLocalParameter4dARB(GLenum target, GLuint index,
- GLdouble x, GLdouble y,
- GLdouble z, GLdouble w)
-{
- _mesa_ProgramLocalParameter4fARB(target, index, (GLfloat)x, (GLfloat)y,
- (GLfloat)z, (GLfloat)w);
-}
-
-
-/* XXX move into arbprogram.c */
-void
-_mesa_ProgramLocalParameter4dvARB(GLenum target, GLuint index,
- const GLdouble *params)
-{
- _mesa_ProgramLocalParameter4fARB(target, index, (GLfloat)params[0],
- (GLfloat)params[1], (GLfloat)params[2],
- (GLfloat)params[3]);
-}
-
-
-/* XXX move into arbprogram.c */
-void
-_mesa_GetProgramLocalParameterfvARB(GLenum target, GLuint index,
- GLfloat *params)
-{
- GET_CURRENT_CONTEXT(ctx);
- ASSERT_OUTSIDE_BEGIN_END(ctx);
-
- if (target == GL_FRAGMENT_PROGRAM_NV) {
- struct fragment_program *fprog = ctx->FragmentProgram.Current;
- if (!fprog) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramLocalParameterARB");
- return;
- }
- if (index >= MAX_NV_FRAGMENT_PROGRAM_PARAMS) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramLocalParameterARB");
- return;
- }
- params[0] = fprog->Base.LocalParams[index][0];
- params[1] = fprog->Base.LocalParams[index][1];
- params[2] = fprog->Base.LocalParams[index][2];
- params[3] = fprog->Base.LocalParams[index][3];
- }
- else {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramLocalParameterARB");
- return;
- }
-}
-
-
-/* XXX move into arbprogram.c */
-void
-_mesa_GetProgramLocalParameterdvARB(GLenum target, GLuint index,
- GLdouble *params)
-{
- GLfloat floatParams[4];
- _mesa_GetProgramLocalParameterfvARB(target, index, floatParams);
- COPY_4V(params, floatParams);
-}
-#endif
diff --git a/src/mesa/main/nvvertexec.c b/src/mesa/main/nvvertexec.c
index b81c2278a5..06f54ca909 100644
--- a/src/mesa/main/nvvertexec.c
+++ b/src/mesa/main/nvvertexec.c
@@ -332,7 +332,17 @@ _mesa_exec_vertex_program(GLcontext *ctx, const struct vertex_program *program)
struct vp_machine *machine = &ctx->VertexProgram.Machine;
const struct vp_instruction *inst;
+ ctx->_CurrentProgram = GL_VERTEX_PROGRAM_ARB; /* or NV, doesn't matter */
+
for (inst = program->Instructions; inst->Opcode != VP_OPCODE_END; inst++) {
+
+ if (ctx->VertexProgram.CallbackEnabled &&
+ ctx->VertexProgram.Callback) {
+ ctx->VertexProgram.CurrentPosition = inst->StringPos;
+ ctx->VertexProgram.Callback(program->Base.Target,
+ ctx->VertexProgram.CallbackData);
+ }
+
switch (inst->Opcode) {
case VP_OPCODE_MOV:
{
@@ -420,10 +430,11 @@ _mesa_exec_vertex_program(GLcontext *ctx, const struct vertex_program *program)
* infinity. This may need some tweaking.
*/
#ifdef VMS
- if (abs_t0 == __MAXFLOAT) {
+ if (abs_t0 == __MAXFLOAT)
#else
- if (IS_INF_OR_NAN(abs_t0)) {
+ if (IS_INF_OR_NAN(abs_t0))
#endif
+ {
SET_POS_INFINITY(q[0]);
q[1] = 1.0F;
SET_POS_INFINITY(q[2]);
@@ -435,7 +446,7 @@ _mesa_exec_vertex_program(GLcontext *ctx, const struct vertex_program *program)
q[1] = (GLfloat) (2.0 * mantissa); /* map [.5, 1) -> [1, 2) */
q[2] = (GLfloat) (q[0] + LOG2(q[1]));
}
- }
+ }
else {
SET_NEG_INFINITY(q[0]);
q[1] = 1.0F;
@@ -723,13 +734,17 @@ _mesa_exec_vertex_program(GLcontext *ctx, const struct vertex_program *program)
break;
case VP_OPCODE_END:
+ ctx->_CurrentProgram = 0;
return;
default:
/* bad instruction opcode */
_mesa_problem(ctx, "Bad VP Opcode in _mesa_exec_vertex_program");
+ ctx->_CurrentProgram = 0;
return;
- }
- }
+ } /* switch */
+ } /* for */
+
+ ctx->_CurrentProgram = 0;
}
diff --git a/src/mesa/main/nvvertparse.c b/src/mesa/main/nvvertparse.c
index 9d0cd5f54d..d6cf58a87e 100644
--- a/src/mesa/main/nvvertparse.c
+++ b/src/mesa/main/nvvertparse.c
@@ -48,6 +48,7 @@ struct parse_state {
GLcontext *ctx;
const GLubyte *start;
const GLubyte *pos;
+ const GLubyte *curLine;
GLboolean isStateProgram;
GLboolean isPositionInvariant;
GLboolean isVersion1_1;
@@ -134,8 +135,9 @@ static GLboolean IsWhitespace(GLubyte b)
* \return <= 0 we found an error, else, return number of characters parsed.
*/
static GLint
-GetToken(const GLubyte *str, GLubyte *token)
+GetToken(struct parse_state *parseState, GLubyte *token)
{
+ const GLubyte *str = parseState->pos;
GLint i = 0, j = 0;
token[0] = 0;
@@ -147,9 +149,13 @@ GetToken(const GLubyte *str, GLubyte *token)
while (str[i] && (str[i] != '\n' && str[i] != '\r')) {
i++;
}
+ if (str[i] == '\n' || str[i] == '\r')
+ parseState->curLine = str + i + 1;
}
else {
/* skip whitespace */
+ if (str[i] == '\n' || str[i] == '\r')
+ parseState->curLine = str + i + 1;
i++;
}
}
@@ -175,7 +181,7 @@ GetToken(const GLubyte *str, GLubyte *token)
return i;
}
- /* punctuation */
+ /* punctuation character */
if (str[i]) {
token[0] = str[i++];
token[1] = 0;
@@ -195,7 +201,7 @@ static GLboolean
Parse_Token(struct parse_state *parseState, GLubyte *token)
{
GLint i;
- i = GetToken(parseState->pos, token);
+ i = GetToken(parseState, token);
if (i <= 0) {
parseState->pos += (-i);
return GL_FALSE;
@@ -212,7 +218,7 @@ static GLboolean
Peek_Token(struct parse_state *parseState, GLubyte *token)
{
GLint i, len;
- i = GetToken(parseState->pos, token);
+ i = GetToken(parseState, token);
if (i <= 0) {
parseState->pos += (-i);
return GL_FALSE;
@@ -240,9 +246,13 @@ Parse_String(struct parse_state *parseState, const char *pattern)
while (*parseState->pos && (*parseState->pos != '\n' && *parseState->pos != '\r')) {
parseState->pos += 1;
}
+ if (*parseState->pos == '\n' || *parseState->pos == '\r')
+ parseState->curLine = parseState->pos + 1;
}
else {
/* skip whitespace */
+ if (*parseState->pos == '\n' || *parseState->pos == '\r')
+ parseState->curLine = parseState->pos + 1;
parseState->pos += 1;
}
}
@@ -792,6 +802,7 @@ Parse_UnaryOpInstruction(struct parse_state *parseState,
RETURN_ERROR1("ABS illegal for vertex program 1.0");
inst->Opcode = opcode;
+ inst->StringPos = parseState->curLine - parseState->start;
/* dest reg */
if (!Parse_MaskedDstReg(parseState, &inst->DstReg))
@@ -823,6 +834,7 @@ Parse_BiOpInstruction(struct parse_state *parseState,
RETURN_ERROR1("SUB illegal for vertex program 1.0");
inst->Opcode = opcode;
+ inst->StringPos = parseState->curLine - parseState->start;
/* dest reg */
if (!Parse_MaskedDstReg(parseState, &inst->DstReg))
@@ -869,6 +881,7 @@ Parse_TriOpInstruction(struct parse_state *parseState,
struct vp_instruction *inst, enum vp_opcode opcode)
{
inst->Opcode = opcode;
+ inst->StringPos = parseState->curLine - parseState->start;
/* dest reg */
if (!Parse_MaskedDstReg(parseState, &inst->DstReg))
@@ -938,6 +951,7 @@ Parse_ScalarInstruction(struct parse_state *parseState,
RETURN_ERROR1("RCC illegal for vertex program 1.0");
inst->Opcode = opcode;
+ inst->StringPos = parseState->curLine - parseState->start;
/* dest reg */
if (!Parse_MaskedDstReg(parseState, &inst->DstReg))
@@ -963,6 +977,7 @@ static GLboolean
Parse_AddressInstruction(struct parse_state *parseState, struct vp_instruction *inst)
{
inst->Opcode = VP_OPCODE_ARL;
+ inst->StringPos = parseState->curLine - parseState->start;
/* dest A0 reg */
if (!Parse_AddrReg(parseState))
@@ -990,6 +1005,7 @@ Parse_EndInstruction(struct parse_state *parseState, struct vp_instruction *inst
GLubyte token[100];
inst->Opcode = VP_OPCODE_END;
+ inst->StringPos = parseState->curLine - parseState->start;
/* this should fail! */
if (Parse_Token(parseState, token))
diff --git a/src/mesa/main/nvvertprog.h b/src/mesa/main/nvvertprog.h
index 411426e963..6ccb0c4efb 100644
--- a/src/mesa/main/nvvertprog.h
+++ b/src/mesa/main/nvvertprog.h
@@ -114,6 +114,9 @@ struct vp_instruction
enum vp_opcode Opcode;
struct vp_src_register SrcReg[3];
struct vp_dst_register DstReg;
+#if FEATURE_MESA_program_debug
+ GLint StringPos;
+#endif
};