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
37 #include "shaderobjects.h"
38 #include "shaderobjects_3dlabs.h"
40 #if USE_3DLABS_FRONTEND
41 #include "slang_mesa.h"
42 #include "Public/ShaderLang.h"
44 #include "slang_link.h"
47 struct gl2_unknown_obj
49 GLuint reference_count
;
50 void (* _destructor
) (struct gl2_unknown_intf
**);
53 struct gl2_unknown_impl
55 struct gl2_unknown_intf
*_vftbl
;
56 struct gl2_unknown_obj _obj
;
60 _unknown_destructor (struct gl2_unknown_intf
**intf
)
65 _unknown_AddRef (struct gl2_unknown_intf
**intf
)
67 struct gl2_unknown_impl
*impl
= (struct gl2_unknown_impl
*) intf
;
69 impl
->_obj
.reference_count
++;
73 _unknown_Release (struct gl2_unknown_intf
**intf
)
75 struct gl2_unknown_impl
*impl
= (struct gl2_unknown_impl
*) intf
;
77 impl
->_obj
.reference_count
--;
78 if (impl
->_obj
.reference_count
== 0)
80 impl
->_obj
._destructor (intf
);
81 _mesa_free ((void *) intf
);
85 static struct gl2_unknown_intf
**
86 _unknown_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
88 if (uiid
== UIID_UNKNOWN
)
90 (**intf
).AddRef (intf
);
96 static struct gl2_unknown_intf _unknown_vftbl
= {
99 _unknown_QueryInterface
103 _unknown_constructor (struct gl2_unknown_impl
*impl
)
105 impl
->_vftbl
= &_unknown_vftbl
;
106 impl
->_obj
.reference_count
= 1;
107 impl
->_obj
._destructor
= _unknown_destructor
;
110 struct gl2_unkinner_obj
112 struct gl2_unknown_intf
**unkouter
;
115 struct gl2_unkinner_impl
117 struct gl2_unknown_intf
*_vftbl
;
118 struct gl2_unkinner_obj _obj
;
122 _unkinner_destructor (struct gl2_unknown_intf
**intf
)
127 _unkinner_AddRef (struct gl2_unknown_intf
**intf
)
129 struct gl2_unkinner_impl
*impl
= (struct gl2_unkinner_impl
*) intf
;
131 (**impl
->_obj
.unkouter
).AddRef (impl
->_obj
.unkouter
);
135 _unkinner_Release (struct gl2_unknown_intf
**intf
)
137 struct gl2_unkinner_impl
*impl
= (struct gl2_unkinner_impl
*) intf
;
139 (**impl
->_obj
.unkouter
).Release (impl
->_obj
.unkouter
);
142 static struct gl2_unknown_intf
**
143 _unkinner_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
145 struct gl2_unkinner_impl
*impl
= (struct gl2_unkinner_impl
*) intf
;
147 return (**impl
->_obj
.unkouter
).QueryInterface (impl
->_obj
.unkouter
, uiid
);
150 static struct gl2_unknown_intf _unkinner_vftbl
= {
153 _unkinner_QueryInterface
157 _unkinner_constructor (struct gl2_unkinner_impl
*impl
, struct gl2_unknown_intf
**outer
)
159 impl
->_vftbl
= &_unkinner_vftbl
;
160 impl
->_obj
.unkouter
= outer
;
163 struct gl2_generic_obj
165 struct gl2_unknown_obj _unknown
;
167 GLboolean delete_status
;
171 struct gl2_generic_impl
173 struct gl2_generic_intf
*_vftbl
;
174 struct gl2_generic_obj _obj
;
178 _generic_destructor (struct gl2_unknown_intf
**intf
)
180 GET_CURRENT_CONTEXT(ctx
);
181 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
183 _mesa_free ((void *) impl
->_obj
.info_log
);
185 _glthread_LOCK_MUTEX (ctx
->Shared
->Mutex
);
186 _mesa_HashRemove (ctx
->Shared
->GL2Objects
, impl
->_obj
.name
);
187 _glthread_UNLOCK_MUTEX (ctx
->Shared
->Mutex
);
189 _unknown_destructor (intf
);
192 static struct gl2_unknown_intf
**
193 _generic_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
195 if (uiid
== UIID_GENERIC
)
197 (**intf
).AddRef (intf
);
200 return _unknown_QueryInterface (intf
, uiid
);
204 _generic_Delete (struct gl2_generic_intf
**intf
)
206 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
208 if (impl
->_obj
.delete_status
== GL_FALSE
)
210 impl
->_obj
.delete_status
= GL_TRUE
;
211 (**intf
)._unknown
.Release ((struct gl2_unknown_intf
**) intf
);
216 _generic_GetName (struct gl2_generic_intf
**intf
)
218 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
220 return impl
->_obj
.name
;
224 _generic_GetDeleteStatus (struct gl2_generic_intf
**intf
)
226 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
228 return impl
->_obj
.delete_status
;
231 static const GLcharARB
*
232 _generic_GetInfoLog (struct gl2_generic_intf
**intf
)
234 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
236 return impl
->_obj
.info_log
;
239 static struct gl2_generic_intf _generic_vftbl
= {
243 _generic_QueryInterface
246 NULL
, /* abstract GetType */
248 _generic_GetDeleteStatus
,
253 _generic_constructor (struct gl2_generic_impl
*impl
)
255 GET_CURRENT_CONTEXT(ctx
);
257 _unknown_constructor ((struct gl2_unknown_impl
*) impl
);
258 impl
->_vftbl
= &_generic_vftbl
;
259 impl
->_obj
._unknown
._destructor
= _generic_destructor
;
260 impl
->_obj
.delete_status
= GL_FALSE
;
261 impl
->_obj
.info_log
= NULL
;
263 _glthread_LOCK_MUTEX (ctx
->Shared
->Mutex
);
264 impl
->_obj
.name
= _mesa_HashFindFreeKeyBlock (ctx
->Shared
->GL2Objects
, 1);
265 _mesa_HashInsert (ctx
->Shared
->GL2Objects
, impl
->_obj
.name
, (void *) impl
);
266 _glthread_UNLOCK_MUTEX (ctx
->Shared
->Mutex
);
269 struct gl2_container_obj
271 struct gl2_generic_obj _generic
;
272 struct gl2_generic_intf
***attached
;
273 GLuint attached_count
;
276 struct gl2_container_impl
278 struct gl2_container_intf
*_vftbl
;
279 struct gl2_container_obj _obj
;
283 _container_destructor (struct gl2_unknown_intf
**intf
)
285 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
288 for (i
= 0; i
< impl
->_obj
.attached_count
; i
++)
290 struct gl2_generic_intf
**x
= impl
->_obj
.attached
[i
];
291 (**x
)._unknown
.Release ((struct gl2_unknown_intf
**) x
);
294 _generic_destructor (intf
);
297 static struct gl2_unknown_intf
**
298 _container_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
300 if (uiid
== UIID_CONTAINER
)
302 (**intf
).AddRef (intf
);
305 return _generic_QueryInterface (intf
, uiid
);
309 _container_Attach (struct gl2_container_intf
**intf
, struct gl2_generic_intf
**att
)
311 GET_CURRENT_CONTEXT(ctx
);
312 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
315 for (i
= 0; i
< impl
->_obj
.attached_count
; i
++)
316 if (impl
->_obj
.attached
[i
] == att
)
318 _mesa_error (ctx
, GL_INVALID_OPERATION
, "_container_Attach");
322 impl
->_obj
.attached
= (struct gl2_generic_intf
***) _mesa_realloc (impl
->_obj
.attached
,
323 impl
->_obj
.attached_count
* sizeof (*impl
->_obj
.attached
), (impl
->_obj
.attached_count
+ 1) *
324 sizeof (*impl
->_obj
.attached
));
325 if (impl
->_obj
.attached
== NULL
)
328 impl
->_obj
.attached
[impl
->_obj
.attached_count
] = att
;
329 impl
->_obj
.attached_count
++;
330 (**att
)._unknown
.AddRef ((struct gl2_unknown_intf
**) att
);
335 _container_Detach (struct gl2_container_intf
**intf
, struct gl2_generic_intf
**att
)
337 GET_CURRENT_CONTEXT(ctx
);
338 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
341 for (i
= 0; i
< impl
->_obj
.attached_count
; i
++)
342 if (impl
->_obj
.attached
[i
] == att
)
344 for (j
= i
; j
< impl
->_obj
.attached_count
- 1; j
++)
345 impl
->_obj
.attached
[j
] = impl
->_obj
.attached
[j
+ 1];
346 impl
->_obj
.attached
= (struct gl2_generic_intf
***) _mesa_realloc (impl
->_obj
.attached
,
347 impl
->_obj
.attached_count
* sizeof (*impl
->_obj
.attached
),
348 (impl
->_obj
.attached_count
- 1) * sizeof (*impl
->_obj
.attached
));
349 impl
->_obj
.attached_count
--;
350 (**att
)._unknown
.Release ((struct gl2_unknown_intf
**) att
);
354 _mesa_error (ctx
, GL_INVALID_OPERATION
, "_container_Detach");
359 _container_GetAttachedCount (struct gl2_container_intf
**intf
)
361 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
363 return impl
->_obj
.attached_count
;
366 static struct gl2_generic_intf
**
367 _container_GetAttached (struct gl2_container_intf
**intf
, GLuint index
)
369 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
371 (**impl
->_obj
.attached
[index
])._unknown
.AddRef (
372 (struct gl2_unknown_intf
**)impl
->_obj
.attached
[index
]);
373 return impl
->_obj
.attached
[index
];
376 static struct gl2_container_intf _container_vftbl
= {
381 _container_QueryInterface
384 NULL
, /* abstract GetType */
386 _generic_GetDeleteStatus
,
391 _container_GetAttachedCount
,
392 _container_GetAttached
396 _container_constructor (struct gl2_container_impl
*impl
)
398 _generic_constructor ((struct gl2_generic_impl
*) impl
);
399 impl
->_vftbl
= &_container_vftbl
;
400 impl
->_obj
._generic
._unknown
._destructor
= _container_destructor
;
401 impl
->_obj
.attached
= NULL
;
402 impl
->_obj
.attached_count
= 0;
405 struct gl2_3dlabs_shhandle_obj
407 struct gl2_unkinner_obj _unknown
;
408 #if USE_3DLABS_FRONTEND
413 struct gl2_3dlabs_shhandle_impl
415 struct gl2_3dlabs_shhandle_intf
*_vftbl
;
416 struct gl2_3dlabs_shhandle_obj _obj
;
420 _3dlabs_shhandle_destructor (struct gl2_unknown_intf
**intf
)
422 #if USE_3DLABS_FRONTEND
423 struct gl2_3dlabs_shhandle_impl
*impl
= (struct gl2_3dlabs_shhandle_impl
*) intf
;
424 ShDestruct (impl
->_obj
.handle
);
426 _unkinner_destructor (intf
);
430 _3dlabs_shhandle_GetShHandle (struct gl2_3dlabs_shhandle_intf
**intf
)
432 #if USE_3DLABS_FRONTEND
433 struct gl2_3dlabs_shhandle_impl
*impl
= (struct gl2_3dlabs_shhandle_impl
*) intf
;
434 return impl
->_obj
.handle
;
440 static struct gl2_3dlabs_shhandle_intf _3dlabs_shhandle_vftbl
= {
444 _unkinner_QueryInterface
446 _3dlabs_shhandle_GetShHandle
450 _3dlabs_shhandle_constructor (struct gl2_3dlabs_shhandle_impl
*impl
, struct gl2_unknown_intf
**outer
)
452 _unkinner_constructor ((struct gl2_unkinner_impl
*) impl
, outer
);
453 impl
->_vftbl
= &_3dlabs_shhandle_vftbl
;
454 #if USE_3DLABS_FRONTEND
455 impl
->_obj
.handle
= NULL
;
459 struct gl2_shader_obj
461 struct gl2_generic_obj _generic
;
462 struct gl2_3dlabs_shhandle_impl _3dlabs_shhandle
;
463 GLboolean compile_status
;
466 GLsizei offset_count
;
467 slang_translation_unit unit
;
470 struct gl2_shader_impl
472 struct gl2_shader_intf
*_vftbl
;
473 struct gl2_shader_obj _obj
;
477 _shader_destructor (struct gl2_unknown_intf
**intf
)
479 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
481 _mesa_free ((void *) impl
->_obj
.source
);
482 _mesa_free ((void *) impl
->_obj
.offsets
);
483 _3dlabs_shhandle_destructor ((struct gl2_unknown_intf
**) &impl
->_obj
._3dlabs_shhandle
._vftbl
);
484 _generic_destructor (intf
);
487 static struct gl2_unknown_intf
**
488 _shader_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
490 #if USE_3DLABS_FRONTEND
491 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
494 if (uiid
== UIID_SHADER
)
496 (**intf
).AddRef (intf
);
499 #if USE_3DLABS_FRONTEND
500 if (uiid
== UIID_3DLABS_SHHANDLE
)
502 (**intf
).AddRef (intf
);
503 return (struct gl2_unknown_intf
**) &impl
->_obj
._3dlabs_shhandle
._vftbl
;
506 return _generic_QueryInterface (intf
, uiid
);
510 _shader_GetType (struct gl2_generic_intf
**intf
)
512 return GL_SHADER_OBJECT_ARB
;
516 _shader_GetCompileStatus (struct gl2_shader_intf
**intf
)
518 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
520 return impl
->_obj
.compile_status
;
524 _shader_SetSource (struct gl2_shader_intf
**intf
, GLcharARB
*src
, GLint
*off
, GLsizei cnt
)
526 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
528 _mesa_free ((void *) impl
->_obj
.source
);
529 impl
->_obj
.source
= src
;
530 _mesa_free ((void *) impl
->_obj
.offsets
);
531 impl
->_obj
.offsets
= off
;
532 impl
->_obj
.offset_count
= cnt
;
535 static const GLcharARB
*
536 _shader_GetSource (struct gl2_shader_intf
**intf
)
538 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
540 return impl
->_obj
.source
;
544 _shader_Compile (struct gl2_shader_intf
**intf
)
546 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
547 #if USE_3DLABS_FRONTEND
549 TBuiltInResource res
;
551 slang_unit_type type
;
552 slang_info_log info_log
;
555 impl
->_obj
.compile_status
= GL_FALSE
;
556 _mesa_free ((void *) impl
->_obj
._generic
.info_log
);
557 impl
->_obj
._generic
.info_log
= NULL
;
559 #if USE_3DLABS_FRONTEND
560 /* 3dlabs compiler expects us to feed it with null-terminated string array,
561 we've got only one big string with offsets, so we must split it; but when
562 there's only one string to deal with, we pass its address directly */
564 if (impl
->_obj
.offset_count
<= 1)
565 strings
= &impl
->_obj
.source
;
568 GLsizei i
, offset
= 0;
570 strings
= (char **) _mesa_malloc (impl
->_obj
.offset_count
* sizeof (char *));
574 for (i
= 0; i
< impl
->_obj
.offset_count
; i
++)
576 GLsizei size
= impl
->_obj
.offsets
[i
] - offset
;
578 strings
[i
] = (char *) _mesa_malloc ((size
+ 1) * sizeof (char));
579 if (strings
[i
] == NULL
)
583 for (j
= 0; j
< i
; j
++)
584 _mesa_free (strings
[j
]);
585 _mesa_free (strings
);
589 _mesa_memcpy (strings
[i
], impl
->_obj
.source
+ offset
, size
* sizeof (char));
590 strings
[i
][size
] = '\0';
591 offset
= impl
->_obj
.offsets
[i
];
595 /* TODO set these fields to some REAL numbers */
597 res
.maxClipPlanes
= 6;
598 res
.maxTextureUnits
= 2;
599 res
.maxTextureCoords
= 2;
600 res
.maxVertexAttribs
= 8;
601 res
.maxVertexUniformComponents
= 64;
602 res
.maxVaryingFloats
= 8;
603 res
.maxVertexTextureImageUnits
= 2;
604 res
.maxCombinedTextureImageUnits
= 2;
605 res
.maxTextureImageUnits
= 2;
606 res
.maxFragmentUniformComponents
= 64;
607 res
.maxDrawBuffers
= 1;
609 if (ShCompile (impl
->_obj
._3dlabs_shhandle
._obj
.handle
, strings
, impl
->_obj
.offset_count
,
610 EShOptFull
, &res
, 0))
611 impl
->_obj
.compile_status
= GL_TRUE
;
612 if (impl
->_obj
.offset_count
> 1)
616 for (i
= 0; i
< impl
->_obj
.offset_count
; i
++)
617 _mesa_free (strings
[i
]);
618 _mesa_free (strings
);
621 impl
->_obj
._generic
.info_log
= _mesa_strdup (ShGetInfoLog (
622 impl
->_obj
._3dlabs_shhandle
._obj
.handle
));
624 if (impl
->_vftbl
->GetSubType (intf
) == GL_FRAGMENT_SHADER
)
625 type
= slang_unit_fragment_shader
;
627 type
= slang_unit_vertex_shader
;
628 slang_info_log_construct (&info_log
);
629 if (_slang_compile (impl
->_obj
.source
, &impl
->_obj
.unit
, type
, &info_log
))
631 impl
->_obj
.compile_status
= GL_TRUE
;
633 if (info_log
.text
!= NULL
)
634 impl
->_obj
._generic
.info_log
= _mesa_strdup (info_log
.text
);
636 impl
->_obj
._generic
.info_log
= _mesa_strdup ("");
637 slang_info_log_destruct (&info_log
);
641 static struct gl2_shader_intf _shader_vftbl
= {
646 _shader_QueryInterface
651 _generic_GetDeleteStatus
,
654 NULL
, /* abstract GetSubType */
655 _shader_GetCompileStatus
,
662 _shader_constructor (struct gl2_shader_impl
*impl
)
664 _generic_constructor ((struct gl2_generic_impl
*) impl
);
665 _3dlabs_shhandle_constructor (&impl
->_obj
._3dlabs_shhandle
, (struct gl2_unknown_intf
**)
667 impl
->_vftbl
= &_shader_vftbl
;
668 impl
->_obj
._generic
._unknown
._destructor
= _shader_destructor
;
669 impl
->_obj
.compile_status
= GL_FALSE
;
670 impl
->_obj
.source
= NULL
;
671 impl
->_obj
.offsets
= NULL
;
672 impl
->_obj
.offset_count
= 0;
675 struct gl2_program_obj
677 struct gl2_container_obj _container
;
678 GLboolean link_status
;
679 GLboolean validate_status
;
680 #if USE_3DLABS_FRONTEND
687 struct gl2_program_impl
689 struct gl2_program_intf
*_vftbl
;
690 struct gl2_program_obj _obj
;
694 _program_destructor (struct gl2_unknown_intf
**intf
)
696 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
697 #if USE_3DLABS_FRONTEND
698 ShDestruct (impl
->_obj
.linker
);
699 ShDestruct (impl
->_obj
.uniforms
);
701 _container_destructor (intf
);
702 slang_program_dtr (&impl
->_obj
.prog
);
705 static struct gl2_unknown_intf
**
706 _program_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
708 if (uiid
== UIID_PROGRAM
)
710 (**intf
).AddRef (intf
);
713 return _container_QueryInterface (intf
, uiid
);
717 _program_GetType (struct gl2_generic_intf
**intf
)
719 return GL_PROGRAM_OBJECT_ARB
;
723 _program_Attach (struct gl2_container_intf
**intf
, struct gl2_generic_intf
**att
)
725 GET_CURRENT_CONTEXT(ctx
);
726 struct gl2_unknown_intf
**sha
;
728 sha
= (**att
)._unknown
.QueryInterface ((struct gl2_unknown_intf
**) att
, UIID_SHADER
);
731 _mesa_error (ctx
, GL_INVALID_OPERATION
, "_program_Attach");
735 (**sha
).Release (sha
);
736 return _container_Attach (intf
, att
);
740 _program_GetLinkStatus (struct gl2_program_intf
**intf
)
742 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
744 return impl
->_obj
.link_status
;
748 _program_GetValidateStatus (struct gl2_program_intf
**intf
)
750 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
752 return impl
->_obj
.validate_status
;
756 _program_Link (struct gl2_program_intf
**intf
)
758 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
759 #if USE_3DLABS_FRONTEND
763 slang_translation_unit
*units
[2];
765 impl
->_obj
.link_status
= GL_FALSE
;
766 _mesa_free ((void *) impl
->_obj
._container
._generic
.info_log
);
767 impl
->_obj
._container
._generic
.info_log
= NULL
;
768 slang_program_dtr (&impl
->_obj
.prog
);
769 slang_program_ctr (&impl
->_obj
.prog
);
771 #if USE_3DLABS_FRONTEND
772 handles
= (ShHandle
*) _mesa_malloc (impl
->_obj
._container
.attached_count
* sizeof (ShHandle
));
776 for (i
= 0; i
< impl
->_obj
._container
.attached_count
; i
++)
778 struct gl2_generic_intf
**gen
= impl
->_obj
._container
.attached
[i
];
779 struct gl2_3dlabs_shhandle_intf
**sh
;
781 sh
= (struct gl2_3dlabs_shhandle_intf
**) (**gen
)._unknown
.QueryInterface (
782 (struct gl2_unknown_intf
**) gen
, UIID_3DLABS_SHHANDLE
);
785 handles
[i
] = (**sh
).GetShHandle (sh
);
786 (**sh
)._unknown
.Release ((struct gl2_unknown_intf
**) sh
);
790 _mesa_free (handles
);
795 if (ShLink (impl
->_obj
.linker
, handles
, impl
->_obj
._container
.attached_count
,
796 impl
->_obj
.uniforms
, NULL
, NULL
))
797 impl
->_obj
.link_status
= GL_TRUE
;
799 impl
->_obj
._container
._generic
.info_log
= _mesa_strdup (ShGetInfoLog (impl
->_obj
.linker
));
801 count
= impl
->_obj
._container
.attached_count
;
802 if (count
== 0 || count
> 2)
804 for (i
= 0; i
< count
; i
++)
806 struct gl2_generic_intf
**obj
;
807 struct gl2_unknown_intf
**unk
;
808 struct gl2_shader_impl
*sha
;
810 obj
= impl
->_obj
._container
.attached
[i
];
811 unk
= (**obj
)._unknown
.QueryInterface ((struct gl2_unknown_intf
**) obj
, UIID_SHADER
);
812 (**obj
)._unknown
.Release ((struct gl2_unknown_intf
**) obj
);
815 sha
= (struct gl2_shader_impl
*) unk
;
816 units
[i
] = &sha
->_obj
.unit
;
817 (**unk
).Release (unk
);
820 impl
->_obj
.link_status
= _slang_link (&impl
->_obj
.prog
, units
, count
);
821 if (impl
->_obj
.link_status
)
822 impl
->_obj
._container
._generic
.info_log
= _mesa_strdup ("Link OK.\n");
824 impl
->_obj
._container
._generic
.info_log
= _mesa_strdup ("Link failed.\n");
829 _program_Validate (struct gl2_program_intf
**intf
)
831 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
833 impl
->_obj
.validate_status
= GL_FALSE
;
834 _mesa_free ((void *) impl
->_obj
._container
._generic
.info_log
);
835 impl
->_obj
._container
._generic
.info_log
= NULL
;
841 write_common_fixed (slang_program
*pro
, GLuint index
, const GLvoid
*src
, GLuint off
, GLuint size
)
845 for (i
= 0; i
< SLANG_SHADER_MAX
; i
++)
849 addr
= pro
->common_fixed_entries
[i
][index
];
854 dst
= (GLubyte
*) pro
->machines
[i
]->mem
+ addr
+ off
* size
;
855 _mesa_memcpy (dst
, src
, size
);
861 write_common_fixed_mat4 (slang_program
*pro
, GLmatrix
*matrix
, GLuint off
, GLuint i
, GLuint ii
,
862 GLuint it
, GLuint iit
)
866 /* we want inverse matrix */
869 /* allocate inverse matrix and make it dirty */
870 _math_matrix_alloc_inv (matrix
);
871 _math_matrix_loadf (matrix
, matrix
->m
);
873 _math_matrix_analyse (matrix
);
875 write_common_fixed (pro
, i
, matrix
->m
, off
, 16 * sizeof (GLfloat
));
878 write_common_fixed (pro
, ii
, matrix
->inv
, off
, 16 * sizeof (GLfloat
));
881 _math_transposef (mat
, matrix
->m
);
882 write_common_fixed (pro
, it
, mat
, off
, 16 * sizeof (GLfloat
));
884 /* inverse transpose */
885 _math_transposef (mat
, matrix
->inv
);
886 write_common_fixed (pro
, iit
, mat
, off
, 16 * sizeof (GLfloat
));
890 write_common_fixed_material (GLcontext
*ctx
, slang_program
*pro
, GLuint i
, GLuint e
, GLuint a
,
891 GLuint d
, GLuint sp
, GLuint sh
)
895 COPY_4FV(v
, ctx
->Light
.Material
.Attrib
[e
]);
896 COPY_4FV((v
+ 4), ctx
->Light
.Material
.Attrib
[a
]);
897 COPY_4FV((v
+ 8), ctx
->Light
.Material
.Attrib
[d
]);
898 COPY_4FV((v
+ 12), ctx
->Light
.Material
.Attrib
[sp
]);
899 v
[16] = ctx
->Light
.Material
.Attrib
[sh
][0];
900 write_common_fixed (pro
, i
, v
, 0, 17 * sizeof (GLfloat
));
904 write_common_fixed_light_model_product (GLcontext
*ctx
, slang_program
*pro
, GLuint i
, GLuint e
,
909 SCALE_4V(v
, ctx
->Light
.Material
.Attrib
[a
], ctx
->Light
.Model
.Ambient
);
910 ACC_4V(v
, ctx
->Light
.Material
.Attrib
[e
]);
911 write_common_fixed (pro
, i
, v
, 0, 4 * sizeof (GLfloat
));
915 write_common_fixed_light_product (GLcontext
*ctx
, slang_program
*pro
, GLuint off
, GLuint i
, GLuint a
,
920 SCALE_4V(v
, ctx
->Light
.Light
[off
].Ambient
, ctx
->Light
.Material
.Attrib
[a
]);
921 SCALE_4V((v
+ 4), ctx
->Light
.Light
[off
].Diffuse
, ctx
->Light
.Material
.Attrib
[d
]);
922 SCALE_4V((v
+ 8), ctx
->Light
.Light
[off
].Specular
, ctx
->Light
.Material
.Attrib
[s
]);
923 write_common_fixed (pro
, i
, v
, off
, 12 * sizeof (GLfloat
));
927 _program_UpdateFixedUniforms (struct gl2_program_intf
**intf
)
929 GET_CURRENT_CONTEXT(ctx
);
930 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
931 slang_program
*pro
= &impl
->_obj
.prog
;
936 /* MODELVIEW matrix */
937 write_common_fixed_mat4 (pro
, ctx
->ModelviewMatrixStack
.Top
, 0,
938 SLANG_COMMON_FIXED_MODELVIEWMATRIX
,
939 SLANG_COMMON_FIXED_MODELVIEWMATRIXINVERSE
,
940 SLANG_COMMON_FIXED_MODELVIEWMATRIXTRANSPOSE
,
941 SLANG_COMMON_FIXED_MODELVIEWMATRIXINVERSETRANSPOSE
);
943 /* PROJECTION matrix */
944 write_common_fixed_mat4 (pro
, ctx
->ProjectionMatrixStack
.Top
, 0,
945 SLANG_COMMON_FIXED_PROJECTIONMATRIX
,
946 SLANG_COMMON_FIXED_PROJECTIONMATRIXINVERSE
,
947 SLANG_COMMON_FIXED_PROJECTIONMATRIXTRANSPOSE
,
948 SLANG_COMMON_FIXED_PROJECTIONMATRIXINVERSETRANSPOSE
);
951 write_common_fixed_mat4 (pro
, &ctx
->_ModelProjectMatrix
, 0,
952 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIX
,
953 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIXINVERSE
,
954 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIXTRANSPOSE
,
955 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIXINVERSETRANSPOSE
);
957 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
960 write_common_fixed_mat4 (pro
, ctx
->TextureMatrixStack
[i
].Top
, i
,
961 SLANG_COMMON_FIXED_TEXTUREMATRIX
,
962 SLANG_COMMON_FIXED_TEXTUREMATRIXINVERSE
,
963 SLANG_COMMON_FIXED_TEXTUREMATRIXTRANSPOSE
,
964 SLANG_COMMON_FIXED_TEXTUREMATRIXINVERSETRANSPOSE
);
966 /* EYE_PLANE texture-coordinate generation */
967 write_common_fixed (pro
, SLANG_COMMON_FIXED_EYEPLANES
, ctx
->Texture
.Unit
[i
].EyePlaneS
,
968 i
, 4 * sizeof (GLfloat
));
969 write_common_fixed (pro
, SLANG_COMMON_FIXED_EYEPLANET
, ctx
->Texture
.Unit
[i
].EyePlaneT
,
970 i
, 4 * sizeof (GLfloat
));
971 write_common_fixed (pro
, SLANG_COMMON_FIXED_EYEPLANER
, ctx
->Texture
.Unit
[i
].EyePlaneR
,
972 i
, 4 * sizeof (GLfloat
));
973 write_common_fixed (pro
, SLANG_COMMON_FIXED_EYEPLANEQ
, ctx
->Texture
.Unit
[i
].EyePlaneQ
,
974 i
, 4 * sizeof (GLfloat
));
976 /* OBJECT_PLANE texture-coordinate generation */
977 write_common_fixed (pro
, SLANG_COMMON_FIXED_OBJECTPLANES
, ctx
->Texture
.Unit
[i
].ObjectPlaneS
,
978 i
, 4 * sizeof (GLfloat
));
979 write_common_fixed (pro
, SLANG_COMMON_FIXED_OBJECTPLANET
, ctx
->Texture
.Unit
[i
].ObjectPlaneT
,
980 i
, 4 * sizeof (GLfloat
));
981 write_common_fixed (pro
, SLANG_COMMON_FIXED_OBJECTPLANER
, ctx
->Texture
.Unit
[i
].ObjectPlaneR
,
982 i
, 4 * sizeof (GLfloat
));
983 write_common_fixed (pro
, SLANG_COMMON_FIXED_OBJECTPLANEQ
, ctx
->Texture
.Unit
[i
].ObjectPlaneQ
,
984 i
, 4 * sizeof (GLfloat
));
987 /* NORMAL matrix - upper 3x3 inverse transpose of MODELVIEW matrix */
988 p
= ctx
->ModelviewMatrixStack
.Top
->inv
;
998 write_common_fixed (pro
, SLANG_COMMON_FIXED_NORMALMATRIX
, v
, 0, 9 * sizeof (GLfloat
));
1001 write_common_fixed (pro
, SLANG_COMMON_FIXED_NORMALSCALE
, &ctx
->_ModelViewInvScale
, 0, sizeof (GLfloat
));
1003 /* depth range parameters */
1004 v
[0] = ctx
->Viewport
.Near
;
1005 v
[1] = ctx
->Viewport
.Far
;
1006 v
[2] = ctx
->Viewport
.Far
- ctx
->Viewport
.Near
;
1007 write_common_fixed (pro
, SLANG_COMMON_FIXED_DEPTHRANGE
, v
, 0, 3 * sizeof (GLfloat
));
1010 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++)
1012 write_common_fixed (pro
, SLANG_COMMON_FIXED_CLIPPLANE
, ctx
->Transform
.EyeUserPlane
[i
], i
,
1013 4 * sizeof (GLfloat
));
1016 /* point parameters */
1017 v
[0] = ctx
->Point
.Size
;
1018 v
[1] = ctx
->Point
.MinSize
;
1019 v
[2] = ctx
->Point
.MaxSize
;
1020 v
[3] = ctx
->Point
.Threshold
;
1021 COPY_3FV((v
+ 4), ctx
->Point
.Params
);
1022 write_common_fixed (pro
, SLANG_COMMON_FIXED_POINT
, v
, 0, 7 * sizeof (GLfloat
));
1024 /* material parameters */
1025 write_common_fixed_material (ctx
, pro
, SLANG_COMMON_FIXED_FRONTMATERIAL
,
1026 MAT_ATTRIB_FRONT_EMISSION
,
1027 MAT_ATTRIB_FRONT_AMBIENT
,
1028 MAT_ATTRIB_FRONT_DIFFUSE
,
1029 MAT_ATTRIB_FRONT_SPECULAR
,
1030 MAT_ATTRIB_FRONT_SHININESS
);
1031 write_common_fixed_material (ctx
, pro
, SLANG_COMMON_FIXED_BACKMATERIAL
,
1032 MAT_ATTRIB_BACK_EMISSION
,
1033 MAT_ATTRIB_BACK_AMBIENT
,
1034 MAT_ATTRIB_BACK_DIFFUSE
,
1035 MAT_ATTRIB_BACK_SPECULAR
,
1036 MAT_ATTRIB_BACK_SHININESS
);
1038 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++)
1040 /* light source parameters */
1041 COPY_4FV(v
, ctx
->Light
.Light
[i
].Ambient
);
1042 COPY_4FV((v
+ 4), ctx
->Light
.Light
[i
].Diffuse
);
1043 COPY_4FV((v
+ 8), ctx
->Light
.Light
[i
].Specular
);
1044 COPY_4FV((v
+ 12), ctx
->Light
.Light
[i
].EyePosition
);
1045 COPY_2FV((v
+ 16), ctx
->Light
.Light
[i
].EyePosition
);
1046 v
[18] = ctx
->Light
.Light
[i
].EyePosition
[2] + 1.0f
;
1047 NORMALIZE_3FV((v
+ 16));
1049 COPY_3V((v
+ 20), ctx
->Light
.Light
[i
].EyeDirection
);
1050 v
[23] = ctx
->Light
.Light
[i
].SpotExponent
;
1051 v
[24] = ctx
->Light
.Light
[i
].SpotCutoff
;
1052 v
[25] = ctx
->Light
.Light
[i
]._CosCutoffNeg
;
1053 v
[26] = ctx
->Light
.Light
[i
].ConstantAttenuation
;
1054 v
[27] = ctx
->Light
.Light
[i
].LinearAttenuation
;
1055 v
[28] = ctx
->Light
.Light
[i
].QuadraticAttenuation
;
1056 write_common_fixed (pro
, SLANG_COMMON_FIXED_LIGHTSOURCE
, v
, i
, 29 * sizeof (GLfloat
));
1059 write_common_fixed_light_product (ctx
, pro
, i
, SLANG_COMMON_FIXED_FRONTLIGHTPRODUCT
,
1060 MAT_ATTRIB_FRONT_AMBIENT
,
1061 MAT_ATTRIB_FRONT_DIFFUSE
,
1062 MAT_ATTRIB_FRONT_SPECULAR
);
1063 write_common_fixed_light_product (ctx
, pro
, i
, SLANG_COMMON_FIXED_BACKLIGHTPRODUCT
,
1064 MAT_ATTRIB_BACK_AMBIENT
,
1065 MAT_ATTRIB_BACK_DIFFUSE
,
1066 MAT_ATTRIB_BACK_SPECULAR
);
1069 /* light model parameters */
1070 write_common_fixed (pro
, SLANG_COMMON_FIXED_LIGHTMODEL
, ctx
->Light
.Model
.Ambient
, 0, 4 * sizeof (GLfloat
));
1072 /* light model product */
1073 write_common_fixed_light_model_product (ctx
, pro
, SLANG_COMMON_FIXED_FRONTLIGHTMODELPRODUCT
,
1074 MAT_ATTRIB_FRONT_EMISSION
,
1075 MAT_ATTRIB_FRONT_AMBIENT
);
1076 write_common_fixed_light_model_product (ctx
, pro
, SLANG_COMMON_FIXED_BACKLIGHTMODELPRODUCT
,
1077 MAT_ATTRIB_BACK_EMISSION
,
1078 MAT_ATTRIB_BACK_AMBIENT
);
1080 /* TEXTURE_ENV_COLOR */
1081 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++)
1083 write_common_fixed (pro
, SLANG_COMMON_FIXED_TEXTUREENVCOLOR
, ctx
->Texture
.Unit
[i
].EnvColor
,
1084 i
, 4 * sizeof (GLfloat
));
1087 /* fog parameters */
1088 COPY_4FV(v
, ctx
->Fog
.Color
);
1089 v
[4] = ctx
->Fog
.Density
;
1090 v
[5] = ctx
->Fog
.Start
;
1091 v
[6] = ctx
->Fog
.End
;
1092 v
[7] = ctx
->Fog
._Scale
;
1093 write_common_fixed (pro
, SLANG_COMMON_FIXED_FOG
, v
, 0, 8 * sizeof (GLfloat
));
1097 _program_UpdateFixedAttribute (struct gl2_program_intf
**intf
, GLuint index
, GLvoid
*data
,
1098 GLuint offset
, GLuint size
, GLboolean write
)
1100 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1101 slang_program
*pro
= &impl
->_obj
.prog
;
1104 addr
= pro
->vertex_fixed_entries
[index
];
1109 mem
= (GLubyte
*) pro
->machines
[SLANG_SHADER_VERTEX
]->mem
+ addr
+ offset
* size
;
1111 _mesa_memcpy (mem
, data
, size
);
1113 _mesa_memcpy (data
, mem
, size
);
1118 _program_UpdateFixedVarying (struct gl2_program_intf
**intf
, GLuint index
, GLvoid
*data
,
1119 GLuint offset
, GLuint size
, GLboolean write
)
1121 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1122 slang_program
*pro
= &impl
->_obj
.prog
;
1125 addr
= pro
->fragment_fixed_entries
[index
];
1130 mem
= (GLubyte
*) pro
->machines
[SLANG_SHADER_FRAGMENT
]->mem
+ addr
+ offset
* size
;
1132 _mesa_memcpy (mem
, data
, size
);
1134 _mesa_memcpy (data
, mem
, size
);
1139 _program_GetTextureImageUsage (struct gl2_program_intf
**intf
, GLbitfield
*teximageusage
)
1141 GET_CURRENT_CONTEXT(ctx
);
1142 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1143 slang_program
*pro
= &impl
->_obj
.prog
;
1146 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++)
1147 teximageusage
[i
] = 0;
1149 for (i
= 0; i
< pro
->texture_usage
.count
; i
++)
1153 n
= slang_export_data_quant_elements (pro
->texture_usage
.table
[i
].quant
);
1154 addr
= pro
->texture_usage
.table
[i
].frag_address
;
1155 for (j
= 0; j
< n
; j
++)
1160 mem
= (GLubyte
*) pro
->machines
[SLANG_SHADER_FRAGMENT
]->mem
+ addr
+ j
* 4;
1161 image
= (GLuint
) *((GLfloat
*) mem
);
1162 if (image
>= 0 && image
< ctx
->Const
.MaxTextureImageUnits
)
1164 switch (slang_export_data_quant_type (pro
->texture_usage
.table
[i
].quant
))
1166 case GL_SAMPLER_1D_ARB
:
1167 case GL_SAMPLER_1D_SHADOW_ARB
:
1168 teximageusage
[image
] |= TEXTURE_1D_BIT
;
1170 case GL_SAMPLER_2D_ARB
:
1171 case GL_SAMPLER_2D_SHADOW_ARB
:
1172 teximageusage
[image
] |= TEXTURE_2D_BIT
;
1174 case GL_SAMPLER_3D_ARB
:
1175 teximageusage
[image
] |= TEXTURE_3D_BIT
;
1177 case GL_SAMPLER_CUBE_ARB
:
1178 teximageusage
[image
] |= TEXTURE_CUBE_BIT
;
1185 /* TODO: make sure that for 0<=i<=MaxTextureImageUint bitcount(teximageuint[i])<=0 */
1189 _program_IsShaderPresent (struct gl2_program_intf
**intf
, GLenum subtype
)
1191 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1192 slang_program
*pro
= &impl
->_obj
.prog
;
1196 case GL_VERTEX_SHADER_ARB
:
1197 return pro
->machines
[SLANG_SHADER_VERTEX
] != NULL
;
1198 case GL_FRAGMENT_SHADER_ARB
:
1199 return pro
->machines
[SLANG_SHADER_FRAGMENT
] != NULL
;
1206 _program_UpdateVarying (struct gl2_program_intf
**intf
, GLuint index
, GLfloat
*value
,
1209 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1210 slang_program
*pro
= &impl
->_obj
.prog
;
1213 if (index
>= pro
->varyings
.total
)
1216 addr
= pro
->varyings
.slots
[index
].vert_addr
/ 4;
1218 addr
= pro
->varyings
.slots
[index
].frag_addr
/ 4;
1222 *value
= pro
->machines
[SLANG_SHADER_VERTEX
]->mem
[addr
]._float
;
1224 pro
->machines
[SLANG_SHADER_FRAGMENT
]->mem
[addr
]._float
= *value
;
1228 static struct gl2_program_intf _program_vftbl
= {
1234 _program_QueryInterface
1239 _generic_GetDeleteStatus
,
1244 _container_GetAttachedCount
,
1245 _container_GetAttached
1247 _program_GetLinkStatus
,
1248 _program_GetValidateStatus
,
1251 _program_UpdateFixedUniforms
,
1252 _program_UpdateFixedAttribute
,
1253 _program_UpdateFixedVarying
,
1254 _program_GetTextureImageUsage
,
1255 _program_IsShaderPresent
,
1256 _program_UpdateVarying
1260 _program_constructor (struct gl2_program_impl
*impl
)
1262 _container_constructor ((struct gl2_container_impl
*) impl
);
1263 impl
->_vftbl
= &_program_vftbl
;
1264 impl
->_obj
._container
._generic
._unknown
._destructor
= _program_destructor
;
1265 impl
->_obj
.link_status
= GL_FALSE
;
1266 impl
->_obj
.validate_status
= GL_FALSE
;
1267 #if USE_3DLABS_FRONTEND
1268 impl
->_obj
.linker
= ShConstructLinker (EShExVertexFragment
, 0);
1269 impl
->_obj
.uniforms
= ShConstructUniformMap ();
1271 slang_program_ctr (&impl
->_obj
.prog
);
1274 struct gl2_fragment_shader_obj
1276 struct gl2_shader_obj _shader
;
1279 struct gl2_fragment_shader_impl
1281 struct gl2_fragment_shader_intf
*_vftbl
;
1282 struct gl2_fragment_shader_obj _obj
;
1286 _fragment_shader_destructor (struct gl2_unknown_intf
**intf
)
1288 struct gl2_fragment_shader_impl
*impl
= (struct gl2_fragment_shader_impl
*) intf
;
1291 /* TODO free fragment shader data */
1293 _shader_destructor (intf
);
1296 static struct gl2_unknown_intf
**
1297 _fragment_shader_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
1299 if (uiid
== UIID_FRAGMENT_SHADER
)
1301 (**intf
).AddRef (intf
);
1304 return _shader_QueryInterface (intf
, uiid
);
1308 _fragment_shader_GetSubType (struct gl2_shader_intf
**intf
)
1310 return GL_FRAGMENT_SHADER_ARB
;
1313 static struct gl2_fragment_shader_intf _fragment_shader_vftbl
= {
1319 _fragment_shader_QueryInterface
1324 _generic_GetDeleteStatus
,
1327 _fragment_shader_GetSubType
,
1328 _shader_GetCompileStatus
,
1336 _fragment_shader_constructor (struct gl2_fragment_shader_impl
*impl
)
1338 _shader_constructor ((struct gl2_shader_impl
*) impl
);
1339 impl
->_vftbl
= &_fragment_shader_vftbl
;
1340 impl
->_obj
._shader
._generic
._unknown
._destructor
= _fragment_shader_destructor
;
1341 #if USE_3DLABS_FRONTEND
1342 impl
->_obj
._shader
._3dlabs_shhandle
._obj
.handle
= ShConstructCompiler (EShLangFragment
, 0);
1346 struct gl2_vertex_shader_obj
1348 struct gl2_shader_obj _shader
;
1351 struct gl2_vertex_shader_impl
1353 struct gl2_vertex_shader_intf
*_vftbl
;
1354 struct gl2_vertex_shader_obj _obj
;
1358 _vertex_shader_destructor (struct gl2_unknown_intf
**intf
)
1360 struct gl2_vertex_shader_impl
*impl
= (struct gl2_vertex_shader_impl
*) intf
;
1363 /* TODO free vertex shader data */
1365 _shader_destructor (intf
);
1368 static struct gl2_unknown_intf
**
1369 _vertex_shader_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
1371 if (uiid
== UIID_VERTEX_SHADER
)
1373 (**intf
).AddRef (intf
);
1376 return _shader_QueryInterface (intf
, uiid
);
1380 _vertex_shader_GetSubType (struct gl2_shader_intf
**intf
)
1382 return GL_VERTEX_SHADER_ARB
;
1385 static struct gl2_vertex_shader_intf _vertex_shader_vftbl
= {
1391 _vertex_shader_QueryInterface
1396 _generic_GetDeleteStatus
,
1399 _vertex_shader_GetSubType
,
1400 _shader_GetCompileStatus
,
1408 _vertex_shader_constructor (struct gl2_vertex_shader_impl
*impl
)
1410 _shader_constructor ((struct gl2_shader_impl
*) impl
);
1411 impl
->_vftbl
= &_vertex_shader_vftbl
;
1412 impl
->_obj
._shader
._generic
._unknown
._destructor
= _vertex_shader_destructor
;
1413 #if USE_3DLABS_FRONTEND
1414 impl
->_obj
._shader
._3dlabs_shhandle
._obj
.handle
= ShConstructCompiler (EShLangVertex
, 0);
1419 _mesa_3dlabs_create_shader_object (GLenum shaderType
)
1423 case GL_FRAGMENT_SHADER_ARB
:
1425 struct gl2_fragment_shader_impl
*x
= (struct gl2_fragment_shader_impl
*)
1426 _mesa_malloc (sizeof (struct gl2_fragment_shader_impl
));
1430 _fragment_shader_constructor (x
);
1431 return x
->_obj
._shader
._generic
.name
;
1435 case GL_VERTEX_SHADER_ARB
:
1437 struct gl2_vertex_shader_impl
*x
= (struct gl2_vertex_shader_impl
*)
1438 _mesa_malloc (sizeof (struct gl2_vertex_shader_impl
));
1442 _vertex_shader_constructor (x
);
1443 return x
->_obj
._shader
._generic
.name
;
1453 _mesa_3dlabs_create_program_object (void)
1455 struct gl2_program_impl
*x
= (struct gl2_program_impl
*)
1456 _mesa_malloc (sizeof (struct gl2_program_impl
));
1460 _program_constructor (x
);
1461 return x
->_obj
._container
._generic
.name
;
1467 #include "slang_assemble.h"
1468 #include "slang_execute.h"
1470 int _slang_fetch_discard (struct gl2_program_intf
**pro
, GLboolean
*val
)
1472 struct gl2_program_impl
*impl
;
1474 impl
= (struct gl2_program_impl
*) pro
;
1475 *val
= impl
->_obj
.prog
.machines
[SLANG_SHADER_FRAGMENT
]->kill
? GL_TRUE
: GL_FALSE
;
1479 static GLvoid
exec_shader (struct gl2_program_intf
**pro
, GLuint i
)
1481 struct gl2_program_impl
*impl
;
1484 impl
= (struct gl2_program_impl
*) pro
;
1485 p
= &impl
->_obj
.prog
;
1487 slang_machine_init (p
->machines
[i
]);
1488 p
->machines
[i
]->ip
= p
->code
[i
][SLANG_COMMON_CODE_MAIN
];
1490 _slang_execute2 (p
->assemblies
[i
], p
->machines
[i
]);
1493 GLvoid
_slang_exec_fragment_shader (struct gl2_program_intf
**pro
)
1495 exec_shader (pro
, SLANG_SHADER_FRAGMENT
);
1498 GLvoid
_slang_exec_vertex_shader (struct gl2_program_intf
**pro
)
1500 exec_shader (pro
, SLANG_SHADER_VERTEX
);
1503 GLint
_slang_get_uniform_location (struct gl2_program_intf
**pro
, const char *name
)
1505 struct gl2_program_impl
*impl
;
1506 slang_uniform_bindings
*bind
;
1509 impl
= (struct gl2_program_impl
*) pro
;
1510 bind
= &impl
->_obj
.prog
.uniforms
;
1511 for (i
= 0; i
< bind
->count
; i
++)
1512 if (_mesa_strcmp (bind
->table
[i
].name
, name
) == 0)
1517 GLboolean
_slang_write_uniform (struct gl2_program_intf
**pro
, GLint loc
, GLsizei count
,
1518 const GLvoid
*data
, GLenum type
)
1520 struct gl2_program_impl
*impl
;
1521 slang_uniform_bindings
*bind
;
1522 slang_uniform_binding
*b
;
1524 GLboolean convert_float_to_bool
= GL_FALSE
;
1525 GLboolean convert_int_to_bool
= GL_FALSE
;
1526 GLboolean convert_int_to_float
= GL_FALSE
;
1527 GLboolean types_match
= GL_FALSE
;
1532 impl
= (struct gl2_program_impl
*) pro
;
1533 bind
= &impl
->_obj
.prog
.uniforms
;
1534 if (loc
>= bind
->count
)
1537 b
= &bind
->table
[loc
];
1538 /* TODO: check sizes */
1539 if (slang_export_data_quant_struct (b
->quant
))
1542 switch (slang_export_data_quant_type (b
->quant
))
1545 types_match
= (type
== GL_FLOAT
) || (type
== GL_INT
);
1546 if (type
== GL_FLOAT
)
1547 convert_float_to_bool
= GL_TRUE
;
1549 convert_int_to_bool
= GL_TRUE
;
1551 case GL_BOOL_VEC2_ARB
:
1552 types_match
= (type
== GL_FLOAT_VEC2_ARB
) || (type
== GL_INT_VEC2_ARB
);
1553 if (type
== GL_FLOAT_VEC2_ARB
)
1554 convert_float_to_bool
= GL_TRUE
;
1556 convert_int_to_bool
= GL_TRUE
;
1558 case GL_BOOL_VEC3_ARB
:
1559 types_match
= (type
== GL_FLOAT_VEC3_ARB
) || (type
== GL_INT_VEC3_ARB
);
1560 if (type
== GL_FLOAT_VEC3_ARB
)
1561 convert_float_to_bool
= GL_TRUE
;
1563 convert_int_to_bool
= GL_TRUE
;
1565 case GL_BOOL_VEC4_ARB
:
1566 types_match
= (type
== GL_FLOAT_VEC4_ARB
) || (type
== GL_INT_VEC4_ARB
);
1567 if (type
== GL_FLOAT_VEC4_ARB
)
1568 convert_float_to_bool
= GL_TRUE
;
1570 convert_int_to_bool
= GL_TRUE
;
1572 case GL_SAMPLER_1D_ARB
:
1573 case GL_SAMPLER_2D_ARB
:
1574 case GL_SAMPLER_3D_ARB
:
1575 case GL_SAMPLER_CUBE_ARB
:
1576 case GL_SAMPLER_1D_SHADOW_ARB
:
1577 case GL_SAMPLER_2D_SHADOW_ARB
:
1578 types_match
= (type
== GL_INT
);
1581 types_match
= (type
== slang_export_data_quant_type (b
->quant
));
1591 case GL_INT_VEC2_ARB
:
1592 case GL_INT_VEC3_ARB
:
1593 case GL_INT_VEC4_ARB
:
1594 convert_int_to_float
= GL_TRUE
;
1598 if (convert_float_to_bool
)
1600 for (i
= 0; i
< SLANG_SHADER_MAX
; i
++)
1601 if (b
->address
[i
] != ~0)
1603 const GLfloat
*src
= (GLfloat
*) (data
);
1604 GLfloat
*dst
= (GLfloat
*) (&impl
->_obj
.prog
.machines
[i
]->mem
[b
->address
[i
] / 4]);
1606 GLuint total
= count
* slang_export_data_quant_components (b
->quant
);
1608 for (j
= 0; j
< total
; j
++)
1609 dst
[j
] = src
[j
] != 0.0f
? 1.0f
: 0.0f
;
1612 else if (convert_int_to_bool
)
1614 for (i
= 0; i
< SLANG_SHADER_MAX
; i
++)
1615 if (b
->address
[i
] != ~0)
1617 const GLuint
*src
= (GLuint
*) (data
);
1618 GLfloat
*dst
= (GLfloat
*) (&impl
->_obj
.prog
.machines
[i
]->mem
[b
->address
[i
] / 4]);
1620 GLuint total
= count
* slang_export_data_quant_components (b
->quant
);
1622 for (j
= 0; j
< total
; j
++)
1623 dst
[j
] = src
[j
] ? 1.0f
: 0.0f
;
1626 else if (convert_int_to_float
)
1628 for (i
= 0; i
< SLANG_SHADER_MAX
; i
++)
1629 if (b
->address
[i
] != ~0)
1631 const GLuint
*src
= (GLuint
*) (data
);
1632 GLfloat
*dst
= (GLfloat
*) (&impl
->_obj
.prog
.machines
[i
]->mem
[b
->address
[i
] / 4]);
1634 GLuint total
= count
* slang_export_data_quant_components (b
->quant
);
1636 for (j
= 0; j
< total
; j
++)
1637 dst
[j
] = (GLfloat
) src
[j
];
1642 for (i
= 0; i
< SLANG_SHADER_MAX
; i
++)
1643 if (b
->address
[i
] != ~0)
1645 _mesa_memcpy (&impl
->_obj
.prog
.machines
[i
]->mem
[b
->address
[i
] / 4], data
,
1646 count
* slang_export_data_quant_size (b
->quant
));
1652 GLuint
_slang_get_active_uniform_count (struct gl2_program_intf
**pro
)
1654 struct gl2_program_impl
*impl
;
1656 impl
= (struct gl2_program_impl
*) pro
;
1657 return impl
->_obj
.prog
.active_uniforms
.count
;
1660 GLuint
_slang_get_active_uniform_max_length (struct gl2_program_intf
**pro
)
1662 struct gl2_program_impl
*impl
;
1665 impl
= (struct gl2_program_impl
*) pro
;
1666 for (i
= 0; i
< impl
->_obj
.prog
.active_uniforms
.count
; i
++)
1668 GLuint n
= _mesa_strlen (impl
->_obj
.prog
.active_uniforms
.table
[i
].name
);
1675 GLvoid
_slang_get_active_uniform (struct gl2_program_intf
**pro
, GLuint index
, GLsizei maxLength
,
1676 GLsizei
*length
, GLint
*size
, GLenum
*type
, char *name
)
1678 struct gl2_program_impl
*impl
;
1679 slang_active_uniform
*u
;
1682 impl
= (struct gl2_program_impl
*) pro
;
1683 u
= &impl
->_obj
.prog
.active_uniforms
.table
[index
];
1685 len
= _mesa_strlen (u
->name
);
1686 if (len
>= maxLength
)
1687 len
= maxLength
- 1;
1688 _mesa_memcpy (name
, u
->name
, len
);
1692 *type
= slang_export_data_quant_type (u
->quant
);
1693 *size
= slang_export_data_quant_elements (u
->quant
);
1697 _mesa_init_shaderobjects_3dlabs (GLcontext
*ctx
)
1699 #if USE_3DLABS_FRONTEND
1700 _glslang_3dlabs_InitProcess ();
1701 _glslang_3dlabs_ShInitialize ();