blob: 4d8cff070012b46abae9d082679e86d7af31b8dc [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"
Brian Paulf49c0d02006-11-02 16:20:29 +000040#include "program.h"
Michal Krol157ec8b2004-03-10 18:02:01 +000041
42
Brian Paulb7eea9a2008-07-29 17:19:25 -060043
44/**
45 * Mixing ARB and NV vertex/fragment programs can be tricky.
46 * Note: GL_VERTEX_PROGRAM_ARB == GL_VERTEX_PROGRAM_NV
47 * but, GL_FRAGMENT_PROGRAM_ARB != GL_FRAGMENT_PROGRAM_NV
48 * The two different fragment program targets are supposed to be compatible
49 * to some extent (see GL_ARB_fragment_program spec).
50 * This function does the compatibility check.
51 */
52static GLboolean
53compatible_program_targets(GLenum t1, GLenum t2)
54{
55 if (t1 == t2)
56 return GL_TRUE;
57 if (t1 == GL_FRAGMENT_PROGRAM_ARB && t2 == GL_FRAGMENT_PROGRAM_NV)
58 return GL_TRUE;
59 if (t1 == GL_FRAGMENT_PROGRAM_NV && t2 == GL_FRAGMENT_PROGRAM_ARB)
60 return GL_TRUE;
61 return GL_FALSE;
62}
63
64
65/**
66 * Bind a program (make it current)
67 * \note Called from the GL API dispatcher by both glBindProgramNV
68 * and glBindProgramARB.
69 */
70void GLAPIENTRY
71_mesa_BindProgram(GLenum target, GLuint id)
72{
73 struct gl_program *curProg, *newProg;
74 GET_CURRENT_CONTEXT(ctx);
75 ASSERT_OUTSIDE_BEGIN_END(ctx);
76
Brian Paulb7eea9a2008-07-29 17:19:25 -060077 /* Error-check target and get curProg */
78 if ((target == GL_VERTEX_PROGRAM_ARB) && /* == GL_VERTEX_PROGRAM_NV */
79 (ctx->Extensions.NV_vertex_program ||
80 ctx->Extensions.ARB_vertex_program)) {
81 curProg = &ctx->VertexProgram.Current->Base;
82 }
83 else if ((target == GL_FRAGMENT_PROGRAM_NV
84 && ctx->Extensions.NV_fragment_program) ||
85 (target == GL_FRAGMENT_PROGRAM_ARB
86 && ctx->Extensions.ARB_fragment_program)) {
87 curProg = &ctx->FragmentProgram.Current->Base;
88 }
89 else {
90 _mesa_error(ctx, GL_INVALID_ENUM, "glBindProgramNV/ARB(target)");
91 return;
92 }
93
94 /*
95 * Get pointer to new program to bind.
96 * NOTE: binding to a non-existant program is not an error.
97 * That's supposed to be caught in glBegin.
98 */
99 if (id == 0) {
100 /* Bind a default program */
101 newProg = NULL;
102 if (target == GL_VERTEX_PROGRAM_ARB) /* == GL_VERTEX_PROGRAM_NV */
103 newProg = &ctx->Shared->DefaultVertexProgram->Base;
104 else
105 newProg = &ctx->Shared->DefaultFragmentProgram->Base;
106 }
107 else {
108 /* Bind a user program */
109 newProg = _mesa_lookup_program(ctx, id);
110 if (!newProg || newProg == &_mesa_DummyProgram) {
111 /* allocate a new program now */
112 newProg = ctx->Driver.NewProgram(ctx, target, id);
113 if (!newProg) {
114 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindProgramNV/ARB");
115 return;
116 }
117 _mesa_HashInsert(ctx->Shared->Programs, id, newProg);
118 }
119 else if (!compatible_program_targets(newProg->Target, target)) {
120 _mesa_error(ctx, GL_INVALID_OPERATION,
121 "glBindProgramNV/ARB(target mismatch)");
122 return;
123 }
124 }
125
126 /** All error checking is complete now **/
127
128 if (curProg->Id == id) {
129 /* binding same program - no change */
130 return;
131 }
132
Brian Paul027ed1b2009-04-24 09:43:44 -0600133 /* signal new program (and its new constants) */
134 FLUSH_VERTICES(ctx, _NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS);
135
Brian Paulb7eea9a2008-07-29 17:19:25 -0600136 /* bind newProg */
137 if (target == GL_VERTEX_PROGRAM_ARB) { /* == GL_VERTEX_PROGRAM_NV */
138 _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current,
139 (struct gl_vertex_program *) newProg);
140 }
141 else if (target == GL_FRAGMENT_PROGRAM_NV ||
142 target == GL_FRAGMENT_PROGRAM_ARB) {
143 _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current,
144 (struct gl_fragment_program *) newProg);
145 }
146
147 /* Never null pointers */
148 ASSERT(ctx->VertexProgram.Current);
149 ASSERT(ctx->FragmentProgram.Current);
150
151 if (ctx->Driver.BindProgram)
152 ctx->Driver.BindProgram(ctx, target, newProg);
153}
154
155
156/**
157 * Delete a list of programs.
158 * \note Not compiled into display lists.
159 * \note Called by both glDeleteProgramsNV and glDeleteProgramsARB.
160 */
161void GLAPIENTRY
162_mesa_DeletePrograms(GLsizei n, const GLuint *ids)
163{
164 GLint i;
165 GET_CURRENT_CONTEXT(ctx);
166 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
167
168 if (n < 0) {
169 _mesa_error( ctx, GL_INVALID_VALUE, "glDeleteProgramsNV" );
170 return;
171 }
172
173 for (i = 0; i < n; i++) {
174 if (ids[i] != 0) {
175 struct gl_program *prog = _mesa_lookup_program(ctx, ids[i]);
176 if (prog == &_mesa_DummyProgram) {
177 _mesa_HashRemove(ctx->Shared->Programs, ids[i]);
178 }
179 else if (prog) {
180 /* Unbind program if necessary */
181 if (prog->Target == GL_VERTEX_PROGRAM_ARB || /* == GL_VERTEX_PROGRAM_NV */
182 prog->Target == GL_VERTEX_STATE_PROGRAM_NV) {
183 if (ctx->VertexProgram.Current &&
184 ctx->VertexProgram.Current->Base.Id == ids[i]) {
185 /* unbind this currently bound program */
186 _mesa_BindProgram(prog->Target, 0);
187 }
188 }
189 else if (prog->Target == GL_FRAGMENT_PROGRAM_NV ||
190 prog->Target == GL_FRAGMENT_PROGRAM_ARB) {
191 if (ctx->FragmentProgram.Current &&
192 ctx->FragmentProgram.Current->Base.Id == ids[i]) {
193 /* unbind this currently bound program */
194 _mesa_BindProgram(prog->Target, 0);
195 }
196 }
197 else {
198 _mesa_problem(ctx, "bad target in glDeleteProgramsNV");
199 return;
200 }
201 /* The ID is immediately available for re-use now */
202 _mesa_HashRemove(ctx->Shared->Programs, ids[i]);
203 _mesa_reference_program(ctx, &prog, NULL);
204 }
205 }
206 }
207}
208
209
210/**
211 * Generate a list of new program identifiers.
212 * \note Not compiled into display lists.
213 * \note Called by both glGenProgramsNV and glGenProgramsARB.
214 */
215void GLAPIENTRY
216_mesa_GenPrograms(GLsizei n, GLuint *ids)
217{
218 GLuint first;
219 GLuint i;
220 GET_CURRENT_CONTEXT(ctx);
221 ASSERT_OUTSIDE_BEGIN_END(ctx);
222
223 if (n < 0) {
224 _mesa_error(ctx, GL_INVALID_VALUE, "glGenPrograms");
225 return;
226 }
227
228 if (!ids)
229 return;
230
231 first = _mesa_HashFindFreeKeyBlock(ctx->Shared->Programs, n);
232
233 /* Insert pointer to dummy program as placeholder */
234 for (i = 0; i < (GLuint) n; i++) {
235 _mesa_HashInsert(ctx->Shared->Programs, first + i, &_mesa_DummyProgram);
236 }
237
238 /* Return the program names */
239 for (i = 0; i < (GLuint) n; i++) {
240 ids[i] = first + i;
241 }
242}
243
244
Michal Krol157ec8b2004-03-10 18:02:01 +0000245void GLAPIENTRY
246_mesa_EnableVertexAttribArrayARB(GLuint index)
247{
248 GET_CURRENT_CONTEXT(ctx);
249 ASSERT_OUTSIDE_BEGIN_END(ctx);
250
Brian Paul05051032005-11-01 04:36:33 +0000251 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000252 _mesa_error(ctx, GL_INVALID_VALUE,
253 "glEnableVertexAttribArrayARB(index)");
254 return;
255 }
256
Brian Paula545f1a2009-05-22 07:51:35 -0600257 ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
258
Michal Krol157ec8b2004-03-10 18:02:01 +0000259 FLUSH_VERTICES(ctx, _NEW_ARRAY);
Ian Romanickee34e6e2006-06-12 16:26:29 +0000260 ctx->Array.ArrayObj->VertexAttrib[index].Enabled = GL_TRUE;
261 ctx->Array.ArrayObj->_Enabled |= _NEW_ARRAY_ATTRIB(index);
Michal Krol157ec8b2004-03-10 18:02:01 +0000262 ctx->Array.NewState |= _NEW_ARRAY_ATTRIB(index);
263}
264
265
266void GLAPIENTRY
267_mesa_DisableVertexAttribArrayARB(GLuint index)
268{
269 GET_CURRENT_CONTEXT(ctx);
270 ASSERT_OUTSIDE_BEGIN_END(ctx);
271
Brian Paul05051032005-11-01 04:36:33 +0000272 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000273 _mesa_error(ctx, GL_INVALID_VALUE,
274 "glEnableVertexAttribArrayARB(index)");
275 return;
276 }
277
Brian Paula545f1a2009-05-22 07:51:35 -0600278 ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
279
Michal Krol157ec8b2004-03-10 18:02:01 +0000280 FLUSH_VERTICES(ctx, _NEW_ARRAY);
Ian Romanickee34e6e2006-06-12 16:26:29 +0000281 ctx->Array.ArrayObj->VertexAttrib[index].Enabled = GL_FALSE;
282 ctx->Array.ArrayObj->_Enabled &= ~_NEW_ARRAY_ATTRIB(index);
Michal Krol157ec8b2004-03-10 18:02:01 +0000283 ctx->Array.NewState |= _NEW_ARRAY_ATTRIB(index);
284}
285
286
287void GLAPIENTRY
288_mesa_GetVertexAttribdvARB(GLuint index, GLenum pname, GLdouble *params)
289{
290 GLfloat fparams[4];
291 GET_CURRENT_CONTEXT(ctx);
292 ASSERT_OUTSIDE_BEGIN_END(ctx);
293
294 _mesa_GetVertexAttribfvARB(index, pname, fparams);
295 if (ctx->ErrorValue == GL_NO_ERROR) {
296 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
297 COPY_4V(params, fparams);
298 }
299 else {
300 params[0] = fparams[0];
301 }
302 }
303}
304
305
Brian Paul024de602009-05-21 16:02:50 -0600306/**
307 * Return info for a generic vertex attribute array (no alias with
308 * legacy vertex attributes (pos, normal, color, etc)).
309 */
Michal Krol157ec8b2004-03-10 18:02:01 +0000310void GLAPIENTRY
311_mesa_GetVertexAttribfvARB(GLuint index, GLenum pname, GLfloat *params)
312{
Brian Paul254845f2009-05-21 15:57:29 -0600313 const struct gl_client_array *array;
Michal Krol157ec8b2004-03-10 18:02:01 +0000314 GET_CURRENT_CONTEXT(ctx);
315 ASSERT_OUTSIDE_BEGIN_END(ctx);
316
Brian Paul882cd6c2009-05-22 07:30:05 -0600317 if (index >= MAX_VERTEX_GENERIC_ATTRIBS) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000318 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribfvARB(index)");
319 return;
320 }
321
Brian Paula545f1a2009-05-22 07:51:35 -0600322 ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
323
Brian Paul254845f2009-05-21 15:57:29 -0600324 array = &ctx->Array.ArrayObj->VertexAttrib[index];
325
Michal Krol157ec8b2004-03-10 18:02:01 +0000326 switch (pname) {
327 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
Brian Paul254845f2009-05-21 15:57:29 -0600328 params[0] = (GLfloat) array->Enabled;
Michal Krol157ec8b2004-03-10 18:02:01 +0000329 break;
330 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
Brian Paul254845f2009-05-21 15:57:29 -0600331 params[0] = (GLfloat) array->Size;
Michal Krol157ec8b2004-03-10 18:02:01 +0000332 break;
333 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
Brian Paul254845f2009-05-21 15:57:29 -0600334 params[0] = (GLfloat) array->Stride;
Michal Krol157ec8b2004-03-10 18:02:01 +0000335 break;
336 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
Brian Paul254845f2009-05-21 15:57:29 -0600337 params[0] = (GLfloat) array->Type;
Michal Krol157ec8b2004-03-10 18:02:01 +0000338 break;
339 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
Brian Paul254845f2009-05-21 15:57:29 -0600340 params[0] = array->Normalized;
Michal Krol157ec8b2004-03-10 18:02:01 +0000341 break;
342 case GL_CURRENT_VERTEX_ATTRIB_ARB:
Brian Paul590b5572006-11-04 17:28:38 +0000343 if (index == 0) {
344 _mesa_error(ctx, GL_INVALID_OPERATION,
Brian Pauladf3a642006-11-04 17:31:21 +0000345 "glGetVertexAttribfvARB(index==0)");
Brian Paul590b5572006-11-04 17:28:38 +0000346 return;
347 }
Michal Krolbb38cad2006-04-11 11:41:11 +0000348 FLUSH_CURRENT(ctx, 0);
349 COPY_4V(params, ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + index]);
Michal Krol157ec8b2004-03-10 18:02:01 +0000350 break;
351 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
Brian Paul254845f2009-05-21 15:57:29 -0600352 params[0] = (GLfloat) array->BufferObj->Name;
Tilman Sauerbeck6be81272006-05-30 16:57:52 +0000353 break;
Michal Krol157ec8b2004-03-10 18:02:01 +0000354 default:
355 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribfvARB(pname)");
356 return;
357 }
358}
359
360
361void GLAPIENTRY
362_mesa_GetVertexAttribivARB(GLuint index, GLenum pname, GLint *params)
363{
364 GLfloat fparams[4];
365 GET_CURRENT_CONTEXT(ctx);
366 ASSERT_OUTSIDE_BEGIN_END(ctx);
367
368 _mesa_GetVertexAttribfvARB(index, pname, fparams);
369 if (ctx->ErrorValue == GL_NO_ERROR) {
370 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
371 COPY_4V_CAST(params, fparams, GLint); /* float to int */
372 }
373 else {
374 params[0] = (GLint) fparams[0];
375 }
376 }
377}
378
379
380void GLAPIENTRY
381_mesa_GetVertexAttribPointervARB(GLuint index, GLenum pname, GLvoid **pointer)
382{
383 GET_CURRENT_CONTEXT(ctx);
384 ASSERT_OUTSIDE_BEGIN_END(ctx);
385
Brian Paul05051032005-11-01 04:36:33 +0000386 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000387 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
388 return;
389 }
390
391 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
392 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
393 return;
394 }
395
Brian Paula545f1a2009-05-22 07:51:35 -0600396 ASSERT(index < Elements(ctx->Array.ArrayObj->VertexAttrib));
397
Ian Romanickee34e6e2006-06-12 16:26:29 +0000398 *pointer = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[index].Ptr;
Michal Krol157ec8b2004-03-10 18:02:01 +0000399}
400
401
Brian Paulf49c0d02006-11-02 16:20:29 +0000402/**
403 * Determine if id names a vertex or fragment program.
404 * \note Not compiled into display lists.
405 * \note Called from both glIsProgramNV and glIsProgramARB.
406 * \param id is the program identifier
407 * \return GL_TRUE if id is a program, else GL_FALSE.
408 */
409GLboolean GLAPIENTRY
410_mesa_IsProgramARB(GLuint id)
411{
Brian Paul308b85f2006-11-23 15:58:30 +0000412 struct gl_program *prog = NULL;
Brian Paulf49c0d02006-11-02 16:20:29 +0000413 GET_CURRENT_CONTEXT(ctx);
414 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
415
416 if (id == 0)
417 return GL_FALSE;
418
Brian Paul308b85f2006-11-23 15:58:30 +0000419 prog = _mesa_lookup_program(ctx, id);
420 if (prog && (prog != &_mesa_DummyProgram))
Brian Paulf49c0d02006-11-02 16:20:29 +0000421 return GL_TRUE;
422 else
423 return GL_FALSE;
424}
425
426
Michal Krol157ec8b2004-03-10 18:02:01 +0000427void GLAPIENTRY
428_mesa_ProgramStringARB(GLenum target, GLenum format, GLsizei len,
429 const GLvoid *string)
430{
431 GET_CURRENT_CONTEXT(ctx);
432 ASSERT_OUTSIDE_BEGIN_END(ctx);
433
434 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
435
Brian Paul8c41a142005-11-19 15:36:28 +0000436 if (format != GL_PROGRAM_FORMAT_ASCII_ARB) {
437 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramStringARB(format)");
438 return;
439 }
440
Michal Krol157ec8b2004-03-10 18:02:01 +0000441 if (target == GL_VERTEX_PROGRAM_ARB
442 && ctx->Extensions.ARB_vertex_program) {
Brian Paul122629f2006-07-20 16:49:57 +0000443 struct gl_vertex_program *prog = ctx->VertexProgram.Current;
Brian Paul8c41a142005-11-19 15:36:28 +0000444 _mesa_parse_arb_vertex_program(ctx, target, string, len, prog);
Michal Krol157ec8b2004-03-10 18:02:01 +0000445
Eric Anholt185320a2008-01-15 15:08:34 -0800446 if (ctx->Program.ErrorPos == -1 && ctx->Driver.ProgramStringNotify)
Michal Krol157ec8b2004-03-10 18:02:01 +0000447 ctx->Driver.ProgramStringNotify( ctx, target, &prog->Base );
448 }
449 else if (target == GL_FRAGMENT_PROGRAM_ARB
450 && ctx->Extensions.ARB_fragment_program) {
Brian Paul122629f2006-07-20 16:49:57 +0000451 struct gl_fragment_program *prog = ctx->FragmentProgram.Current;
Brian Paul8c41a142005-11-19 15:36:28 +0000452 _mesa_parse_arb_fragment_program(ctx, target, string, len, prog);
Michal Krol157ec8b2004-03-10 18:02:01 +0000453
Eric Anholt185320a2008-01-15 15:08:34 -0800454 if (ctx->Program.ErrorPos == -1 && ctx->Driver.ProgramStringNotify)
Michal Krol157ec8b2004-03-10 18:02:01 +0000455 ctx->Driver.ProgramStringNotify( ctx, target, &prog->Base );
456 }
457 else {
458 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramStringARB(target)");
459 return;
460 }
461}
462
463
Roland Scheidegger86a48102007-11-09 14:46:59 +0100464/**
465 * Set a program env parameter register.
466 * \note Called from the GL API dispatcher.
467 * Note, this function is also used by the GL_NV_vertex_program extension
468 * (alias to ProgramParameterdNV)
469 */
Michal Krol157ec8b2004-03-10 18:02:01 +0000470void GLAPIENTRY
471_mesa_ProgramEnvParameter4dARB(GLenum target, GLuint index,
472 GLdouble x, GLdouble y, GLdouble z, GLdouble w)
473{
474 _mesa_ProgramEnvParameter4fARB(target, index, (GLfloat) x, (GLfloat) y,
475 (GLfloat) z, (GLfloat) w);
476}
477
478
Roland Scheidegger86a48102007-11-09 14:46:59 +0100479/**
480 * Set a program env parameter register.
481 * \note Called from the GL API dispatcher.
482 * Note, this function is also used by the GL_NV_vertex_program extension
483 * (alias to ProgramParameterdvNV)
484 */
Michal Krol157ec8b2004-03-10 18:02:01 +0000485void GLAPIENTRY
486_mesa_ProgramEnvParameter4dvARB(GLenum target, GLuint index,
487 const GLdouble *params)
488{
489 _mesa_ProgramEnvParameter4fARB(target, index, (GLfloat) params[0],
490 (GLfloat) params[1], (GLfloat) params[2],
491 (GLfloat) params[3]);
492}
493
494
Roland Scheidegger86a48102007-11-09 14:46:59 +0100495/**
496 * Set a program env parameter register.
497 * \note Called from the GL API dispatcher.
498 * Note, this function is also used by the GL_NV_vertex_program extension
499 * (alias to ProgramParameterfNV)
500 */
Michal Krol157ec8b2004-03-10 18:02:01 +0000501void GLAPIENTRY
502_mesa_ProgramEnvParameter4fARB(GLenum target, GLuint index,
503 GLfloat x, GLfloat y, GLfloat z, GLfloat w)
504{
505 GET_CURRENT_CONTEXT(ctx);
506 ASSERT_OUTSIDE_BEGIN_END(ctx);
507
Brian Paul027ed1b2009-04-24 09:43:44 -0600508 FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
Michal Krol157ec8b2004-03-10 18:02:01 +0000509
510 if (target == GL_FRAGMENT_PROGRAM_ARB
511 && ctx->Extensions.ARB_fragment_program) {
Brian Paul05051032005-11-01 04:36:33 +0000512 if (index >= ctx->Const.FragmentProgram.MaxEnvParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000513 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameter(index)");
514 return;
515 }
516 ASSIGN_4V(ctx->FragmentProgram.Parameters[index], x, y, z, w);
517 }
Roland Scheidegger86a48102007-11-09 14:46:59 +0100518 else if (target == GL_VERTEX_PROGRAM_ARB /* == GL_VERTEX_PROGRAM_NV */
519 && (ctx->Extensions.ARB_vertex_program || ctx->Extensions.NV_vertex_program)) {
Brian Paul05051032005-11-01 04:36:33 +0000520 if (index >= ctx->Const.VertexProgram.MaxEnvParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000521 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameter(index)");
522 return;
523 }
524 ASSIGN_4V(ctx->VertexProgram.Parameters[index], x, y, z, w);
525 }
526 else {
527 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramEnvParameter(target)");
528 return;
529 }
530}
531
Roland Scheidegger86a48102007-11-09 14:46:59 +0100532/**
533 * Set a program env parameter register.
534 * \note Called from the GL API dispatcher.
535 * Note, this function is also used by the GL_NV_vertex_program extension
536 * (alias to ProgramParameterfvNV)
537 */
Michal Krol157ec8b2004-03-10 18:02:01 +0000538void GLAPIENTRY
539_mesa_ProgramEnvParameter4fvARB(GLenum target, GLuint index,
540 const GLfloat *params)
541{
542 _mesa_ProgramEnvParameter4fARB(target, index, params[0], params[1],
543 params[2], params[3]);
544}
545
546
547void GLAPIENTRY
Ian Romanick8c41c752006-08-15 16:47:34 +0000548_mesa_ProgramEnvParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
549 const GLfloat *params)
550{
551 GET_CURRENT_CONTEXT(ctx);
Brian223d7cb2007-01-23 16:37:51 -0700552 GLint i;
Ian Romanick8c41c752006-08-15 16:47:34 +0000553 GLfloat * dest;
554 ASSERT_OUTSIDE_BEGIN_END(ctx);
555
Brian Paul027ed1b2009-04-24 09:43:44 -0600556 FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
Ian Romanick8c41c752006-08-15 16:47:34 +0000557
558 if (count <= 0) {
559 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameters4fv(count)");
560 }
561
562 if (target == GL_FRAGMENT_PROGRAM_ARB
563 && ctx->Extensions.ARB_fragment_program) {
564 if ((index + count) > ctx->Const.FragmentProgram.MaxEnvParams) {
565 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameters4fv(index + count)");
566 return;
567 }
568 dest = ctx->FragmentProgram.Parameters[index];
569 }
570 else if (target == GL_VERTEX_PROGRAM_ARB
571 && ctx->Extensions.ARB_vertex_program) {
572 if ((index + count) > ctx->Const.VertexProgram.MaxEnvParams) {
573 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameters4fv(index + count)");
574 return;
575 }
576 dest = ctx->VertexProgram.Parameters[index];
577 }
578 else {
579 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramEnvParameters4fv(target)");
580 return;
581 }
582
583 for ( i = 0 ; i < count ; i++ ) {
584 COPY_4V(dest, params);
585 params += 4;
586 dest += 4;
587 }
588}
589
590
591void GLAPIENTRY
Michal Krol157ec8b2004-03-10 18:02:01 +0000592_mesa_GetProgramEnvParameterdvARB(GLenum target, GLuint index,
593 GLdouble *params)
594{
595 GET_CURRENT_CONTEXT(ctx);
596 GLfloat fparams[4];
597
598 _mesa_GetProgramEnvParameterfvARB(target, index, fparams);
599 if (ctx->ErrorValue == GL_NO_ERROR) {
600 params[0] = fparams[0];
601 params[1] = fparams[1];
602 params[2] = fparams[2];
603 params[3] = fparams[3];
604 }
605}
606
607
608void GLAPIENTRY
609_mesa_GetProgramEnvParameterfvARB(GLenum target, GLuint index,
610 GLfloat *params)
611{
612 GET_CURRENT_CONTEXT(ctx);
613
Brian Paul548be382009-03-11 20:08:37 -0600614 ASSERT_OUTSIDE_BEGIN_END(ctx);
Michal Krol157ec8b2004-03-10 18:02:01 +0000615
616 if (target == GL_FRAGMENT_PROGRAM_ARB
617 && ctx->Extensions.ARB_fragment_program) {
Brian Paul05051032005-11-01 04:36:33 +0000618 if (index >= ctx->Const.FragmentProgram.MaxEnvParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000619 _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramEnvParameter(index)");
620 return;
621 }
622 COPY_4V(params, ctx->FragmentProgram.Parameters[index]);
623 }
Brian Paul83c74b72004-10-16 00:29:03 +0000624 else if (target == GL_VERTEX_PROGRAM_ARB
Michal Krol157ec8b2004-03-10 18:02:01 +0000625 && ctx->Extensions.ARB_vertex_program) {
Brian Paul05051032005-11-01 04:36:33 +0000626 if (index >= ctx->Const.VertexProgram.MaxEnvParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000627 _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramEnvParameter(index)");
628 return;
629 }
630 COPY_4V(params, ctx->VertexProgram.Parameters[index]);
631 }
632 else {
633 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramEnvParameter(target)");
634 return;
635 }
636}
637
638
639/**
640 * Note, this function is also used by the GL_NV_fragment_program extension.
641 */
642void GLAPIENTRY
643_mesa_ProgramLocalParameter4fARB(GLenum target, GLuint index,
644 GLfloat x, GLfloat y, GLfloat z, GLfloat w)
645{
646 GET_CURRENT_CONTEXT(ctx);
Brian Paul122629f2006-07-20 16:49:57 +0000647 struct gl_program *prog;
Michal Krol157ec8b2004-03-10 18:02:01 +0000648 ASSERT_OUTSIDE_BEGIN_END(ctx);
649
Brian Paul027ed1b2009-04-24 09:43:44 -0600650 FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
Michal Krol157ec8b2004-03-10 18:02:01 +0000651
652 if ((target == GL_FRAGMENT_PROGRAM_NV
653 && ctx->Extensions.NV_fragment_program) ||
654 (target == GL_FRAGMENT_PROGRAM_ARB
655 && ctx->Extensions.ARB_fragment_program)) {
Brian Paul05051032005-11-01 04:36:33 +0000656 if (index >= ctx->Const.FragmentProgram.MaxLocalParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000657 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameterARB");
658 return;
659 }
660 prog = &(ctx->FragmentProgram.Current->Base);
661 }
662 else if (target == GL_VERTEX_PROGRAM_ARB
663 && ctx->Extensions.ARB_vertex_program) {
Brian Paul05051032005-11-01 04:36:33 +0000664 if (index >= ctx->Const.VertexProgram.MaxLocalParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000665 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameterARB");
666 return;
667 }
668 prog = &(ctx->VertexProgram.Current->Base);
669 }
670 else {
671 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameterARB");
672 return;
673 }
674
675 ASSERT(index < MAX_PROGRAM_LOCAL_PARAMS);
676 prog->LocalParams[index][0] = x;
677 prog->LocalParams[index][1] = y;
678 prog->LocalParams[index][2] = z;
679 prog->LocalParams[index][3] = w;
680}
681
682
683/**
684 * Note, this function is also used by the GL_NV_fragment_program extension.
685 */
686void GLAPIENTRY
687_mesa_ProgramLocalParameter4fvARB(GLenum target, GLuint index,
688 const GLfloat *params)
689{
690 _mesa_ProgramLocalParameter4fARB(target, index, params[0], params[1],
691 params[2], params[3]);
692}
693
694
Ian Romanick8c41c752006-08-15 16:47:34 +0000695void GLAPIENTRY
696_mesa_ProgramLocalParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
697 const GLfloat *params)
698{
699 GET_CURRENT_CONTEXT(ctx);
700 struct gl_program *prog;
Brian223d7cb2007-01-23 16:37:51 -0700701 GLint i;
Ian Romanick8c41c752006-08-15 16:47:34 +0000702 ASSERT_OUTSIDE_BEGIN_END(ctx);
703
Brian Paul027ed1b2009-04-24 09:43:44 -0600704 FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
Ian Romanick8c41c752006-08-15 16:47:34 +0000705
706 if (count <= 0) {
707 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fv(count)");
708 }
709
710 if (target == GL_FRAGMENT_PROGRAM_ARB
711 && ctx->Extensions.ARB_fragment_program) {
712 if ((index + count) > ctx->Const.FragmentProgram.MaxLocalParams) {
713 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fvEXT(index + count)");
714 return;
715 }
716 prog = &(ctx->FragmentProgram.Current->Base);
717 }
718 else if (target == GL_VERTEX_PROGRAM_ARB
719 && ctx->Extensions.ARB_vertex_program) {
720 if ((index + count) > ctx->Const.VertexProgram.MaxLocalParams) {
721 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fvEXT(index + count)");
722 return;
723 }
724 prog = &(ctx->VertexProgram.Current->Base);
725 }
726 else {
727 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameters4fvEXT(target)");
728 return;
729 }
730
731 for (i = 0; i < count; i++) {
732 ASSERT((index + i) < MAX_PROGRAM_LOCAL_PARAMS);
733 COPY_4V(prog->LocalParams[index + i], params);
734 params += 4;
735 }
736}
737
738
Michal Krol157ec8b2004-03-10 18:02:01 +0000739/**
740 * Note, this function is also used by the GL_NV_fragment_program extension.
741 */
742void GLAPIENTRY
743_mesa_ProgramLocalParameter4dARB(GLenum target, GLuint index,
744 GLdouble x, GLdouble y,
745 GLdouble z, GLdouble w)
746{
747 _mesa_ProgramLocalParameter4fARB(target, index, (GLfloat) x, (GLfloat) y,
748 (GLfloat) z, (GLfloat) w);
749}
750
751
752/**
753 * Note, this function is also used by the GL_NV_fragment_program extension.
754 */
755void GLAPIENTRY
756_mesa_ProgramLocalParameter4dvARB(GLenum target, GLuint index,
757 const GLdouble *params)
758{
759 _mesa_ProgramLocalParameter4fARB(target, index,
760 (GLfloat) params[0], (GLfloat) params[1],
761 (GLfloat) params[2], (GLfloat) params[3]);
762}
763
764
765/**
766 * Note, this function is also used by the GL_NV_fragment_program extension.
767 */
768void GLAPIENTRY
769_mesa_GetProgramLocalParameterfvARB(GLenum target, GLuint index,
770 GLfloat *params)
771{
Brian Paul122629f2006-07-20 16:49:57 +0000772 const struct gl_program *prog;
Michal Krol157ec8b2004-03-10 18:02:01 +0000773 GLuint maxParams;
774 GET_CURRENT_CONTEXT(ctx);
775 ASSERT_OUTSIDE_BEGIN_END(ctx);
776
777 if (target == GL_VERTEX_PROGRAM_ARB
778 && ctx->Extensions.ARB_vertex_program) {
779 prog = &(ctx->VertexProgram.Current->Base);
Brian Paul05051032005-11-01 04:36:33 +0000780 maxParams = ctx->Const.VertexProgram.MaxLocalParams;
Michal Krol157ec8b2004-03-10 18:02:01 +0000781 }
782 else if (target == GL_FRAGMENT_PROGRAM_ARB
783 && ctx->Extensions.ARB_fragment_program) {
784 prog = &(ctx->FragmentProgram.Current->Base);
Brian Paul05051032005-11-01 04:36:33 +0000785 maxParams = ctx->Const.FragmentProgram.MaxLocalParams;
Michal Krol157ec8b2004-03-10 18:02:01 +0000786 }
787 else if (target == GL_FRAGMENT_PROGRAM_NV
788 && ctx->Extensions.NV_fragment_program) {
789 prog = &(ctx->FragmentProgram.Current->Base);
790 maxParams = MAX_NV_FRAGMENT_PROGRAM_PARAMS;
791 }
792 else {
793 _mesa_error(ctx, GL_INVALID_ENUM,
794 "glGetProgramLocalParameterARB(target)");
795 return;
796 }
797
798 if (index >= maxParams) {
799 _mesa_error(ctx, GL_INVALID_VALUE,
800 "glGetProgramLocalParameterARB(index)");
801 return;
802 }
803
804 ASSERT(prog);
805 ASSERT(index < MAX_PROGRAM_LOCAL_PARAMS);
806 COPY_4V(params, prog->LocalParams[index]);
807}
808
809
810/**
811 * Note, this function is also used by the GL_NV_fragment_program extension.
812 */
813void GLAPIENTRY
814_mesa_GetProgramLocalParameterdvARB(GLenum target, GLuint index,
815 GLdouble *params)
816{
817 GET_CURRENT_CONTEXT(ctx);
818 GLfloat floatParams[4];
Brian Pauleb26cc62009-01-20 09:17:12 -0700819 ASSIGN_4V(floatParams, 0.0F, 0.0F, 0.0F, 0.0F);
Michal Krol157ec8b2004-03-10 18:02:01 +0000820 _mesa_GetProgramLocalParameterfvARB(target, index, floatParams);
821 if (ctx->ErrorValue == GL_NO_ERROR) {
822 COPY_4V(params, floatParams);
823 }
824}
825
826
827void GLAPIENTRY
828_mesa_GetProgramivARB(GLenum target, GLenum pname, GLint *params)
829{
Brian Paul05051032005-11-01 04:36:33 +0000830 const struct gl_program_constants *limits;
Brian Paul122629f2006-07-20 16:49:57 +0000831 struct gl_program *prog;
Michal Krol157ec8b2004-03-10 18:02:01 +0000832 GET_CURRENT_CONTEXT(ctx);
833
Brian Paul548be382009-03-11 20:08:37 -0600834 ASSERT_OUTSIDE_BEGIN_END(ctx);
Michal Krol157ec8b2004-03-10 18:02:01 +0000835
836 if (target == GL_VERTEX_PROGRAM_ARB
837 && ctx->Extensions.ARB_vertex_program) {
838 prog = &(ctx->VertexProgram.Current->Base);
Brian Paul05051032005-11-01 04:36:33 +0000839 limits = &ctx->Const.VertexProgram;
Michal Krol157ec8b2004-03-10 18:02:01 +0000840 }
841 else if (target == GL_FRAGMENT_PROGRAM_ARB
842 && ctx->Extensions.ARB_fragment_program) {
843 prog = &(ctx->FragmentProgram.Current->Base);
Brian Paul05051032005-11-01 04:36:33 +0000844 limits = &ctx->Const.FragmentProgram;
Michal Krol157ec8b2004-03-10 18:02:01 +0000845 }
846 else {
847 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(target)");
848 return;
849 }
850
851 ASSERT(prog);
Brian Paul05051032005-11-01 04:36:33 +0000852 ASSERT(limits);
Michal Krol157ec8b2004-03-10 18:02:01 +0000853
Brian Paul05051032005-11-01 04:36:33 +0000854 /* Queries supported for both vertex and fragment programs */
Michal Krol157ec8b2004-03-10 18:02:01 +0000855 switch (pname) {
856 case GL_PROGRAM_LENGTH_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000857 *params
858 = prog->String ? (GLint) _mesa_strlen((char *) prog->String) : 0;
859 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000860 case GL_PROGRAM_FORMAT_ARB:
861 *params = prog->Format;
Brian Paul05051032005-11-01 04:36:33 +0000862 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000863 case GL_PROGRAM_BINDING_ARB:
864 *params = prog->Id;
Brian Paul05051032005-11-01 04:36:33 +0000865 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000866 case GL_PROGRAM_INSTRUCTIONS_ARB:
867 *params = prog->NumInstructions;
Brian Paul05051032005-11-01 04:36:33 +0000868 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000869 case GL_MAX_PROGRAM_INSTRUCTIONS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000870 *params = limits->MaxInstructions;
871 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000872 case GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000873 *params = prog->NumNativeInstructions;
874 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000875 case GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000876 *params = limits->MaxNativeInstructions;
877 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000878 case GL_PROGRAM_TEMPORARIES_ARB:
879 *params = prog->NumTemporaries;
Brian Paul05051032005-11-01 04:36:33 +0000880 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000881 case GL_MAX_PROGRAM_TEMPORARIES_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000882 *params = limits->MaxTemps;
883 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000884 case GL_PROGRAM_NATIVE_TEMPORARIES_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000885 *params = prog->NumNativeTemporaries;
886 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000887 case GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000888 *params = limits->MaxNativeTemps;
889 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000890 case GL_PROGRAM_PARAMETERS_ARB:
891 *params = prog->NumParameters;
Brian Paul05051032005-11-01 04:36:33 +0000892 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000893 case GL_MAX_PROGRAM_PARAMETERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000894 *params = limits->MaxParameters;
895 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000896 case GL_PROGRAM_NATIVE_PARAMETERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000897 *params = prog->NumNativeParameters;
898 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000899 case GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000900 *params = limits->MaxNativeParameters;
901 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000902 case GL_PROGRAM_ATTRIBS_ARB:
903 *params = prog->NumAttributes;
Brian Paul05051032005-11-01 04:36:33 +0000904 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000905 case GL_MAX_PROGRAM_ATTRIBS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000906 *params = limits->MaxAttribs;
907 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000908 case GL_PROGRAM_NATIVE_ATTRIBS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000909 *params = prog->NumNativeAttributes;
910 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000911 case GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000912 *params = limits->MaxNativeAttribs;
913 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000914 case GL_PROGRAM_ADDRESS_REGISTERS_ARB:
915 *params = prog->NumAddressRegs;
Brian Paul05051032005-11-01 04:36:33 +0000916 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000917 case GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000918 *params = limits->MaxAddressRegs;
919 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000920 case GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000921 *params = prog->NumNativeAddressRegs;
922 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000923 case GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000924 *params = limits->MaxNativeAddressRegs;
925 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000926 case GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000927 *params = limits->MaxLocalParams;
928 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000929 case GL_MAX_PROGRAM_ENV_PARAMETERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000930 *params = limits->MaxEnvParams;
931 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000932 case GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000933 /*
934 * XXX we may not really need a driver callback here.
935 * If the number of native instructions, registers, etc. used
936 * are all below the maximums, we could return true.
937 * The spec says that even if this query returns true, there's
938 * no guarantee that the program will run in hardware.
939 */
Brian4ca7c802007-04-28 08:01:18 -0600940 if (prog->Id == 0) {
941 /* default/null program */
942 *params = GL_FALSE;
943 }
944 else if (ctx->Driver.IsProgramNative) {
945 /* ask the driver */
Michal Krol157ec8b2004-03-10 18:02:01 +0000946 *params = ctx->Driver.IsProgramNative( ctx, target, prog );
Brian4ca7c802007-04-28 08:01:18 -0600947 }
948 else {
949 /* probably running in software */
Michal Krol157ec8b2004-03-10 18:02:01 +0000950 *params = GL_TRUE;
Brian4ca7c802007-04-28 08:01:18 -0600951 }
Michal Krol157ec8b2004-03-10 18:02:01 +0000952 return;
Brian Paul05051032005-11-01 04:36:33 +0000953 default:
954 /* continue with fragment-program only queries below */
955 break;
956 }
957
958 /*
959 * The following apply to fragment programs only (at this time)
960 */
961 if (target == GL_FRAGMENT_PROGRAM_ARB) {
Brian Paul122629f2006-07-20 16:49:57 +0000962 const struct gl_fragment_program *fp = ctx->FragmentProgram.Current;
Brian Paul05051032005-11-01 04:36:33 +0000963 switch (pname) {
964 case GL_PROGRAM_ALU_INSTRUCTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700965 *params = fp->Base.NumNativeAluInstructions;
Brian Paul05051032005-11-01 04:36:33 +0000966 return;
967 case GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700968 *params = fp->Base.NumAluInstructions;
Brian Paul05051032005-11-01 04:36:33 +0000969 return;
970 case GL_PROGRAM_TEX_INSTRUCTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700971 *params = fp->Base.NumTexInstructions;
Brian Paul05051032005-11-01 04:36:33 +0000972 return;
973 case GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700974 *params = fp->Base.NumNativeTexInstructions;
Brian Paul05051032005-11-01 04:36:33 +0000975 return;
976 case GL_PROGRAM_TEX_INDIRECTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700977 *params = fp->Base.NumTexIndirections;
Brian Paul05051032005-11-01 04:36:33 +0000978 return;
979 case GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700980 *params = fp->Base.NumNativeTexIndirections;
Brian Paul05051032005-11-01 04:36:33 +0000981 return;
982 case GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB:
983 *params = limits->MaxAluInstructions;
984 return;
985 case GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB:
986 *params = limits->MaxNativeAluInstructions;
987 return;
988 case GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB:
989 *params = limits->MaxTexInstructions;
990 return;
991 case GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB:
992 *params = limits->MaxNativeTexInstructions;
993 return;
994 case GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB:
995 *params = limits->MaxTexIndirections;
996 return;
997 case GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB:
998 *params = limits->MaxNativeTexIndirections;
999 return;
1000 default:
1001 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(pname)");
1002 return;
1003 }
Ian Romanick4bccd692009-08-24 12:48:01 -07001004 } else {
1005 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(pname)");
1006 return;
Michal Krol157ec8b2004-03-10 18:02:01 +00001007 }
1008}
1009
1010
1011void GLAPIENTRY
1012_mesa_GetProgramStringARB(GLenum target, GLenum pname, GLvoid *string)
1013{
Brian Paul122629f2006-07-20 16:49:57 +00001014 const struct gl_program *prog;
Brian Paul308b85f2006-11-23 15:58:30 +00001015 char *dst = (char *) string;
Michal Krol157ec8b2004-03-10 18:02:01 +00001016 GET_CURRENT_CONTEXT(ctx);
1017
Brian Paul548be382009-03-11 20:08:37 -06001018 ASSERT_OUTSIDE_BEGIN_END(ctx);
Michal Krol157ec8b2004-03-10 18:02:01 +00001019
1020 if (target == GL_VERTEX_PROGRAM_ARB) {
1021 prog = &(ctx->VertexProgram.Current->Base);
1022 }
1023 else if (target == GL_FRAGMENT_PROGRAM_ARB) {
1024 prog = &(ctx->FragmentProgram.Current->Base);
1025 }
1026 else {
1027 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramStringARB(target)");
1028 return;
1029 }
1030
1031 ASSERT(prog);
1032
1033 if (pname != GL_PROGRAM_STRING_ARB) {
1034 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramStringARB(pname)");
1035 return;
1036 }
1037
Brian Paul308b85f2006-11-23 15:58:30 +00001038 if (prog->String)
1039 _mesa_memcpy(dst, prog->String, _mesa_strlen((char *) prog->String));
1040 else
1041 *dst = '\0';
Michal Krol157ec8b2004-03-10 18:02:01 +00001042}