Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Mesa 3-D graphics library |
Brian Paul | a23e668 | 2006-10-30 00:12:05 +0000 | [diff] [blame] | 3 | * Version: 6.5.2 |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 4 | * |
Brian Paul | 65a51c0 | 2006-05-24 03:30:31 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999-2006 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 | |
| 32 | #include "glheader.h" |
| 33 | #include "context.h" |
| 34 | #include "hash.h" |
| 35 | #include "imports.h" |
| 36 | #include "macros.h" |
| 37 | #include "mtypes.h" |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 38 | #include "nvfragparse.h" |
Brian | 0560d81 | 2006-12-14 15:01:28 -0700 | [diff] [blame] | 39 | #include "program.h" |
| 40 | #include "prog_parameter.h" |
| 41 | #include "prog_instruction.h" |
| 42 | #include "prog_statevars.h" |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 43 | #include "nvvertparse.h" |
Roland Scheidegger | f519a77 | 2005-09-02 01:11:53 +0000 | [diff] [blame] | 44 | #include "atifragshader.h" |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 45 | |
| 46 | |
Brian Paul | 7b98b40 | 2005-11-12 23:25:49 +0000 | [diff] [blame] | 47 | |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 48 | /**********************************************************************/ |
| 49 | /* Utility functions */ |
| 50 | /**********************************************************************/ |
| 51 | |
| 52 | |
Brian Paul | 765f1a1 | 2004-09-14 22:28:27 +0000 | [diff] [blame] | 53 | /* A pointer to this dummy program is put into the hash table when |
| 54 | * glGenPrograms is called. |
| 55 | */ |
Brian Paul | 122629f | 2006-07-20 16:49:57 +0000 | [diff] [blame] | 56 | struct gl_program _mesa_DummyProgram; |
Brian Paul | 765f1a1 | 2004-09-14 22:28:27 +0000 | [diff] [blame] | 57 | |
| 58 | |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 59 | /** |
Brian Paul | 21841f0 | 2004-08-14 14:28:11 +0000 | [diff] [blame] | 60 | * Init context's vertex/fragment program state |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 61 | */ |
| 62 | void |
| 63 | _mesa_init_program(GLcontext *ctx) |
| 64 | { |
| 65 | GLuint i; |
| 66 | |
| 67 | ctx->Program.ErrorPos = -1; |
| 68 | ctx->Program.ErrorString = _mesa_strdup(""); |
| 69 | |
| 70 | #if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program |
| 71 | ctx->VertexProgram.Enabled = GL_FALSE; |
| 72 | ctx->VertexProgram.PointSizeEnabled = GL_FALSE; |
| 73 | ctx->VertexProgram.TwoSideEnabled = GL_FALSE; |
Brian Paul | 122629f | 2006-07-20 16:49:57 +0000 | [diff] [blame] | 74 | ctx->VertexProgram.Current = (struct gl_vertex_program *) ctx->Shared->DefaultVertexProgram; |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 75 | assert(ctx->VertexProgram.Current); |
| 76 | ctx->VertexProgram.Current->Base.RefCount++; |
| 77 | for (i = 0; i < MAX_NV_VERTEX_PROGRAM_PARAMS / 4; i++) { |
| 78 | ctx->VertexProgram.TrackMatrix[i] = GL_NONE; |
| 79 | ctx->VertexProgram.TrackMatrixTransform[i] = GL_IDENTITY_NV; |
| 80 | } |
| 81 | #endif |
| 82 | |
| 83 | #if FEATURE_NV_fragment_program || FEATURE_ARB_fragment_program |
| 84 | ctx->FragmentProgram.Enabled = GL_FALSE; |
Brian Paul | 122629f | 2006-07-20 16:49:57 +0000 | [diff] [blame] | 85 | ctx->FragmentProgram.Current = (struct gl_fragment_program *) ctx->Shared->DefaultFragmentProgram; |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 86 | assert(ctx->FragmentProgram.Current); |
| 87 | ctx->FragmentProgram.Current->Base.RefCount++; |
| 88 | #endif |
Dave Airlie | 7f752fe | 2004-12-19 03:06:59 +0000 | [diff] [blame] | 89 | |
Brian Paul | 63d6830 | 2005-11-19 16:43:04 +0000 | [diff] [blame] | 90 | /* XXX probably move this stuff */ |
Dave Airlie | 7f752fe | 2004-12-19 03:06:59 +0000 | [diff] [blame] | 91 | #if FEATURE_ATI_fragment_shader |
| 92 | ctx->ATIFragmentShader.Enabled = GL_FALSE; |
| 93 | ctx->ATIFragmentShader.Current = (struct ati_fragment_shader *) ctx->Shared->DefaultFragmentShader; |
| 94 | assert(ctx->ATIFragmentShader.Current); |
Brian Paul | 63d6830 | 2005-11-19 16:43:04 +0000 | [diff] [blame] | 95 | ctx->ATIFragmentShader.Current->RefCount++; |
Dave Airlie | 7f752fe | 2004-12-19 03:06:59 +0000 | [diff] [blame] | 96 | #endif |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | |
| 100 | /** |
Brian Paul | 21841f0 | 2004-08-14 14:28:11 +0000 | [diff] [blame] | 101 | * Free a context's vertex/fragment program state |
| 102 | */ |
| 103 | void |
| 104 | _mesa_free_program_data(GLcontext *ctx) |
| 105 | { |
Roland Scheidegger | 93da673 | 2006-03-01 23:11:14 +0000 | [diff] [blame] | 106 | #if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program |
Brian Paul | 21841f0 | 2004-08-14 14:28:11 +0000 | [diff] [blame] | 107 | if (ctx->VertexProgram.Current) { |
| 108 | ctx->VertexProgram.Current->Base.RefCount--; |
| 109 | if (ctx->VertexProgram.Current->Base.RefCount <= 0) |
| 110 | ctx->Driver.DeleteProgram(ctx, &(ctx->VertexProgram.Current->Base)); |
| 111 | } |
| 112 | #endif |
Roland Scheidegger | 93da673 | 2006-03-01 23:11:14 +0000 | [diff] [blame] | 113 | #if FEATURE_NV_fragment_program || FEATURE_ARB_fragment_program |
Brian Paul | 21841f0 | 2004-08-14 14:28:11 +0000 | [diff] [blame] | 114 | if (ctx->FragmentProgram.Current) { |
| 115 | ctx->FragmentProgram.Current->Base.RefCount--; |
| 116 | if (ctx->FragmentProgram.Current->Base.RefCount <= 0) |
| 117 | ctx->Driver.DeleteProgram(ctx, &(ctx->FragmentProgram.Current->Base)); |
| 118 | } |
| 119 | #endif |
Brian Paul | 63d6830 | 2005-11-19 16:43:04 +0000 | [diff] [blame] | 120 | /* XXX probably move this stuff */ |
Dave Airlie | 7f752fe | 2004-12-19 03:06:59 +0000 | [diff] [blame] | 121 | #if FEATURE_ATI_fragment_shader |
| 122 | if (ctx->ATIFragmentShader.Current) { |
Brian Paul | 63d6830 | 2005-11-19 16:43:04 +0000 | [diff] [blame] | 123 | ctx->ATIFragmentShader.Current->RefCount--; |
| 124 | if (ctx->ATIFragmentShader.Current->RefCount <= 0) { |
| 125 | _mesa_free(ctx->ATIFragmentShader.Current); |
| 126 | } |
Dave Airlie | 7f752fe | 2004-12-19 03:06:59 +0000 | [diff] [blame] | 127 | } |
| 128 | #endif |
Brian Paul | 21841f0 | 2004-08-14 14:28:11 +0000 | [diff] [blame] | 129 | _mesa_free((void *) ctx->Program.ErrorString); |
| 130 | } |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | /** |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 136 | * Set the vertex/fragment program error state (position and error string). |
| 137 | * This is generally called from within the parsers. |
| 138 | */ |
| 139 | void |
| 140 | _mesa_set_program_error(GLcontext *ctx, GLint pos, const char *string) |
| 141 | { |
| 142 | ctx->Program.ErrorPos = pos; |
| 143 | _mesa_free((void *) ctx->Program.ErrorString); |
| 144 | if (!string) |
| 145 | string = ""; |
| 146 | ctx->Program.ErrorString = _mesa_strdup(string); |
| 147 | } |
| 148 | |
| 149 | |
| 150 | /** |
| 151 | * Find the line number and column for 'pos' within 'string'. |
| 152 | * Return a copy of the line which contains 'pos'. Free the line with |
| 153 | * _mesa_free(). |
| 154 | * \param string the program string |
| 155 | * \param pos the position within the string |
| 156 | * \param line returns the line number corresponding to 'pos'. |
| 157 | * \param col returns the column number corresponding to 'pos'. |
| 158 | * \return copy of the line containing 'pos'. |
| 159 | */ |
| 160 | const GLubyte * |
| 161 | _mesa_find_line_column(const GLubyte *string, const GLubyte *pos, |
| 162 | GLint *line, GLint *col) |
| 163 | { |
| 164 | const GLubyte *lineStart = string; |
| 165 | const GLubyte *p = string; |
| 166 | GLubyte *s; |
| 167 | int len; |
| 168 | |
| 169 | *line = 1; |
| 170 | |
| 171 | while (p != pos) { |
| 172 | if (*p == (GLubyte) '\n') { |
| 173 | (*line)++; |
| 174 | lineStart = p + 1; |
| 175 | } |
| 176 | p++; |
| 177 | } |
| 178 | |
| 179 | *col = (pos - lineStart) + 1; |
| 180 | |
| 181 | /* return copy of this line */ |
| 182 | while (*p != 0 && *p != '\n') |
| 183 | p++; |
| 184 | len = p - lineStart; |
| 185 | s = (GLubyte *) _mesa_malloc(len + 1); |
| 186 | _mesa_memcpy(s, lineStart, len); |
| 187 | s[len] = 0; |
| 188 | |
| 189 | return s; |
| 190 | } |
| 191 | |
| 192 | |
Brian Paul | 765f1a1 | 2004-09-14 22:28:27 +0000 | [diff] [blame] | 193 | /** |
| 194 | * Initialize a new vertex/fragment program object. |
| 195 | */ |
Brian Paul | 122629f | 2006-07-20 16:49:57 +0000 | [diff] [blame] | 196 | static struct gl_program * |
| 197 | _mesa_init_program_struct( GLcontext *ctx, struct gl_program *prog, |
Brian Paul | 765f1a1 | 2004-09-14 22:28:27 +0000 | [diff] [blame] | 198 | GLenum target, GLuint id) |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 199 | { |
Brian Paul | a6c423d | 2004-08-25 15:59:48 +0000 | [diff] [blame] | 200 | (void) ctx; |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 201 | if (prog) { |
Brian | fe1d01c | 2006-12-13 14:54:47 -0700 | [diff] [blame] | 202 | _mesa_bzero(prog, sizeof(*prog)); |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 203 | prog->Id = id; |
| 204 | prog->Target = target; |
| 205 | prog->Resident = GL_TRUE; |
| 206 | prog->RefCount = 1; |
Brian Paul | 308b85f | 2006-11-23 15:58:30 +0000 | [diff] [blame] | 207 | prog->Format = GL_PROGRAM_FORMAT_ASCII_ARB; |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | return prog; |
| 211 | } |
| 212 | |
Brian Paul | 765f1a1 | 2004-09-14 22:28:27 +0000 | [diff] [blame] | 213 | |
| 214 | /** |
| 215 | * Initialize a new fragment program object. |
| 216 | */ |
Brian Paul | 122629f | 2006-07-20 16:49:57 +0000 | [diff] [blame] | 217 | struct gl_program * |
| 218 | _mesa_init_fragment_program( GLcontext *ctx, struct gl_fragment_program *prog, |
Brian Paul | 765f1a1 | 2004-09-14 22:28:27 +0000 | [diff] [blame] | 219 | GLenum target, GLuint id) |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 220 | { |
| 221 | if (prog) |
| 222 | return _mesa_init_program_struct( ctx, &prog->Base, target, id ); |
| 223 | else |
| 224 | return NULL; |
| 225 | } |
| 226 | |
Brian Paul | 765f1a1 | 2004-09-14 22:28:27 +0000 | [diff] [blame] | 227 | |
| 228 | /** |
| 229 | * Initialize a new vertex program object. |
| 230 | */ |
Brian Paul | 122629f | 2006-07-20 16:49:57 +0000 | [diff] [blame] | 231 | struct gl_program * |
| 232 | _mesa_init_vertex_program( GLcontext *ctx, struct gl_vertex_program *prog, |
Brian Paul | 765f1a1 | 2004-09-14 22:28:27 +0000 | [diff] [blame] | 233 | GLenum target, GLuint id) |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 234 | { |
| 235 | if (prog) |
| 236 | return _mesa_init_program_struct( ctx, &prog->Base, target, id ); |
| 237 | else |
| 238 | return NULL; |
| 239 | } |
| 240 | |
| 241 | |
| 242 | /** |
| 243 | * Allocate and initialize a new fragment/vertex program object but |
| 244 | * don't put it into the program hash table. Called via |
| 245 | * ctx->Driver.NewProgram. May be overridden (ie. replaced) by a |
| 246 | * device driver function to implement OO deriviation with additional |
| 247 | * types not understood by this function. |
| 248 | * |
| 249 | * \param ctx context |
| 250 | * \param id program id/number |
| 251 | * \param target program target/type |
| 252 | * \return pointer to new program object |
| 253 | */ |
Brian Paul | 122629f | 2006-07-20 16:49:57 +0000 | [diff] [blame] | 254 | struct gl_program * |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 255 | _mesa_new_program(GLcontext *ctx, GLenum target, GLuint id) |
| 256 | { |
| 257 | switch (target) { |
| 258 | case GL_VERTEX_PROGRAM_ARB: /* == GL_VERTEX_PROGRAM_NV */ |
Brian Paul | 122629f | 2006-07-20 16:49:57 +0000 | [diff] [blame] | 259 | return _mesa_init_vertex_program(ctx, CALLOC_STRUCT(gl_vertex_program), |
| 260 | target, id ); |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 261 | case GL_FRAGMENT_PROGRAM_NV: |
| 262 | case GL_FRAGMENT_PROGRAM_ARB: |
Brian Paul | 122629f | 2006-07-20 16:49:57 +0000 | [diff] [blame] | 263 | return _mesa_init_fragment_program(ctx, |
| 264 | CALLOC_STRUCT(gl_fragment_program), |
| 265 | target, id ); |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 266 | default: |
| 267 | _mesa_problem(ctx, "bad target in _mesa_new_program"); |
| 268 | return NULL; |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | |
| 273 | /** |
| 274 | * Delete a program and remove it from the hash table, ignoring the |
| 275 | * reference count. |
| 276 | * Called via ctx->Driver.DeleteProgram. May be wrapped (OO deriviation) |
| 277 | * by a device driver function. |
| 278 | */ |
| 279 | void |
Brian Paul | 122629f | 2006-07-20 16:49:57 +0000 | [diff] [blame] | 280 | _mesa_delete_program(GLcontext *ctx, struct gl_program *prog) |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 281 | { |
Brian Paul | a6c423d | 2004-08-25 15:59:48 +0000 | [diff] [blame] | 282 | (void) ctx; |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 283 | ASSERT(prog); |
| 284 | |
Brian Paul | 308b85f | 2006-11-23 15:58:30 +0000 | [diff] [blame] | 285 | if (prog == &_mesa_DummyProgram) |
| 286 | return; |
| 287 | |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 288 | if (prog->String) |
| 289 | _mesa_free(prog->String); |
Brian Paul | de99760 | 2005-11-12 17:53:14 +0000 | [diff] [blame] | 290 | |
| 291 | if (prog->Instructions) { |
| 292 | GLuint i; |
| 293 | for (i = 0; i < prog->NumInstructions; i++) { |
| 294 | if (prog->Instructions[i].Data) |
| 295 | _mesa_free(prog->Instructions[i].Data); |
Brian Paul | 575700f | 2004-12-16 03:07:18 +0000 | [diff] [blame] | 296 | } |
Brian Paul | de99760 | 2005-11-12 17:53:14 +0000 | [diff] [blame] | 297 | _mesa_free(prog->Instructions); |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 298 | } |
Brian Paul | de99760 | 2005-11-12 17:53:14 +0000 | [diff] [blame] | 299 | |
Brian Paul | 65a51c0 | 2006-05-24 03:30:31 +0000 | [diff] [blame] | 300 | if (prog->Parameters) { |
Brian Paul | de99760 | 2005-11-12 17:53:14 +0000 | [diff] [blame] | 301 | _mesa_free_parameter_list(prog->Parameters); |
Brian Paul | 65a51c0 | 2006-05-24 03:30:31 +0000 | [diff] [blame] | 302 | } |
Brian Paul | de99760 | 2005-11-12 17:53:14 +0000 | [diff] [blame] | 303 | |
Brian | fe1d01c | 2006-12-13 14:54:47 -0700 | [diff] [blame] | 304 | if (prog->Varying) { |
| 305 | _mesa_free_parameter_list(prog->Varying); |
| 306 | } |
| 307 | |
Brian Paul | 58d080b | 2006-08-25 19:46:31 +0000 | [diff] [blame] | 308 | /* XXX this is a little ugly */ |
| 309 | if (prog->Target == GL_VERTEX_PROGRAM_ARB) { |
| 310 | struct gl_vertex_program *vprog = (struct gl_vertex_program *) prog; |
| 311 | if (vprog->TnlData) |
| 312 | _mesa_free(vprog->TnlData); |
| 313 | } |
| 314 | |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 315 | _mesa_free(prog); |
| 316 | } |
| 317 | |
| 318 | |
Brian Paul | 4d12a05 | 2006-08-23 23:10:14 +0000 | [diff] [blame] | 319 | /** |
| 320 | * Return the gl_program object for a given ID. |
| 321 | * Basically just a wrapper for _mesa_HashLookup() to avoid a lot of |
| 322 | * casts elsewhere. |
| 323 | */ |
| 324 | struct gl_program * |
| 325 | _mesa_lookup_program(GLcontext *ctx, GLuint id) |
| 326 | { |
| 327 | if (id) |
| 328 | return (struct gl_program *) _mesa_HashLookup(ctx->Shared->Programs, id); |
| 329 | else |
| 330 | return NULL; |
| 331 | } |
| 332 | |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 333 | |
Brian Paul | 3b9b8de | 2006-08-24 21:57:36 +0000 | [diff] [blame] | 334 | /** |
Brian | b2a3a85 | 2006-12-14 13:56:58 -0700 | [diff] [blame] | 335 | * Return a copy of a program. |
| 336 | * XXX Problem here if the program object is actually OO-derivation |
| 337 | * made by a device driver. |
| 338 | */ |
| 339 | struct gl_program * |
| 340 | _mesa_clone_program(GLcontext *ctx, const struct gl_program *prog) |
| 341 | { |
| 342 | struct gl_program *clone; |
| 343 | |
| 344 | clone = _mesa_new_program(ctx, prog->Target, prog->Id); |
| 345 | if (!clone) |
| 346 | return NULL; |
| 347 | |
| 348 | assert(clone->Target == prog->Target); |
| 349 | clone->String = (GLubyte *) _mesa_strdup((char *) prog->String); |
| 350 | clone->RefCount = 1; |
| 351 | clone->Format = prog->Format; |
| 352 | clone->Instructions = _mesa_alloc_instructions(prog->NumInstructions); |
| 353 | if (!clone->Instructions) { |
| 354 | _mesa_delete_program(ctx, clone); |
| 355 | return NULL; |
| 356 | } |
| 357 | memcpy(clone->Instructions, prog->Instructions, |
| 358 | prog->NumInstructions * sizeof(struct prog_instruction)); |
| 359 | clone->InputsRead = prog->InputsRead; |
| 360 | clone->OutputsWritten = prog->OutputsWritten; |
Brian | c9db223 | 2007-01-04 17:22:19 -0700 | [diff] [blame^] | 361 | memcpy(clone->TexturesUsed, prog->TexturesUsed, sizeof(prog->TexturesUsed)); |
| 362 | |
Brian | 2e76f0a | 2006-12-19 09:52:07 -0700 | [diff] [blame] | 363 | if (prog->Parameters) |
| 364 | clone->Parameters = _mesa_clone_parameter_list(prog->Parameters); |
Brian | b2a3a85 | 2006-12-14 13:56:58 -0700 | [diff] [blame] | 365 | memcpy(clone->LocalParams, prog->LocalParams, sizeof(clone->LocalParams)); |
Brian | 2e76f0a | 2006-12-19 09:52:07 -0700 | [diff] [blame] | 366 | if (prog->Varying) |
| 367 | clone->Varying = _mesa_clone_parameter_list(prog->Varying); |
Brian | b2a3a85 | 2006-12-14 13:56:58 -0700 | [diff] [blame] | 368 | memcpy(clone->LocalParams, prog->LocalParams, sizeof(clone->LocalParams)); |
| 369 | clone->NumInstructions = prog->NumInstructions; |
| 370 | clone->NumTemporaries = prog->NumTemporaries; |
| 371 | clone->NumParameters = prog->NumParameters; |
| 372 | clone->NumAttributes = prog->NumAttributes; |
| 373 | clone->NumAddressRegs = prog->NumAddressRegs; |
| 374 | clone->NumNativeInstructions = prog->NumNativeInstructions; |
| 375 | clone->NumNativeTemporaries = prog->NumNativeTemporaries; |
| 376 | clone->NumNativeParameters = prog->NumNativeParameters; |
| 377 | clone->NumNativeAttributes = prog->NumNativeAttributes; |
| 378 | clone->NumNativeAddressRegs = prog->NumNativeAddressRegs; |
| 379 | |
| 380 | switch (prog->Target) { |
| 381 | case GL_VERTEX_PROGRAM_ARB: |
| 382 | { |
| 383 | const struct gl_vertex_program *vp |
| 384 | = (const struct gl_vertex_program *) prog; |
| 385 | struct gl_vertex_program *vpc = (struct gl_vertex_program *) clone; |
| 386 | vpc->IsPositionInvariant = vp->IsPositionInvariant; |
| 387 | } |
| 388 | break; |
| 389 | case GL_FRAGMENT_PROGRAM_ARB: |
| 390 | { |
| 391 | const struct gl_fragment_program *fp |
| 392 | = (const struct gl_fragment_program *) prog; |
| 393 | struct gl_fragment_program *fpc = (struct gl_fragment_program *) clone; |
Brian | b2a3a85 | 2006-12-14 13:56:58 -0700 | [diff] [blame] | 394 | fpc->NumAluInstructions = fp->NumAluInstructions; |
| 395 | fpc->NumTexInstructions = fp->NumTexInstructions; |
| 396 | fpc->NumTexIndirections = fp->NumTexIndirections; |
| 397 | fpc->NumNativeAluInstructions = fp->NumNativeAluInstructions; |
| 398 | fpc->NumNativeTexInstructions = fp->NumNativeTexInstructions; |
| 399 | fpc->NumNativeTexIndirections = fp->NumNativeTexIndirections; |
| 400 | fpc->FogOption = fp->FogOption; |
| 401 | fpc->UsesKill = fp->UsesKill; |
| 402 | } |
| 403 | break; |
| 404 | default: |
| 405 | _mesa_problem(NULL, "Unexpected target in _mesa_clone_program"); |
| 406 | } |
| 407 | |
| 408 | return clone; |
| 409 | } |
| 410 | |
| 411 | |
| 412 | |
| 413 | /** |
Brian Paul | 77427a1 | 2006-08-24 23:11:39 +0000 | [diff] [blame] | 414 | * Mixing ARB and NV vertex/fragment programs can be tricky. |
| 415 | * Note: GL_VERTEX_PROGRAM_ARB == GL_VERTEX_PROGRAM_NV |
| 416 | * but, GL_FRAGMENT_PROGRAM_ARB != GL_FRAGMENT_PROGRAM_NV |
| 417 | * The two different fragment program targets are supposed to be compatible |
| 418 | * to some extent (see GL_ARB_fragment_program spec). |
| 419 | * This function does the compatibility check. |
| 420 | */ |
| 421 | static GLboolean |
| 422 | compatible_program_targets(GLenum t1, GLenum t2) |
| 423 | { |
| 424 | if (t1 == t2) |
| 425 | return GL_TRUE; |
| 426 | if (t1 == GL_FRAGMENT_PROGRAM_ARB && t2 == GL_FRAGMENT_PROGRAM_NV) |
| 427 | return GL_TRUE; |
| 428 | if (t1 == GL_FRAGMENT_PROGRAM_NV && t2 == GL_FRAGMENT_PROGRAM_ARB) |
| 429 | return GL_TRUE; |
| 430 | return GL_FALSE; |
| 431 | } |
| 432 | |
| 433 | |
Brian Paul | 30d6a4b | 2005-11-05 20:18:18 +0000 | [diff] [blame] | 434 | |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 435 | /**********************************************************************/ |
| 436 | /* API functions */ |
| 437 | /**********************************************************************/ |
| 438 | |
| 439 | |
| 440 | /** |
| 441 | * Bind a program (make it current) |
| 442 | * \note Called from the GL API dispatcher by both glBindProgramNV |
| 443 | * and glBindProgramARB. |
| 444 | */ |
| 445 | void GLAPIENTRY |
| 446 | _mesa_BindProgram(GLenum target, GLuint id) |
| 447 | { |
Brian Paul | a360bc3 | 2006-08-25 17:18:56 +0000 | [diff] [blame] | 448 | struct gl_program *curProg, *newProg; |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 449 | GET_CURRENT_CONTEXT(ctx); |
| 450 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 451 | |
| 452 | FLUSH_VERTICES(ctx, _NEW_PROGRAM); |
| 453 | |
Brian Paul | a360bc3 | 2006-08-25 17:18:56 +0000 | [diff] [blame] | 454 | /* Error-check target and get curProg */ |
Roland Scheidegger | e1e03b3 | 2006-03-03 15:03:04 +0000 | [diff] [blame] | 455 | if ((target == GL_VERTEX_PROGRAM_ARB) && /* == GL_VERTEX_PROGRAM_NV */ |
| 456 | (ctx->Extensions.NV_vertex_program || |
| 457 | ctx->Extensions.ARB_vertex_program)) { |
Brian Paul | a360bc3 | 2006-08-25 17:18:56 +0000 | [diff] [blame] | 458 | curProg = &ctx->VertexProgram.Current->Base; |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 459 | } |
| 460 | else if ((target == GL_FRAGMENT_PROGRAM_NV |
| 461 | && ctx->Extensions.NV_fragment_program) || |
| 462 | (target == GL_FRAGMENT_PROGRAM_ARB |
| 463 | && ctx->Extensions.ARB_fragment_program)) { |
Brian Paul | a360bc3 | 2006-08-25 17:18:56 +0000 | [diff] [blame] | 464 | curProg = &ctx->FragmentProgram.Current->Base; |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 465 | } |
| 466 | else { |
| 467 | _mesa_error(ctx, GL_INVALID_ENUM, "glBindProgramNV/ARB(target)"); |
| 468 | return; |
| 469 | } |
| 470 | |
Brian Paul | a360bc3 | 2006-08-25 17:18:56 +0000 | [diff] [blame] | 471 | /* |
| 472 | * Get pointer to new program to bind. |
| 473 | * NOTE: binding to a non-existant program is not an error. |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 474 | * That's supposed to be caught in glBegin. |
| 475 | */ |
| 476 | if (id == 0) { |
Brian Paul | a360bc3 | 2006-08-25 17:18:56 +0000 | [diff] [blame] | 477 | /* Bind a default program */ |
| 478 | newProg = NULL; |
Roland Scheidegger | e1e03b3 | 2006-03-03 15:03:04 +0000 | [diff] [blame] | 479 | if (target == GL_VERTEX_PROGRAM_ARB) /* == GL_VERTEX_PROGRAM_NV */ |
Brian Paul | a360bc3 | 2006-08-25 17:18:56 +0000 | [diff] [blame] | 480 | newProg = ctx->Shared->DefaultVertexProgram; |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 481 | else |
Brian Paul | a360bc3 | 2006-08-25 17:18:56 +0000 | [diff] [blame] | 482 | newProg = ctx->Shared->DefaultFragmentProgram; |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 483 | } |
| 484 | else { |
Brian Paul | a360bc3 | 2006-08-25 17:18:56 +0000 | [diff] [blame] | 485 | /* Bind a user program */ |
| 486 | newProg = _mesa_lookup_program(ctx, id); |
| 487 | if (!newProg || newProg == &_mesa_DummyProgram) { |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 488 | /* allocate a new program now */ |
Brian Paul | a360bc3 | 2006-08-25 17:18:56 +0000 | [diff] [blame] | 489 | newProg = ctx->Driver.NewProgram(ctx, target, id); |
| 490 | if (!newProg) { |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 491 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindProgramNV/ARB"); |
| 492 | return; |
| 493 | } |
Brian Paul | a360bc3 | 2006-08-25 17:18:56 +0000 | [diff] [blame] | 494 | _mesa_HashInsert(ctx->Shared->Programs, id, newProg); |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 495 | } |
Brian Paul | a360bc3 | 2006-08-25 17:18:56 +0000 | [diff] [blame] | 496 | else if (!compatible_program_targets(newProg->Target, target)) { |
Brian Paul | 765f1a1 | 2004-09-14 22:28:27 +0000 | [diff] [blame] | 497 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 498 | "glBindProgramNV/ARB(target mismatch)"); |
| 499 | return; |
| 500 | } |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Brian Paul | a360bc3 | 2006-08-25 17:18:56 +0000 | [diff] [blame] | 503 | /** All error checking is complete now **/ |
| 504 | |
| 505 | if (curProg->Id == id) { |
| 506 | /* binding same program - no change */ |
| 507 | return; |
| 508 | } |
| 509 | |
| 510 | /* unbind/delete oldProg */ |
| 511 | if (curProg->Id != 0) { |
| 512 | /* decrement refcount on previously bound fragment program */ |
| 513 | curProg->RefCount--; |
| 514 | /* and delete if refcount goes below one */ |
| 515 | if (curProg->RefCount <= 0) { |
| 516 | /* the program ID was already removed from the hash table */ |
| 517 | ctx->Driver.DeleteProgram(ctx, curProg); |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | /* bind newProg */ |
Roland Scheidegger | e1e03b3 | 2006-03-03 15:03:04 +0000 | [diff] [blame] | 522 | if (target == GL_VERTEX_PROGRAM_ARB) { /* == GL_VERTEX_PROGRAM_NV */ |
Brian Paul | a360bc3 | 2006-08-25 17:18:56 +0000 | [diff] [blame] | 523 | ctx->VertexProgram.Current = (struct gl_vertex_program *) newProg; |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 524 | } |
Brian Paul | a360bc3 | 2006-08-25 17:18:56 +0000 | [diff] [blame] | 525 | else if (target == GL_FRAGMENT_PROGRAM_NV || |
| 526 | target == GL_FRAGMENT_PROGRAM_ARB) { |
| 527 | ctx->FragmentProgram.Current = (struct gl_fragment_program *) newProg; |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 528 | } |
Brian Paul | a360bc3 | 2006-08-25 17:18:56 +0000 | [diff] [blame] | 529 | newProg->RefCount++; |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 530 | |
Brian Paul | 765f1a1 | 2004-09-14 22:28:27 +0000 | [diff] [blame] | 531 | /* Never null pointers */ |
| 532 | ASSERT(ctx->VertexProgram.Current); |
| 533 | ASSERT(ctx->FragmentProgram.Current); |
| 534 | |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 535 | if (ctx->Driver.BindProgram) |
Brian Paul | a360bc3 | 2006-08-25 17:18:56 +0000 | [diff] [blame] | 536 | ctx->Driver.BindProgram(ctx, target, newProg); |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | |
| 540 | /** |
| 541 | * Delete a list of programs. |
| 542 | * \note Not compiled into display lists. |
| 543 | * \note Called by both glDeleteProgramsNV and glDeleteProgramsARB. |
| 544 | */ |
| 545 | void GLAPIENTRY |
| 546 | _mesa_DeletePrograms(GLsizei n, const GLuint *ids) |
| 547 | { |
| 548 | GLint i; |
| 549 | GET_CURRENT_CONTEXT(ctx); |
| 550 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
| 551 | |
| 552 | if (n < 0) { |
| 553 | _mesa_error( ctx, GL_INVALID_VALUE, "glDeleteProgramsNV" ); |
| 554 | return; |
| 555 | } |
| 556 | |
| 557 | for (i = 0; i < n; i++) { |
| 558 | if (ids[i] != 0) { |
Brian Paul | 4d12a05 | 2006-08-23 23:10:14 +0000 | [diff] [blame] | 559 | struct gl_program *prog = _mesa_lookup_program(ctx, ids[i]); |
Brian Paul | 9ca8392 | 2004-10-02 15:16:59 +0000 | [diff] [blame] | 560 | if (prog == &_mesa_DummyProgram) { |
Brian Paul | 765f1a1 | 2004-09-14 22:28:27 +0000 | [diff] [blame] | 561 | _mesa_HashRemove(ctx->Shared->Programs, ids[i]); |
| 562 | } |
| 563 | else if (prog) { |
| 564 | /* Unbind program if necessary */ |
Roland Scheidegger | e1e03b3 | 2006-03-03 15:03:04 +0000 | [diff] [blame] | 565 | if (prog->Target == GL_VERTEX_PROGRAM_ARB || /* == GL_VERTEX_PROGRAM_NV */ |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 566 | prog->Target == GL_VERTEX_STATE_PROGRAM_NV) { |
| 567 | if (ctx->VertexProgram.Current && |
| 568 | ctx->VertexProgram.Current->Base.Id == ids[i]) { |
| 569 | /* unbind this currently bound program */ |
| 570 | _mesa_BindProgram(prog->Target, 0); |
| 571 | } |
| 572 | } |
| 573 | else if (prog->Target == GL_FRAGMENT_PROGRAM_NV || |
| 574 | prog->Target == GL_FRAGMENT_PROGRAM_ARB) { |
| 575 | if (ctx->FragmentProgram.Current && |
| 576 | ctx->FragmentProgram.Current->Base.Id == ids[i]) { |
| 577 | /* unbind this currently bound program */ |
| 578 | _mesa_BindProgram(prog->Target, 0); |
| 579 | } |
| 580 | } |
| 581 | else { |
| 582 | _mesa_problem(ctx, "bad target in glDeleteProgramsNV"); |
| 583 | return; |
| 584 | } |
Brian Paul | ea2943e | 2005-01-20 04:02:02 +0000 | [diff] [blame] | 585 | /* The ID is immediately available for re-use now */ |
| 586 | _mesa_HashRemove(ctx->Shared->Programs, ids[i]); |
| 587 | prog->RefCount--; |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 588 | if (prog->RefCount <= 0) { |
| 589 | ctx->Driver.DeleteProgram(ctx, prog); |
| 590 | } |
| 591 | } |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 592 | } |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | |
| 597 | /** |
| 598 | * Generate a list of new program identifiers. |
| 599 | * \note Not compiled into display lists. |
| 600 | * \note Called by both glGenProgramsNV and glGenProgramsARB. |
| 601 | */ |
| 602 | void GLAPIENTRY |
| 603 | _mesa_GenPrograms(GLsizei n, GLuint *ids) |
| 604 | { |
| 605 | GLuint first; |
| 606 | GLuint i; |
| 607 | GET_CURRENT_CONTEXT(ctx); |
| 608 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 609 | |
| 610 | if (n < 0) { |
| 611 | _mesa_error(ctx, GL_INVALID_VALUE, "glGenPrograms"); |
| 612 | return; |
| 613 | } |
| 614 | |
| 615 | if (!ids) |
| 616 | return; |
| 617 | |
| 618 | first = _mesa_HashFindFreeKeyBlock(ctx->Shared->Programs, n); |
| 619 | |
Brian Paul | 765f1a1 | 2004-09-14 22:28:27 +0000 | [diff] [blame] | 620 | /* Insert pointer to dummy program as placeholder */ |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 621 | for (i = 0; i < (GLuint) n; i++) { |
Brian Paul | 9ca8392 | 2004-10-02 15:16:59 +0000 | [diff] [blame] | 622 | _mesa_HashInsert(ctx->Shared->Programs, first + i, &_mesa_DummyProgram); |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | /* Return the program names */ |
| 626 | for (i = 0; i < (GLuint) n; i++) { |
| 627 | ids[i] = first + i; |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 632 | /**********************************************************************/ |
| 633 | /* GL_MESA_program_debug extension */ |
| 634 | /**********************************************************************/ |
| 635 | |
| 636 | |
| 637 | /* XXX temporary */ |
Daniel Borca | 0a13ceb | 2005-02-14 08:01:59 +0000 | [diff] [blame] | 638 | GLAPI void GLAPIENTRY |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 639 | glProgramCallbackMESA(GLenum target, GLprogramcallbackMESA callback, |
| 640 | GLvoid *data) |
| 641 | { |
| 642 | _mesa_ProgramCallbackMESA(target, callback, data); |
| 643 | } |
| 644 | |
| 645 | |
| 646 | void |
| 647 | _mesa_ProgramCallbackMESA(GLenum target, GLprogramcallbackMESA callback, |
| 648 | GLvoid *data) |
| 649 | { |
| 650 | GET_CURRENT_CONTEXT(ctx); |
| 651 | |
| 652 | switch (target) { |
| 653 | case GL_FRAGMENT_PROGRAM_ARB: |
| 654 | if (!ctx->Extensions.ARB_fragment_program) { |
| 655 | _mesa_error(ctx, GL_INVALID_ENUM, "glProgramCallbackMESA(target)"); |
| 656 | return; |
| 657 | } |
| 658 | ctx->FragmentProgram.Callback = callback; |
| 659 | ctx->FragmentProgram.CallbackData = data; |
| 660 | break; |
| 661 | case GL_FRAGMENT_PROGRAM_NV: |
| 662 | if (!ctx->Extensions.NV_fragment_program) { |
| 663 | _mesa_error(ctx, GL_INVALID_ENUM, "glProgramCallbackMESA(target)"); |
| 664 | return; |
| 665 | } |
| 666 | ctx->FragmentProgram.Callback = callback; |
| 667 | ctx->FragmentProgram.CallbackData = data; |
| 668 | break; |
| 669 | case GL_VERTEX_PROGRAM_ARB: /* == GL_VERTEX_PROGRAM_NV */ |
| 670 | if (!ctx->Extensions.ARB_vertex_program && |
| 671 | !ctx->Extensions.NV_vertex_program) { |
| 672 | _mesa_error(ctx, GL_INVALID_ENUM, "glProgramCallbackMESA(target)"); |
| 673 | return; |
| 674 | } |
| 675 | ctx->VertexProgram.Callback = callback; |
| 676 | ctx->VertexProgram.CallbackData = data; |
| 677 | break; |
| 678 | default: |
| 679 | _mesa_error(ctx, GL_INVALID_ENUM, "glProgramCallbackMESA(target)"); |
| 680 | return; |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | |
| 685 | /* XXX temporary */ |
Daniel Borca | 0a13ceb | 2005-02-14 08:01:59 +0000 | [diff] [blame] | 686 | GLAPI void GLAPIENTRY |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 687 | glGetProgramRegisterfvMESA(GLenum target, |
| 688 | GLsizei len, const GLubyte *registerName, |
| 689 | GLfloat *v) |
| 690 | { |
| 691 | _mesa_GetProgramRegisterfvMESA(target, len, registerName, v); |
| 692 | } |
| 693 | |
| 694 | |
| 695 | void |
| 696 | _mesa_GetProgramRegisterfvMESA(GLenum target, |
| 697 | GLsizei len, const GLubyte *registerName, |
| 698 | GLfloat *v) |
| 699 | { |
| 700 | char reg[1000]; |
| 701 | GET_CURRENT_CONTEXT(ctx); |
| 702 | |
| 703 | /* We _should_ be inside glBegin/glEnd */ |
| 704 | #if 0 |
| 705 | if (ctx->Driver.CurrentExecPrimitive == PRIM_OUTSIDE_BEGIN_END) { |
| 706 | _mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramRegisterfvMESA"); |
| 707 | return; |
| 708 | } |
| 709 | #endif |
| 710 | |
| 711 | /* make null-terminated copy of registerName */ |
| 712 | len = MIN2((unsigned int) len, sizeof(reg) - 1); |
| 713 | _mesa_memcpy(reg, registerName, len); |
| 714 | reg[len] = 0; |
| 715 | |
| 716 | switch (target) { |
Roland Scheidegger | e1e03b3 | 2006-03-03 15:03:04 +0000 | [diff] [blame] | 717 | case GL_VERTEX_PROGRAM_ARB: /* == GL_VERTEX_PROGRAM_NV */ |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 718 | if (!ctx->Extensions.ARB_vertex_program && |
| 719 | !ctx->Extensions.NV_vertex_program) { |
| 720 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 721 | "glGetProgramRegisterfvMESA(target)"); |
| 722 | return; |
| 723 | } |
Brian Paul | 6d460af | 2004-04-23 14:16:46 +0000 | [diff] [blame] | 724 | if (!ctx->VertexProgram._Enabled) { |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 725 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 726 | "glGetProgramRegisterfvMESA"); |
| 727 | return; |
| 728 | } |
| 729 | /* GL_NV_vertex_program */ |
| 730 | if (reg[0] == 'R') { |
| 731 | /* Temp register */ |
| 732 | GLint i = _mesa_atoi(reg + 1); |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 733 | if (i >= (GLint)ctx->Const.VertexProgram.MaxTemps) { |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 734 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 735 | "glGetProgramRegisterfvMESA(registerName)"); |
| 736 | return; |
| 737 | } |
Brian Paul | a23e668 | 2006-10-30 00:12:05 +0000 | [diff] [blame] | 738 | #if 0 /* FIX ME */ |
| 739 | ctx->Driver.GetVertexProgramRegister(ctx, PROGRAM_TEMPORARY, i, v); |
| 740 | #endif |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 741 | } |
| 742 | else if (reg[0] == 'v' && reg[1] == '[') { |
| 743 | /* Vertex Input attribute */ |
| 744 | GLuint i; |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 745 | for (i = 0; i < ctx->Const.VertexProgram.MaxAttribs; i++) { |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 746 | const char *name = _mesa_nv_vertex_input_register_name(i); |
| 747 | char number[10]; |
Brian Paul | aa20695 | 2005-09-16 18:14:24 +0000 | [diff] [blame] | 748 | _mesa_sprintf(number, "%d", i); |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 749 | if (_mesa_strncmp(reg + 2, name, 4) == 0 || |
| 750 | _mesa_strncmp(reg + 2, number, _mesa_strlen(number)) == 0) { |
Brian Paul | a23e668 | 2006-10-30 00:12:05 +0000 | [diff] [blame] | 751 | #if 0 /* FIX ME */ |
| 752 | ctx->Driver.GetVertexProgramRegister(ctx, PROGRAM_INPUT, |
| 753 | i, v); |
| 754 | #endif |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 755 | return; |
| 756 | } |
| 757 | } |
| 758 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 759 | "glGetProgramRegisterfvMESA(registerName)"); |
| 760 | return; |
| 761 | } |
| 762 | else if (reg[0] == 'o' && reg[1] == '[') { |
| 763 | /* Vertex output attribute */ |
| 764 | } |
| 765 | /* GL_ARB_vertex_program */ |
| 766 | else if (_mesa_strncmp(reg, "vertex.", 7) == 0) { |
| 767 | |
| 768 | } |
| 769 | else { |
| 770 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 771 | "glGetProgramRegisterfvMESA(registerName)"); |
| 772 | return; |
| 773 | } |
| 774 | break; |
| 775 | case GL_FRAGMENT_PROGRAM_ARB: |
| 776 | if (!ctx->Extensions.ARB_fragment_program) { |
| 777 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 778 | "glGetProgramRegisterfvMESA(target)"); |
| 779 | return; |
| 780 | } |
Brian Paul | 6d460af | 2004-04-23 14:16:46 +0000 | [diff] [blame] | 781 | if (!ctx->FragmentProgram._Enabled) { |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 782 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 783 | "glGetProgramRegisterfvMESA"); |
| 784 | return; |
| 785 | } |
| 786 | /* XXX to do */ |
| 787 | break; |
| 788 | case GL_FRAGMENT_PROGRAM_NV: |
| 789 | if (!ctx->Extensions.NV_fragment_program) { |
| 790 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 791 | "glGetProgramRegisterfvMESA(target)"); |
| 792 | return; |
| 793 | } |
Brian Paul | 6d460af | 2004-04-23 14:16:46 +0000 | [diff] [blame] | 794 | if (!ctx->FragmentProgram._Enabled) { |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 795 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 796 | "glGetProgramRegisterfvMESA"); |
| 797 | return; |
| 798 | } |
| 799 | if (reg[0] == 'R') { |
| 800 | /* Temp register */ |
| 801 | GLint i = _mesa_atoi(reg + 1); |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 802 | if (i >= (GLint)ctx->Const.FragmentProgram.MaxTemps) { |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 803 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 804 | "glGetProgramRegisterfvMESA(registerName)"); |
| 805 | return; |
| 806 | } |
Brian Paul | 39c4daa | 2006-10-10 21:43:31 +0000 | [diff] [blame] | 807 | ctx->Driver.GetFragmentProgramRegister(ctx, PROGRAM_TEMPORARY, |
| 808 | i, v); |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 809 | } |
| 810 | else if (reg[0] == 'f' && reg[1] == '[') { |
| 811 | /* Fragment input attribute */ |
| 812 | GLuint i; |
Brian Paul | 0505103 | 2005-11-01 04:36:33 +0000 | [diff] [blame] | 813 | for (i = 0; i < ctx->Const.FragmentProgram.MaxAttribs; i++) { |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 814 | const char *name = _mesa_nv_fragment_input_register_name(i); |
| 815 | if (_mesa_strncmp(reg + 2, name, 4) == 0) { |
Brian Paul | 39c4daa | 2006-10-10 21:43:31 +0000 | [diff] [blame] | 816 | ctx->Driver.GetFragmentProgramRegister(ctx, |
| 817 | PROGRAM_INPUT, i, v); |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 818 | return; |
| 819 | } |
| 820 | } |
| 821 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 822 | "glGetProgramRegisterfvMESA(registerName)"); |
| 823 | return; |
| 824 | } |
| 825 | else if (_mesa_strcmp(reg, "o[COLR]") == 0) { |
| 826 | /* Fragment output color */ |
Brian Paul | 39c4daa | 2006-10-10 21:43:31 +0000 | [diff] [blame] | 827 | ctx->Driver.GetFragmentProgramRegister(ctx, PROGRAM_OUTPUT, |
| 828 | FRAG_RESULT_COLR, v); |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 829 | } |
| 830 | else if (_mesa_strcmp(reg, "o[COLH]") == 0) { |
| 831 | /* Fragment output color */ |
Brian Paul | 39c4daa | 2006-10-10 21:43:31 +0000 | [diff] [blame] | 832 | ctx->Driver.GetFragmentProgramRegister(ctx, PROGRAM_OUTPUT, |
| 833 | FRAG_RESULT_COLH, v); |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 834 | } |
| 835 | else if (_mesa_strcmp(reg, "o[DEPR]") == 0) { |
| 836 | /* Fragment output depth */ |
Brian Paul | 39c4daa | 2006-10-10 21:43:31 +0000 | [diff] [blame] | 837 | ctx->Driver.GetFragmentProgramRegister(ctx, PROGRAM_OUTPUT, |
| 838 | FRAG_RESULT_DEPR, v); |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 839 | } |
| 840 | else { |
| 841 | /* try user-defined identifiers */ |
| 842 | const GLfloat *value = _mesa_lookup_parameter_value( |
Brian Paul | de99760 | 2005-11-12 17:53:14 +0000 | [diff] [blame] | 843 | ctx->FragmentProgram.Current->Base.Parameters, -1, reg); |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 844 | if (value) { |
| 845 | COPY_4V(v, value); |
| 846 | } |
| 847 | else { |
| 848 | _mesa_error(ctx, GL_INVALID_VALUE, |
| 849 | "glGetProgramRegisterfvMESA(registerName)"); |
| 850 | return; |
| 851 | } |
| 852 | } |
| 853 | break; |
| 854 | default: |
| 855 | _mesa_error(ctx, GL_INVALID_ENUM, |
| 856 | "glGetProgramRegisterfvMESA(target)"); |
| 857 | return; |
| 858 | } |
Michal Krol | 2861e73 | 2004-03-29 11:09:34 +0000 | [diff] [blame] | 859 | } |