Fix Windows newlines.
[mesa.git] / src / mesa / shader / shaderobjects_3dlabs.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 2005-2006 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_3dlabs.c
27 * shader objects definitions for 3dlabs compiler
28 * \author Michal Krol
29 */
30
31 /* Set this to 1 when we are ready to use 3dlabs' front-end */
32 #define USE_3DLABS_FRONTEND 0
33
34 #include "imports.h"
35 #include "hash.h"
36 #include "macros.h"
37 #include "shaderobjects.h"
38 #include "shaderobjects_3dlabs.h"
39
40 #if USE_3DLABS_FRONTEND
41 #include "slang_mesa.h"
42 #include "Public/ShaderLang.h"
43 #else
44 #include "slang_link.h"
45 #endif
46
47 #if FEATURE_ARB_shader_objects
48
49 struct gl2_unknown_obj
50 {
51 GLuint reference_count;
52 void (* _destructor) (struct gl2_unknown_intf **);
53 };
54
55 struct gl2_unknown_impl
56 {
57 struct gl2_unknown_intf *_vftbl;
58 struct gl2_unknown_obj _obj;
59 };
60
61 static void
62 _unknown_destructor (struct gl2_unknown_intf **intf)
63 {
64 }
65
66 static void
67 _unknown_AddRef (struct gl2_unknown_intf **intf)
68 {
69 struct gl2_unknown_impl *impl = (struct gl2_unknown_impl *) intf;
70
71 impl->_obj.reference_count++;
72 }
73
74 static void
75 _unknown_Release (struct gl2_unknown_intf **intf)
76 {
77 struct gl2_unknown_impl *impl = (struct gl2_unknown_impl *) intf;
78
79 impl->_obj.reference_count--;
80 if (impl->_obj.reference_count == 0)
81 {
82 impl->_obj._destructor (intf);
83 _mesa_free ((void *) intf);
84 }
85 }
86
87 static struct gl2_unknown_intf **
88 _unknown_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
89 {
90 if (uiid == UIID_UNKNOWN)
91 {
92 (**intf).AddRef (intf);
93 return intf;
94 }
95 return NULL;
96 }
97
98 static struct gl2_unknown_intf _unknown_vftbl = {
99 _unknown_AddRef,
100 _unknown_Release,
101 _unknown_QueryInterface
102 };
103
104 static void
105 _unknown_constructor (struct gl2_unknown_impl *impl)
106 {
107 impl->_vftbl = &_unknown_vftbl;
108 impl->_obj.reference_count = 1;
109 impl->_obj._destructor = _unknown_destructor;
110 }
111
112 struct gl2_unkinner_obj
113 {
114 struct gl2_unknown_intf **unkouter;
115 };
116
117 struct gl2_unkinner_impl
118 {
119 struct gl2_unknown_intf *_vftbl;
120 struct gl2_unkinner_obj _obj;
121 };
122
123 static void
124 _unkinner_destructor (struct gl2_unknown_intf **intf)
125 {
126 }
127
128 static void
129 _unkinner_AddRef (struct gl2_unknown_intf **intf)
130 {
131 struct gl2_unkinner_impl *impl = (struct gl2_unkinner_impl *) intf;
132
133 (**impl->_obj.unkouter).AddRef (impl->_obj.unkouter);
134 }
135
136 static void
137 _unkinner_Release (struct gl2_unknown_intf **intf)
138 {
139 struct gl2_unkinner_impl *impl = (struct gl2_unkinner_impl *) intf;
140
141 (**impl->_obj.unkouter).Release (impl->_obj.unkouter);
142 }
143
144 static struct gl2_unknown_intf **
145 _unkinner_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
146 {
147 struct gl2_unkinner_impl *impl = (struct gl2_unkinner_impl *) intf;
148
149 return (**impl->_obj.unkouter).QueryInterface (impl->_obj.unkouter, uiid);
150 }
151
152 static struct gl2_unknown_intf _unkinner_vftbl = {
153 _unkinner_AddRef,
154 _unkinner_Release,
155 _unkinner_QueryInterface
156 };
157
158 static void
159 _unkinner_constructor (struct gl2_unkinner_impl *impl, struct gl2_unknown_intf **outer)
160 {
161 impl->_vftbl = &_unkinner_vftbl;
162 impl->_obj.unkouter = outer;
163 }
164
165 struct gl2_generic_obj
166 {
167 struct gl2_unknown_obj _unknown;
168 GLhandleARB name;
169 GLboolean delete_status;
170 GLcharARB *info_log;
171 };
172
173 struct gl2_generic_impl
174 {
175 struct gl2_generic_intf *_vftbl;
176 struct gl2_generic_obj _obj;
177 };
178
179 static void
180 _generic_destructor (struct gl2_unknown_intf **intf)
181 {
182 GET_CURRENT_CONTEXT(ctx);
183 struct gl2_generic_impl *impl = (struct gl2_generic_impl *) intf;
184
185 _mesa_free ((void *) impl->_obj.info_log);
186
187 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
188 _mesa_HashRemove (ctx->Shared->GL2Objects, impl->_obj.name);
189 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
190
191 _unknown_destructor (intf);
192 }
193
194 static struct gl2_unknown_intf **
195 _generic_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
196 {
197 if (uiid == UIID_GENERIC)
198 {
199 (**intf).AddRef (intf);
200 return intf;
201 }
202 return _unknown_QueryInterface (intf, uiid);
203 }
204
205 static void
206 _generic_Delete (struct gl2_generic_intf **intf)
207 {
208 struct gl2_generic_impl *impl = (struct gl2_generic_impl *) intf;
209
210 if (impl->_obj.delete_status == GL_FALSE)
211 {
212 impl->_obj.delete_status = GL_TRUE;
213 (**intf)._unknown.Release ((struct gl2_unknown_intf **) intf);
214 }
215 }
216
217 static GLhandleARB
218 _generic_GetName (struct gl2_generic_intf **intf)
219 {
220 struct gl2_generic_impl *impl = (struct gl2_generic_impl *) intf;
221
222 return impl->_obj.name;
223 }
224
225 static GLboolean
226 _generic_GetDeleteStatus (struct gl2_generic_intf **intf)
227 {
228 struct gl2_generic_impl *impl = (struct gl2_generic_impl *) intf;
229
230 return impl->_obj.delete_status;
231 }
232
233 static GLvoid
234 _generic_GetInfoLog (struct gl2_generic_intf **intf, GLsizei maxlen, GLcharARB *infolog)
235 {
236 struct gl2_generic_impl *impl = (struct gl2_generic_impl *) (intf);
237
238 if (maxlen > 0) {
239 _mesa_strncpy (infolog, impl->_obj.info_log, maxlen - 1);
240 infolog[maxlen - 1] = '\0';
241 }
242 }
243
244 static GLsizei
245 _generic_GetInfoLogLength (struct gl2_generic_intf **intf)
246 {
247 struct gl2_generic_impl *impl = (struct gl2_generic_impl *) (intf);
248
249 if (impl->_obj.info_log == NULL)
250 return 1;
251 return _mesa_strlen (impl->_obj.info_log) + 1;
252 }
253
254 static struct gl2_generic_intf _generic_vftbl = {
255 {
256 _unknown_AddRef,
257 _unknown_Release,
258 _generic_QueryInterface
259 },
260 _generic_Delete,
261 NULL, /* abstract GetType */
262 _generic_GetName,
263 _generic_GetDeleteStatus,
264 _generic_GetInfoLog,
265 _generic_GetInfoLogLength
266 };
267
268 static void
269 _generic_constructor (struct gl2_generic_impl *impl)
270 {
271 GET_CURRENT_CONTEXT(ctx);
272
273 _unknown_constructor ((struct gl2_unknown_impl *) impl);
274 impl->_vftbl = &_generic_vftbl;
275 impl->_obj._unknown._destructor = _generic_destructor;
276 impl->_obj.delete_status = GL_FALSE;
277 impl->_obj.info_log = NULL;
278
279 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);
280 impl->_obj.name = _mesa_HashFindFreeKeyBlock (ctx->Shared->GL2Objects, 1);
281 _mesa_HashInsert (ctx->Shared->GL2Objects, impl->_obj.name, (void *) impl);
282 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);
283 }
284
285 struct gl2_container_obj
286 {
287 struct gl2_generic_obj _generic;
288 struct gl2_generic_intf ***attached;
289 GLuint attached_count;
290 };
291
292 struct gl2_container_impl
293 {
294 struct gl2_container_intf *_vftbl;
295 struct gl2_container_obj _obj;
296 };
297
298 static void
299 _container_destructor (struct gl2_unknown_intf **intf)
300 {
301 struct gl2_container_impl *impl = (struct gl2_container_impl *) intf;
302 GLuint i;
303
304 for (i = 0; i < impl->_obj.attached_count; i++)
305 {
306 struct gl2_generic_intf **x = impl->_obj.attached[i];
307 (**x)._unknown.Release ((struct gl2_unknown_intf **) x);
308 }
309
310 _generic_destructor (intf);
311 }
312
313 static struct gl2_unknown_intf **
314 _container_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
315 {
316 if (uiid == UIID_CONTAINER)
317 {
318 (**intf).AddRef (intf);
319 return intf;
320 }
321 return _generic_QueryInterface (intf, uiid);
322 }
323
324 static GLboolean
325 _container_Attach (struct gl2_container_intf **intf, struct gl2_generic_intf **att)
326 {
327 GET_CURRENT_CONTEXT(ctx);
328 struct gl2_container_impl *impl = (struct gl2_container_impl *) intf;
329 GLuint i;
330
331 for (i = 0; i < impl->_obj.attached_count; i++)
332 if (impl->_obj.attached[i] == att)
333 {
334 _mesa_error (ctx, GL_INVALID_OPERATION, "_container_Attach");
335 return GL_FALSE;
336 }
337
338 impl->_obj.attached = (struct gl2_generic_intf ***) _mesa_realloc (impl->_obj.attached,
339 impl->_obj.attached_count * sizeof (*impl->_obj.attached), (impl->_obj.attached_count + 1) *
340 sizeof (*impl->_obj.attached));
341 if (impl->_obj.attached == NULL)
342 return GL_FALSE;
343
344 impl->_obj.attached[impl->_obj.attached_count] = att;
345 impl->_obj.attached_count++;
346 (**att)._unknown.AddRef ((struct gl2_unknown_intf **) att);
347 return GL_TRUE;
348 }
349
350 static GLboolean
351 _container_Detach (struct gl2_container_intf **intf, struct gl2_generic_intf **att)
352 {
353 GET_CURRENT_CONTEXT(ctx);
354 struct gl2_container_impl *impl = (struct gl2_container_impl *) intf;
355 GLuint i, j;
356
357 for (i = 0; i < impl->_obj.attached_count; i++)
358 if (impl->_obj.attached[i] == att)
359 {
360 for (j = i; j < impl->_obj.attached_count - 1; j++)
361 impl->_obj.attached[j] = impl->_obj.attached[j + 1];
362 impl->_obj.attached = (struct gl2_generic_intf ***) _mesa_realloc (impl->_obj.attached,
363 impl->_obj.attached_count * sizeof (*impl->_obj.attached),
364 (impl->_obj.attached_count - 1) * sizeof (*impl->_obj.attached));
365 impl->_obj.attached_count--;
366 (**att)._unknown.Release ((struct gl2_unknown_intf **) att);
367 return GL_TRUE;
368 }
369
370 _mesa_error (ctx, GL_INVALID_OPERATION, "_container_Detach");
371 return GL_FALSE;
372 }
373
374 static GLsizei
375 _container_GetAttachedCount (struct gl2_container_intf **intf)
376 {
377 struct gl2_container_impl *impl = (struct gl2_container_impl *) intf;
378
379 return impl->_obj.attached_count;
380 }
381
382 static struct gl2_generic_intf **
383 _container_GetAttached (struct gl2_container_intf **intf, GLuint index)
384 {
385 struct gl2_container_impl *impl = (struct gl2_container_impl *) intf;
386
387 (**impl->_obj.attached[index])._unknown.AddRef (
388 (struct gl2_unknown_intf **)impl->_obj.attached[index]);
389 return impl->_obj.attached[index];
390 }
391
392 static struct gl2_container_intf _container_vftbl = {
393 {
394 {
395 _unknown_AddRef,
396 _unknown_Release,
397 _container_QueryInterface
398 },
399 _generic_Delete,
400 NULL, /* abstract GetType */
401 _generic_GetName,
402 _generic_GetDeleteStatus,
403 _generic_GetInfoLog,
404 _generic_GetInfoLogLength
405 },
406 _container_Attach,
407 _container_Detach,
408 _container_GetAttachedCount,
409 _container_GetAttached
410 };
411
412 static void
413 _container_constructor (struct gl2_container_impl *impl)
414 {
415 _generic_constructor ((struct gl2_generic_impl *) impl);
416 impl->_vftbl = &_container_vftbl;
417 impl->_obj._generic._unknown._destructor = _container_destructor;
418 impl->_obj.attached = NULL;
419 impl->_obj.attached_count = 0;
420 }
421
422 struct gl2_3dlabs_shhandle_obj
423 {
424 struct gl2_unkinner_obj _unknown;
425 #if USE_3DLABS_FRONTEND
426 ShHandle handle;
427 #endif
428 };
429
430 struct gl2_3dlabs_shhandle_impl
431 {
432 struct gl2_3dlabs_shhandle_intf *_vftbl;
433 struct gl2_3dlabs_shhandle_obj _obj;
434 };
435
436 static void
437 _3dlabs_shhandle_destructor (struct gl2_unknown_intf **intf)
438 {
439 #if USE_3DLABS_FRONTEND
440 struct gl2_3dlabs_shhandle_impl *impl = (struct gl2_3dlabs_shhandle_impl *) intf;
441 ShDestruct (impl->_obj.handle);
442 #endif
443 _unkinner_destructor (intf);
444 }
445
446 static GLvoid *
447 _3dlabs_shhandle_GetShHandle (struct gl2_3dlabs_shhandle_intf **intf)
448 {
449 #if USE_3DLABS_FRONTEND
450 struct gl2_3dlabs_shhandle_impl *impl = (struct gl2_3dlabs_shhandle_impl *) intf;
451 return impl->_obj.handle;
452 #else
453 return NULL;
454 #endif
455 }
456
457 static struct gl2_3dlabs_shhandle_intf _3dlabs_shhandle_vftbl = {
458 {
459 _unkinner_AddRef,
460 _unkinner_Release,
461 _unkinner_QueryInterface
462 },
463 _3dlabs_shhandle_GetShHandle
464 };
465
466 static void
467 _3dlabs_shhandle_constructor (struct gl2_3dlabs_shhandle_impl *impl, struct gl2_unknown_intf **outer)
468 {
469 _unkinner_constructor ((struct gl2_unkinner_impl *) impl, outer);
470 impl->_vftbl = &_3dlabs_shhandle_vftbl;
471 #if USE_3DLABS_FRONTEND
472 impl->_obj.handle = NULL;
473 #endif
474 }
475
476 struct gl2_shader_obj
477 {
478 struct gl2_generic_obj _generic;
479 struct gl2_3dlabs_shhandle_impl _3dlabs_shhandle;
480 GLboolean compile_status;
481 GLcharARB *source;
482 GLint *offsets;
483 GLsizei offset_count;
484 slang_code_object code;
485 };
486
487 struct gl2_shader_impl
488 {
489 struct gl2_shader_intf *_vftbl;
490 struct gl2_shader_obj _obj;
491 };
492
493 static void
494 _shader_destructor (struct gl2_unknown_intf **intf)
495 {
496 struct gl2_shader_impl *impl = (struct gl2_shader_impl *) intf;
497
498 _mesa_free ((void *) impl->_obj.source);
499 _mesa_free ((void *) impl->_obj.offsets);
500 _slang_code_object_dtr (&impl->_obj.code);
501 _3dlabs_shhandle_destructor ((struct gl2_unknown_intf **) &impl->_obj._3dlabs_shhandle._vftbl);
502 _generic_destructor (intf);
503 }
504
505 static struct gl2_unknown_intf **
506 _shader_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
507 {
508 #if USE_3DLABS_FRONTEND
509 struct gl2_shader_impl *impl = (struct gl2_shader_impl *) intf;
510 #endif
511
512 if (uiid == UIID_SHADER)
513 {
514 (**intf).AddRef (intf);
515 return intf;
516 }
517 #if USE_3DLABS_FRONTEND
518 if (uiid == UIID_3DLABS_SHHANDLE)
519 {
520 (**intf).AddRef (intf);
521 return (struct gl2_unknown_intf **) &impl->_obj._3dlabs_shhandle._vftbl;
522 }
523 #endif
524 return _generic_QueryInterface (intf, uiid);
525 }
526
527 static GLenum
528 _shader_GetType (struct gl2_generic_intf **intf)
529 {
530 return GL_SHADER_OBJECT_ARB;
531 }
532
533 static GLvoid
534 _shader_GetInfoLog (struct gl2_generic_intf **intf, GLsizei maxlen, GLcharARB *infolog)
535 {
536 struct gl2_shader_impl *impl = (struct gl2_shader_impl *) (intf);
537
538 if (maxlen > 0) {
539 if (impl->_obj._generic.info_log != NULL) {
540 GLsizei len = _mesa_strlen (impl->_obj._generic.info_log);
541 if (len > maxlen - 1)
542 len = maxlen - 1;
543 _mesa_memcpy (infolog, impl->_obj._generic.info_log, len);
544 infolog += len;
545 maxlen -= len;
546 }
547 if (impl->_obj.code.machine.infolog != NULL &&
548 impl->_obj.code.machine.infolog->text != NULL) {
549 GLsizei len = _mesa_strlen (impl->_obj.code.machine.infolog->text);
550 if (len > maxlen - 1)
551 len = maxlen - 1;
552 _mesa_memcpy (infolog, impl->_obj.code.machine.infolog->text, len);
553 }
554 infolog[maxlen - 1] = '\0';
555 }
556 }
557
558 static GLsizei
559 _shader_GetInfoLogLength (struct gl2_generic_intf **intf)
560 {
561 struct gl2_shader_impl *impl = (struct gl2_shader_impl *) (intf);
562 GLsizei length = 1;
563
564 if (impl->_obj._generic.info_log != NULL)
565 length += _mesa_strlen (impl->_obj._generic.info_log);
566 if (impl->_obj.code.machine.infolog != NULL &&
567 impl->_obj.code.machine.infolog->text != NULL)
568 length += _mesa_strlen (impl->_obj.code.machine.infolog->text);
569 return length;
570 }
571
572 static GLboolean
573 _shader_GetCompileStatus (struct gl2_shader_intf **intf)
574 {
575 struct gl2_shader_impl *impl = (struct gl2_shader_impl *) intf;
576
577 return impl->_obj.compile_status;
578 }
579
580 static GLvoid
581 _shader_SetSource (struct gl2_shader_intf **intf, GLcharARB *src, GLint *off, GLsizei cnt)
582 {
583 struct gl2_shader_impl *impl = (struct gl2_shader_impl *) intf;
584
585 _mesa_free ((void *) impl->_obj.source);
586 impl->_obj.source = src;
587 _mesa_free ((void *) impl->_obj.offsets);
588 impl->_obj.offsets = off;
589 impl->_obj.offset_count = cnt;
590 }
591
592 static const GLcharARB *
593 _shader_GetSource (struct gl2_shader_intf **intf)
594 {
595 struct gl2_shader_impl *impl = (struct gl2_shader_impl *) intf;
596
597 return impl->_obj.source;
598 }
599
600 static GLvoid
601 _shader_Compile (struct gl2_shader_intf **intf)
602 {
603 struct gl2_shader_impl *impl = (struct gl2_shader_impl *) intf;
604 #if USE_3DLABS_FRONTEND
605 char **strings;
606 TBuiltInResource res;
607 #else
608 slang_unit_type type;
609 slang_info_log info_log;
610 #endif
611
612 impl->_obj.compile_status = GL_FALSE;
613 _mesa_free ((void *) impl->_obj._generic.info_log);
614 impl->_obj._generic.info_log = NULL;
615
616 #if USE_3DLABS_FRONTEND
617 /* 3dlabs compiler expects us to feed it with null-terminated string array,
618 we've got only one big string with offsets, so we must split it; but when
619 there's only one string to deal with, we pass its address directly */
620
621 if (impl->_obj.offset_count <= 1)
622 strings = &impl->_obj.source;
623 else
624 {
625 GLsizei i, offset = 0;
626
627 strings = (char **) _mesa_malloc (impl->_obj.offset_count * sizeof (char *));
628 if (strings == NULL)
629 return;
630
631 for (i = 0; i < impl->_obj.offset_count; i++)
632 {
633 GLsizei size = impl->_obj.offsets[i] - offset;
634
635 strings[i] = (char *) _mesa_malloc ((size + 1) * sizeof (char));
636 if (strings[i] == NULL)
637 {
638 GLsizei j;
639
640 for (j = 0; j < i; j++)
641 _mesa_free (strings[j]);
642 _mesa_free (strings);
643 return;
644 }
645
646 _mesa_memcpy (strings[i], impl->_obj.source + offset, size * sizeof (char));
647 strings[i][size] = '\0';
648 offset = impl->_obj.offsets[i];
649 }
650 }
651
652 /* TODO set these fields to some REAL numbers */
653 res.maxLights = 8;
654 res.maxClipPlanes = 6;
655 res.maxTextureUnits = 2;
656 res.maxTextureCoords = 2;
657 res.maxVertexAttribs = 8;
658 res.maxVertexUniformComponents = 64;
659 res.maxVaryingFloats = 8;
660 res.maxVertexTextureImageUnits = 2;
661 res.maxCombinedTextureImageUnits = 2;
662 res.maxTextureImageUnits = 2;
663 res.maxFragmentUniformComponents = 64;
664 res.maxDrawBuffers = 1;
665
666 if (ShCompile (impl->_obj._3dlabs_shhandle._obj.handle, strings, impl->_obj.offset_count,
667 EShOptFull, &res, 0))
668 impl->_obj.compile_status = GL_TRUE;
669 if (impl->_obj.offset_count > 1)
670 {
671 GLsizei i;
672
673 for (i = 0; i < impl->_obj.offset_count; i++)
674 _mesa_free (strings[i]);
675 _mesa_free (strings);
676 }
677
678 impl->_obj._generic.info_log = _mesa_strdup (ShGetInfoLog (
679 impl->_obj._3dlabs_shhandle._obj.handle));
680 #else
681 if (impl->_vftbl->GetSubType (intf) == GL_FRAGMENT_SHADER)
682 type = slang_unit_fragment_shader;
683 else
684 type = slang_unit_vertex_shader;
685 slang_info_log_construct (&info_log);
686 if (_slang_compile (impl->_obj.source, &impl->_obj.code, type, &info_log))
687 impl->_obj.compile_status = GL_TRUE;
688 if (info_log.text != NULL)
689 impl->_obj._generic.info_log = _mesa_strdup (info_log.text);
690 else if (impl->_obj.compile_status)
691 impl->_obj._generic.info_log = _mesa_strdup ("Compile OK.\n");
692 else
693 impl->_obj._generic.info_log = _mesa_strdup ("Compile failed.\n");
694 slang_info_log_destruct (&info_log);
695 #endif
696 }
697
698 static struct gl2_shader_intf _shader_vftbl = {
699 {
700 {
701 _unknown_AddRef,
702 _unknown_Release,
703 _shader_QueryInterface
704 },
705 _generic_Delete,
706 _shader_GetType,
707 _generic_GetName,
708 _generic_GetDeleteStatus,
709 _shader_GetInfoLog,
710 _shader_GetInfoLogLength
711 },
712 NULL, /* abstract GetSubType */
713 _shader_GetCompileStatus,
714 _shader_SetSource,
715 _shader_GetSource,
716 _shader_Compile
717 };
718
719 static void
720 _shader_constructor (struct gl2_shader_impl *impl)
721 {
722 _generic_constructor ((struct gl2_generic_impl *) impl);
723 _3dlabs_shhandle_constructor (&impl->_obj._3dlabs_shhandle, (struct gl2_unknown_intf **)
724 &impl->_vftbl);
725 impl->_vftbl = &_shader_vftbl;
726 impl->_obj._generic._unknown._destructor = _shader_destructor;
727 impl->_obj.compile_status = GL_FALSE;
728 impl->_obj.source = NULL;
729 impl->_obj.offsets = NULL;
730 impl->_obj.offset_count = 0;
731 _slang_code_object_ctr (&impl->_obj.code);
732 }
733
734 struct gl2_program_obj
735 {
736 struct gl2_container_obj _container;
737 GLboolean link_status;
738 GLboolean validate_status;
739 #if USE_3DLABS_FRONTEND
740 ShHandle linker;
741 ShHandle uniforms;
742 #endif
743 slang_program prog;
744 };
745
746 struct gl2_program_impl
747 {
748 struct gl2_program_intf *_vftbl;
749 struct gl2_program_obj _obj;
750 };
751
752 static void
753 _program_destructor (struct gl2_unknown_intf **intf)
754 {
755 struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;
756 #if USE_3DLABS_FRONTEND
757 ShDestruct (impl->_obj.linker);
758 ShDestruct (impl->_obj.uniforms);
759 #endif
760 _container_destructor (intf);
761 slang_program_dtr (&impl->_obj.prog);
762 }
763
764 static struct gl2_unknown_intf **
765 _program_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
766 {
767 if (uiid == UIID_PROGRAM)
768 {
769 (**intf).AddRef (intf);
770 return intf;
771 }
772 return _container_QueryInterface (intf, uiid);
773 }
774
775 static GLenum
776 _program_GetType (struct gl2_generic_intf **intf)
777 {
778 return GL_PROGRAM_OBJECT_ARB;
779 }
780
781 static GLboolean
782 _program_Attach (struct gl2_container_intf **intf, struct gl2_generic_intf **att)
783 {
784 GET_CURRENT_CONTEXT(ctx);
785 struct gl2_unknown_intf **sha;
786
787 sha = (**att)._unknown.QueryInterface ((struct gl2_unknown_intf **) att, UIID_SHADER);
788 if (sha == NULL)
789 {
790 _mesa_error (ctx, GL_INVALID_OPERATION, "_program_Attach");
791 return GL_FALSE;
792 }
793
794 (**sha).Release (sha);
795 return _container_Attach (intf, att);
796 }
797
798 static GLboolean
799 _program_GetLinkStatus (struct gl2_program_intf **intf)
800 {
801 struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;
802
803 return impl->_obj.link_status;
804 }
805
806 static GLboolean
807 _program_GetValidateStatus (struct gl2_program_intf **intf)
808 {
809 struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;
810
811 return impl->_obj.validate_status;
812 }
813
814 static GLvoid
815 _program_Link (struct gl2_program_intf **intf)
816 {
817 struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;
818 #if USE_3DLABS_FRONTEND
819 ShHandle *handles;
820 #endif
821 GLuint i, count;
822 slang_code_object *code[2];
823 GLboolean all_compiled = GL_TRUE;
824
825 impl->_obj.link_status = GL_FALSE;
826 _mesa_free ((void *) impl->_obj._container._generic.info_log);
827 impl->_obj._container._generic.info_log = NULL;
828 slang_program_rst (&impl->_obj.prog);
829
830 #if USE_3DLABS_FRONTEND
831 handles = (ShHandle *) _mesa_malloc (impl->_obj._container.attached_count * sizeof (ShHandle));
832 if (handles == NULL)
833 return;
834
835 for (i = 0; i < impl->_obj._container.attached_count; i++)
836 {
837 struct gl2_generic_intf **gen = impl->_obj._container.attached[i];
838 struct gl2_3dlabs_shhandle_intf **sh;
839
840 sh = (struct gl2_3dlabs_shhandle_intf **) (**gen)._unknown.QueryInterface (
841 (struct gl2_unknown_intf **) gen, UIID_3DLABS_SHHANDLE);
842 if (sh != NULL)
843 {
844 handles[i] = (**sh).GetShHandle (sh);
845 (**sh)._unknown.Release ((struct gl2_unknown_intf **) sh);
846 }
847 else
848 {
849 _mesa_free (handles);
850 return;
851 }
852 }
853
854 if (ShLink (impl->_obj.linker, handles, impl->_obj._container.attached_count,
855 impl->_obj.uniforms, NULL, NULL))
856 impl->_obj.link_status = GL_TRUE;
857
858 impl->_obj._container._generic.info_log = _mesa_strdup (ShGetInfoLog (impl->_obj.linker));
859 #else
860 count = impl->_obj._container.attached_count;
861 if (count > 2)
862 return;
863 for (i = 0; i < count; i++)
864 {
865 struct gl2_generic_intf **obj;
866 struct gl2_unknown_intf **unk;
867 struct gl2_shader_impl *sha;
868
869 obj = impl->_obj._container.attached[i];
870 unk = (**obj)._unknown.QueryInterface ((struct gl2_unknown_intf **) obj, UIID_SHADER);
871 if (unk == NULL)
872 return;
873 sha = (struct gl2_shader_impl *) unk;
874 code[i] = &sha->_obj.code;
875 all_compiled = all_compiled && sha->_obj.compile_status;
876 (**unk).Release (unk);
877 }
878
879 impl->_obj.link_status = all_compiled;
880 if (!impl->_obj.link_status)
881 {
882 impl->_obj._container._generic.info_log = _mesa_strdup (
883 "Error: One or more shaders has not successfully compiled.\n");
884 return;
885 }
886
887 impl->_obj.link_status = _slang_link (&impl->_obj.prog, code, count);
888 if (!impl->_obj.link_status)
889 {
890 impl->_obj._container._generic.info_log = _mesa_strdup ("Link failed.\n");
891 return;
892 }
893
894 impl->_obj._container._generic.info_log = _mesa_strdup ("Link OK.\n");
895 #endif
896 }
897
898 static GLvoid
899 _program_Validate (struct gl2_program_intf **intf)
900 {
901 struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;
902
903 impl->_obj.validate_status = GL_FALSE;
904 _mesa_free ((void *) impl->_obj._container._generic.info_log);
905 impl->_obj._container._generic.info_log = NULL;
906
907 /* TODO validate */
908 }
909
910 static GLvoid
911 write_common_fixed (slang_program *pro, GLuint index, const GLvoid *src, GLuint off, GLuint size)
912 {
913 GLuint i;
914
915 for (i = 0; i < SLANG_SHADER_MAX; i++)
916 {
917 GLuint addr;
918
919 addr = pro->common_fixed_entries[i][index];
920 if (addr != ~0)
921 {
922 GLubyte *dst;
923
924 dst = (GLubyte *) pro->machines[i]->mem + addr + off * size;
925 _mesa_memcpy (dst, src, size);
926 }
927 }
928 }
929
930 static GLvoid
931 write_common_fixed_mat4 (slang_program *pro, GLmatrix *matrix, GLuint off, GLuint i, GLuint ii,
932 GLuint it, GLuint iit)
933 {
934 GLfloat mat[16];
935
936 /* we want inverse matrix */
937 if (!matrix->inv)
938 {
939 /* allocate inverse matrix and make it dirty */
940 _math_matrix_alloc_inv (matrix);
941 _math_matrix_loadf (matrix, matrix->m);
942 }
943 _math_matrix_analyse (matrix);
944
945 write_common_fixed (pro, i, matrix->m, off, 16 * sizeof (GLfloat));
946
947 /* inverse */
948 write_common_fixed (pro, ii, matrix->inv, off, 16 * sizeof (GLfloat));
949
950 /* transpose */
951 _math_transposef (mat, matrix->m);
952 write_common_fixed (pro, it, mat, off, 16 * sizeof (GLfloat));
953
954 /* inverse transpose */
955 _math_transposef (mat, matrix->inv);
956 write_common_fixed (pro, iit, mat, off, 16 * sizeof (GLfloat));
957 }
958
959 static GLvoid
960 write_common_fixed_material (GLcontext *ctx, slang_program *pro, GLuint i, GLuint e, GLuint a,
961 GLuint d, GLuint sp, GLuint sh)
962 {
963 GLfloat v[17];
964
965 COPY_4FV(v, ctx->Light.Material.Attrib[e]);
966 COPY_4FV((v + 4), ctx->Light.Material.Attrib[a]);
967 COPY_4FV((v + 8), ctx->Light.Material.Attrib[d]);
968 COPY_4FV((v + 12), ctx->Light.Material.Attrib[sp]);
969 v[16] = ctx->Light.Material.Attrib[sh][0];
970 write_common_fixed (pro, i, v, 0, 17 * sizeof (GLfloat));
971 }
972
973 static GLvoid
974 write_common_fixed_light_model_product (GLcontext *ctx, slang_program *pro, GLuint i, GLuint e,
975 GLuint a)
976 {
977 GLfloat v[4];
978
979 SCALE_4V(v, ctx->Light.Material.Attrib[a], ctx->Light.Model.Ambient);
980 ACC_4V(v, ctx->Light.Material.Attrib[e]);
981 write_common_fixed (pro, i, v, 0, 4 * sizeof (GLfloat));
982 }
983
984 static GLvoid
985 write_common_fixed_light_product (GLcontext *ctx, slang_program *pro, GLuint off, GLuint i, GLuint a,
986 GLuint d, GLuint s)
987 {
988 GLfloat v[12];
989
990 SCALE_4V(v, ctx->Light.Light[off].Ambient, ctx->Light.Material.Attrib[a]);
991 SCALE_4V((v + 4), ctx->Light.Light[off].Diffuse, ctx->Light.Material.Attrib[d]);
992 SCALE_4V((v + 8), ctx->Light.Light[off].Specular, ctx->Light.Material.Attrib[s]);
993 write_common_fixed (pro, i, v, off, 12 * sizeof (GLfloat));
994 }
995
996 static GLvoid
997 _program_UpdateFixedUniforms (struct gl2_program_intf **intf)
998 {
999 GET_CURRENT_CONTEXT(ctx);
1000 struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;
1001 slang_program *pro = &impl->_obj.prog;
1002 GLuint i;
1003 GLfloat v[29];
1004 GLfloat *p;
1005
1006 /* MODELVIEW matrix */
1007 write_common_fixed_mat4 (pro, ctx->ModelviewMatrixStack.Top, 0,
1008 SLANG_COMMON_FIXED_MODELVIEWMATRIX,
1009 SLANG_COMMON_FIXED_MODELVIEWMATRIXINVERSE,
1010 SLANG_COMMON_FIXED_MODELVIEWMATRIXTRANSPOSE,
1011 SLANG_COMMON_FIXED_MODELVIEWMATRIXINVERSETRANSPOSE);
1012
1013 /* PROJECTION matrix */
1014 write_common_fixed_mat4 (pro, ctx->ProjectionMatrixStack.Top, 0,
1015 SLANG_COMMON_FIXED_PROJECTIONMATRIX,
1016 SLANG_COMMON_FIXED_PROJECTIONMATRIXINVERSE,
1017 SLANG_COMMON_FIXED_PROJECTIONMATRIXTRANSPOSE,
1018 SLANG_COMMON_FIXED_PROJECTIONMATRIXINVERSETRANSPOSE);
1019
1020 /* MVP matrix */
1021 write_common_fixed_mat4 (pro, &ctx->_ModelProjectMatrix, 0,
1022 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIX,
1023 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIXINVERSE,
1024 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIXTRANSPOSE,
1025 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIXINVERSETRANSPOSE);
1026
1027 for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++)
1028 {
1029 /* TEXTURE matrix */
1030 write_common_fixed_mat4 (pro, ctx->TextureMatrixStack[i].Top, i,
1031 SLANG_COMMON_FIXED_TEXTUREMATRIX,
1032 SLANG_COMMON_FIXED_TEXTUREMATRIXINVERSE,
1033 SLANG_COMMON_FIXED_TEXTUREMATRIXTRANSPOSE,
1034 SLANG_COMMON_FIXED_TEXTUREMATRIXINVERSETRANSPOSE);
1035
1036 /* EYE_PLANE texture-coordinate generation */
1037 write_common_fixed (pro, SLANG_COMMON_FIXED_EYEPLANES, ctx->Texture.Unit[i].EyePlaneS,
1038 i, 4 * sizeof (GLfloat));
1039 write_common_fixed (pro, SLANG_COMMON_FIXED_EYEPLANET, ctx->Texture.Unit[i].EyePlaneT,
1040 i, 4 * sizeof (GLfloat));
1041 write_common_fixed (pro, SLANG_COMMON_FIXED_EYEPLANER, ctx->Texture.Unit[i].EyePlaneR,
1042 i, 4 * sizeof (GLfloat));
1043 write_common_fixed (pro, SLANG_COMMON_FIXED_EYEPLANEQ, ctx->Texture.Unit[i].EyePlaneQ,
1044 i, 4 * sizeof (GLfloat));
1045
1046 /* OBJECT_PLANE texture-coordinate generation */
1047 write_common_fixed (pro, SLANG_COMMON_FIXED_OBJECTPLANES, ctx->Texture.Unit[i].ObjectPlaneS,
1048 i, 4 * sizeof (GLfloat));
1049 write_common_fixed (pro, SLANG_COMMON_FIXED_OBJECTPLANET, ctx->Texture.Unit[i].ObjectPlaneT,
1050 i, 4 * sizeof (GLfloat));
1051 write_common_fixed (pro, SLANG_COMMON_FIXED_OBJECTPLANER, ctx->Texture.Unit[i].ObjectPlaneR,
1052 i, 4 * sizeof (GLfloat));
1053 write_common_fixed (pro, SLANG_COMMON_FIXED_OBJECTPLANEQ, ctx->Texture.Unit[i].ObjectPlaneQ,
1054 i, 4 * sizeof (GLfloat));
1055 }
1056
1057 /* NORMAL matrix - upper 3x3 inverse transpose of MODELVIEW matrix */
1058 p = ctx->ModelviewMatrixStack.Top->inv;
1059 v[0] = p[0];
1060 v[1] = p[4];
1061 v[2] = p[8];
1062 v[3] = p[1];
1063 v[4] = p[5];
1064 v[5] = p[9];
1065 v[6] = p[2];
1066 v[7] = p[6];
1067 v[8] = p[10];
1068 write_common_fixed (pro, SLANG_COMMON_FIXED_NORMALMATRIX, v, 0, 9 * sizeof (GLfloat));
1069
1070 /* normal scale */
1071 write_common_fixed (pro, SLANG_COMMON_FIXED_NORMALSCALE, &ctx->_ModelViewInvScale, 0, sizeof (GLfloat));
1072
1073 /* depth range parameters */
1074 v[0] = ctx->Viewport.Near;
1075 v[1] = ctx->Viewport.Far;
1076 v[2] = ctx->Viewport.Far - ctx->Viewport.Near;
1077 write_common_fixed (pro, SLANG_COMMON_FIXED_DEPTHRANGE, v, 0, 3 * sizeof (GLfloat));
1078
1079 /* CLIP_PLANEi */
1080 for (i = 0; i < ctx->Const.MaxClipPlanes; i++)
1081 {
1082 write_common_fixed (pro, SLANG_COMMON_FIXED_CLIPPLANE, ctx->Transform.EyeUserPlane[i], i,
1083 4 * sizeof (GLfloat));
1084 }
1085
1086 /* point parameters */
1087 v[0] = ctx->Point.Size;
1088 v[1] = ctx->Point.MinSize;
1089 v[2] = ctx->Point.MaxSize;
1090 v[3] = ctx->Point.Threshold;
1091 COPY_3FV((v + 4), ctx->Point.Params);
1092 write_common_fixed (pro, SLANG_COMMON_FIXED_POINT, v, 0, 7 * sizeof (GLfloat));
1093
1094 /* material parameters */
1095 write_common_fixed_material (ctx, pro, SLANG_COMMON_FIXED_FRONTMATERIAL,
1096 MAT_ATTRIB_FRONT_EMISSION,
1097 MAT_ATTRIB_FRONT_AMBIENT,
1098 MAT_ATTRIB_FRONT_DIFFUSE,
1099 MAT_ATTRIB_FRONT_SPECULAR,
1100 MAT_ATTRIB_FRONT_SHININESS);
1101 write_common_fixed_material (ctx, pro, SLANG_COMMON_FIXED_BACKMATERIAL,
1102 MAT_ATTRIB_BACK_EMISSION,
1103 MAT_ATTRIB_BACK_AMBIENT,
1104 MAT_ATTRIB_BACK_DIFFUSE,
1105 MAT_ATTRIB_BACK_SPECULAR,
1106 MAT_ATTRIB_BACK_SHININESS);
1107
1108 for (i = 0; i < ctx->Const.MaxLights; i++)
1109 {
1110 /* light source parameters */
1111 COPY_4FV(v, ctx->Light.Light[i].Ambient);
1112 COPY_4FV((v + 4), ctx->Light.Light[i].Diffuse);
1113 COPY_4FV((v + 8), ctx->Light.Light[i].Specular);
1114 COPY_4FV((v + 12), ctx->Light.Light[i].EyePosition);
1115 COPY_2FV((v + 16), ctx->Light.Light[i].EyePosition);
1116 v[18] = ctx->Light.Light[i].EyePosition[2] + 1.0f;
1117 NORMALIZE_3FV((v + 16));
1118 v[19] = 0.0f;
1119 COPY_3V((v + 20), ctx->Light.Light[i].EyeDirection);
1120 v[23] = ctx->Light.Light[i].SpotExponent;
1121 v[24] = ctx->Light.Light[i].SpotCutoff;
1122 v[25] = ctx->Light.Light[i]._CosCutoffNeg;
1123 v[26] = ctx->Light.Light[i].ConstantAttenuation;
1124 v[27] = ctx->Light.Light[i].LinearAttenuation;
1125 v[28] = ctx->Light.Light[i].QuadraticAttenuation;
1126 write_common_fixed (pro, SLANG_COMMON_FIXED_LIGHTSOURCE, v, i, 29 * sizeof (GLfloat));
1127
1128 /* light product */
1129 write_common_fixed_light_product (ctx, pro, i, SLANG_COMMON_FIXED_FRONTLIGHTPRODUCT,
1130 MAT_ATTRIB_FRONT_AMBIENT,
1131 MAT_ATTRIB_FRONT_DIFFUSE,
1132 MAT_ATTRIB_FRONT_SPECULAR);
1133 write_common_fixed_light_product (ctx, pro, i, SLANG_COMMON_FIXED_BACKLIGHTPRODUCT,
1134 MAT_ATTRIB_BACK_AMBIENT,
1135 MAT_ATTRIB_BACK_DIFFUSE,
1136 MAT_ATTRIB_BACK_SPECULAR);
1137 }
1138
1139 /* light model parameters */
1140 write_common_fixed (pro, SLANG_COMMON_FIXED_LIGHTMODEL, ctx->Light.Model.Ambient, 0, 4 * sizeof (GLfloat));
1141
1142 /* light model product */
1143 write_common_fixed_light_model_product (ctx, pro, SLANG_COMMON_FIXED_FRONTLIGHTMODELPRODUCT,
1144 MAT_ATTRIB_FRONT_EMISSION,
1145 MAT_ATTRIB_FRONT_AMBIENT);
1146 write_common_fixed_light_model_product (ctx, pro, SLANG_COMMON_FIXED_BACKLIGHTMODELPRODUCT,
1147 MAT_ATTRIB_BACK_EMISSION,
1148 MAT_ATTRIB_BACK_AMBIENT);
1149
1150 /* TEXTURE_ENV_COLOR */
1151 for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++)
1152 {
1153 write_common_fixed (pro, SLANG_COMMON_FIXED_TEXTUREENVCOLOR, ctx->Texture.Unit[i].EnvColor,
1154 i, 4 * sizeof (GLfloat));
1155 }
1156
1157 /* fog parameters */
1158 COPY_4FV(v, ctx->Fog.Color);
1159 v[4] = ctx->Fog.Density;
1160 v[5] = ctx->Fog.Start;
1161 v[6] = ctx->Fog.End;
1162 v[7] = ctx->Fog._Scale;
1163 write_common_fixed (pro, SLANG_COMMON_FIXED_FOG, v, 0, 8 * sizeof (GLfloat));
1164 }
1165
1166 static GLvoid
1167 _program_UpdateFixedAttrib (struct gl2_program_intf **intf, GLuint index, GLvoid *data,
1168 GLuint offset, GLuint size, GLboolean write)
1169 {
1170 struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;
1171 slang_program *pro = &impl->_obj.prog;
1172 GLuint addr;
1173
1174 addr = pro->vertex_fixed_entries[index];
1175 if (addr != ~0)
1176 {
1177 GLubyte *mem;
1178
1179 mem = (GLubyte *) pro->machines[SLANG_SHADER_VERTEX]->mem + addr + offset * size;
1180 if (write)
1181 _mesa_memcpy (mem, data, size);
1182 else
1183 _mesa_memcpy (data, mem, size);
1184 }
1185 }
1186
1187
1188 /**
1189 * Called during fragment shader execution to either load a varying
1190 * register with values, or fetch values from a varying register.
1191 * \param intf the internal program?
1192 * \param index which varying register, one of the SLANG_FRAGMENT_FIXED_*
1193 * values for example.
1194 * \param data source values to load (or dest to write to)
1195 * \param offset indicates a texture unit or generic varying attribute
1196 * \param size number of bytes to copy
1197 * \param write if true, write to the varying register, else store values
1198 * in 'data'
1199 */
1200 static GLvoid
1201 _program_UpdateFixedVarying(struct gl2_program_intf **intf, GLuint index,
1202 GLvoid *data,
1203 GLuint offset, GLuint size, GLboolean write)
1204 {
1205 struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;
1206 slang_program *pro = &impl->_obj.prog;
1207 GLuint addr;
1208
1209 addr = pro->fragment_fixed_entries[index];
1210 if (addr != ~0)
1211 {
1212 GLubyte *mem;
1213
1214 mem = (GLubyte *) pro->machines[SLANG_SHADER_FRAGMENT]->mem + addr + offset * size;
1215 if (write)
1216 _mesa_memcpy (mem, data, size);
1217 else
1218 _mesa_memcpy (data, mem, size);
1219 }
1220 }
1221
1222 static GLvoid
1223 _program_GetTextureImageUsage (struct gl2_program_intf **intf, GLbitfield *teximageusage)
1224 {
1225 GET_CURRENT_CONTEXT(ctx);
1226 struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;
1227 slang_program *pro = &impl->_obj.prog;
1228 GLuint i;
1229
1230 for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++)
1231 teximageusage[i] = 0;
1232
1233 for (i = 0; i < pro->texture_usage.count; i++)
1234 {
1235 GLuint n, addr, j;
1236
1237 n = slang_export_data_quant_elements (pro->texture_usage.table[i].quant);
1238 addr = pro->texture_usage.table[i].frag_address;
1239 for (j = 0; j < n; j++)
1240 {
1241 GLubyte *mem;
1242 GLuint image;
1243
1244 mem = (GLubyte *) pro->machines[SLANG_SHADER_FRAGMENT]->mem + addr + j * 4;
1245 image = (GLuint) *((GLfloat *) mem);
1246 if (image >= 0 && image < ctx->Const.MaxTextureImageUnits)
1247 {
1248 switch (slang_export_data_quant_type (pro->texture_usage.table[i].quant))
1249 {
1250 case GL_SAMPLER_1D_ARB:
1251 case GL_SAMPLER_1D_SHADOW_ARB:
1252 teximageusage[image] |= TEXTURE_1D_BIT;
1253 break;
1254 case GL_SAMPLER_2D_ARB:
1255 case GL_SAMPLER_2D_SHADOW_ARB:
1256 teximageusage[image] |= TEXTURE_2D_BIT;
1257 break;
1258 case GL_SAMPLER_3D_ARB:
1259 teximageusage[image] |= TEXTURE_3D_BIT;
1260 break;
1261 case GL_SAMPLER_CUBE_ARB:
1262 teximageusage[image] |= TEXTURE_CUBE_BIT;
1263 break;
1264 }
1265 }
1266 }
1267 }
1268
1269 /* TODO: make sure that for 0<=i<=MaxTextureImageUint bitcount(teximageuint[i])<=0 */
1270 }
1271
1272 static GLboolean
1273 _program_IsShaderPresent (struct gl2_program_intf **intf, GLenum subtype)
1274 {
1275 struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;
1276 slang_program *pro = &impl->_obj.prog;
1277
1278 switch (subtype)
1279 {
1280 case GL_VERTEX_SHADER_ARB:
1281 return pro->machines[SLANG_SHADER_VERTEX] != NULL;
1282 case GL_FRAGMENT_SHADER_ARB:
1283 return pro->machines[SLANG_SHADER_FRAGMENT] != NULL;
1284 default:
1285 return GL_FALSE;
1286 }
1287 }
1288
1289 static GLvoid
1290 get_active_variable (slang_active_variable *var, GLsizei maxLength, GLsizei *length, GLint *size,
1291 GLenum *type, GLchar *name)
1292 {
1293 GLsizei len;
1294
1295 len = _mesa_strlen (var->name);
1296 if (len >= maxLength)
1297 len = maxLength - 1;
1298 if (length != NULL)
1299 *length = len;
1300 *size = slang_export_data_quant_elements (var->quant);
1301 *type = slang_export_data_quant_type (var->quant);
1302 _mesa_memcpy (name, var->name, len);
1303 name[len] = '\0';
1304 }
1305
1306 static GLuint
1307 get_active_variable_max_length (slang_active_variables *vars)
1308 {
1309 GLuint i, len = 0;
1310
1311 for (i = 0; i < vars->count; i++)
1312 {
1313 GLuint n = _mesa_strlen (vars->table[i].name);
1314 if (n > len)
1315 len = n;
1316 }
1317 return len;
1318 }
1319
1320 static GLvoid
1321 _program_GetActiveUniform (struct gl2_program_intf **intf, GLuint index, GLsizei maxLength,
1322 GLsizei *length, GLint *size, GLenum *type, GLchar *name)
1323 {
1324 struct gl2_program_impl *impl = (struct gl2_program_impl *) (intf);
1325 slang_active_variable *u = &impl->_obj.prog.active_uniforms.table[index];
1326
1327 get_active_variable (u, maxLength, length, size, type, name);
1328 }
1329
1330 static GLuint
1331 _program_GetActiveUniformMaxLength (struct gl2_program_intf **intf)
1332 {
1333 struct gl2_program_impl *impl = (struct gl2_program_impl *) (intf);
1334
1335 return get_active_variable_max_length (&impl->_obj.prog.active_uniforms);
1336 }
1337
1338 static GLuint
1339 _program_GetActiveUniformCount (struct gl2_program_intf **intf)
1340 {
1341 struct gl2_program_impl *impl = (struct gl2_program_impl *) (intf);
1342
1343 return impl->_obj.prog.active_uniforms.count;
1344 }
1345
1346 static GLint
1347 _program_GetUniformLocation (struct gl2_program_intf **intf, const GLchar *name)
1348 {
1349 struct gl2_program_impl *impl = (struct gl2_program_impl *) (intf);
1350 slang_uniform_bindings *bind = &impl->_obj.prog.uniforms;
1351 GLuint i;
1352
1353 for (i = 0; i < bind->count; i++)
1354 if (_mesa_strcmp (bind->table[i].name, name) == 0)
1355 return i;
1356 return -1;
1357 }
1358
1359 static GLboolean
1360 _program_WriteUniform (struct gl2_program_intf **intf, GLint loc, GLsizei count, const GLvoid *data,
1361 GLenum type)
1362 {
1363 struct gl2_program_impl *impl = (struct gl2_program_impl *) (intf);
1364 slang_uniform_bindings *uniforms = &impl->_obj.prog.uniforms;
1365 slang_uniform_binding *uniform;
1366 GLuint i;
1367 GLboolean convert_float_to_bool = GL_FALSE;
1368 GLboolean convert_int_to_bool = GL_FALSE;
1369 GLboolean convert_int_to_float = GL_FALSE;
1370 GLboolean types_match = GL_FALSE;
1371
1372 if (loc == -1)
1373 return GL_TRUE;
1374 if (loc >= uniforms->count)
1375 return GL_FALSE;
1376
1377 uniform = &uniforms->table[loc];
1378 /* TODO: check sizes */
1379 if (slang_export_data_quant_struct (uniform->quant))
1380 return GL_FALSE;
1381
1382 switch (slang_export_data_quant_type (uniform->quant))
1383 {
1384 case GL_BOOL_ARB:
1385 types_match = (type == GL_FLOAT) || (type == GL_INT);
1386 if (type == GL_FLOAT)
1387 convert_float_to_bool = GL_TRUE;
1388 else
1389 convert_int_to_bool = GL_TRUE;
1390 break;
1391 case GL_BOOL_VEC2_ARB:
1392 types_match = (type == GL_FLOAT_VEC2_ARB) || (type == GL_INT_VEC2_ARB);
1393 if (type == GL_FLOAT_VEC2_ARB)
1394 convert_float_to_bool = GL_TRUE;
1395 else
1396 convert_int_to_bool = GL_TRUE;
1397 break;
1398 case GL_BOOL_VEC3_ARB:
1399 types_match = (type == GL_FLOAT_VEC3_ARB) || (type == GL_INT_VEC3_ARB);
1400 if (type == GL_FLOAT_VEC3_ARB)
1401 convert_float_to_bool = GL_TRUE;
1402 else
1403 convert_int_to_bool = GL_TRUE;
1404 break;
1405 case GL_BOOL_VEC4_ARB:
1406 types_match = (type == GL_FLOAT_VEC4_ARB) || (type == GL_INT_VEC4_ARB);
1407 if (type == GL_FLOAT_VEC4_ARB)
1408 convert_float_to_bool = GL_TRUE;
1409 else
1410 convert_int_to_bool = GL_TRUE;
1411 break;
1412 case GL_SAMPLER_1D_ARB:
1413 case GL_SAMPLER_2D_ARB:
1414 case GL_SAMPLER_3D_ARB:
1415 case GL_SAMPLER_CUBE_ARB:
1416 case GL_SAMPLER_1D_SHADOW_ARB:
1417 case GL_SAMPLER_2D_SHADOW_ARB:
1418 types_match = (type == GL_INT);
1419 break;
1420 default:
1421 types_match = (type == slang_export_data_quant_type (uniform->quant));
1422 break;
1423 }
1424
1425 if (!types_match)
1426 return GL_FALSE;
1427
1428 switch (type)
1429 {
1430 case GL_INT:
1431 case GL_INT_VEC2_ARB:
1432 case GL_INT_VEC3_ARB:
1433 case GL_INT_VEC4_ARB:
1434 convert_int_to_float = GL_TRUE;
1435 break;
1436 }
1437
1438 if (convert_float_to_bool)
1439 {
1440 for (i = 0; i < SLANG_SHADER_MAX; i++)
1441 if (uniform->address[i] != ~0)
1442 {
1443 const GLfloat *src = (GLfloat *) (data);
1444 GLfloat *dst = (GLfloat *)
1445 (&impl->_obj.prog.machines[i]->mem[uniform->address[i] / 4]);
1446 GLuint j;
1447 GLuint total = count * slang_export_data_quant_components (uniform->quant);
1448
1449 for (j = 0; j < total; j++)
1450 dst[j] = src[j] != 0.0f ? 1.0f : 0.0f;
1451 }
1452 }
1453 else if (convert_int_to_bool)
1454 {
1455 for (i = 0; i < SLANG_SHADER_MAX; i++)
1456 if (uniform->address[i] != ~0)
1457 {
1458 const GLuint *src = (GLuint *) (data);
1459 GLfloat *dst = (GLfloat *)
1460 (&impl->_obj.prog.machines[i]->mem[uniform->address[i] / 4]);
1461 GLuint j;
1462 GLuint total = count * slang_export_data_quant_components (uniform->quant);
1463
1464 for (j = 0; j < total; j++)
1465 dst[j] = src[j] ? 1.0f : 0.0f;
1466 }
1467 }
1468 else if (convert_int_to_float)
1469 {
1470 for (i = 0; i < SLANG_SHADER_MAX; i++)
1471 if (uniform->address[i] != ~0)
1472 {
1473 const GLuint *src = (GLuint *) (data);
1474 GLfloat *dst = (GLfloat *)
1475 (&impl->_obj.prog.machines[i]->mem[uniform->address[i] / 4]);
1476 GLuint j;
1477 GLuint total = count * slang_export_data_quant_components (uniform->quant);
1478
1479 for (j = 0; j < total; j++)
1480 dst[j] = (GLfloat) src[j];
1481 }
1482 }
1483 else
1484 {
1485 for (i = 0; i < SLANG_SHADER_MAX; i++)
1486 if (uniform->address[i] != ~0)
1487 {
1488 _mesa_memcpy (&impl->_obj.prog.machines[i]->mem[uniform->address[i] / 4], data,
1489 count * slang_export_data_quant_size (uniform->quant));
1490 }
1491 }
1492 return GL_TRUE;
1493 }
1494
1495 static GLvoid
1496 _program_GetActiveAttrib (struct gl2_program_intf **intf, GLuint index, GLsizei maxLength,
1497 GLsizei *length, GLint *size, GLenum *type, GLchar *name)
1498 {
1499 struct gl2_program_impl *impl = (struct gl2_program_impl *) (intf);
1500 slang_active_variable *a = &impl->_obj.prog.active_attribs.table[index];
1501
1502 get_active_variable (a, maxLength, length, size, type, name);
1503 }
1504
1505 static GLuint
1506 _program_GetActiveAttribMaxLength (struct gl2_program_intf **intf)
1507 {
1508 struct gl2_program_impl *impl = (struct gl2_program_impl *) (intf);
1509
1510 return get_active_variable_max_length (&impl->_obj.prog.active_attribs);
1511 }
1512
1513 static GLuint
1514 _program_GetActiveAttribCount (struct gl2_program_intf **intf)
1515 {
1516 struct gl2_program_impl *impl = (struct gl2_program_impl *) (intf);
1517
1518 return impl->_obj.prog.active_attribs.count;
1519 }
1520
1521 static GLint
1522 _program_GetAttribLocation (struct gl2_program_intf **intf, const GLchar *name)
1523 {
1524 struct gl2_program_impl *impl = (struct gl2_program_impl *) (intf);
1525 slang_attrib_bindings *attribs = &impl->_obj.prog.attribs;
1526 GLuint i;
1527
1528 for (i = 0; i < attribs->binding_count; i++)
1529 if (_mesa_strcmp (attribs->bindings[i].name, name) == 0)
1530 return attribs->bindings[i].first_slot_index;
1531 return -1;
1532 }
1533
1534 static GLvoid
1535 _program_OverrideAttribBinding (struct gl2_program_intf **intf, GLuint index, const GLchar *name)
1536 {
1537 GET_CURRENT_CONTEXT(ctx);
1538 struct gl2_program_impl *impl = (struct gl2_program_impl *) (intf);
1539 slang_program *pro = &impl->_obj.prog;
1540
1541 if (!slang_attrib_overrides_add (&pro->attrib_overrides, index, name))
1542 _mesa_error (ctx, GL_OUT_OF_MEMORY, "_program_OverrideAttribBinding");
1543 }
1544
1545 static GLvoid
1546 _program_WriteAttrib (struct gl2_program_intf **intf, GLuint index, const GLfloat *value)
1547 {
1548 struct gl2_program_impl *impl = (struct gl2_program_impl *) (intf);
1549 slang_program *pro = &impl->_obj.prog;
1550 slang_attrib_slot *slot = &pro->attribs.slots[index];
1551
1552 /*
1553 * Generic attributes can be allocated in a shader with scalar, vec or mat type.
1554 * For scalar and vec types (specifically float, vec2 and vec3) this is simple - just
1555 * ignore the extra components. For mat type this is more complicated - the vertex_shader
1556 * spec requires to store every column of a matrix in a separate attrib slot.
1557 * To prvent from overwriting data from neighbouring matrix columns, the "fill" information
1558 * is kept to know how many components to copy.
1559 */
1560
1561 if (slot->addr != ~0)
1562 _mesa_memcpy (&pro->machines[SLANG_SHADER_VERTEX]->mem[slot->addr / 4]._float, value,
1563 slot->fill * sizeof (GLfloat));
1564 }
1565
1566 static GLvoid
1567 _program_UpdateVarying (struct gl2_program_intf **intf, GLuint index, GLfloat *value,
1568 GLboolean vert)
1569 {
1570 struct gl2_program_impl *impl = (struct gl2_program_impl *) intf;
1571 slang_program *pro = &impl->_obj.prog;
1572 GLuint addr;
1573
1574 if (index >= pro->varyings.slot_count)
1575 return;
1576 if (vert)
1577 addr = pro->varyings.slots[index].vert_addr / 4;
1578 else
1579 addr = pro->varyings.slots[index].frag_addr / 4;
1580 if (addr != ~0)
1581 {
1582 if (vert)
1583 *value = pro->machines[SLANG_SHADER_VERTEX]->mem[addr]._float;
1584 else
1585 pro->machines[SLANG_SHADER_FRAGMENT]->mem[addr]._float = *value;
1586 }
1587 }
1588
1589 static struct gl2_program_intf _program_vftbl = {
1590 {
1591 {
1592 {
1593 _unknown_AddRef,
1594 _unknown_Release,
1595 _program_QueryInterface
1596 },
1597 _generic_Delete,
1598 _program_GetType,
1599 _generic_GetName,
1600 _generic_GetDeleteStatus,
1601 _generic_GetInfoLog,
1602 _generic_GetInfoLogLength
1603 },
1604 _program_Attach,
1605 _container_Detach,
1606 _container_GetAttachedCount,
1607 _container_GetAttached
1608 },
1609 _program_GetLinkStatus,
1610 _program_GetValidateStatus,
1611 _program_Link,
1612 _program_Validate,
1613 _program_UpdateFixedUniforms,
1614 _program_UpdateFixedAttrib,
1615 _program_UpdateFixedVarying,
1616 _program_GetTextureImageUsage,
1617 _program_IsShaderPresent,
1618 _program_GetActiveUniform,
1619 _program_GetActiveUniformMaxLength,
1620 _program_GetActiveUniformCount,
1621 _program_GetUniformLocation,
1622 _program_WriteUniform,
1623 _program_GetActiveAttrib,
1624 _program_GetActiveAttribMaxLength,
1625 _program_GetActiveAttribCount,
1626 _program_GetAttribLocation,
1627 _program_OverrideAttribBinding,
1628 _program_WriteAttrib,
1629 _program_UpdateVarying
1630 };
1631
1632 static void
1633 _program_constructor (struct gl2_program_impl *impl)
1634 {
1635 _container_constructor ((struct gl2_container_impl *) impl);
1636 impl->_vftbl = &_program_vftbl;
1637 impl->_obj._container._generic._unknown._destructor = _program_destructor;
1638 impl->_obj.link_status = GL_FALSE;
1639 impl->_obj.validate_status = GL_FALSE;
1640 #if USE_3DLABS_FRONTEND
1641 impl->_obj.linker = ShConstructLinker (EShExVertexFragment, 0);
1642 impl->_obj.uniforms = ShConstructUniformMap ();
1643 #endif
1644 slang_program_ctr (&impl->_obj.prog);
1645 }
1646
1647 struct gl2_fragment_shader_obj
1648 {
1649 struct gl2_shader_obj _shader;
1650 };
1651
1652 struct gl2_fragment_shader_impl
1653 {
1654 struct gl2_fragment_shader_intf *_vftbl;
1655 struct gl2_fragment_shader_obj _obj;
1656 };
1657
1658 static void
1659 _fragment_shader_destructor (struct gl2_unknown_intf **intf)
1660 {
1661 struct gl2_fragment_shader_impl *impl = (struct gl2_fragment_shader_impl *) intf;
1662
1663 (void) impl;
1664 /* TODO free fragment shader data */
1665
1666 _shader_destructor (intf);
1667 }
1668
1669 static struct gl2_unknown_intf **
1670 _fragment_shader_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
1671 {
1672 if (uiid == UIID_FRAGMENT_SHADER)
1673 {
1674 (**intf).AddRef (intf);
1675 return intf;
1676 }
1677 return _shader_QueryInterface (intf, uiid);
1678 }
1679
1680 static GLenum
1681 _fragment_shader_GetSubType (struct gl2_shader_intf **intf)
1682 {
1683 return GL_FRAGMENT_SHADER_ARB;
1684 }
1685
1686 static struct gl2_fragment_shader_intf _fragment_shader_vftbl = {
1687 {
1688 {
1689 {
1690 _unknown_AddRef,
1691 _unknown_Release,
1692 _fragment_shader_QueryInterface
1693 },
1694 _generic_Delete,
1695 _shader_GetType,
1696 _generic_GetName,
1697 _generic_GetDeleteStatus,
1698 _shader_GetInfoLog,
1699 _shader_GetInfoLogLength
1700 },
1701 _fragment_shader_GetSubType,
1702 _shader_GetCompileStatus,
1703 _shader_SetSource,
1704 _shader_GetSource,
1705 _shader_Compile
1706 }
1707 };
1708
1709 static void
1710 _fragment_shader_constructor (struct gl2_fragment_shader_impl *impl)
1711 {
1712 _shader_constructor ((struct gl2_shader_impl *) impl);
1713 impl->_vftbl = &_fragment_shader_vftbl;
1714 impl->_obj._shader._generic._unknown._destructor = _fragment_shader_destructor;
1715 #if USE_3DLABS_FRONTEND
1716 impl->_obj._shader._3dlabs_shhandle._obj.handle = ShConstructCompiler (EShLangFragment, 0);
1717 #endif
1718 }
1719
1720 struct gl2_vertex_shader_obj
1721 {
1722 struct gl2_shader_obj _shader;
1723 };
1724
1725 struct gl2_vertex_shader_impl
1726 {
1727 struct gl2_vertex_shader_intf *_vftbl;
1728 struct gl2_vertex_shader_obj _obj;
1729 };
1730
1731 static void
1732 _vertex_shader_destructor (struct gl2_unknown_intf **intf)
1733 {
1734 struct gl2_vertex_shader_impl *impl = (struct gl2_vertex_shader_impl *) intf;
1735
1736 (void) impl;
1737 /* TODO free vertex shader data */
1738
1739 _shader_destructor (intf);
1740 }
1741
1742 static struct gl2_unknown_intf **
1743 _vertex_shader_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
1744 {
1745 if (uiid == UIID_VERTEX_SHADER)
1746 {
1747 (**intf).AddRef (intf);
1748 return intf;
1749 }
1750 return _shader_QueryInterface (intf, uiid);
1751 }
1752
1753 static GLenum
1754 _vertex_shader_GetSubType (struct gl2_shader_intf **intf)
1755 {
1756 return GL_VERTEX_SHADER_ARB;
1757 }
1758
1759 static struct gl2_vertex_shader_intf _vertex_shader_vftbl = {
1760 {
1761 {
1762 {
1763 _unknown_AddRef,
1764 _unknown_Release,
1765 _vertex_shader_QueryInterface
1766 },
1767 _generic_Delete,
1768 _shader_GetType,
1769 _generic_GetName,
1770 _generic_GetDeleteStatus,
1771 _shader_GetInfoLog,
1772 _shader_GetInfoLogLength
1773 },
1774 _vertex_shader_GetSubType,
1775 _shader_GetCompileStatus,
1776 _shader_SetSource,
1777 _shader_GetSource,
1778 _shader_Compile
1779 }
1780 };
1781
1782 static void
1783 _vertex_shader_constructor (struct gl2_vertex_shader_impl *impl)
1784 {
1785 _shader_constructor ((struct gl2_shader_impl *) impl);
1786 impl->_vftbl = &_vertex_shader_vftbl;
1787 impl->_obj._shader._generic._unknown._destructor = _vertex_shader_destructor;
1788 #if USE_3DLABS_FRONTEND
1789 impl->_obj._shader._3dlabs_shhandle._obj.handle = ShConstructCompiler (EShLangVertex, 0);
1790 #endif
1791 }
1792
1793 struct gl2_debug_obj
1794 {
1795 struct gl2_generic_obj _generic;
1796 };
1797
1798 struct gl2_debug_impl
1799 {
1800 struct gl2_debug_intf *_vftbl;
1801 struct gl2_debug_obj _obj;
1802 };
1803
1804 static GLvoid
1805 _debug_destructor (struct gl2_unknown_intf **intf)
1806 {
1807 struct gl2_debug_impl *impl = (struct gl2_debug_impl *) (intf);
1808
1809 (void) (impl);
1810 /* TODO */
1811
1812 _generic_destructor (intf);
1813 }
1814
1815 static struct gl2_unknown_intf **
1816 _debug_QueryInterface (struct gl2_unknown_intf **intf, enum gl2_uiid uiid)
1817 {
1818 if (uiid == UIID_DEBUG) {
1819 (**intf).AddRef (intf);
1820 return intf;
1821 }
1822 return _generic_QueryInterface (intf, uiid);
1823 }
1824
1825 static GLenum
1826 _debug_GetType (struct gl2_generic_intf **intf)
1827 {
1828 return /*GL_DEBUG_OBJECT_MESA*/0;
1829 }
1830
1831 static GLvoid
1832 _debug_ClearDebugLog (struct gl2_debug_intf **intf, GLenum logType, GLenum shaderType)
1833 {
1834 struct gl2_debug_impl *impl = (struct gl2_debug_impl *) (intf);
1835
1836 (void) (impl);
1837 /* TODO */
1838 }
1839
1840 static GLvoid
1841 _debug_GetDebugLog (struct gl2_debug_intf **intf, GLenum logType, GLenum shaderType,
1842 GLsizei maxLength, GLsizei *length, GLcharARB *infoLog)
1843 {
1844 struct gl2_debug_impl *impl = (struct gl2_debug_impl *) (intf);
1845
1846 (void) (impl);
1847 /* TODO */
1848 }
1849
1850 static GLsizei
1851 _debug_GetDebugLogLength (struct gl2_debug_intf **intf, GLenum logType, GLenum shaderType)
1852 {
1853 struct gl2_debug_impl *impl = (struct gl2_debug_impl *) (intf);
1854
1855 (void) (impl);
1856 /* TODO */
1857
1858 return 0;
1859 }
1860
1861 static struct gl2_debug_intf _debug_vftbl = {
1862 {
1863 {
1864 _unknown_AddRef,
1865 _unknown_Release,
1866 _debug_QueryInterface
1867 },
1868 _generic_Delete,
1869 _debug_GetType,
1870 _generic_GetName,
1871 _generic_GetDeleteStatus,
1872 _generic_GetInfoLog,
1873 _generic_GetInfoLogLength
1874 },
1875 _debug_ClearDebugLog,
1876 _debug_GetDebugLog,
1877 _debug_GetDebugLogLength
1878 };
1879
1880 static GLvoid
1881 _debug_constructor (struct gl2_debug_impl *impl)
1882 {
1883 _generic_constructor ((struct gl2_generic_impl *) (impl));
1884 impl->_vftbl = &_debug_vftbl;
1885 impl->_obj._generic._unknown._destructor = _debug_destructor;
1886 }
1887
1888 GLhandleARB
1889 _mesa_3dlabs_create_shader_object (GLenum shaderType)
1890 {
1891 switch (shaderType)
1892 {
1893 case GL_FRAGMENT_SHADER_ARB:
1894 {
1895 struct gl2_fragment_shader_impl *x = (struct gl2_fragment_shader_impl *)
1896 _mesa_malloc (sizeof (struct gl2_fragment_shader_impl));
1897
1898 if (x != NULL)
1899 {
1900 _fragment_shader_constructor (x);
1901 return x->_obj._shader._generic.name;
1902 }
1903 }
1904 break;
1905 case GL_VERTEX_SHADER_ARB:
1906 {
1907 struct gl2_vertex_shader_impl *x = (struct gl2_vertex_shader_impl *)
1908 _mesa_malloc (sizeof (struct gl2_vertex_shader_impl));
1909
1910 if (x != NULL)
1911 {
1912 _vertex_shader_constructor (x);
1913 return x->_obj._shader._generic.name;
1914 }
1915 }
1916 break;
1917 }
1918
1919 return 0;
1920 }
1921
1922 GLhandleARB
1923 _mesa_3dlabs_create_program_object (void)
1924 {
1925 struct gl2_program_impl *x = (struct gl2_program_impl *)
1926 _mesa_malloc (sizeof (struct gl2_program_impl));
1927
1928 if (x != NULL)
1929 {
1930 _program_constructor (x);
1931 return x->_obj._container._generic.name;
1932 }
1933
1934 return 0;
1935 }
1936
1937 GLhandleARB
1938 _mesa_3dlabs_create_debug_object (GLvoid)
1939 {
1940 struct gl2_debug_impl *obj;
1941
1942 obj = (struct gl2_debug_impl *) (_mesa_malloc (sizeof (struct gl2_debug_impl)));
1943 if (obj != NULL) {
1944 _debug_constructor (obj);
1945 return obj->_obj._generic.name;
1946 }
1947 return 0;
1948 }
1949
1950 #include "slang_assemble.h"
1951 #include "slang_execute.h"
1952
1953 int _slang_fetch_discard (struct gl2_program_intf **pro, GLboolean *val)
1954 {
1955 struct gl2_program_impl *impl;
1956
1957 impl = (struct gl2_program_impl *) pro;
1958 *val = impl->_obj.prog.machines[SLANG_SHADER_FRAGMENT]->kill ? GL_TRUE : GL_FALSE;
1959 return 1;
1960 }
1961
1962 static GLvoid exec_shader (struct gl2_program_intf **pro, GLuint i)
1963 {
1964 struct gl2_program_impl *impl;
1965 slang_program *p;
1966
1967 impl = (struct gl2_program_impl *) pro;
1968 p = &impl->_obj.prog;
1969
1970 slang_machine_init (p->machines[i]);
1971 p->machines[i]->ip = p->code[i][SLANG_COMMON_CODE_MAIN];
1972
1973 _slang_execute2 (p->assemblies[i], p->machines[i]);
1974 }
1975
1976 GLvoid _slang_exec_fragment_shader (struct gl2_program_intf **pro)
1977 {
1978 exec_shader (pro, SLANG_SHADER_FRAGMENT);
1979 }
1980
1981 GLvoid _slang_exec_vertex_shader (struct gl2_program_intf **pro)
1982 {
1983 exec_shader (pro, SLANG_SHADER_VERTEX);
1984 }
1985
1986 #endif
1987
1988 void
1989 _mesa_init_shaderobjects_3dlabs (GLcontext *ctx)
1990 {
1991 #if USE_3DLABS_FRONTEND
1992 _glslang_3dlabs_InitProcess ();
1993 _glslang_3dlabs_ShInitialize ();
1994 #endif
1995 }
1996