blob: 981565ab8f1880438c34722aa2685d84fe627a08 [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
77 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
78
79 /* Error-check target and get curProg */
80 if ((target == GL_VERTEX_PROGRAM_ARB) && /* == GL_VERTEX_PROGRAM_NV */
81 (ctx->Extensions.NV_vertex_program ||
82 ctx->Extensions.ARB_vertex_program)) {
83 curProg = &ctx->VertexProgram.Current->Base;
84 }
85 else if ((target == GL_FRAGMENT_PROGRAM_NV
86 && ctx->Extensions.NV_fragment_program) ||
87 (target == GL_FRAGMENT_PROGRAM_ARB
88 && ctx->Extensions.ARB_fragment_program)) {
89 curProg = &ctx->FragmentProgram.Current->Base;
90 }
91 else {
92 _mesa_error(ctx, GL_INVALID_ENUM, "glBindProgramNV/ARB(target)");
93 return;
94 }
95
96 /*
97 * Get pointer to new program to bind.
98 * NOTE: binding to a non-existant program is not an error.
99 * That's supposed to be caught in glBegin.
100 */
101 if (id == 0) {
102 /* Bind a default program */
103 newProg = NULL;
104 if (target == GL_VERTEX_PROGRAM_ARB) /* == GL_VERTEX_PROGRAM_NV */
105 newProg = &ctx->Shared->DefaultVertexProgram->Base;
106 else
107 newProg = &ctx->Shared->DefaultFragmentProgram->Base;
108 }
109 else {
110 /* Bind a user program */
111 newProg = _mesa_lookup_program(ctx, id);
112 if (!newProg || newProg == &_mesa_DummyProgram) {
113 /* allocate a new program now */
114 newProg = ctx->Driver.NewProgram(ctx, target, id);
115 if (!newProg) {
116 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindProgramNV/ARB");
117 return;
118 }
119 _mesa_HashInsert(ctx->Shared->Programs, id, newProg);
120 }
121 else if (!compatible_program_targets(newProg->Target, target)) {
122 _mesa_error(ctx, GL_INVALID_OPERATION,
123 "glBindProgramNV/ARB(target mismatch)");
124 return;
125 }
126 }
127
128 /** All error checking is complete now **/
129
130 if (curProg->Id == id) {
131 /* binding same program - no change */
132 return;
133 }
134
135 /* bind newProg */
136 if (target == GL_VERTEX_PROGRAM_ARB) { /* == GL_VERTEX_PROGRAM_NV */
137 _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current,
138 (struct gl_vertex_program *) newProg);
139 }
140 else if (target == GL_FRAGMENT_PROGRAM_NV ||
141 target == GL_FRAGMENT_PROGRAM_ARB) {
142 _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current,
143 (struct gl_fragment_program *) newProg);
144 }
145
146 /* Never null pointers */
147 ASSERT(ctx->VertexProgram.Current);
148 ASSERT(ctx->FragmentProgram.Current);
149
150 if (ctx->Driver.BindProgram)
151 ctx->Driver.BindProgram(ctx, target, newProg);
152}
153
154
155/**
156 * Delete a list of programs.
157 * \note Not compiled into display lists.
158 * \note Called by both glDeleteProgramsNV and glDeleteProgramsARB.
159 */
160void GLAPIENTRY
161_mesa_DeletePrograms(GLsizei n, const GLuint *ids)
162{
163 GLint i;
164 GET_CURRENT_CONTEXT(ctx);
165 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
166
167 if (n < 0) {
168 _mesa_error( ctx, GL_INVALID_VALUE, "glDeleteProgramsNV" );
169 return;
170 }
171
172 for (i = 0; i < n; i++) {
173 if (ids[i] != 0) {
174 struct gl_program *prog = _mesa_lookup_program(ctx, ids[i]);
175 if (prog == &_mesa_DummyProgram) {
176 _mesa_HashRemove(ctx->Shared->Programs, ids[i]);
177 }
178 else if (prog) {
179 /* Unbind program if necessary */
180 if (prog->Target == GL_VERTEX_PROGRAM_ARB || /* == GL_VERTEX_PROGRAM_NV */
181 prog->Target == GL_VERTEX_STATE_PROGRAM_NV) {
182 if (ctx->VertexProgram.Current &&
183 ctx->VertexProgram.Current->Base.Id == ids[i]) {
184 /* unbind this currently bound program */
185 _mesa_BindProgram(prog->Target, 0);
186 }
187 }
188 else if (prog->Target == GL_FRAGMENT_PROGRAM_NV ||
189 prog->Target == GL_FRAGMENT_PROGRAM_ARB) {
190 if (ctx->FragmentProgram.Current &&
191 ctx->FragmentProgram.Current->Base.Id == ids[i]) {
192 /* unbind this currently bound program */
193 _mesa_BindProgram(prog->Target, 0);
194 }
195 }
196 else {
197 _mesa_problem(ctx, "bad target in glDeleteProgramsNV");
198 return;
199 }
200 /* The ID is immediately available for re-use now */
201 _mesa_HashRemove(ctx->Shared->Programs, ids[i]);
202 _mesa_reference_program(ctx, &prog, NULL);
203 }
204 }
205 }
206}
207
208
209/**
210 * Generate a list of new program identifiers.
211 * \note Not compiled into display lists.
212 * \note Called by both glGenProgramsNV and glGenProgramsARB.
213 */
214void GLAPIENTRY
215_mesa_GenPrograms(GLsizei n, GLuint *ids)
216{
217 GLuint first;
218 GLuint i;
219 GET_CURRENT_CONTEXT(ctx);
220 ASSERT_OUTSIDE_BEGIN_END(ctx);
221
222 if (n < 0) {
223 _mesa_error(ctx, GL_INVALID_VALUE, "glGenPrograms");
224 return;
225 }
226
227 if (!ids)
228 return;
229
230 first = _mesa_HashFindFreeKeyBlock(ctx->Shared->Programs, n);
231
232 /* Insert pointer to dummy program as placeholder */
233 for (i = 0; i < (GLuint) n; i++) {
234 _mesa_HashInsert(ctx->Shared->Programs, first + i, &_mesa_DummyProgram);
235 }
236
237 /* Return the program names */
238 for (i = 0; i < (GLuint) n; i++) {
239 ids[i] = first + i;
240 }
241}
242
243
Michal Krol157ec8b2004-03-10 18:02:01 +0000244void GLAPIENTRY
245_mesa_EnableVertexAttribArrayARB(GLuint index)
246{
247 GET_CURRENT_CONTEXT(ctx);
248 ASSERT_OUTSIDE_BEGIN_END(ctx);
249
Brian Paul05051032005-11-01 04:36:33 +0000250 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000251 _mesa_error(ctx, GL_INVALID_VALUE,
252 "glEnableVertexAttribArrayARB(index)");
253 return;
254 }
255
256 FLUSH_VERTICES(ctx, _NEW_ARRAY);
Ian Romanickee34e6e2006-06-12 16:26:29 +0000257 ctx->Array.ArrayObj->VertexAttrib[index].Enabled = GL_TRUE;
258 ctx->Array.ArrayObj->_Enabled |= _NEW_ARRAY_ATTRIB(index);
Michal Krol157ec8b2004-03-10 18:02:01 +0000259 ctx->Array.NewState |= _NEW_ARRAY_ATTRIB(index);
260}
261
262
263void GLAPIENTRY
264_mesa_DisableVertexAttribArrayARB(GLuint index)
265{
266 GET_CURRENT_CONTEXT(ctx);
267 ASSERT_OUTSIDE_BEGIN_END(ctx);
268
Brian Paul05051032005-11-01 04:36:33 +0000269 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000270 _mesa_error(ctx, GL_INVALID_VALUE,
271 "glEnableVertexAttribArrayARB(index)");
272 return;
273 }
274
275 FLUSH_VERTICES(ctx, _NEW_ARRAY);
Ian Romanickee34e6e2006-06-12 16:26:29 +0000276 ctx->Array.ArrayObj->VertexAttrib[index].Enabled = GL_FALSE;
277 ctx->Array.ArrayObj->_Enabled &= ~_NEW_ARRAY_ATTRIB(index);
Michal Krol157ec8b2004-03-10 18:02:01 +0000278 ctx->Array.NewState |= _NEW_ARRAY_ATTRIB(index);
279}
280
281
282void GLAPIENTRY
283_mesa_GetVertexAttribdvARB(GLuint index, GLenum pname, GLdouble *params)
284{
285 GLfloat fparams[4];
286 GET_CURRENT_CONTEXT(ctx);
287 ASSERT_OUTSIDE_BEGIN_END(ctx);
288
289 _mesa_GetVertexAttribfvARB(index, pname, fparams);
290 if (ctx->ErrorValue == GL_NO_ERROR) {
291 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
292 COPY_4V(params, fparams);
293 }
294 else {
295 params[0] = fparams[0];
296 }
297 }
298}
299
300
301void GLAPIENTRY
302_mesa_GetVertexAttribfvARB(GLuint index, GLenum pname, GLfloat *params)
303{
304 GET_CURRENT_CONTEXT(ctx);
305 ASSERT_OUTSIDE_BEGIN_END(ctx);
306
Brian Paul590b5572006-11-04 17:28:38 +0000307 if (index >= MAX_VERTEX_PROGRAM_ATTRIBS) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000308 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribfvARB(index)");
309 return;
310 }
311
312 switch (pname) {
313 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
Ian Romanickee34e6e2006-06-12 16:26:29 +0000314 params[0] = (GLfloat) ctx->Array.ArrayObj->VertexAttrib[index].Enabled;
Michal Krol157ec8b2004-03-10 18:02:01 +0000315 break;
316 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
Ian Romanickee34e6e2006-06-12 16:26:29 +0000317 params[0] = (GLfloat) ctx->Array.ArrayObj->VertexAttrib[index].Size;
Michal Krol157ec8b2004-03-10 18:02:01 +0000318 break;
319 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
Ian Romanickee34e6e2006-06-12 16:26:29 +0000320 params[0] = (GLfloat) ctx->Array.ArrayObj->VertexAttrib[index].Stride;
Michal Krol157ec8b2004-03-10 18:02:01 +0000321 break;
322 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
Ian Romanickee34e6e2006-06-12 16:26:29 +0000323 params[0] = (GLfloat) ctx->Array.ArrayObj->VertexAttrib[index].Type;
Michal Krol157ec8b2004-03-10 18:02:01 +0000324 break;
325 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
Ian Romanickee34e6e2006-06-12 16:26:29 +0000326 params[0] = ctx->Array.ArrayObj->VertexAttrib[index].Normalized;
Michal Krol157ec8b2004-03-10 18:02:01 +0000327 break;
328 case GL_CURRENT_VERTEX_ATTRIB_ARB:
Brian Paul590b5572006-11-04 17:28:38 +0000329 if (index == 0) {
330 _mesa_error(ctx, GL_INVALID_OPERATION,
Brian Pauladf3a642006-11-04 17:31:21 +0000331 "glGetVertexAttribfvARB(index==0)");
Brian Paul590b5572006-11-04 17:28:38 +0000332 return;
333 }
Michal Krolbb38cad2006-04-11 11:41:11 +0000334 FLUSH_CURRENT(ctx, 0);
335 COPY_4V(params, ctx->Current.Attrib[VERT_ATTRIB_GENERIC0 + index]);
Michal Krol157ec8b2004-03-10 18:02:01 +0000336 break;
337 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
Ian Romanickee34e6e2006-06-12 16:26:29 +0000338 params[0] = (GLfloat) ctx->Array.ArrayObj->VertexAttrib[index].BufferObj->Name;
Tilman Sauerbeck6be81272006-05-30 16:57:52 +0000339 break;
Michal Krol157ec8b2004-03-10 18:02:01 +0000340 default:
341 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribfvARB(pname)");
342 return;
343 }
344}
345
346
347void GLAPIENTRY
348_mesa_GetVertexAttribivARB(GLuint index, GLenum pname, GLint *params)
349{
350 GLfloat fparams[4];
351 GET_CURRENT_CONTEXT(ctx);
352 ASSERT_OUTSIDE_BEGIN_END(ctx);
353
354 _mesa_GetVertexAttribfvARB(index, pname, fparams);
355 if (ctx->ErrorValue == GL_NO_ERROR) {
356 if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) {
357 COPY_4V_CAST(params, fparams, GLint); /* float to int */
358 }
359 else {
360 params[0] = (GLint) fparams[0];
361 }
362 }
363}
364
365
366void GLAPIENTRY
367_mesa_GetVertexAttribPointervARB(GLuint index, GLenum pname, GLvoid **pointer)
368{
369 GET_CURRENT_CONTEXT(ctx);
370 ASSERT_OUTSIDE_BEGIN_END(ctx);
371
Brian Paul05051032005-11-01 04:36:33 +0000372 if (index >= ctx->Const.VertexProgram.MaxAttribs) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000373 _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexAttribPointerARB(index)");
374 return;
375 }
376
377 if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {
378 _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexAttribPointerARB(pname)");
379 return;
380 }
381
Ian Romanickee34e6e2006-06-12 16:26:29 +0000382 *pointer = (GLvoid *) ctx->Array.ArrayObj->VertexAttrib[index].Ptr;
Michal Krol157ec8b2004-03-10 18:02:01 +0000383}
384
385
Brian Paulf49c0d02006-11-02 16:20:29 +0000386/**
387 * Determine if id names a vertex or fragment program.
388 * \note Not compiled into display lists.
389 * \note Called from both glIsProgramNV and glIsProgramARB.
390 * \param id is the program identifier
391 * \return GL_TRUE if id is a program, else GL_FALSE.
392 */
393GLboolean GLAPIENTRY
394_mesa_IsProgramARB(GLuint id)
395{
Brian Paul308b85f2006-11-23 15:58:30 +0000396 struct gl_program *prog = NULL;
Brian Paulf49c0d02006-11-02 16:20:29 +0000397 GET_CURRENT_CONTEXT(ctx);
398 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
399
400 if (id == 0)
401 return GL_FALSE;
402
Brian Paul308b85f2006-11-23 15:58:30 +0000403 prog = _mesa_lookup_program(ctx, id);
404 if (prog && (prog != &_mesa_DummyProgram))
Brian Paulf49c0d02006-11-02 16:20:29 +0000405 return GL_TRUE;
406 else
407 return GL_FALSE;
408}
409
410
Michal Krol157ec8b2004-03-10 18:02:01 +0000411void GLAPIENTRY
412_mesa_ProgramStringARB(GLenum target, GLenum format, GLsizei len,
413 const GLvoid *string)
414{
415 GET_CURRENT_CONTEXT(ctx);
416 ASSERT_OUTSIDE_BEGIN_END(ctx);
417
418 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
419
Brian Paul8c41a142005-11-19 15:36:28 +0000420 if (format != GL_PROGRAM_FORMAT_ASCII_ARB) {
421 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramStringARB(format)");
422 return;
423 }
424
Michal Krol157ec8b2004-03-10 18:02:01 +0000425 if (target == GL_VERTEX_PROGRAM_ARB
426 && ctx->Extensions.ARB_vertex_program) {
Brian Paul122629f2006-07-20 16:49:57 +0000427 struct gl_vertex_program *prog = ctx->VertexProgram.Current;
Brian Paul8c41a142005-11-19 15:36:28 +0000428 _mesa_parse_arb_vertex_program(ctx, target, string, len, prog);
Michal Krol157ec8b2004-03-10 18:02:01 +0000429
Eric Anholt185320a2008-01-15 15:08:34 -0800430 if (ctx->Program.ErrorPos == -1 && ctx->Driver.ProgramStringNotify)
Michal Krol157ec8b2004-03-10 18:02:01 +0000431 ctx->Driver.ProgramStringNotify( ctx, target, &prog->Base );
432 }
433 else if (target == GL_FRAGMENT_PROGRAM_ARB
434 && ctx->Extensions.ARB_fragment_program) {
Brian Paul122629f2006-07-20 16:49:57 +0000435 struct gl_fragment_program *prog = ctx->FragmentProgram.Current;
Brian Paul8c41a142005-11-19 15:36:28 +0000436 _mesa_parse_arb_fragment_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 {
442 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramStringARB(target)");
443 return;
444 }
445}
446
447
Roland Scheidegger86a48102007-11-09 14:46:59 +0100448/**
449 * Set a program env parameter register.
450 * \note Called from the GL API dispatcher.
451 * Note, this function is also used by the GL_NV_vertex_program extension
452 * (alias to ProgramParameterdNV)
453 */
Michal Krol157ec8b2004-03-10 18:02:01 +0000454void GLAPIENTRY
455_mesa_ProgramEnvParameter4dARB(GLenum target, GLuint index,
456 GLdouble x, GLdouble y, GLdouble z, GLdouble w)
457{
458 _mesa_ProgramEnvParameter4fARB(target, index, (GLfloat) x, (GLfloat) y,
459 (GLfloat) z, (GLfloat) w);
460}
461
462
Roland Scheidegger86a48102007-11-09 14:46:59 +0100463/**
464 * Set a program env parameter register.
465 * \note Called from the GL API dispatcher.
466 * Note, this function is also used by the GL_NV_vertex_program extension
467 * (alias to ProgramParameterdvNV)
468 */
Michal Krol157ec8b2004-03-10 18:02:01 +0000469void GLAPIENTRY
470_mesa_ProgramEnvParameter4dvARB(GLenum target, GLuint index,
471 const GLdouble *params)
472{
473 _mesa_ProgramEnvParameter4fARB(target, index, (GLfloat) params[0],
474 (GLfloat) params[1], (GLfloat) params[2],
475 (GLfloat) params[3]);
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 ProgramParameterfNV)
484 */
Michal Krol157ec8b2004-03-10 18:02:01 +0000485void GLAPIENTRY
486_mesa_ProgramEnvParameter4fARB(GLenum target, GLuint index,
487 GLfloat x, GLfloat y, GLfloat z, GLfloat w)
488{
489 GET_CURRENT_CONTEXT(ctx);
490 ASSERT_OUTSIDE_BEGIN_END(ctx);
491
Brian Paul64e331e2009-04-21 15:56:45 -0600492 FLUSH_VERTICES(ctx, _NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS);
Michal Krol157ec8b2004-03-10 18:02:01 +0000493
494 if (target == GL_FRAGMENT_PROGRAM_ARB
495 && ctx->Extensions.ARB_fragment_program) {
Brian Paul05051032005-11-01 04:36:33 +0000496 if (index >= ctx->Const.FragmentProgram.MaxEnvParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000497 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameter(index)");
498 return;
499 }
500 ASSIGN_4V(ctx->FragmentProgram.Parameters[index], x, y, z, w);
501 }
Roland Scheidegger86a48102007-11-09 14:46:59 +0100502 else if (target == GL_VERTEX_PROGRAM_ARB /* == GL_VERTEX_PROGRAM_NV */
503 && (ctx->Extensions.ARB_vertex_program || ctx->Extensions.NV_vertex_program)) {
Brian Paul05051032005-11-01 04:36:33 +0000504 if (index >= ctx->Const.VertexProgram.MaxEnvParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000505 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameter(index)");
506 return;
507 }
508 ASSIGN_4V(ctx->VertexProgram.Parameters[index], x, y, z, w);
509 }
510 else {
511 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramEnvParameter(target)");
512 return;
513 }
514}
515
Roland Scheidegger86a48102007-11-09 14:46:59 +0100516/**
517 * Set a program env parameter register.
518 * \note Called from the GL API dispatcher.
519 * Note, this function is also used by the GL_NV_vertex_program extension
520 * (alias to ProgramParameterfvNV)
521 */
Michal Krol157ec8b2004-03-10 18:02:01 +0000522void GLAPIENTRY
523_mesa_ProgramEnvParameter4fvARB(GLenum target, GLuint index,
524 const GLfloat *params)
525{
526 _mesa_ProgramEnvParameter4fARB(target, index, params[0], params[1],
527 params[2], params[3]);
528}
529
530
531void GLAPIENTRY
Ian Romanick8c41c752006-08-15 16:47:34 +0000532_mesa_ProgramEnvParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
533 const GLfloat *params)
534{
535 GET_CURRENT_CONTEXT(ctx);
Brian223d7cb2007-01-23 16:37:51 -0700536 GLint i;
Ian Romanick8c41c752006-08-15 16:47:34 +0000537 GLfloat * dest;
538 ASSERT_OUTSIDE_BEGIN_END(ctx);
539
Brian Paul64e331e2009-04-21 15:56:45 -0600540 FLUSH_VERTICES(ctx, _NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS);
Ian Romanick8c41c752006-08-15 16:47:34 +0000541
542 if (count <= 0) {
543 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameters4fv(count)");
544 }
545
546 if (target == GL_FRAGMENT_PROGRAM_ARB
547 && ctx->Extensions.ARB_fragment_program) {
548 if ((index + count) > ctx->Const.FragmentProgram.MaxEnvParams) {
549 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameters4fv(index + count)");
550 return;
551 }
552 dest = ctx->FragmentProgram.Parameters[index];
553 }
554 else if (target == GL_VERTEX_PROGRAM_ARB
555 && ctx->Extensions.ARB_vertex_program) {
556 if ((index + count) > ctx->Const.VertexProgram.MaxEnvParams) {
557 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameters4fv(index + count)");
558 return;
559 }
560 dest = ctx->VertexProgram.Parameters[index];
561 }
562 else {
563 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramEnvParameters4fv(target)");
564 return;
565 }
566
567 for ( i = 0 ; i < count ; i++ ) {
568 COPY_4V(dest, params);
569 params += 4;
570 dest += 4;
571 }
572}
573
574
575void GLAPIENTRY
Michal Krol157ec8b2004-03-10 18:02:01 +0000576_mesa_GetProgramEnvParameterdvARB(GLenum target, GLuint index,
577 GLdouble *params)
578{
579 GET_CURRENT_CONTEXT(ctx);
580 GLfloat fparams[4];
581
582 _mesa_GetProgramEnvParameterfvARB(target, index, fparams);
583 if (ctx->ErrorValue == GL_NO_ERROR) {
584 params[0] = fparams[0];
585 params[1] = fparams[1];
586 params[2] = fparams[2];
587 params[3] = fparams[3];
588 }
589}
590
591
592void GLAPIENTRY
593_mesa_GetProgramEnvParameterfvARB(GLenum target, GLuint index,
594 GLfloat *params)
595{
596 GET_CURRENT_CONTEXT(ctx);
597
Brian Paul548be382009-03-11 20:08:37 -0600598 ASSERT_OUTSIDE_BEGIN_END(ctx);
Michal Krol157ec8b2004-03-10 18:02:01 +0000599
600 if (target == GL_FRAGMENT_PROGRAM_ARB
601 && ctx->Extensions.ARB_fragment_program) {
Brian Paul05051032005-11-01 04:36:33 +0000602 if (index >= ctx->Const.FragmentProgram.MaxEnvParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000603 _mesa_error(ctx, GL_INVALID_VALUE, "glGetProgramEnvParameter(index)");
604 return;
605 }
606 COPY_4V(params, ctx->FragmentProgram.Parameters[index]);
607 }
Brian Paul83c74b72004-10-16 00:29:03 +0000608 else if (target == GL_VERTEX_PROGRAM_ARB
Michal Krol157ec8b2004-03-10 18:02:01 +0000609 && ctx->Extensions.ARB_vertex_program) {
Brian Paul05051032005-11-01 04:36:33 +0000610 if (index >= ctx->Const.VertexProgram.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->VertexProgram.Parameters[index]);
615 }
616 else {
617 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramEnvParameter(target)");
618 return;
619 }
620}
621
622
623/**
624 * Note, this function is also used by the GL_NV_fragment_program extension.
625 */
626void GLAPIENTRY
627_mesa_ProgramLocalParameter4fARB(GLenum target, GLuint index,
628 GLfloat x, GLfloat y, GLfloat z, GLfloat w)
629{
630 GET_CURRENT_CONTEXT(ctx);
Brian Paul122629f2006-07-20 16:49:57 +0000631 struct gl_program *prog;
Michal Krol157ec8b2004-03-10 18:02:01 +0000632 ASSERT_OUTSIDE_BEGIN_END(ctx);
633
Brian Paul64e331e2009-04-21 15:56:45 -0600634 FLUSH_VERTICES(ctx, _NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS);
Michal Krol157ec8b2004-03-10 18:02:01 +0000635
636 if ((target == GL_FRAGMENT_PROGRAM_NV
637 && ctx->Extensions.NV_fragment_program) ||
638 (target == GL_FRAGMENT_PROGRAM_ARB
639 && ctx->Extensions.ARB_fragment_program)) {
Brian Paul05051032005-11-01 04:36:33 +0000640 if (index >= ctx->Const.FragmentProgram.MaxLocalParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000641 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameterARB");
642 return;
643 }
644 prog = &(ctx->FragmentProgram.Current->Base);
645 }
646 else if (target == GL_VERTEX_PROGRAM_ARB
647 && ctx->Extensions.ARB_vertex_program) {
Brian Paul05051032005-11-01 04:36:33 +0000648 if (index >= ctx->Const.VertexProgram.MaxLocalParams) {
Michal Krol157ec8b2004-03-10 18:02:01 +0000649 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameterARB");
650 return;
651 }
652 prog = &(ctx->VertexProgram.Current->Base);
653 }
654 else {
655 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameterARB");
656 return;
657 }
658
659 ASSERT(index < MAX_PROGRAM_LOCAL_PARAMS);
660 prog->LocalParams[index][0] = x;
661 prog->LocalParams[index][1] = y;
662 prog->LocalParams[index][2] = z;
663 prog->LocalParams[index][3] = w;
664}
665
666
667/**
668 * Note, this function is also used by the GL_NV_fragment_program extension.
669 */
670void GLAPIENTRY
671_mesa_ProgramLocalParameter4fvARB(GLenum target, GLuint index,
672 const GLfloat *params)
673{
674 _mesa_ProgramLocalParameter4fARB(target, index, params[0], params[1],
675 params[2], params[3]);
676}
677
678
Ian Romanick8c41c752006-08-15 16:47:34 +0000679void GLAPIENTRY
680_mesa_ProgramLocalParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
681 const GLfloat *params)
682{
683 GET_CURRENT_CONTEXT(ctx);
684 struct gl_program *prog;
Brian223d7cb2007-01-23 16:37:51 -0700685 GLint i;
Ian Romanick8c41c752006-08-15 16:47:34 +0000686 ASSERT_OUTSIDE_BEGIN_END(ctx);
687
Brian Paul64e331e2009-04-21 15:56:45 -0600688 FLUSH_VERTICES(ctx, _NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS);
Ian Romanick8c41c752006-08-15 16:47:34 +0000689
690 if (count <= 0) {
691 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fv(count)");
692 }
693
694 if (target == GL_FRAGMENT_PROGRAM_ARB
695 && ctx->Extensions.ARB_fragment_program) {
696 if ((index + count) > ctx->Const.FragmentProgram.MaxLocalParams) {
697 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fvEXT(index + count)");
698 return;
699 }
700 prog = &(ctx->FragmentProgram.Current->Base);
701 }
702 else if (target == GL_VERTEX_PROGRAM_ARB
703 && ctx->Extensions.ARB_vertex_program) {
704 if ((index + count) > ctx->Const.VertexProgram.MaxLocalParams) {
705 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fvEXT(index + count)");
706 return;
707 }
708 prog = &(ctx->VertexProgram.Current->Base);
709 }
710 else {
711 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameters4fvEXT(target)");
712 return;
713 }
714
715 for (i = 0; i < count; i++) {
716 ASSERT((index + i) < MAX_PROGRAM_LOCAL_PARAMS);
717 COPY_4V(prog->LocalParams[index + i], params);
718 params += 4;
719 }
720}
721
722
Michal Krol157ec8b2004-03-10 18:02:01 +0000723/**
724 * Note, this function is also used by the GL_NV_fragment_program extension.
725 */
726void GLAPIENTRY
727_mesa_ProgramLocalParameter4dARB(GLenum target, GLuint index,
728 GLdouble x, GLdouble y,
729 GLdouble z, GLdouble w)
730{
731 _mesa_ProgramLocalParameter4fARB(target, index, (GLfloat) x, (GLfloat) y,
732 (GLfloat) z, (GLfloat) w);
733}
734
735
736/**
737 * Note, this function is also used by the GL_NV_fragment_program extension.
738 */
739void GLAPIENTRY
740_mesa_ProgramLocalParameter4dvARB(GLenum target, GLuint index,
741 const GLdouble *params)
742{
743 _mesa_ProgramLocalParameter4fARB(target, index,
744 (GLfloat) params[0], (GLfloat) params[1],
745 (GLfloat) params[2], (GLfloat) params[3]);
746}
747
748
749/**
750 * Note, this function is also used by the GL_NV_fragment_program extension.
751 */
752void GLAPIENTRY
753_mesa_GetProgramLocalParameterfvARB(GLenum target, GLuint index,
754 GLfloat *params)
755{
Brian Paul122629f2006-07-20 16:49:57 +0000756 const struct gl_program *prog;
Michal Krol157ec8b2004-03-10 18:02:01 +0000757 GLuint maxParams;
758 GET_CURRENT_CONTEXT(ctx);
759 ASSERT_OUTSIDE_BEGIN_END(ctx);
760
761 if (target == GL_VERTEX_PROGRAM_ARB
762 && ctx->Extensions.ARB_vertex_program) {
763 prog = &(ctx->VertexProgram.Current->Base);
Brian Paul05051032005-11-01 04:36:33 +0000764 maxParams = ctx->Const.VertexProgram.MaxLocalParams;
Michal Krol157ec8b2004-03-10 18:02:01 +0000765 }
766 else if (target == GL_FRAGMENT_PROGRAM_ARB
767 && ctx->Extensions.ARB_fragment_program) {
768 prog = &(ctx->FragmentProgram.Current->Base);
Brian Paul05051032005-11-01 04:36:33 +0000769 maxParams = ctx->Const.FragmentProgram.MaxLocalParams;
Michal Krol157ec8b2004-03-10 18:02:01 +0000770 }
771 else if (target == GL_FRAGMENT_PROGRAM_NV
772 && ctx->Extensions.NV_fragment_program) {
773 prog = &(ctx->FragmentProgram.Current->Base);
774 maxParams = MAX_NV_FRAGMENT_PROGRAM_PARAMS;
775 }
776 else {
777 _mesa_error(ctx, GL_INVALID_ENUM,
778 "glGetProgramLocalParameterARB(target)");
779 return;
780 }
781
782 if (index >= maxParams) {
783 _mesa_error(ctx, GL_INVALID_VALUE,
784 "glGetProgramLocalParameterARB(index)");
785 return;
786 }
787
788 ASSERT(prog);
789 ASSERT(index < MAX_PROGRAM_LOCAL_PARAMS);
790 COPY_4V(params, prog->LocalParams[index]);
791}
792
793
794/**
795 * Note, this function is also used by the GL_NV_fragment_program extension.
796 */
797void GLAPIENTRY
798_mesa_GetProgramLocalParameterdvARB(GLenum target, GLuint index,
799 GLdouble *params)
800{
801 GET_CURRENT_CONTEXT(ctx);
802 GLfloat floatParams[4];
Brian Pauleb26cc62009-01-20 09:17:12 -0700803 ASSIGN_4V(floatParams, 0.0F, 0.0F, 0.0F, 0.0F);
Michal Krol157ec8b2004-03-10 18:02:01 +0000804 _mesa_GetProgramLocalParameterfvARB(target, index, floatParams);
805 if (ctx->ErrorValue == GL_NO_ERROR) {
806 COPY_4V(params, floatParams);
807 }
808}
809
810
811void GLAPIENTRY
812_mesa_GetProgramivARB(GLenum target, GLenum pname, GLint *params)
813{
Brian Paul05051032005-11-01 04:36:33 +0000814 const struct gl_program_constants *limits;
Brian Paul122629f2006-07-20 16:49:57 +0000815 struct gl_program *prog;
Michal Krol157ec8b2004-03-10 18:02:01 +0000816 GET_CURRENT_CONTEXT(ctx);
817
Brian Paul548be382009-03-11 20:08:37 -0600818 ASSERT_OUTSIDE_BEGIN_END(ctx);
Michal Krol157ec8b2004-03-10 18:02:01 +0000819
820 if (target == GL_VERTEX_PROGRAM_ARB
821 && ctx->Extensions.ARB_vertex_program) {
822 prog = &(ctx->VertexProgram.Current->Base);
Brian Paul05051032005-11-01 04:36:33 +0000823 limits = &ctx->Const.VertexProgram;
Michal Krol157ec8b2004-03-10 18:02:01 +0000824 }
825 else if (target == GL_FRAGMENT_PROGRAM_ARB
826 && ctx->Extensions.ARB_fragment_program) {
827 prog = &(ctx->FragmentProgram.Current->Base);
Brian Paul05051032005-11-01 04:36:33 +0000828 limits = &ctx->Const.FragmentProgram;
Michal Krol157ec8b2004-03-10 18:02:01 +0000829 }
830 else {
831 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(target)");
832 return;
833 }
834
835 ASSERT(prog);
Brian Paul05051032005-11-01 04:36:33 +0000836 ASSERT(limits);
Michal Krol157ec8b2004-03-10 18:02:01 +0000837
Brian Paul05051032005-11-01 04:36:33 +0000838 /* Queries supported for both vertex and fragment programs */
Michal Krol157ec8b2004-03-10 18:02:01 +0000839 switch (pname) {
840 case GL_PROGRAM_LENGTH_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000841 *params
842 = prog->String ? (GLint) _mesa_strlen((char *) prog->String) : 0;
843 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000844 case GL_PROGRAM_FORMAT_ARB:
845 *params = prog->Format;
Brian Paul05051032005-11-01 04:36:33 +0000846 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000847 case GL_PROGRAM_BINDING_ARB:
848 *params = prog->Id;
Brian Paul05051032005-11-01 04:36:33 +0000849 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000850 case GL_PROGRAM_INSTRUCTIONS_ARB:
851 *params = prog->NumInstructions;
Brian Paul05051032005-11-01 04:36:33 +0000852 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000853 case GL_MAX_PROGRAM_INSTRUCTIONS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000854 *params = limits->MaxInstructions;
855 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000856 case GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000857 *params = prog->NumNativeInstructions;
858 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000859 case GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000860 *params = limits->MaxNativeInstructions;
861 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000862 case GL_PROGRAM_TEMPORARIES_ARB:
863 *params = prog->NumTemporaries;
Brian Paul05051032005-11-01 04:36:33 +0000864 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000865 case GL_MAX_PROGRAM_TEMPORARIES_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000866 *params = limits->MaxTemps;
867 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000868 case GL_PROGRAM_NATIVE_TEMPORARIES_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000869 *params = prog->NumNativeTemporaries;
870 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000871 case GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000872 *params = limits->MaxNativeTemps;
873 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000874 case GL_PROGRAM_PARAMETERS_ARB:
875 *params = prog->NumParameters;
Brian Paul05051032005-11-01 04:36:33 +0000876 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000877 case GL_MAX_PROGRAM_PARAMETERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000878 *params = limits->MaxParameters;
879 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000880 case GL_PROGRAM_NATIVE_PARAMETERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000881 *params = prog->NumNativeParameters;
882 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000883 case GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000884 *params = limits->MaxNativeParameters;
885 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000886 case GL_PROGRAM_ATTRIBS_ARB:
887 *params = prog->NumAttributes;
Brian Paul05051032005-11-01 04:36:33 +0000888 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000889 case GL_MAX_PROGRAM_ATTRIBS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000890 *params = limits->MaxAttribs;
891 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000892 case GL_PROGRAM_NATIVE_ATTRIBS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000893 *params = prog->NumNativeAttributes;
894 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000895 case GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000896 *params = limits->MaxNativeAttribs;
897 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000898 case GL_PROGRAM_ADDRESS_REGISTERS_ARB:
899 *params = prog->NumAddressRegs;
Brian Paul05051032005-11-01 04:36:33 +0000900 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000901 case GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000902 *params = limits->MaxAddressRegs;
903 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000904 case GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000905 *params = prog->NumNativeAddressRegs;
906 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000907 case GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000908 *params = limits->MaxNativeAddressRegs;
909 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000910 case GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000911 *params = limits->MaxLocalParams;
912 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000913 case GL_MAX_PROGRAM_ENV_PARAMETERS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000914 *params = limits->MaxEnvParams;
915 return;
Michal Krol157ec8b2004-03-10 18:02:01 +0000916 case GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB:
Brian Paul05051032005-11-01 04:36:33 +0000917 /*
918 * XXX we may not really need a driver callback here.
919 * If the number of native instructions, registers, etc. used
920 * are all below the maximums, we could return true.
921 * The spec says that even if this query returns true, there's
922 * no guarantee that the program will run in hardware.
923 */
Brian4ca7c802007-04-28 08:01:18 -0600924 if (prog->Id == 0) {
925 /* default/null program */
926 *params = GL_FALSE;
927 }
928 else if (ctx->Driver.IsProgramNative) {
929 /* ask the driver */
Michal Krol157ec8b2004-03-10 18:02:01 +0000930 *params = ctx->Driver.IsProgramNative( ctx, target, prog );
Brian4ca7c802007-04-28 08:01:18 -0600931 }
932 else {
933 /* probably running in software */
Michal Krol157ec8b2004-03-10 18:02:01 +0000934 *params = GL_TRUE;
Brian4ca7c802007-04-28 08:01:18 -0600935 }
Michal Krol157ec8b2004-03-10 18:02:01 +0000936 return;
Brian Paul05051032005-11-01 04:36:33 +0000937 default:
938 /* continue with fragment-program only queries below */
939 break;
940 }
941
942 /*
943 * The following apply to fragment programs only (at this time)
944 */
945 if (target == GL_FRAGMENT_PROGRAM_ARB) {
Brian Paul122629f2006-07-20 16:49:57 +0000946 const struct gl_fragment_program *fp = ctx->FragmentProgram.Current;
Brian Paul05051032005-11-01 04:36:33 +0000947 switch (pname) {
948 case GL_PROGRAM_ALU_INSTRUCTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700949 *params = fp->Base.NumNativeAluInstructions;
Brian Paul05051032005-11-01 04:36:33 +0000950 return;
951 case GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700952 *params = fp->Base.NumAluInstructions;
Brian Paul05051032005-11-01 04:36:33 +0000953 return;
954 case GL_PROGRAM_TEX_INSTRUCTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700955 *params = fp->Base.NumTexInstructions;
Brian Paul05051032005-11-01 04:36:33 +0000956 return;
957 case GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700958 *params = fp->Base.NumNativeTexInstructions;
Brian Paul05051032005-11-01 04:36:33 +0000959 return;
960 case GL_PROGRAM_TEX_INDIRECTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700961 *params = fp->Base.NumTexIndirections;
Brian Paul05051032005-11-01 04:36:33 +0000962 return;
963 case GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB:
Brian21f99792007-01-09 11:00:21 -0700964 *params = fp->Base.NumNativeTexIndirections;
Brian Paul05051032005-11-01 04:36:33 +0000965 return;
966 case GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB:
967 *params = limits->MaxAluInstructions;
968 return;
969 case GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB:
970 *params = limits->MaxNativeAluInstructions;
971 return;
972 case GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB:
973 *params = limits->MaxTexInstructions;
974 return;
975 case GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB:
976 *params = limits->MaxNativeTexInstructions;
977 return;
978 case GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB:
979 *params = limits->MaxTexIndirections;
980 return;
981 case GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB:
982 *params = limits->MaxNativeTexIndirections;
983 return;
984 default:
985 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(pname)");
986 return;
987 }
Michal Krol157ec8b2004-03-10 18:02:01 +0000988 }
989}
990
991
992void GLAPIENTRY
993_mesa_GetProgramStringARB(GLenum target, GLenum pname, GLvoid *string)
994{
Brian Paul122629f2006-07-20 16:49:57 +0000995 const struct gl_program *prog;
Brian Paul308b85f2006-11-23 15:58:30 +0000996 char *dst = (char *) string;
Michal Krol157ec8b2004-03-10 18:02:01 +0000997 GET_CURRENT_CONTEXT(ctx);
998
Brian Paul548be382009-03-11 20:08:37 -0600999 ASSERT_OUTSIDE_BEGIN_END(ctx);
Michal Krol157ec8b2004-03-10 18:02:01 +00001000
1001 if (target == GL_VERTEX_PROGRAM_ARB) {
1002 prog = &(ctx->VertexProgram.Current->Base);
1003 }
1004 else if (target == GL_FRAGMENT_PROGRAM_ARB) {
1005 prog = &(ctx->FragmentProgram.Current->Base);
1006 }
1007 else {
1008 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramStringARB(target)");
1009 return;
1010 }
1011
1012 ASSERT(prog);
1013
1014 if (pname != GL_PROGRAM_STRING_ARB) {
1015 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramStringARB(pname)");
1016 return;
1017 }
1018
Brian Paul308b85f2006-11-23 15:58:30 +00001019 if (prog->String)
1020 _mesa_memcpy(dst, prog->String, _mesa_strlen((char *) prog->String));
1021 else
1022 *dst = '\0';
Michal Krol157ec8b2004-03-10 18:02:01 +00001023}