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 #if FEATURE_ARB_shader_objects
49 struct gl2_unknown_obj
51 GLuint reference_count
;
52 void (* _destructor
) (struct gl2_unknown_intf
**);
55 struct gl2_unknown_impl
57 struct gl2_unknown_intf
*_vftbl
;
58 struct gl2_unknown_obj _obj
;
62 _unknown_destructor (struct gl2_unknown_intf
**intf
)
67 _unknown_AddRef (struct gl2_unknown_intf
**intf
)
69 struct gl2_unknown_impl
*impl
= (struct gl2_unknown_impl
*) intf
;
71 impl
->_obj
.reference_count
++;
75 _unknown_Release (struct gl2_unknown_intf
**intf
)
77 struct gl2_unknown_impl
*impl
= (struct gl2_unknown_impl
*) intf
;
79 impl
->_obj
.reference_count
--;
80 if (impl
->_obj
.reference_count
== 0)
82 impl
->_obj
._destructor (intf
);
83 _mesa_free ((void *) intf
);
87 static struct gl2_unknown_intf
**
88 _unknown_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
90 if (uiid
== UIID_UNKNOWN
)
92 (**intf
).AddRef (intf
);
98 static struct gl2_unknown_intf _unknown_vftbl
= {
101 _unknown_QueryInterface
105 _unknown_constructor (struct gl2_unknown_impl
*impl
)
107 impl
->_vftbl
= &_unknown_vftbl
;
108 impl
->_obj
.reference_count
= 1;
109 impl
->_obj
._destructor
= _unknown_destructor
;
112 struct gl2_unkinner_obj
114 struct gl2_unknown_intf
**unkouter
;
117 struct gl2_unkinner_impl
119 struct gl2_unknown_intf
*_vftbl
;
120 struct gl2_unkinner_obj _obj
;
124 _unkinner_destructor (struct gl2_unknown_intf
**intf
)
129 _unkinner_AddRef (struct gl2_unknown_intf
**intf
)
131 struct gl2_unkinner_impl
*impl
= (struct gl2_unkinner_impl
*) intf
;
133 (**impl
->_obj
.unkouter
).AddRef (impl
->_obj
.unkouter
);
137 _unkinner_Release (struct gl2_unknown_intf
**intf
)
139 struct gl2_unkinner_impl
*impl
= (struct gl2_unkinner_impl
*) intf
;
141 (**impl
->_obj
.unkouter
).Release (impl
->_obj
.unkouter
);
144 static struct gl2_unknown_intf
**
145 _unkinner_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
147 struct gl2_unkinner_impl
*impl
= (struct gl2_unkinner_impl
*) intf
;
149 return (**impl
->_obj
.unkouter
).QueryInterface (impl
->_obj
.unkouter
, uiid
);
152 static struct gl2_unknown_intf _unkinner_vftbl
= {
155 _unkinner_QueryInterface
159 _unkinner_constructor (struct gl2_unkinner_impl
*impl
, struct gl2_unknown_intf
**outer
)
161 impl
->_vftbl
= &_unkinner_vftbl
;
162 impl
->_obj
.unkouter
= outer
;
165 struct gl2_generic_obj
167 struct gl2_unknown_obj _unknown
;
169 GLboolean delete_status
;
173 struct gl2_generic_impl
175 struct gl2_generic_intf
*_vftbl
;
176 struct gl2_generic_obj _obj
;
180 _generic_destructor (struct gl2_unknown_intf
**intf
)
182 GET_CURRENT_CONTEXT(ctx
);
183 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
185 _mesa_free ((void *) impl
->_obj
.info_log
);
187 _glthread_LOCK_MUTEX (ctx
->Shared
->Mutex
);
188 _mesa_HashRemove (ctx
->Shared
->GL2Objects
, impl
->_obj
.name
);
189 _glthread_UNLOCK_MUTEX (ctx
->Shared
->Mutex
);
191 _unknown_destructor (intf
);
194 static struct gl2_unknown_intf
**
195 _generic_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
197 if (uiid
== UIID_GENERIC
)
199 (**intf
).AddRef (intf
);
202 return _unknown_QueryInterface (intf
, uiid
);
206 _generic_Delete (struct gl2_generic_intf
**intf
)
208 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
210 if (impl
->_obj
.delete_status
== GL_FALSE
)
212 impl
->_obj
.delete_status
= GL_TRUE
;
213 (**intf
)._unknown
.Release ((struct gl2_unknown_intf
**) intf
);
218 _generic_GetName (struct gl2_generic_intf
**intf
)
220 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
222 return impl
->_obj
.name
;
226 _generic_GetDeleteStatus (struct gl2_generic_intf
**intf
)
228 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
230 return impl
->_obj
.delete_status
;
234 _generic_GetInfoLog (struct gl2_generic_intf
**intf
, GLsizei maxlen
, GLcharARB
*infolog
)
236 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) (intf
);
239 _mesa_strncpy (infolog
, impl
->_obj
.info_log
, maxlen
- 1);
240 infolog
[maxlen
- 1] = '\0';
245 _generic_GetInfoLogLength (struct gl2_generic_intf
**intf
)
247 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) (intf
);
249 if (impl
->_obj
.info_log
== NULL
)
251 return _mesa_strlen (impl
->_obj
.info_log
) + 1;
254 static struct gl2_generic_intf _generic_vftbl
= {
258 _generic_QueryInterface
261 NULL
, /* abstract GetType */
263 _generic_GetDeleteStatus
,
265 _generic_GetInfoLogLength
269 _generic_constructor (struct gl2_generic_impl
*impl
)
271 GET_CURRENT_CONTEXT(ctx
);
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
;
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
);
285 struct gl2_container_obj
287 struct gl2_generic_obj _generic
;
288 struct gl2_generic_intf
***attached
;
289 GLuint attached_count
;
292 struct gl2_container_impl
294 struct gl2_container_intf
*_vftbl
;
295 struct gl2_container_obj _obj
;
299 _container_destructor (struct gl2_unknown_intf
**intf
)
301 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
304 for (i
= 0; i
< impl
->_obj
.attached_count
; i
++)
306 struct gl2_generic_intf
**x
= impl
->_obj
.attached
[i
];
307 (**x
)._unknown
.Release ((struct gl2_unknown_intf
**) x
);
310 _generic_destructor (intf
);
313 static struct gl2_unknown_intf
**
314 _container_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
316 if (uiid
== UIID_CONTAINER
)
318 (**intf
).AddRef (intf
);
321 return _generic_QueryInterface (intf
, uiid
);
325 _container_Attach (struct gl2_container_intf
**intf
, struct gl2_generic_intf
**att
)
327 GET_CURRENT_CONTEXT(ctx
);
328 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
331 for (i
= 0; i
< impl
->_obj
.attached_count
; i
++)
332 if (impl
->_obj
.attached
[i
] == att
)
334 _mesa_error (ctx
, GL_INVALID_OPERATION
, "_container_Attach");
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
)
344 impl
->_obj
.attached
[impl
->_obj
.attached_count
] = att
;
345 impl
->_obj
.attached_count
++;
346 (**att
)._unknown
.AddRef ((struct gl2_unknown_intf
**) att
);
351 _container_Detach (struct gl2_container_intf
**intf
, struct gl2_generic_intf
**att
)
353 GET_CURRENT_CONTEXT(ctx
);
354 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
357 for (i
= 0; i
< impl
->_obj
.attached_count
; i
++)
358 if (impl
->_obj
.attached
[i
] == att
)
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
);
370 _mesa_error (ctx
, GL_INVALID_OPERATION
, "_container_Detach");
375 _container_GetAttachedCount (struct gl2_container_intf
**intf
)
377 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
379 return impl
->_obj
.attached_count
;
382 static struct gl2_generic_intf
**
383 _container_GetAttached (struct gl2_container_intf
**intf
, GLuint index
)
385 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
387 (**impl
->_obj
.attached
[index
])._unknown
.AddRef (
388 (struct gl2_unknown_intf
**)impl
->_obj
.attached
[index
]);
389 return impl
->_obj
.attached
[index
];
392 static struct gl2_container_intf _container_vftbl
= {
397 _container_QueryInterface
400 NULL
, /* abstract GetType */
402 _generic_GetDeleteStatus
,
404 _generic_GetInfoLogLength
408 _container_GetAttachedCount
,
409 _container_GetAttached
413 _container_constructor (struct gl2_container_impl
*impl
)
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;
422 struct gl2_3dlabs_shhandle_obj
424 struct gl2_unkinner_obj _unknown
;
425 #if USE_3DLABS_FRONTEND
430 struct gl2_3dlabs_shhandle_impl
432 struct gl2_3dlabs_shhandle_intf
*_vftbl
;
433 struct gl2_3dlabs_shhandle_obj _obj
;
437 _3dlabs_shhandle_destructor (struct gl2_unknown_intf
**intf
)
439 #if USE_3DLABS_FRONTEND
440 struct gl2_3dlabs_shhandle_impl
*impl
= (struct gl2_3dlabs_shhandle_impl
*) intf
;
441 ShDestruct (impl
->_obj
.handle
);
443 _unkinner_destructor (intf
);
447 _3dlabs_shhandle_GetShHandle (struct gl2_3dlabs_shhandle_intf
**intf
)
449 #if USE_3DLABS_FRONTEND
450 struct gl2_3dlabs_shhandle_impl
*impl
= (struct gl2_3dlabs_shhandle_impl
*) intf
;
451 return impl
->_obj
.handle
;
457 static struct gl2_3dlabs_shhandle_intf _3dlabs_shhandle_vftbl
= {
461 _unkinner_QueryInterface
463 _3dlabs_shhandle_GetShHandle
467 _3dlabs_shhandle_constructor (struct gl2_3dlabs_shhandle_impl
*impl
, struct gl2_unknown_intf
**outer
)
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
;
476 struct gl2_shader_obj
478 struct gl2_generic_obj _generic
;
479 struct gl2_3dlabs_shhandle_impl _3dlabs_shhandle
;
480 GLboolean compile_status
;
483 GLsizei offset_count
;
484 slang_code_object code
;
487 struct gl2_shader_impl
489 struct gl2_shader_intf
*_vftbl
;
490 struct gl2_shader_obj _obj
;
494 _shader_destructor (struct gl2_unknown_intf
**intf
)
496 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
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
);
505 static struct gl2_unknown_intf
**
506 _shader_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
508 #if USE_3DLABS_FRONTEND
509 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
512 if (uiid
== UIID_SHADER
)
514 (**intf
).AddRef (intf
);
517 #if USE_3DLABS_FRONTEND
518 if (uiid
== UIID_3DLABS_SHHANDLE
)
520 (**intf
).AddRef (intf
);
521 return (struct gl2_unknown_intf
**) &impl
->_obj
._3dlabs_shhandle
._vftbl
;
524 return _generic_QueryInterface (intf
, uiid
);
528 _shader_GetType (struct gl2_generic_intf
**intf
)
530 return GL_SHADER_OBJECT_ARB
;
534 _shader_GetInfoLog (struct gl2_generic_intf
**intf
, GLsizei maxlen
, GLcharARB
*infolog
)
536 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) (intf
);
539 if (impl
->_obj
._generic
.info_log
!= NULL
) {
540 GLsizei len
= _mesa_strlen (impl
->_obj
._generic
.info_log
);
541 if (len
> maxlen
- 1)
543 _mesa_memcpy (infolog
, impl
->_obj
._generic
.info_log
, len
);
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)
552 _mesa_memcpy (infolog
, impl
->_obj
.code
.machine
.infolog
->text
, len
);
554 infolog
[maxlen
- 1] = '\0';
559 _shader_GetInfoLogLength (struct gl2_generic_intf
**intf
)
561 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) (intf
);
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
);
573 _shader_GetCompileStatus (struct gl2_shader_intf
**intf
)
575 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
577 return impl
->_obj
.compile_status
;
581 _shader_SetSource (struct gl2_shader_intf
**intf
, GLcharARB
*src
, GLint
*off
, GLsizei cnt
)
583 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
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
;
592 static const GLcharARB
*
593 _shader_GetSource (struct gl2_shader_intf
**intf
)
595 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
597 return impl
->_obj
.source
;
601 _shader_Compile (struct gl2_shader_intf
**intf
)
603 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
604 #if USE_3DLABS_FRONTEND
606 TBuiltInResource res
;
608 slang_unit_type type
;
609 slang_info_log info_log
;
612 impl
->_obj
.compile_status
= GL_FALSE
;
613 _mesa_free ((void *) impl
->_obj
._generic
.info_log
);
614 impl
->_obj
._generic
.info_log
= NULL
;
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 */
621 if (impl
->_obj
.offset_count
<= 1)
622 strings
= &impl
->_obj
.source
;
625 GLsizei i
, offset
= 0;
627 strings
= (char **) _mesa_malloc (impl
->_obj
.offset_count
* sizeof (char *));
631 for (i
= 0; i
< impl
->_obj
.offset_count
; i
++)
633 GLsizei size
= impl
->_obj
.offsets
[i
] - offset
;
635 strings
[i
] = (char *) _mesa_malloc ((size
+ 1) * sizeof (char));
636 if (strings
[i
] == NULL
)
640 for (j
= 0; j
< i
; j
++)
641 _mesa_free (strings
[j
]);
642 _mesa_free (strings
);
646 _mesa_memcpy (strings
[i
], impl
->_obj
.source
+ offset
, size
* sizeof (char));
647 strings
[i
][size
] = '\0';
648 offset
= impl
->_obj
.offsets
[i
];
652 /* TODO set these fields to some REAL numbers */
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;
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)
673 for (i
= 0; i
< impl
->_obj
.offset_count
; i
++)
674 _mesa_free (strings
[i
]);
675 _mesa_free (strings
);
678 impl
->_obj
._generic
.info_log
= _mesa_strdup (ShGetInfoLog (
679 impl
->_obj
._3dlabs_shhandle
._obj
.handle
));
681 if (impl
->_vftbl
->GetSubType (intf
) == GL_FRAGMENT_SHADER
)
682 type
= slang_unit_fragment_shader
;
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");
693 impl
->_obj
._generic
.info_log
= _mesa_strdup ("Compile failed.\n");
694 slang_info_log_destruct (&info_log
);
698 static struct gl2_shader_intf _shader_vftbl
= {
703 _shader_QueryInterface
708 _generic_GetDeleteStatus
,
710 _shader_GetInfoLogLength
712 NULL
, /* abstract GetSubType */
713 _shader_GetCompileStatus
,
720 _shader_constructor (struct gl2_shader_impl
*impl
)
722 _generic_constructor ((struct gl2_generic_impl
*) impl
);
723 _3dlabs_shhandle_constructor (&impl
->_obj
._3dlabs_shhandle
, (struct gl2_unknown_intf
**)
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
);
734 struct gl2_program_obj
736 struct gl2_container_obj _container
;
737 GLboolean link_status
;
738 GLboolean validate_status
;
739 #if USE_3DLABS_FRONTEND
746 struct gl2_program_impl
748 struct gl2_program_intf
*_vftbl
;
749 struct gl2_program_obj _obj
;
753 _program_destructor (struct gl2_unknown_intf
**intf
)
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
);
760 _container_destructor (intf
);
761 _slang_program_dtr (&impl
->_obj
.prog
);
764 static struct gl2_unknown_intf
**
765 _program_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
767 if (uiid
== UIID_PROGRAM
)
769 (**intf
).AddRef (intf
);
772 return _container_QueryInterface (intf
, uiid
);
776 _program_GetType (struct gl2_generic_intf
**intf
)
778 return GL_PROGRAM_OBJECT_ARB
;
782 _program_Attach (struct gl2_container_intf
**intf
, struct gl2_generic_intf
**att
)
784 GET_CURRENT_CONTEXT(ctx
);
785 struct gl2_unknown_intf
**sha
;
787 sha
= (**att
)._unknown
.QueryInterface ((struct gl2_unknown_intf
**) att
, UIID_SHADER
);
790 _mesa_error (ctx
, GL_INVALID_OPERATION
, "_program_Attach");
794 (**sha
).Release (sha
);
795 return _container_Attach (intf
, att
);
799 _program_GetLinkStatus (struct gl2_program_intf
**intf
)
801 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
803 return impl
->_obj
.link_status
;
807 _program_GetValidateStatus (struct gl2_program_intf
**intf
)
809 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
811 return impl
->_obj
.validate_status
;
815 _program_Link (struct gl2_program_intf
**intf
)
817 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
818 #if USE_3DLABS_FRONTEND
822 slang_code_object
*code
[2];
823 GLboolean all_compiled
= GL_TRUE
;
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
);
830 #if USE_3DLABS_FRONTEND
831 handles
= (ShHandle
*) _mesa_malloc (impl
->_obj
._container
.attached_count
* sizeof (ShHandle
));
835 for (i
= 0; i
< impl
->_obj
._container
.attached_count
; i
++)
837 struct gl2_generic_intf
**gen
= impl
->_obj
._container
.attached
[i
];
838 struct gl2_3dlabs_shhandle_intf
**sh
;
840 sh
= (struct gl2_3dlabs_shhandle_intf
**) (**gen
)._unknown
.QueryInterface (
841 (struct gl2_unknown_intf
**) gen
, UIID_3DLABS_SHHANDLE
);
844 handles
[i
] = (**sh
).GetShHandle (sh
);
845 (**sh
)._unknown
.Release ((struct gl2_unknown_intf
**) sh
);
849 _mesa_free (handles
);
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
;
858 impl
->_obj
._container
._generic
.info_log
= _mesa_strdup (ShGetInfoLog (impl
->_obj
.linker
));
860 count
= impl
->_obj
._container
.attached_count
;
863 for (i
= 0; i
< count
; i
++)
865 struct gl2_generic_intf
**obj
;
866 struct gl2_unknown_intf
**unk
;
867 struct gl2_shader_impl
*sha
;
869 obj
= impl
->_obj
._container
.attached
[i
];
870 unk
= (**obj
)._unknown
.QueryInterface ((struct gl2_unknown_intf
**) obj
, UIID_SHADER
);
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
);
879 impl
->_obj
.link_status
= all_compiled
;
880 if (!impl
->_obj
.link_status
)
882 impl
->_obj
._container
._generic
.info_log
= _mesa_strdup (
883 "Error: One or more shaders has not successfully compiled.\n");
887 impl
->_obj
.link_status
= _slang_link (&impl
->_obj
.prog
, code
, count
);
888 if (!impl
->_obj
.link_status
)
890 impl
->_obj
._container
._generic
.info_log
= _mesa_strdup ("Link failed.\n");
894 impl
->_obj
._container
._generic
.info_log
= _mesa_strdup ("Link OK.\n");
899 _program_Validate (struct gl2_program_intf
**intf
)
901 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
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
;
911 write_common_fixed (slang_program
*pro
, GLuint index
, const GLvoid
*src
, GLuint off
, GLuint size
)
915 for (i
= 0; i
< SLANG_SHADER_MAX
; i
++)
919 addr
= pro
->common_fixed_entries
[i
][index
];
924 dst
= (GLubyte
*) pro
->machines
[i
]->mem
+ addr
+ off
* size
;
925 _mesa_memcpy (dst
, src
, size
);
931 write_common_fixed_mat4 (slang_program
*pro
, GLmatrix
*matrix
, GLuint off
, GLuint i
, GLuint ii
,
932 GLuint it
, GLuint iit
)
936 /* we want inverse matrix */
939 /* allocate inverse matrix and make it dirty */
940 _math_matrix_alloc_inv (matrix
);
941 _math_matrix_loadf (matrix
, matrix
->m
);
943 _math_matrix_analyse (matrix
);
945 write_common_fixed (pro
, i
, matrix
->m
, off
, 16 * sizeof (GLfloat
));
948 write_common_fixed (pro
, ii
, matrix
->inv
, off
, 16 * sizeof (GLfloat
));
951 _math_transposef (mat
, matrix
->m
);
952 write_common_fixed (pro
, it
, mat
, off
, 16 * sizeof (GLfloat
));
954 /* inverse transpose */
955 _math_transposef (mat
, matrix
->inv
);
956 write_common_fixed (pro
, iit
, mat
, off
, 16 * sizeof (GLfloat
));
960 write_common_fixed_material (GLcontext
*ctx
, slang_program
*pro
, GLuint i
, GLuint e
, GLuint a
,
961 GLuint d
, GLuint sp
, GLuint sh
)
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
));
974 write_common_fixed_light_model_product (GLcontext
*ctx
, slang_program
*pro
, GLuint i
, GLuint e
,
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
));
985 write_common_fixed_light_product (GLcontext
*ctx
, slang_program
*pro
, GLuint off
, GLuint i
, GLuint a
,
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
));
997 _program_UpdateFixedUniforms (struct gl2_program_intf
**intf
)
999 GET_CURRENT_CONTEXT(ctx
);
1000 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1001 slang_program
*pro
= &impl
->_obj
.prog
;
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
);
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
);
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
);
1027 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
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
);
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
));
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
));
1057 /* NORMAL matrix - upper 3x3 inverse transpose of MODELVIEW matrix */
1058 p
= ctx
->ModelviewMatrixStack
.Top
->inv
;
1068 write_common_fixed (pro
, SLANG_COMMON_FIXED_NORMALMATRIX
, v
, 0, 9 * sizeof (GLfloat
));
1071 write_common_fixed (pro
, SLANG_COMMON_FIXED_NORMALSCALE
, &ctx
->_ModelViewInvScale
, 0, sizeof (GLfloat
));
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
));
1080 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++)
1082 write_common_fixed (pro
, SLANG_COMMON_FIXED_CLIPPLANE
, ctx
->Transform
.EyeUserPlane
[i
], i
,
1083 4 * sizeof (GLfloat
));
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
));
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
);
1108 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++)
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));
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
));
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
);
1139 /* light model parameters */
1140 write_common_fixed (pro
, SLANG_COMMON_FIXED_LIGHTMODEL
, ctx
->Light
.Model
.Ambient
, 0, 4 * sizeof (GLfloat
));
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
);
1150 /* TEXTURE_ENV_COLOR */
1151 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++)
1153 write_common_fixed (pro
, SLANG_COMMON_FIXED_TEXTUREENVCOLOR
, ctx
->Texture
.Unit
[i
].EnvColor
,
1154 i
, 4 * sizeof (GLfloat
));
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
));
1167 _program_UpdateFixedAttrib (struct gl2_program_intf
**intf
, GLuint index
, GLvoid
*data
,
1168 GLuint offset
, GLuint size
, GLboolean write
)
1170 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1171 slang_program
*pro
= &impl
->_obj
.prog
;
1174 addr
= pro
->vertex_fixed_entries
[index
];
1179 mem
= (GLubyte
*) pro
->machines
[SLANG_SHADER_VERTEX
]->mem
+ addr
+ offset
* size
;
1181 _mesa_memcpy (mem
, data
, size
);
1183 _mesa_memcpy (data
, mem
, size
);
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
1201 _program_UpdateFixedVarying(struct gl2_program_intf
**intf
, GLuint index
,
1203 GLuint offset
, GLuint size
, GLboolean write
)
1205 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1206 slang_program
*pro
= &impl
->_obj
.prog
;
1209 addr
= pro
->fragment_fixed_entries
[index
];
1214 mem
= (GLubyte
*) pro
->machines
[SLANG_SHADER_FRAGMENT
]->mem
+ addr
+ offset
* size
;
1216 _mesa_memcpy (mem
, data
, size
);
1218 _mesa_memcpy (data
, mem
, size
);
1223 _program_GetTextureImageUsage (struct gl2_program_intf
**intf
, GLbitfield
*teximageusage
)
1225 GET_CURRENT_CONTEXT(ctx
);
1226 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1227 slang_program
*pro
= &impl
->_obj
.prog
;
1230 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++)
1231 teximageusage
[i
] = 0;
1233 for (i
= 0; i
< pro
->texture_usage
.count
; i
++)
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
++)
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
)
1248 switch (slang_export_data_quant_type (pro
->texture_usage
.table
[i
].quant
))
1250 case GL_SAMPLER_1D_ARB
:
1251 case GL_SAMPLER_1D_SHADOW_ARB
:
1252 teximageusage
[image
] |= TEXTURE_1D_BIT
;
1254 case GL_SAMPLER_2D_ARB
:
1255 case GL_SAMPLER_2D_SHADOW_ARB
:
1256 teximageusage
[image
] |= TEXTURE_2D_BIT
;
1258 case GL_SAMPLER_3D_ARB
:
1259 teximageusage
[image
] |= TEXTURE_3D_BIT
;
1261 case GL_SAMPLER_CUBE_ARB
:
1262 teximageusage
[image
] |= TEXTURE_CUBE_BIT
;
1269 /* TODO: make sure that for 0<=i<=MaxTextureImageUint bitcount(teximageuint[i])<=0 */
1273 _program_IsShaderPresent (struct gl2_program_intf
**intf
, GLenum subtype
)
1275 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1276 slang_program
*pro
= &impl
->_obj
.prog
;
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
;
1290 get_active_variable (slang_active_variable
*var
, GLsizei maxLength
, GLsizei
*length
, GLint
*size
,
1291 GLenum
*type
, GLchar
*name
)
1295 len
= _mesa_strlen (var
->name
);
1296 if (len
>= maxLength
)
1297 len
= maxLength
- 1;
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
);
1307 get_active_variable_max_length (slang_active_variables
*vars
)
1311 for (i
= 0; i
< vars
->count
; i
++)
1313 GLuint n
= _mesa_strlen (vars
->table
[i
].name
);
1321 _program_GetActiveUniform (struct gl2_program_intf
**intf
, GLuint index
, GLsizei maxLength
,
1322 GLsizei
*length
, GLint
*size
, GLenum
*type
, GLchar
*name
)
1324 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1325 slang_active_variable
*u
= &impl
->_obj
.prog
.active_uniforms
.table
[index
];
1327 get_active_variable (u
, maxLength
, length
, size
, type
, name
);
1331 _program_GetActiveUniformMaxLength (struct gl2_program_intf
**intf
)
1333 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1335 return get_active_variable_max_length (&impl
->_obj
.prog
.active_uniforms
);
1339 _program_GetActiveUniformCount (struct gl2_program_intf
**intf
)
1341 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1343 return impl
->_obj
.prog
.active_uniforms
.count
;
1347 _program_GetUniformLocation (struct gl2_program_intf
**intf
, const GLchar
*name
)
1349 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1350 slang_uniform_bindings
*bind
= &impl
->_obj
.prog
.uniforms
;
1353 for (i
= 0; i
< bind
->count
; i
++)
1354 if (_mesa_strcmp (bind
->table
[i
].name
, name
) == 0)
1360 _program_WriteUniform (struct gl2_program_intf
**intf
, GLint loc
, GLsizei count
, const GLvoid
*data
,
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
;
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
;
1374 if (loc
>= uniforms
->count
)
1377 uniform
= &uniforms
->table
[loc
];
1378 /* TODO: check sizes */
1379 if (slang_export_data_quant_struct (uniform
->quant
))
1382 switch (slang_export_data_quant_type (uniform
->quant
))
1385 types_match
= (type
== GL_FLOAT
) || (type
== GL_INT
);
1386 if (type
== GL_FLOAT
)
1387 convert_float_to_bool
= GL_TRUE
;
1389 convert_int_to_bool
= GL_TRUE
;
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
;
1396 convert_int_to_bool
= GL_TRUE
;
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
;
1403 convert_int_to_bool
= GL_TRUE
;
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
;
1410 convert_int_to_bool
= GL_TRUE
;
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
);
1421 types_match
= (type
== slang_export_data_quant_type (uniform
->quant
));
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
;
1438 if (convert_float_to_bool
)
1440 for (i
= 0; i
< SLANG_SHADER_MAX
; i
++)
1441 if (uniform
->address
[i
] != ~0)
1443 const GLfloat
*src
= (GLfloat
*) (data
);
1444 GLfloat
*dst
= (GLfloat
*)
1445 (&impl
->_obj
.prog
.machines
[i
]->mem
[uniform
->address
[i
] / 4]);
1447 GLuint total
= count
* slang_export_data_quant_components (uniform
->quant
);
1449 for (j
= 0; j
< total
; j
++)
1450 dst
[j
] = src
[j
] != 0.0f
? 1.0f
: 0.0f
;
1453 else if (convert_int_to_bool
)
1455 for (i
= 0; i
< SLANG_SHADER_MAX
; i
++)
1456 if (uniform
->address
[i
] != ~0)
1458 const GLuint
*src
= (GLuint
*) (data
);
1459 GLfloat
*dst
= (GLfloat
*)
1460 (&impl
->_obj
.prog
.machines
[i
]->mem
[uniform
->address
[i
] / 4]);
1462 GLuint total
= count
* slang_export_data_quant_components (uniform
->quant
);
1464 for (j
= 0; j
< total
; j
++)
1465 dst
[j
] = src
[j
] ? 1.0f
: 0.0f
;
1468 else if (convert_int_to_float
)
1470 for (i
= 0; i
< SLANG_SHADER_MAX
; i
++)
1471 if (uniform
->address
[i
] != ~0)
1473 const GLuint
*src
= (GLuint
*) (data
);
1474 GLfloat
*dst
= (GLfloat
*)
1475 (&impl
->_obj
.prog
.machines
[i
]->mem
[uniform
->address
[i
] / 4]);
1477 GLuint total
= count
* slang_export_data_quant_components (uniform
->quant
);
1479 for (j
= 0; j
< total
; j
++)
1480 dst
[j
] = (GLfloat
) src
[j
];
1485 for (i
= 0; i
< SLANG_SHADER_MAX
; i
++)
1486 if (uniform
->address
[i
] != ~0)
1488 _mesa_memcpy (&impl
->_obj
.prog
.machines
[i
]->mem
[uniform
->address
[i
] / 4], data
,
1489 count
* slang_export_data_quant_size (uniform
->quant
));
1496 _program_GetActiveAttrib (struct gl2_program_intf
**intf
, GLuint index
, GLsizei maxLength
,
1497 GLsizei
*length
, GLint
*size
, GLenum
*type
, GLchar
*name
)
1499 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1500 slang_active_variable
*a
= &impl
->_obj
.prog
.active_attribs
.table
[index
];
1502 get_active_variable (a
, maxLength
, length
, size
, type
, name
);
1506 _program_GetActiveAttribMaxLength (struct gl2_program_intf
**intf
)
1508 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1510 return get_active_variable_max_length (&impl
->_obj
.prog
.active_attribs
);
1514 _program_GetActiveAttribCount (struct gl2_program_intf
**intf
)
1516 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1518 return impl
->_obj
.prog
.active_attribs
.count
;
1522 _program_GetAttribLocation (struct gl2_program_intf
**intf
, const GLchar
*name
)
1524 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1525 slang_attrib_bindings
*attribs
= &impl
->_obj
.prog
.attribs
;
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
;
1535 _program_OverrideAttribBinding (struct gl2_program_intf
**intf
, GLuint index
, const GLchar
*name
)
1537 GET_CURRENT_CONTEXT(ctx
);
1538 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1539 slang_program
*pro
= &impl
->_obj
.prog
;
1541 if (!_slang_attrib_overrides_add (&pro
->attrib_overrides
, index
, name
))
1542 _mesa_error (ctx
, GL_OUT_OF_MEMORY
, "_program_OverrideAttribBinding");
1546 _program_WriteAttrib (struct gl2_program_intf
**intf
, GLuint index
, const GLfloat
*value
)
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
];
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.
1561 if (slot
->addr
!= ~0)
1562 _mesa_memcpy (&pro
->machines
[SLANG_SHADER_VERTEX
]->mem
[slot
->addr
/ 4]._float
, value
,
1563 slot
->fill
* sizeof (GLfloat
));
1567 _program_UpdateVarying (struct gl2_program_intf
**intf
, GLuint index
, GLfloat
*value
,
1570 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1571 slang_program
*pro
= &impl
->_obj
.prog
;
1574 if (index
>= pro
->varyings
.slot_count
)
1577 addr
= pro
->varyings
.slots
[index
].vert_addr
/ 4;
1579 addr
= pro
->varyings
.slots
[index
].frag_addr
/ 4;
1583 *value
= pro
->machines
[SLANG_SHADER_VERTEX
]->mem
[addr
]._float
;
1585 pro
->machines
[SLANG_SHADER_FRAGMENT
]->mem
[addr
]._float
= *value
;
1589 static struct gl2_program_intf _program_vftbl
= {
1595 _program_QueryInterface
1600 _generic_GetDeleteStatus
,
1601 _generic_GetInfoLog
,
1602 _generic_GetInfoLogLength
1606 _container_GetAttachedCount
,
1607 _container_GetAttached
1609 _program_GetLinkStatus
,
1610 _program_GetValidateStatus
,
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
1633 _program_constructor (struct gl2_program_impl
*impl
)
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 ();
1644 _slang_program_ctr (&impl
->_obj
.prog
);
1647 struct gl2_fragment_shader_obj
1649 struct gl2_shader_obj _shader
;
1652 struct gl2_fragment_shader_impl
1654 struct gl2_fragment_shader_intf
*_vftbl
;
1655 struct gl2_fragment_shader_obj _obj
;
1659 _fragment_shader_destructor (struct gl2_unknown_intf
**intf
)
1661 struct gl2_fragment_shader_impl
*impl
= (struct gl2_fragment_shader_impl
*) intf
;
1664 /* TODO free fragment shader data */
1666 _shader_destructor (intf
);
1669 static struct gl2_unknown_intf
**
1670 _fragment_shader_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
1672 if (uiid
== UIID_FRAGMENT_SHADER
)
1674 (**intf
).AddRef (intf
);
1677 return _shader_QueryInterface (intf
, uiid
);
1681 _fragment_shader_GetSubType (struct gl2_shader_intf
**intf
)
1683 return GL_FRAGMENT_SHADER_ARB
;
1686 static struct gl2_fragment_shader_intf _fragment_shader_vftbl
= {
1692 _fragment_shader_QueryInterface
1697 _generic_GetDeleteStatus
,
1699 _shader_GetInfoLogLength
1701 _fragment_shader_GetSubType
,
1702 _shader_GetCompileStatus
,
1710 _fragment_shader_constructor (struct gl2_fragment_shader_impl
*impl
)
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);
1720 struct gl2_vertex_shader_obj
1722 struct gl2_shader_obj _shader
;
1725 struct gl2_vertex_shader_impl
1727 struct gl2_vertex_shader_intf
*_vftbl
;
1728 struct gl2_vertex_shader_obj _obj
;
1732 _vertex_shader_destructor (struct gl2_unknown_intf
**intf
)
1734 struct gl2_vertex_shader_impl
*impl
= (struct gl2_vertex_shader_impl
*) intf
;
1737 /* TODO free vertex shader data */
1739 _shader_destructor (intf
);
1742 static struct gl2_unknown_intf
**
1743 _vertex_shader_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
1745 if (uiid
== UIID_VERTEX_SHADER
)
1747 (**intf
).AddRef (intf
);
1750 return _shader_QueryInterface (intf
, uiid
);
1754 _vertex_shader_GetSubType (struct gl2_shader_intf
**intf
)
1756 return GL_VERTEX_SHADER_ARB
;
1759 static struct gl2_vertex_shader_intf _vertex_shader_vftbl
= {
1765 _vertex_shader_QueryInterface
1770 _generic_GetDeleteStatus
,
1772 _shader_GetInfoLogLength
1774 _vertex_shader_GetSubType
,
1775 _shader_GetCompileStatus
,
1783 _vertex_shader_constructor (struct gl2_vertex_shader_impl
*impl
)
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);
1793 struct gl2_debug_obj
1795 struct gl2_generic_obj _generic
;
1798 struct gl2_debug_impl
1800 struct gl2_debug_intf
*_vftbl
;
1801 struct gl2_debug_obj _obj
;
1805 _debug_destructor (struct gl2_unknown_intf
**intf
)
1807 struct gl2_debug_impl
*impl
= (struct gl2_debug_impl
*) (intf
);
1812 _generic_destructor (intf
);
1815 static struct gl2_unknown_intf
**
1816 _debug_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
1818 if (uiid
== UIID_DEBUG
) {
1819 (**intf
).AddRef (intf
);
1822 return _generic_QueryInterface (intf
, uiid
);
1826 _debug_GetType (struct gl2_generic_intf
**intf
)
1828 return /*GL_DEBUG_OBJECT_MESA*/0;
1832 _debug_ClearDebugLog (struct gl2_debug_intf
**intf
, GLenum logType
, GLenum shaderType
)
1834 struct gl2_debug_impl
*impl
= (struct gl2_debug_impl
*) (intf
);
1841 _debug_GetDebugLog (struct gl2_debug_intf
**intf
, GLenum logType
, GLenum shaderType
,
1842 GLsizei maxLength
, GLsizei
*length
, GLcharARB
*infoLog
)
1844 struct gl2_debug_impl
*impl
= (struct gl2_debug_impl
*) (intf
);
1851 _debug_GetDebugLogLength (struct gl2_debug_intf
**intf
, GLenum logType
, GLenum shaderType
)
1853 struct gl2_debug_impl
*impl
= (struct gl2_debug_impl
*) (intf
);
1861 static struct gl2_debug_intf _debug_vftbl
= {
1866 _debug_QueryInterface
1871 _generic_GetDeleteStatus
,
1872 _generic_GetInfoLog
,
1873 _generic_GetInfoLogLength
1875 _debug_ClearDebugLog
,
1877 _debug_GetDebugLogLength
1881 _debug_constructor (struct gl2_debug_impl
*impl
)
1883 _generic_constructor ((struct gl2_generic_impl
*) (impl
));
1884 impl
->_vftbl
= &_debug_vftbl
;
1885 impl
->_obj
._generic
._unknown
._destructor
= _debug_destructor
;
1889 _mesa_3dlabs_create_shader_object (GLenum shaderType
)
1893 case GL_FRAGMENT_SHADER_ARB
:
1895 struct gl2_fragment_shader_impl
*x
= (struct gl2_fragment_shader_impl
*)
1896 _mesa_malloc (sizeof (struct gl2_fragment_shader_impl
));
1900 _fragment_shader_constructor (x
);
1901 return x
->_obj
._shader
._generic
.name
;
1905 case GL_VERTEX_SHADER_ARB
:
1907 struct gl2_vertex_shader_impl
*x
= (struct gl2_vertex_shader_impl
*)
1908 _mesa_malloc (sizeof (struct gl2_vertex_shader_impl
));
1912 _vertex_shader_constructor (x
);
1913 return x
->_obj
._shader
._generic
.name
;
1923 _mesa_3dlabs_create_program_object (void)
1925 struct gl2_program_impl
*x
= (struct gl2_program_impl
*)
1926 _mesa_malloc (sizeof (struct gl2_program_impl
));
1930 _program_constructor (x
);
1931 return x
->_obj
._container
._generic
.name
;
1938 _mesa_3dlabs_create_debug_object (GLvoid
)
1940 struct gl2_debug_impl
*obj
;
1942 obj
= (struct gl2_debug_impl
*) (_mesa_malloc (sizeof (struct gl2_debug_impl
)));
1944 _debug_constructor (obj
);
1945 return obj
->_obj
._generic
.name
;
1950 #include "slang_assemble.h"
1951 #include "slang_execute.h"
1953 int _slang_fetch_discard (struct gl2_program_intf
**pro
, GLboolean
*val
)
1955 struct gl2_program_impl
*impl
;
1957 impl
= (struct gl2_program_impl
*) pro
;
1958 *val
= impl
->_obj
.prog
.machines
[SLANG_SHADER_FRAGMENT
]->kill
? GL_TRUE
: GL_FALSE
;
1962 static GLvoid
exec_shader (struct gl2_program_intf
**pro
, GLuint i
)
1964 struct gl2_program_impl
*impl
;
1967 impl
= (struct gl2_program_impl
*) pro
;
1968 p
= &impl
->_obj
.prog
;
1970 slang_machine_init (p
->machines
[i
]);
1971 p
->machines
[i
]->ip
= p
->code
[i
][SLANG_COMMON_CODE_MAIN
];
1973 _slang_execute2 (p
->assemblies
[i
], p
->machines
[i
]);
1976 GLvoid
_slang_exec_fragment_shader (struct gl2_program_intf
**pro
)
1978 exec_shader (pro
, SLANG_SHADER_FRAGMENT
);
1981 GLvoid
_slang_exec_vertex_shader (struct gl2_program_intf
**pro
)
1983 exec_shader (pro
, SLANG_SHADER_VERTEX
);
1989 _mesa_init_shaderobjects_3dlabs (GLcontext
*ctx
)
1991 #if USE_3DLABS_FRONTEND
1992 _glslang_3dlabs_InitProcess ();
1993 _glslang_3dlabs_ShInitialize ();