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