blob: 409c61cdc114e5bbe078c6d5c82bdaffea723d15 [file] [log] [blame]
Michal Krol2861e732004-03-29 11:09:34 +00001/*
2 * Mesa 3-D graphics library
Brian Paulebcedd22006-10-29 18:33:14 +00003 * Version: 6.5.2
Michal Krol2861e732004-03-29 11:09:34 +00004 *
Brian Paul8a979462006-04-20 15:06:40 +00005 * Copyright (C) 1999-2006 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 nvprogram.c
27 * NVIDIA vertex/fragment program state management functions.
28 * \author Brian Paul
29 */
30
31/*
32 * Regarding GL_NV_fragment/vertex_program, GL_NV_vertex_program1_1, etc:
33 *
34 * Portions of this software may use or implement intellectual
35 * property owned and licensed by NVIDIA Corporation. NVIDIA disclaims
36 * any and all warranties with respect to such intellectual property,
37 * including any use thereof or modifications thereto.
38 */
39
40#include "glheader.h"
41#include "context.h"
42#include "hash.h"
43#include "imports.h"
44#include "macros.h"
Brian57d95312006-12-14 15:03:04 -070045#include "prog_parameter.h"
46#include "prog_instruction.h"
Brian62324382006-12-14 15:54:01 -070047#include "nvfragparse.h"
Michal Krol2861e732004-03-29 11:09:34 +000048#include "nvvertparse.h"
Michal Krol2861e732004-03-29 11:09:34 +000049#include "nvprogram.h"
50#include "program.h"
51
52
53
54/**
55 * Execute a vertex state program.
56 * \note Called from the GL API dispatcher.
57 */
58void GLAPIENTRY
59_mesa_ExecuteProgramNV(GLenum target, GLuint id, const GLfloat *params)
60{
Brian Paul122629f2006-07-20 16:49:57 +000061 struct gl_vertex_program *vprog;
Michal Krol2861e732004-03-29 11:09:34 +000062 GET_CURRENT_CONTEXT(ctx);
63 ASSERT_OUTSIDE_BEGIN_END(ctx);
64
65 if (target != GL_VERTEX_STATE_PROGRAM_NV) {
66 _mesa_error(ctx, GL_INVALID_ENUM, "glExecuteProgramNV");
67 return;
68 }
69
70 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
71
Brian Paul4d12a052006-08-23 23:10:14 +000072 vprog = (struct gl_vertex_program *) _mesa_lookup_program(ctx, id);
Michal Krol2861e732004-03-29 11:09:34 +000073
74 if (!vprog || vprog->Base.Target != GL_VERTEX_STATE_PROGRAM_NV) {
75 _mesa_error(ctx, GL_INVALID_OPERATION, "glExecuteProgramNV");
76 return;
77 }
78
Brian740a8b02007-02-22 16:00:54 -070079 _mesa_problem(ctx, "glExecuteProgramNV() not supported");
Michal Krol2861e732004-03-29 11:09:34 +000080}
81
82
83/**
84 * Determine if a set of programs is resident in hardware.
85 * \note Not compiled into display lists.
86 * \note Called from the GL API dispatcher.
87 */
Brian Paul81968ec2006-10-10 22:45:50 +000088GLboolean GLAPIENTRY
89_mesa_AreProgramsResidentNV(GLsizei n, const GLuint *ids,
90 GLboolean *residences)
Michal Krol2861e732004-03-29 11:09:34 +000091{
92 GLint i, j;
93 GLboolean allResident = GL_TRUE;
94 GET_CURRENT_CONTEXT(ctx);
95 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
96
97 if (n < 0) {
98 _mesa_error(ctx, GL_INVALID_VALUE, "glAreProgramsResidentNV(n)");
99 return GL_FALSE;
100 }
101
102 for (i = 0; i < n; i++) {
Brian Paul122629f2006-07-20 16:49:57 +0000103 const struct gl_program *prog;
Michal Krol2861e732004-03-29 11:09:34 +0000104 if (ids[i] == 0) {
105 _mesa_error(ctx, GL_INVALID_VALUE, "glAreProgramsResidentNV");
106 return GL_FALSE;
107 }
Brian Paul4d12a052006-08-23 23:10:14 +0000108 prog = _mesa_lookup_program(ctx, ids[i]);
Michal Krol2861e732004-03-29 11:09:34 +0000109 if (!prog) {
110 _mesa_error(ctx, GL_INVALID_VALUE, "glAreProgramsResidentNV");
111 return GL_FALSE;
112 }
113 if (prog->Resident) {
114 if (!allResident)
115 residences[i] = GL_TRUE;
116 }
117 else {
118 if (allResident) {
119 allResident = GL_FALSE;
120 for (j = 0; j < i; j++)
121 residences[j] = GL_TRUE;
122 }
123 residences[i] = GL_FALSE;
124 }
125 }
126
127 return allResident;
128}
129
130
131/**
132 * Request that a set of programs be resident in hardware.
133 * \note Called from the GL API dispatcher.
134 */
135void GLAPIENTRY
136_mesa_RequestResidentProgramsNV(GLsizei n, const GLuint *ids)
137{
138 GLint i;
139 GET_CURRENT_CONTEXT(ctx);
140 ASSERT_OUTSIDE_BEGIN_END(ctx);
141
142 if (n < 0) {
143 _mesa_error(ctx, GL_INVALID_VALUE, "glRequestResidentProgramsNV(n)");
144 return;
145 }
146
147 /* just error checking for now */
148 for (i = 0; i < n; i++) {
Brian Paul122629f2006-07-20 16:49:57 +0000149 struct gl_program *prog;
Michal Krol2861e732004-03-29 11:09:34 +0000150
151 if (ids[i] == 0) {
152 _mesa_error(ctx, GL_INVALID_VALUE, "glRequestResidentProgramsNV(id)");
153 return;
154 }
155
Brian Paul4d12a052006-08-23 23:10:14 +0000156 prog = _mesa_lookup_program(ctx, ids[i]);
Michal Krol2861e732004-03-29 11:09:34 +0000157 if (!prog) {
158 _mesa_error(ctx, GL_INVALID_VALUE, "glRequestResidentProgramsNV(id)");
159 return;
160 }
161
Brian Paul9ca83922004-10-02 15:16:59 +0000162 /* XXX this is really a hardware thing we should hook out */
Michal Krol2861e732004-03-29 11:09:34 +0000163 prog->Resident = GL_TRUE;
164 }
165}
166
167
168/**
169 * Get a program parameter register.
170 * \note Not compiled into display lists.
171 * \note Called from the GL API dispatcher.
172 */
173void GLAPIENTRY
174_mesa_GetProgramParameterfvNV(GLenum target, GLuint index,
175 GLenum pname, GLfloat *params)
176{
177 GET_CURRENT_CONTEXT(ctx);
178 ASSERT_OUTSIDE_BEGIN_END(ctx);
179
180 if (target == GL_VERTEX_PROGRAM_NV) {
181 if (pname == GL_PROGRAM_PARAMETER_NV) {
182 if (index < MAX_NV_VERTEX_PROGRAM_PARAMS) {
183 COPY_4V(params, ctx->VertexProgram.Parameters[index]);
184 }
185 else {
186 _mesa_error(ctx, GL_INVALID_VALUE,
187 "glGetProgramParameterfvNV(index)");
188 return;
189 }
190 }
191 else {
192 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramParameterfvNV(pname)");
193 return;
194 }
195 }
196 else {
197 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramParameterfvNV(target)");
198 return;
199 }
200}
201
202
203/**
204 * Get a program parameter register.
205 * \note Not compiled into display lists.
206 * \note Called from the GL API dispatcher.
207 */
208void GLAPIENTRY
209_mesa_GetProgramParameterdvNV(GLenum target, GLuint index,
210 GLenum pname, GLdouble *params)
211{
212 GET_CURRENT_CONTEXT(ctx);
213 ASSERT_OUTSIDE_BEGIN_END(ctx);
214
215 if (target == GL_VERTEX_PROGRAM_NV) {
216 if (pname == GL_PROGRAM_PARAMETER_NV) {
217 if (index < MAX_NV_VERTEX_PROGRAM_PARAMS) {
218 COPY_4V(params, ctx->VertexProgram.Parameters[index]);
219 }
220 else {
221 _mesa_error(ctx, GL_INVALID_VALUE,
222 "glGetProgramParameterdvNV(index)");
223 return;
224 }
225 }
226 else {
227 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramParameterdvNV(pname)");
228 return;
229 }
230 }
231 else {
232 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramParameterdvNV(target)");
233 return;
234 }
235}
236
237
238/**
239 * Get a program attribute.
240 * \note Not compiled into display lists.
241 * \note Called from the GL API dispatcher.
242 */
243void GLAPIENTRY
244_mesa_GetProgramivNV(GLuint id, GLenum pname, GLint *params)
245{
Brian Paul122629f2006-07-20 16:49:57 +0000246 struct gl_program *prog;
Michal Krol2861e732004-03-29 11:09:34 +0000247 GET_CURRENT_CONTEXT(ctx);
248
249 if (!ctx->_CurrentProgram)
250 ASSERT_OUTSIDE_BEGIN_END(ctx);
251
Brian Paul4d12a052006-08-23 23:10:14 +0000252 prog = _mesa_lookup_program(ctx, id);
Michal Krol2861e732004-03-29 11:09:34 +0000253 if (!prog) {
254 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramivNV");
255 return;
256 }
257
258 switch (pname) {
259 case GL_PROGRAM_TARGET_NV:
260 *params = prog->Target;
261 return;
262 case GL_PROGRAM_LENGTH_NV:
Karl Schultz6258b762005-05-05 21:08:07 +0000263 *params = prog->String ?(GLint)_mesa_strlen((char *) prog->String) : 0;
Michal Krol2861e732004-03-29 11:09:34 +0000264 return;
265 case GL_PROGRAM_RESIDENT_NV:
266 *params = prog->Resident;
267 return;
268 default:
269 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivNV(pname)");
270 return;
271 }
272}
273
274
275/**
276 * Get the program source code.
277 * \note Not compiled into display lists.
278 * \note Called from the GL API dispatcher.
279 */
280void GLAPIENTRY
281_mesa_GetProgramStringNV(GLuint id, GLenum pname, GLubyte *program)
282{
Brian Paul122629f2006-07-20 16:49:57 +0000283 struct gl_program *prog;
Michal Krol2861e732004-03-29 11:09:34 +0000284 GET_CURRENT_CONTEXT(ctx);
285
286 if (!ctx->_CurrentProgram)
287 ASSERT_OUTSIDE_BEGIN_END(ctx);
288
289 if (pname != GL_PROGRAM_STRING_NV) {
290 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramStringNV(pname)");
291 return;
292 }
293
Brian Paul4d12a052006-08-23 23:10:14 +0000294 prog = _mesa_lookup_program(ctx, id);
Michal Krol2861e732004-03-29 11:09:34 +0000295 if (!prog) {
296 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramStringNV");
297 return;
298 }
299
300 if (prog->String) {
301 MEMCPY(program, prog->String, _mesa_strlen((char *) prog->String));
302 }
303 else {
304 program[0] = 0;
305 }
306}
307
308
309/**
310 * Get matrix tracking information.
311 * \note Not compiled into display lists.
312 * \note Called from the GL API dispatcher.
313 */
314void GLAPIENTRY
315_mesa_GetTrackMatrixivNV(GLenum target, GLuint address,
316 GLenum pname, GLint *params)
317{
318 GET_CURRENT_CONTEXT(ctx);
319 ASSERT_OUTSIDE_BEGIN_END(ctx);
320
321 if (target == GL_VERTEX_PROGRAM_NV
322 && ctx->Extensions.NV_vertex_program) {
323 GLuint i;
324
325 if ((address & 0x3) || address >= MAX_NV_VERTEX_PROGRAM_PARAMS) {
326 _mesa_error(ctx, GL_INVALID_VALUE, "glGetTrackMatrixivNV(address)");
327 return;
328 }
329
330 i = address / 4;
331
332 switch (pname) {
333 case GL_TRACK_MATRIX_NV:
334 params[0] = (GLint) ctx->VertexProgram.TrackMatrix[i];
335 return;
336 case GL_TRACK_MATRIX_TRANSFORM_NV:
337 params[0] = (GLint) ctx->VertexProgram.TrackMatrixTransform[i];
338 return;
339 default:
340 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTrackMatrixivNV");
341 return;
342 }
343 }
344 else {
345 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTrackMatrixivNV");
346 return;
347 }
348}
349
350
351/**
352 * Get a vertex (or vertex array) attribute.
353 * \note Not compiled into display lists.
354 * \note Called from the GL API dispatcher.
355 */
356void GLAPIENTRY
357_mesa_GetVertexAttribdvNV(GLuint index, GLenum pname, GLdouble *params)
358{
359 GET_CURRENT_CONTEXT(ctx);
360 ASSERT_OUTSIDE_BEGIN_END(ctx);
361
Brian Paul120584a2006-11-04 17:31:45 +0000362 if (index >= MAX_NV_VERTEX_PROGRAM_INPUTS) {
Michal Krol2861e732004-03-29 11:09:34 +0000363 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribdvNV(index)");
364 return;
365 }
366
367 switch (pname) {
368 case GL_ATTRIB_ARRAY_SIZE_NV:
Ian Romanickee34e6e2006-06-12 16:26:29 +0000369 params[0] = ctx->Array.ArrayObj->VertexAttrib[index].Size;
Michal Krol2861e732004-03-29 11:09:34 +0000370 break;
371 case GL_ATTRIB_ARRAY_STRIDE_NV:
Ian Romanickee34e6e2006-06-12 16:26:29 +0000372 params[0] = ctx->Array.ArrayObj->VertexAttrib[index].Stride;
Michal Krol2861e732004-03-29 11:09:34 +0000373 break;
374 case GL_ATTRIB_ARRAY_TYPE_NV:
Ian Romanickee34e6e2006-06-12 16:26:29 +0000375 params[0] = ctx->Array.ArrayObj->VertexAttrib[index].Type;
Michal Krol2861e732004-03-29 11:09:34 +0000376 break;
377 case GL_CURRENT_ATTRIB_NV:
Brian Paul120584a2006-11-04 17:31:45 +0000378 if (index == 0) {
379 _mesa_error(ctx, GL_INVALID_OPERATION,
380 "glGetVertexAttribdvNV(index == 0)");
381 return;
382 }
Michal Krol2861e732004-03-29 11:09:34 +0000383 FLUSH_CURRENT(ctx, 0);
384 COPY_4V(params, ctx->Current.Attrib[index]);
385 break;
386 default:
387 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribdvNV");
388 return;
389 }
390}
391
392/**
393 * Get a vertex (or vertex array) attribute.
394 * \note Not compiled into display lists.
395 * \note Called from the GL API dispatcher.
396 */
397void GLAPIENTRY
398_mesa_GetVertexAttribfvNV(GLuint index, GLenum pname, GLfloat *params)
399{
400 GET_CURRENT_CONTEXT(ctx);
401 ASSERT_OUTSIDE_BEGIN_END(ctx);
402
Brian Paul120584a2006-11-04 17:31:45 +0000403 if (index >= MAX_NV_VERTEX_PROGRAM_INPUTS) {
Michal Krol2861e732004-03-29 11:09:34 +0000404 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribdvNV(index)");
405 return;
406 }
407
408 switch (pname) {
409 case GL_ATTRIB_ARRAY_SIZE_NV:
Ian Romanickee34e6e2006-06-12 16:26:29 +0000410 params[0] = (GLfloat) ctx->Array.ArrayObj->VertexAttrib[index].Size;
Michal Krol2861e732004-03-29 11:09:34 +0000411 break;
412 case GL_ATTRIB_ARRAY_STRIDE_NV:
Ian Romanickee34e6e2006-06-12 16:26:29 +0000413 params[0] = (GLfloat) ctx->Array.ArrayObj->VertexAttrib[index].Stride;
Michal Krol2861e732004-03-29 11:09:34 +0000414 break;
415 case GL_ATTRIB_ARRAY_TYPE_NV:
Ian Romanickee34e6e2006-06-12 16:26:29 +0000416 params[0] = (GLfloat) ctx->Array.ArrayObj->VertexAttrib[index].Type;
Michal Krol2861e732004-03-29 11:09:34 +0000417 break;
418 case GL_CURRENT_ATTRIB_NV:
Brian Paul120584a2006-11-04 17:31:45 +0000419 if (index == 0) {
420 _mesa_error(ctx, GL_INVALID_OPERATION,
421 "glGetVertexAttribfvNV(index == 0)");
422 return;
423 }
Michal Krol2861e732004-03-29 11:09:34 +0000424 FLUSH_CURRENT(ctx, 0);
425 COPY_4V(params, ctx->Current.Attrib[index]);
426 break;
427 default:
428 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribdvNV");
429 return;
430 }
431}
432
433/**
434 * Get a vertex (or vertex array) attribute.
435 * \note Not compiled into display lists.
436 * \note Called from the GL API dispatcher.
437 */
438void GLAPIENTRY
439_mesa_GetVertexAttribivNV(GLuint index, GLenum pname, GLint *params)
440{
441 GET_CURRENT_CONTEXT(ctx);
442 ASSERT_OUTSIDE_BEGIN_END(ctx);
443
Brian Paul120584a2006-11-04 17:31:45 +0000444 if (index >= MAX_NV_VERTEX_PROGRAM_INPUTS) {
Michal Krol2861e732004-03-29 11:09:34 +0000445 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribdvNV(index)");
446 return;
447 }
448
449 switch (pname) {
450 case GL_ATTRIB_ARRAY_SIZE_NV:
Ian Romanickee34e6e2006-06-12 16:26:29 +0000451 params[0] = ctx->Array.ArrayObj->VertexAttrib[index].Size;
Michal Krol2861e732004-03-29 11:09:34 +0000452 break;
453 case GL_ATTRIB_ARRAY_STRIDE_NV:
Ian Romanickee34e6e2006-06-12 16:26:29 +0000454 params[0] = ctx->Array.ArrayObj->VertexAttrib[index].Stride;
Michal Krol2861e732004-03-29 11:09:34 +0000455 break;
456 case GL_ATTRIB_ARRAY_TYPE_NV:
Ian Romanickee34e6e2006-06-12 16:26:29 +0000457 params[0] = ctx->Array.ArrayObj->VertexAttrib[index].Type;
Michal Krol2861e732004-03-29 11:09:34 +0000458 break;
459 case GL_CURRENT_ATTRIB_NV:
Brian Paul120584a2006-11-04 17:31:45 +0000460 if (index == 0) {
461 _mesa_error(ctx, GL_INVALID_OPERATION,
462 "glGetVertexAttribivNV(index == 0)");
463 return;
464 }
Michal Krol2861e732004-03-29 11:09:34 +0000465 FLUSH_CURRENT(ctx, 0);
466 params[0] = (GLint) ctx->Current.Attrib[index][0];
467 params[1] = (GLint) ctx->Current.Attrib[index][1];
468 params[2] = (GLint) ctx->Current.Attrib[index][2];
469 params[3] = (GLint) ctx->Current.Attrib[index][3];
470 break;
471 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
472 if (!ctx->Extensions.ARB_vertex_buffer_object) {
473 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribdvNV");
474 return;
475 }
Ian Romanickee34e6e2006-06-12 16:26:29 +0000476 params[0] = ctx->Array.ArrayObj->VertexAttrib[index].BufferObj->Name;
Michal Krol2861e732004-03-29 11:09:34 +0000477 break;
478 default:
479 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribdvNV");
480 return;
481 }
482}
483
484
485/**
486 * Get a vertex array attribute pointer.
487 * \note Not compiled into display lists.
488 * \note Called from the GL API dispatcher.
489 */
490void GLAPIENTRY
491_mesa_GetVertexAttribPointervNV(GLuint index, GLenum pname, GLvoid **pointer)
492{
493 GET_CURRENT_CONTEXT(ctx);
494 ASSERT_OUTSIDE_BEGIN_END(ctx);
495
496 if (index >= MAX_NV_VERTEX_PROGRAM_INPUTS) {
497 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerNV(index)");
498 return;
499 }
500
501 if (pname != GL_ATTRIB_ARRAY_POINTER_NV) {
502 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerNV(pname)");
503 return;
504 }
505
Ian Romanickee34e6e2006-06-12 16:26:29 +0000506 *pointer = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[index].Ptr;
Michal Krol2861e732004-03-29 11:09:34 +0000507}
508
509
510
511/**
512 * Load/parse/compile a program.
513 * \note Called from the GL API dispatcher.
514 */
515void GLAPIENTRY
516_mesa_LoadProgramNV(GLenum target, GLuint id, GLsizei len,
517 const GLubyte *program)
518{
Brian Paul122629f2006-07-20 16:49:57 +0000519 struct gl_program *prog;
Michal Krol2861e732004-03-29 11:09:34 +0000520 GET_CURRENT_CONTEXT(ctx);
521 ASSERT_OUTSIDE_BEGIN_END(ctx);
522
523 if (id == 0) {
524 _mesa_error(ctx, GL_INVALID_VALUE, "glLoadProgramNV(id)");
525 return;
526 }
527
Brian Paul8a979462006-04-20 15:06:40 +0000528 if (len < 0) {
529 _mesa_error(ctx, GL_INVALID_VALUE, "glLoadProgramNV(len)");
530 return;
531 }
532
Michal Krol2861e732004-03-29 11:09:34 +0000533 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
534
Brian Paul4d12a052006-08-23 23:10:14 +0000535 prog = _mesa_lookup_program(ctx, id);
Michal Krol2861e732004-03-29 11:09:34 +0000536
537 if (prog && prog->Target != 0 && prog->Target != target) {
538 _mesa_error(ctx, GL_INVALID_OPERATION, "glLoadProgramNV(target)");
539 return;
540 }
541
542 if ((target == GL_VERTEX_PROGRAM_NV ||
543 target == GL_VERTEX_STATE_PROGRAM_NV)
544 && ctx->Extensions.NV_vertex_program) {
Brian Paul122629f2006-07-20 16:49:57 +0000545 struct gl_vertex_program *vprog = (struct gl_vertex_program *) prog;
Brian Paul9ca83922004-10-02 15:16:59 +0000546 if (!vprog || prog == &_mesa_DummyProgram) {
Brian Paul122629f2006-07-20 16:49:57 +0000547 vprog = (struct gl_vertex_program *)
Brian Paul05907862004-06-20 20:57:22 +0000548 ctx->Driver.NewProgram(ctx, target, id);
Michal Krol2861e732004-03-29 11:09:34 +0000549 if (!vprog) {
550 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glLoadProgramNV");
551 return;
552 }
Michal Krol2861e732004-03-29 11:09:34 +0000553 _mesa_HashInsert(ctx->Shared->Programs, id, vprog);
554 }
555 _mesa_parse_nv_vertex_program(ctx, target, program, len, vprog);
556 }
557 else if (target == GL_FRAGMENT_PROGRAM_NV
558 && ctx->Extensions.NV_fragment_program) {
Brian Paul122629f2006-07-20 16:49:57 +0000559 struct gl_fragment_program *fprog = (struct gl_fragment_program *) prog;
Brian Paul9ca83922004-10-02 15:16:59 +0000560 if (!fprog || prog == &_mesa_DummyProgram) {
Brian Paul122629f2006-07-20 16:49:57 +0000561 fprog = (struct gl_fragment_program *)
Brian Paul05907862004-06-20 20:57:22 +0000562 ctx->Driver.NewProgram(ctx, target, id);
Michal Krol2861e732004-03-29 11:09:34 +0000563 if (!fprog) {
564 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glLoadProgramNV");
565 return;
566 }
Michal Krol2861e732004-03-29 11:09:34 +0000567 _mesa_HashInsert(ctx->Shared->Programs, id, fprog);
568 }
569 _mesa_parse_nv_fragment_program(ctx, target, program, len, fprog);
570 }
571 else {
572 _mesa_error(ctx, GL_INVALID_ENUM, "glLoadProgramNV(target)");
573 }
574}
575
576
577
578/**
Michal Krol2861e732004-03-29 11:09:34 +0000579 * Set a sequence of program parameter registers.
580 * \note Called from the GL API dispatcher.
581 */
582void GLAPIENTRY
583_mesa_ProgramParameters4dvNV(GLenum target, GLuint index,
584 GLuint num, const GLdouble *params)
585{
586 GET_CURRENT_CONTEXT(ctx);
587 ASSERT_OUTSIDE_BEGIN_END(ctx);
588
589 if (target == GL_VERTEX_PROGRAM_NV && ctx->Extensions.NV_vertex_program) {
590 GLuint i;
591 if (index + num > MAX_NV_VERTEX_PROGRAM_PARAMS) {
592 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramParameters4dvNV");
593 return;
594 }
595 for (i = 0; i < num; i++) {
596 ctx->VertexProgram.Parameters[index + i][0] = (GLfloat) params[0];
597 ctx->VertexProgram.Parameters[index + i][1] = (GLfloat) params[1];
598 ctx->VertexProgram.Parameters[index + i][2] = (GLfloat) params[2];
599 ctx->VertexProgram.Parameters[index + i][3] = (GLfloat) params[3];
600 params += 4;
601 };
602 }
603 else {
604 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramParameters4dvNV");
605 return;
606 }
607}
608
609
610/**
611 * Set a sequence of program parameter registers.
612 * \note Called from the GL API dispatcher.
613 */
614void GLAPIENTRY
615_mesa_ProgramParameters4fvNV(GLenum target, GLuint index,
616 GLuint num, const GLfloat *params)
617{
618 GET_CURRENT_CONTEXT(ctx);
619 ASSERT_OUTSIDE_BEGIN_END(ctx);
620
621 if (target == GL_VERTEX_PROGRAM_NV && ctx->Extensions.NV_vertex_program) {
622 GLuint i;
623 if (index + num > MAX_NV_VERTEX_PROGRAM_PARAMS) {
624 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramParameters4fvNV");
625 return;
626 }
627 for (i = 0; i < num; i++) {
628 COPY_4V(ctx->VertexProgram.Parameters[index + i], params);
629 params += 4;
Ian Romanickdaea7172006-08-15 16:26:34 +0000630 }
Michal Krol2861e732004-03-29 11:09:34 +0000631 }
632 else {
633 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramParameters4fvNV");
634 return;
635 }
636}
637
638
639
640/**
641 * Setup tracking of matrices into program parameter registers.
642 * \note Called from the GL API dispatcher.
643 */
644void GLAPIENTRY
645_mesa_TrackMatrixNV(GLenum target, GLuint address,
646 GLenum matrix, GLenum transform)
647{
648 GET_CURRENT_CONTEXT(ctx);
649 ASSERT_OUTSIDE_BEGIN_END(ctx);
650
651 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
652
653 if (target == GL_VERTEX_PROGRAM_NV && ctx->Extensions.NV_vertex_program) {
654 if (address & 0x3) {
655 /* addr must be multiple of four */
656 _mesa_error(ctx, GL_INVALID_VALUE, "glTrackMatrixNV(address)");
657 return;
658 }
659
660 switch (matrix) {
661 case GL_NONE:
662 case GL_MODELVIEW:
663 case GL_PROJECTION:
664 case GL_TEXTURE:
665 case GL_COLOR:
666 case GL_MODELVIEW_PROJECTION_NV:
667 case GL_MATRIX0_NV:
668 case GL_MATRIX1_NV:
669 case GL_MATRIX2_NV:
670 case GL_MATRIX3_NV:
671 case GL_MATRIX4_NV:
672 case GL_MATRIX5_NV:
673 case GL_MATRIX6_NV:
674 case GL_MATRIX7_NV:
675 /* OK, fallthrough */
676 break;
677 default:
678 _mesa_error(ctx, GL_INVALID_ENUM, "glTrackMatrixNV(matrix)");
679 return;
680 }
681
682 switch (transform) {
683 case GL_IDENTITY_NV:
684 case GL_INVERSE_NV:
685 case GL_TRANSPOSE_NV:
686 case GL_INVERSE_TRANSPOSE_NV:
687 /* OK, fallthrough */
688 break;
689 default:
690 _mesa_error(ctx, GL_INVALID_ENUM, "glTrackMatrixNV(transform)");
691 return;
692 }
693
694 ctx->VertexProgram.TrackMatrix[address / 4] = matrix;
695 ctx->VertexProgram.TrackMatrixTransform[address / 4] = transform;
696 }
697 else {
698 _mesa_error(ctx, GL_INVALID_ENUM, "glTrackMatrixNV(target)");
699 return;
700 }
701}
702
703
704void GLAPIENTRY
705_mesa_ProgramNamedParameter4fNV(GLuint id, GLsizei len, const GLubyte *name,
706 GLfloat x, GLfloat y, GLfloat z, GLfloat w)
707{
Brian Paul122629f2006-07-20 16:49:57 +0000708 struct gl_program *prog;
709 struct gl_fragment_program *fragProg;
Michal Krol2861e732004-03-29 11:09:34 +0000710 GLfloat *v;
711
712 GET_CURRENT_CONTEXT(ctx);
713 ASSERT_OUTSIDE_BEGIN_END(ctx);
714
715 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
716
Brian Paul4d12a052006-08-23 23:10:14 +0000717 prog = _mesa_lookup_program(ctx, id);
Michal Krol2861e732004-03-29 11:09:34 +0000718 if (!prog || prog->Target != GL_FRAGMENT_PROGRAM_NV) {
719 _mesa_error(ctx, GL_INVALID_OPERATION, "glProgramNamedParameterNV");
720 return;
721 }
722
723 if (len <= 0) {
Brian Paul9ca83922004-10-02 15:16:59 +0000724 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramNamedParameterNV(len)");
Michal Krol2861e732004-03-29 11:09:34 +0000725 return;
726 }
727
Brian Paul122629f2006-07-20 16:49:57 +0000728 fragProg = (struct gl_fragment_program *) prog;
Brian Paulde997602005-11-12 17:53:14 +0000729 v = _mesa_lookup_parameter_value(fragProg->Base.Parameters, len,
730 (char *) name);
Michal Krol2861e732004-03-29 11:09:34 +0000731 if (v) {
732 v[0] = x;
733 v[1] = y;
734 v[2] = z;
735 v[3] = w;
736 return;
737 }
738
Brian Paul9ca83922004-10-02 15:16:59 +0000739 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramNamedParameterNV(name)");
Michal Krol2861e732004-03-29 11:09:34 +0000740}
741
742
743void GLAPIENTRY
744_mesa_ProgramNamedParameter4fvNV(GLuint id, GLsizei len, const GLubyte *name,
745 const float v[])
746{
747 _mesa_ProgramNamedParameter4fNV(id, len, name, v[0], v[1], v[2], v[3]);
748}
749
750
751void GLAPIENTRY
752_mesa_ProgramNamedParameter4dNV(GLuint id, GLsizei len, const GLubyte *name,
753 GLdouble x, GLdouble y, GLdouble z, GLdouble w)
754{
755 _mesa_ProgramNamedParameter4fNV(id, len, name, (GLfloat)x, (GLfloat)y,
756 (GLfloat)z, (GLfloat)w);
757}
758
759
760void GLAPIENTRY
761_mesa_ProgramNamedParameter4dvNV(GLuint id, GLsizei len, const GLubyte *name,
762 const double v[])
763{
764 _mesa_ProgramNamedParameter4fNV(id, len, name,
765 (GLfloat)v[0], (GLfloat)v[1],
766 (GLfloat)v[2], (GLfloat)v[3]);
767}
768
769
770void GLAPIENTRY
771_mesa_GetProgramNamedParameterfvNV(GLuint id, GLsizei len, const GLubyte *name,
772 GLfloat *params)
773{
Brian Paul122629f2006-07-20 16:49:57 +0000774 struct gl_program *prog;
775 struct gl_fragment_program *fragProg;
Michal Krol2861e732004-03-29 11:09:34 +0000776 const GLfloat *v;
777
778 GET_CURRENT_CONTEXT(ctx);
779
780 if (!ctx->_CurrentProgram)
781 ASSERT_OUTSIDE_BEGIN_END(ctx);
782
Brian Paul4d12a052006-08-23 23:10:14 +0000783 prog = _mesa_lookup_program(ctx, id);
Michal Krol2861e732004-03-29 11:09:34 +0000784 if (!prog || prog->Target != GL_FRAGMENT_PROGRAM_NV) {
785 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramNamedParameterNV");
786 return;
787 }
788
789 if (len <= 0) {
790 _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramNamedParameterNV");
791 return;
792 }
793
Brian Paul122629f2006-07-20 16:49:57 +0000794 fragProg = (struct gl_fragment_program *) prog;
Brian Paulde997602005-11-12 17:53:14 +0000795 v = _mesa_lookup_parameter_value(fragProg->Base.Parameters,
796 len, (char *) name);
Michal Krol2861e732004-03-29 11:09:34 +0000797 if (v) {
798 params[0] = v[0];
799 params[1] = v[1];
800 params[2] = v[2];
801 params[3] = v[3];
802 return;
803 }
804
805 _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramNamedParameterNV");
806}
807
808
809void GLAPIENTRY
810_mesa_GetProgramNamedParameterdvNV(GLuint id, GLsizei len, const GLubyte *name,
811 GLdouble *params)
812{
813 GLfloat floatParams[4];
814 _mesa_GetProgramNamedParameterfvNV(id, len, name, floatParams);
815 COPY_4V(params, floatParams);
816}