blob: 21c5cfbf99cb54be6c48fd0e876ec4468a4f09f9 [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
257 FLUSH_VERTICES(ctx, _NEW_ARRAY);
Ian Romanickee34e6e2006-06-12 16:26:29 +0000258 ctx->Array.ArrayObj->VertexAttrib[index].Enabled = GL_TRUE;
259 ctx->Array.ArrayObj->_Enabled |= _NEW_ARRAY_ATTRIB(index);
Michal Krol157ec8b2004-03-10 18:02:01 +0000260 ctx->Array.NewState |= _NEW_ARRAY_ATTRIB(index);
261}
262
263
264void GLAPIENTRY
265_mesa_DisableVertexAttribArrayARB(GLuint index)
266{
267 GET_CURRENT_CONTEXT(ctx);
268 ASSERT_OUTSIDE_BEGIN_END(ctx);
269
Brian Paul05051032005-11-01 04:36:33 +0000270 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000271 _mesa_error(ctx, GL_INVALID_VALUE,
272 "glEnableVertexAttribArrayARB(index)");
273 return;
274 }
275
276 FLUSH_VERTICES(ctx, _NEW_ARRAY);
Ian Romanickee34e6e2006-06-12 16:26:29 +0000277 ctx->Array.ArrayObj->VertexAttrib[index].Enabled = GL_FALSE;
278 ctx->Array.ArrayObj->_Enabled &= ~_NEW_ARRAY_ATTRIB(index);
Michal Krol157ec8b2004-03-10 18:02:01 +0000279 ctx->Array.NewState |= _NEW_ARRAY_ATTRIB(index);
280}
281
282
283void GLAPIENTRY
284_mesa_GetVertexAttribdvARB(GLuint index, GLenum pname, GLdouble *params)
285{
286 GLfloat fparams[4];
287 GET_CURRENT_CONTEXT(ctx);
288 ASSERT_OUTSIDE_BEGIN_END(ctx);
289
290 _mesa_GetVertexAttribfvARB(index, pname, fparams);
291 if (ctx->ErrorValue == GL_NO_ERROR) {
292 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
293 COPY_4V(params, fparams);
294 }
295 else {
296 params[0] = fparams[0];
297 }
298 }
299}
300
301
Brian Paul024de602009-05-21 16:02:50 -0600302/**
303 * Return info for a generic vertex attribute array (no alias with
304 * legacy vertex attributes (pos, normal, color, etc)).
305 */
Michal Krol157ec8b2004-03-10 18:02:01 +0000306void GLAPIENTRY
307_mesa_GetVertexAttribfvARB(GLuint index, GLenum pname, GLfloat *params)
308{
Brian Paul254845f2009-05-21 15:57:29 -0600309 const struct gl_client_array *array;
Michal Krol157ec8b2004-03-10 18:02:01 +0000310 GET_CURRENT_CONTEXT(ctx);
311 ASSERT_OUTSIDE_BEGIN_END(ctx);
312
Brian Paul882cd6c2009-05-22 07:30:05 -0600313 if (index >= MAX_VERTEX_GENERIC_ATTRIBS) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000314 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribfvARB(index)");
315 return;
316 }
317
Brian Paul254845f2009-05-21 15:57:29 -0600318 array = &ctx->Array.ArrayObj->VertexAttrib[index];
319
Michal Krol157ec8b2004-03-10 18:02:01 +0000320 switch (pname) {
321 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
Brian Paul254845f2009-05-21 15:57:29 -0600322 params[0] = (GLfloat) array->Enabled;
Michal Krol157ec8b2004-03-10 18:02:01 +0000323 break;
324 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
Brian Paul254845f2009-05-21 15:57:29 -0600325 params[0] = (GLfloat) array->Size;
Michal Krol157ec8b2004-03-10 18:02:01 +0000326 break;
327 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
Brian Paul254845f2009-05-21 15:57:29 -0600328 params[0] = (GLfloat) array->Stride;
Michal Krol157ec8b2004-03-10 18:02:01 +0000329 break;
330 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
Brian Paul254845f2009-05-21 15:57:29 -0600331 params[0] = (GLfloat) array->Type;
Michal Krol157ec8b2004-03-10 18:02:01 +0000332 break;
333 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
Brian Paul254845f2009-05-21 15:57:29 -0600334 params[0] = array->Normalized;
Michal Krol157ec8b2004-03-10 18:02:01 +0000335 break;
336 case GL_CURRENT_VERTEX_ATTRIB_ARB:
Brian Paul590b5572006-11-04 17:28:38 +0000337 if (index == 0) {
338 _mesa_error(ctx, GL_INVALID_OPERATION,
Brian Pauladf3a642006-11-04 17:31:21 +0000339 "glGetVertexAttribfvARB(index==0)");
Brian Paul590b5572006-11-04 17:28:38 +0000340 return;
341 }
Michal Krolbb38cad2006-04-11 11:41:11 +0000342 FLUSH_CURRENT(ctx, 0);
343 COPY_4V(params, ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + index]);
Michal Krol157ec8b2004-03-10 18:02:01 +0000344 break;
345 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
Brian Paul254845f2009-05-21 15:57:29 -0600346 params[0] = (GLfloat) array->BufferObj->Name;
Tilman Sauerbeck6be81272006-05-30 16:57:52 +0000347 break;
Michal Krol157ec8b2004-03-10 18:02:01 +0000348 default:
349 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribfvARB(pname)");
350 return;
351 }
352}
353
354
355void GLAPIENTRY
356_mesa_GetVertexAttribivARB(GLuint index, GLenum pname, GLint *params)
357{
358 GLfloat fparams[4];
359 GET_CURRENT_CONTEXT(ctx);
360 ASSERT_OUTSIDE_BEGIN_END(ctx);
361
362 _mesa_GetVertexAttribfvARB(index, pname, fparams);
363 if (ctx->ErrorValue == GL_NO_ERROR) {
364 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
365 COPY_4V_CAST(params, fparams, GLint); /* float to int */
366 }
367 else {
368 params[0] = (GLint) fparams[0];
369 }
370 }
371}
372
373
374void GLAPIENTRY
375_mesa_GetVertexAttribPointervARB(GLuint index, GLenum pname, GLvoid **pointer)
376{
377 GET_CURRENT_CONTEXT(ctx);
378 ASSERT_OUTSIDE_BEGIN_END(ctx);
379
Brian Paul05051032005-11-01 04:36:33 +0000380 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000381 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
382 return;
383 }
384
385 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
386 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
387 return;
388 }
389
Ian Romanickee34e6e2006-06-12 16:26:29 +0000390 *pointer = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[index].Ptr;
Michal Krol157ec8b2004-03-10 18:02:01 +0000391}
392
393
Brian Paulf49c0d02006-11-02 16:20:29 +0000394/**
395 * Determine if id names a vertex or fragment program.
396 * \note Not compiled into display lists.
397 * \note Called from both glIsProgramNV and glIsProgramARB.
398 * \param id is the program identifier
399 * \return GL_TRUE if id is a program, else GL_FALSE.
400 */
401GLboolean GLAPIENTRY
402_mesa_IsProgramARB(GLuint id)
403{
Brian Paul308b85f2006-11-23 15:58:30 +0000404 struct gl_program *prog = NULL;
Brian Paulf49c0d02006-11-02 16:20:29 +0000405 GET_CURRENT_CONTEXT(ctx);
406 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
407
408 if (id == 0)
409 return GL_FALSE;
410
Brian Paul308b85f2006-11-23 15:58:30 +0000411 prog = _mesa_lookup_program(ctx, id);
412 if (prog && (prog != &_mesa_DummyProgram))
Brian Paulf49c0d02006-11-02 16:20:29 +0000413 return GL_TRUE;
414 else
415 return GL_FALSE;
416}
417
418
Michal Krol157ec8b2004-03-10 18:02:01 +0000419void GLAPIENTRY
420_mesa_ProgramStringARB(GLenum target, GLenum format, GLsizei len,
421 const GLvoid *string)
422{
423 GET_CURRENT_CONTEXT(ctx);
424 ASSERT_OUTSIDE_BEGIN_END(ctx);
425
426 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
427
Brian Paul8c41a142005-11-19 15:36:28 +0000428 if (format != GL_PROGRAM_FORMAT_ASCII_ARB) {
429 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramStringARB(format)");
430 return;
431 }
432
Michal Krol157ec8b2004-03-10 18:02:01 +0000433 if (target == GL_VERTEX_PROGRAM_ARB
434 && ctx->Extensions.ARB_vertex_program) {
Brian Paul122629f2006-07-20 16:49:57 +0000435 struct gl_vertex_program *prog = ctx->VertexProgram.Current;
Brian Paul8c41a142005-11-19 15:36:28 +0000436 _mesa_parse_arb_vertex_program(ctx, target, string, len, prog);
Michal Krol157ec8b2004-03-10 18:02:01 +0000437
Eric Anholt185320a2008-01-15 15:08:34 -0800438 if (ctx->Program.ErrorPos == -1 && ctx->Driver.ProgramStringNotify)
Michal Krol157ec8b2004-03-10 18:02:01 +0000439 ctx->Driver.ProgramStringNotify( ctx, target, &prog->Base );
440 }
441 else if (target == GL_FRAGMENT_PROGRAM_ARB
442 && ctx->Extensions.ARB_fragment_program) {
Brian Paul122629f2006-07-20 16:49:57 +0000443 struct gl_fragment_program *prog = ctx->FragmentProgram.Current;
Brian Paul8c41a142005-11-19 15:36:28 +0000444 _mesa_parse_arb_fragment_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 {
450 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramStringARB(target)");
451 return;
452 }
453}
454
455
Roland Scheidegger86a48102007-11-09 14:46:59 +0100456/**
457 * Set a program env parameter register.
458 * \note Called from the GL API dispatcher.
459 * Note, this function is also used by the GL_NV_vertex_program extension
460 * (alias to ProgramParameterdNV)
461 */
Michal Krol157ec8b2004-03-10 18:02:01 +0000462void GLAPIENTRY
463_mesa_ProgramEnvParameter4dARB(GLenum target, GLuint index,
464 GLdouble x, GLdouble y, GLdouble z, GLdouble w)
465{
466 _mesa_ProgramEnvParameter4fARB(target, index, (GLfloat) x, (GLfloat) y,
467 (GLfloat) z, (GLfloat) w);
468}
469
470
Roland Scheidegger86a48102007-11-09 14:46:59 +0100471/**
472 * Set a program env parameter register.
473 * \note Called from the GL API dispatcher.
474 * Note, this function is also used by the GL_NV_vertex_program extension
475 * (alias to ProgramParameterdvNV)
476 */
Michal Krol157ec8b2004-03-10 18:02:01 +0000477void GLAPIENTRY
478_mesa_ProgramEnvParameter4dvARB(GLenum target, GLuint index,
479 const GLdouble *params)
480{
481 _mesa_ProgramEnvParameter4fARB(target, index, (GLfloat) params[0],
482 (GLfloat) params[1], (GLfloat) params[2],
483 (GLfloat) params[3]);
484}
485
486
Roland Scheidegger86a48102007-11-09 14:46:59 +0100487/**
488 * Set a program env parameter register.
489 * \note Called from the GL API dispatcher.
490 * Note, this function is also used by the GL_NV_vertex_program extension
491 * (alias to ProgramParameterfNV)
492 */
Michal Krol157ec8b2004-03-10 18:02:01 +0000493void GLAPIENTRY
494_mesa_ProgramEnvParameter4fARB(GLenum target, GLuint index,
495 GLfloat x, GLfloat y, GLfloat z, GLfloat w)
496{
497 GET_CURRENT_CONTEXT(ctx);
498 ASSERT_OUTSIDE_BEGIN_END(ctx);
499
Brian Paul027ed1b2009-04-24 09:43:44 -0600500 FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
Michal Krol157ec8b2004-03-10 18:02:01 +0000501
502 if (target == GL_FRAGMENT_PROGRAM_ARB
503 && ctx->Extensions.ARB_fragment_program) {
Brian Paul05051032005-11-01 04:36:33 +0000504 if (index >= ctx->Const.FragmentProgram.MaxEnvParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000505 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameter(index)");
506 return;
507 }
508 ASSIGN_4V(ctx->FragmentProgram.Parameters[index], x, y, z, w);
509 }
Roland Scheidegger86a48102007-11-09 14:46:59 +0100510 else if (target == GL_VERTEX_PROGRAM_ARB /* == GL_VERTEX_PROGRAM_NV */
511 && (ctx->Extensions.ARB_vertex_program || ctx->Extensions.NV_vertex_program)) {
Brian Paul05051032005-11-01 04:36:33 +0000512 if (index >= ctx->Const.VertexProgram.MaxEnvParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000513 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameter(index)");
514 return;
515 }
516 ASSIGN_4V(ctx->VertexProgram.Parameters[index], x, y, z, w);
517 }
518 else {
519 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramEnvParameter(target)");
520 return;
521 }
522}
523
Roland Scheidegger86a48102007-11-09 14:46:59 +0100524/**
525 * Set a program env parameter register.
526 * \note Called from the GL API dispatcher.
527 * Note, this function is also used by the GL_NV_vertex_program extension
528 * (alias to ProgramParameterfvNV)
529 */
Michal Krol157ec8b2004-03-10 18:02:01 +0000530void GLAPIENTRY
531_mesa_ProgramEnvParameter4fvARB(GLenum target, GLuint index,
532 const GLfloat *params)
533{
534 _mesa_ProgramEnvParameter4fARB(target, index, params[0], params[1],
535 params[2], params[3]);
536}
537
538
539void GLAPIENTRY
Ian Romanick8c41c752006-08-15 16:47:34 +0000540_mesa_ProgramEnvParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
541 const GLfloat *params)
542{
543 GET_CURRENT_CONTEXT(ctx);
Brian223d7cb2007-01-23 16:37:51 -0700544 GLint i;
Ian Romanick8c41c752006-08-15 16:47:34 +0000545 GLfloat * dest;
546 ASSERT_OUTSIDE_BEGIN_END(ctx);
547
Brian Paul027ed1b2009-04-24 09:43:44 -0600548 FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
Ian Romanick8c41c752006-08-15 16:47:34 +0000549
550 if (count <= 0) {
551 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameters4fv(count)");
552 }
553
554 if (target == GL_FRAGMENT_PROGRAM_ARB
555 && ctx->Extensions.ARB_fragment_program) {
556 if ((index + count) > ctx->Const.FragmentProgram.MaxEnvParams) {
557 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameters4fv(index + count)");
558 return;
559 }
560 dest = ctx->FragmentProgram.Parameters[index];
561 }
562 else if (target == GL_VERTEX_PROGRAM_ARB
563 && ctx->Extensions.ARB_vertex_program) {
564 if ((index + count) > ctx->Const.VertexProgram.MaxEnvParams) {
565 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameters4fv(index + count)");
566 return;
567 }
568 dest = ctx->VertexProgram.Parameters[index];
569 }
570 else {
571 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramEnvParameters4fv(target)");
572 return;
573 }
574
575 for ( i = 0 ; i < count ; i++ ) {
576 COPY_4V(dest, params);
577 params += 4;
578 dest += 4;
579 }
580}
581
582
583void GLAPIENTRY
Michal Krol157ec8b2004-03-10 18:02:01 +0000584_mesa_GetProgramEnvParameterdvARB(GLenum target, GLuint index,
585 GLdouble *params)
586{
587 GET_CURRENT_CONTEXT(ctx);
588 GLfloat fparams[4];
589
590 _mesa_GetProgramEnvParameterfvARB(target, index, fparams);
591 if (ctx->ErrorValue == GL_NO_ERROR) {
592 params[0] = fparams[0];
593 params[1] = fparams[1];
594 params[2] = fparams[2];
595 params[3] = fparams[3];
596 }
597}
598
599
600void GLAPIENTRY
601_mesa_GetProgramEnvParameterfvARB(GLenum target, GLuint index,
602 GLfloat *params)
603{
604 GET_CURRENT_CONTEXT(ctx);
605
Brian Paul548be382009-03-11 20:08:37 -0600606 ASSERT_OUTSIDE_BEGIN_END(ctx);
Michal Krol157ec8b2004-03-10 18:02:01 +0000607
608 if (target == GL_FRAGMENT_PROGRAM_ARB
609 && ctx->Extensions.ARB_fragment_program) {
Brian Paul05051032005-11-01 04:36:33 +0000610 if (index >= ctx->Const.FragmentProgram.MaxEnvParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000611 _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramEnvParameter(index)");
612 return;
613 }
614 COPY_4V(params, ctx->FragmentProgram.Parameters[index]);
615 }
Brian Paul83c74b72004-10-16 00:29:03 +0000616 else if (target == GL_VERTEX_PROGRAM_ARB
Michal Krol157ec8b2004-03-10 18:02:01 +0000617 && ctx->Extensions.ARB_vertex_program) {
Brian Paul05051032005-11-01 04:36:33 +0000618 if (index >= ctx->Const.VertexProgram.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->VertexProgram.Parameters[index]);
623 }
624 else {
625 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramEnvParameter(target)");
626 return;
627 }
628}
629
630
631/**
632 * Note, this function is also used by the GL_NV_fragment_program extension.
633 */
634void GLAPIENTRY
635_mesa_ProgramLocalParameter4fARB(GLenum target, GLuint index,
636 GLfloat x, GLfloat y, GLfloat z, GLfloat w)
637{
638 GET_CURRENT_CONTEXT(ctx);
Brian Paul122629f2006-07-20 16:49:57 +0000639 struct gl_program *prog;
Michal Krol157ec8b2004-03-10 18:02:01 +0000640 ASSERT_OUTSIDE_BEGIN_END(ctx);
641
Brian Paul027ed1b2009-04-24 09:43:44 -0600642 FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
Michal Krol157ec8b2004-03-10 18:02:01 +0000643
644 if ((target == GL_FRAGMENT_PROGRAM_NV
645 && ctx->Extensions.NV_fragment_program) ||
646 (target == GL_FRAGMENT_PROGRAM_ARB
647 && ctx->Extensions.ARB_fragment_program)) {
Brian Paul05051032005-11-01 04:36:33 +0000648 if (index >= ctx->Const.FragmentProgram.MaxLocalParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000649 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameterARB");
650 return;
651 }
652 prog = &(ctx->FragmentProgram.Current->Base);
653 }
654 else if (target == GL_VERTEX_PROGRAM_ARB
655 && ctx->Extensions.ARB_vertex_program) {
Brian Paul05051032005-11-01 04:36:33 +0000656 if (index >= ctx->Const.VertexProgram.MaxLocalParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000657 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameterARB");
658 return;
659 }
660 prog = &(ctx->VertexProgram.Current->Base);
661 }
662 else {
663 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameterARB");
664 return;
665 }
666
667 ASSERT(index < MAX_PROGRAM_LOCAL_PARAMS);
668 prog->LocalParams[index][0] = x;
669 prog->LocalParams[index][1] = y;
670 prog->LocalParams[index][2] = z;
671 prog->LocalParams[index][3] = w;
672}
673
674
675/**
676 * Note, this function is also used by the GL_NV_fragment_program extension.
677 */
678void GLAPIENTRY
679_mesa_ProgramLocalParameter4fvARB(GLenum target, GLuint index,
680 const GLfloat *params)
681{
682 _mesa_ProgramLocalParameter4fARB(target, index, params[0], params[1],
683 params[2], params[3]);
684}
685
686
Ian Romanick8c41c752006-08-15 16:47:34 +0000687void GLAPIENTRY
688_mesa_ProgramLocalParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
689 const GLfloat *params)
690{
691 GET_CURRENT_CONTEXT(ctx);
692 struct gl_program *prog;
Brian223d7cb2007-01-23 16:37:51 -0700693 GLint i;
Ian Romanick8c41c752006-08-15 16:47:34 +0000694 ASSERT_OUTSIDE_BEGIN_END(ctx);
695
Brian Paul027ed1b2009-04-24 09:43:44 -0600696 FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
Ian Romanick8c41c752006-08-15 16:47:34 +0000697
698 if (count <= 0) {
699 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fv(count)");
700 }
701
702 if (target == GL_FRAGMENT_PROGRAM_ARB
703 && ctx->Extensions.ARB_fragment_program) {
704 if ((index + count) > ctx->Const.FragmentProgram.MaxLocalParams) {
705 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fvEXT(index + count)");
706 return;
707 }
708 prog = &(ctx->FragmentProgram.Current->Base);
709 }
710 else if (target == GL_VERTEX_PROGRAM_ARB
711 && ctx->Extensions.ARB_vertex_program) {
712 if ((index + count) > ctx->Const.VertexProgram.MaxLocalParams) {
713 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fvEXT(index + count)");
714 return;
715 }
716 prog = &(ctx->VertexProgram.Current->Base);
717 }
718 else {
719 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameters4fvEXT(target)");
720 return;
721 }
722
723 for (i = 0; i < count; i++) {
724 ASSERT((index + i) < MAX_PROGRAM_LOCAL_PARAMS);
725 COPY_4V(prog->LocalParams[index + i], params);
726 params += 4;
727 }
728}
729
730
Michal Krol157ec8b2004-03-10 18:02:01 +0000731/**
732 * Note, this function is also used by the GL_NV_fragment_program extension.
733 */
734void GLAPIENTRY
735_mesa_ProgramLocalParameter4dARB(GLenum target, GLuint index,
736 GLdouble x, GLdouble y,
737 GLdouble z, GLdouble w)
738{
739 _mesa_ProgramLocalParameter4fARB(target, index, (GLfloat) x, (GLfloat) y,
740 (GLfloat) z, (GLfloat) w);
741}
742
743
744/**
745 * Note, this function is also used by the GL_NV_fragment_program extension.
746 */
747void GLAPIENTRY
748_mesa_ProgramLocalParameter4dvARB(GLenum target, GLuint index,
749 const GLdouble *params)
750{
751 _mesa_ProgramLocalParameter4fARB(target, index,
752 (GLfloat) params[0], (GLfloat) params[1],
753 (GLfloat) params[2], (GLfloat) params[3]);
754}
755
756
757/**
758 * Note, this function is also used by the GL_NV_fragment_program extension.
759 */
760void GLAPIENTRY
761_mesa_GetProgramLocalParameterfvARB(GLenum target, GLuint index,
762 GLfloat *params)
763{
Brian Paul122629f2006-07-20 16:49:57 +0000764 const struct gl_program *prog;
Michal Krol157ec8b2004-03-10 18:02:01 +0000765 GLuint maxParams;
766 GET_CURRENT_CONTEXT(ctx);
767 ASSERT_OUTSIDE_BEGIN_END(ctx);
768
769 if (target == GL_VERTEX_PROGRAM_ARB
770 && ctx->Extensions.ARB_vertex_program) {
771 prog = &(ctx->VertexProgram.Current->Base);
Brian Paul05051032005-11-01 04:36:33 +0000772 maxParams = ctx->Const.VertexProgram.MaxLocalParams;
Michal Krol157ec8b2004-03-10 18:02:01 +0000773 }
774 else if (target == GL_FRAGMENT_PROGRAM_ARB
775 && ctx->Extensions.ARB_fragment_program) {
776 prog = &(ctx->FragmentProgram.Current->Base);
Brian Paul05051032005-11-01 04:36:33 +0000777 maxParams = ctx->Const.FragmentProgram.MaxLocalParams;
Michal Krol157ec8b2004-03-10 18:02:01 +0000778 }
779 else if (target == GL_FRAGMENT_PROGRAM_NV
780 && ctx->Extensions.NV_fragment_program) {
781 prog = &(ctx->FragmentProgram.Current->Base);
782 maxParams = MAX_NV_FRAGMENT_PROGRAM_PARAMS;
783 }
784 else {
785 _mesa_error(ctx, GL_INVALID_ENUM,
786 "glGetProgramLocalParameterARB(target)");
787 return;
788 }
789
790 if (index >= maxParams) {
791 _mesa_error(ctx, GL_INVALID_VALUE,
792 "glGetProgramLocalParameterARB(index)");
793 return;
794 }
795
796 ASSERT(prog);
797 ASSERT(index < MAX_PROGRAM_LOCAL_PARAMS);
798 COPY_4V(params, prog->LocalParams[index]);
799}
800
801
802/**
803 * Note, this function is also used by the GL_NV_fragment_program extension.
804 */
805void GLAPIENTRY
806_mesa_GetProgramLocalParameterdvARB(GLenum target, GLuint index,
807 GLdouble *params)
808{
809 GET_CURRENT_CONTEXT(ctx);
810 GLfloat floatParams[4];
Brian Pauleb26cc62009-01-20 09:17:12 -0700811 ASSIGN_4V(floatParams, 0.0F, 0.0F, 0.0F, 0.0F);
Michal Krol157ec8b2004-03-10 18:02:01 +0000812 _mesa_GetProgramLocalParameterfvARB(target, index, floatParams);
813 if (ctx->ErrorValue == GL_NO_ERROR) {
814 COPY_4V(params, floatParams);
815 }
816}
817
818
819void GLAPIENTRY
820_mesa_GetProgramivARB(GLenum target, GLenum pname, GLint *params)
821{
Brian Paul05051032005-11-01 04:36:33 +0000822 const struct gl_program_constants *limits;
Brian Paul122629f2006-07-20 16:49:57 +0000823 struct gl_program *prog;
Michal Krol157ec8b2004-03-10 18:02:01 +0000824 GET_CURRENT_CONTEXT(ctx);
825
Brian Paul548be382009-03-11 20:08:37 -0600826 ASSERT_OUTSIDE_BEGIN_END(ctx);
Michal Krol157ec8b2004-03-10 18:02:01 +0000827
828 if (target == GL_VERTEX_PROGRAM_ARB
829 && ctx->Extensions.ARB_vertex_program) {
830 prog = &(ctx->VertexProgram.Current->Base);
Brian Paul05051032005-11-01 04:36:33 +0000831 limits = &ctx->Const.VertexProgram;
Michal Krol157ec8b2004-03-10 18:02:01 +0000832 }
833 else if (target == GL_FRAGMENT_PROGRAM_ARB
834 && ctx->Extensions.ARB_fragment_program) {
835 prog = &(ctx->FragmentProgram.Current->Base);
Brian Paul05051032005-11-01 04:36:33 +0000836 limits = &ctx->Const.FragmentProgram;
Michal Krol157ec8b2004-03-10 18:02:01 +0000837 }
838 else {
839 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(target)");
840 return;
841 }
842
843 ASSERT(prog);
Brian Paul05051032005-11-01 04:36:33 +0000844 ASSERT(limits);
Michal Krol157ec8b2004-03-10 18:02:01 +0000845
Brian Paul05051032005-11-01 04:36:33 +0000846 /* Queries supported for both vertex and fragment programs */
Michal Krol157ec8b2004-03-10 18:02:01 +0000847 switch (pname) {
848 case GL_PROGRAM_LENGTH_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000849 *params
850 = prog->String ? (GLint) _mesa_strlen((char *) prog->String) : 0;
851 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000852 case GL_PROGRAM_FORMAT_ARB:
853 *params = prog->Format;
Brian Paul05051032005-11-01 04:36:33 +0000854 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000855 case GL_PROGRAM_BINDING_ARB:
856 *params = prog->Id;
Brian Paul05051032005-11-01 04:36:33 +0000857 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000858 case GL_PROGRAM_INSTRUCTIONS_ARB:
859 *params = prog->NumInstructions;
Brian Paul05051032005-11-01 04:36:33 +0000860 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000861 case GL_MAX_PROGRAM_INSTRUCTIONS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000862 *params = limits->MaxInstructions;
863 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000864 case GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000865 *params = prog->NumNativeInstructions;
866 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000867 case GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000868 *params = limits->MaxNativeInstructions;
869 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000870 case GL_PROGRAM_TEMPORARIES_ARB:
871 *params = prog->NumTemporaries;
Brian Paul05051032005-11-01 04:36:33 +0000872 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000873 case GL_MAX_PROGRAM_TEMPORARIES_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000874 *params = limits->MaxTemps;
875 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000876 case GL_PROGRAM_NATIVE_TEMPORARIES_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000877 *params = prog->NumNativeTemporaries;
878 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000879 case GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000880 *params = limits->MaxNativeTemps;
881 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000882 case GL_PROGRAM_PARAMETERS_ARB:
883 *params = prog->NumParameters;
Brian Paul05051032005-11-01 04:36:33 +0000884 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000885 case GL_MAX_PROGRAM_PARAMETERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000886 *params = limits->MaxParameters;
887 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000888 case GL_PROGRAM_NATIVE_PARAMETERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000889 *params = prog->NumNativeParameters;
890 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000891 case GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000892 *params = limits->MaxNativeParameters;
893 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000894 case GL_PROGRAM_ATTRIBS_ARB:
895 *params = prog->NumAttributes;
Brian Paul05051032005-11-01 04:36:33 +0000896 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000897 case GL_MAX_PROGRAM_ATTRIBS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000898 *params = limits->MaxAttribs;
899 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000900 case GL_PROGRAM_NATIVE_ATTRIBS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000901 *params = prog->NumNativeAttributes;
902 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000903 case GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000904 *params = limits->MaxNativeAttribs;
905 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000906 case GL_PROGRAM_ADDRESS_REGISTERS_ARB:
907 *params = prog->NumAddressRegs;
Brian Paul05051032005-11-01 04:36:33 +0000908 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000909 case GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000910 *params = limits->MaxAddressRegs;
911 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000912 case GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000913 *params = prog->NumNativeAddressRegs;
914 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000915 case GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000916 *params = limits->MaxNativeAddressRegs;
917 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000918 case GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000919 *params = limits->MaxLocalParams;
920 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000921 case GL_MAX_PROGRAM_ENV_PARAMETERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000922 *params = limits->MaxEnvParams;
923 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000924 case GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000925 /*
926 * XXX we may not really need a driver callback here.
927 * If the number of native instructions, registers, etc. used
928 * are all below the maximums, we could return true.
929 * The spec says that even if this query returns true, there's
930 * no guarantee that the program will run in hardware.
931 */
Brian4ca7c802007-04-28 08:01:18 -0600932 if (prog->Id == 0) {
933 /* default/null program */
934 *params = GL_FALSE;
935 }
936 else if (ctx->Driver.IsProgramNative) {
937 /* ask the driver */
Michal Krol157ec8b2004-03-10 18:02:01 +0000938 *params = ctx->Driver.IsProgramNative( ctx, target, prog );
Brian4ca7c802007-04-28 08:01:18 -0600939 }
940 else {
941 /* probably running in software */
Michal Krol157ec8b2004-03-10 18:02:01 +0000942 *params = GL_TRUE;
Brian4ca7c802007-04-28 08:01:18 -0600943 }
Michal Krol157ec8b2004-03-10 18:02:01 +0000944 return;
Brian Paul05051032005-11-01 04:36:33 +0000945 default:
946 /* continue with fragment-program only queries below */
947 break;
948 }
949
950 /*
951 * The following apply to fragment programs only (at this time)
952 */
953 if (target == GL_FRAGMENT_PROGRAM_ARB) {
Brian Paul122629f2006-07-20 16:49:57 +0000954 const struct gl_fragment_program *fp = ctx->FragmentProgram.Current;
Brian Paul05051032005-11-01 04:36:33 +0000955 switch (pname) {
956 case GL_PROGRAM_ALU_INSTRUCTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700957 *params = fp->Base.NumNativeAluInstructions;
Brian Paul05051032005-11-01 04:36:33 +0000958 return;
959 case GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700960 *params = fp->Base.NumAluInstructions;
Brian Paul05051032005-11-01 04:36:33 +0000961 return;
962 case GL_PROGRAM_TEX_INSTRUCTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700963 *params = fp->Base.NumTexInstructions;
Brian Paul05051032005-11-01 04:36:33 +0000964 return;
965 case GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700966 *params = fp->Base.NumNativeTexInstructions;
Brian Paul05051032005-11-01 04:36:33 +0000967 return;
968 case GL_PROGRAM_TEX_INDIRECTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700969 *params = fp->Base.NumTexIndirections;
Brian Paul05051032005-11-01 04:36:33 +0000970 return;
971 case GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700972 *params = fp->Base.NumNativeTexIndirections;
Brian Paul05051032005-11-01 04:36:33 +0000973 return;
974 case GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB:
975 *params = limits->MaxAluInstructions;
976 return;
977 case GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB:
978 *params = limits->MaxNativeAluInstructions;
979 return;
980 case GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB:
981 *params = limits->MaxTexInstructions;
982 return;
983 case GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB:
984 *params = limits->MaxNativeTexInstructions;
985 return;
986 case GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB:
987 *params = limits->MaxTexIndirections;
988 return;
989 case GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB:
990 *params = limits->MaxNativeTexIndirections;
991 return;
992 default:
993 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(pname)");
994 return;
995 }
Michal Krol157ec8b2004-03-10 18:02:01 +0000996 }
997}
998
999
1000void GLAPIENTRY
1001_mesa_GetProgramStringARB(GLenum target, GLenum pname, GLvoid *string)
1002{
Brian Paul122629f2006-07-20 16:49:57 +00001003 const struct gl_program *prog;
Brian Paul308b85f2006-11-23 15:58:30 +00001004 char *dst = (char *) string;
Michal Krol157ec8b2004-03-10 18:02:01 +00001005 GET_CURRENT_CONTEXT(ctx);
1006
Brian Paul548be382009-03-11 20:08:37 -06001007 ASSERT_OUTSIDE_BEGIN_END(ctx);
Michal Krol157ec8b2004-03-10 18:02:01 +00001008
1009 if (target == GL_VERTEX_PROGRAM_ARB) {
1010 prog = &(ctx->VertexProgram.Current->Base);
1011 }
1012 else if (target == GL_FRAGMENT_PROGRAM_ARB) {
1013 prog = &(ctx->FragmentProgram.Current->Base);
1014 }
1015 else {
1016 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramStringARB(target)");
1017 return;
1018 }
1019
1020 ASSERT(prog);
1021
1022 if (pname != GL_PROGRAM_STRING_ARB) {
1023 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramStringARB(pname)");
1024 return;
1025 }
1026
Brian Paul308b85f2006-11-23 15:58:30 +00001027 if (prog->String)
1028 _mesa_memcpy(dst, prog->String, _mesa_strlen((char *) prog->String));
1029 else
1030 *dst = '\0';
Michal Krol157ec8b2004-03-10 18:02:01 +00001031}