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"
39 #if USE_3DLABS_FRONTEND
40 #include "slang_mesa.h"
41 #include "Public/ShaderLang.h"
43 #include "slang_link.h"
46 struct gl2_unknown_obj
48 GLuint reference_count
;
49 void (* _destructor
) (struct gl2_unknown_intf
**);
52 struct gl2_unknown_impl
54 struct gl2_unknown_intf
*_vftbl
;
55 struct gl2_unknown_obj _obj
;
59 _unknown_destructor (struct gl2_unknown_intf
**intf
)
64 _unknown_AddRef (struct gl2_unknown_intf
**intf
)
66 struct gl2_unknown_impl
*impl
= (struct gl2_unknown_impl
*) intf
;
68 impl
->_obj
.reference_count
++;
72 _unknown_Release (struct gl2_unknown_intf
**intf
)
74 struct gl2_unknown_impl
*impl
= (struct gl2_unknown_impl
*) intf
;
76 impl
->_obj
.reference_count
--;
77 if (impl
->_obj
.reference_count
== 0)
79 impl
->_obj
._destructor (intf
);
80 _mesa_free ((void *) intf
);
84 static struct gl2_unknown_intf
**
85 _unknown_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
87 if (uiid
== UIID_UNKNOWN
)
89 (**intf
).AddRef (intf
);
95 static struct gl2_unknown_intf _unknown_vftbl
= {
98 _unknown_QueryInterface
102 _unknown_constructor (struct gl2_unknown_impl
*impl
)
104 impl
->_vftbl
= &_unknown_vftbl
;
105 impl
->_obj
.reference_count
= 1;
106 impl
->_obj
._destructor
= _unknown_destructor
;
109 struct gl2_unkinner_obj
111 struct gl2_unknown_intf
**unkouter
;
114 struct gl2_unkinner_impl
116 struct gl2_unknown_intf
*_vftbl
;
117 struct gl2_unkinner_obj _obj
;
121 _unkinner_destructor (struct gl2_unknown_intf
**intf
)
126 _unkinner_AddRef (struct gl2_unknown_intf
**intf
)
128 struct gl2_unkinner_impl
*impl
= (struct gl2_unkinner_impl
*) intf
;
130 (**impl
->_obj
.unkouter
).AddRef (impl
->_obj
.unkouter
);
134 _unkinner_Release (struct gl2_unknown_intf
**intf
)
136 struct gl2_unkinner_impl
*impl
= (struct gl2_unkinner_impl
*) intf
;
138 (**impl
->_obj
.unkouter
).Release (impl
->_obj
.unkouter
);
141 static struct gl2_unknown_intf
**
142 _unkinner_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
144 struct gl2_unkinner_impl
*impl
= (struct gl2_unkinner_impl
*) intf
;
146 return (**impl
->_obj
.unkouter
).QueryInterface (impl
->_obj
.unkouter
, uiid
);
149 static struct gl2_unknown_intf _unkinner_vftbl
= {
152 _unkinner_QueryInterface
156 _unkinner_constructor (struct gl2_unkinner_impl
*impl
, struct gl2_unknown_intf
**outer
)
158 impl
->_vftbl
= &_unkinner_vftbl
;
159 impl
->_obj
.unkouter
= outer
;
162 struct gl2_generic_obj
164 struct gl2_unknown_obj _unknown
;
166 GLboolean delete_status
;
170 struct gl2_generic_impl
172 struct gl2_generic_intf
*_vftbl
;
173 struct gl2_generic_obj _obj
;
177 _generic_destructor (struct gl2_unknown_intf
**intf
)
179 GET_CURRENT_CONTEXT(ctx
);
180 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
182 _mesa_free ((void *) impl
->_obj
.info_log
);
184 _glthread_LOCK_MUTEX (ctx
->Shared
->Mutex
);
185 _mesa_HashRemove (ctx
->Shared
->GL2Objects
, impl
->_obj
.name
);
186 _glthread_UNLOCK_MUTEX (ctx
->Shared
->Mutex
);
188 _unknown_destructor (intf
);
191 static struct gl2_unknown_intf
**
192 _generic_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
194 if (uiid
== UIID_GENERIC
)
196 (**intf
).AddRef (intf
);
199 return _unknown_QueryInterface (intf
, uiid
);
203 _generic_Delete (struct gl2_generic_intf
**intf
)
205 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
207 if (impl
->_obj
.delete_status
== GL_FALSE
)
209 impl
->_obj
.delete_status
= GL_TRUE
;
210 (**intf
)._unknown
.Release ((struct gl2_unknown_intf
**) intf
);
215 _generic_GetName (struct gl2_generic_intf
**intf
)
217 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
219 return impl
->_obj
.name
;
223 _generic_GetDeleteStatus (struct gl2_generic_intf
**intf
)
225 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
227 return impl
->_obj
.delete_status
;
230 static const GLcharARB
*
231 _generic_GetInfoLog (struct gl2_generic_intf
**intf
)
233 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
235 return impl
->_obj
.info_log
;
238 static struct gl2_generic_intf _generic_vftbl
= {
242 _generic_QueryInterface
245 NULL
, /* abstract GetType */
247 _generic_GetDeleteStatus
,
252 _generic_constructor (struct gl2_generic_impl
*impl
)
254 GET_CURRENT_CONTEXT(ctx
);
256 _unknown_constructor ((struct gl2_unknown_impl
*) impl
);
257 impl
->_vftbl
= &_generic_vftbl
;
258 impl
->_obj
._unknown
._destructor
= _generic_destructor
;
259 impl
->_obj
.delete_status
= GL_FALSE
;
260 impl
->_obj
.info_log
= NULL
;
262 _glthread_LOCK_MUTEX (ctx
->Shared
->Mutex
);
263 impl
->_obj
.name
= _mesa_HashFindFreeKeyBlock (ctx
->Shared
->GL2Objects
, 1);
264 _mesa_HashInsert (ctx
->Shared
->GL2Objects
, impl
->_obj
.name
, (void *) impl
);
265 _glthread_UNLOCK_MUTEX (ctx
->Shared
->Mutex
);
268 struct gl2_container_obj
270 struct gl2_generic_obj _generic
;
271 struct gl2_generic_intf
***attached
;
272 GLuint attached_count
;
275 struct gl2_container_impl
277 struct gl2_container_intf
*_vftbl
;
278 struct gl2_container_obj _obj
;
282 _container_destructor (struct gl2_unknown_intf
**intf
)
284 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
287 for (i
= 0; i
< impl
->_obj
.attached_count
; i
++)
289 struct gl2_generic_intf
**x
= impl
->_obj
.attached
[i
];
290 (**x
)._unknown
.Release ((struct gl2_unknown_intf
**) x
);
293 _generic_destructor (intf
);
296 static struct gl2_unknown_intf
**
297 _container_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
299 if (uiid
== UIID_CONTAINER
)
301 (**intf
).AddRef (intf
);
304 return _generic_QueryInterface (intf
, uiid
);
308 _container_Attach (struct gl2_container_intf
**intf
, struct gl2_generic_intf
**att
)
310 GET_CURRENT_CONTEXT(ctx
);
311 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
314 for (i
= 0; i
< impl
->_obj
.attached_count
; i
++)
315 if (impl
->_obj
.attached
[i
] == att
)
317 _mesa_error (ctx
, GL_INVALID_OPERATION
, "_container_Attach");
321 impl
->_obj
.attached
= (struct gl2_generic_intf
***) _mesa_realloc (impl
->_obj
.attached
,
322 impl
->_obj
.attached_count
* sizeof (*impl
->_obj
.attached
), (impl
->_obj
.attached_count
+ 1) *
323 sizeof (*impl
->_obj
.attached
));
324 if (impl
->_obj
.attached
== NULL
)
327 impl
->_obj
.attached
[impl
->_obj
.attached_count
] = att
;
328 impl
->_obj
.attached_count
++;
329 (**att
)._unknown
.AddRef ((struct gl2_unknown_intf
**) att
);
334 _container_Detach (struct gl2_container_intf
**intf
, struct gl2_generic_intf
**att
)
336 GET_CURRENT_CONTEXT(ctx
);
337 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
340 for (i
= 0; i
< impl
->_obj
.attached_count
; i
++)
341 if (impl
->_obj
.attached
[i
] == att
)
343 for (j
= i
; j
< impl
->_obj
.attached_count
- 1; j
++)
344 impl
->_obj
.attached
[j
] = impl
->_obj
.attached
[j
+ 1];
345 impl
->_obj
.attached
= (struct gl2_generic_intf
***) _mesa_realloc (impl
->_obj
.attached
,
346 impl
->_obj
.attached_count
* sizeof (*impl
->_obj
.attached
),
347 (impl
->_obj
.attached_count
- 1) * sizeof (*impl
->_obj
.attached
));
348 impl
->_obj
.attached_count
--;
349 (**att
)._unknown
.Release ((struct gl2_unknown_intf
**) att
);
353 _mesa_error (ctx
, GL_INVALID_OPERATION
, "_container_Detach");
358 _container_GetAttachedCount (struct gl2_container_intf
**intf
)
360 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
362 return impl
->_obj
.attached_count
;
365 static struct gl2_generic_intf
**
366 _container_GetAttached (struct gl2_container_intf
**intf
, GLuint index
)
368 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
370 (**impl
->_obj
.attached
[index
])._unknown
.AddRef (
371 (struct gl2_unknown_intf
**)impl
->_obj
.attached
[index
]);
372 return impl
->_obj
.attached
[index
];
375 static struct gl2_container_intf _container_vftbl
= {
380 _container_QueryInterface
383 NULL
, /* abstract GetType */
385 _generic_GetDeleteStatus
,
390 _container_GetAttachedCount
,
391 _container_GetAttached
395 _container_constructor (struct gl2_container_impl
*impl
)
397 _generic_constructor ((struct gl2_generic_impl
*) impl
);
398 impl
->_vftbl
= &_container_vftbl
;
399 impl
->_obj
._generic
._unknown
._destructor
= _container_destructor
;
400 impl
->_obj
.attached
= NULL
;
401 impl
->_obj
.attached_count
= 0;
404 struct gl2_3dlabs_shhandle_obj
406 struct gl2_unkinner_obj _unknown
;
407 #if USE_3DLABS_FRONTEND
412 struct gl2_3dlabs_shhandle_impl
414 struct gl2_3dlabs_shhandle_intf
*_vftbl
;
415 struct gl2_3dlabs_shhandle_obj _obj
;
419 _3dlabs_shhandle_destructor (struct gl2_unknown_intf
**intf
)
421 #if USE_3DLABS_FRONTEND
422 struct gl2_3dlabs_shhandle_impl
*impl
= (struct gl2_3dlabs_shhandle_impl
*) intf
;
423 ShDestruct (impl
->_obj
.handle
);
425 _unkinner_destructor (intf
);
429 _3dlabs_shhandle_GetShHandle (struct gl2_3dlabs_shhandle_intf
**intf
)
431 #if USE_3DLABS_FRONTEND
432 struct gl2_3dlabs_shhandle_impl
*impl
= (struct gl2_3dlabs_shhandle_impl
*) intf
;
433 return impl
->_obj
.handle
;
439 static struct gl2_3dlabs_shhandle_intf _3dlabs_shhandle_vftbl
= {
443 _unkinner_QueryInterface
445 _3dlabs_shhandle_GetShHandle
449 _3dlabs_shhandle_constructor (struct gl2_3dlabs_shhandle_impl
*impl
, struct gl2_unknown_intf
**outer
)
451 _unkinner_constructor ((struct gl2_unkinner_impl
*) impl
, outer
);
452 impl
->_vftbl
= &_3dlabs_shhandle_vftbl
;
453 #if USE_3DLABS_FRONTEND
454 impl
->_obj
.handle
= NULL
;
458 struct gl2_shader_obj
460 struct gl2_generic_obj _generic
;
461 struct gl2_3dlabs_shhandle_impl _3dlabs_shhandle
;
462 GLboolean compile_status
;
465 GLsizei offset_count
;
466 slang_translation_unit unit
;
469 struct gl2_shader_impl
471 struct gl2_shader_intf
*_vftbl
;
472 struct gl2_shader_obj _obj
;
476 _shader_destructor (struct gl2_unknown_intf
**intf
)
478 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
480 _mesa_free ((void *) impl
->_obj
.source
);
481 _mesa_free ((void *) impl
->_obj
.offsets
);
482 _3dlabs_shhandle_destructor ((struct gl2_unknown_intf
**) &impl
->_obj
._3dlabs_shhandle
._vftbl
);
483 _generic_destructor (intf
);
486 static struct gl2_unknown_intf
**
487 _shader_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
489 #if USE_3DLABS_FRONTEND
490 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
493 if (uiid
== UIID_SHADER
)
495 (**intf
).AddRef (intf
);
498 #if USE_3DLABS_FRONTEND
499 if (uiid
== UIID_3DLABS_SHHANDLE
)
501 (**intf
).AddRef (intf
);
502 return (struct gl2_unknown_intf
**) &impl
->_obj
._3dlabs_shhandle
._vftbl
;
505 return _generic_QueryInterface (intf
, uiid
);
509 _shader_GetType (struct gl2_generic_intf
**intf
)
511 return GL_SHADER_OBJECT_ARB
;
515 _shader_GetCompileStatus (struct gl2_shader_intf
**intf
)
517 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
519 return impl
->_obj
.compile_status
;
523 _shader_SetSource (struct gl2_shader_intf
**intf
, GLcharARB
*src
, GLint
*off
, GLsizei cnt
)
525 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
527 _mesa_free ((void *) impl
->_obj
.source
);
528 impl
->_obj
.source
= src
;
529 _mesa_free ((void *) impl
->_obj
.offsets
);
530 impl
->_obj
.offsets
= off
;
531 impl
->_obj
.offset_count
= cnt
;
534 static const GLcharARB
*
535 _shader_GetSource (struct gl2_shader_intf
**intf
)
537 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
539 return impl
->_obj
.source
;
543 _shader_Compile (struct gl2_shader_intf
**intf
)
545 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
546 #if USE_3DLABS_FRONTEND
548 TBuiltInResource res
;
550 slang_unit_type type
;
551 slang_info_log info_log
;
554 impl
->_obj
.compile_status
= GL_FALSE
;
555 _mesa_free ((void *) impl
->_obj
._generic
.info_log
);
556 impl
->_obj
._generic
.info_log
= NULL
;
558 #if USE_3DLABS_FRONTEND
559 /* 3dlabs compiler expects us to feed it with null-terminated string array,
560 we've got only one big string with offsets, so we must split it; but when
561 there's only one string to deal with, we pass its address directly */
563 if (impl
->_obj
.offset_count
<= 1)
564 strings
= &impl
->_obj
.source
;
567 GLsizei i
, offset
= 0;
569 strings
= (char **) _mesa_malloc (impl
->_obj
.offset_count
* sizeof (char *));
573 for (i
= 0; i
< impl
->_obj
.offset_count
; i
++)
575 GLsizei size
= impl
->_obj
.offsets
[i
] - offset
;
577 strings
[i
] = (char *) _mesa_malloc ((size
+ 1) * sizeof (char));
578 if (strings
[i
] == NULL
)
582 for (j
= 0; j
< i
; j
++)
583 _mesa_free (strings
[j
]);
584 _mesa_free (strings
);
588 _mesa_memcpy (strings
[i
], impl
->_obj
.source
+ offset
, size
* sizeof (char));
589 strings
[i
][size
] = '\0';
590 offset
= impl
->_obj
.offsets
[i
];
594 /* TODO set these fields to some REAL numbers */
596 res
.maxClipPlanes
= 6;
597 res
.maxTextureUnits
= 2;
598 res
.maxTextureCoords
= 2;
599 res
.maxVertexAttribs
= 8;
600 res
.maxVertexUniformComponents
= 64;
601 res
.maxVaryingFloats
= 8;
602 res
.maxVertexTextureImageUnits
= 2;
603 res
.maxCombinedTextureImageUnits
= 2;
604 res
.maxTextureImageUnits
= 2;
605 res
.maxFragmentUniformComponents
= 64;
606 res
.maxDrawBuffers
= 1;
608 if (ShCompile (impl
->_obj
._3dlabs_shhandle
._obj
.handle
, strings
, impl
->_obj
.offset_count
,
609 EShOptFull
, &res
, 0))
610 impl
->_obj
.compile_status
= GL_TRUE
;
611 if (impl
->_obj
.offset_count
> 1)
615 for (i
= 0; i
< impl
->_obj
.offset_count
; i
++)
616 _mesa_free (strings
[i
]);
617 _mesa_free (strings
);
620 impl
->_obj
._generic
.info_log
= _mesa_strdup (ShGetInfoLog (
621 impl
->_obj
._3dlabs_shhandle
._obj
.handle
));
623 if (impl
->_vftbl
->GetSubType (intf
) == GL_FRAGMENT_SHADER
)
624 type
= slang_unit_fragment_shader
;
626 type
= slang_unit_vertex_shader
;
627 slang_info_log_construct (&info_log
);
628 if (_slang_compile (impl
->_obj
.source
, &impl
->_obj
.unit
, type
, &info_log
))
630 impl
->_obj
.compile_status
= GL_TRUE
;
632 if (info_log
.text
!= NULL
)
633 impl
->_obj
._generic
.info_log
= _mesa_strdup (info_log
.text
);
635 impl
->_obj
._generic
.info_log
= _mesa_strdup ("");
636 slang_info_log_destruct (&info_log
);
640 static struct gl2_shader_intf _shader_vftbl
= {
645 _shader_QueryInterface
650 _generic_GetDeleteStatus
,
653 NULL
, /* abstract GetSubType */
654 _shader_GetCompileStatus
,
661 _shader_constructor (struct gl2_shader_impl
*impl
)
663 _generic_constructor ((struct gl2_generic_impl
*) impl
);
664 _3dlabs_shhandle_constructor (&impl
->_obj
._3dlabs_shhandle
, (struct gl2_unknown_intf
**)
666 impl
->_vftbl
= &_shader_vftbl
;
667 impl
->_obj
._generic
._unknown
._destructor
= _shader_destructor
;
668 impl
->_obj
.compile_status
= GL_FALSE
;
669 impl
->_obj
.source
= NULL
;
670 impl
->_obj
.offsets
= NULL
;
671 impl
->_obj
.offset_count
= 0;
674 struct gl2_program_obj
676 struct gl2_container_obj _container
;
677 GLboolean link_status
;
678 GLboolean validate_status
;
679 #if USE_3DLABS_FRONTEND
686 struct gl2_program_impl
688 struct gl2_program_intf
*_vftbl
;
689 struct gl2_program_obj _obj
;
693 _program_destructor (struct gl2_unknown_intf
**intf
)
695 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
696 #if USE_3DLABS_FRONTEND
697 ShDestruct (impl
->_obj
.linker
);
698 ShDestruct (impl
->_obj
.uniforms
);
700 _container_destructor (intf
);
701 slang_program_dtr (&impl
->_obj
.prog
);
704 static struct gl2_unknown_intf
**
705 _program_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
707 if (uiid
== UIID_PROGRAM
)
709 (**intf
).AddRef (intf
);
712 return _container_QueryInterface (intf
, uiid
);
716 _program_GetType (struct gl2_generic_intf
**intf
)
718 return GL_PROGRAM_OBJECT_ARB
;
722 _program_Attach (struct gl2_container_intf
**intf
, struct gl2_generic_intf
**att
)
724 GET_CURRENT_CONTEXT(ctx
);
725 struct gl2_unknown_intf
**sha
;
727 sha
= (**att
)._unknown
.QueryInterface ((struct gl2_unknown_intf
**) att
, UIID_SHADER
);
730 _mesa_error (ctx
, GL_INVALID_OPERATION
, "_program_Attach");
734 (**sha
).Release (sha
);
735 return _container_Attach (intf
, att
);
739 _program_GetLinkStatus (struct gl2_program_intf
**intf
)
741 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
743 return impl
->_obj
.link_status
;
747 _program_GetValidateStatus (struct gl2_program_intf
**intf
)
749 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
751 return impl
->_obj
.validate_status
;
755 _program_Link (struct gl2_program_intf
**intf
)
757 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
758 #if USE_3DLABS_FRONTEND
762 slang_translation_unit
*units
[2];
764 impl
->_obj
.link_status
= GL_FALSE
;
765 _mesa_free ((void *) impl
->_obj
._container
._generic
.info_log
);
766 impl
->_obj
._container
._generic
.info_log
= NULL
;
767 slang_program_dtr (&impl
->_obj
.prog
);
768 slang_program_ctr (&impl
->_obj
.prog
);
770 #if USE_3DLABS_FRONTEND
771 handles
= (ShHandle
*) _mesa_malloc (impl
->_obj
._container
.attached_count
* sizeof (ShHandle
));
775 for (i
= 0; i
< impl
->_obj
._container
.attached_count
; i
++)
777 struct gl2_generic_intf
**gen
= impl
->_obj
._container
.attached
[i
];
778 struct gl2_3dlabs_shhandle_intf
**sh
;
780 sh
= (struct gl2_3dlabs_shhandle_intf
**) (**gen
)._unknown
.QueryInterface (
781 (struct gl2_unknown_intf
**) gen
, UIID_3DLABS_SHHANDLE
);
784 handles
[i
] = (**sh
).GetShHandle (sh
);
785 (**sh
)._unknown
.Release ((struct gl2_unknown_intf
**) sh
);
789 _mesa_free (handles
);
794 if (ShLink (impl
->_obj
.linker
, handles
, impl
->_obj
._container
.attached_count
,
795 impl
->_obj
.uniforms
, NULL
, NULL
))
796 impl
->_obj
.link_status
= GL_TRUE
;
798 impl
->_obj
._container
._generic
.info_log
= _mesa_strdup (ShGetInfoLog (impl
->_obj
.linker
));
800 count
= impl
->_obj
._container
.attached_count
;
801 if (count
== 0 || count
> 2)
803 for (i
= 0; i
< count
; i
++)
805 struct gl2_generic_intf
**obj
;
806 struct gl2_unknown_intf
**unk
;
807 struct gl2_shader_impl
*sha
;
809 obj
= impl
->_obj
._container
.attached
[i
];
810 unk
= (**obj
)._unknown
.QueryInterface ((struct gl2_unknown_intf
**) obj
, UIID_SHADER
);
811 (**obj
)._unknown
.Release ((struct gl2_unknown_intf
**) obj
);
814 sha
= (struct gl2_shader_impl
*) unk
;
815 units
[i
] = &sha
->_obj
.unit
;
816 (**unk
).Release (unk
);
819 impl
->_obj
.link_status
= _slang_link (&impl
->_obj
.prog
, units
, count
);
820 if (impl
->_obj
.link_status
)
821 impl
->_obj
._container
._generic
.info_log
= _mesa_strdup ("Link OK.\n");
823 impl
->_obj
._container
._generic
.info_log
= _mesa_strdup ("Link failed.\n");
828 _program_Validate (struct gl2_program_intf
**intf
)
830 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
832 impl
->_obj
.validate_status
= GL_FALSE
;
833 _mesa_free ((void *) impl
->_obj
._container
._generic
.info_log
);
834 impl
->_obj
._container
._generic
.info_log
= NULL
;
840 write_common_fixed (slang_program
*pro
, GLuint index
, const GLvoid
*src
, GLuint off
, GLuint size
)
844 for (i
= 0; i
< SLANG_SHADER_MAX
; i
++)
848 addr
= pro
->common_fixed_entries
[i
][index
];
853 dst
= (GLubyte
*) pro
->machines
[i
]->mem
+ addr
+ off
* size
;
854 _mesa_memcpy (dst
, src
, size
);
860 write_common_fixed_mat4 (slang_program
*pro
, GLmatrix
*matrix
, GLuint off
, GLuint i
, GLuint ii
,
861 GLuint it
, GLuint iit
)
865 /* we want inverse matrix */
868 /* allocate inverse matrix and make it dirty */
869 _math_matrix_alloc_inv (matrix
);
870 _math_matrix_loadf (matrix
, matrix
->m
);
872 _math_matrix_analyse (matrix
);
874 write_common_fixed (pro
, i
, matrix
->m
, off
, 16 * sizeof (GLfloat
));
877 write_common_fixed (pro
, ii
, matrix
->inv
, off
, 16 * sizeof (GLfloat
));
880 _math_transposef (mat
, matrix
->m
);
881 write_common_fixed (pro
, it
, mat
, off
, 16 * sizeof (GLfloat
));
883 /* inverse transpose */
884 _math_transposef (mat
, matrix
->inv
);
885 write_common_fixed (pro
, iit
, mat
, off
, 16 * sizeof (GLfloat
));
889 write_common_fixed_material (GLcontext
*ctx
, slang_program
*pro
, GLuint i
, GLuint e
, GLuint a
,
890 GLuint d
, GLuint sp
, GLuint sh
)
894 COPY_4FV(v
, ctx
->Light
.Material
.Attrib
[e
]);
895 COPY_4FV((v
+ 4), ctx
->Light
.Material
.Attrib
[a
]);
896 COPY_4FV((v
+ 8), ctx
->Light
.Material
.Attrib
[d
]);
897 COPY_4FV((v
+ 12), ctx
->Light
.Material
.Attrib
[sp
]);
898 v
[16] = ctx
->Light
.Material
.Attrib
[sh
][0];
899 write_common_fixed (pro
, i
, v
, 0, 17 * sizeof (GLfloat
));
903 write_common_fixed_light_model_product (GLcontext
*ctx
, slang_program
*pro
, GLuint i
, GLuint e
,
908 SCALE_4V(v
, ctx
->Light
.Material
.Attrib
[a
], ctx
->Light
.Model
.Ambient
);
909 ACC_4V(v
, ctx
->Light
.Material
.Attrib
[e
]);
910 write_common_fixed (pro
, i
, v
, 0, 4 * sizeof (GLfloat
));
914 write_common_fixed_light_product (GLcontext
*ctx
, slang_program
*pro
, GLuint off
, GLuint i
, GLuint a
,
919 SCALE_4V(v
, ctx
->Light
.Light
[off
].Ambient
, ctx
->Light
.Material
.Attrib
[a
]);
920 SCALE_4V((v
+ 4), ctx
->Light
.Light
[off
].Diffuse
, ctx
->Light
.Material
.Attrib
[d
]);
921 SCALE_4V((v
+ 8), ctx
->Light
.Light
[off
].Specular
, ctx
->Light
.Material
.Attrib
[s
]);
922 write_common_fixed (pro
, i
, v
, off
, 12 * sizeof (GLfloat
));
926 _program_UpdateFixedUniforms (struct gl2_program_intf
**intf
)
928 GET_CURRENT_CONTEXT(ctx
);
929 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
930 slang_program
*pro
= &impl
->_obj
.prog
;
935 /* MODELVIEW matrix */
936 write_common_fixed_mat4 (pro
, ctx
->ModelviewMatrixStack
.Top
, 0,
937 SLANG_COMMON_FIXED_MODELVIEWMATRIX
,
938 SLANG_COMMON_FIXED_MODELVIEWMATRIXINVERSE
,
939 SLANG_COMMON_FIXED_MODELVIEWMATRIXTRANSPOSE
,
940 SLANG_COMMON_FIXED_MODELVIEWMATRIXINVERSETRANSPOSE
);
942 /* PROJECTION matrix */
943 write_common_fixed_mat4 (pro
, ctx
->ProjectionMatrixStack
.Top
, 0,
944 SLANG_COMMON_FIXED_PROJECTIONMATRIX
,
945 SLANG_COMMON_FIXED_PROJECTIONMATRIXINVERSE
,
946 SLANG_COMMON_FIXED_PROJECTIONMATRIXTRANSPOSE
,
947 SLANG_COMMON_FIXED_PROJECTIONMATRIXINVERSETRANSPOSE
);
950 write_common_fixed_mat4 (pro
, &ctx
->_ModelProjectMatrix
, 0,
951 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIX
,
952 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIXINVERSE
,
953 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIXTRANSPOSE
,
954 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIXINVERSETRANSPOSE
);
956 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++)
959 write_common_fixed_mat4 (pro
, ctx
->TextureMatrixStack
[i
].Top
, i
,
960 SLANG_COMMON_FIXED_TEXTUREMATRIX
,
961 SLANG_COMMON_FIXED_TEXTUREMATRIXINVERSE
,
962 SLANG_COMMON_FIXED_TEXTUREMATRIXTRANSPOSE
,
963 SLANG_COMMON_FIXED_TEXTUREMATRIXINVERSETRANSPOSE
);
965 /* EYE_PLANE texture-coordinate generation */
966 write_common_fixed (pro
, SLANG_COMMON_FIXED_EYEPLANES
, ctx
->Texture
.Unit
[i
].EyePlaneS
,
967 i
, 4 * sizeof (GLfloat
));
968 write_common_fixed (pro
, SLANG_COMMON_FIXED_EYEPLANET
, ctx
->Texture
.Unit
[i
].EyePlaneT
,
969 i
, 4 * sizeof (GLfloat
));
970 write_common_fixed (pro
, SLANG_COMMON_FIXED_EYEPLANER
, ctx
->Texture
.Unit
[i
].EyePlaneR
,
971 i
, 4 * sizeof (GLfloat
));
972 write_common_fixed (pro
, SLANG_COMMON_FIXED_EYEPLANEQ
, ctx
->Texture
.Unit
[i
].EyePlaneQ
,
973 i
, 4 * sizeof (GLfloat
));
975 /* OBJECT_PLANE texture-coordinate generation */
976 write_common_fixed (pro
, SLANG_COMMON_FIXED_OBJECTPLANES
, ctx
->Texture
.Unit
[i
].ObjectPlaneS
,
977 i
, 4 * sizeof (GLfloat
));
978 write_common_fixed (pro
, SLANG_COMMON_FIXED_OBJECTPLANET
, ctx
->Texture
.Unit
[i
].ObjectPlaneT
,
979 i
, 4 * sizeof (GLfloat
));
980 write_common_fixed (pro
, SLANG_COMMON_FIXED_OBJECTPLANER
, ctx
->Texture
.Unit
[i
].ObjectPlaneR
,
981 i
, 4 * sizeof (GLfloat
));
982 write_common_fixed (pro
, SLANG_COMMON_FIXED_OBJECTPLANEQ
, ctx
->Texture
.Unit
[i
].ObjectPlaneQ
,
983 i
, 4 * sizeof (GLfloat
));
986 /* NORMAL matrix - upper 3x3 inverse transpose of MODELVIEW matrix */
987 p
= ctx
->ModelviewMatrixStack
.Top
->inv
;
997 write_common_fixed (pro
, SLANG_COMMON_FIXED_NORMALMATRIX
, v
, 0, 9 * sizeof (GLfloat
));
1000 write_common_fixed (pro
, SLANG_COMMON_FIXED_NORMALSCALE
, &ctx
->_ModelViewInvScale
, 0, sizeof (GLfloat
));
1002 /* depth range parameters */
1003 v
[0] = ctx
->Viewport
.Near
;
1004 v
[1] = ctx
->Viewport
.Far
;
1005 v
[2] = ctx
->Viewport
.Far
- ctx
->Viewport
.Near
;
1006 write_common_fixed (pro
, SLANG_COMMON_FIXED_DEPTHRANGE
, v
, 0, 3 * sizeof (GLfloat
));
1009 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++)
1011 write_common_fixed (pro
, SLANG_COMMON_FIXED_CLIPPLANE
, ctx
->Transform
.EyeUserPlane
[i
], i
,
1012 4 * sizeof (GLfloat
));
1015 /* point parameters */
1016 v
[0] = ctx
->Point
.Size
;
1017 v
[1] = ctx
->Point
.MinSize
;
1018 v
[2] = ctx
->Point
.MaxSize
;
1019 v
[3] = ctx
->Point
.Threshold
;
1020 COPY_3FV((v
+ 4), ctx
->Point
.Params
);
1021 write_common_fixed (pro
, SLANG_COMMON_FIXED_POINT
, v
, 0, 7 * sizeof (GLfloat
));
1023 /* material parameters */
1024 write_common_fixed_material (ctx
, pro
, SLANG_COMMON_FIXED_FRONTMATERIAL
,
1025 MAT_ATTRIB_FRONT_EMISSION
,
1026 MAT_ATTRIB_FRONT_AMBIENT
,
1027 MAT_ATTRIB_FRONT_DIFFUSE
,
1028 MAT_ATTRIB_FRONT_SPECULAR
,
1029 MAT_ATTRIB_FRONT_SHININESS
);
1030 write_common_fixed_material (ctx
, pro
, SLANG_COMMON_FIXED_BACKMATERIAL
,
1031 MAT_ATTRIB_BACK_EMISSION
,
1032 MAT_ATTRIB_BACK_AMBIENT
,
1033 MAT_ATTRIB_BACK_DIFFUSE
,
1034 MAT_ATTRIB_BACK_SPECULAR
,
1035 MAT_ATTRIB_BACK_SHININESS
);
1037 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++)
1039 /* light source parameters */
1040 COPY_4FV(v
, ctx
->Light
.Light
[i
].Ambient
);
1041 COPY_4FV((v
+ 4), ctx
->Light
.Light
[i
].Diffuse
);
1042 COPY_4FV((v
+ 8), ctx
->Light
.Light
[i
].Specular
);
1043 COPY_4FV((v
+ 12), ctx
->Light
.Light
[i
].EyePosition
);
1044 COPY_2FV((v
+ 16), ctx
->Light
.Light
[i
].EyePosition
);
1045 v
[18] = ctx
->Light
.Light
[i
].EyePosition
[2] + 1.0f
;
1046 NORMALIZE_3FV((v
+ 16));
1048 COPY_3V((v
+ 20), ctx
->Light
.Light
[i
].EyeDirection
);
1049 v
[23] = ctx
->Light
.Light
[i
].SpotExponent
;
1050 v
[24] = ctx
->Light
.Light
[i
].SpotCutoff
;
1051 v
[25] = ctx
->Light
.Light
[i
]._CosCutoffNeg
;
1052 v
[26] = ctx
->Light
.Light
[i
].ConstantAttenuation
;
1053 v
[27] = ctx
->Light
.Light
[i
].LinearAttenuation
;
1054 v
[28] = ctx
->Light
.Light
[i
].QuadraticAttenuation
;
1055 write_common_fixed (pro
, SLANG_COMMON_FIXED_LIGHTSOURCE
, v
, i
, 29 * sizeof (GLfloat
));
1058 write_common_fixed_light_product (ctx
, pro
, i
, SLANG_COMMON_FIXED_FRONTLIGHTPRODUCT
,
1059 MAT_ATTRIB_FRONT_AMBIENT
,
1060 MAT_ATTRIB_FRONT_DIFFUSE
,
1061 MAT_ATTRIB_FRONT_SPECULAR
);
1062 write_common_fixed_light_product (ctx
, pro
, i
, SLANG_COMMON_FIXED_BACKLIGHTPRODUCT
,
1063 MAT_ATTRIB_BACK_AMBIENT
,
1064 MAT_ATTRIB_BACK_DIFFUSE
,
1065 MAT_ATTRIB_BACK_SPECULAR
);
1068 /* light model parameters */
1069 write_common_fixed (pro
, SLANG_COMMON_FIXED_LIGHTMODEL
, ctx
->Light
.Model
.Ambient
, 0, 4 * sizeof (GLfloat
));
1071 /* light model product */
1072 write_common_fixed_light_model_product (ctx
, pro
, SLANG_COMMON_FIXED_FRONTLIGHTMODELPRODUCT
,
1073 MAT_ATTRIB_FRONT_EMISSION
,
1074 MAT_ATTRIB_FRONT_AMBIENT
);
1075 write_common_fixed_light_model_product (ctx
, pro
, SLANG_COMMON_FIXED_BACKLIGHTMODELPRODUCT
,
1076 MAT_ATTRIB_BACK_EMISSION
,
1077 MAT_ATTRIB_BACK_AMBIENT
);
1079 /* TEXTURE_ENV_COLOR */
1080 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++)
1082 write_common_fixed (pro
, SLANG_COMMON_FIXED_TEXTUREENVCOLOR
, ctx
->Texture
.Unit
[i
].EnvColor
,
1083 i
, 4 * sizeof (GLfloat
));
1086 /* fog parameters */
1087 COPY_4FV(v
, ctx
->Fog
.Color
);
1088 v
[4] = ctx
->Fog
.Density
;
1089 v
[5] = ctx
->Fog
.Start
;
1090 v
[6] = ctx
->Fog
.End
;
1091 v
[7] = ctx
->Fog
._Scale
;
1092 write_common_fixed (pro
, SLANG_COMMON_FIXED_FOG
, v
, 0, 8 * sizeof (GLfloat
));
1096 _program_UpdateFixedAttribute (struct gl2_program_intf
**intf
, GLuint index
, GLvoid
*data
,
1097 GLuint offset
, GLuint size
, GLboolean write
)
1099 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1100 slang_program
*pro
= &impl
->_obj
.prog
;
1103 addr
= pro
->vertex_fixed_entries
[index
];
1108 mem
= (GLubyte
*) pro
->machines
[SLANG_SHADER_VERTEX
]->mem
+ addr
+ offset
* size
;
1110 _mesa_memcpy (mem
, data
, size
);
1112 _mesa_memcpy (data
, mem
, size
);
1117 _program_UpdateFixedVarying (struct gl2_program_intf
**intf
, GLuint index
, GLvoid
*data
,
1118 GLuint offset
, GLuint size
, GLboolean write
)
1120 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1121 slang_program
*pro
= &impl
->_obj
.prog
;
1124 addr
= pro
->fragment_fixed_entries
[index
];
1129 mem
= (GLubyte
*) pro
->machines
[SLANG_SHADER_FRAGMENT
]->mem
+ addr
+ offset
* size
;
1131 _mesa_memcpy (mem
, data
, size
);
1133 _mesa_memcpy (data
, mem
, size
);
1138 _program_GetTextureImageUsage (struct gl2_program_intf
**intf
, GLbitfield
*teximageusage
)
1140 GET_CURRENT_CONTEXT(ctx
);
1141 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1142 slang_program
*pro
= &impl
->_obj
.prog
;
1145 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++)
1146 teximageusage
[i
] = 0;
1148 for (i
= 0; i
< pro
->texture_usage
.count
; i
++)
1152 n
= pro
->texture_usage
.table
[i
].quant
->array_len
;
1155 addr
= pro
->texture_usage
.table
[i
].frag_address
;
1156 for (j
= 0; j
< n
; j
++)
1161 mem
= (GLubyte
*) pro
->machines
[SLANG_SHADER_FRAGMENT
]->mem
+ addr
+ j
* 4;
1162 image
= (GLuint
) *((GLfloat
*) mem
);
1163 if (image
>= 0 && image
< ctx
->Const
.MaxTextureImageUnits
)
1165 switch (pro
->texture_usage
.table
[i
].quant
->u
.basic_type
)
1167 case GL_SAMPLER_1D_ARB
:
1168 case GL_SAMPLER_1D_SHADOW_ARB
:
1169 teximageusage
[image
] |= TEXTURE_1D_BIT
;
1171 case GL_SAMPLER_2D_ARB
:
1172 case GL_SAMPLER_2D_SHADOW_ARB
:
1173 teximageusage
[image
] |= TEXTURE_2D_BIT
;
1175 case GL_SAMPLER_3D_ARB
:
1176 teximageusage
[image
] |= TEXTURE_3D_BIT
;
1178 case GL_SAMPLER_CUBE_ARB
:
1179 teximageusage
[image
] |= TEXTURE_CUBE_BIT
;
1186 /* TODO: make sure that for 0<=i<=MaxTextureImageUint bitcount(teximageuint[i])<=0 */
1190 _program_IsShaderPresent (struct gl2_program_intf
**intf
, GLenum subtype
)
1192 GET_CURRENT_CONTEXT(ctx
);
1193 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1194 slang_program
*pro
= &impl
->_obj
.prog
;
1198 case GL_VERTEX_SHADER_ARB
:
1199 return pro
->machines
[SLANG_SHADER_VERTEX
] != NULL
;
1200 case GL_FRAGMENT_SHADER_ARB
:
1201 return pro
->machines
[SLANG_SHADER_FRAGMENT
] != NULL
;
1207 static struct gl2_program_intf _program_vftbl
= {
1213 _program_QueryInterface
1218 _generic_GetDeleteStatus
,
1223 _container_GetAttachedCount
,
1224 _container_GetAttached
1226 _program_GetLinkStatus
,
1227 _program_GetValidateStatus
,
1230 _program_UpdateFixedUniforms
,
1231 _program_UpdateFixedAttribute
,
1232 _program_UpdateFixedVarying
,
1233 _program_GetTextureImageUsage
,
1234 _program_IsShaderPresent
1238 _program_constructor (struct gl2_program_impl
*impl
)
1240 _container_constructor ((struct gl2_container_impl
*) impl
);
1241 impl
->_vftbl
= &_program_vftbl
;
1242 impl
->_obj
._container
._generic
._unknown
._destructor
= _program_destructor
;
1243 impl
->_obj
.link_status
= GL_FALSE
;
1244 impl
->_obj
.validate_status
= GL_FALSE
;
1245 #if USE_3DLABS_FRONTEND
1246 impl
->_obj
.linker
= ShConstructLinker (EShExVertexFragment
, 0);
1247 impl
->_obj
.uniforms
= ShConstructUniformMap ();
1249 slang_program_ctr (&impl
->_obj
.prog
);
1252 struct gl2_fragment_shader_obj
1254 struct gl2_shader_obj _shader
;
1257 struct gl2_fragment_shader_impl
1259 struct gl2_fragment_shader_intf
*_vftbl
;
1260 struct gl2_fragment_shader_obj _obj
;
1264 _fragment_shader_destructor (struct gl2_unknown_intf
**intf
)
1266 struct gl2_fragment_shader_impl
*impl
= (struct gl2_fragment_shader_impl
*) intf
;
1269 /* TODO free fragment shader data */
1271 _shader_destructor (intf
);
1274 static struct gl2_unknown_intf
**
1275 _fragment_shader_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
1277 if (uiid
== UIID_FRAGMENT_SHADER
)
1279 (**intf
).AddRef (intf
);
1282 return _shader_QueryInterface (intf
, uiid
);
1286 _fragment_shader_GetSubType (struct gl2_shader_intf
**intf
)
1288 return GL_FRAGMENT_SHADER_ARB
;
1291 static struct gl2_fragment_shader_intf _fragment_shader_vftbl
= {
1297 _fragment_shader_QueryInterface
1302 _generic_GetDeleteStatus
,
1305 _fragment_shader_GetSubType
,
1306 _shader_GetCompileStatus
,
1314 _fragment_shader_constructor (struct gl2_fragment_shader_impl
*impl
)
1316 _shader_constructor ((struct gl2_shader_impl
*) impl
);
1317 impl
->_vftbl
= &_fragment_shader_vftbl
;
1318 impl
->_obj
._shader
._generic
._unknown
._destructor
= _fragment_shader_destructor
;
1319 #if USE_3DLABS_FRONTEND
1320 impl
->_obj
._shader
._3dlabs_shhandle
._obj
.handle
= ShConstructCompiler (EShLangFragment
, 0);
1324 struct gl2_vertex_shader_obj
1326 struct gl2_shader_obj _shader
;
1329 struct gl2_vertex_shader_impl
1331 struct gl2_vertex_shader_intf
*_vftbl
;
1332 struct gl2_vertex_shader_obj _obj
;
1336 _vertex_shader_destructor (struct gl2_unknown_intf
**intf
)
1338 struct gl2_vertex_shader_impl
*impl
= (struct gl2_vertex_shader_impl
*) intf
;
1341 /* TODO free vertex shader data */
1343 _shader_destructor (intf
);
1346 static struct gl2_unknown_intf
**
1347 _vertex_shader_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
1349 if (uiid
== UIID_VERTEX_SHADER
)
1351 (**intf
).AddRef (intf
);
1354 return _shader_QueryInterface (intf
, uiid
);
1358 _vertex_shader_GetSubType (struct gl2_shader_intf
**intf
)
1360 return GL_VERTEX_SHADER_ARB
;
1363 static struct gl2_vertex_shader_intf _vertex_shader_vftbl
= {
1369 _vertex_shader_QueryInterface
1374 _generic_GetDeleteStatus
,
1377 _vertex_shader_GetSubType
,
1378 _shader_GetCompileStatus
,
1386 _vertex_shader_constructor (struct gl2_vertex_shader_impl
*impl
)
1388 _shader_constructor ((struct gl2_shader_impl
*) impl
);
1389 impl
->_vftbl
= &_vertex_shader_vftbl
;
1390 impl
->_obj
._shader
._generic
._unknown
._destructor
= _vertex_shader_destructor
;
1391 #if USE_3DLABS_FRONTEND
1392 impl
->_obj
._shader
._3dlabs_shhandle
._obj
.handle
= ShConstructCompiler (EShLangVertex
, 0);
1397 _mesa_3dlabs_create_shader_object (GLenum shaderType
)
1401 case GL_FRAGMENT_SHADER_ARB
:
1403 struct gl2_fragment_shader_impl
*x
= (struct gl2_fragment_shader_impl
*)
1404 _mesa_malloc (sizeof (struct gl2_fragment_shader_impl
));
1408 _fragment_shader_constructor (x
);
1409 return x
->_obj
._shader
._generic
.name
;
1413 case GL_VERTEX_SHADER_ARB
:
1415 struct gl2_vertex_shader_impl
*x
= (struct gl2_vertex_shader_impl
*)
1416 _mesa_malloc (sizeof (struct gl2_vertex_shader_impl
));
1420 _vertex_shader_constructor (x
);
1421 return x
->_obj
._shader
._generic
.name
;
1431 _mesa_3dlabs_create_program_object (void)
1433 struct gl2_program_impl
*x
= (struct gl2_program_impl
*)
1434 _mesa_malloc (sizeof (struct gl2_program_impl
));
1438 _program_constructor (x
);
1439 return x
->_obj
._container
._generic
.name
;
1445 #include "slang_assemble.h"
1446 #include "slang_execute.h"
1448 int _slang_fetch_discard (struct gl2_program_intf
**pro
, GLboolean
*val
)
1450 struct gl2_program_impl
*impl
;
1452 impl
= (struct gl2_program_impl
*) pro
;
1453 *val
= impl
->_obj
.prog
.machines
[SLANG_SHADER_FRAGMENT
]->kill
? GL_TRUE
: GL_FALSE
;
1457 static GLvoid
exec_shader (struct gl2_program_intf
**pro
, GLuint i
)
1459 struct gl2_program_impl
*impl
;
1462 impl
= (struct gl2_program_impl
*) pro
;
1463 p
= &impl
->_obj
.prog
;
1465 slang_machine_init (p
->machines
[i
]);
1466 p
->machines
[i
]->ip
= p
->code
[i
][SLANG_COMMON_CODE_MAIN
];
1468 _slang_execute2 (p
->assemblies
[i
], p
->machines
[i
]);
1471 GLvoid
_slang_exec_fragment_shader (struct gl2_program_intf
**pro
)
1473 exec_shader (pro
, SLANG_SHADER_FRAGMENT
);
1476 GLvoid
_slang_exec_vertex_shader (struct gl2_program_intf
**pro
)
1478 exec_shader (pro
, SLANG_SHADER_VERTEX
);
1481 GLint
_slang_get_uniform_location (struct gl2_program_intf
**pro
, const char *name
)
1483 struct gl2_program_impl
*impl
;
1484 slang_uniform_bindings
*bind
;
1487 impl
= (struct gl2_program_impl
*) pro
;
1488 bind
= &impl
->_obj
.prog
.uniforms
;
1489 for (i
= 0; i
< bind
->count
; i
++)
1490 if (_mesa_strcmp (bind
->table
[i
].name
, name
) == 0)
1495 GLboolean
_slang_write_uniform (struct gl2_program_intf
**pro
, GLint loc
, GLsizei count
,
1496 const GLvoid
*data
, GLenum type
)
1498 struct gl2_program_impl
*impl
;
1499 slang_uniform_bindings
*bind
;
1500 slang_uniform_binding
*b
;
1502 GLboolean convert_float_to_bool
= GL_FALSE
;
1503 GLboolean convert_int_to_bool
= GL_FALSE
;
1504 GLboolean convert_int_to_float
= GL_FALSE
;
1505 GLboolean types_match
= GL_FALSE
;
1510 impl
= (struct gl2_program_impl
*) pro
;
1511 bind
= &impl
->_obj
.prog
.uniforms
;
1512 if (loc
>= bind
->count
)
1515 b
= &bind
->table
[loc
];
1516 /* TODO: check sizes */
1517 if (b
->quant
->structure
!= NULL
)
1520 switch (b
->quant
->u
.basic_type
)
1523 types_match
= (type
== GL_FLOAT
) || (type
== GL_INT
);
1524 if (type
== GL_FLOAT
)
1525 convert_float_to_bool
= GL_TRUE
;
1527 convert_int_to_bool
= GL_TRUE
;
1529 case GL_BOOL_VEC2_ARB
:
1530 types_match
= (type
== GL_FLOAT_VEC2_ARB
) || (type
== GL_INT_VEC2_ARB
);
1531 if (type
== GL_FLOAT_VEC2_ARB
)
1532 convert_float_to_bool
= GL_TRUE
;
1534 convert_int_to_bool
= GL_TRUE
;
1536 case GL_BOOL_VEC3_ARB
:
1537 types_match
= (type
== GL_FLOAT_VEC3_ARB
) || (type
== GL_INT_VEC3_ARB
);
1538 if (type
== GL_FLOAT_VEC3_ARB
)
1539 convert_float_to_bool
= GL_TRUE
;
1541 convert_int_to_bool
= GL_TRUE
;
1543 case GL_BOOL_VEC4_ARB
:
1544 types_match
= (type
== GL_FLOAT_VEC4_ARB
) || (type
== GL_INT_VEC4_ARB
);
1545 if (type
== GL_FLOAT_VEC4_ARB
)
1546 convert_float_to_bool
= GL_TRUE
;
1548 convert_int_to_bool
= GL_TRUE
;
1550 case GL_SAMPLER_1D_ARB
:
1551 case GL_SAMPLER_2D_ARB
:
1552 case GL_SAMPLER_3D_ARB
:
1553 case GL_SAMPLER_CUBE_ARB
:
1554 case GL_SAMPLER_1D_SHADOW_ARB
:
1555 case GL_SAMPLER_2D_SHADOW_ARB
:
1556 types_match
= (type
== GL_INT
);
1559 types_match
= (type
== b
->quant
->u
.basic_type
);
1569 case GL_INT_VEC2_ARB
:
1570 case GL_INT_VEC3_ARB
:
1571 case GL_INT_VEC4_ARB
:
1572 convert_int_to_float
= GL_TRUE
;
1576 if (convert_float_to_bool
)
1578 for (i
= 0; i
< SLANG_SHADER_MAX
; i
++)
1579 if (b
->address
[i
] != ~0)
1581 const GLfloat
*src
= (GLfloat
*) (data
);
1582 GLfloat
*dst
= (GLfloat
*) (&impl
->_obj
.prog
.machines
[i
]->mem
[b
->address
[i
] / 4]);
1585 for (j
= 0; j
< count
* b
->quant
->size
/ 4; j
++)
1586 dst
[j
] = src
[j
] != 0.0f
? 1.0f
: 0.0f
;
1589 else if (convert_int_to_bool
)
1591 for (i
= 0; i
< SLANG_SHADER_MAX
; i
++)
1592 if (b
->address
[i
] != ~0)
1594 const GLuint
*src
= (GLuint
*) (data
);
1595 GLfloat
*dst
= (GLfloat
*) (&impl
->_obj
.prog
.machines
[i
]->mem
[b
->address
[i
] / 4]);
1598 for (j
= 0; j
< count
* b
->quant
->size
/ 4; j
++)
1599 dst
[j
] = src
[j
] ? 1.0f
: 0.0f
;
1602 else if (convert_int_to_float
)
1604 for (i
= 0; i
< SLANG_SHADER_MAX
; i
++)
1605 if (b
->address
[i
] != ~0)
1607 const GLuint
*src
= (GLuint
*) (data
);
1608 GLfloat
*dst
= (GLfloat
*) (&impl
->_obj
.prog
.machines
[i
]->mem
[b
->address
[i
] / 4]);
1611 for (j
= 0; j
< count
* b
->quant
->size
/ 4; j
++)
1612 dst
[j
] = (GLfloat
) src
[j
];
1617 for (i
= 0; i
< SLANG_SHADER_MAX
; i
++)
1618 if (b
->address
[i
] != ~0)
1620 _mesa_memcpy (&impl
->_obj
.prog
.machines
[i
]->mem
[b
->address
[i
] / 4], data
,
1621 count
* b
->quant
->size
);
1627 GLuint
_slang_get_active_uniform_count (struct gl2_program_intf
**pro
)
1629 struct gl2_program_impl
*impl
;
1631 impl
= (struct gl2_program_impl
*) pro
;
1632 return impl
->_obj
.prog
.active_uniforms
.count
;
1635 GLuint
_slang_get_active_uniform_max_length (struct gl2_program_intf
**pro
)
1637 struct gl2_program_impl
*impl
;
1640 impl
= (struct gl2_program_impl
*) pro
;
1641 for (i
= 0; i
< impl
->_obj
.prog
.active_uniforms
.count
; i
++)
1643 GLuint n
= _mesa_strlen (impl
->_obj
.prog
.active_uniforms
.table
[i
].name
);
1650 GLvoid
_slang_get_active_uniform (struct gl2_program_intf
**pro
, GLuint index
, GLsizei maxLength
,
1651 GLsizei
*length
, GLint
*size
, GLenum
*type
, char *name
)
1653 struct gl2_program_impl
*impl
;
1654 slang_active_uniform
*u
;
1657 impl
= (struct gl2_program_impl
*) pro
;
1658 u
= &impl
->_obj
.prog
.active_uniforms
.table
[index
];
1660 len
= _mesa_strlen (u
->name
);
1661 if (len
>= maxLength
)
1662 len
= maxLength
- 1;
1663 _mesa_memcpy (name
, u
->name
, len
);
1667 *type
= u
->quant
->u
.basic_type
;
1668 if (u
->quant
->array_len
== 0)
1671 *size
= u
->quant
->array_len
;
1675 _mesa_init_shaderobjects_3dlabs (GLcontext
*ctx
)
1677 #if USE_3DLABS_FRONTEND
1678 _glslang_3dlabs_InitProcess ();
1679 _glslang_3dlabs_ShInitialize ();