2 * Mesa 3-D graphics library
5 * Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
26 * \file shaderobjects_3dlabs.c
27 * shader objects definitions for 3dlabs compiler
31 /* Set this to 1 when we are ready to use 3dlabs' front-end */
32 #define USE_3DLABS_FRONTEND 0
36 #include "shaderobjects.h"
37 #include "shaderobjects_3dlabs.h"
39 #if USE_3DLABS_FRONTEND
40 #include "slang_mesa.h"
41 #include "Public/ShaderLang.h"
43 #include "slang_link.h"
46 struct gl2_unknown_obj
48 GLuint reference_count
;
49 void (* _destructor
) (struct gl2_unknown_intf
**);
52 struct gl2_unknown_impl
54 struct gl2_unknown_intf
*_vftbl
;
55 struct gl2_unknown_obj _obj
;
59 _unknown_destructor (struct gl2_unknown_intf
**intf
)
64 _unknown_AddRef (struct gl2_unknown_intf
**intf
)
66 struct gl2_unknown_impl
*impl
= (struct gl2_unknown_impl
*) intf
;
68 impl
->_obj
.reference_count
++;
72 _unknown_Release (struct gl2_unknown_intf
**intf
)
74 struct gl2_unknown_impl
*impl
= (struct gl2_unknown_impl
*) intf
;
76 impl
->_obj
.reference_count
--;
77 if (impl
->_obj
.reference_count
== 0)
79 impl
->_obj
._destructor (intf
);
80 _mesa_free ((void *) intf
);
84 static struct gl2_unknown_intf
**
85 _unknown_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
87 if (uiid
== UIID_UNKNOWN
)
89 (**intf
).AddRef (intf
);
95 static struct gl2_unknown_intf _unknown_vftbl
= {
98 _unknown_QueryInterface
102 _unknown_constructor (struct gl2_unknown_impl
*impl
)
104 impl
->_vftbl
= &_unknown_vftbl
;
105 impl
->_obj
.reference_count
= 1;
106 impl
->_obj
._destructor
= _unknown_destructor
;
109 struct gl2_unkinner_obj
111 struct gl2_unknown_intf
**unkouter
;
114 struct gl2_unkinner_impl
116 struct gl2_unknown_intf
*_vftbl
;
117 struct gl2_unkinner_obj _obj
;
121 _unkinner_destructor (struct gl2_unknown_intf
**intf
)
126 _unkinner_AddRef (struct gl2_unknown_intf
**intf
)
128 struct gl2_unkinner_impl
*impl
= (struct gl2_unkinner_impl
*) intf
;
130 (**impl
->_obj
.unkouter
).AddRef (impl
->_obj
.unkouter
);
134 _unkinner_Release (struct gl2_unknown_intf
**intf
)
136 struct gl2_unkinner_impl
*impl
= (struct gl2_unkinner_impl
*) intf
;
138 (**impl
->_obj
.unkouter
).Release (impl
->_obj
.unkouter
);
141 static struct gl2_unknown_intf
**
142 _unkinner_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
144 struct gl2_unkinner_impl
*impl
= (struct gl2_unkinner_impl
*) intf
;
146 return (**impl
->_obj
.unkouter
).QueryInterface (impl
->_obj
.unkouter
, uiid
);
149 static struct gl2_unknown_intf _unkinner_vftbl
= {
152 _unkinner_QueryInterface
156 _unkinner_constructor (struct gl2_unkinner_impl
*impl
, struct gl2_unknown_intf
**outer
)
158 impl
->_vftbl
= &_unkinner_vftbl
;
159 impl
->_obj
.unkouter
= outer
;
162 struct gl2_generic_obj
164 struct gl2_unknown_obj _unknown
;
166 GLboolean delete_status
;
170 struct gl2_generic_impl
172 struct gl2_generic_intf
*_vftbl
;
173 struct gl2_generic_obj _obj
;
177 _generic_destructor (struct gl2_unknown_intf
**intf
)
179 GET_CURRENT_CONTEXT(ctx
);
180 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
182 _mesa_free ((void *) impl
->_obj
.info_log
);
184 _glthread_LOCK_MUTEX (ctx
->Shared
->Mutex
);
185 _mesa_HashRemove (ctx
->Shared
->GL2Objects
, impl
->_obj
.name
);
186 _glthread_UNLOCK_MUTEX (ctx
->Shared
->Mutex
);
188 _unknown_destructor (intf
);
191 static struct gl2_unknown_intf
**
192 _generic_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
194 if (uiid
== UIID_GENERIC
)
196 (**intf
).AddRef (intf
);
199 return _unknown_QueryInterface (intf
, uiid
);
203 _generic_Delete (struct gl2_generic_intf
**intf
)
205 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
207 if (impl
->_obj
.delete_status
== GL_FALSE
)
209 impl
->_obj
.delete_status
= GL_TRUE
;
210 (**intf
)._unknown
.Release ((struct gl2_unknown_intf
**) intf
);
215 _generic_GetName (struct gl2_generic_intf
**intf
)
217 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
219 return impl
->_obj
.name
;
223 _generic_GetDeleteStatus (struct gl2_generic_intf
**intf
)
225 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
227 return impl
->_obj
.delete_status
;
230 static const GLcharARB
*
231 _generic_GetInfoLog (struct gl2_generic_intf
**intf
)
233 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
235 return impl
->_obj
.info_log
;
238 static struct gl2_generic_intf _generic_vftbl
= {
242 _generic_QueryInterface
245 NULL
, /* abstract GetType */
247 _generic_GetDeleteStatus
,
252 _generic_constructor (struct gl2_generic_impl
*impl
)
254 GET_CURRENT_CONTEXT(ctx
);
256 _unknown_constructor ((struct gl2_unknown_impl
*) impl
);
257 impl
->_vftbl
= &_generic_vftbl
;
258 impl
->_obj
._unknown
._destructor
= _generic_destructor
;
259 impl
->_obj
.delete_status
= GL_FALSE
;
260 impl
->_obj
.info_log
= NULL
;
262 _glthread_LOCK_MUTEX (ctx
->Shared
->Mutex
);
263 impl
->_obj
.name
= _mesa_HashFindFreeKeyBlock (ctx
->Shared
->GL2Objects
, 1);
264 _mesa_HashInsert (ctx
->Shared
->GL2Objects
, impl
->_obj
.name
, (void *) impl
);
265 _glthread_UNLOCK_MUTEX (ctx
->Shared
->Mutex
);
268 struct gl2_container_obj
270 struct gl2_generic_obj _generic
;
271 struct gl2_generic_intf
***attached
;
272 GLuint attached_count
;
275 struct gl2_container_impl
277 struct gl2_container_intf
*_vftbl
;
278 struct gl2_container_obj _obj
;
282 _container_destructor (struct gl2_unknown_intf
**intf
)
284 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
287 for (i
= 0; i
< impl
->_obj
.attached_count
; i
++)
289 struct gl2_generic_intf
**x
= impl
->_obj
.attached
[i
];
290 (**x
)._unknown
.Release ((struct gl2_unknown_intf
**) x
);
293 _generic_destructor (intf
);
296 static struct gl2_unknown_intf
**
297 _container_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
299 if (uiid
== UIID_CONTAINER
)
301 (**intf
).AddRef (intf
);
304 return _generic_QueryInterface (intf
, uiid
);
308 _container_Attach (struct gl2_container_intf
**intf
, struct gl2_generic_intf
**att
)
310 GET_CURRENT_CONTEXT(ctx
);
311 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
314 for (i
= 0; i
< impl
->_obj
.attached_count
; i
++)
315 if (impl
->_obj
.attached
[i
] == att
)
317 _mesa_error (ctx
, GL_INVALID_OPERATION
, "_container_Attach");
321 impl
->_obj
.attached
= (struct gl2_generic_intf
***) _mesa_realloc (impl
->_obj
.attached
,
322 impl
->_obj
.attached_count
* sizeof (*impl
->_obj
.attached
), (impl
->_obj
.attached_count
+ 1) *
323 sizeof (*impl
->_obj
.attached
));
324 if (impl
->_obj
.attached
== NULL
)
327 impl
->_obj
.attached
[impl
->_obj
.attached_count
] = att
;
328 impl
->_obj
.attached_count
++;
329 (**att
)._unknown
.AddRef ((struct gl2_unknown_intf
**) att
);
334 _container_Detach (struct gl2_container_intf
**intf
, struct gl2_generic_intf
**att
)
336 GET_CURRENT_CONTEXT(ctx
);
337 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
340 for (i
= 0; i
< impl
->_obj
.attached_count
; i
++)
341 if (impl
->_obj
.attached
[i
] == att
)
343 for (j
= i
; j
< impl
->_obj
.attached_count
- 1; j
++)
344 impl
->_obj
.attached
[j
] = impl
->_obj
.attached
[j
+ 1];
345 impl
->_obj
.attached
= (struct gl2_generic_intf
***) _mesa_realloc (impl
->_obj
.attached
,
346 impl
->_obj
.attached_count
* sizeof (*impl
->_obj
.attached
),
347 (impl
->_obj
.attached_count
- 1) * sizeof (*impl
->_obj
.attached
));
348 impl
->_obj
.attached_count
--;
349 (**att
)._unknown
.Release ((struct gl2_unknown_intf
**) att
);
353 _mesa_error (ctx
, GL_INVALID_OPERATION
, "_container_Detach");
358 _container_GetAttachedCount (struct gl2_container_intf
**intf
)
360 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
362 return impl
->_obj
.attached_count
;
365 static struct gl2_generic_intf
**
366 _container_GetAttached (struct gl2_container_intf
**intf
, GLuint index
)
368 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
370 (**impl
->_obj
.attached
[index
])._unknown
.AddRef (
371 (struct gl2_unknown_intf
**)impl
->_obj
.attached
[index
]);
372 return impl
->_obj
.attached
[index
];
375 static struct gl2_container_intf _container_vftbl
= {
380 _container_QueryInterface
383 NULL
, /* abstract GetType */
385 _generic_GetDeleteStatus
,
390 _container_GetAttachedCount
,
391 _container_GetAttached
395 _container_constructor (struct gl2_container_impl
*impl
)
397 _generic_constructor ((struct gl2_generic_impl
*) impl
);
398 impl
->_vftbl
= &_container_vftbl
;
399 impl
->_obj
._generic
._unknown
._destructor
= _container_destructor
;
400 impl
->_obj
.attached
= NULL
;
401 impl
->_obj
.attached_count
= 0;
404 struct gl2_3dlabs_shhandle_obj
406 struct gl2_unkinner_obj _unknown
;
407 #if USE_3DLABS_FRONTEND
412 struct gl2_3dlabs_shhandle_impl
414 struct gl2_3dlabs_shhandle_intf
*_vftbl
;
415 struct gl2_3dlabs_shhandle_obj _obj
;
419 _3dlabs_shhandle_destructor (struct gl2_unknown_intf
**intf
)
421 #if USE_3DLABS_FRONTEND
422 struct gl2_3dlabs_shhandle_impl
*impl
= (struct gl2_3dlabs_shhandle_impl
*) intf
;
423 ShDestruct (impl
->_obj
.handle
);
425 _unkinner_destructor (intf
);
429 _3dlabs_shhandle_GetShHandle (struct gl2_3dlabs_shhandle_intf
**intf
)
431 #if USE_3DLABS_FRONTEND
432 struct gl2_3dlabs_shhandle_impl
*impl
= (struct gl2_3dlabs_shhandle_impl
*) intf
;
433 return impl
->_obj
.handle
;
439 static struct gl2_3dlabs_shhandle_intf _3dlabs_shhandle_vftbl
= {
443 _unkinner_QueryInterface
445 _3dlabs_shhandle_GetShHandle
449 _3dlabs_shhandle_constructor (struct gl2_3dlabs_shhandle_impl
*impl
, struct gl2_unknown_intf
**outer
)
451 _unkinner_constructor ((struct gl2_unkinner_impl
*) impl
, outer
);
452 impl
->_vftbl
= &_3dlabs_shhandle_vftbl
;
453 #if USE_3DLABS_FRONTEND
454 impl
->_obj
.handle
= NULL
;
458 struct gl2_shader_obj
460 struct gl2_generic_obj _generic
;
461 struct gl2_3dlabs_shhandle_impl _3dlabs_shhandle
;
462 GLboolean compile_status
;
465 GLsizei offset_count
;
466 slang_translation_unit unit
;
469 struct gl2_shader_impl
471 struct gl2_shader_intf
*_vftbl
;
472 struct gl2_shader_obj _obj
;
476 _shader_destructor (struct gl2_unknown_intf
**intf
)
478 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
480 _mesa_free ((void *) impl
->_obj
.source
);
481 _mesa_free ((void *) impl
->_obj
.offsets
);
482 _3dlabs_shhandle_destructor ((struct gl2_unknown_intf
**) &impl
->_obj
._3dlabs_shhandle
._vftbl
);
483 _generic_destructor (intf
);
486 static struct gl2_unknown_intf
**
487 _shader_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
489 #if USE_3DLABS_FRONTEND
490 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
493 if (uiid
== UIID_SHADER
)
495 (**intf
).AddRef (intf
);
498 #if USE_3DLABS_FRONTEND
499 if (uiid
== UIID_3DLABS_SHHANDLE
)
501 (**intf
).AddRef (intf
);
502 return (struct gl2_unknown_intf
**) &impl
->_obj
._3dlabs_shhandle
._vftbl
;
505 return _generic_QueryInterface (intf
, uiid
);
509 _shader_GetType (struct gl2_generic_intf
**intf
)
511 return GL_SHADER_OBJECT_ARB
;
515 _shader_GetCompileStatus (struct gl2_shader_intf
**intf
)
517 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
519 return impl
->_obj
.compile_status
;
523 _shader_SetSource (struct gl2_shader_intf
**intf
, GLcharARB
*src
, GLint
*off
, GLsizei cnt
)
525 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
527 _mesa_free ((void *) impl
->_obj
.source
);
528 impl
->_obj
.source
= src
;
529 _mesa_free ((void *) impl
->_obj
.offsets
);
530 impl
->_obj
.offsets
= off
;
531 impl
->_obj
.offset_count
= cnt
;
534 static const GLcharARB
*
535 _shader_GetSource (struct gl2_shader_intf
**intf
)
537 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
539 return impl
->_obj
.source
;
543 _shader_Compile (struct gl2_shader_intf
**intf
)
545 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
546 #if USE_3DLABS_FRONTEND
548 TBuiltInResource res
;
550 slang_unit_type type
;
551 slang_info_log info_log
;
554 impl
->_obj
.compile_status
= GL_FALSE
;
555 _mesa_free ((void *) impl
->_obj
._generic
.info_log
);
556 impl
->_obj
._generic
.info_log
= NULL
;
558 #if USE_3DLABS_FRONTEND
559 /* 3dlabs compiler expects us to feed it with null-terminated string array,
560 we've got only one big string with offsets, so we must split it; but when
561 there's only one string to deal with, we pass its address directly */
563 if (impl
->_obj
.offset_count
<= 1)
564 strings
= &impl
->_obj
.source
;
567 GLsizei i
, offset
= 0;
569 strings
= (char **) _mesa_malloc (impl
->_obj
.offset_count
* sizeof (char *));
573 for (i
= 0; i
< impl
->_obj
.offset_count
; i
++)
575 GLsizei size
= impl
->_obj
.offsets
[i
] - offset
;
577 strings
[i
] = (char *) _mesa_malloc ((size
+ 1) * sizeof (char));
578 if (strings
[i
] == NULL
)
582 for (j
= 0; j
< i
; j
++)
583 _mesa_free (strings
[j
]);
584 _mesa_free (strings
);
588 _mesa_memcpy (strings
[i
], impl
->_obj
.source
+ offset
, size
* sizeof (char));
589 strings
[i
][size
] = '\0';
590 offset
= impl
->_obj
.offsets
[i
];
594 /* TODO set these fields to some REAL numbers */
596 res
.maxClipPlanes
= 6;
597 res
.maxTextureUnits
= 2;
598 res
.maxTextureCoords
= 2;
599 res
.maxVertexAttribs
= 8;
600 res
.maxVertexUniformComponents
= 64;
601 res
.maxVaryingFloats
= 8;
602 res
.maxVertexTextureImageUnits
= 2;
603 res
.maxCombinedTextureImageUnits
= 2;
604 res
.maxTextureImageUnits
= 2;
605 res
.maxFragmentUniformComponents
= 64;
606 res
.maxDrawBuffers
= 1;
608 if (ShCompile (impl
->_obj
._3dlabs_shhandle
._obj
.handle
, strings
, impl
->_obj
.offset_count
,
609 EShOptFull
, &res
, 0))
610 impl
->_obj
.compile_status
= GL_TRUE
;
611 if (impl
->_obj
.offset_count
> 1)
615 for (i
= 0; i
< impl
->_obj
.offset_count
; i
++)
616 _mesa_free (strings
[i
]);
617 _mesa_free (strings
);
620 impl
->_obj
._generic
.info_log
= _mesa_strdup (ShGetInfoLog (
621 impl
->_obj
._3dlabs_shhandle
._obj
.handle
));
623 if (impl
->_vftbl
->GetSubType (intf
) == GL_FRAGMENT_SHADER
)
624 type
= slang_unit_fragment_shader
;
626 type
= slang_unit_vertex_shader
;
627 slang_info_log_construct (&info_log
);
628 if (_slang_compile (impl
->_obj
.source
, &impl
->_obj
.unit
, type
, &info_log
))
630 impl
->_obj
.compile_status
= GL_TRUE
;
632 if (info_log
.text
!= NULL
)
633 impl
->_obj
._generic
.info_log
= _mesa_strdup (info_log
.text
);
635 impl
->_obj
._generic
.info_log
= _mesa_strdup ("");
636 slang_info_log_destruct (&info_log
);
640 static struct gl2_shader_intf _shader_vftbl
= {
645 _shader_QueryInterface
650 _generic_GetDeleteStatus
,
653 NULL
, /* abstract GetSubType */
654 _shader_GetCompileStatus
,
661 _shader_constructor (struct gl2_shader_impl
*impl
)
663 _generic_constructor ((struct gl2_generic_impl
*) impl
);
664 _3dlabs_shhandle_constructor (&impl
->_obj
._3dlabs_shhandle
, (struct gl2_unknown_intf
**)
666 impl
->_vftbl
= &_shader_vftbl
;
667 impl
->_obj
._generic
._unknown
._destructor
= _shader_destructor
;
668 impl
->_obj
.compile_status
= GL_FALSE
;
669 impl
->_obj
.source
= NULL
;
670 impl
->_obj
.offsets
= NULL
;
671 impl
->_obj
.offset_count
= 0;
674 struct gl2_program_obj
676 struct gl2_container_obj _container
;
677 GLboolean link_status
;
678 GLboolean validate_status
;
679 #if USE_3DLABS_FRONTEND
686 struct gl2_program_impl
688 struct gl2_program_intf
*_vftbl
;
689 struct gl2_program_obj _obj
;
693 _program_destructor (struct gl2_unknown_intf
**intf
)
695 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
696 #if USE_3DLABS_FRONTEND
697 ShDestruct (impl
->_obj
.linker
);
698 ShDestruct (impl
->_obj
.uniforms
);
700 _container_destructor (intf
);
701 slang_program_dtr (&impl
->_obj
.prog
);
704 static struct gl2_unknown_intf
**
705 _program_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
707 if (uiid
== UIID_PROGRAM
)
709 (**intf
).AddRef (intf
);
712 return _container_QueryInterface (intf
, uiid
);
716 _program_GetType (struct gl2_generic_intf
**intf
)
718 return GL_PROGRAM_OBJECT_ARB
;
722 _program_Attach (struct gl2_container_intf
**intf
, struct gl2_generic_intf
**att
)
724 GET_CURRENT_CONTEXT(ctx
);
725 struct gl2_unknown_intf
**sha
;
727 sha
= (**att
)._unknown
.QueryInterface ((struct gl2_unknown_intf
**) att
, UIID_SHADER
);
730 _mesa_error (ctx
, GL_INVALID_OPERATION
, "_program_Attach");
734 (**sha
).Release (sha
);
735 return _container_Attach (intf
, att
);
739 _program_GetLinkStatus (struct gl2_program_intf
**intf
)
741 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
743 return impl
->_obj
.link_status
;
747 _program_GetValidateStatus (struct gl2_program_intf
**intf
)
749 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
751 return impl
->_obj
.validate_status
;
755 _program_Link (struct gl2_program_intf
**intf
)
757 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
758 #if USE_3DLABS_FRONTEND
762 slang_translation_unit
*units
[2];
764 impl
->_obj
.link_status
= GL_FALSE
;
765 _mesa_free ((void *) impl
->_obj
._container
._generic
.info_log
);
766 impl
->_obj
._container
._generic
.info_log
= NULL
;
767 slang_program_dtr (&impl
->_obj
.prog
);
768 slang_program_ctr (&impl
->_obj
.prog
);
770 #if USE_3DLABS_FRONTEND
771 handles
= (ShHandle
*) _mesa_malloc (impl
->_obj
._container
.attached_count
* sizeof (ShHandle
));
775 for (i
= 0; i
< impl
->_obj
._container
.attached_count
; i
++)
777 struct gl2_generic_intf
**gen
= impl
->_obj
._container
.attached
[i
];
778 struct gl2_3dlabs_shhandle_intf
**sh
;
780 sh
= (struct gl2_3dlabs_shhandle_intf
**) (**gen
)._unknown
.QueryInterface (
781 (struct gl2_unknown_intf
**) gen
, UIID_3DLABS_SHHANDLE
);
784 handles
[i
] = (**sh
).GetShHandle (sh
);
785 (**sh
)._unknown
.Release ((struct gl2_unknown_intf
**) sh
);
789 _mesa_free (handles
);
794 if (ShLink (impl
->_obj
.linker
, handles
, impl
->_obj
._container
.attached_count
,
795 impl
->_obj
.uniforms
, NULL
, NULL
))
796 impl
->_obj
.link_status
= GL_TRUE
;
798 impl
->_obj
._container
._generic
.info_log
= _mesa_strdup (ShGetInfoLog (impl
->_obj
.linker
));
800 count
= impl
->_obj
._container
.attached_count
;
801 if (count
== 0 || count
> 2)
803 for (i
= 0; i
< count
; i
++)
805 struct gl2_generic_intf
**obj
;
806 struct gl2_unknown_intf
**unk
;
807 struct gl2_shader_impl
*sha
;
809 obj
= impl
->_obj
._container
.attached
[i
];
810 unk
= (**obj
)._unknown
.QueryInterface ((struct gl2_unknown_intf
**) obj
, UIID_SHADER
);
811 (**obj
)._unknown
.Release ((struct gl2_unknown_intf
**) obj
);
814 sha
= (struct gl2_shader_impl
*) unk
;
815 units
[i
] = &sha
->_obj
.unit
;
816 (**unk
).Release (unk
);
819 impl
->_obj
.link_status
= _slang_link (&impl
->_obj
.prog
, units
, count
);
820 if (impl
->_obj
.link_status
)
821 impl
->_obj
._container
._generic
.info_log
= _mesa_strdup ("Link OK.\n");
823 impl
->_obj
._container
._generic
.info_log
= _mesa_strdup ("Link failed.\n");
828 _program_Validate (struct gl2_program_intf
**intf
)
830 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
832 impl
->_obj
.validate_status
= GL_FALSE
;
833 _mesa_free ((void *) impl
->_obj
._container
._generic
.info_log
);
834 impl
->_obj
._container
._generic
.info_log
= NULL
;
840 write_common_fixed (slang_program
*pro
, GLuint index
, const GLvoid
*src
, GLuint off
, GLuint size
)
844 for (i
= 0; i
< SLANG_UNIFORM_BINDING_MAX
; i
++)
848 addr
= pro
->common_fixed_entries
[i
][index
];
853 dst
= (GLubyte
*) pro
->machines
[i
]->mem
+ addr
+ off
* size
;
854 _mesa_memcpy (dst
, src
, size
);
860 write_common_fixed_mat4 (slang_program
*pro
, GLmatrix
*matrix
, GLuint off
, GLuint i
, GLuint ii
,
861 GLuint it
, GLuint iit
)
865 /* we want inverse matrix */
868 /* allocate inverse matrix and make it dirty */
869 _math_matrix_alloc_inv (matrix
);
870 _math_matrix_loadf (matrix
, matrix
->m
);
872 _math_matrix_analyse (matrix
);
874 write_common_fixed (pro
, i
, matrix
->m
, off
, 16 * sizeof (GLfloat
));
877 write_common_fixed (pro
, ii
, matrix
->inv
, off
, 16 * sizeof (GLfloat
));
880 _math_transposef (mat
, matrix
->m
);
881 write_common_fixed (pro
, it
, mat
, off
, 16 * sizeof (GLfloat
));
883 /* inverse transpose */
884 _math_transposef (mat
, matrix
->inv
);
885 write_common_fixed (pro
, iit
, mat
, off
, 16 * sizeof (GLfloat
));
889 _program_UpdateFixedUniforms (struct gl2_program_intf
**intf
)
891 GET_CURRENT_CONTEXT(ctx
);
892 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
893 slang_program
*pro
= &impl
->_obj
.prog
;
898 /* MODELVIEW matrix */
899 write_common_fixed_mat4 (pro
, ctx
->ModelviewMatrixStack
.Top
, 0,
900 SLANG_COMMON_FIXED_MODELVIEWMATRIX
,
901 SLANG_COMMON_FIXED_MODELVIEWMATRIXINVERSE
,
902 SLANG_COMMON_FIXED_MODELVIEWMATRIXTRANSPOSE
,
903 SLANG_COMMON_FIXED_MODELVIEWMATRIXINVERSETRANSPOSE
);
905 /* PROJECTION matrix */
906 write_common_fixed_mat4 (pro
, ctx
->ProjectionMatrixStack
.Top
, 0,
907 SLANG_COMMON_FIXED_PROJECTIONMATRIX
,
908 SLANG_COMMON_FIXED_PROJECTIONMATRIXINVERSE
,
909 SLANG_COMMON_FIXED_PROJECTIONMATRIXTRANSPOSE
,
910 SLANG_COMMON_FIXED_PROJECTIONMATRIXINVERSETRANSPOSE
);
913 write_common_fixed_mat4 (pro
, &ctx
->_ModelProjectMatrix
, 0,
914 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIX
,
915 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIXINVERSE
,
916 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIXTRANSPOSE
,
917 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIXINVERSETRANSPOSE
);
920 for (i
= 0; i
< 8; i
++)
922 write_common_fixed_mat4 (pro
, ctx
->TextureMatrixStack
[i
].Top
, i
,
923 SLANG_COMMON_FIXED_TEXTUREMATRIX
,
924 SLANG_COMMON_FIXED_TEXTUREMATRIXINVERSE
,
925 SLANG_COMMON_FIXED_TEXTUREMATRIXTRANSPOSE
,
926 SLANG_COMMON_FIXED_TEXTUREMATRIXINVERSETRANSPOSE
);
929 /* NORMAL matrix - upper 3x3 inverse transpose of MODELVIEW matrix */
930 p
= ctx
->ModelviewMatrixStack
.Top
->inv
;
940 write_common_fixed (pro
, SLANG_COMMON_FIXED_NORMALMATRIX
, v
, 0, 9 * sizeof (GLfloat
));
942 /* XXX: fetch uniform float gl_NormalScale */
943 /* XXX: fetch uniform mat4 gl_ClipPlane */
944 /* XXX: fetch uniform mat4 gl_TextureEnvColor */
945 /* XXX: fetch uniform mat4 gl_EyePlaneS */
946 /* XXX: fetch uniform mat4 gl_EyePlaneT */
947 /* XXX: fetch uniform mat4 gl_EyePlaneR */
948 /* XXX: fetch uniform mat4 gl_EyePlaneQ */
949 /* XXX: fetch uniform mat4 gl_ObjectPlaneS */
950 /* XXX: fetch uniform mat4 gl_ObjectPlaneT */
951 /* XXX: fetch uniform mat4 gl_ObjectPlaneR */
952 /* XXX: fetch uniform mat4 gl_ObjectPlaneQ */
956 _program_UpdateFixedAttribute (struct gl2_program_intf
**intf
, GLuint index
, GLvoid
*data
,
957 GLuint offset
, GLuint size
, GLboolean write
)
959 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
960 slang_program
*pro
= &impl
->_obj
.prog
;
963 addr
= pro
->vertex_fixed_entries
[index
];
968 mem
= (GLubyte
*) pro
->machines
[SLANG_UNIFORM_BINDING_VERTEX
]->mem
+ addr
+ offset
* size
;
970 _mesa_memcpy (mem
, data
, size
);
972 _mesa_memcpy (data
, mem
, size
);
977 _program_UpdateFixedVarying (struct gl2_program_intf
**intf
, GLuint index
, GLvoid
*data
,
978 GLuint offset
, GLuint size
, GLboolean write
)
980 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
981 slang_program
*pro
= &impl
->_obj
.prog
;
984 addr
= pro
->fragment_fixed_entries
[index
];
989 mem
= (GLubyte
*) pro
->machines
[SLANG_UNIFORM_BINDING_FRAGMENT
]->mem
+ addr
+ offset
* size
;
991 _mesa_memcpy (mem
, data
, size
);
993 _mesa_memcpy (data
, mem
, size
);
997 static struct gl2_program_intf _program_vftbl
= {
1003 _program_QueryInterface
1008 _generic_GetDeleteStatus
,
1013 _container_GetAttachedCount
,
1014 _container_GetAttached
1016 _program_GetLinkStatus
,
1017 _program_GetValidateStatus
,
1020 _program_UpdateFixedUniforms
,
1021 _program_UpdateFixedAttribute
,
1022 _program_UpdateFixedVarying
1026 _program_constructor (struct gl2_program_impl
*impl
)
1028 _container_constructor ((struct gl2_container_impl
*) impl
);
1029 impl
->_vftbl
= &_program_vftbl
;
1030 impl
->_obj
._container
._generic
._unknown
._destructor
= _program_destructor
;
1031 impl
->_obj
.link_status
= GL_FALSE
;
1032 impl
->_obj
.validate_status
= GL_FALSE
;
1033 #if USE_3DLABS_FRONTEND
1034 impl
->_obj
.linker
= ShConstructLinker (EShExVertexFragment
, 0);
1035 impl
->_obj
.uniforms
= ShConstructUniformMap ();
1037 slang_program_ctr (&impl
->_obj
.prog
);
1040 struct gl2_fragment_shader_obj
1042 struct gl2_shader_obj _shader
;
1045 struct gl2_fragment_shader_impl
1047 struct gl2_fragment_shader_intf
*_vftbl
;
1048 struct gl2_fragment_shader_obj _obj
;
1052 _fragment_shader_destructor (struct gl2_unknown_intf
**intf
)
1054 struct gl2_fragment_shader_impl
*impl
= (struct gl2_fragment_shader_impl
*) intf
;
1057 /* TODO free fragment shader data */
1059 _shader_destructor (intf
);
1062 static struct gl2_unknown_intf
**
1063 _fragment_shader_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
1065 if (uiid
== UIID_FRAGMENT_SHADER
)
1067 (**intf
).AddRef (intf
);
1070 return _shader_QueryInterface (intf
, uiid
);
1074 _fragment_shader_GetSubType (struct gl2_shader_intf
**intf
)
1076 return GL_FRAGMENT_SHADER_ARB
;
1079 static struct gl2_fragment_shader_intf _fragment_shader_vftbl
= {
1085 _fragment_shader_QueryInterface
1090 _generic_GetDeleteStatus
,
1093 _fragment_shader_GetSubType
,
1094 _shader_GetCompileStatus
,
1102 _fragment_shader_constructor (struct gl2_fragment_shader_impl
*impl
)
1104 _shader_constructor ((struct gl2_shader_impl
*) impl
);
1105 impl
->_vftbl
= &_fragment_shader_vftbl
;
1106 impl
->_obj
._shader
._generic
._unknown
._destructor
= _fragment_shader_destructor
;
1107 #if USE_3DLABS_FRONTEND
1108 impl
->_obj
._shader
._3dlabs_shhandle
._obj
.handle
= ShConstructCompiler (EShLangFragment
, 0);
1112 struct gl2_vertex_shader_obj
1114 struct gl2_shader_obj _shader
;
1117 struct gl2_vertex_shader_impl
1119 struct gl2_vertex_shader_intf
*_vftbl
;
1120 struct gl2_vertex_shader_obj _obj
;
1124 _vertex_shader_destructor (struct gl2_unknown_intf
**intf
)
1126 struct gl2_vertex_shader_impl
*impl
= (struct gl2_vertex_shader_impl
*) intf
;
1129 /* TODO free vertex shader data */
1131 _shader_destructor (intf
);
1134 static struct gl2_unknown_intf
**
1135 _vertex_shader_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
1137 if (uiid
== UIID_VERTEX_SHADER
)
1139 (**intf
).AddRef (intf
);
1142 return _shader_QueryInterface (intf
, uiid
);
1146 _vertex_shader_GetSubType (struct gl2_shader_intf
**intf
)
1148 return GL_VERTEX_SHADER_ARB
;
1151 static struct gl2_vertex_shader_intf _vertex_shader_vftbl
= {
1157 _vertex_shader_QueryInterface
1162 _generic_GetDeleteStatus
,
1165 _vertex_shader_GetSubType
,
1166 _shader_GetCompileStatus
,
1174 _vertex_shader_constructor (struct gl2_vertex_shader_impl
*impl
)
1176 _shader_constructor ((struct gl2_shader_impl
*) impl
);
1177 impl
->_vftbl
= &_vertex_shader_vftbl
;
1178 impl
->_obj
._shader
._generic
._unknown
._destructor
= _vertex_shader_destructor
;
1179 #if USE_3DLABS_FRONTEND
1180 impl
->_obj
._shader
._3dlabs_shhandle
._obj
.handle
= ShConstructCompiler (EShLangVertex
, 0);
1185 _mesa_3dlabs_create_shader_object (GLenum shaderType
)
1189 case GL_FRAGMENT_SHADER_ARB
:
1191 struct gl2_fragment_shader_impl
*x
= (struct gl2_fragment_shader_impl
*)
1192 _mesa_malloc (sizeof (struct gl2_fragment_shader_impl
));
1196 _fragment_shader_constructor (x
);
1197 return x
->_obj
._shader
._generic
.name
;
1201 case GL_VERTEX_SHADER_ARB
:
1203 struct gl2_vertex_shader_impl
*x
= (struct gl2_vertex_shader_impl
*)
1204 _mesa_malloc (sizeof (struct gl2_vertex_shader_impl
));
1208 _vertex_shader_constructor (x
);
1209 return x
->_obj
._shader
._generic
.name
;
1219 _mesa_3dlabs_create_program_object (void)
1221 struct gl2_program_impl
*x
= (struct gl2_program_impl
*)
1222 _mesa_malloc (sizeof (struct gl2_program_impl
));
1226 _program_constructor (x
);
1227 return x
->_obj
._container
._generic
.name
;
1233 #include "slang_assemble.h"
1234 #include "slang_execute.h"
1236 int _slang_fetch_discard (struct gl2_program_intf
**pro
, GLboolean
*val
)
1238 struct gl2_program_impl
*impl
;
1240 impl
= (struct gl2_program_impl
*) pro
;
1241 *val
= impl
->_obj
.prog
.machines
[SLANG_UNIFORM_BINDING_FRAGMENT
]->kill
? GL_TRUE
: GL_FALSE
;
1245 static GLvoid
exec_shader (struct gl2_program_intf
**pro
, GLuint i
)
1247 struct gl2_program_impl
*impl
;
1250 impl
= (struct gl2_program_impl
*) pro
;
1251 p
= &impl
->_obj
.prog
;
1253 slang_machine_init (p
->machines
[i
]);
1254 p
->machines
[i
]->ip
= p
->code
[i
];
1256 _slang_execute2 (p
->assemblies
[i
], p
->machines
[i
]);
1259 GLvoid
_slang_exec_fragment_shader (struct gl2_program_intf
**pro
)
1261 exec_shader (pro
, SLANG_UNIFORM_BINDING_FRAGMENT
);
1264 GLvoid
_slang_exec_vertex_shader (struct gl2_program_intf
**pro
)
1266 exec_shader (pro
, SLANG_UNIFORM_BINDING_VERTEX
);
1269 GLint
_slang_get_uniform_location (struct gl2_program_intf
**pro
, const char *name
)
1271 struct gl2_program_impl
*impl
;
1272 slang_uniform_bindings
*bind
;
1275 impl
= (struct gl2_program_impl
*) pro
;
1276 bind
= &impl
->_obj
.prog
.uniforms
;
1277 for (i
= 0; i
< bind
->count
; i
++)
1278 if (_mesa_strcmp (bind
->table
[i
].name
, name
) == 0)
1283 GLboolean
_slang_write_uniform (struct gl2_program_intf
**pro
, GLint loc
, GLsizei count
,
1284 const GLvoid
*data
, GLenum type
)
1286 struct gl2_program_impl
*impl
;
1287 slang_uniform_bindings
*bind
;
1288 slang_uniform_binding
*b
;
1294 impl
= (struct gl2_program_impl
*) pro
;
1295 bind
= &impl
->_obj
.prog
.uniforms
;
1296 if (loc
>= bind
->count
)
1299 b
= &bind
->table
[loc
];
1300 /* TODO: check sizes */
1301 /* TODO: check if not structure */
1302 if (b
->quant
->u
.basic_type
!= type
)
1305 for (i
= 0; i
< SLANG_UNIFORM_BINDING_MAX
; i
++)
1306 if (b
->address
[i
] != ~0)
1308 _mesa_memcpy (&impl
->_obj
.prog
.machines
[i
]->mem
[b
->address
[i
] / 4], data
,
1309 count
* b
->quant
->size
);
1314 GLuint
_slang_get_active_uniform_count (struct gl2_program_intf
**pro
)
1316 struct gl2_program_impl
*impl
;
1318 impl
= (struct gl2_program_impl
*) pro
;
1319 return impl
->_obj
.prog
.active_uniforms
.count
;
1322 GLuint
_slang_get_active_uniform_max_length (struct gl2_program_intf
**pro
)
1324 struct gl2_program_impl
*impl
;
1327 impl
= (struct gl2_program_impl
*) pro
;
1328 for (i
= 0; i
< impl
->_obj
.prog
.active_uniforms
.count
; i
++)
1330 GLuint n
= _mesa_strlen (impl
->_obj
.prog
.active_uniforms
.table
[i
].name
);
1337 GLvoid
_slang_get_active_uniform (struct gl2_program_intf
**pro
, GLuint index
, GLsizei maxLength
,
1338 GLsizei
*length
, GLint
*size
, GLenum
*type
, char *name
)
1340 struct gl2_program_impl
*impl
;
1341 slang_active_uniform
*u
;
1344 impl
= (struct gl2_program_impl
*) pro
;
1345 u
= &impl
->_obj
.prog
.active_uniforms
.table
[index
];
1347 len
= _mesa_strlen (u
->name
);
1348 if (len
>= maxLength
)
1349 len
= maxLength
- 1;
1350 _mesa_memcpy (name
, u
->name
, len
);
1354 *type
= u
->quant
->u
.basic_type
;
1355 if (u
->quant
->array_len
== 0)
1358 *size
= u
->quant
->array_len
;
1362 _mesa_init_shaderobjects_3dlabs (GLcontext
*ctx
)
1364 #if USE_3DLABS_FRONTEND
1365 _glslang_3dlabs_InitProcess ();
1366 _glslang_3dlabs_ShInitialize ();