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