init secondary color to (0,0,0,1). remove some redundant initializations.
[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 extern struct program *
62 _mesa_new_program(GLcontext *ctx, GLenum target, GLuint id);
63
64 extern void
65 _mesa_delete_program(GLcontext *ctx, struct program *prog);
66
67
68
69 /*
70 * Used for describing GL state referenced from inside ARB vertex and
71 * fragment programs.
72 * A string such as "state.light[0].ambient" gets translated into a
73 * sequence of tokens such as [ STATE_LIGHT, 0, STATE_AMBIENT ].
74 */
75 enum state_index {
76 STATE_MATERIAL,
77
78 STATE_LIGHT,
79 STATE_LIGHTMODEL_AMBIENT,
80 STATE_LIGHTMODEL_SCENECOLOR,
81 STATE_LIGHTPROD,
82
83 STATE_TEXGEN,
84
85 STATE_FOG_COLOR,
86 STATE_FOG_PARAMS,
87
88 STATE_CLIPPLANE,
89
90 STATE_POINT_SIZE,
91 STATE_POINT_ATTENUATION,
92
93 STATE_MATRIX,
94 STATE_MODELVIEW,
95 STATE_PROJECTION,
96 STATE_MVP,
97 STATE_TEXTURE,
98 STATE_PROGRAM,
99 STATE_MATRIX_INVERSE,
100 STATE_MATRIX_TRANSPOSE,
101 STATE_MATRIX_INVTRANS,
102
103 STATE_AMBIENT,
104 STATE_DIFFUSE,
105 STATE_SPECULAR,
106 STATE_EMISSION,
107 STATE_SHININESS,
108 STATE_HALF,
109
110 STATE_POSITION,
111 STATE_ATTENUATION,
112 STATE_SPOT_DIRECTION,
113
114 STATE_TEXGEN_EYE_S,
115 STATE_TEXGEN_EYE_T,
116 STATE_TEXGEN_EYE_R,
117 STATE_TEXGEN_EYE_Q,
118 STATE_TEXGEN_OBJECT_S,
119 STATE_TEXGEN_OBJECT_T,
120 STATE_TEXGEN_OBJECT_R,
121 STATE_TEXGEN_OBJECT_Q,
122
123 STATE_TEXENV_COLOR,
124
125 STATE_DEPTH_RANGE,
126
127 STATE_VERTEX_PROGRAM,
128 STATE_FRAGMENT_PROGRAM,
129
130 STATE_ENV,
131 STATE_LOCAL
132 };
133
134
135
136 /*
137 * Named program parameters
138 * Used for NV_fragment_program "DEFINE"d constants and "DECLARE"d parameters,
139 * and ARB_fragment_program global state references. For the later, Name
140 * might be "state.light[0].diffuse", for example.
141 */
142
143 enum parameter_type
144 {
145 NAMED_PARAMETER,
146 CONSTANT,
147 STATE
148 };
149
150
151 struct program_parameter
152 {
153 const char *Name; /* Null-terminated */
154 enum parameter_type Type;
155 enum state_index StateIndexes[6]; /* Global state reference */
156 GLfloat Values[4];
157 };
158
159
160 struct program_parameter_list
161 {
162 GLuint NumParameters;
163 struct program_parameter *Parameters;
164 };
165
166
167 /*
168 * Program parameter functions
169 */
170
171 extern struct program_parameter_list *
172 _mesa_new_parameter_list(void);
173
174 extern void
175 _mesa_free_parameter_list(struct program_parameter_list *paramList);
176
177 extern void
178 _mesa_free_parameters(struct program_parameter_list *paramList);
179
180 extern GLint
181 _mesa_add_named_parameter(struct program_parameter_list *paramList,
182 const char *name, const GLfloat values[4]);
183
184 extern GLint
185 _mesa_add_named_constant(struct program_parameter_list *paramList,
186 const char *name, const GLfloat values[4]);
187
188 extern GLint
189 _mesa_add_unnamed_constant(struct program_parameter_list *paramList,
190 const GLfloat values[4]);
191
192 extern GLint
193 _mesa_add_state_reference(struct program_parameter_list *paramList,
194 GLint *stateTokens);
195
196 extern GLfloat *
197 _mesa_lookup_parameter_value(struct program_parameter_list *paramList,
198 GLsizei nameLen, const char *name);
199
200 extern GLint
201 _mesa_lookup_parameter_index(struct program_parameter_list *paramList,
202 GLsizei nameLen, const char *name);
203
204 extern void
205 _mesa_load_state_parameters(GLcontext *ctx,
206 struct program_parameter_list *paramList);
207
208
209 /*
210 * API functions
211 */
212
213 extern void GLAPIENTRY
214 _mesa_BindProgram(GLenum target, GLuint id);
215
216 extern void GLAPIENTRY
217 _mesa_DeletePrograms(GLsizei n, const GLuint *ids);
218
219 extern void GLAPIENTRY
220 _mesa_GenPrograms(GLsizei n, GLuint *ids);
221
222 extern GLboolean GLAPIENTRY
223 _mesa_IsProgram(GLuint id);
224
225
226
227 /*
228 * GL_MESA_program_debug
229 */
230
231 extern void
232 _mesa_ProgramCallbackMESA(GLenum target, GLprogramcallbackMESA callback,
233 GLvoid *data);
234
235 extern void
236 _mesa_GetProgramRegisterfvMESA(GLenum target, GLsizei len,
237 const GLubyte *registerName, GLfloat *v);
238
239
240 #endif /* PROGRAM_H */