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