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