test version of startmenu root with big icons
[reactos.git] / reactos / lib / mesa32 / src / shader / arbfragparse.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.1
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 "arbprogparse.h"
39 #include "arbfragparse.h"
40
41 void
42 _mesa_debug_fp_inst(GLint num, struct fp_instruction *fp)
43 {
44 GLint a;
45
46 fprintf(stderr, "PROGRAM_OUTPUT: 0x%x\n", PROGRAM_OUTPUT);
47 fprintf(stderr, "PROGRAM_INPUT: 0x%x\n", PROGRAM_INPUT);
48 fprintf(stderr, "PROGRAM_TEMPORARY: 0x%x\n", PROGRAM_TEMPORARY);
49
50 for (a=0; a<num; a++) {
51 switch (fp[a].Opcode) {
52 case FP_OPCODE_END:
53 fprintf(stderr, "FP_OPCODE_END"); break;
54
55 case FP_OPCODE_ABS:
56 fprintf(stderr, "FP_OPCODE_ABS"); break;
57
58 case FP_OPCODE_ADD:
59 fprintf(stderr, "FP_OPCODE_ADD"); break;
60
61 case FP_OPCODE_CMP:
62 fprintf(stderr, "FP_OPCODE_CMP"); break;
63
64 case FP_OPCODE_COS:
65 fprintf(stderr, "FP_OPCODE_COS"); break;
66
67 case FP_OPCODE_DP3:
68 fprintf(stderr, "FP_OPCODE_DP3"); break;
69
70 case FP_OPCODE_DP4:
71 fprintf(stderr, "FP_OPCODE_DP4"); break;
72
73 case FP_OPCODE_DPH:
74 fprintf(stderr, "FP_OPCODE_DPH"); break;
75
76 case FP_OPCODE_DST:
77 fprintf(stderr, "FP_OPCODE_DST"); break;
78
79 case FP_OPCODE_EX2:
80 fprintf(stderr, "FP_OPCODE_EX2"); break;
81
82 case FP_OPCODE_FLR:
83 fprintf(stderr, "FP_OPCODE_FLR"); break;
84
85 case FP_OPCODE_FRC:
86 fprintf(stderr, "FP_OPCODE_FRC"); break;
87
88 case FP_OPCODE_KIL:
89 fprintf(stderr, "FP_OPCODE_KIL"); break;
90
91 case FP_OPCODE_LG2:
92 fprintf(stderr, "FP_OPCODE_LG2"); break;
93
94 case FP_OPCODE_LIT:
95 fprintf(stderr, "FP_OPCODE_LIT"); break;
96
97 case FP_OPCODE_LRP:
98 fprintf(stderr, "FP_OPCODE_LRP"); break;
99
100 case FP_OPCODE_MAD:
101 fprintf(stderr, "FP_OPCODE_MAD"); break;
102
103 case FP_OPCODE_MAX:
104 fprintf(stderr, "FP_OPCODE_MAX"); break;
105
106 case FP_OPCODE_MIN:
107 fprintf(stderr, "FP_OPCODE_MIN"); break;
108
109 case FP_OPCODE_MOV:
110 fprintf(stderr, "FP_OPCODE_MOV"); break;
111
112 case FP_OPCODE_MUL:
113 fprintf(stderr, "FP_OPCODE_MUL"); break;
114
115 case FP_OPCODE_POW:
116 fprintf(stderr, "FP_OPCODE_POW"); break;
117
118 case FP_OPCODE_RCP:
119 fprintf(stderr, "FP_OPCODE_RCP"); break;
120
121 case FP_OPCODE_RSQ:
122 fprintf(stderr, "FP_OPCODE_RSQ"); break;
123
124 case FP_OPCODE_SCS:
125 fprintf(stderr, "FP_OPCODE_SCS"); break;
126
127 case FP_OPCODE_SIN:
128 fprintf(stderr, "FP_OPCODE_SIN"); break;
129
130 case FP_OPCODE_SLT:
131 fprintf(stderr, "FP_OPCODE_SLT"); break;
132
133 case FP_OPCODE_SUB:
134 fprintf(stderr, "FP_OPCODE_SUB"); break;
135
136 case FP_OPCODE_SWZ:
137 fprintf(stderr, "FP_OPCODE_SWZ"); break;
138
139 case FP_OPCODE_TEX:
140 fprintf(stderr, "FP_OPCODE_TEX"); break;
141
142 case FP_OPCODE_TXB:
143 fprintf(stderr, "FP_OPCODE_TXB"); break;
144
145 case FP_OPCODE_TXP:
146 fprintf(stderr, "FP_OPCODE_TXP"); break;
147
148 case FP_OPCODE_XPD:
149 fprintf(stderr, "FP_OPCODE_XPD"); break;
150
151 default:
152 _mesa_warning(NULL, "Bad opcode in debug_fg_inst()");
153 }
154
155 fprintf(stderr, " D(0x%x:%d:%d%d%d%d) ",
156 fp[a].DstReg.File, fp[a].DstReg.Index,
157 fp[a].DstReg.WriteMask[0], fp[a].DstReg.WriteMask[1],
158 fp[a].DstReg.WriteMask[2], fp[a].DstReg.WriteMask[3]);
159
160 fprintf(stderr, "S1(0x%x:%d:%d%d%d%d) ", fp[a].SrcReg[0].File, fp[a].SrcReg[0].Index,
161 fp[a].SrcReg[0].Swizzle[0],
162 fp[a].SrcReg[0].Swizzle[1],
163 fp[a].SrcReg[0].Swizzle[2],
164 fp[a].SrcReg[0].Swizzle[3]);
165
166 fprintf(stderr, "S2(0x%x:%d:%d%d%d%d) ", fp[a].SrcReg[1].File, fp[a].SrcReg[1].Index,
167 fp[a].SrcReg[1].Swizzle[0],
168 fp[a].SrcReg[1].Swizzle[1],
169 fp[a].SrcReg[1].Swizzle[2],
170 fp[a].SrcReg[1].Swizzle[3]);
171
172 fprintf(stderr, "S3(0x%x:%d:%d%d%d%d)", fp[a].SrcReg[2].File, fp[a].SrcReg[2].Index,
173 fp[a].SrcReg[2].Swizzle[0],
174 fp[a].SrcReg[2].Swizzle[1],
175 fp[a].SrcReg[2].Swizzle[2],
176 fp[a].SrcReg[2].Swizzle[3]);
177
178 fprintf(stderr, "\n");
179 }
180 }
181
182 void
183 _mesa_parse_arb_fragment_program(GLcontext * ctx, GLenum target,
184 const GLubyte * str, GLsizei len,
185 struct fragment_program *program)
186 {
187 GLuint a, retval;
188 struct arb_program ap;
189 (void) target;
190
191 /* set the program target before parsing */
192 ap.Base.Target = GL_FRAGMENT_PROGRAM_ARB;
193
194 retval = _mesa_parse_arb_program(ctx, str, len, &ap);
195
196 /* XXX: Parse error. Cleanup things and return */
197 if (retval)
198 {
199 program->Instructions = (struct fp_instruction *) _mesa_malloc (
200 sizeof(struct fp_instruction) );
201 program->Instructions[0].Opcode = FP_OPCODE_END;
202 return;
203 }
204
205 /* copy the relvant contents of the arb_program struct into the
206 * fragment_program struct
207 */
208 program->Base.String = ap.Base.String;
209 program->Base.NumInstructions = ap.Base.NumInstructions;
210 program->Base.NumTemporaries = ap.Base.NumTemporaries;
211 program->Base.NumParameters = ap.Base.NumParameters;
212 program->Base.NumAttributes = ap.Base.NumAttributes;
213 program->Base.NumAddressRegs = ap.Base.NumAddressRegs;
214
215 program->InputsRead = ap.InputsRead;
216 program->OutputsWritten = ap.OutputsWritten;
217 for (a=0; a<MAX_TEXTURE_IMAGE_UNITS; a++)
218 program->TexturesUsed[a] = ap.TexturesUsed[a];
219 program->NumAluInstructions = ap.NumAluInstructions;
220 program->NumTexInstructions = ap.NumTexInstructions;
221 program->NumTexIndirections = ap.NumTexIndirections;
222 program->Parameters = ap.Parameters;
223 program->FogOption = ap.FogOption;
224
225 /* XXX: Eh.. we parsed something that wasn't a fragment program. doh! */
226 /* this wont happen any more */
227 /*
228 if (ap.Base.Target != GL_FRAGMENT_PROGRAM_ARB)
229 {
230 program->Instructions = (struct fp_instruction *) _mesa_malloc (
231 sizeof(struct fp_instruction) );
232 program->Instructions[0].Opcode = FP_OPCODE_END;
233
234 _mesa_error (ctx, GL_INVALID_OPERATION, "Parsed a non-fragment program as a fragment program");
235 return;
236 }
237 */
238
239 #if DEBUG_FP
240 _mesa_debug_fp_inst(ap.Base.NumInstructions, ap.FPInstructions);
241 #endif
242
243 program->Instructions = ap.FPInstructions;
244 }