Massively cleaned up the code that calculates front/back/depth buffer
[mesa.git] / src / mesa / shader / program.h
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 /**
26 * \file program.c
27 * Vertex and fragment program support functions.
28 * \author Brian Paul
29 */
30
31
32 /**
33 * \mainpage Mesa vertex and fragment program module
34 *
35 * This module or directory contains most of the code for vertex and
36 * fragment programs and shaders, including state management, parsers,
37 * and (some) software routines for executing programs
38 */
39
40 #ifndef PROGRAM_H
41 #define PROGRAM_H
42
43 #include "mtypes.h"
44
45
46 /* for GL_ARB_v_p and GL_ARB_f_p SWZ instruction */
47 #define SWIZZLE_X 0
48 #define SWIZZLE_Y 1
49 #define SWIZZLE_Z 2
50 #define SWIZZLE_W 3
51 #define SWIZZLE_ZERO 4 /* keep these values together: KW */
52 #define SWIZZLE_ONE 5 /* keep these values together: KW */
53
54
55 extern struct program _mesa_DummyProgram;
56
57
58 /*
59 * Internal functions
60 */
61
62 extern void
63 _mesa_init_program(GLcontext *ctx);
64
65 extern void
66 _mesa_free_program_data(GLcontext *ctx);
67
68 extern void
69 _mesa_set_program_error(GLcontext *ctx, GLint pos, const char *string);
70
71 extern const GLubyte *
72 _mesa_find_line_column(const GLubyte *string, const GLubyte *pos,
73 GLint *line, GLint *col);
74
75
76 extern struct program *
77 _mesa_init_vertex_program( GLcontext *ctx,
78 struct vertex_program *prog,
79 GLenum target,
80 GLuint id );
81
82 extern struct program *
83 _mesa_init_fragment_program( GLcontext *ctx,
84 struct fragment_program *prog,
85 GLenum target,
86 GLuint id );
87
88 extern struct program *
89 _mesa_new_program(GLcontext *ctx, GLenum target, GLuint id);
90
91 extern void
92 _mesa_delete_program(GLcontext *ctx, struct program *prog);
93
94
95
96 /*
97 * Used for describing GL state referenced from inside ARB vertex and
98 * fragment programs.
99 * A string such as "state.light[0].ambient" gets translated into a
100 * sequence of tokens such as [ STATE_LIGHT, 0, STATE_AMBIENT ].
101 */
102 enum state_index {
103 STATE_MATERIAL,
104
105 STATE_LIGHT,
106 STATE_LIGHTMODEL_AMBIENT,
107 STATE_LIGHTMODEL_SCENECOLOR,
108 STATE_LIGHTPROD,
109
110 STATE_TEXGEN,
111
112 STATE_FOG_COLOR,
113 STATE_FOG_PARAMS,
114
115 STATE_CLIPPLANE,
116
117 STATE_POINT_SIZE,
118 STATE_POINT_ATTENUATION,
119
120 STATE_MATRIX,
121 STATE_MODELVIEW,
122 STATE_PROJECTION,
123 STATE_MVP,
124 STATE_TEXTURE,
125 STATE_PROGRAM,
126 STATE_MATRIX_INVERSE,
127 STATE_MATRIX_TRANSPOSE,
128 STATE_MATRIX_INVTRANS,
129
130 STATE_AMBIENT,
131 STATE_DIFFUSE,
132 STATE_SPECULAR,
133 STATE_EMISSION,
134 STATE_SHININESS,
135 STATE_HALF,
136
137 STATE_POSITION,
138 STATE_ATTENUATION,
139 STATE_SPOT_DIRECTION,
140
141 STATE_TEXGEN_EYE_S,
142 STATE_TEXGEN_EYE_T,
143 STATE_TEXGEN_EYE_R,
144 STATE_TEXGEN_EYE_Q,
145 STATE_TEXGEN_OBJECT_S,
146 STATE_TEXGEN_OBJECT_T,
147 STATE_TEXGEN_OBJECT_R,
148 STATE_TEXGEN_OBJECT_Q,
149
150 STATE_TEXENV_COLOR,
151
152 STATE_DEPTH_RANGE,
153
154 STATE_VERTEX_PROGRAM,
155 STATE_FRAGMENT_PROGRAM,
156
157 STATE_ENV,
158 STATE_LOCAL
159 };
160
161
162
163 /*
164 * Named program parameters
165 * Used for NV_fragment_program "DEFINE"d constants and "DECLARE"d parameters,
166 * and ARB_fragment_program global state references. For the later, Name
167 * might be "state.light[0].diffuse", for example.
168 */
169
170 enum parameter_type
171 {
172 NAMED_PARAMETER,
173 CONSTANT,
174 STATE
175 };
176
177
178 struct program_parameter
179 {
180 const char *Name; /* Null-terminated */
181 enum parameter_type Type;
182 enum state_index StateIndexes[6]; /* Global state reference */
183 GLfloat Values[4];
184 };
185
186
187 struct program_parameter_list
188 {
189 GLuint NumParameters;
190 struct program_parameter *Parameters;
191 };
192
193
194 /*
195 * Program parameter functions
196 */
197
198 extern struct program_parameter_list *
199 _mesa_new_parameter_list(void);
200
201 extern void
202 _mesa_free_parameter_list(struct program_parameter_list *paramList);
203
204 extern void
205 _mesa_free_parameters(struct program_parameter_list *paramList);
206
207 extern GLint
208 _mesa_add_named_parameter(struct program_parameter_list *paramList,
209 const char *name, const GLfloat values[4]);
210
211 extern GLint
212 _mesa_add_named_constant(struct program_parameter_list *paramList,
213 const char *name, const GLfloat values[4]);
214
215 extern GLint
216 _mesa_add_unnamed_constant(struct program_parameter_list *paramList,
217 const GLfloat values[4]);
218
219 extern GLint
220 _mesa_add_state_reference(struct program_parameter_list *paramList,
221 GLint *stateTokens);
222
223 extern GLfloat *
224 _mesa_lookup_parameter_value(struct program_parameter_list *paramList,
225 GLsizei nameLen, const char *name);
226
227 extern GLint
228 _mesa_lookup_parameter_index(struct program_parameter_list *paramList,
229 GLsizei nameLen, const char *name);
230
231 extern void
232 _mesa_load_state_parameters(GLcontext *ctx,
233 struct program_parameter_list *paramList);
234
235
236 /*
237 * API functions
238 */
239
240 extern void GLAPIENTRY
241 _mesa_BindProgram(GLenum target, GLuint id);
242
243 extern void GLAPIENTRY
244 _mesa_DeletePrograms(GLsizei n, const GLuint *ids);
245
246 extern void GLAPIENTRY
247 _mesa_GenPrograms(GLsizei n, GLuint *ids);
248
249 extern GLboolean GLAPIENTRY
250 _mesa_IsProgram(GLuint id);
251
252
253
254 /*
255 * GL_MESA_program_debug
256 */
257
258 extern void
259 _mesa_ProgramCallbackMESA(GLenum target, GLprogramcallbackMESA callback,
260 GLvoid *data);
261
262 extern void
263 _mesa_GetProgramRegisterfvMESA(GLenum target, GLsizei len,
264 const GLubyte *registerName, GLfloat *v);
265
266
267 #endif /* PROGRAM_H */