silence warning, new assertion
[mesa.git] / src / mesa / shader / arbprogram.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.0
4 *
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
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 arbprogram.c
27 * ARB_vertex/fragment_program state management functions.
28 * \author Brian Paul
29 */
30
31
32 #include "glheader.h"
33 #include "arbprogram.h"
34 #include "arbprogparse.h"
35 #include "context.h"
36 #include "imports.h"
37 #include "macros.h"
38 #include "mtypes.h"
39 #include "program.h"
40
41
42 void GLAPIENTRY
43 _mesa_EnableVertexAttribArrayARB(GLuint index)
44 {
45 GET_CURRENT_CONTEXT(ctx);
46 ASSERT_OUTSIDE_BEGIN_END(ctx);
47
48 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
49 _mesa_error(ctx, GL_INVALID_VALUE,
50 "glEnableVertexAttribArrayARB(index)");
51 return;
52 }
53
54 FLUSH_VERTICES(ctx, _NEW_ARRAY);
55 ctx->Array.ArrayObj->VertexAttrib[index].Enabled = GL_TRUE;
56 ctx->Array.ArrayObj->_Enabled |= _NEW_ARRAY_ATTRIB(index);
57 ctx->Array.NewState |= _NEW_ARRAY_ATTRIB(index);
58 }
59
60
61 void GLAPIENTRY
62 _mesa_DisableVertexAttribArrayARB(GLuint index)
63 {
64 GET_CURRENT_CONTEXT(ctx);
65 ASSERT_OUTSIDE_BEGIN_END(ctx);
66
67 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
68 _mesa_error(ctx, GL_INVALID_VALUE,
69 "glEnableVertexAttribArrayARB(index)");
70 return;
71 }
72
73 FLUSH_VERTICES(ctx, _NEW_ARRAY);
74 ctx->Array.ArrayObj->VertexAttrib[index].Enabled = GL_FALSE;
75 ctx->Array.ArrayObj->_Enabled &= ~_NEW_ARRAY_ATTRIB(index);
76 ctx->Array.NewState |= _NEW_ARRAY_ATTRIB(index);
77 }
78
79
80 void GLAPIENTRY
81 _mesa_GetVertexAttribdvARB(GLuint index, GLenum pname, GLdouble *params)
82 {
83 GLfloat fparams[4];
84 GET_CURRENT_CONTEXT(ctx);
85 ASSERT_OUTSIDE_BEGIN_END(ctx);
86
87 _mesa_GetVertexAttribfvARB(index, pname, fparams);
88 if (ctx->ErrorValue == GL_NO_ERROR) {
89 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
90 COPY_4V(params, fparams);
91 }
92 else {
93 params[0] = fparams[0];
94 }
95 }
96 }
97
98
99 void GLAPIENTRY
100 _mesa_GetVertexAttribfvARB(GLuint index, GLenum pname, GLfloat *params)
101 {
102 GET_CURRENT_CONTEXT(ctx);
103 ASSERT_OUTSIDE_BEGIN_END(ctx);
104
105 if (index >= MAX_VERTEX_PROGRAM_ATTRIBS) {
106 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribfvARB(index)");
107 return;
108 }
109
110 switch (pname) {
111 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
112 params[0] = (GLfloat) ctx->Array.ArrayObj->VertexAttrib[index].Enabled;
113 break;
114 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
115 params[0] = (GLfloat) ctx->Array.ArrayObj->VertexAttrib[index].Size;
116 break;
117 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
118 params[0] = (GLfloat) ctx->Array.ArrayObj->VertexAttrib[index].Stride;
119 break;
120 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
121 params[0] = (GLfloat) ctx->Array.ArrayObj->VertexAttrib[index].Type;
122 break;
123 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
124 params[0] = ctx->Array.ArrayObj->VertexAttrib[index].Normalized;
125 break;
126 case GL_CURRENT_VERTEX_ATTRIB_ARB:
127 if (index == 0) {
128 _mesa_error(ctx, GL_INVALID_OPERATION,
129 "glGetVertexAttribfvARB(index==0)");
130 return;
131 }
132 FLUSH_CURRENT(ctx, 0);
133 COPY_4V(params, ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + index]);
134 break;
135 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
136 if (!ctx->Extensions.ARB_vertex_buffer_object) {
137 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribfvARB(pname)");
138 return;
139 }
140 params[0] = (GLfloat) ctx->Array.ArrayObj->VertexAttrib[index].BufferObj->Name;
141 break;
142 default:
143 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribfvARB(pname)");
144 return;
145 }
146 }
147
148
149 void GLAPIENTRY
150 _mesa_GetVertexAttribivARB(GLuint index, GLenum pname, GLint *params)
151 {
152 GLfloat fparams[4];
153 GET_CURRENT_CONTEXT(ctx);
154 ASSERT_OUTSIDE_BEGIN_END(ctx);
155
156 _mesa_GetVertexAttribfvARB(index, pname, fparams);
157 if (ctx->ErrorValue == GL_NO_ERROR) {
158 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
159 COPY_4V_CAST(params, fparams, GLint); /* float to int */
160 }
161 else {
162 params[0] = (GLint) fparams[0];
163 }
164 }
165 }
166
167
168 void GLAPIENTRY
169 _mesa_GetVertexAttribPointervARB(GLuint index, GLenum pname, GLvoid **pointer)
170 {
171 GET_CURRENT_CONTEXT(ctx);
172 ASSERT_OUTSIDE_BEGIN_END(ctx);
173
174 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
175 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
176 return;
177 }
178
179 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
180 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
181 return;
182 }
183
184 *pointer = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[index].Ptr;
185 }
186
187
188 /**
189 * Determine if id names a vertex or fragment program.
190 * \note Not compiled into display lists.
191 * \note Called from both glIsProgramNV and glIsProgramARB.
192 * \param id is the program identifier
193 * \return GL_TRUE if id is a program, else GL_FALSE.
194 */
195 GLboolean GLAPIENTRY
196 _mesa_IsProgramARB(GLuint id)
197 {
198 struct gl_program *prog = NULL;
199 GET_CURRENT_CONTEXT(ctx);
200 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
201
202 if (id == 0)
203 return GL_FALSE;
204
205 prog = _mesa_lookup_program(ctx, id);
206 if (prog && (prog != &_mesa_DummyProgram))
207 return GL_TRUE;
208 else
209 return GL_FALSE;
210 }
211
212
213 void GLAPIENTRY
214 _mesa_ProgramStringARB(GLenum target, GLenum format, GLsizei len,
215 const GLvoid *string)
216 {
217 GET_CURRENT_CONTEXT(ctx);
218 ASSERT_OUTSIDE_BEGIN_END(ctx);
219
220 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
221
222 if (format != GL_PROGRAM_FORMAT_ASCII_ARB) {
223 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramStringARB(format)");
224 return;
225 }
226
227 if (target == GL_VERTEX_PROGRAM_ARB
228 && ctx->Extensions.ARB_vertex_program) {
229 struct gl_vertex_program *prog = ctx->VertexProgram.Current;
230 _mesa_parse_arb_vertex_program(ctx, target, string, len, prog);
231
232 if (ctx->Program.ErrorPos == -1 && ctx->Driver.ProgramStringNotify)
233 ctx->Driver.ProgramStringNotify( ctx, target, &prog->Base );
234 }
235 else if (target == GL_FRAGMENT_PROGRAM_ARB
236 && ctx->Extensions.ARB_fragment_program) {
237 struct gl_fragment_program *prog = ctx->FragmentProgram.Current;
238 _mesa_parse_arb_fragment_program(ctx, target, string, len, prog);
239
240 if (ctx->Program.ErrorPos == -1 && ctx->Driver.ProgramStringNotify)
241 ctx->Driver.ProgramStringNotify( ctx, target, &prog->Base );
242 }
243 else {
244 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramStringARB(target)");
245 return;
246 }
247 }
248
249
250 /**
251 * Set a program env parameter register.
252 * \note Called from the GL API dispatcher.
253 * Note, this function is also used by the GL_NV_vertex_program extension
254 * (alias to ProgramParameterdNV)
255 */
256 void GLAPIENTRY
257 _mesa_ProgramEnvParameter4dARB(GLenum target, GLuint index,
258 GLdouble x, GLdouble y, GLdouble z, GLdouble w)
259 {
260 _mesa_ProgramEnvParameter4fARB(target, index, (GLfloat) x, (GLfloat) y,
261 (GLfloat) z, (GLfloat) w);
262 }
263
264
265 /**
266 * Set a program env parameter register.
267 * \note Called from the GL API dispatcher.
268 * Note, this function is also used by the GL_NV_vertex_program extension
269 * (alias to ProgramParameterdvNV)
270 */
271 void GLAPIENTRY
272 _mesa_ProgramEnvParameter4dvARB(GLenum target, GLuint index,
273 const GLdouble *params)
274 {
275 _mesa_ProgramEnvParameter4fARB(target, index, (GLfloat) params[0],
276 (GLfloat) params[1], (GLfloat) params[2],
277 (GLfloat) params[3]);
278 }
279
280
281 /**
282 * Set a program env parameter register.
283 * \note Called from the GL API dispatcher.
284 * Note, this function is also used by the GL_NV_vertex_program extension
285 * (alias to ProgramParameterfNV)
286 */
287 void GLAPIENTRY
288 _mesa_ProgramEnvParameter4fARB(GLenum target, GLuint index,
289 GLfloat x, GLfloat y, GLfloat z, GLfloat w)
290 {
291 GET_CURRENT_CONTEXT(ctx);
292 ASSERT_OUTSIDE_BEGIN_END(ctx);
293
294 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
295
296 if (target == GL_FRAGMENT_PROGRAM_ARB
297 && ctx->Extensions.ARB_fragment_program) {
298 if (index >= ctx->Const.FragmentProgram.MaxEnvParams) {
299 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameter(index)");
300 return;
301 }
302 ASSIGN_4V(ctx->FragmentProgram.Parameters[index], x, y, z, w);
303 }
304 else if (target == GL_VERTEX_PROGRAM_ARB /* == GL_VERTEX_PROGRAM_NV */
305 && (ctx->Extensions.ARB_vertex_program || ctx->Extensions.NV_vertex_program)) {
306 if (index >= ctx->Const.VertexProgram.MaxEnvParams) {
307 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameter(index)");
308 return;
309 }
310 ASSIGN_4V(ctx->VertexProgram.Parameters[index], x, y, z, w);
311 }
312 else {
313 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramEnvParameter(target)");
314 return;
315 }
316 }
317
318 /**
319 * Set a program env parameter register.
320 * \note Called from the GL API dispatcher.
321 * Note, this function is also used by the GL_NV_vertex_program extension
322 * (alias to ProgramParameterfvNV)
323 */
324 void GLAPIENTRY
325 _mesa_ProgramEnvParameter4fvARB(GLenum target, GLuint index,
326 const GLfloat *params)
327 {
328 _mesa_ProgramEnvParameter4fARB(target, index, params[0], params[1],
329 params[2], params[3]);
330 }
331
332
333 void GLAPIENTRY
334 _mesa_ProgramEnvParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
335 const GLfloat *params)
336 {
337 GET_CURRENT_CONTEXT(ctx);
338 GLint i;
339 GLfloat * dest;
340 ASSERT_OUTSIDE_BEGIN_END(ctx);
341
342 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
343
344 if (count <= 0) {
345 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameters4fv(count)");
346 }
347
348 if (target == GL_FRAGMENT_PROGRAM_ARB
349 && ctx->Extensions.ARB_fragment_program) {
350 if ((index + count) > ctx->Const.FragmentProgram.MaxEnvParams) {
351 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameters4fv(index + count)");
352 return;
353 }
354 dest = ctx->FragmentProgram.Parameters[index];
355 }
356 else if (target == GL_VERTEX_PROGRAM_ARB
357 && ctx->Extensions.ARB_vertex_program) {
358 if ((index + count) > ctx->Const.VertexProgram.MaxEnvParams) {
359 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameters4fv(index + count)");
360 return;
361 }
362 dest = ctx->VertexProgram.Parameters[index];
363 }
364 else {
365 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramEnvParameters4fv(target)");
366 return;
367 }
368
369 for ( i = 0 ; i < count ; i++ ) {
370 COPY_4V(dest, params);
371 params += 4;
372 dest += 4;
373 }
374 }
375
376
377 void GLAPIENTRY
378 _mesa_GetProgramEnvParameterdvARB(GLenum target, GLuint index,
379 GLdouble *params)
380 {
381 GET_CURRENT_CONTEXT(ctx);
382 GLfloat fparams[4];
383
384 _mesa_GetProgramEnvParameterfvARB(target, index, fparams);
385 if (ctx->ErrorValue == GL_NO_ERROR) {
386 params[0] = fparams[0];
387 params[1] = fparams[1];
388 params[2] = fparams[2];
389 params[3] = fparams[3];
390 }
391 }
392
393
394 void GLAPIENTRY
395 _mesa_GetProgramEnvParameterfvARB(GLenum target, GLuint index,
396 GLfloat *params)
397 {
398 GET_CURRENT_CONTEXT(ctx);
399
400 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
401
402 if (!ctx->_CurrentProgram)
403 ASSERT_OUTSIDE_BEGIN_END(ctx);
404
405 if (target == GL_FRAGMENT_PROGRAM_ARB
406 && ctx->Extensions.ARB_fragment_program) {
407 if (index >= ctx->Const.FragmentProgram.MaxEnvParams) {
408 _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramEnvParameter(index)");
409 return;
410 }
411 COPY_4V(params, ctx->FragmentProgram.Parameters[index]);
412 }
413 else if (target == GL_VERTEX_PROGRAM_ARB
414 && ctx->Extensions.ARB_vertex_program) {
415 if (index >= ctx->Const.VertexProgram.MaxEnvParams) {
416 _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramEnvParameter(index)");
417 return;
418 }
419 COPY_4V(params, ctx->VertexProgram.Parameters[index]);
420 }
421 else {
422 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramEnvParameter(target)");
423 return;
424 }
425 }
426
427
428 /**
429 * Note, this function is also used by the GL_NV_fragment_program extension.
430 */
431 void GLAPIENTRY
432 _mesa_ProgramLocalParameter4fARB(GLenum target, GLuint index,
433 GLfloat x, GLfloat y, GLfloat z, GLfloat w)
434 {
435 GET_CURRENT_CONTEXT(ctx);
436 struct gl_program *prog;
437 ASSERT_OUTSIDE_BEGIN_END(ctx);
438
439 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
440
441 if ((target == GL_FRAGMENT_PROGRAM_NV
442 && ctx->Extensions.NV_fragment_program) ||
443 (target == GL_FRAGMENT_PROGRAM_ARB
444 && ctx->Extensions.ARB_fragment_program)) {
445 if (index >= ctx->Const.FragmentProgram.MaxLocalParams) {
446 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameterARB");
447 return;
448 }
449 prog = &(ctx->FragmentProgram.Current->Base);
450 }
451 else if (target == GL_VERTEX_PROGRAM_ARB
452 && ctx->Extensions.ARB_vertex_program) {
453 if (index >= ctx->Const.VertexProgram.MaxLocalParams) {
454 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameterARB");
455 return;
456 }
457 prog = &(ctx->VertexProgram.Current->Base);
458 }
459 else {
460 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameterARB");
461 return;
462 }
463
464 ASSERT(index < MAX_PROGRAM_LOCAL_PARAMS);
465 prog->LocalParams[index][0] = x;
466 prog->LocalParams[index][1] = y;
467 prog->LocalParams[index][2] = z;
468 prog->LocalParams[index][3] = w;
469 }
470
471
472 /**
473 * Note, this function is also used by the GL_NV_fragment_program extension.
474 */
475 void GLAPIENTRY
476 _mesa_ProgramLocalParameter4fvARB(GLenum target, GLuint index,
477 const GLfloat *params)
478 {
479 _mesa_ProgramLocalParameter4fARB(target, index, params[0], params[1],
480 params[2], params[3]);
481 }
482
483
484 void GLAPIENTRY
485 _mesa_ProgramLocalParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
486 const GLfloat *params)
487 {
488 GET_CURRENT_CONTEXT(ctx);
489 struct gl_program *prog;
490 GLint i;
491 ASSERT_OUTSIDE_BEGIN_END(ctx);
492
493 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
494
495 if (count <= 0) {
496 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fv(count)");
497 }
498
499 if (target == GL_FRAGMENT_PROGRAM_ARB
500 && ctx->Extensions.ARB_fragment_program) {
501 if ((index + count) > ctx->Const.FragmentProgram.MaxLocalParams) {
502 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fvEXT(index + count)");
503 return;
504 }
505 prog = &(ctx->FragmentProgram.Current->Base);
506 }
507 else if (target == GL_VERTEX_PROGRAM_ARB
508 && ctx->Extensions.ARB_vertex_program) {
509 if ((index + count) > ctx->Const.VertexProgram.MaxLocalParams) {
510 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fvEXT(index + count)");
511 return;
512 }
513 prog = &(ctx->VertexProgram.Current->Base);
514 }
515 else {
516 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameters4fvEXT(target)");
517 return;
518 }
519
520 for (i = 0; i < count; i++) {
521 ASSERT((index + i) < MAX_PROGRAM_LOCAL_PARAMS);
522 COPY_4V(prog->LocalParams[index + i], params);
523 params += 4;
524 }
525 }
526
527
528 /**
529 * Note, this function is also used by the GL_NV_fragment_program extension.
530 */
531 void GLAPIENTRY
532 _mesa_ProgramLocalParameter4dARB(GLenum target, GLuint index,
533 GLdouble x, GLdouble y,
534 GLdouble z, GLdouble w)
535 {
536 _mesa_ProgramLocalParameter4fARB(target, index, (GLfloat) x, (GLfloat) y,
537 (GLfloat) z, (GLfloat) w);
538 }
539
540
541 /**
542 * Note, this function is also used by the GL_NV_fragment_program extension.
543 */
544 void GLAPIENTRY
545 _mesa_ProgramLocalParameter4dvARB(GLenum target, GLuint index,
546 const GLdouble *params)
547 {
548 _mesa_ProgramLocalParameter4fARB(target, index,
549 (GLfloat) params[0], (GLfloat) params[1],
550 (GLfloat) params[2], (GLfloat) params[3]);
551 }
552
553
554 /**
555 * Note, this function is also used by the GL_NV_fragment_program extension.
556 */
557 void GLAPIENTRY
558 _mesa_GetProgramLocalParameterfvARB(GLenum target, GLuint index,
559 GLfloat *params)
560 {
561 const struct gl_program *prog;
562 GLuint maxParams;
563 GET_CURRENT_CONTEXT(ctx);
564 ASSERT_OUTSIDE_BEGIN_END(ctx);
565
566 if (target == GL_VERTEX_PROGRAM_ARB
567 && ctx->Extensions.ARB_vertex_program) {
568 prog = &(ctx->VertexProgram.Current->Base);
569 maxParams = ctx->Const.VertexProgram.MaxLocalParams;
570 }
571 else if (target == GL_FRAGMENT_PROGRAM_ARB
572 && ctx->Extensions.ARB_fragment_program) {
573 prog = &(ctx->FragmentProgram.Current->Base);
574 maxParams = ctx->Const.FragmentProgram.MaxLocalParams;
575 }
576 else if (target == GL_FRAGMENT_PROGRAM_NV
577 && ctx->Extensions.NV_fragment_program) {
578 prog = &(ctx->FragmentProgram.Current->Base);
579 maxParams = MAX_NV_FRAGMENT_PROGRAM_PARAMS;
580 }
581 else {
582 _mesa_error(ctx, GL_INVALID_ENUM,
583 "glGetProgramLocalParameterARB(target)");
584 return;
585 }
586
587 if (index >= maxParams) {
588 _mesa_error(ctx, GL_INVALID_VALUE,
589 "glGetProgramLocalParameterARB(index)");
590 return;
591 }
592
593 ASSERT(prog);
594 ASSERT(index < MAX_PROGRAM_LOCAL_PARAMS);
595 COPY_4V(params, prog->LocalParams[index]);
596 }
597
598
599 /**
600 * Note, this function is also used by the GL_NV_fragment_program extension.
601 */
602 void GLAPIENTRY
603 _mesa_GetProgramLocalParameterdvARB(GLenum target, GLuint index,
604 GLdouble *params)
605 {
606 GET_CURRENT_CONTEXT(ctx);
607 GLfloat floatParams[4];
608 _mesa_GetProgramLocalParameterfvARB(target, index, floatParams);
609 if (ctx->ErrorValue == GL_NO_ERROR) {
610 COPY_4V(params, floatParams);
611 }
612 }
613
614
615 void GLAPIENTRY
616 _mesa_GetProgramivARB(GLenum target, GLenum pname, GLint *params)
617 {
618 const struct gl_program_constants *limits;
619 struct gl_program *prog;
620 GET_CURRENT_CONTEXT(ctx);
621
622 if (!ctx->_CurrentProgram)
623 ASSERT_OUTSIDE_BEGIN_END(ctx);
624
625 if (target == GL_VERTEX_PROGRAM_ARB
626 && ctx->Extensions.ARB_vertex_program) {
627 prog = &(ctx->VertexProgram.Current->Base);
628 limits = &ctx->Const.VertexProgram;
629 }
630 else if (target == GL_FRAGMENT_PROGRAM_ARB
631 && ctx->Extensions.ARB_fragment_program) {
632 prog = &(ctx->FragmentProgram.Current->Base);
633 limits = &ctx->Const.FragmentProgram;
634 }
635 else {
636 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(target)");
637 return;
638 }
639
640 ASSERT(prog);
641 ASSERT(limits);
642
643 /* Queries supported for both vertex and fragment programs */
644 switch (pname) {
645 case GL_PROGRAM_LENGTH_ARB:
646 *params
647 = prog->String ? (GLint) _mesa_strlen((char *) prog->String) : 0;
648 return;
649 case GL_PROGRAM_FORMAT_ARB:
650 *params = prog->Format;
651 return;
652 case GL_PROGRAM_BINDING_ARB:
653 *params = prog->Id;
654 return;
655 case GL_PROGRAM_INSTRUCTIONS_ARB:
656 *params = prog->NumInstructions;
657 return;
658 case GL_MAX_PROGRAM_INSTRUCTIONS_ARB:
659 *params = limits->MaxInstructions;
660 return;
661 case GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB:
662 *params = prog->NumNativeInstructions;
663 return;
664 case GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB:
665 *params = limits->MaxNativeInstructions;
666 return;
667 case GL_PROGRAM_TEMPORARIES_ARB:
668 *params = prog->NumTemporaries;
669 return;
670 case GL_MAX_PROGRAM_TEMPORARIES_ARB:
671 *params = limits->MaxTemps;
672 return;
673 case GL_PROGRAM_NATIVE_TEMPORARIES_ARB:
674 *params = prog->NumNativeTemporaries;
675 return;
676 case GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB:
677 *params = limits->MaxNativeTemps;
678 return;
679 case GL_PROGRAM_PARAMETERS_ARB:
680 *params = prog->NumParameters;
681 return;
682 case GL_MAX_PROGRAM_PARAMETERS_ARB:
683 *params = limits->MaxParameters;
684 return;
685 case GL_PROGRAM_NATIVE_PARAMETERS_ARB:
686 *params = prog->NumNativeParameters;
687 return;
688 case GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB:
689 *params = limits->MaxNativeParameters;
690 return;
691 case GL_PROGRAM_ATTRIBS_ARB:
692 *params = prog->NumAttributes;
693 return;
694 case GL_MAX_PROGRAM_ATTRIBS_ARB:
695 *params = limits->MaxAttribs;
696 return;
697 case GL_PROGRAM_NATIVE_ATTRIBS_ARB:
698 *params = prog->NumNativeAttributes;
699 return;
700 case GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB:
701 *params = limits->MaxNativeAttribs;
702 return;
703 case GL_PROGRAM_ADDRESS_REGISTERS_ARB:
704 *params = prog->NumAddressRegs;
705 return;
706 case GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB:
707 *params = limits->MaxAddressRegs;
708 return;
709 case GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB:
710 *params = prog->NumNativeAddressRegs;
711 return;
712 case GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB:
713 *params = limits->MaxNativeAddressRegs;
714 return;
715 case GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB:
716 *params = limits->MaxLocalParams;
717 return;
718 case GL_MAX_PROGRAM_ENV_PARAMETERS_ARB:
719 *params = limits->MaxEnvParams;
720 return;
721 case GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB:
722 /*
723 * XXX we may not really need a driver callback here.
724 * If the number of native instructions, registers, etc. used
725 * are all below the maximums, we could return true.
726 * The spec says that even if this query returns true, there's
727 * no guarantee that the program will run in hardware.
728 */
729 if (prog->Id == 0) {
730 /* default/null program */
731 *params = GL_FALSE;
732 }
733 else if (ctx->Driver.IsProgramNative) {
734 /* ask the driver */
735 *params = ctx->Driver.IsProgramNative( ctx, target, prog );
736 }
737 else {
738 /* probably running in software */
739 *params = GL_TRUE;
740 }
741 return;
742 default:
743 /* continue with fragment-program only queries below */
744 break;
745 }
746
747 /*
748 * The following apply to fragment programs only (at this time)
749 */
750 if (target == GL_FRAGMENT_PROGRAM_ARB) {
751 const struct gl_fragment_program *fp = ctx->FragmentProgram.Current;
752 switch (pname) {
753 case GL_PROGRAM_ALU_INSTRUCTIONS_ARB:
754 *params = fp->Base.NumNativeAluInstructions;
755 return;
756 case GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB:
757 *params = fp->Base.NumAluInstructions;
758 return;
759 case GL_PROGRAM_TEX_INSTRUCTIONS_ARB:
760 *params = fp->Base.NumTexInstructions;
761 return;
762 case GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB:
763 *params = fp->Base.NumNativeTexInstructions;
764 return;
765 case GL_PROGRAM_TEX_INDIRECTIONS_ARB:
766 *params = fp->Base.NumTexIndirections;
767 return;
768 case GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB:
769 *params = fp->Base.NumNativeTexIndirections;
770 return;
771 case GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB:
772 *params = limits->MaxAluInstructions;
773 return;
774 case GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB:
775 *params = limits->MaxNativeAluInstructions;
776 return;
777 case GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB:
778 *params = limits->MaxTexInstructions;
779 return;
780 case GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB:
781 *params = limits->MaxNativeTexInstructions;
782 return;
783 case GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB:
784 *params = limits->MaxTexIndirections;
785 return;
786 case GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB:
787 *params = limits->MaxNativeTexIndirections;
788 return;
789 default:
790 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(pname)");
791 return;
792 }
793 }
794 }
795
796
797 void GLAPIENTRY
798 _mesa_GetProgramStringARB(GLenum target, GLenum pname, GLvoid *string)
799 {
800 const struct gl_program *prog;
801 char *dst = (char *) string;
802 GET_CURRENT_CONTEXT(ctx);
803
804 if (!ctx->_CurrentProgram)
805 ASSERT_OUTSIDE_BEGIN_END(ctx);
806
807 if (target == GL_VERTEX_PROGRAM_ARB) {
808 prog = &(ctx->VertexProgram.Current->Base);
809 }
810 else if (target == GL_FRAGMENT_PROGRAM_ARB) {
811 prog = &(ctx->FragmentProgram.Current->Base);
812 }
813 else {
814 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramStringARB(target)");
815 return;
816 }
817
818 ASSERT(prog);
819
820 if (pname != GL_PROGRAM_STRING_ARB) {
821 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramStringARB(pname)");
822 return;
823 }
824
825 if (prog->String)
826 _mesa_memcpy(dst, prog->String, _mesa_strlen((char *) prog->String));
827 else
828 *dst = '\0';
829 }