Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Mesa 3-D graphics library |
Brian Paul | fd4395b | 2005-11-05 03:02:28 +0000 | [diff] [blame] | 3 | * Version: 6.5 |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 4 | * |
Brian Paul | cdb6541 | 2005-01-11 15:56:47 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999-2005 Brian Paul All Rights Reserved. |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 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 | |
Brian Paul | 253204f | 2004-09-10 00:45:12 +0000 | [diff] [blame] | 32 | /** |
| 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 Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 40 | #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 | |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 54 | #define MAKE_SWIZZLE4(a,b,c,d) (((a)<<0) | ((b)<<3) | ((c)<<6) | ((d)<<9)) |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 55 | #define SWIZZLE_NOOP MAKE_SWIZZLE4(0,1,2,3) |
| 56 | #define GET_SWZ(swz, idx) (((swz) >> ((idx)*3)) & 0x7) |
| 57 | #define GET_BIT(msk, idx) (((msk) >> (idx)) & 0x1) |
| 58 | |
| 59 | |
| 60 | #define WRITEMASK_X 0x1 |
| 61 | #define WRITEMASK_Y 0x2 |
| 62 | #define WRITEMASK_XY 0x3 |
| 63 | #define WRITEMASK_Z 0x4 |
| 64 | #define WRITEMASK_XZ 0x5 |
| 65 | #define WRITEMASK_YZ 0x6 |
| 66 | #define WRITEMASK_XYZ 0x7 |
| 67 | #define WRITEMASK_W 0x8 |
| 68 | #define WRITEMASK_XW 0x9 |
| 69 | #define WRITEMASK_YW 0xa |
| 70 | #define WRITEMASK_XYW 0xb |
| 71 | #define WRITEMASK_ZW 0xc |
| 72 | #define WRITEMASK_XZW 0xd |
| 73 | #define WRITEMASK_YZW 0xe |
| 74 | #define WRITEMASK_XYZW 0xf |
| 75 | |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 76 | |
Brian Paul | 9ca8392 | 2004-10-02 15:16:59 +0000 | [diff] [blame] | 77 | extern struct program _mesa_DummyProgram; |
| 78 | |
| 79 | |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 80 | /* |
| 81 | * Internal functions |
| 82 | */ |
| 83 | |
| 84 | extern void |
| 85 | _mesa_init_program(GLcontext *ctx); |
| 86 | |
| 87 | extern void |
Brian Paul | 21841f0 | 2004-08-14 14:28:11 +0000 | [diff] [blame] | 88 | _mesa_free_program_data(GLcontext *ctx); |
| 89 | |
| 90 | extern void |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 91 | _mesa_set_program_error(GLcontext *ctx, GLint pos, const char *string); |
| 92 | |
| 93 | extern const GLubyte * |
| 94 | _mesa_find_line_column(const GLubyte *string, const GLubyte *pos, |
| 95 | GLint *line, GLint *col); |
| 96 | |
| 97 | |
| 98 | extern struct program * |
Brian Paul | cdb6541 | 2005-01-11 15:56:47 +0000 | [diff] [blame] | 99 | _mesa_init_vertex_program(GLcontext *ctx, |
| 100 | struct vertex_program *prog, |
| 101 | GLenum target, GLuint id); |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 102 | |
| 103 | extern struct program * |
Brian Paul | cdb6541 | 2005-01-11 15:56:47 +0000 | [diff] [blame] | 104 | _mesa_init_fragment_program(GLcontext *ctx, |
| 105 | struct fragment_program *prog, |
| 106 | GLenum target, GLuint id); |
| 107 | |
| 108 | extern struct program * |
| 109 | _mesa_init_ati_fragment_shader(GLcontext *ctx, |
| 110 | struct ati_fragment_shader *prog, |
| 111 | GLenum target, GLuint id ); |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 112 | |
| 113 | extern struct program * |
| 114 | _mesa_new_program(GLcontext *ctx, GLenum target, GLuint id); |
| 115 | |
| 116 | extern void |
| 117 | _mesa_delete_program(GLcontext *ctx, struct program *prog); |
| 118 | |
| 119 | |
| 120 | |
Brian Paul | fd4395b | 2005-11-05 03:02:28 +0000 | [diff] [blame] | 121 | /** |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 122 | * Used for describing GL state referenced from inside ARB vertex and |
| 123 | * fragment programs. |
| 124 | * A string such as "state.light[0].ambient" gets translated into a |
| 125 | * sequence of tokens such as [ STATE_LIGHT, 0, STATE_AMBIENT ]. |
| 126 | */ |
| 127 | enum state_index { |
| 128 | STATE_MATERIAL, |
| 129 | |
| 130 | STATE_LIGHT, |
| 131 | STATE_LIGHTMODEL_AMBIENT, |
| 132 | STATE_LIGHTMODEL_SCENECOLOR, |
| 133 | STATE_LIGHTPROD, |
| 134 | |
| 135 | STATE_TEXGEN, |
| 136 | |
| 137 | STATE_FOG_COLOR, |
| 138 | STATE_FOG_PARAMS, |
| 139 | |
| 140 | STATE_CLIPPLANE, |
| 141 | |
| 142 | STATE_POINT_SIZE, |
| 143 | STATE_POINT_ATTENUATION, |
| 144 | |
| 145 | STATE_MATRIX, |
| 146 | STATE_MODELVIEW, |
| 147 | STATE_PROJECTION, |
| 148 | STATE_MVP, |
| 149 | STATE_TEXTURE, |
| 150 | STATE_PROGRAM, |
| 151 | STATE_MATRIX_INVERSE, |
| 152 | STATE_MATRIX_TRANSPOSE, |
| 153 | STATE_MATRIX_INVTRANS, |
| 154 | |
| 155 | STATE_AMBIENT, |
| 156 | STATE_DIFFUSE, |
| 157 | STATE_SPECULAR, |
| 158 | STATE_EMISSION, |
| 159 | STATE_SHININESS, |
| 160 | STATE_HALF, |
| 161 | |
| 162 | STATE_POSITION, |
| 163 | STATE_ATTENUATION, |
| 164 | STATE_SPOT_DIRECTION, |
| 165 | |
| 166 | STATE_TEXGEN_EYE_S, |
| 167 | STATE_TEXGEN_EYE_T, |
| 168 | STATE_TEXGEN_EYE_R, |
| 169 | STATE_TEXGEN_EYE_Q, |
| 170 | STATE_TEXGEN_OBJECT_S, |
| 171 | STATE_TEXGEN_OBJECT_T, |
| 172 | STATE_TEXGEN_OBJECT_R, |
| 173 | STATE_TEXGEN_OBJECT_Q, |
| 174 | |
| 175 | STATE_TEXENV_COLOR, |
| 176 | |
| 177 | STATE_DEPTH_RANGE, |
| 178 | |
| 179 | STATE_VERTEX_PROGRAM, |
| 180 | STATE_FRAGMENT_PROGRAM, |
| 181 | |
| 182 | STATE_ENV, |
Keith Whitwell | 7c26b61 | 2005-04-21 14:46:57 +0000 | [diff] [blame] | 183 | STATE_LOCAL, |
| 184 | |
| 185 | STATE_INTERNAL, /* Mesa additions */ |
| 186 | STATE_NORMAL_SCALE, |
Brian Paul | fd4395b | 2005-11-05 03:02:28 +0000 | [diff] [blame] | 187 | STATE_POSITION_NORMALIZED /* normalized light position */ |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | |
| 191 | |
Brian Paul | 613e1ad | 2005-11-05 02:15:21 +0000 | [diff] [blame] | 192 | /** |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 193 | * Named program parameters |
| 194 | * Used for NV_fragment_program "DEFINE"d constants and "DECLARE"d parameters, |
| 195 | * and ARB_fragment_program global state references. For the later, Name |
| 196 | * might be "state.light[0].diffuse", for example. |
| 197 | */ |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 198 | struct program_parameter |
| 199 | { |
| 200 | const char *Name; /* Null-terminated */ |
Brian Paul | 613e1ad | 2005-11-05 02:15:21 +0000 | [diff] [blame] | 201 | enum register_file Type; /** PROGRAM_NAMED_PARAM, CONSTANT or STATE_VAR */ |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 202 | enum state_index StateIndexes[6]; /* Global state reference */ |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | |
| 206 | struct program_parameter_list |
| 207 | { |
Brian Paul | 613e1ad | 2005-11-05 02:15:21 +0000 | [diff] [blame] | 208 | GLuint Size; /** allocated size of Parameters, ParameterValues */ |
| 209 | GLuint NumParameters; /** number of parameters in arrays */ |
| 210 | struct program_parameter *Parameters; /** Array [Size] */ |
| 211 | GLfloat (*ParameterValues)[4]; /** Array [Size] */ |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 212 | }; |
| 213 | |
| 214 | |
| 215 | /* |
| 216 | * Program parameter functions |
| 217 | */ |
| 218 | |
| 219 | extern struct program_parameter_list * |
| 220 | _mesa_new_parameter_list(void); |
| 221 | |
| 222 | extern void |
| 223 | _mesa_free_parameter_list(struct program_parameter_list *paramList); |
| 224 | |
| 225 | extern void |
| 226 | _mesa_free_parameters(struct program_parameter_list *paramList); |
| 227 | |
| 228 | extern GLint |
| 229 | _mesa_add_named_parameter(struct program_parameter_list *paramList, |
| 230 | const char *name, const GLfloat values[4]); |
| 231 | |
| 232 | extern GLint |
| 233 | _mesa_add_named_constant(struct program_parameter_list *paramList, |
| 234 | const char *name, const GLfloat values[4]); |
| 235 | |
| 236 | extern GLint |
| 237 | _mesa_add_unnamed_constant(struct program_parameter_list *paramList, |
| 238 | const GLfloat values[4]); |
| 239 | |
| 240 | extern GLint |
| 241 | _mesa_add_state_reference(struct program_parameter_list *paramList, |
Brian Paul | 1624162 | 2005-11-03 02:26:47 +0000 | [diff] [blame] | 242 | const GLint *stateTokens); |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 243 | |
| 244 | extern GLfloat * |
| 245 | _mesa_lookup_parameter_value(struct program_parameter_list *paramList, |
| 246 | GLsizei nameLen, const char *name); |
| 247 | |
| 248 | extern GLint |
| 249 | _mesa_lookup_parameter_index(struct program_parameter_list *paramList, |
| 250 | GLsizei nameLen, const char *name); |
| 251 | |
| 252 | extern void |
| 253 | _mesa_load_state_parameters(GLcontext *ctx, |
| 254 | struct program_parameter_list *paramList); |
| 255 | |
| 256 | |
Brian Paul | 30d6a4b | 2005-11-05 20:18:18 +0000 | [diff] [blame] | 257 | |
| 258 | extern void |
Brian Paul | de99760 | 2005-11-12 17:53:14 +0000 | [diff] [blame^] | 259 | _mesa_print_instruction(const struct prog_instruction *inst); |
| 260 | |
| 261 | extern void |
| 262 | _mesa_print_program(const struct program *prog); |
| 263 | |
| 264 | extern void |
| 265 | _mesa_print_program_parameters(GLcontext *ctx, const struct program *prog); |
Brian Paul | 30d6a4b | 2005-11-05 20:18:18 +0000 | [diff] [blame] | 266 | |
| 267 | |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 268 | /* |
Brian Paul | fd4395b | 2005-11-05 03:02:28 +0000 | [diff] [blame] | 269 | * API functions common to ARB/NV_vertex/fragment_program |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 270 | */ |
| 271 | |
| 272 | extern void GLAPIENTRY |
| 273 | _mesa_BindProgram(GLenum target, GLuint id); |
| 274 | |
| 275 | extern void GLAPIENTRY |
| 276 | _mesa_DeletePrograms(GLsizei n, const GLuint *ids); |
| 277 | |
| 278 | extern void GLAPIENTRY |
| 279 | _mesa_GenPrograms(GLsizei n, GLuint *ids); |
| 280 | |
| 281 | extern GLboolean GLAPIENTRY |
| 282 | _mesa_IsProgram(GLuint id); |
| 283 | |
| 284 | |
| 285 | |
| 286 | /* |
| 287 | * GL_MESA_program_debug |
| 288 | */ |
| 289 | |
| 290 | extern void |
| 291 | _mesa_ProgramCallbackMESA(GLenum target, GLprogramcallbackMESA callback, |
| 292 | GLvoid *data); |
| 293 | |
| 294 | extern void |
| 295 | _mesa_GetProgramRegisterfvMESA(GLenum target, GLsizei len, |
| 296 | const GLubyte *registerName, GLfloat *v); |
| 297 | |
| 298 | |
| 299 | #endif /* PROGRAM_H */ |