consolidate vertex/fragment program printing into _mesa_print_program()
[mesa.git] / src / mesa / shader / arbfragparse.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.2
4 *
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #define DEBUG_FP 0
26
27 /**
28 * \file arbfragparse.c
29 * ARB_fragment_program parser.
30 * \author Karl Rasche
31 */
32
33 #include "glheader.h"
34 #include "context.h"
35 #include "imports.h"
36 #include "macros.h"
37 #include "mtypes.h"
38 #include "program.h"
39 #include "arbprogparse.h"
40 #include "arbfragparse.h"
41
42
43 void
44 _mesa_parse_arb_fragment_program(GLcontext * ctx, GLenum target,
45 const GLubyte * str, GLsizei len,
46 struct fragment_program *program)
47 {
48 GLuint i;
49 struct arb_program ap;
50 struct prog_instruction *newInstructions;
51 (void) target;
52
53 /* set the program target before parsing */
54 ap.Base.Target = GL_FRAGMENT_PROGRAM_ARB;
55
56 if (!_mesa_parse_arb_program(ctx, str, len, &ap)) {
57 /* Error in the program. Just return. */
58 return;
59 }
60
61 /* Copy the relevant contents of the arb_program struct into the
62 * fragment_program struct.
63 */
64 /* copy instruction buffer */
65 newInstructions = (struct prog_instruction *)
66 _mesa_malloc(ap.Base.NumInstructions * sizeof(struct prog_instruction));
67 if (!newInstructions) {
68 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glProgramStringARB");
69 return;
70 }
71 _mesa_memcpy(newInstructions, ap.FPInstructions,
72 ap.Base.NumInstructions * sizeof(struct prog_instruction));
73 if (program->Instructions)
74 _mesa_free(program->Instructions);
75 program->Instructions = newInstructions;
76 program->Base.String = ap.Base.String;
77 program->Base.NumInstructions = ap.Base.NumInstructions;
78 program->Base.NumTemporaries = ap.Base.NumTemporaries;
79 program->Base.NumParameters = ap.Base.NumParameters;
80 program->Base.NumAttributes = ap.Base.NumAttributes;
81 program->Base.NumAddressRegs = ap.Base.NumAddressRegs;
82 program->NumAluInstructions = ap.NumAluInstructions;
83 program->NumTexInstructions = ap.NumTexInstructions;
84 program->NumTexIndirections = ap.NumTexIndirections;
85 program->InputsRead = ap.InputsRead;
86 program->OutputsWritten = ap.OutputsWritten;
87 for (i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++)
88 program->TexturesUsed[i] = ap.TexturesUsed[i];
89
90 if (program->Parameters) {
91 /* free previous program's parameters */
92 _mesa_free_parameter_list(program->Parameters);
93 }
94 program->Parameters = ap.Parameters;
95 program->FogOption = ap.FogOption;
96
97 #if DEBUG_FP
98 _mesa_print_program(ap.Base.NumInstructions, ap.FPInstructions);
99 #endif
100 }