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