Disable _mesa_3dlabs_create_{program,shader}_object references.
[mesa.git] / src / mesa / shader / shaderobjects.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.3
4 *
5 * Copyright (C) 2004-2005 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 shaderobjects.c
27 * ARB_shader_objects state management functions
28 * \author Michal Krol
29 */
30
31
32 #include "glheader.h"
33 #include "shaderobjects.h"
34 #include "shaderobjects_3dlabs.h"
35 #include "context.h"
36 #include "macros.h"
37 #include "hash.h"
38
39
40 void GLAPIENTRY
41 _mesa_DeleteObjectARB (GLhandleARB obj)
42 {
43 GET_CURRENT_CONTEXT(ctx);
44 struct gl2_unknown_intf **unk;
45 struct gl2_generic_intf **gen;
46
47 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
48 unk = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, obj);
49 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
50
51 if (unk == NULL)
52 {
53 _mesa_error (ctx, GL_INVALID_VALUE, "glDeleteObjectARB");
54 return;
55 }
56
57 gen = (struct gl2_generic_intf **) (**unk).QueryInterface (unk, UIID_GENERIC);
58 if (gen == NULL)
59 {
60 _mesa_error (ctx, GL_INVALID_VALUE, "glDeleteObjectARB");
61 return;
62 }
63
64 (**gen).Delete (gen);
65 (**gen)._unknown.Release ((struct gl2_unknown_intf **) gen);
66 }
67
68 GLhandleARB GLAPIENTRY
69 _mesa_GetHandleARB (GLenum pname)
70 {
71 GET_CURRENT_CONTEXT(ctx);
72
73 switch (pname)
74 {
75 case GL_PROGRAM_OBJECT_ARB:
76 if (ctx->ShaderObjects.current_program != NULL)
77 return (**ctx->ShaderObjects.current_program)._container._generic.GetName (
78 (struct gl2_generic_intf **) ctx->ShaderObjects.current_program);
79 break;
80 }
81
82 return 0;
83 }
84
85 void GLAPIENTRY
86 _mesa_DetachObjectARB (GLhandleARB containerObj, GLhandleARB attachedObj)
87 {
88 GET_CURRENT_CONTEXT(ctx);
89 struct gl2_unknown_intf **unkc, **unka;
90 struct gl2_container_intf **con;
91 struct gl2_generic_intf **att;
92
93 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
94 unkc = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, containerObj);
95 unka = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, attachedObj);
96 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
97
98 if (unkc == NULL || unka == NULL)
99 {
100 _mesa_error (ctx, GL_INVALID_VALUE, "glDetachObjectARB");
101 return;
102 }
103
104 con = (struct gl2_container_intf **) (**unkc).QueryInterface (unkc, UIID_CONTAINER);
105 if (con == NULL)
106 {
107 _mesa_error (ctx, GL_INVALID_OPERATION, "glDetachObjectARB");
108 return;
109 }
110
111 att = (struct gl2_generic_intf **) (**unka).QueryInterface (unka, UIID_GENERIC);
112 if (att == NULL)
113 {
114 (**con)._generic._unknown.Release ((struct gl2_unknown_intf **) con);
115 _mesa_error (ctx, GL_INVALID_VALUE, "glDetachObjectARB");
116 return;
117 }
118
119 if ((**con).Detach (con, att) == GL_FALSE)
120 {
121 (**con)._generic._unknown.Release ((struct gl2_unknown_intf **) con);
122 (**att)._unknown.Release ((struct gl2_unknown_intf **) att);
123 return;
124 }
125
126 (**con)._generic._unknown.Release ((struct gl2_unknown_intf **) con);
127 (**att)._unknown.Release ((struct gl2_unknown_intf **) att);
128 }
129
130 GLhandleARB GLAPIENTRY
131 _mesa_CreateShaderObjectARB (GLenum shaderType)
132 {
133 #if 0
134 return _mesa_3dlabs_create_shader_object (shaderType);
135 #endif
136 }
137
138 void GLAPIENTRY
139 _mesa_ShaderSourceARB (GLhandleARB shaderObj, GLsizei count, const GLcharARB **string,
140 const GLint *length)
141 {
142 GET_CURRENT_CONTEXT(ctx);
143 struct gl2_unknown_intf **unk;
144 struct gl2_shader_intf **sha;
145 GLint *offsets;
146 GLsizei i;
147 GLcharARB *source;
148
149 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
150 unk = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, shaderObj);
151 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
152
153 if (unk == NULL)
154 {
155 _mesa_error (ctx, GL_INVALID_VALUE, "glShaderSourceARB");
156 return;
157 }
158
159 sha = (struct gl2_shader_intf **) (**unk).QueryInterface (unk, UIID_SHADER);
160 if (sha == NULL)
161 {
162 _mesa_error (ctx, GL_INVALID_OPERATION, "glShaderSourceARB");
163 return;
164 }
165
166 /* this array holds offsets of where the appropriate string ends, thus the last
167 element will be set to the total length of the source code */
168 offsets = (GLint *) _mesa_malloc (count * sizeof (GLint));
169 if (offsets == NULL)
170 {
171 (**sha)._generic._unknown.Release ((struct gl2_unknown_intf **) sha);
172 _mesa_error (ctx, GL_OUT_OF_MEMORY, "glShaderSourceARB");
173 return;
174 }
175
176 for (i = 0; i < count; i++)
177 {
178 if (length == NULL || length[i] < 0)
179 offsets[i] = _mesa_strlen (string[i]);
180 else
181 offsets[i] = length[i];
182 /* accumulate string lengths */
183 if (i > 0)
184 offsets[i] += offsets[i - 1];
185 }
186
187 source = (GLcharARB *) _mesa_malloc ((offsets[count - 1] + 1) * sizeof (GLcharARB));
188 if (source == NULL)
189 {
190 _mesa_free ((void *) offsets);
191 (**sha)._generic._unknown.Release ((struct gl2_unknown_intf **) sha);
192 _mesa_error (ctx, GL_OUT_OF_MEMORY, "glShaderSourceARB");
193 return;
194 }
195
196 for (i = 0; i < count; i++)
197 {
198 GLint start = (i > 0) ? offsets[i - 1] : 0;
199 _mesa_memcpy (source + start, string[i], (offsets[i] - start) * sizeof (GLcharARB));
200 }
201 source[offsets[count - 1]] = '\0';
202
203 (**sha).SetSource (sha, source, offsets, count);
204 (**sha)._generic._unknown.Release ((struct gl2_unknown_intf **) sha);
205 }
206
207 void GLAPIENTRY
208 _mesa_CompileShaderARB (GLhandleARB shaderObj)
209 {
210 GET_CURRENT_CONTEXT(ctx);
211 struct gl2_unknown_intf **unk;
212 struct gl2_shader_intf **sha;
213
214 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
215 unk = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, shaderObj);
216 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
217
218 if (unk == NULL)
219 {
220 _mesa_error (ctx, GL_INVALID_VALUE, "glCompileShaderARB");
221 return;
222 }
223
224 sha = (struct gl2_shader_intf **) (**unk).QueryInterface (unk, UIID_SHADER);
225 if (sha == NULL)
226 {
227 _mesa_error (ctx, GL_INVALID_OPERATION, "glCompileShaderARB");
228 return;
229 }
230
231 (**sha).Compile (sha);
232 (**sha)._generic._unknown.Release ((struct gl2_unknown_intf **) sha);
233 }
234
235 GLhandleARB GLAPIENTRY
236 _mesa_CreateProgramObjectARB (void)
237 {
238 #if 0
239 return _mesa_3dlabs_create_program_object ();
240 #endif
241 }
242
243 void GLAPIENTRY
244 _mesa_AttachObjectARB (GLhandleARB containerObj, GLhandleARB obj)
245 {
246 GET_CURRENT_CONTEXT(ctx);
247 struct gl2_unknown_intf **unkc, **unka;
248 struct gl2_container_intf **con;
249 struct gl2_generic_intf **att;
250
251 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
252 unkc = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, containerObj);
253 unka = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, obj);
254 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
255
256 if (unkc == NULL || unka == NULL)
257 {
258 _mesa_error (ctx, GL_INVALID_VALUE, "glAttachObjectARB");
259 return;
260 }
261
262 con = (struct gl2_container_intf **) (**unkc).QueryInterface (unkc, UIID_CONTAINER);
263 if (con == NULL)
264 {
265 _mesa_error (ctx, GL_INVALID_VALUE, "glAttachObjectARB");
266 return;
267 }
268
269 att = (struct gl2_generic_intf **) (**unka).QueryInterface (unka, UIID_GENERIC);
270 if (att == NULL)
271 {
272 (**con)._generic._unknown.Release ((struct gl2_unknown_intf **) con);
273 _mesa_error (ctx, GL_INVALID_VALUE, "glAttachObjectARB");
274 return;
275 }
276
277 if (!(**con).Attach (con, att))
278 {
279 (**con)._generic._unknown.Release ((struct gl2_unknown_intf **) con);
280 (**att)._unknown.Release ((struct gl2_unknown_intf **) att);
281 return;
282 }
283
284 (**con)._generic._unknown.Release ((struct gl2_unknown_intf **) con);
285 (**att)._unknown.Release ((struct gl2_unknown_intf **) att);
286 }
287
288 void GLAPIENTRY
289 _mesa_LinkProgramARB (GLhandleARB programObj)
290 {
291 GET_CURRENT_CONTEXT(ctx);
292 struct gl2_unknown_intf **unk;
293 struct gl2_program_intf **pro;
294
295 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
296 unk = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, programObj);
297 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
298
299 if (unk == NULL)
300 {
301 _mesa_error (ctx, GL_INVALID_VALUE, "glLinkProgramARB");
302 return;
303 }
304
305 pro = (struct gl2_program_intf **) (**unk).QueryInterface (unk, UIID_PROGRAM);
306 if (pro == NULL)
307 {
308 _mesa_error (ctx, GL_INVALID_OPERATION, "glLinkProgramARB");
309 return;
310 }
311
312 if (pro == ctx->ShaderObjects.current_program)
313 {
314 /* TODO re-install executable program */
315 }
316
317 (**pro).Link (pro);
318 (**pro)._container._generic._unknown.Release ((struct gl2_unknown_intf **) pro);
319 }
320
321 void GLAPIENTRY
322 _mesa_UseProgramObjectARB (GLhandleARB programObj)
323 {
324 GET_CURRENT_CONTEXT(ctx);
325 struct gl2_program_intf **pro;
326
327 if (programObj == 0)
328 {
329 pro = NULL;
330 }
331 else
332 {
333 struct gl2_unknown_intf **unk;
334
335 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
336 unk = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, programObj);
337 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
338
339 if (unk == NULL)
340 {
341 _mesa_error (ctx, GL_INVALID_VALUE, "glUseProgramObjectARB");
342 return;
343 }
344
345 pro = (struct gl2_program_intf **) (**unk).QueryInterface (unk, UIID_PROGRAM);
346 if (pro == NULL)
347 {
348 _mesa_error (ctx, GL_INVALID_OPERATION, "glUseProgramObjectARB");
349 return;
350 }
351
352 if ((**pro).GetLinkStatus (pro) == GL_FALSE)
353 {
354 (**pro)._container._generic._unknown.Release ((struct gl2_unknown_intf **) pro);
355 _mesa_error (ctx, GL_INVALID_OPERATION, "glUseProgramObjectARB");
356 return;
357 }
358 }
359
360 if (ctx->ShaderObjects.current_program != NULL)
361 {
362 (**ctx->ShaderObjects.current_program)._container._generic._unknown.Release (
363 (struct gl2_unknown_intf **) ctx->ShaderObjects.current_program);
364 }
365
366 ctx->ShaderObjects.current_program = pro;
367 }
368
369 void GLAPIENTRY
370 _mesa_ValidateProgramARB (GLhandleARB programObj)
371 {
372 GET_CURRENT_CONTEXT(ctx);
373 struct gl2_unknown_intf **unk;
374 struct gl2_program_intf **pro;
375
376 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
377 unk = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, programObj);
378 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
379
380 if (unk == NULL)
381 {
382 _mesa_error (ctx, GL_INVALID_VALUE, "glValidateProgramARB");
383 return;
384 }
385
386 pro = (struct gl2_program_intf **) (**unk).QueryInterface (unk, UIID_PROGRAM);
387 if (pro == NULL)
388 {
389 _mesa_error (ctx, GL_INVALID_OPERATION, "glValidateProgramARB");
390 return;
391 }
392
393 (**pro).Validate (pro);
394 (**pro)._container._generic._unknown.Release ((struct gl2_unknown_intf **) pro);
395 }
396
397 /*
398 Errors TODO
399
400 The error INVALID_OPERATION is generated by the Uniform*ARB if the
401 number of values loaded results in exceeding the declared extent of a
402 uniform.
403
404 The error INVALID_OPERATION is generated by the Uniform*ARB commands if
405 the size does not match the size of the uniform declared in the shader.
406
407 The error INVALID_OPERATION is generated by the Uniform*ARB commands if
408 the type does not match the type of the uniform declared in the shader,
409 if the uniform is not of type Boolean.
410
411 The error INVALID_OPERATION is generated by the Uniform*ARB commands if
412 <location> does not exist for the program object currently in use.
413
414 The error INVALID_OPERATION is generated if a uniform command other than
415 Uniform1i{v}ARB is used to load a sampler value.
416
417
418 */
419
420 void GLAPIENTRY
421 _mesa_Uniform1fARB (GLint location, GLfloat v0)
422 {
423 GET_CURRENT_CONTEXT(ctx);
424
425 if (ctx->ShaderObjects.current_program == NULL)
426 {
427 _mesa_error (ctx, GL_INVALID_OPERATION, "glUniform1fARB");
428 return;
429 }
430 }
431
432 void GLAPIENTRY
433 _mesa_Uniform2fARB (GLint location, GLfloat v0, GLfloat v1)
434 {
435 GET_CURRENT_CONTEXT(ctx);
436
437 if (ctx->ShaderObjects.current_program == NULL)
438 {
439 _mesa_error (ctx, GL_INVALID_OPERATION, "glUniform2fARB");
440 return;
441 }
442 }
443
444 void GLAPIENTRY
445 _mesa_Uniform3fARB (GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
446 {
447 GET_CURRENT_CONTEXT(ctx);
448
449 if (ctx->ShaderObjects.current_program == NULL)
450 {
451 _mesa_error (ctx, GL_INVALID_OPERATION, "glUniform3fARB");
452 return;
453 }
454 }
455
456 void GLAPIENTRY
457 _mesa_Uniform4fARB (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3)
458 {
459 GET_CURRENT_CONTEXT(ctx);
460
461 if (ctx->ShaderObjects.current_program == NULL)
462 {
463 _mesa_error (ctx, GL_INVALID_OPERATION, "glUniform4fARB");
464 return;
465 }
466 }
467
468 void GLAPIENTRY
469 _mesa_Uniform1iARB (GLint location, GLint v0)
470 {
471 GET_CURRENT_CONTEXT(ctx);
472
473 if (ctx->ShaderObjects.current_program == NULL)
474 {
475 _mesa_error (ctx, GL_INVALID_OPERATION, "glUniform1iARB");
476 return;
477 }
478 }
479
480 void GLAPIENTRY
481 _mesa_Uniform2iARB (GLint location, GLint v0, GLint v1)
482 {
483 GET_CURRENT_CONTEXT(ctx);
484
485 if (ctx->ShaderObjects.current_program == NULL)
486 {
487 _mesa_error (ctx, GL_INVALID_OPERATION, "glUniform2iARB");
488 return;
489 }
490 }
491
492 void GLAPIENTRY
493 _mesa_Uniform3iARB (GLint location, GLint v0, GLint v1, GLint v2)
494 {
495 GET_CURRENT_CONTEXT(ctx);
496
497 if (ctx->ShaderObjects.current_program == NULL)
498 {
499 _mesa_error (ctx, GL_INVALID_OPERATION, "glUniform3iARB");
500 return;
501 }
502 }
503
504 void GLAPIENTRY
505 _mesa_Uniform4iARB (GLint location, GLint v0, GLint v1, GLint v2, GLint v3)
506 {
507 GET_CURRENT_CONTEXT(ctx);
508
509 if (ctx->ShaderObjects.current_program == NULL)
510 {
511 _mesa_error (ctx, GL_INVALID_OPERATION, "glUniform4iARB");
512 return;
513 }
514 }
515
516 void GLAPIENTRY
517 _mesa_Uniform1fvARB (GLint location, GLsizei count, const GLfloat *value)
518 {
519 GET_CURRENT_CONTEXT(ctx);
520
521 if (ctx->ShaderObjects.current_program == NULL)
522 {
523 _mesa_error (ctx, GL_INVALID_OPERATION, "glUniform1fvARB");
524 return;
525 }
526 }
527
528 void GLAPIENTRY
529 _mesa_Uniform2fvARB (GLint location, GLsizei count, const GLfloat *value)
530 {
531 GET_CURRENT_CONTEXT(ctx);
532
533 if (ctx->ShaderObjects.current_program == NULL)
534 {
535 _mesa_error (ctx, GL_INVALID_OPERATION, "glUniform2fvARB");
536 return;
537 }
538 }
539
540 void GLAPIENTRY
541 _mesa_Uniform3fvARB (GLint location, GLsizei count, const GLfloat *value)
542 {
543 GET_CURRENT_CONTEXT(ctx);
544
545 if (ctx->ShaderObjects.current_program == NULL)
546 {
547 _mesa_error (ctx, GL_INVALID_OPERATION, "glUniform3fvARB");
548 return;
549 }
550 }
551
552 void GLAPIENTRY
553 _mesa_Uniform4fvARB (GLint location, GLsizei count, const GLfloat *value)
554 {
555 GET_CURRENT_CONTEXT(ctx);
556
557 if (ctx->ShaderObjects.current_program == NULL)
558 {
559 _mesa_error (ctx, GL_INVALID_OPERATION, "glUniform4fvARB");
560 return;
561 }
562 }
563
564 void GLAPIENTRY
565 _mesa_Uniform1ivARB (GLint location, GLsizei count, const GLint *value)
566 {
567 GET_CURRENT_CONTEXT(ctx);
568
569 if (ctx->ShaderObjects.current_program == NULL)
570 {
571 _mesa_error (ctx, GL_INVALID_OPERATION, "glUniform1ivARB");
572 return;
573 }
574 }
575
576 void GLAPIENTRY
577 _mesa_Uniform2ivARB (GLint location, GLsizei count, const GLint *value)
578 {
579 GET_CURRENT_CONTEXT(ctx);
580
581 if (ctx->ShaderObjects.current_program == NULL)
582 {
583 _mesa_error (ctx, GL_INVALID_OPERATION, "glUniform2ivARB");
584 return;
585 }
586 }
587
588 void GLAPIENTRY
589 _mesa_Uniform3ivARB (GLint location, GLsizei count, const GLint *value)
590 {
591 GET_CURRENT_CONTEXT(ctx);
592
593 if (ctx->ShaderObjects.current_program == NULL)
594 {
595 _mesa_error (ctx, GL_INVALID_OPERATION, "glUniform3ivARB");
596 return;
597 }
598 }
599
600 void GLAPIENTRY
601 _mesa_Uniform4ivARB (GLint location, GLsizei count, const GLint *value)
602 {
603 GET_CURRENT_CONTEXT(ctx);
604
605 if (ctx->ShaderObjects.current_program == NULL)
606 {
607 _mesa_error (ctx, GL_INVALID_OPERATION, "glUniform4ivARB");
608 return;
609 }
610 }
611
612 void GLAPIENTRY
613 _mesa_UniformMatrix2fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
614 {
615 GET_CURRENT_CONTEXT(ctx);
616
617 if (ctx->ShaderObjects.current_program == NULL)
618 {
619 _mesa_error (ctx, GL_INVALID_OPERATION, "glUniformMatrix2fvARB");
620 return;
621 }
622 }
623
624 void GLAPIENTRY
625 _mesa_UniformMatrix3fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
626 {
627 GET_CURRENT_CONTEXT(ctx);
628
629 if (ctx->ShaderObjects.current_program == NULL)
630 {
631 _mesa_error (ctx, GL_INVALID_OPERATION, "glUniformMatrix3fvARB");
632 return;
633 }
634 }
635
636 void GLAPIENTRY
637 _mesa_UniformMatrix4fvARB (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
638 {
639 GET_CURRENT_CONTEXT(ctx);
640
641 if (ctx->ShaderObjects.current_program == NULL)
642 {
643 _mesa_error (ctx, GL_INVALID_OPERATION, "glUniformMatrix4fvARB");
644 return;
645 }
646 }
647
648 static GLboolean
649 _mesa_get_object_parameter (GLhandleARB obj, GLenum pname, GLvoid *params, GLboolean *integral,
650 GLint *size)
651 {
652 GET_CURRENT_CONTEXT(ctx);
653 struct gl2_unknown_intf **unk;
654 struct gl2_generic_intf **gen;
655 struct gl2_shader_intf **sha;
656 struct gl2_program_intf **pro;
657 GLint *ipar = (GLint *) params;
658 /*GLfloat *fpar = (GLfloat *) params;*/
659 GLboolean success = GL_TRUE;
660
661 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
662 unk = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, obj);
663 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
664
665 if (unk == NULL)
666 {
667 _mesa_error (ctx, GL_INVALID_VALUE, "glGetObjectParameterivARB");
668 return GL_FALSE;
669 }
670
671 gen = (struct gl2_generic_intf **) (**unk).QueryInterface (unk, UIID_GENERIC);
672 if (gen == NULL)
673 {
674 _mesa_error (ctx, GL_INVALID_OPERATION, "glGetObjectParameterivARB");
675 return GL_FALSE;
676 }
677
678 sha = (struct gl2_shader_intf **) (**unk).QueryInterface (unk, UIID_SHADER);
679 pro = (struct gl2_program_intf **) (**unk).QueryInterface (unk, UIID_PROGRAM);
680
681 /* set default values */
682 *integral = GL_TRUE; /* indicates param type, TRUE: GLint, FALSE: GLfloat */
683 *size = 1; /* param array size */
684
685 switch (pname)
686 {
687 case GL_OBJECT_TYPE_ARB:
688 *ipar = (**gen).GetType (gen);
689 break;
690 case GL_OBJECT_SUBTYPE_ARB:
691 if (sha != NULL)
692 *ipar = (**sha).GetSubType (sha);
693 else {
694 _mesa_error (ctx, GL_INVALID_OPERATION, "glGetObjectParameterivARB");
695 success = GL_FALSE;
696 }
697 break;
698 case GL_OBJECT_DELETE_STATUS_ARB:
699 *ipar = (**gen).GetDeleteStatus (gen);
700 break;
701 case GL_OBJECT_COMPILE_STATUS_ARB:
702 if (sha != NULL)
703 *ipar = (**sha).GetCompileStatus (sha);
704 else {
705 _mesa_error (ctx, GL_INVALID_OPERATION, "glGetObjectParameterivARB");
706 success = GL_FALSE;
707 }
708 break;
709 case GL_OBJECT_LINK_STATUS_ARB:
710 if (pro != NULL)
711 *ipar = (**pro).GetLinkStatus (pro);
712 else {
713 _mesa_error (ctx, GL_INVALID_OPERATION, "glGetObjectParameterivARB");
714 success = GL_FALSE;
715 }
716 break;
717 case GL_OBJECT_VALIDATE_STATUS_ARB:
718 if (pro != NULL)
719 *ipar = (**pro).GetValidateStatus (pro);
720 else {
721 _mesa_error (ctx, GL_INVALID_OPERATION, "glGetObjectParameterivARB");
722 success = GL_FALSE;
723 }
724 break;
725 case GL_OBJECT_INFO_LOG_LENGTH_ARB:
726 {
727 const GLcharARB *info = (**gen).GetInfoLog (gen);
728 if (info == NULL)
729 *ipar = 0;
730 else
731 *ipar = _mesa_strlen (info) + 1;
732 }
733 break;
734 case GL_OBJECT_ATTACHED_OBJECTS_ARB:
735 if (pro != NULL)
736 *ipar = (**pro)._container.GetAttachedCount ((struct gl2_container_intf **) pro);
737 else {
738 _mesa_error (ctx, GL_INVALID_OPERATION, "glGetObjectParameterivARB");
739 success = GL_FALSE;
740 }
741 break;
742 case GL_OBJECT_ACTIVE_UNIFORMS_ARB:
743 if (pro != NULL)
744 *ipar = 0; /* TODO */
745 else {
746 _mesa_error (ctx, GL_INVALID_OPERATION, "glGetObjectParameterivARB");
747 success = GL_FALSE;
748 }
749 break;
750 case GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB:
751 if (pro != NULL)
752 *ipar = 0; /* TODO */
753 else {
754 _mesa_error (ctx, GL_INVALID_OPERATION, "glGetObjectParameterivARB");
755 success = GL_FALSE;
756 }
757 break;
758 case GL_OBJECT_SHADER_SOURCE_LENGTH_ARB:
759 if (sha != NULL) {
760 const GLcharARB *src = (**sha).GetSource (sha);
761 if (src == NULL)
762 *ipar = 0;
763 else
764 *ipar = _mesa_strlen (src) + 1;
765 } else {
766 _mesa_error (ctx, GL_INVALID_OPERATION, "glGetObjectParameterivARB");
767 success = GL_FALSE;
768 }
769 break;
770 default:
771 _mesa_error (ctx, GL_INVALID_ENUM, "glGetObjectParameterivARB");
772 success = GL_FALSE;
773 break;
774 }
775
776 (**gen)._unknown.Release ((struct gl2_unknown_intf **) gen);
777 if (sha != NULL)
778 (**sha)._generic._unknown.Release ((struct gl2_unknown_intf **) sha);
779 if (pro != NULL)
780 (**pro)._container._generic._unknown.Release ((struct gl2_unknown_intf **) pro);
781
782 return success;
783 }
784
785 void GLAPIENTRY
786 _mesa_GetObjectParameterfvARB (GLhandleARB obj, GLenum pname, GLfloat *params)
787 {
788 GLboolean integral;
789 GLint size, i;
790
791 assert (sizeof (GLfloat) == sizeof (GLint));
792
793 if (_mesa_get_object_parameter (obj, pname, (GLvoid *) params, &integral, &size) != GL_FALSE)
794 if (integral != GL_FALSE)
795 for (i = 0; i < size; i++)
796 params[i] = (GLfloat) ((GLint *) params)[i];
797 }
798
799 void GLAPIENTRY
800 _mesa_GetObjectParameterivARB (GLhandleARB obj, GLenum pname, GLint *params)
801 {
802 GLboolean integral;
803 GLint size, i;
804
805 assert (sizeof (GLfloat) == sizeof (GLint));
806
807 if (_mesa_get_object_parameter (obj, pname, (GLvoid *) params, &integral, &size) != GL_FALSE)
808 if (integral == GL_FALSE)
809 for (i = 0; i < size; i++)
810 params[i] = (GLint) ((GLfloat *) params)[i];
811 }
812
813 static void
814 _mesa_get_string (const GLcharARB *src, GLsizei maxLength, GLsizei *length, GLcharARB *str)
815 {
816 GLsizei len;
817
818 if (src == NULL)
819 src = "";
820
821 len = _mesa_strlen (src);
822 if (len > maxLength)
823 {
824 len = maxLength;
825 /* allocate space for null termination */
826 if (len > 0)
827 len--;
828 }
829
830 _mesa_memcpy (str, src, len * sizeof (GLcharARB));
831 if (maxLength > 0)
832 str[len] = '\0';
833
834 if (length != NULL)
835 *length = len;
836 }
837
838 void GLAPIENTRY
839 _mesa_GetInfoLogARB (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *infoLog)
840 {
841 GET_CURRENT_CONTEXT(ctx);
842 struct gl2_unknown_intf **unk;
843 struct gl2_generic_intf **gen;
844
845 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
846 unk = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, obj);
847 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
848
849 if (unk == NULL)
850 {
851 _mesa_error (ctx, GL_INVALID_VALUE, "glGetInfoLogARB");
852 return;
853 }
854
855 gen = (struct gl2_generic_intf **) (**unk).QueryInterface (unk, UIID_GENERIC);
856 if (gen == NULL)
857 {
858 _mesa_error (ctx, GL_INVALID_OPERATION, "glGetInfoLogARB");
859 return;
860 }
861
862 _mesa_get_string ((**gen).GetInfoLog (gen), maxLength, length, infoLog);
863
864 (**gen)._unknown.Release ((struct gl2_unknown_intf **) gen);
865 }
866
867 void GLAPIENTRY
868 _mesa_GetAttachedObjectsARB (GLhandleARB containerObj, GLsizei maxCount, GLsizei *count, GLhandleARB *obj)
869 {
870 GET_CURRENT_CONTEXT(ctx);
871 struct gl2_unknown_intf **unk;
872 struct gl2_container_intf **con;
873 GLsizei cnt, i;
874
875 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
876 unk = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, containerObj);
877 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
878
879 if (unk == NULL)
880 {
881 _mesa_error (ctx, GL_INVALID_VALUE, "glGetAttachedObjectsARB");
882 return;
883 }
884
885 con = (struct gl2_container_intf **) (**unk).QueryInterface (unk, UIID_CONTAINER);
886 if (con == NULL)
887 {
888 _mesa_error (ctx, GL_INVALID_OPERATION, "glGetAttachedObjectsARB");
889 return;
890 }
891
892 cnt = (**con).GetAttachedCount (con);
893 if (cnt > maxCount)
894 cnt = maxCount;
895
896 for (i = 0; i < cnt; i++)
897 {
898 struct gl2_generic_intf **x = (**con).GetAttached (con, i);
899 obj[i] = (**x).GetName (x);
900 (**x)._unknown.Release ((struct gl2_unknown_intf **) x);
901 }
902
903 (**con)._generic._unknown.Release ((struct gl2_unknown_intf **) con);
904
905 if (count != NULL)
906 *count = cnt;
907 }
908
909 GLint GLAPIENTRY
910 _mesa_GetUniformLocationARB (GLhandleARB programObj, const GLcharARB *name)
911 {
912 GET_CURRENT_CONTEXT(ctx);
913 struct gl2_unknown_intf **unk;
914 struct gl2_program_intf **pro;
915 GLint loc = -1;
916
917 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
918 unk = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, programObj);
919 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
920
921 if (unk == NULL)
922 {
923 _mesa_error (ctx, GL_INVALID_VALUE, "glGetUniformLocationARB");
924 return -1;
925 }
926
927 pro = (struct gl2_program_intf **) (**unk).QueryInterface (unk, UIID_PROGRAM);
928 if (pro == NULL)
929 {
930 _mesa_error (ctx, GL_INVALID_OPERATION, "glGetUniformLocationARB");
931 return -1;
932 }
933
934 if ((**pro).GetLinkStatus (pro) == GL_FALSE)
935 {
936 _mesa_error (ctx, GL_INVALID_OPERATION, "glGetUniformLocationARB");
937 (**pro)._container._generic._unknown.Release ((struct gl2_unknown_intf **) pro);
938 return -1;
939 }
940
941 /* TODO */
942
943 (**pro)._container._generic._unknown.Release ((struct gl2_unknown_intf **) pro);
944 return loc;
945 }
946
947 void GLAPIENTRY
948 _mesa_GetActiveUniformARB (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name)
949 {
950 GET_CURRENT_CONTEXT(ctx);
951 struct gl2_unknown_intf **unk;
952 struct gl2_program_intf **pro;
953
954 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
955 unk = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, programObj);
956 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
957
958 if (unk == NULL)
959 {
960 _mesa_error (ctx, GL_INVALID_VALUE, "glGetActiveUniformARB");
961 return;
962 }
963
964 pro = (struct gl2_program_intf **) (**unk).QueryInterface (unk, UIID_PROGRAM);
965 if (pro == NULL)
966 {
967 _mesa_error (ctx, GL_INVALID_OPERATION, "glGetActiveUniformARB");
968 return;
969 }
970
971 /* if (index >= val (OBJECT_ACTIVE_ATTRIBUTES_ARB))
972 {
973 _mesa_error (ctx, GL_INVALID_VALUE, "glGetActiveUniformARB");
974 (**pro)._container._generic._unknown.Release ((struct gl2_unknown_intf **) pro);
975 return;
976 }*/
977
978 /* TODO */
979
980 (**pro)._container._generic._unknown.Release ((struct gl2_unknown_intf **) pro);
981 }
982
983 void GLAPIENTRY
984 _mesa_GetUniformfvARB (GLhandleARB programObj, GLint location, GLfloat *params)
985 {
986 GET_CURRENT_CONTEXT(ctx);
987 struct gl2_unknown_intf **unk;
988 struct gl2_program_intf **pro;
989
990 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
991 unk = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, programObj);
992 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
993
994 if (unk == NULL)
995 {
996 _mesa_error (ctx, GL_INVALID_VALUE, "glGetUniformfvARB");
997 return;
998 }
999
1000 pro = (struct gl2_program_intf **) (**unk).QueryInterface (unk, UIID_PROGRAM);
1001 if (pro == NULL)
1002 {
1003 _mesa_error (ctx, GL_INVALID_OPERATION, "glGetUniformfvARB");
1004 return;
1005 }
1006
1007 if ((**pro).GetLinkStatus (pro) == GL_FALSE)
1008 {
1009 _mesa_error (ctx, GL_INVALID_OPERATION, "glGetUniformfvARB");
1010 (**pro)._container._generic._unknown.Release ((struct gl2_unknown_intf **) pro);
1011 return;
1012 }
1013
1014 /* TODO validate location (OPERATION) */
1015
1016 /* TODO */
1017
1018 (**pro)._container._generic._unknown.Release ((struct gl2_unknown_intf **) pro);
1019 }
1020
1021 void GLAPIENTRY
1022 _mesa_GetUniformivARB (GLhandleARB programObj, GLint location, GLint *params)
1023 {
1024 GET_CURRENT_CONTEXT(ctx);
1025 struct gl2_unknown_intf **unk;
1026 struct gl2_program_intf **pro;
1027
1028 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
1029 unk = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, programObj);
1030 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
1031
1032 if (unk == NULL)
1033 {
1034 _mesa_error (ctx, GL_INVALID_VALUE, "glGetUniformivARB");
1035 return;
1036 }
1037
1038 pro = (struct gl2_program_intf **) (**unk).QueryInterface (unk, UIID_PROGRAM);
1039 if (pro == NULL)
1040 {
1041 _mesa_error (ctx, GL_INVALID_OPERATION, "glGetUniformivARB");
1042 return;
1043 }
1044
1045 if ((**pro).GetLinkStatus (pro) == GL_FALSE)
1046 {
1047 _mesa_error (ctx, GL_INVALID_OPERATION, "glGetUniformivARB");
1048 (**pro)._container._generic._unknown.Release ((struct gl2_unknown_intf **) pro);
1049 return;
1050 }
1051
1052 /* TODO validate location (GL_INVALID_OPERATION) */
1053
1054 /* TODO */
1055
1056 (**pro)._container._generic._unknown.Release ((struct gl2_unknown_intf **) pro);
1057 }
1058
1059 void GLAPIENTRY
1060 _mesa_GetShaderSourceARB (GLhandleARB obj, GLsizei maxLength, GLsizei *length, GLcharARB *source)
1061 {
1062 GET_CURRENT_CONTEXT(ctx);
1063 struct gl2_unknown_intf **unk;
1064 struct gl2_shader_intf **sha;
1065
1066 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
1067 unk = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, obj);
1068 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
1069
1070 if (unk == NULL)
1071 {
1072 _mesa_error (ctx, GL_INVALID_VALUE, "glGetShaderSourceARB");
1073 return;
1074 }
1075
1076 sha = (struct gl2_shader_intf **) (**unk).QueryInterface (unk, UIID_SHADER);
1077 if (sha == NULL)
1078 {
1079 _mesa_error (ctx, GL_INVALID_OPERATION, "glGetShaderSourceARB");
1080 return;
1081 }
1082
1083 _mesa_get_string ((**sha).GetSource (sha), maxLength, length, source);
1084
1085 (**sha)._generic._unknown.Release ((struct gl2_unknown_intf **) sha);
1086 }
1087
1088 /* GL_ARB_vertex_shader */
1089
1090 void GLAPIENTRY
1091 _mesa_BindAttribLocationARB (GLhandleARB programObj, GLuint index, const GLcharARB *name)
1092 {
1093 GET_CURRENT_CONTEXT(ctx);
1094 struct gl2_unknown_intf **unk;
1095 struct gl2_program_intf **pro;
1096
1097 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
1098 unk = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, programObj);
1099 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
1100
1101 if (unk == NULL)
1102 {
1103 _mesa_error (ctx, GL_INVALID_VALUE, "glBindAttribLocationARB");
1104 return;
1105 }
1106
1107 pro = (struct gl2_program_intf **) (**unk).QueryInterface (unk, UIID_PROGRAM);
1108 if (pro == NULL)
1109 {
1110 _mesa_error (ctx, GL_INVALID_VALUE, "glBindAttribLocationARB");
1111 return;
1112 }
1113
1114 /* TODO */
1115
1116 (**pro)._container._generic._unknown.Release ((struct gl2_unknown_intf **) pro);
1117 }
1118
1119 void GLAPIENTRY
1120 _mesa_GetActiveAttribARB (GLhandleARB programObj, GLuint index, GLsizei maxLength, GLsizei *length, GLint *size, GLenum *type, GLcharARB *name)
1121 {
1122 GET_CURRENT_CONTEXT(ctx);
1123 struct gl2_unknown_intf **unk;
1124 struct gl2_program_intf **pro;
1125
1126 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
1127 unk = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, programObj);
1128 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
1129
1130 if (unk == NULL)
1131 {
1132 _mesa_error (ctx, GL_INVALID_VALUE, "glGetActiveAttribARB");
1133 return;
1134 }
1135
1136 pro = (struct gl2_program_intf **) (**unk).QueryInterface (unk, UIID_PROGRAM);
1137 if (pro == NULL)
1138 {
1139 _mesa_error (ctx, GL_INVALID_VALUE, "glGetActiveAttribARB");
1140 return;
1141 }
1142
1143 /* TODO */
1144
1145 (**pro)._container._generic._unknown.Release ((struct gl2_unknown_intf **) pro);
1146 }
1147
1148 GLint GLAPIENTRY
1149 _mesa_GetAttribLocationARB (GLhandleARB programObj, const GLcharARB *name)
1150 {
1151 GET_CURRENT_CONTEXT(ctx);
1152 struct gl2_unknown_intf **unk;
1153 struct gl2_program_intf **pro;
1154 GLint loc = 0;
1155
1156 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
1157 unk = (struct gl2_unknown_intf **) _mesa_HashLookup (ctx->Shared->GL2Objects, programObj);
1158 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
1159
1160 if (unk == NULL)
1161 {
1162 _mesa_error (ctx, GL_INVALID_VALUE, "glGetAttribLocationARB");
1163 return 0;
1164 }
1165
1166 pro = (struct gl2_program_intf **) (**unk).QueryInterface (unk, UIID_PROGRAM);
1167 if (pro == NULL)
1168 {
1169 _mesa_error (ctx, GL_INVALID_VALUE, "glGetAttribLocationARB");
1170 return 0;
1171 }
1172
1173 /* TODO */
1174
1175 (**pro)._container._generic._unknown.Release ((struct gl2_unknown_intf **) pro);
1176 return loc;
1177 }
1178
1179 void
1180 _mesa_init_shaderobjects (GLcontext *ctx)
1181 {
1182 ctx->ShaderObjects.current_program = NULL;
1183
1184 #if 0 /* disable for now */
1185 _mesa_init_shaderobjects_3dlabs (ctx);
1186 #endif
1187 }
1188