Some groundwork for GL_ARB_vertex/fragment_program.
[mesa.git] / src / mesa / main / arbprogram.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 5.1
4 *
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /**
26 * \file arbprogram.c
27 * \brief ARB_vertex/fragment_program state management functions.
28 * \author Brian Paul
29 */
30
31
32 #include "glheader.h"
33 #include "context.h"
34 #include "hash.h"
35 #include "imports.h"
36 #include "macros.h"
37 #include "mtypes.h"
38 #include "arbprogram.h"
39
40
41
42 void
43 _mesa_VertexAttrib1sARB(GLuint index, GLshort x)
44 {
45 }
46
47 void
48 _mesa_VertexAttrib1fARB(GLuint index, GLfloat x)
49 {
50 }
51
52 void
53 _mesa_VertexAttrib1dARB(GLuint index, GLdouble x)
54 {
55 }
56
57 void
58 _mesa_VertexAttrib2sARB(GLuint index, GLshort x, GLshort y)
59 {
60 }
61
62 void
63 _mesa_VertexAttrib2fARB(GLuint index, GLfloat x, GLfloat y)
64 {
65 }
66
67 void
68 _mesa_VertexAttrib2dARB(GLuint index, GLdouble x, GLdouble y)
69 {
70 }
71
72 void
73 _mesa_VertexAttrib3sARB(GLuint index, GLshort x, GLshort y, GLshort z)
74 {
75 }
76
77 void
78 _mesa_VertexAttrib3fARB(GLuint index, GLfloat x, GLfloat y, GLfloat z)
79 {
80 }
81
82 void
83 _mesa_VertexAttrib3dARB(GLuint index, GLdouble x, GLdouble y, GLdouble z)
84 {
85 }
86
87 void
88 _mesa_VertexAttrib4sARB(GLuint index, GLshort x, GLshort y, GLshort z, GLshort w)
89 {
90 }
91
92 void
93 _mesa_VertexAttrib4fARB(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
94 {
95 }
96
97 void
98 _mesa_VertexAttrib4dARB(GLuint index, GLdouble x, GLdouble y, GLdouble z, GLdouble w)
99 {
100 }
101
102 void
103 _mesa_VertexAttrib4NubARB(GLuint index, GLubyte x, GLubyte y, GLubyte z, GLubyte w)
104 {
105 }
106
107 void
108 _mesa_VertexAttrib1svARB(GLuint index, const GLshort *v)
109 {
110 }
111
112 void
113 _mesa_VertexAttrib1fvARB(GLuint index, const GLfloat *v)
114 {
115 }
116
117 void
118 _mesa_VertexAttrib1dvARB(GLuint index, const GLdouble *v)
119 {
120 }
121
122 void
123 _mesa_VertexAttrib2svARB(GLuint index, const GLshort *v)
124 {
125 }
126
127 void
128 _mesa_VertexAttrib2fvARB(GLuint index, const GLfloat *v)
129 {
130 }
131
132 void
133 _mesa_VertexAttrib2dvARB(GLuint index, const GLdouble *v)
134 {
135 }
136
137 void
138 _mesa_VertexAttrib3svARB(GLuint index, const GLshort *v)
139 {
140 }
141
142 void
143 _mesa_VertexAttrib3fvARB(GLuint index, const GLfloat *v)
144 {
145 }
146
147 void
148 _mesa_VertexAttrib3dvARB(GLuint index, const GLdouble *v)
149 {
150 }
151
152 void
153 _mesa_VertexAttrib4bvARB(GLuint index, const GLbyte *v)
154 {
155 }
156
157 void
158 _mesa_VertexAttrib4svARB(GLuint index, const GLshort *v)
159 {
160 }
161
162 void
163 _mesa_VertexAttrib4ivARB(GLuint index, const GLint *v)
164 {
165 }
166
167 void
168 _mesa_VertexAttrib4ubvARB(GLuint index, const GLubyte *v)
169 {
170 }
171
172 void
173 _mesa_VertexAttrib4usvARB(GLuint index, const GLushort *v)
174 {
175 }
176
177 void
178 _mesa_VertexAttrib4uivARB(GLuint index, const GLuint *v)
179 {
180 }
181
182 void
183 _mesa_VertexAttrib4fvARB(GLuint index, const GLfloat *v)
184 {
185 }
186
187 void
188 _mesa_VertexAttrib4dvARB(GLuint index, const GLdouble *v)
189 {
190 }
191
192 void
193 _mesa_VertexAttrib4NbvARB(GLuint index, const GLbyte *v)
194 {
195 }
196
197 void
198 _mesa_VertexAttrib4NsvARB(GLuint index, const GLshort *v)
199 {
200 }
201
202 void
203 _mesa_VertexAttrib4NivARB(GLuint index, const GLint *v)
204 {
205 }
206
207 void
208 _mesa_VertexAttrib4NubvARB(GLuint index, const GLubyte *v)
209 {
210 }
211
212 void
213 _mesa_VertexAttrib4NusvARB(GLuint index, const GLushort *v)
214 {
215 }
216
217 void
218 _mesa_VertexAttrib4NuivARB(GLuint index, const GLuint *v)
219 {
220 }
221
222
223 void
224 _mesa_VertexAttribPointerARB(GLuint index, GLint size, GLenum type,
225 GLboolean normalized, GLsizei stride,
226 const GLvoid *pointer)
227 {
228 }
229
230
231 void
232 _mesa_EnableVertexAttribArrayARB(GLuint index)
233 {
234 }
235
236
237 void
238 _mesa_DisableVertexAttribArrayARB(GLuint index)
239 {
240 }
241
242
243 void
244 _mesa_GetVertexAttribdvARB(GLuint index, GLenum pname, GLdouble *params)
245 {
246 }
247
248
249 void
250 _mesa_GetVertexAttribfvARB(GLuint index, GLenum pname, GLfloat *params)
251 {
252 }
253
254
255 void
256 _mesa_GetVertexAttribivARB(GLuint index, GLenum pname, GLint *params)
257 {
258 }
259
260
261 void
262 _mesa_GetVertexAttribPointervARB(GLuint index, GLenum pname, GLvoid **pointer)
263 {
264 }
265
266
267 void
268 _mesa_ProgramStringARB(GLenum target, GLenum format, GLsizei len,
269 const GLvoid *string)
270 {
271 }
272
273
274 void
275 _mesa_BindProgramARB(GLenum target, GLuint program)
276 {
277 }
278
279
280 void
281 _mesa_DeleteProgramsARB(GLsizei n, const GLuint *programs)
282 {
283 }
284
285
286 void
287 _mesa_GenProgramsARB(GLsizei n, GLuint *programs)
288 {
289 }
290
291
292 void
293 _mesa_ProgramEnvParameter4dARB(GLenum target, GLuint index,
294 GLdouble x, GLdouble y, GLdouble z, GLdouble w)
295 {
296 }
297
298
299 void
300 _mesa_ProgramEnvParameter4dvARB(GLenum target, GLuint index,
301 const GLdouble *params)
302 {
303 }
304
305
306 void
307 _mesa_ProgramEnvParameter4fARB(GLenum target, GLuint index,
308 GLfloat x, GLfloat y, GLfloat z, GLfloat w)
309 {
310 }
311
312
313 void
314 _mesa_ProgramEnvParameter4fvARB(GLenum target, GLuint index,
315 const GLfloat *params)
316 {
317 }
318
319
320 #if 111
321
322 void
323 _mesa_ProgramLocalParameter4fARB(GLenum target, GLuint index,
324 GLfloat x, GLfloat y, GLfloat z, GLfloat w)
325 {
326 GET_CURRENT_CONTEXT(ctx);
327 ASSERT_OUTSIDE_BEGIN_END(ctx);
328
329 if (target == GL_FRAGMENT_PROGRAM_NV) {
330 struct fragment_program *fprog = ctx->FragmentProgram.Current;
331 if (!fprog) {
332 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameterARB");
333 return;
334 }
335 if (index >= MAX_NV_FRAGMENT_PROGRAM_PARAMS) {
336 _mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameterARB");
337 return;
338 }
339 fprog->Base.LocalParams[index][0] = x;
340 fprog->Base.LocalParams[index][1] = y;
341 fprog->Base.LocalParams[index][2] = z;
342 fprog->Base.LocalParams[index][3] = w;
343 }
344 else {
345 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramLocalParameterARB");
346 return;
347 }
348 }
349
350
351 void
352 _mesa_ProgramLocalParameter4fvARB(GLenum target, GLuint index,
353 const GLfloat *params)
354 {
355 glProgramLocalParameter4fARB(target, index, params[0], params[1],
356 params[2], params[3]);
357 }
358
359
360 void
361 _mesa_ProgramLocalParameter4dARB(GLenum target, GLuint index,
362 GLdouble x, GLdouble y,
363 GLdouble z, GLdouble w)
364 {
365 glProgramLocalParameter4fARB(target, index, (GLfloat)x, (GLfloat)y,
366 (GLfloat)z, (GLfloat)w);
367 }
368
369
370 void
371 _mesa_ProgramLocalParameter4dvARB(GLenum target, GLuint index,
372 const GLdouble *params)
373 {
374 glProgramLocalParameter4fARB(target, index, (GLfloat)params[0],
375 (GLfloat)params[1], (GLfloat)params[2],
376 (GLfloat)params[3]);
377 }
378
379
380 void
381 _mesa_GetProgramLocalParameterfvARB(GLenum target, GLuint index,
382 GLfloat *params)
383 {
384 struct program *prog;
385 GLuint maxParams;
386 GET_CURRENT_CONTEXT(ctx);
387 ASSERT_OUTSIDE_BEGIN_END(ctx);
388
389 if (target == GL_VERTEX_PROGRAM_ARB
390 && ctx->Extensions.ARB_vertex_program) {
391 prog = &(ctx->VertexProgram.Current->Base);
392 maxParams = ctx->Const.MaxVertexProgramParams;
393 }
394 else if ((target == GL_FRAGMENT_PROGRAM_ARB
395 && ctx->Extensions.ARB_fragment_program) ||
396 (target == GL_FRAGMENT_PROGRAM_NV
397 && ctx->Extensions.NV_fragment_program)) {
398 prog = &(ctx->FragmentProgram.Current->Base);
399 maxParams = ctx->Const.MaxFragmentProgramParams;
400 }
401 else {
402 _mesa_error(ctx, GL_INVALID_ENUM,
403 "glGetProgramLocalParameterARB(target)");
404 return;
405 }
406
407 if (index >= maxParams) {
408 _mesa_error(ctx, GL_INVALID_VALUE,
409 "glGetProgramLocalParameterARB(index)");
410 return;
411 }
412
413 ASSERT(prog);
414 params[0] = prog->LocalParams[index][0];
415 params[1] = prog->LocalParams[index][1];
416 params[2] = prog->LocalParams[index][2];
417 params[3] = prog->LocalParams[index][3];
418 }
419
420
421 void
422 _mesa_GetProgramLocalParameterdvARB(GLenum target, GLuint index,
423 GLdouble *params)
424 {
425 GLfloat floatParams[4];
426 glGetProgramLocalParameterfvARB(target, index, floatParams);
427 COPY_4V(params, floatParams);
428 }
429
430 #else
431
432
433 void
434 _mesa_ProgramLocalParameter4dARB(GLenum target, GLuint index,
435 GLdouble x, GLdouble y,
436 GLdouble z, GLdouble w)
437 {
438 }
439
440
441 void
442 _mesa_ProgramLocalParameter4dvARB(GLenum target, GLuint index,
443 const GLdouble *params)
444 {
445 }
446
447
448 void
449 _mesa_ProgramLocalParameter4fARB(GLenum target, GLuint index,
450 GLfloat x, GLfloat y, GLfloat z, GLfloat w)
451 {
452 }
453
454
455 void
456 _mesa_ProgramLocalParameter4fvARB(GLenum target, GLuint index,
457 const GLfloat *params)
458 {
459 }
460
461 #endif
462
463 void
464 _mesa_GetProgramEnvParameterdvARB(GLenum target, GLuint index,
465 GLdouble *params)
466 {
467 }
468
469
470 void
471 _mesa_GetProgramEnvParameterfvARB(GLenum target, GLuint index,
472 GLfloat *params)
473 {
474 }
475
476
477 #if 000
478 void
479 _mesa_GetProgramLocalParameterdvARB(GLenum target, GLuint index,
480 GLdouble *params)
481 {
482 }
483
484
485 void
486 _mesa_GetProgramLocalParameterfvARB(GLenum target, GLuint index,
487 GLfloat *params)
488 {
489 }
490 #endif
491
492
493
494 void
495 _mesa_GetProgramivARB(GLenum target, GLenum pname, GLint *params)
496 {
497 struct program *prog;
498 GET_CURRENT_CONTEXT(ctx);
499 ASSERT_OUTSIDE_BEGIN_END(ctx);
500
501 if (target == GL_VERTEX_PROGRAM_ARB) {
502 prog = &(ctx->VertexProgram.Current->Base);
503 }
504 else if (target == GL_FRAGMENT_PROGRAM_ARB) {
505 prog = &(ctx->FragmentProgram.Current->Base);
506 }
507 else {
508 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(target)");
509 return;
510 }
511
512 ASSERT(prog);
513
514 switch (pname) {
515 case GL_PROGRAM_LENGTH_ARB:
516 *params = prog->String ? _mesa_strlen((char *) prog->String) : 0;
517 break;
518 case GL_PROGRAM_FORMAT_ARB:
519 *params = prog->Format;
520 break;
521 case GL_PROGRAM_BINDING_ARB:
522 *params = prog->Id;
523 break;
524 case GL_PROGRAM_INSTRUCTIONS_ARB:
525 *params = prog->NumInstructions;
526 break;
527 case GL_MAX_PROGRAM_INSTRUCTIONS_ARB:
528 case GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB:
529 case GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB:
530 case GL_PROGRAM_TEMPORARIES_ARB:
531 case GL_MAX_PROGRAM_TEMPORARIES_ARB:
532 case GL_PROGRAM_NATIVE_TEMPORARIES_ARB:
533 case GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB:
534 case GL_PROGRAM_PARAMETERS_ARB:
535 case GL_MAX_PROGRAM_PARAMETERS_ARB:
536 case GL_PROGRAM_NATIVE_PARAMETERS_ARB:
537 case GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB:
538 case GL_PROGRAM_ATTRIBS_ARB:
539 case GL_MAX_PROGRAM_ATTRIBS_ARB:
540 case GL_PROGRAM_NATIVE_ATTRIBS_ARB:
541 case GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB:
542 case GL_PROGRAM_ADDRESS_REGISTERS_ARB:
543 case GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB:
544 case GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB:
545 case GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB:
546 case GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB:
547 case GL_MAX_PROGRAM_ENV_PARAMETERS_ARB:
548 case GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB:
549 break;
550 default:
551 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramivARB(pname)");
552 return;
553 }
554 }
555
556
557 void
558 _mesa_GetProgramStringARB(GLenum target, GLenum pname, GLvoid *string)
559 {
560 struct program *prog;
561 GET_CURRENT_CONTEXT(ctx);
562 ASSERT_OUTSIDE_BEGIN_END(ctx);
563
564 if (target == GL_VERTEX_PROGRAM_ARB) {
565 prog = &(ctx->VertexProgram.Current->Base);
566 }
567 else if (target == GL_FRAGMENT_PROGRAM_ARB) {
568 prog = &(ctx->FragmentProgram.Current->Base);
569 }
570 else {
571 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramStringARB(target)");
572 return;
573 }
574
575 ASSERT(prog);
576
577 if (pname != GL_PROGRAM_STRING_ARB) {
578 _mesa_error(ctx, GL_INVALID_ENUM, "glGetProgramStringARB(pname)");
579 return;
580 }
581
582 MEMCPY(string, prog->String, _mesa_strlen((char *) prog->String));
583 }
584
585
586 GLboolean
587 _mesa_IsProgramARB(GLuint program)
588 {
589 struct program *prog;
590 GET_CURRENT_CONTEXT(ctx);
591 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
592
593 if (program == 0)
594 return GL_FALSE;
595
596 prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, program);
597 if (prog && prog->Target)
598 return GL_TRUE;
599 else
600 return GL_FALSE;
601 }