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
35 #include "shaderobjects.h"
36 #include "shaderobjects_3dlabs.h"
41 #if USE_3DLABS_FRONTEND
42 #include "slang_mesa.h"
43 #include "Public/ShaderLang.h"
45 #include "slang_utility.h"
46 #include "slang_compile.h"
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
;
233 static const GLcharARB
*
234 _generic_GetInfoLog (struct gl2_generic_intf
**intf
)
236 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
238 return impl
->_obj
.info_log
;
241 static struct gl2_generic_intf _generic_vftbl
= {
245 _generic_QueryInterface
248 NULL
, /* abstract GetType */
250 _generic_GetDeleteStatus
,
255 _generic_constructor (struct gl2_generic_impl
*impl
)
257 GET_CURRENT_CONTEXT(ctx
);
259 _unknown_constructor ((struct gl2_unknown_impl
*) impl
);
260 impl
->_vftbl
= &_generic_vftbl
;
261 impl
->_obj
._unknown
._destructor
= _generic_destructor
;
262 impl
->_obj
.delete_status
= GL_FALSE
;
263 impl
->_obj
.info_log
= NULL
;
265 _glthread_LOCK_MUTEX (ctx
->Shared
->Mutex
);
266 impl
->_obj
.name
= _mesa_HashFindFreeKeyBlock (ctx
->Shared
->GL2Objects
, 1);
267 _mesa_HashInsert (ctx
->Shared
->GL2Objects
, impl
->_obj
.name
, (void *) impl
);
268 _glthread_UNLOCK_MUTEX (ctx
->Shared
->Mutex
);
271 struct gl2_container_obj
273 struct gl2_generic_obj _generic
;
274 struct gl2_generic_intf
***attached
;
275 GLuint attached_count
;
278 struct gl2_container_impl
280 struct gl2_container_intf
*_vftbl
;
281 struct gl2_container_obj _obj
;
285 _container_destructor (struct gl2_unknown_intf
**intf
)
287 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
290 for (i
= 0; i
< impl
->_obj
.attached_count
; i
++)
292 struct gl2_generic_intf
**x
= impl
->_obj
.attached
[i
];
293 (**x
)._unknown
.Release ((struct gl2_unknown_intf
**) x
);
296 _generic_destructor (intf
);
299 static struct gl2_unknown_intf
**
300 _container_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
302 if (uiid
== UIID_CONTAINER
)
304 (**intf
).AddRef (intf
);
307 return _generic_QueryInterface (intf
, uiid
);
311 _container_Attach (struct gl2_container_intf
**intf
, struct gl2_generic_intf
**att
)
313 GET_CURRENT_CONTEXT(ctx
);
314 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
317 for (i
= 0; i
< impl
->_obj
.attached_count
; i
++)
318 if (impl
->_obj
.attached
[i
] == att
)
320 _mesa_error (ctx
, GL_INVALID_OPERATION
, "_container_Attach");
324 impl
->_obj
.attached
= (struct gl2_generic_intf
***) _mesa_realloc (impl
->_obj
.attached
,
325 impl
->_obj
.attached_count
* sizeof (*impl
->_obj
.attached
), (impl
->_obj
.attached_count
+ 1) *
326 sizeof (*impl
->_obj
.attached
));
327 if (impl
->_obj
.attached
== NULL
)
330 impl
->_obj
.attached
[impl
->_obj
.attached_count
] = att
;
331 impl
->_obj
.attached_count
++;
332 (**att
)._unknown
.AddRef ((struct gl2_unknown_intf
**) att
);
337 _container_Detach (struct gl2_container_intf
**intf
, struct gl2_generic_intf
**att
)
339 GET_CURRENT_CONTEXT(ctx
);
340 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
343 for (i
= 0; i
< impl
->_obj
.attached_count
; i
++)
344 if (impl
->_obj
.attached
[i
] == att
)
346 for (j
= i
; j
< impl
->_obj
.attached_count
- 1; j
++)
347 impl
->_obj
.attached
[j
] = impl
->_obj
.attached
[j
+ 1];
348 impl
->_obj
.attached
= (struct gl2_generic_intf
***) _mesa_realloc (impl
->_obj
.attached
,
349 impl
->_obj
.attached_count
* sizeof (*impl
->_obj
.attached
),
350 (impl
->_obj
.attached_count
- 1) * sizeof (*impl
->_obj
.attached
));
351 impl
->_obj
.attached_count
--;
352 (**att
)._unknown
.Release ((struct gl2_unknown_intf
**) att
);
356 _mesa_error (ctx
, GL_INVALID_OPERATION
, "_container_Detach");
361 _container_GetAttachedCount (struct gl2_container_intf
**intf
)
363 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
365 return impl
->_obj
.attached_count
;
368 static struct gl2_generic_intf
**
369 _container_GetAttached (struct gl2_container_intf
**intf
, GLuint index
)
371 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
373 (**impl
->_obj
.attached
[index
])._unknown
.AddRef (
374 (struct gl2_unknown_intf
**)impl
->_obj
.attached
[index
]);
375 return impl
->_obj
.attached
[index
];
378 static struct gl2_container_intf _container_vftbl
= {
383 _container_QueryInterface
386 NULL
, /* abstract GetType */
388 _generic_GetDeleteStatus
,
393 _container_GetAttachedCount
,
394 _container_GetAttached
398 _container_constructor (struct gl2_container_impl
*impl
)
400 _generic_constructor ((struct gl2_generic_impl
*) impl
);
401 impl
->_vftbl
= &_container_vftbl
;
402 impl
->_obj
._generic
._unknown
._destructor
= _container_destructor
;
403 impl
->_obj
.attached
= NULL
;
404 impl
->_obj
.attached_count
= 0;
407 struct gl2_3dlabs_shhandle_obj
409 struct gl2_unkinner_obj _unknown
;
410 #if USE_3DLABS_FRONTEND
415 struct gl2_3dlabs_shhandle_impl
417 struct gl2_3dlabs_shhandle_intf
*_vftbl
;
418 struct gl2_3dlabs_shhandle_obj _obj
;
422 _3dlabs_shhandle_destructor (struct gl2_unknown_intf
**intf
)
424 #if USE_3DLABS_FRONTEND
425 struct gl2_3dlabs_shhandle_impl
*impl
= (struct gl2_3dlabs_shhandle_impl
*) intf
;
426 ShDestruct (impl
->_obj
.handle
);
428 _unkinner_destructor (intf
);
432 _3dlabs_shhandle_GetShHandle (struct gl2_3dlabs_shhandle_intf
**intf
)
434 #if USE_3DLABS_FRONTEND
435 struct gl2_3dlabs_shhandle_impl
*impl
= (struct gl2_3dlabs_shhandle_impl
*) intf
;
436 return impl
->_obj
.handle
;
442 static struct gl2_3dlabs_shhandle_intf _3dlabs_shhandle_vftbl
= {
446 _unkinner_QueryInterface
448 _3dlabs_shhandle_GetShHandle
452 _3dlabs_shhandle_constructor (struct gl2_3dlabs_shhandle_impl
*impl
, struct gl2_unknown_intf
**outer
)
454 _unkinner_constructor ((struct gl2_unkinner_impl
*) impl
, outer
);
455 impl
->_vftbl
= &_3dlabs_shhandle_vftbl
;
456 #if USE_3DLABS_FRONTEND
457 impl
->_obj
.handle
= NULL
;
461 struct gl2_shader_obj
463 struct gl2_generic_obj _generic
;
464 struct gl2_3dlabs_shhandle_impl _3dlabs_shhandle
;
465 GLboolean compile_status
;
468 GLsizei offset_count
;
469 slang_translation_unit unit
;
472 struct gl2_shader_impl
474 struct gl2_shader_intf
*_vftbl
;
475 struct gl2_shader_obj _obj
;
479 _shader_destructor (struct gl2_unknown_intf
**intf
)
481 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
483 _mesa_free ((void *) impl
->_obj
.source
);
484 _mesa_free ((void *) impl
->_obj
.offsets
);
485 _3dlabs_shhandle_destructor ((struct gl2_unknown_intf
**) &impl
->_obj
._3dlabs_shhandle
._vftbl
);
486 _generic_destructor (intf
);
489 static struct gl2_unknown_intf
**
490 _shader_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
492 #if USE_3DLABS_FRONTEND
493 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
496 if (uiid
== UIID_SHADER
)
498 (**intf
).AddRef (intf
);
501 #if USE_3DLABS_FRONTEND
502 if (uiid
== UIID_3DLABS_SHHANDLE
)
504 (**intf
).AddRef (intf
);
505 return (struct gl2_unknown_intf
**) &impl
->_obj
._3dlabs_shhandle
._vftbl
;
508 return _generic_QueryInterface (intf
, uiid
);
512 _shader_GetType (struct gl2_generic_intf
**intf
)
514 return GL_SHADER_OBJECT_ARB
;
518 _shader_GetCompileStatus (struct gl2_shader_intf
**intf
)
520 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
522 return impl
->_obj
.compile_status
;
526 _shader_SetSource (struct gl2_shader_intf
**intf
, GLcharARB
*src
, GLint
*off
, GLsizei cnt
)
528 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
530 _mesa_free ((void *) impl
->_obj
.source
);
531 impl
->_obj
.source
= src
;
532 _mesa_free ((void *) impl
->_obj
.offsets
);
533 impl
->_obj
.offsets
= off
;
534 impl
->_obj
.offset_count
= cnt
;
537 static const GLcharARB
*
538 _shader_GetSource (struct gl2_shader_intf
**intf
)
540 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
542 return impl
->_obj
.source
;
546 _shader_Compile (struct gl2_shader_intf
**intf
)
548 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
549 #if USE_3DLABS_FRONTEND
551 TBuiltInResource res
;
553 slang_unit_type type
;
554 slang_info_log info_log
;
557 impl
->_obj
.compile_status
= GL_FALSE
;
558 _mesa_free ((void *) impl
->_obj
._generic
.info_log
);
559 impl
->_obj
._generic
.info_log
= NULL
;
561 #if USE_3DLABS_FRONTEND
562 /* 3dlabs compiler expects us to feed it with null-terminated string array,
563 we've got only one big string with offsets, so we must split it; but when
564 there's only one string to deal with, we pass its address directly */
566 if (impl
->_obj
.offset_count
<= 1)
567 strings
= &impl
->_obj
.source
;
570 GLsizei i
, offset
= 0;
572 strings
= (char **) _mesa_malloc (impl
->_obj
.offset_count
* sizeof (char *));
576 for (i
= 0; i
< impl
->_obj
.offset_count
; i
++)
578 GLsizei size
= impl
->_obj
.offsets
[i
] - offset
;
580 strings
[i
] = (char *) _mesa_malloc ((size
+ 1) * sizeof (char));
581 if (strings
[i
] == NULL
)
585 for (j
= 0; j
< i
; j
++)
586 _mesa_free (strings
[j
]);
587 _mesa_free (strings
);
591 _mesa_memcpy (strings
[i
], impl
->_obj
.source
+ offset
, size
* sizeof (char));
592 strings
[i
][size
] = '\0';
593 offset
= impl
->_obj
.offsets
[i
];
597 /* TODO set these fields to some REAL numbers */
599 res
.maxClipPlanes
= 6;
600 res
.maxTextureUnits
= 2;
601 res
.maxTextureCoords
= 2;
602 res
.maxVertexAttribs
= 8;
603 res
.maxVertexUniformComponents
= 64;
604 res
.maxVaryingFloats
= 8;
605 res
.maxVertexTextureImageUnits
= 2;
606 res
.maxCombinedTextureImageUnits
= 2;
607 res
.maxTextureImageUnits
= 2;
608 res
.maxFragmentUniformComponents
= 64;
609 res
.maxDrawBuffers
= 1;
611 if (ShCompile (impl
->_obj
._3dlabs_shhandle
._obj
.handle
, strings
, impl
->_obj
.offset_count
,
612 EShOptFull
, &res
, 0))
613 impl
->_obj
.compile_status
= GL_TRUE
;
614 if (impl
->_obj
.offset_count
> 1)
618 for (i
= 0; i
< impl
->_obj
.offset_count
; i
++)
619 _mesa_free (strings
[i
]);
620 _mesa_free (strings
);
623 impl
->_obj
._generic
.info_log
= _mesa_strdup (ShGetInfoLog (
624 impl
->_obj
._3dlabs_shhandle
._obj
.handle
));
626 if (impl
->_vftbl
->GetSubType (intf
) == GL_FRAGMENT_SHADER
)
627 type
= slang_unit_fragment_shader
;
629 type
= slang_unit_vertex_shader
;
630 slang_info_log_construct (&info_log
);
631 if (_slang_compile (impl
->_obj
.source
, &impl
->_obj
.unit
, type
, &info_log
))
633 impl
->_obj
.compile_status
= GL_TRUE
;
635 if (info_log
.text
!= NULL
)
636 impl
->_obj
._generic
.info_log
= _mesa_strdup (info_log
.text
);
638 impl
->_obj
._generic
.info_log
= _mesa_strdup ("");
639 slang_info_log_destruct (&info_log
);
643 static struct gl2_shader_intf _shader_vftbl
= {
648 _shader_QueryInterface
653 _generic_GetDeleteStatus
,
656 NULL
, /* abstract GetSubType */
657 _shader_GetCompileStatus
,
664 _shader_constructor (struct gl2_shader_impl
*impl
)
666 _generic_constructor ((struct gl2_generic_impl
*) impl
);
667 _3dlabs_shhandle_constructor (&impl
->_obj
._3dlabs_shhandle
, (struct gl2_unknown_intf
**)
669 impl
->_vftbl
= &_shader_vftbl
;
670 impl
->_obj
._generic
._unknown
._destructor
= _shader_destructor
;
671 impl
->_obj
.compile_status
= GL_FALSE
;
672 impl
->_obj
.source
= NULL
;
673 impl
->_obj
.offsets
= NULL
;
674 impl
->_obj
.offset_count
= 0;
677 struct gl2_program_obj
679 struct gl2_container_obj _container
;
680 GLboolean link_status
;
681 GLboolean validate_status
;
682 #if USE_3DLABS_FRONTEND
688 struct gl2_program_impl
690 struct gl2_program_intf
*_vftbl
;
691 struct gl2_program_obj _obj
;
695 _program_destructor (struct gl2_unknown_intf
**intf
)
697 #if USE_3DLABS_FRONTEND
698 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
700 ShDestruct (impl
->_obj
.linker
);
701 ShDestruct (impl
->_obj
.uniforms
);
703 _container_destructor (intf
);
706 static struct gl2_unknown_intf
**
707 _program_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
709 if (uiid
== UIID_PROGRAM
)
711 (**intf
).AddRef (intf
);
714 return _container_QueryInterface (intf
, uiid
);
718 _program_GetType (struct gl2_generic_intf
**intf
)
720 return GL_PROGRAM_OBJECT_ARB
;
724 _program_Attach (struct gl2_container_intf
**intf
, struct gl2_generic_intf
**att
)
726 GET_CURRENT_CONTEXT(ctx
);
727 struct gl2_unknown_intf
**sha
;
729 sha
= (**att
)._unknown
.QueryInterface ((struct gl2_unknown_intf
**) att
, UIID_SHADER
);
732 _mesa_error (ctx
, GL_INVALID_OPERATION
, "_program_Attach");
736 (**sha
).Release (sha
);
737 return _container_Attach (intf
, att
);
741 _program_GetLinkStatus (struct gl2_program_intf
**intf
)
743 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
745 return impl
->_obj
.link_status
;
749 _program_GetValidateStatus (struct gl2_program_intf
**intf
)
751 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
753 return impl
->_obj
.validate_status
;
757 _program_Link (struct gl2_program_intf
**intf
)
759 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
760 #if USE_3DLABS_FRONTEND
765 impl
->_obj
.link_status
= GL_FALSE
;
766 _mesa_free ((void *) impl
->_obj
._container
._generic
.info_log
);
767 impl
->_obj
._container
._generic
.info_log
= NULL
;
769 #if USE_3DLABS_FRONTEND
770 handles
= (ShHandle
*) _mesa_malloc (impl
->_obj
._container
.attached_count
* sizeof (ShHandle
));
774 for (i
= 0; i
< impl
->_obj
._container
.attached_count
; i
++)
776 struct gl2_generic_intf
**gen
= impl
->_obj
._container
.attached
[i
];
777 struct gl2_3dlabs_shhandle_intf
**sh
;
779 sh
= (struct gl2_3dlabs_shhandle_intf
**) (**gen
)._unknown
.QueryInterface (
780 (struct gl2_unknown_intf
**) gen
, UIID_3DLABS_SHHANDLE
);
783 handles
[i
] = (**sh
).GetShHandle (sh
);
784 (**sh
)._unknown
.Release ((struct gl2_unknown_intf
**) sh
);
788 _mesa_free (handles
);
793 if (ShLink (impl
->_obj
.linker
, handles
, impl
->_obj
._container
.attached_count
,
794 impl
->_obj
.uniforms
, NULL
, NULL
))
795 impl
->_obj
.link_status
= GL_TRUE
;
797 impl
->_obj
._container
._generic
.info_log
= _mesa_strdup (ShGetInfoLog (impl
->_obj
.linker
));
799 /* TODO: do the real linking */
800 impl
->_obj
.link_status
= GL_TRUE
;
801 impl
->_obj
._container
._generic
.info_log
= _mesa_strdup ("Link OK.\n");
806 _program_Validate (struct gl2_program_intf
**intf
)
808 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
810 impl
->_obj
.validate_status
= GL_FALSE
;
811 _mesa_free ((void *) impl
->_obj
._container
._generic
.info_log
);
812 impl
->_obj
._container
._generic
.info_log
= NULL
;
817 static struct gl2_program_intf _program_vftbl
= {
823 _program_QueryInterface
828 _generic_GetDeleteStatus
,
833 _container_GetAttachedCount
,
834 _container_GetAttached
836 _program_GetLinkStatus
,
837 _program_GetValidateStatus
,
843 _program_constructor (struct gl2_program_impl
*impl
)
845 _container_constructor ((struct gl2_container_impl
*) impl
);
846 impl
->_vftbl
= &_program_vftbl
;
847 impl
->_obj
._container
._generic
._unknown
._destructor
= _program_destructor
;
848 impl
->_obj
.link_status
= GL_FALSE
;
849 impl
->_obj
.validate_status
= GL_FALSE
;
850 #if USE_3DLABS_FRONTEND
851 impl
->_obj
.linker
= ShConstructLinker (EShExVertexFragment
, 0);
852 impl
->_obj
.uniforms
= ShConstructUniformMap ();
856 struct gl2_fragment_shader_obj
858 struct gl2_shader_obj _shader
;
861 struct gl2_fragment_shader_impl
863 struct gl2_fragment_shader_intf
*_vftbl
;
864 struct gl2_fragment_shader_obj _obj
;
868 _fragment_shader_destructor (struct gl2_unknown_intf
**intf
)
870 struct gl2_fragment_shader_impl
*impl
= (struct gl2_fragment_shader_impl
*) intf
;
873 /* TODO free fragment shader data */
875 _shader_destructor (intf
);
878 static struct gl2_unknown_intf
**
879 _fragment_shader_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
881 if (uiid
== UIID_FRAGMENT_SHADER
)
883 (**intf
).AddRef (intf
);
886 return _shader_QueryInterface (intf
, uiid
);
890 _fragment_shader_GetSubType (struct gl2_shader_intf
**intf
)
892 return GL_FRAGMENT_SHADER_ARB
;
895 static struct gl2_fragment_shader_intf _fragment_shader_vftbl
= {
901 _fragment_shader_QueryInterface
906 _generic_GetDeleteStatus
,
909 _fragment_shader_GetSubType
,
910 _shader_GetCompileStatus
,
918 _fragment_shader_constructor (struct gl2_fragment_shader_impl
*impl
)
920 _shader_constructor ((struct gl2_shader_impl
*) impl
);
921 impl
->_vftbl
= &_fragment_shader_vftbl
;
922 impl
->_obj
._shader
._generic
._unknown
._destructor
= _fragment_shader_destructor
;
923 #if USE_3DLABS_FRONTEND
924 impl
->_obj
._shader
._3dlabs_shhandle
._obj
.handle
= ShConstructCompiler (EShLangFragment
, 0);
928 struct gl2_vertex_shader_obj
930 struct gl2_shader_obj _shader
;
933 struct gl2_vertex_shader_impl
935 struct gl2_vertex_shader_intf
*_vftbl
;
936 struct gl2_vertex_shader_obj _obj
;
940 _vertex_shader_destructor (struct gl2_unknown_intf
**intf
)
942 struct gl2_vertex_shader_impl
*impl
= (struct gl2_vertex_shader_impl
*) intf
;
945 /* TODO free vertex shader data */
947 _shader_destructor (intf
);
950 static struct gl2_unknown_intf
**
951 _vertex_shader_QueryInterface (struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
953 if (uiid
== UIID_VERTEX_SHADER
)
955 (**intf
).AddRef (intf
);
958 return _shader_QueryInterface (intf
, uiid
);
962 _vertex_shader_GetSubType (struct gl2_shader_intf
**intf
)
964 return GL_VERTEX_SHADER_ARB
;
967 static struct gl2_vertex_shader_intf _vertex_shader_vftbl
= {
973 _vertex_shader_QueryInterface
978 _generic_GetDeleteStatus
,
981 _vertex_shader_GetSubType
,
982 _shader_GetCompileStatus
,
990 _vertex_shader_constructor (struct gl2_vertex_shader_impl
*impl
)
992 _shader_constructor ((struct gl2_shader_impl
*) impl
);
993 impl
->_vftbl
= &_vertex_shader_vftbl
;
994 impl
->_obj
._shader
._generic
._unknown
._destructor
= _vertex_shader_destructor
;
995 #if USE_3DLABS_FRONTEND
996 impl
->_obj
._shader
._3dlabs_shhandle
._obj
.handle
= ShConstructCompiler (EShLangVertex
, 0);
1001 _mesa_3dlabs_create_shader_object (GLenum shaderType
)
1005 case GL_FRAGMENT_SHADER_ARB
:
1007 struct gl2_fragment_shader_impl
*x
= (struct gl2_fragment_shader_impl
*)
1008 _mesa_malloc (sizeof (struct gl2_fragment_shader_impl
));
1012 _fragment_shader_constructor (x
);
1013 return x
->_obj
._shader
._generic
.name
;
1017 case GL_VERTEX_SHADER_ARB
:
1019 struct gl2_vertex_shader_impl
*x
= (struct gl2_vertex_shader_impl
*)
1020 _mesa_malloc (sizeof (struct gl2_vertex_shader_impl
));
1024 _vertex_shader_constructor (x
);
1025 return x
->_obj
._shader
._generic
.name
;
1035 _mesa_3dlabs_create_program_object (void)
1037 struct gl2_program_impl
*x
= (struct gl2_program_impl
*)
1038 _mesa_malloc (sizeof (struct gl2_program_impl
));
1042 _program_constructor (x
);
1043 return x
->_obj
._container
._generic
.name
;
1049 #include "slang_assemble.h"
1050 #include "slang_execute.h"
1052 static GLubyte
*get_address_of (struct gl2_vertex_shader_intf
**vs
, const char *name
)
1054 struct gl2_vertex_shader_impl
*impl
= (struct gl2_vertex_shader_impl
*) vs
;
1055 slang_translation_unit
*unit
;
1057 slang_variable
*var
;
1059 impl
= (struct gl2_vertex_shader_impl
*) vs
;
1060 unit
= &impl
->_obj
._shader
.unit
;
1061 atom
= slang_atom_pool_atom (unit
->atom_pool
, name
);
1062 var
= _slang_locate_variable (&unit
->globals
, atom
, 1);
1063 if (var
== NULL
|| var
->address
== ~0)
1065 return (GLubyte
*) unit
->machine
->mem
+ var
->address
;
1068 static int fetch_mem (struct gl2_vertex_shader_intf
**vs
, const char *name
, GLvoid
*val
,
1069 GLuint size
, GLuint index
, int write
)
1073 data
= get_address_of (vs
, name
) + index
* size
;
1077 _mesa_memcpy (data
, val
, size
);
1079 _mesa_memcpy (val
, data
, size
);
1083 int _slang_fetch_float (struct gl2_vertex_shader_intf
**vs
, const char *name
, GLfloat
*val
, int write
)
1085 return fetch_mem (vs
, name
, val
, 4, 0, write
);
1088 int _slang_fetch_vec3 (struct gl2_vertex_shader_intf
**vs
, const char *name
, GLfloat
*val
, int write
)
1090 return fetch_mem (vs
, name
, val
, 12, 0, write
);
1093 int _slang_fetch_vec4 (struct gl2_vertex_shader_intf
**vs
, const char *name
, GLfloat
*val
,
1094 GLuint index
, int write
)
1096 return fetch_mem (vs
, name
, val
, 16, index
, write
);
1099 int _slang_fetch_mat4 (struct gl2_vertex_shader_intf
**vs
, const char *name
, GLfloat
*val
,
1100 GLuint index
, int write
)
1102 return fetch_mem (vs
, name
, val
, 64, index
, write
);
1106 int _slang_call_function (slang_assembly_file
*file
, slang_function
*fun
, slang_operation
*params
,
1107 unsigned int param_count
, int assignment
, slang_assembly_name_space
*space
,
1108 slang_assembly_local_info
*info
, struct slang_machine_
*pmach
, slang_atom_pool
*);
1110 void exec_vertex_shader (struct gl2_vertex_shader_intf
**vs
)
1112 struct gl2_vertex_shader_impl
*impl
= (struct gl2_vertex_shader_impl
*) vs
;
1113 slang_translation_unit
*unit
;
1117 impl
= (struct gl2_vertex_shader_impl
*) vs
;
1118 unit
= &impl
->_obj
._shader
.unit
;
1119 atom
= slang_atom_pool_atom (unit
->atom_pool
, "main");
1120 for (i
= 0; i
< unit
->functions
.num_functions
; i
++)
1121 if (atom
== unit
->functions
.functions
[i
].header
.a_name
)
1123 if (i
< unit
->functions
.num_functions
)
1126 slang_assembly_file_restore_point point
;
1128 slang_assembly_local_info info
;
1129 slang_assembly_name_space space
;
1131 f
= &unit
->functions
.functions
[i
];
1132 slang_assembly_file_restore_point_save (unit
->assembly
, &point
);
1133 mach
= *unit
->machine
;
1134 mach
.ip
= unit
->assembly
->count
;
1137 info
.swizzle_tmp
= 4;
1138 slang_assembly_file_push_label (unit
->assembly
, slang_asm_local_alloc
, 20);
1139 slang_assembly_file_push_label (unit
->assembly
, slang_asm_enter
, 20);
1140 space
.funcs
= &unit
->functions
;
1141 space
.structs
= &unit
->structs
;
1142 space
.vars
= &unit
->globals
;
1143 _slang_call_function (unit
->assembly
, f
, NULL
, 0, 0, &space
, &info
, unit
->machine
,
1145 slang_assembly_file_push (unit
->assembly
, slang_asm_exit
);
1146 _slang_execute2 (unit
->assembly
, &mach
);
1147 slang_assembly_file_restore_point_load (unit
->assembly
, &point
);
1148 _mesa_memcpy (unit
->machine
->mem
, mach
.mem
, SLANG_MACHINE_MEMORY_SIZE
* sizeof (slang_machine_slot
));
1153 _mesa_init_shaderobjects_3dlabs (GLcontext
*ctx
)
1155 #if USE_3DLABS_FRONTEND
1156 _glslang_3dlabs_InitProcess ();
1157 _glslang_3dlabs_ShInitialize ();