aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2009-09-28 15:26:12 -0600
committerBrian Paul <[email protected]>2009-09-29 10:38:02 -0600
commitc7aee65bb96df3f8e8421b5125dca84c028e9073 (patch)
tree184164f37a1ed629157cef22717e2345728ed229 /src/mesa
parentbaddcbc5225e12052b3bc8c07a8b65243d76574d (diff)
mesa: added _mesa_nop_vertex/fragment_program()
For debug/test purposes.
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/shader/programopt.c91
-rw-r--r--src/mesa/shader/programopt.h7
2 files changed, 98 insertions, 0 deletions
diff --git a/src/mesa/shader/programopt.c b/src/mesa/shader/programopt.c
index f70c75cec8e..3b8529592dd 100644
--- a/src/mesa/shader/programopt.c
+++ b/src/mesa/shader/programopt.c
@@ -573,3 +573,94 @@ _mesa_remove_output_reads(struct gl_program *prog, gl_register_file type)
}
}
}
+
+
+/**
+ * Make the given fragment program into a "no-op" shader.
+ * Actually, just copy the incoming fragment color (or texcoord)
+ * to the output color.
+ * This is for debug/test purposes.
+ */
+void
+_mesa_nop_fragment_program(GLcontext *ctx, struct gl_fragment_program *prog)
+{
+ struct prog_instruction *inst;
+ GLuint inputAttr;
+
+ inst = _mesa_alloc_instructions(2);
+ if (!inst) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "_mesa_nop_fragment_program");
+ return;
+ }
+
+ _mesa_init_instructions(inst, 2);
+
+ inst[0].Opcode = OPCODE_MOV;
+ inst[0].DstReg.File = PROGRAM_OUTPUT;
+ inst[0].DstReg.Index = FRAG_RESULT_COLOR;
+ inst[0].SrcReg[0].File = PROGRAM_INPUT;
+ if (prog->Base.InputsRead & FRAG_BIT_COL0)
+ inputAttr = FRAG_ATTRIB_COL0;
+ else
+ inputAttr = FRAG_ATTRIB_TEX0;
+ inst[0].SrcReg[0].Index = inputAttr;
+
+ inst[1].Opcode = OPCODE_END;
+
+ _mesa_free_instructions(prog->Base.Instructions,
+ prog->Base.NumInstructions);
+
+ prog->Base.Instructions = inst;
+ prog->Base.NumInstructions = 2;
+ prog->Base.InputsRead = 1 << inputAttr;
+ prog->Base.OutputsWritten = 1 << FRAG_RESULT_COLOR;
+}
+
+
+/**
+ * \sa _mesa_nop_fragment_program
+ * Replace the given vertex program with a "no-op" program that just
+ * transforms vertex position and emits color.
+ */
+void
+_mesa_nop_vertex_program(GLcontext *ctx, struct gl_vertex_program *prog)
+{
+ struct prog_instruction *inst;
+ GLuint inputAttr;
+
+ /*
+ * Start with a simple vertex program that emits color.
+ */
+ inst = _mesa_alloc_instructions(2);
+ if (!inst) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "_mesa_nop_vertex_program");
+ return;
+ }
+
+ _mesa_init_instructions(inst, 2);
+
+ inst[0].Opcode = OPCODE_MOV;
+ inst[0].DstReg.File = PROGRAM_OUTPUT;
+ inst[0].DstReg.Index = VERT_RESULT_COL0;
+ inst[0].SrcReg[0].File = PROGRAM_INPUT;
+ if (prog->Base.InputsRead & VERT_BIT_COLOR0)
+ inputAttr = VERT_ATTRIB_COLOR0;
+ else
+ inputAttr = VERT_ATTRIB_TEX0;
+ inst[0].SrcReg[0].Index = inputAttr;
+
+ inst[1].Opcode = OPCODE_END;
+
+ _mesa_free_instructions(prog->Base.Instructions,
+ prog->Base.NumInstructions);
+
+ prog->Base.Instructions = inst;
+ prog->Base.NumInstructions = 2;
+ prog->Base.InputsRead = 1 << inputAttr;
+ prog->Base.OutputsWritten = 1 << VERT_RESULT_COL0;
+
+ /*
+ * Now insert code to do standard modelview/projection transformation.
+ */
+ _mesa_insert_mvp_code(ctx, prog);
+}
diff --git a/src/mesa/shader/programopt.h b/src/mesa/shader/programopt.h
index 96acaf9566c..21fac07849a 100644
--- a/src/mesa/shader/programopt.h
+++ b/src/mesa/shader/programopt.h
@@ -42,4 +42,11 @@ _mesa_count_texture_instructions(struct gl_program *prog);
extern void
_mesa_remove_output_reads(struct gl_program *prog, gl_register_file type);
+extern void
+_mesa_nop_fragment_program(GLcontext *ctx, struct gl_fragment_program *prog);
+
+extern void
+_mesa_nop_vertex_program(GLcontext *ctx, struct gl_vertex_program *prog);
+
+
#endif /* PROGRAMOPT_H */