blob: ca71a3939ccb3deec1b529f1fcb1f5beeab5289e [file] [log] [blame]
Michal Krol157ec8b2004-03-10 18:02:01 +00001/*
2 * Mesa 3-D graphics library
Brian4ca7c802007-04-28 08:01:18 -06003 * Version: 7.0
Michal Krol157ec8b2004-03-10 18:02:01 +00004 *
Brian4ca7c802007-04-28 08:01:18 -06005 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
Michal Krol157ec8b2004-03-10 18:02:01 +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 arbprogram.c
27 * ARB_vertex/fragment_program state management functions.
28 * \author Brian Paul
29 */
30
31
Brian Paulbbd28712008-09-18 12:26:54 -060032#include "main/glheader.h"
33#include "main/context.h"
34#include "main/hash.h"
35#include "main/imports.h"
36#include "main/macros.h"
37#include "main/mtypes.h"
Michal Krol157ec8b2004-03-10 18:02:01 +000038#include "arbprogram.h"
Brian Paul8c41a142005-11-19 15:36:28 +000039#include "arbprogparse.h"
Ian Romanick74528772009-11-02 13:37:47 -080040#include "nvfragparse.h"
Brian Paulf49c0d02006-11-02 16:20:29 +000041#include "program.h"
Michal Krol157ec8b2004-03-10 18:02:01 +000042
43
Brian Paulb7eea9a2008-07-29 17:19:25 -060044
45/**
46 * Mixing ARB and NV vertex/fragment programs can be tricky.
47 * Note: GL_VERTEX_PROGRAM_ARB == GL_VERTEX_PROGRAM_NV
48 * but, GL_FRAGMENT_PROGRAM_ARB != GL_FRAGMENT_PROGRAM_NV
49 * The two different fragment program targets are supposed to be compatible
50 * to some extent (see GL_ARB_fragment_program spec).
51 * This function does the compatibility check.
52 */
53static GLboolean
54compatible_program_targets(GLenum t1, GLenum t2)
55{
56 if (t1 == t2)
57 return GL_TRUE;
58 if (t1 == GL_FRAGMENT_PROGRAM_ARB && t2 == GL_FRAGMENT_PROGRAM_NV)
59 return GL_TRUE;
60 if (t1 == GL_FRAGMENT_PROGRAM_NV && t2 == GL_FRAGMENT_PROGRAM_ARB)
61 return GL_TRUE;
62 return GL_FALSE;
63}
64
65
66/**
67 * Bind a program (make it current)
68 * \note Called from the GL API dispatcher by both glBindProgramNV
69 * and glBindProgramARB.
70 */
71void GLAPIENTRY
72_mesa_BindProgram(GLenum target, GLuint id)
73{
74 struct gl_program *curProg, *newProg;
75 GET_CURRENT_CONTEXT(ctx);
76 ASSERT_OUTSIDE_BEGIN_END(ctx);
77
Brian Paulb7eea9a2008-07-29 17:19:25 -060078 /* Error-check target and get curProg */
79 if ((target == GL_VERTEX_PROGRAM_ARB) && /* == GL_VERTEX_PROGRAM_NV */
80 (ctx->Extensions.NV_vertex_program ||
81 ctx->Extensions.ARB_vertex_program)) {
82 curProg = &ctx->VertexProgram.Current->Base;
83 }
84 else if ((target == GL_FRAGMENT_PROGRAM_NV
85 && ctx->Extensions.NV_fragment_program) ||
86 (target == GL_FRAGMENT_PROGRAM_ARB
87 && ctx->Extensions.ARB_fragment_program)) {
88 curProg = &ctx->FragmentProgram.Current->Base;
89 }
90 else {
91 _mesa_error(ctx, GL_INVALID_ENUM, "glBindProgramNV/ARB(target)");
92 return;
93 }
94
95 /*
96 * Get pointer to new program to bind.
97 * NOTE: binding to a non-existant program is not an error.
98 * That's supposed to be caught in glBegin.
99 */
100 if (id == 0) {
101 /* Bind a default program */
102 newProg = NULL;
103 if (target == GL_VERTEX_PROGRAM_ARB) /* == GL_VERTEX_PROGRAM_NV */
104 newProg = &ctx->Shared->DefaultVertexProgram->Base;
105 else
106 newProg = &ctx->Shared->DefaultFragmentProgram->Base;
107 }
108 else {
109 /* Bind a user program */
110 newProg = _mesa_lookup_program(ctx, id);
111 if (!newProg || newProg == &_mesa_DummyProgram) {
112 /* allocate a new program now */
113 newProg = ctx->Driver.NewProgram(ctx, target, id);
114 if (!newProg) {
115 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindProgramNV/ARB");
116 return;
117 }
118 _mesa_HashInsert(ctx->Shared->Programs, id, newProg);
119 }
120 else if (!compatible_program_targets(newProg->Target, target)) {
121 _mesa_error(ctx, GL_INVALID_OPERATION,
122 "glBindProgramNV/ARB(target mismatch)");
123 return;
124 }
125 }
126
127 /** All error checking is complete now **/
128
129 if (curProg->Id == id) {
130 /* binding same program - no change */
131 return;
132 }
133
Brian Paul027ed1b2009-04-24 09:43:44 -0600134 /* signal new program (and its new constants) */
135 FLUSH_VERTICES(ctx, _NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS);
136
Brian Paulb7eea9a2008-07-29 17:19:25 -0600137 /* bind newProg */
138 if (target == GL_VERTEX_PROGRAM_ARB) { /* == GL_VERTEX_PROGRAM_NV */
139 _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current,
140 (struct gl_vertex_program *) newProg);
141 }
142 else if (target == GL_FRAGMENT_PROGRAM_NV ||
143 target == GL_FRAGMENT_PROGRAM_ARB) {
144 _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current,
145 (struct gl_fragment_program *) newProg);
146 }
147
148 /* Never null pointers */
149 ASSERT(ctx->VertexProgram.Current);
150 ASSERT(ctx->FragmentProgram.Current);
151
152 if (ctx->Driver.BindProgram)
153 ctx->Driver.BindProgram(ctx, target, newProg);
154}
155
156
157/**
158 * Delete a list of programs.
159 * \note Not compiled into display lists.
160 * \note Called by both glDeleteProgramsNV and glDeleteProgramsARB.
161 */
162void GLAPIENTRY
163_mesa_DeletePrograms(GLsizei n, const GLuint *ids)
164{
165 GLint i;
166 GET_CURRENT_CONTEXT(ctx);
167 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
168
169 if (n < 0) {
170 _mesa_error( ctx, GL_INVALID_VALUE, "glDeleteProgramsNV" );
171 return;
172 }
173
174 for (i = 0; i < n; i++) {
175 if (ids[i] != 0) {
176 struct gl_program *prog = _mesa_lookup_program(ctx, ids[i]);
177 if (prog == &_mesa_DummyProgram) {
178 _mesa_HashRemove(ctx->Shared->Programs, ids[i]);
179 }
180 else if (prog) {
181 /* Unbind program if necessary */
182 if (prog->Target == GL_VERTEX_PROGRAM_ARB || /* == GL_VERTEX_PROGRAM_NV */
183 prog->Target == GL_VERTEX_STATE_PROGRAM_NV) {
184 if (ctx->VertexProgram.Current &&
185 ctx->VertexProgram.Current->Base.Id == ids[i]) {
186 /* unbind this currently bound program */
187 _mesa_BindProgram(prog->Target, 0);
188 }
189 }
190 else if (prog->Target == GL_FRAGMENT_PROGRAM_NV ||
191 prog->Target == GL_FRAGMENT_PROGRAM_ARB) {
192 if (ctx->FragmentProgram.Current &&
193 ctx->FragmentProgram.Current->Base.Id == ids[i]) {
194 /* unbind this currently bound program */
195 _mesa_BindProgram(prog->Target, 0);
196 }
197 }
198 else {
199 _mesa_problem(ctx, "bad target in glDeleteProgramsNV");
200 return;
201 }
202 /* The ID is immediately available for re-use now */
203 _mesa_HashRemove(ctx->Shared->Programs, ids[i]);
204 _mesa_reference_program(ctx, &prog, NULL);
205 }
206 }
207 }
208}
209
210
211/**
212 * Generate a list of new program identifiers.
213 * \note Not compiled into display lists.
214 * \note Called by both glGenProgramsNV and glGenProgramsARB.
215 */
216void GLAPIENTRY
217_mesa_GenPrograms(GLsizei n, GLuint *ids)
218{
219 GLuint first;
220 GLuint i;
221 GET_CURRENT_CONTEXT(ctx);
222 ASSERT_OUTSIDE_BEGIN_END(ctx);
223
224 if (n < 0) {
225 _mesa_error(ctx, GL_INVALID_VALUE, "glGenPrograms");
226 return;
227 }
228
229 if (!ids)
230 return;
231
232 first = _mesa_HashFindFreeKeyBlock(ctx->Shared->Programs, n);
233
234 /* Insert pointer to dummy program as placeholder */
235 for (i = 0; i < (GLuint) n; i++) {
236 _mesa_HashInsert(ctx->Shared->Programs, first + i, &_mesa_DummyProgram);
237 }
238
239 /* Return the program names */
240 for (i = 0; i < (GLuint) n; i++) {
241 ids[i] = first + i;
242 }
243}
244
245
Michal Krol157ec8b2004-03-10 18:02:01 +0000246void GLAPIENTRY
247_mesa_EnableVertexAttribArrayARB(GLuint index)
248{
249 GET_CURRENT_CONTEXT(ctx);
250 ASSERT_OUTSIDE_BEGIN_END(ctx);
251
Brian Paul05051032005-11-01 04:36:33 +0000252 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000253 _mesa_error(ctx, GL_INVALID_VALUE,
254 "glEnableVertexAttribArrayARB(index)");
255 return;
256 }
257
Brian Paula545f1a2009-05-22 07:51:35 -0600258 ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
259
Michal Krol157ec8b2004-03-10 18:02:01 +0000260 FLUSH_VERTICES(ctx, _NEW_ARRAY);
Ian Romanickee34e6e2006-06-12 16:26:29 +0000261 ctx->Array.ArrayObj->VertexAttrib[index].Enabled = GL_TRUE;
262 ctx->Array.ArrayObj->_Enabled |= _NEW_ARRAY_ATTRIB(index);
Michal Krol157ec8b2004-03-10 18:02:01 +0000263 ctx->Array.NewState |= _NEW_ARRAY_ATTRIB(index);
264}
265
266
267void GLAPIENTRY
268_mesa_DisableVertexAttribArrayARB(GLuint index)
269{
270 GET_CURRENT_CONTEXT(ctx);
271 ASSERT_OUTSIDE_BEGIN_END(ctx);
272
Brian Paul05051032005-11-01 04:36:33 +0000273 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000274 _mesa_error(ctx, GL_INVALID_VALUE,
275 "glEnableVertexAttribArrayARB(index)");
276 return;
277 }
278
Brian Paula545f1a2009-05-22 07:51:35 -0600279 ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
280
Michal Krol157ec8b2004-03-10 18:02:01 +0000281 FLUSH_VERTICES(ctx, _NEW_ARRAY);
Ian Romanickee34e6e2006-06-12 16:26:29 +0000282 ctx->Array.ArrayObj->VertexAttrib[index].Enabled = GL_FALSE;
283 ctx->Array.ArrayObj->_Enabled &= ~_NEW_ARRAY_ATTRIB(index);
Michal Krol157ec8b2004-03-10 18:02:01 +0000284 ctx->Array.NewState |= _NEW_ARRAY_ATTRIB(index);
285}
286
287
288void GLAPIENTRY
289_mesa_GetVertexAttribdvARB(GLuint index, GLenum pname, GLdouble *params)
290{
291 GLfloat fparams[4];
292 GET_CURRENT_CONTEXT(ctx);
293 ASSERT_OUTSIDE_BEGIN_END(ctx);
294
295 _mesa_GetVertexAttribfvARB(index, pname, fparams);
296 if (ctx->ErrorValue == GL_NO_ERROR) {
297 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
298 COPY_4V(params, fparams);
299 }
300 else {
301 params[0] = fparams[0];
302 }
303 }
304}
305
306
Brian Paul024de602009-05-21 16:02:50 -0600307/**
308 * Return info for a generic vertex attribute array (no alias with
309 * legacy vertex attributes (pos, normal, color, etc)).
310 */
Michal Krol157ec8b2004-03-10 18:02:01 +0000311void GLAPIENTRY
312_mesa_GetVertexAttribfvARB(GLuint index, GLenum pname, GLfloat *params)
313{
Brian Paul254845f2009-05-21 15:57:29 -0600314 const struct gl_client_array *array;
Michal Krol157ec8b2004-03-10 18:02:01 +0000315 GET_CURRENT_CONTEXT(ctx);
316 ASSERT_OUTSIDE_BEGIN_END(ctx);
317
Brian Paul882cd6c2009-05-22 07:30:05 -0600318 if (index >= MAX_VERTEX_GENERIC_ATTRIBS) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000319 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribfvARB(index)");
320 return;
321 }
322
Brian Paula545f1a2009-05-22 07:51:35 -0600323 ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
324
Brian Paul254845f2009-05-21 15:57:29 -0600325 array = &ctx->Array.ArrayObj->VertexAttrib[index];
326
Michal Krol157ec8b2004-03-10 18:02:01 +0000327 switch (pname) {
328 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
Brian Paul254845f2009-05-21 15:57:29 -0600329 params[0] = (GLfloat) array->Enabled;
Michal Krol157ec8b2004-03-10 18:02:01 +0000330 break;
331 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
Brian Paul254845f2009-05-21 15:57:29 -0600332 params[0] = (GLfloat) array->Size;
Michal Krol157ec8b2004-03-10 18:02:01 +0000333 break;
334 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
Brian Paul254845f2009-05-21 15:57:29 -0600335 params[0] = (GLfloat) array->Stride;
Michal Krol157ec8b2004-03-10 18:02:01 +0000336 break;
337 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
Brian Paul254845f2009-05-21 15:57:29 -0600338 params[0] = (GLfloat) array->Type;
Michal Krol157ec8b2004-03-10 18:02:01 +0000339 break;
340 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
Brian Paul254845f2009-05-21 15:57:29 -0600341 params[0] = array->Normalized;
Michal Krol157ec8b2004-03-10 18:02:01 +0000342 break;
343 case GL_CURRENT_VERTEX_ATTRIB_ARB:
Brian Paul590b5572006-11-04 17:28:38 +0000344 if (index == 0) {
345 _mesa_error(ctx, GL_INVALID_OPERATION,
Brian Pauladf3a642006-11-04 17:31:21 +0000346 "glGetVertexAttribfvARB(index==0)");
Brian Paul590b5572006-11-04 17:28:38 +0000347 return;
348 }
Michal Krolbb38cad2006-04-11 11:41:11 +0000349 FLUSH_CURRENT(ctx, 0);
350 COPY_4V(params, ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + index]);
Michal Krol157ec8b2004-03-10 18:02:01 +0000351 break;
352 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
Brian Paul254845f2009-05-21 15:57:29 -0600353 params[0] = (GLfloat) array->BufferObj->Name;
Tilman Sauerbeck6be81272006-05-30 16:57:52 +0000354 break;
Michal Krol157ec8b2004-03-10 18:02:01 +0000355 default:
356 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribfvARB(pname)");
357 return;
358 }
359}
360
361
362void GLAPIENTRY
363_mesa_GetVertexAttribivARB(GLuint index, GLenum pname, GLint *params)
364{
365 GLfloat fparams[4];
366 GET_CURRENT_CONTEXT(ctx);
367 ASSERT_OUTSIDE_BEGIN_END(ctx);
368
369 _mesa_GetVertexAttribfvARB(index, pname, fparams);
370 if (ctx->ErrorValue == GL_NO_ERROR) {
371 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
372 COPY_4V_CAST(params, fparams, GLint); /* float to int */
373 }
374 else {
375 params[0] = (GLint) fparams[0];
376 }
377 }
378}
379
380
381void GLAPIENTRY
382_mesa_GetVertexAttribPointervARB(GLuint index, GLenum pname, GLvoid **pointer)
383{
384 GET_CURRENT_CONTEXT(ctx);
385 ASSERT_OUTSIDE_BEGIN_END(ctx);
386
Brian Paul05051032005-11-01 04:36:33 +0000387 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000388 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
389 return;
390 }
391
392 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
393 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
394 return;
395 }
396
Brian Paula545f1a2009-05-22 07:51:35 -0600397 ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
398
Ian Romanickee34e6e2006-06-12 16:26:29 +0000399 *pointer = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[index].Ptr;
Michal Krol157ec8b2004-03-10 18:02:01 +0000400}
401
402
Brian Paulf49c0d02006-11-02 16:20:29 +0000403/**
404 * Determine if id names a vertex or fragment program.
405 * \note Not compiled into display lists.
406 * \note Called from both glIsProgramNV and glIsProgramARB.
407 * \param id is the program identifier
408 * \return GL_TRUE if id is a program, else GL_FALSE.
409 */
410GLboolean GLAPIENTRY
411_mesa_IsProgramARB(GLuint id)
412{
Brian Paul308b85f2006-11-23 15:58:30 +0000413 struct gl_program *prog = NULL;
Brian Paulf49c0d02006-11-02 16:20:29 +0000414 GET_CURRENT_CONTEXT(ctx);
415 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
416
417 if (id == 0)
418 return GL_FALSE;
419
Brian Paul308b85f2006-11-23 15:58:30 +0000420 prog = _mesa_lookup_program(ctx, id);
421 if (prog && (prog != &_mesa_DummyProgram))
Brian Paulf49c0d02006-11-02 16:20:29 +0000422 return GL_TRUE;
423 else
424 return GL_FALSE;
425}
426
427
Michal Krol157ec8b2004-03-10 18:02:01 +0000428void GLAPIENTRY
429_mesa_ProgramStringARB(GLenum target, GLenum format, GLsizei len,
430 const GLvoid *string)
431{
Ian Romanick74528772009-11-02 13:37:47 -0800432 struct gl_program *base;
Michal Krol157ec8b2004-03-10 18:02:01 +0000433 GET_CURRENT_CONTEXT(ctx);
434 ASSERT_OUTSIDE_BEGIN_END(ctx);
435
436 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
437
Brian Paul8c41a142005-11-19 15:36:28 +0000438 if (format != GL_PROGRAM_FORMAT_ASCII_ARB) {
439 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramStringARB(format)");
440 return;
441 }
442
Michal Krol157ec8b2004-03-10 18:02:01 +0000443 if (target == GL_VERTEX_PROGRAM_ARB
444 && ctx->Extensions.ARB_vertex_program) {
Brian Paul122629f2006-07-20 16:49:57 +0000445 struct gl_vertex_program *prog = ctx->VertexProgram.Current;
Brian Paul8c41a142005-11-19 15:36:28 +0000446 _mesa_parse_arb_vertex_program(ctx, target, string, len, prog);
Ian Romanick74528772009-11-02 13:37:47 -0800447
448 base = & prog->Base;
Michal Krol157ec8b2004-03-10 18:02:01 +0000449 }
450 else if (target == GL_FRAGMENT_PROGRAM_ARB
451 && ctx->Extensions.ARB_fragment_program) {
Brian Paul122629f2006-07-20 16:49:57 +0000452 struct gl_fragment_program *prog = ctx->FragmentProgram.Current;
Brian Paul8c41a142005-11-19 15:36:28 +0000453 _mesa_parse_arb_fragment_program(ctx, target, string, len, prog);
Michal Krol157ec8b2004-03-10 18:02:01 +0000454
Ian Romanick74528772009-11-02 13:37:47 -0800455 base = & prog->Base;
456 }
457 else if (target == GL_FRAGMENT_PROGRAM_NV
458 && ctx->Extensions.NV_fragment_program) {
459 struct gl_fragment_program *prog = ctx->FragmentProgram.Current;
460 _mesa_parse_nv_fragment_program(ctx, target, string, len, prog);
461
462 base = & prog->Base;
Michal Krol157ec8b2004-03-10 18:02:01 +0000463 }
464 else {
465 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramStringARB(target)");
466 return;
467 }
Ian Romanick74528772009-11-02 13:37:47 -0800468
469 if (ctx->Program.ErrorPos == -1 && ctx->Driver.ProgramStringNotify)
470 ctx->Driver.ProgramStringNotify( ctx, target, base );
Michal Krol157ec8b2004-03-10 18:02:01 +0000471}
472
473
Roland Scheidegger86a48102007-11-09 14:46:59 +0100474/**
475 * Set a program env parameter register.
476 * \note Called from the GL API dispatcher.
477 * Note, this function is also used by the GL_NV_vertex_program extension
478 * (alias to ProgramParameterdNV)
479 */
Michal Krol157ec8b2004-03-10 18:02:01 +0000480void GLAPIENTRY
481_mesa_ProgramEnvParameter4dARB(GLenum target, GLuint index,
482 GLdouble x, GLdouble y, GLdouble z, GLdouble w)
483{
484 _mesa_ProgramEnvParameter4fARB(target, index, (GLfloat) x, (GLfloat) y,
485 (GLfloat) z, (GLfloat) w);
486}
487
488
Roland Scheidegger86a48102007-11-09 14:46:59 +0100489/**
490 * Set a program env parameter register.
491 * \note Called from the GL API dispatcher.
492 * Note, this function is also used by the GL_NV_vertex_program extension
493 * (alias to ProgramParameterdvNV)
494 */
Michal Krol157ec8b2004-03-10 18:02:01 +0000495void GLAPIENTRY
496_mesa_ProgramEnvParameter4dvARB(GLenum target, GLuint index,
497 const GLdouble *params)
498{
499 _mesa_ProgramEnvParameter4fARB(target, index, (GLfloat) params[0],
500 (GLfloat) params[1], (GLfloat) params[2],
501 (GLfloat) params[3]);
502}
503
504
Roland Scheidegger86a48102007-11-09 14:46:59 +0100505/**
506 * Set a program env parameter register.
507 * \note Called from the GL API dispatcher.
508 * Note, this function is also used by the GL_NV_vertex_program extension
509 * (alias to ProgramParameterfNV)
510 */
Michal Krol157ec8b2004-03-10 18:02:01 +0000511void GLAPIENTRY
512_mesa_ProgramEnvParameter4fARB(GLenum target, GLuint index,
513 GLfloat x, GLfloat y, GLfloat z, GLfloat w)
514{
515 GET_CURRENT_CONTEXT(ctx);
516 ASSERT_OUTSIDE_BEGIN_END(ctx);
517
Brian Paul027ed1b2009-04-24 09:43:44 -0600518 FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
Michal Krol157ec8b2004-03-10 18:02:01 +0000519
520 if (target == GL_FRAGMENT_PROGRAM_ARB
521 && ctx->Extensions.ARB_fragment_program) {
Brian Paul05051032005-11-01 04:36:33 +0000522 if (index >= ctx->Const.FragmentProgram.MaxEnvParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000523 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameter(index)");
524 return;
525 }
526 ASSIGN_4V(ctx->FragmentProgram.Parameters[index], x, y, z, w);
527 }
Roland Scheidegger86a48102007-11-09 14:46:59 +0100528 else if (target == GL_VERTEX_PROGRAM_ARB /* == GL_VERTEX_PROGRAM_NV */
529 && (ctx->Extensions.ARB_vertex_program || ctx->Extensions.NV_vertex_program)) {
Brian Paul05051032005-11-01 04:36:33 +0000530 if (index >= ctx->Const.VertexProgram.MaxEnvParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000531 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameter(index)");
532 return;
533 }
534 ASSIGN_4V(ctx->VertexProgram.Parameters[index], x, y, z, w);
535 }
536 else {
537 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramEnvParameter(target)");
538 return;
539 }
540}
541
Roland Scheidegger86a48102007-11-09 14:46:59 +0100542/**
543 * Set a program env parameter register.
544 * \note Called from the GL API dispatcher.
545 * Note, this function is also used by the GL_NV_vertex_program extension
546 * (alias to ProgramParameterfvNV)
547 */
Michal Krol157ec8b2004-03-10 18:02:01 +0000548void GLAPIENTRY
549_mesa_ProgramEnvParameter4fvARB(GLenum target, GLuint index,
550 const GLfloat *params)
551{
552 _mesa_ProgramEnvParameter4fARB(target, index, params[0], params[1],
553 params[2], params[3]);
554}
555
556
557void GLAPIENTRY
Ian Romanick8c41c752006-08-15 16:47:34 +0000558_mesa_ProgramEnvParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
559 const GLfloat *params)
560{
561 GET_CURRENT_CONTEXT(ctx);
Brian223d7cb2007-01-23 16:37:51 -0700562 GLint i;
Ian Romanick8c41c752006-08-15 16:47:34 +0000563 GLfloat * dest;
564 ASSERT_OUTSIDE_BEGIN_END(ctx);
565
Brian Paul027ed1b2009-04-24 09:43:44 -0600566 FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
Ian Romanick8c41c752006-08-15 16:47:34 +0000567
568 if (count <= 0) {
569 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameters4fv(count)");
570 }
571
572 if (target == GL_FRAGMENT_PROGRAM_ARB
573 && ctx->Extensions.ARB_fragment_program) {
574 if ((index + count) > ctx->Const.FragmentProgram.MaxEnvParams) {
575 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameters4fv(index + count)");
576 return;
577 }
578 dest = ctx->FragmentProgram.Parameters[index];
579 }
580 else if (target == GL_VERTEX_PROGRAM_ARB
581 && ctx->Extensions.ARB_vertex_program) {
582 if ((index + count) > ctx->Const.VertexProgram.MaxEnvParams) {
583 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameters4fv(index + count)");
584 return;
585 }
586 dest = ctx->VertexProgram.Parameters[index];
587 }
588 else {
589 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramEnvParameters4fv(target)");
590 return;
591 }
592
593 for ( i = 0 ; i < count ; i++ ) {
594 COPY_4V(dest, params);
595 params += 4;
596 dest += 4;
597 }
598}
599
600
601void GLAPIENTRY
Michal Krol157ec8b2004-03-10 18:02:01 +0000602_mesa_GetProgramEnvParameterdvARB(GLenum target, GLuint index,
603 GLdouble *params)
604{
605 GET_CURRENT_CONTEXT(ctx);
606 GLfloat fparams[4];
607
608 _mesa_GetProgramEnvParameterfvARB(target, index, fparams);
609 if (ctx->ErrorValue == GL_NO_ERROR) {
610 params[0] = fparams[0];
611 params[1] = fparams[1];
612 params[2] = fparams[2];
613 params[3] = fparams[3];
614 }
615}
616
617
618void GLAPIENTRY
619_mesa_GetProgramEnvParameterfvARB(GLenum target, GLuint index,
620 GLfloat *params)
621{
622 GET_CURRENT_CONTEXT(ctx);
623
Brian Paul548be382009-03-11 20:08:37 -0600624 ASSERT_OUTSIDE_BEGIN_END(ctx);
Michal Krol157ec8b2004-03-10 18:02:01 +0000625
626 if (target == GL_FRAGMENT_PROGRAM_ARB
627 && ctx->Extensions.ARB_fragment_program) {
Brian Paul05051032005-11-01 04:36:33 +0000628 if (index >= ctx->Const.FragmentProgram.MaxEnvParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000629 _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramEnvParameter(index)");
630 return;
631 }
632 COPY_4V(params, ctx->FragmentProgram.Parameters[index]);
633 }
Brian Paul83c74b72004-10-16 00:29:03 +0000634 else if (target == GL_VERTEX_PROGRAM_ARB
Michal Krol157ec8b2004-03-10 18:02:01 +0000635 && ctx->Extensions.ARB_vertex_program) {
Brian Paul05051032005-11-01 04:36:33 +0000636 if (index >= ctx->Const.VertexProgram.MaxEnvParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000637 _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramEnvParameter(index)");
638 return;
639 }
640 COPY_4V(params, ctx->VertexProgram.Parameters[index]);
641 }
642 else {
643 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramEnvParameter(target)");
644 return;
645 }
646}
647
648
649/**
650 * Note, this function is also used by the GL_NV_fragment_program extension.
651 */
652void GLAPIENTRY
653_mesa_ProgramLocalParameter4fARB(GLenum target, GLuint index,
654 GLfloat x, GLfloat y, GLfloat z, GLfloat w)
655{
656 GET_CURRENT_CONTEXT(ctx);
Brian Paul122629f2006-07-20 16:49:57 +0000657 struct gl_program *prog;
Michal Krol157ec8b2004-03-10 18:02:01 +0000658 ASSERT_OUTSIDE_BEGIN_END(ctx);
659
Brian Paul027ed1b2009-04-24 09:43:44 -0600660 FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
Michal Krol157ec8b2004-03-10 18:02:01 +0000661
662 if ((target == GL_FRAGMENT_PROGRAM_NV
663 && ctx->Extensions.NV_fragment_program) ||
664 (target == GL_FRAGMENT_PROGRAM_ARB
665 && ctx->Extensions.ARB_fragment_program)) {
Brian Paul05051032005-11-01 04:36:33 +0000666 if (index >= ctx->Const.FragmentProgram.MaxLocalParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000667 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameterARB");
668 return;
669 }
670 prog = &(ctx->FragmentProgram.Current->Base);
671 }
672 else if (target == GL_VERTEX_PROGRAM_ARB
673 && ctx->Extensions.ARB_vertex_program) {
Brian Paul05051032005-11-01 04:36:33 +0000674 if (index >= ctx->Const.VertexProgram.MaxLocalParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000675 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameterARB");
676 return;
677 }
678 prog = &(ctx->VertexProgram.Current->Base);
679 }
680 else {
681 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameterARB");
682 return;
683 }
684
685 ASSERT(index < MAX_PROGRAM_LOCAL_PARAMS);
686 prog->LocalParams[index][0] = x;
687 prog->LocalParams[index][1] = y;
688 prog->LocalParams[index][2] = z;
689 prog->LocalParams[index][3] = w;
690}
691
692
693/**
694 * Note, this function is also used by the GL_NV_fragment_program extension.
695 */
696void GLAPIENTRY
697_mesa_ProgramLocalParameter4fvARB(GLenum target, GLuint index,
698 const GLfloat *params)
699{
700 _mesa_ProgramLocalParameter4fARB(target, index, params[0], params[1],
701 params[2], params[3]);
702}
703
704
Ian Romanick8c41c752006-08-15 16:47:34 +0000705void GLAPIENTRY
706_mesa_ProgramLocalParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
707 const GLfloat *params)
708{
709 GET_CURRENT_CONTEXT(ctx);
710 struct gl_program *prog;
Brian223d7cb2007-01-23 16:37:51 -0700711 GLint i;
Ian Romanick8c41c752006-08-15 16:47:34 +0000712 ASSERT_OUTSIDE_BEGIN_END(ctx);
713
Brian Paul027ed1b2009-04-24 09:43:44 -0600714 FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
Ian Romanick8c41c752006-08-15 16:47:34 +0000715
716 if (count <= 0) {
717 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fv(count)");
718 }
719
720 if (target == GL_FRAGMENT_PROGRAM_ARB
721 && ctx->Extensions.ARB_fragment_program) {
722 if ((index + count) > ctx->Const.FragmentProgram.MaxLocalParams) {
723 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fvEXT(index + count)");
724 return;
725 }
726 prog = &(ctx->FragmentProgram.Current->Base);
727 }
728 else if (target == GL_VERTEX_PROGRAM_ARB
729 && ctx->Extensions.ARB_vertex_program) {
730 if ((index + count) > ctx->Const.VertexProgram.MaxLocalParams) {
731 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fvEXT(index + count)");
732 return;
733 }
734 prog = &(ctx->VertexProgram.Current->Base);
735 }
736 else {
737 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameters4fvEXT(target)");
738 return;
739 }
740
741 for (i = 0; i < count; i++) {
742 ASSERT((index + i) < MAX_PROGRAM_LOCAL_PARAMS);
743 COPY_4V(prog->LocalParams[index + i], params);
744 params += 4;
745 }
746}
747
748
Michal Krol157ec8b2004-03-10 18:02:01 +0000749/**
750 * Note, this function is also used by the GL_NV_fragment_program extension.
751 */
752void GLAPIENTRY
753_mesa_ProgramLocalParameter4dARB(GLenum target, GLuint index,
754 GLdouble x, GLdouble y,
755 GLdouble z, GLdouble w)
756{
757 _mesa_ProgramLocalParameter4fARB(target, index, (GLfloat) x, (GLfloat) y,
758 (GLfloat) z, (GLfloat) w);
759}
760
761
762/**
763 * Note, this function is also used by the GL_NV_fragment_program extension.
764 */
765void GLAPIENTRY
766_mesa_ProgramLocalParameter4dvARB(GLenum target, GLuint index,
767 const GLdouble *params)
768{
769 _mesa_ProgramLocalParameter4fARB(target, index,
770 (GLfloat) params[0], (GLfloat) params[1],
771 (GLfloat) params[2], (GLfloat) params[3]);
772}
773
774
775/**
776 * Note, this function is also used by the GL_NV_fragment_program extension.
777 */
778void GLAPIENTRY
779_mesa_GetProgramLocalParameterfvARB(GLenum target, GLuint index,
780 GLfloat *params)
781{
Brian Paul122629f2006-07-20 16:49:57 +0000782 const struct gl_program *prog;
Michal Krol157ec8b2004-03-10 18:02:01 +0000783 GLuint maxParams;
784 GET_CURRENT_CONTEXT(ctx);
785 ASSERT_OUTSIDE_BEGIN_END(ctx);
786
787 if (target == GL_VERTEX_PROGRAM_ARB
788 && ctx->Extensions.ARB_vertex_program) {
789 prog = &(ctx->VertexProgram.Current->Base);
Brian Paul05051032005-11-01 04:36:33 +0000790 maxParams = ctx->Const.VertexProgram.MaxLocalParams;
Michal Krol157ec8b2004-03-10 18:02:01 +0000791 }
792 else if (target == GL_FRAGMENT_PROGRAM_ARB
793 && ctx->Extensions.ARB_fragment_program) {
794 prog = &(ctx->FragmentProgram.Current->Base);
Brian Paul05051032005-11-01 04:36:33 +0000795 maxParams = ctx->Const.FragmentProgram.MaxLocalParams;
Michal Krol157ec8b2004-03-10 18:02:01 +0000796 }
797 else if (target == GL_FRAGMENT_PROGRAM_NV
798 && ctx->Extensions.NV_fragment_program) {
799 prog = &(ctx->FragmentProgram.Current->Base);
800 maxParams = MAX_NV_FRAGMENT_PROGRAM_PARAMS;
801 }
802 else {
803 _mesa_error(ctx, GL_INVALID_ENUM,
804 "glGetProgramLocalParameterARB(target)");
805 return;
806 }
807
808 if (index >= maxParams) {
809 _mesa_error(ctx, GL_INVALID_VALUE,
810 "glGetProgramLocalParameterARB(index)");
811 return;
812 }
813
814 ASSERT(prog);
815 ASSERT(index < MAX_PROGRAM_LOCAL_PARAMS);
816 COPY_4V(params, prog->LocalParams[index]);
817}
818
819
820/**
821 * Note, this function is also used by the GL_NV_fragment_program extension.
822 */
823void GLAPIENTRY
824_mesa_GetProgramLocalParameterdvARB(GLenum target, GLuint index,
825 GLdouble *params)
826{
827 GET_CURRENT_CONTEXT(ctx);
828 GLfloat floatParams[4];
Brian Pauleb26cc62009-01-20 09:17:12 -0700829 ASSIGN_4V(floatParams, 0.0F, 0.0F, 0.0F, 0.0F);
Michal Krol157ec8b2004-03-10 18:02:01 +0000830 _mesa_GetProgramLocalParameterfvARB(target, index, floatParams);
831 if (ctx->ErrorValue == GL_NO_ERROR) {
832 COPY_4V(params, floatParams);
833 }
834}
835
836
837void GLAPIENTRY
838_mesa_GetProgramivARB(GLenum target, GLenum pname, GLint *params)
839{
Brian Paul05051032005-11-01 04:36:33 +0000840 const struct gl_program_constants *limits;
Brian Paul122629f2006-07-20 16:49:57 +0000841 struct gl_program *prog;
Michal Krol157ec8b2004-03-10 18:02:01 +0000842 GET_CURRENT_CONTEXT(ctx);
843
Brian Paul548be382009-03-11 20:08:37 -0600844 ASSERT_OUTSIDE_BEGIN_END(ctx);
Michal Krol157ec8b2004-03-10 18:02:01 +0000845
846 if (target == GL_VERTEX_PROGRAM_ARB
847 && ctx->Extensions.ARB_vertex_program) {
848 prog = &(ctx->VertexProgram.Current->Base);
Brian Paul05051032005-11-01 04:36:33 +0000849 limits = &ctx->Const.VertexProgram;
Michal Krol157ec8b2004-03-10 18:02:01 +0000850 }
851 else if (target == GL_FRAGMENT_PROGRAM_ARB
852 && ctx->Extensions.ARB_fragment_program) {
853 prog = &(ctx->FragmentProgram.Current->Base);
Brian Paul05051032005-11-01 04:36:33 +0000854 limits = &ctx->Const.FragmentProgram;
Michal Krol157ec8b2004-03-10 18:02:01 +0000855 }
856 else {
857 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(target)");
858 return;
859 }
860
861 ASSERT(prog);
Brian Paul05051032005-11-01 04:36:33 +0000862 ASSERT(limits);
Michal Krol157ec8b2004-03-10 18:02:01 +0000863
Brian Paul05051032005-11-01 04:36:33 +0000864 /* Queries supported for both vertex and fragment programs */
Michal Krol157ec8b2004-03-10 18:02:01 +0000865 switch (pname) {
866 case GL_PROGRAM_LENGTH_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000867 *params
868 = prog->String ? (GLint) _mesa_strlen((char *) prog->String) : 0;
869 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000870 case GL_PROGRAM_FORMAT_ARB:
871 *params = prog->Format;
Brian Paul05051032005-11-01 04:36:33 +0000872 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000873 case GL_PROGRAM_BINDING_ARB:
874 *params = prog->Id;
Brian Paul05051032005-11-01 04:36:33 +0000875 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000876 case GL_PROGRAM_INSTRUCTIONS_ARB:
877 *params = prog->NumInstructions;
Brian Paul05051032005-11-01 04:36:33 +0000878 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000879 case GL_MAX_PROGRAM_INSTRUCTIONS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000880 *params = limits->MaxInstructions;
881 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000882 case GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000883 *params = prog->NumNativeInstructions;
884 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000885 case GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000886 *params = limits->MaxNativeInstructions;
887 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000888 case GL_PROGRAM_TEMPORARIES_ARB:
889 *params = prog->NumTemporaries;
Brian Paul05051032005-11-01 04:36:33 +0000890 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000891 case GL_MAX_PROGRAM_TEMPORARIES_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000892 *params = limits->MaxTemps;
893 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000894 case GL_PROGRAM_NATIVE_TEMPORARIES_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000895 *params = prog->NumNativeTemporaries;
896 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000897 case GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000898 *params = limits->MaxNativeTemps;
899 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000900 case GL_PROGRAM_PARAMETERS_ARB:
901 *params = prog->NumParameters;
Brian Paul05051032005-11-01 04:36:33 +0000902 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000903 case GL_MAX_PROGRAM_PARAMETERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000904 *params = limits->MaxParameters;
905 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000906 case GL_PROGRAM_NATIVE_PARAMETERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000907 *params = prog->NumNativeParameters;
908 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000909 case GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000910 *params = limits->MaxNativeParameters;
911 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000912 case GL_PROGRAM_ATTRIBS_ARB:
913 *params = prog->NumAttributes;
Brian Paul05051032005-11-01 04:36:33 +0000914 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000915 case GL_MAX_PROGRAM_ATTRIBS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000916 *params = limits->MaxAttribs;
917 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000918 case GL_PROGRAM_NATIVE_ATTRIBS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000919 *params = prog->NumNativeAttributes;
920 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000921 case GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000922 *params = limits->MaxNativeAttribs;
923 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000924 case GL_PROGRAM_ADDRESS_REGISTERS_ARB:
925 *params = prog->NumAddressRegs;
Brian Paul05051032005-11-01 04:36:33 +0000926 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000927 case GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000928 *params = limits->MaxAddressRegs;
929 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000930 case GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000931 *params = prog->NumNativeAddressRegs;
932 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000933 case GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000934 *params = limits->MaxNativeAddressRegs;
935 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000936 case GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000937 *params = limits->MaxLocalParams;
938 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000939 case GL_MAX_PROGRAM_ENV_PARAMETERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000940 *params = limits->MaxEnvParams;
941 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000942 case GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000943 /*
944 * XXX we may not really need a driver callback here.
945 * If the number of native instructions, registers, etc. used
946 * are all below the maximums, we could return true.
947 * The spec says that even if this query returns true, there's
948 * no guarantee that the program will run in hardware.
949 */
Brian4ca7c802007-04-28 08:01:18 -0600950 if (prog->Id == 0) {
951 /* default/null program */
952 *params = GL_FALSE;
953 }
954 else if (ctx->Driver.IsProgramNative) {
955 /* ask the driver */
Michal Krol157ec8b2004-03-10 18:02:01 +0000956 *params = ctx->Driver.IsProgramNative( ctx, target, prog );
Brian4ca7c802007-04-28 08:01:18 -0600957 }
958 else {
959 /* probably running in software */
Michal Krol157ec8b2004-03-10 18:02:01 +0000960 *params = GL_TRUE;
Brian4ca7c802007-04-28 08:01:18 -0600961 }
Michal Krol157ec8b2004-03-10 18:02:01 +0000962 return;
Brian Paul05051032005-11-01 04:36:33 +0000963 default:
964 /* continue with fragment-program only queries below */
965 break;
966 }
967
968 /*
969 * The following apply to fragment programs only (at this time)
970 */
971 if (target == GL_FRAGMENT_PROGRAM_ARB) {
Brian Paul122629f2006-07-20 16:49:57 +0000972 const struct gl_fragment_program *fp = ctx->FragmentProgram.Current;
Brian Paul05051032005-11-01 04:36:33 +0000973 switch (pname) {
974 case GL_PROGRAM_ALU_INSTRUCTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700975 *params = fp->Base.NumNativeAluInstructions;
Brian Paul05051032005-11-01 04:36:33 +0000976 return;
977 case GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700978 *params = fp->Base.NumAluInstructions;
Brian Paul05051032005-11-01 04:36:33 +0000979 return;
980 case GL_PROGRAM_TEX_INSTRUCTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700981 *params = fp->Base.NumTexInstructions;
Brian Paul05051032005-11-01 04:36:33 +0000982 return;
983 case GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700984 *params = fp->Base.NumNativeTexInstructions;
Brian Paul05051032005-11-01 04:36:33 +0000985 return;
986 case GL_PROGRAM_TEX_INDIRECTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700987 *params = fp->Base.NumTexIndirections;
Brian Paul05051032005-11-01 04:36:33 +0000988 return;
989 case GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700990 *params = fp->Base.NumNativeTexIndirections;
Brian Paul05051032005-11-01 04:36:33 +0000991 return;
992 case GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB:
993 *params = limits->MaxAluInstructions;
994 return;
995 case GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB:
996 *params = limits->MaxNativeAluInstructions;
997 return;
998 case GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB:
999 *params = limits->MaxTexInstructions;
1000 return;
1001 case GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB:
1002 *params = limits->MaxNativeTexInstructions;
1003 return;
1004 case GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB:
1005 *params = limits->MaxTexIndirections;
1006 return;
1007 case GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB:
1008 *params = limits->MaxNativeTexIndirections;
1009 return;
1010 default:
1011 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(pname)");
1012 return;
1013 }
Ian Romanick4bccd692009-08-24 12:48:01 -07001014 } else {
1015 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(pname)");
1016 return;
Michal Krol157ec8b2004-03-10 18:02:01 +00001017 }
1018}
1019
1020
1021void GLAPIENTRY
1022_mesa_GetProgramStringARB(GLenum target, GLenum pname, GLvoid *string)
1023{
Brian Paul122629f2006-07-20 16:49:57 +00001024 const struct gl_program *prog;
Brian Paul308b85f2006-11-23 15:58:30 +00001025 char *dst = (char *) string;
Michal Krol157ec8b2004-03-10 18:02:01 +00001026 GET_CURRENT_CONTEXT(ctx);
1027
Brian Paul548be382009-03-11 20:08:37 -06001028 ASSERT_OUTSIDE_BEGIN_END(ctx);
Michal Krol157ec8b2004-03-10 18:02:01 +00001029
1030 if (target == GL_VERTEX_PROGRAM_ARB) {
1031 prog = &(ctx->VertexProgram.Current->Base);
1032 }
1033 else if (target == GL_FRAGMENT_PROGRAM_ARB) {
1034 prog = &(ctx->FragmentProgram.Current->Base);
1035 }
1036 else {
1037 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramStringARB(target)");
1038 return;
1039 }
1040
1041 ASSERT(prog);
1042
1043 if (pname != GL_PROGRAM_STRING_ARB) {
1044 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramStringARB(pname)");
1045 return;
1046 }
1047
Brian Paul308b85f2006-11-23 15:58:30 +00001048 if (prog->String)
1049 _mesa_memcpy(dst, prog->String, _mesa_strlen((char *) prog->String));
1050 else
1051 *dst = '\0';
Michal Krol157ec8b2004-03-10 18:02:01 +00001052}