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) {
81 impl
->_obj
._destructor(intf
);
82 _mesa_free((void *) intf
);
86 static struct gl2_unknown_intf
**
87 _unknown_QueryInterface(struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
89 if (uiid
== UIID_UNKNOWN
) {
90 (**intf
).AddRef(intf
);
96 static struct gl2_unknown_intf _unknown_vftbl
= {
99 _unknown_QueryInterface
103 _unknown_constructor(struct gl2_unknown_impl
*impl
)
105 impl
->_vftbl
= &_unknown_vftbl
;
106 impl
->_obj
.reference_count
= 1;
107 impl
->_obj
._destructor
= _unknown_destructor
;
110 struct gl2_unkinner_obj
112 struct gl2_unknown_intf
**unkouter
;
115 struct gl2_unkinner_impl
117 struct gl2_unknown_intf
*_vftbl
;
118 struct gl2_unkinner_obj _obj
;
122 _unkinner_destructor(struct gl2_unknown_intf
**intf
)
127 _unkinner_AddRef(struct gl2_unknown_intf
**intf
)
129 struct gl2_unkinner_impl
*impl
= (struct gl2_unkinner_impl
*) intf
;
131 (**impl
->_obj
.unkouter
).AddRef(impl
->_obj
.unkouter
);
135 _unkinner_Release(struct gl2_unknown_intf
**intf
)
137 struct gl2_unkinner_impl
*impl
= (struct gl2_unkinner_impl
*) intf
;
139 (**impl
->_obj
.unkouter
).Release(impl
->_obj
.unkouter
);
142 static struct gl2_unknown_intf
**
143 _unkinner_QueryInterface(struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
145 struct gl2_unkinner_impl
*impl
= (struct gl2_unkinner_impl
*) intf
;
147 return (**impl
->_obj
.unkouter
).QueryInterface(impl
->_obj
.unkouter
, uiid
);
150 static struct gl2_unknown_intf _unkinner_vftbl
= {
153 _unkinner_QueryInterface
157 _unkinner_constructor(struct gl2_unkinner_impl
*impl
,
158 struct gl2_unknown_intf
**outer
)
160 impl
->_vftbl
= &_unkinner_vftbl
;
161 impl
->_obj
.unkouter
= outer
;
164 struct gl2_generic_obj
166 struct gl2_unknown_obj _unknown
;
168 GLboolean delete_status
;
172 struct gl2_generic_impl
174 struct gl2_generic_intf
*_vftbl
;
175 struct gl2_generic_obj _obj
;
179 _generic_destructor(struct gl2_unknown_intf
**intf
)
181 GET_CURRENT_CONTEXT(ctx
);
182 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
184 _mesa_free((void *) impl
->_obj
.info_log
);
186 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
187 _mesa_HashRemove(ctx
->Shared
->GL2Objects
, impl
->_obj
.name
);
188 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
190 _unknown_destructor(intf
);
193 static struct gl2_unknown_intf
**
194 _generic_QueryInterface(struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
196 if (uiid
== UIID_GENERIC
) {
197 (**intf
).AddRef(intf
);
200 return _unknown_QueryInterface(intf
, uiid
);
204 _generic_Delete(struct gl2_generic_intf
**intf
)
206 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) intf
;
208 if (impl
->_obj
.delete_status
== GL_FALSE
) {
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
;
231 _generic_GetInfoLog(struct gl2_generic_intf
**intf
, GLsizei maxlen
,
234 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) (intf
);
237 _mesa_strncpy(infolog
, impl
->_obj
.info_log
, maxlen
- 1);
238 infolog
[maxlen
- 1] = '\0';
243 _generic_GetInfoLogLength(struct gl2_generic_intf
**intf
)
245 struct gl2_generic_impl
*impl
= (struct gl2_generic_impl
*) (intf
);
247 if (impl
->_obj
.info_log
== NULL
)
249 return _mesa_strlen(impl
->_obj
.info_log
) + 1;
252 static struct gl2_generic_intf _generic_vftbl
= {
256 _generic_QueryInterface
},
258 NULL
, /* abstract GetType */
260 _generic_GetDeleteStatus
,
262 _generic_GetInfoLogLength
266 _generic_constructor(struct gl2_generic_impl
*impl
)
268 GET_CURRENT_CONTEXT(ctx
);
270 _unknown_constructor((struct gl2_unknown_impl
*) impl
);
271 impl
->_vftbl
= &_generic_vftbl
;
272 impl
->_obj
._unknown
._destructor
= _generic_destructor
;
273 impl
->_obj
.delete_status
= GL_FALSE
;
274 impl
->_obj
.info_log
= NULL
;
276 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
277 impl
->_obj
.name
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->GL2Objects
, 1);
278 _mesa_HashInsert(ctx
->Shared
->GL2Objects
, impl
->_obj
.name
, (void *) impl
);
279 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
282 struct gl2_container_obj
284 struct gl2_generic_obj _generic
;
285 struct gl2_generic_intf
***attached
;
286 GLuint attached_count
;
289 struct gl2_container_impl
291 struct gl2_container_intf
*_vftbl
;
292 struct gl2_container_obj _obj
;
296 _container_destructor(struct gl2_unknown_intf
**intf
)
298 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
301 for (i
= 0; i
< impl
->_obj
.attached_count
; i
++) {
302 struct gl2_generic_intf
**x
= impl
->_obj
.attached
[i
];
303 (**x
)._unknown
.Release((struct gl2_unknown_intf
**) x
);
306 _generic_destructor(intf
);
309 static struct gl2_unknown_intf
**
310 _container_QueryInterface(struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
312 if (uiid
== UIID_CONTAINER
) {
313 (**intf
).AddRef(intf
);
316 return _generic_QueryInterface(intf
, uiid
);
320 _container_Attach(struct gl2_container_intf
**intf
,
321 struct gl2_generic_intf
**att
)
323 GET_CURRENT_CONTEXT(ctx
);
324 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
327 for (i
= 0; i
< impl
->_obj
.attached_count
; i
++)
328 if (impl
->_obj
.attached
[i
] == att
) {
329 _mesa_error(ctx
, GL_INVALID_OPERATION
, "_container_Attach");
333 impl
->_obj
.attached
= (struct gl2_generic_intf
***)
334 _mesa_realloc(impl
->_obj
.attached
,
335 impl
->_obj
.attached_count
* sizeof(*impl
->_obj
.attached
),
336 (impl
->_obj
.attached_count
+ 1) * sizeof(*impl
->_obj
.attached
));
337 if (impl
->_obj
.attached
== NULL
)
340 impl
->_obj
.attached
[impl
->_obj
.attached_count
] = att
;
341 impl
->_obj
.attached_count
++;
342 (**att
)._unknown
.AddRef((struct gl2_unknown_intf
**) att
);
347 _container_Detach(struct gl2_container_intf
**intf
,
348 struct gl2_generic_intf
**att
)
350 GET_CURRENT_CONTEXT(ctx
);
351 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
354 for (i
= 0; i
< impl
->_obj
.attached_count
; i
++)
355 if (impl
->_obj
.attached
[i
] == att
) {
356 for (j
= i
; j
< impl
->_obj
.attached_count
- 1; j
++)
357 impl
->_obj
.attached
[j
] = impl
->_obj
.attached
[j
+ 1];
358 impl
->_obj
.attached
= (struct gl2_generic_intf
***)
359 _mesa_realloc(impl
->_obj
.attached
,
360 impl
->_obj
.attached_count
* sizeof(*impl
->_obj
.attached
),
361 (impl
->_obj
.attached_count
- 1) * sizeof(*impl
->_obj
.attached
));
362 impl
->_obj
.attached_count
--;
363 (**att
)._unknown
.Release((struct gl2_unknown_intf
**) att
);
367 _mesa_error(ctx
, GL_INVALID_OPERATION
, "_container_Detach");
372 _container_GetAttachedCount(struct gl2_container_intf
**intf
)
374 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
376 return impl
->_obj
.attached_count
;
379 static struct gl2_generic_intf
**
380 _container_GetAttached(struct gl2_container_intf
**intf
, GLuint index
)
382 struct gl2_container_impl
*impl
= (struct gl2_container_impl
*) intf
;
384 (**impl
->_obj
.attached
[index
])._unknown
.AddRef((struct gl2_unknown_intf
**)
385 impl
->_obj
.attached
[index
]);
386 return impl
->_obj
.attached
[index
];
389 static struct gl2_container_intf _container_vftbl
= {
394 _container_QueryInterface
397 NULL
, /* abstract GetType */
399 _generic_GetDeleteStatus
,
401 _generic_GetInfoLogLength
405 _container_GetAttachedCount
,
406 _container_GetAttached
410 _container_constructor(struct gl2_container_impl
*impl
)
412 _generic_constructor((struct gl2_generic_impl
*) impl
);
413 impl
->_vftbl
= &_container_vftbl
;
414 impl
->_obj
._generic
._unknown
._destructor
= _container_destructor
;
415 impl
->_obj
.attached
= NULL
;
416 impl
->_obj
.attached_count
= 0;
419 struct gl2_3dlabs_shhandle_obj
421 struct gl2_unkinner_obj _unknown
;
422 #if USE_3DLABS_FRONTEND
427 struct gl2_3dlabs_shhandle_impl
429 struct gl2_3dlabs_shhandle_intf
*_vftbl
;
430 struct gl2_3dlabs_shhandle_obj _obj
;
434 _3dlabs_shhandle_destructor(struct gl2_unknown_intf
**intf
)
436 #if USE_3DLABS_FRONTEND
437 struct gl2_3dlabs_shhandle_impl
*impl
=
438 (struct gl2_3dlabs_shhandle_impl
*) intf
;
439 ShDestruct(impl
->_obj
.handle
);
441 _unkinner_destructor(intf
);
445 _3dlabs_shhandle_GetShHandle(struct gl2_3dlabs_shhandle_intf
**intf
)
447 #if USE_3DLABS_FRONTEND
448 struct gl2_3dlabs_shhandle_impl
*impl
=
449 (struct gl2_3dlabs_shhandle_impl
*) intf
;
450 return impl
->_obj
.handle
;
456 static struct gl2_3dlabs_shhandle_intf _3dlabs_shhandle_vftbl
= {
460 _unkinner_QueryInterface
},
461 _3dlabs_shhandle_GetShHandle
465 _3dlabs_shhandle_constructor(struct gl2_3dlabs_shhandle_impl
*impl
,
466 struct gl2_unknown_intf
**outer
)
468 _unkinner_constructor((struct gl2_unkinner_impl
*) impl
, outer
);
469 impl
->_vftbl
= &_3dlabs_shhandle_vftbl
;
470 #if USE_3DLABS_FRONTEND
471 impl
->_obj
.handle
= NULL
;
475 struct gl2_shader_obj
477 struct gl2_generic_obj _generic
;
478 struct gl2_3dlabs_shhandle_impl _3dlabs_shhandle
;
479 GLboolean compile_status
;
482 GLsizei offset_count
;
483 slang_code_object code
;
486 struct gl2_shader_impl
488 struct gl2_shader_intf
*_vftbl
;
489 struct gl2_shader_obj _obj
;
493 _shader_destructor(struct gl2_unknown_intf
**intf
)
495 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
497 _mesa_free((void *) impl
->_obj
.source
);
498 _mesa_free((void *) impl
->_obj
.offsets
);
499 _slang_code_object_dtr(&impl
->_obj
.code
);
500 _3dlabs_shhandle_destructor((struct gl2_unknown_intf
**) &impl
->_obj
.
501 _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
) {
513 (**intf
).AddRef(intf
);
516 #if USE_3DLABS_FRONTEND
517 if (uiid
== UIID_3DLABS_SHHANDLE
) {
518 (**intf
).AddRef(intf
);
519 return (struct gl2_unknown_intf
**) &impl
->_obj
._3dlabs_shhandle
._vftbl
;
522 return _generic_QueryInterface(intf
, uiid
);
526 _shader_GetType(struct gl2_generic_intf
**intf
)
528 return GL_SHADER_OBJECT_ARB
;
532 _shader_GetInfoLog(struct gl2_generic_intf
**intf
, GLsizei maxlen
,
535 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) (intf
);
538 if (impl
->_obj
._generic
.info_log
!= NULL
) {
539 GLsizei len
= _mesa_strlen(impl
->_obj
._generic
.info_log
);
540 if (len
> maxlen
- 1)
542 _mesa_memcpy(infolog
, impl
->_obj
._generic
.info_log
, len
);
546 if (impl
->_obj
.code
.machine
.infolog
!= NULL
&&
547 impl
->_obj
.code
.machine
.infolog
->text
!= NULL
) {
548 GLsizei len
= _mesa_strlen(impl
->_obj
.code
.machine
.infolog
->text
);
549 if (len
> maxlen
- 1)
551 _mesa_memcpy(infolog
, impl
->_obj
.code
.machine
.infolog
->text
, len
);
553 infolog
[maxlen
- 1] = '\0';
558 _shader_GetInfoLogLength(struct gl2_generic_intf
**intf
)
560 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) (intf
);
563 if (impl
->_obj
._generic
.info_log
!= NULL
)
564 length
+= _mesa_strlen(impl
->_obj
._generic
.info_log
);
565 if (impl
->_obj
.code
.machine
.infolog
!= NULL
&&
566 impl
->_obj
.code
.machine
.infolog
->text
!= NULL
)
567 length
+= _mesa_strlen(impl
->_obj
.code
.machine
.infolog
->text
);
572 _shader_GetCompileStatus(struct gl2_shader_intf
**intf
)
574 struct gl2_shader_impl
*impl
= (struct gl2_shader_impl
*) intf
;
576 return impl
->_obj
.compile_status
;
580 _shader_SetSource(struct gl2_shader_intf
**intf
, GLcharARB
* src
, GLint
* off
,
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
;
624 GLsizei i
, offset
= 0;
627 (char **) _mesa_malloc(impl
->_obj
.offset_count
* sizeof(char *));
631 for (i
= 0; i
< impl
->_obj
.offset_count
; i
++) {
632 GLsizei size
= impl
->_obj
.offsets
[i
] - offset
;
634 strings
[i
] = (char *) _mesa_malloc((size
+ 1) * sizeof(char));
635 if (strings
[i
] == NULL
) {
638 for (j
= 0; j
< i
; j
++)
639 _mesa_free(strings
[j
]);
644 _mesa_memcpy(strings
[i
], impl
->_obj
.source
+ offset
,
645 size
* sizeof(char));
646 strings
[i
][size
] = '\0';
647 offset
= impl
->_obj
.offsets
[i
];
651 /* TODO set these fields to some REAL numbers */
653 res
.maxClipPlanes
= 6;
654 res
.maxTextureUnits
= 2;
655 res
.maxTextureCoords
= 2;
656 res
.maxVertexAttribs
= 8;
657 res
.maxVertexUniformComponents
= 64;
658 res
.maxVaryingFloats
= 8;
659 res
.maxVertexTextureImageUnits
= 2;
660 res
.maxCombinedTextureImageUnits
= 2;
661 res
.maxTextureImageUnits
= 2;
662 res
.maxFragmentUniformComponents
= 64;
663 res
.maxDrawBuffers
= 1;
666 (impl
->_obj
._3dlabs_shhandle
._obj
.handle
, strings
,
667 impl
->_obj
.offset_count
, EShOptFull
, &res
, 0))
668 impl
->_obj
.compile_status
= GL_TRUE
;
669 if (impl
->_obj
.offset_count
> 1) {
672 for (i
= 0; i
< impl
->_obj
.offset_count
; i
++)
673 _mesa_free(strings
[i
]);
677 impl
->_obj
._generic
.info_log
=
678 _mesa_strdup(ShGetInfoLog(impl
->_obj
._3dlabs_shhandle
._obj
.handle
));
680 if (impl
->_vftbl
->GetSubType(intf
) == GL_FRAGMENT_SHADER
)
681 type
= slang_unit_fragment_shader
;
683 type
= slang_unit_vertex_shader
;
684 slang_info_log_construct(&info_log
);
685 if (_slang_compile(impl
->_obj
.source
, &impl
->_obj
.code
, type
, &info_log
))
686 impl
->_obj
.compile_status
= GL_TRUE
;
687 if (info_log
.text
!= NULL
)
688 impl
->_obj
._generic
.info_log
= _mesa_strdup(info_log
.text
);
689 else if (impl
->_obj
.compile_status
)
690 impl
->_obj
._generic
.info_log
= _mesa_strdup("Compile OK.\n");
692 impl
->_obj
._generic
.info_log
= _mesa_strdup("Compile failed.\n");
693 slang_info_log_destruct(&info_log
);
697 static struct gl2_shader_intf _shader_vftbl
= {
702 _shader_QueryInterface
707 _generic_GetDeleteStatus
,
709 _shader_GetInfoLogLength
711 NULL
, /* abstract GetSubType */
712 _shader_GetCompileStatus
,
719 _shader_constructor(struct gl2_shader_impl
*impl
)
721 _generic_constructor((struct gl2_generic_impl
*) impl
);
722 _3dlabs_shhandle_constructor(&impl
->_obj
._3dlabs_shhandle
,
723 (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
) {
768 (**intf
).AddRef(intf
);
771 return _container_QueryInterface(intf
, uiid
);
775 _program_GetType(struct gl2_generic_intf
**intf
)
777 return GL_PROGRAM_OBJECT_ARB
;
781 _program_Attach(struct gl2_container_intf
**intf
,
782 struct gl2_generic_intf
**att
)
784 GET_CURRENT_CONTEXT(ctx
);
785 struct gl2_unknown_intf
**sha
;
788 (**att
)._unknown
.QueryInterface((struct gl2_unknown_intf
**) att
,
791 _mesa_error(ctx
, GL_INVALID_OPERATION
, "_program_Attach");
795 (**sha
).Release(sha
);
796 return _container_Attach(intf
, att
);
800 _program_GetLinkStatus(struct gl2_program_intf
**intf
)
802 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
804 return impl
->_obj
.link_status
;
808 _program_GetValidateStatus(struct gl2_program_intf
**intf
)
810 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
812 return impl
->_obj
.validate_status
;
816 _program_Link(struct gl2_program_intf
**intf
)
818 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
819 #if USE_3DLABS_FRONTEND
823 slang_code_object
*code
[2];
824 GLboolean all_compiled
= GL_TRUE
;
826 impl
->_obj
.link_status
= GL_FALSE
;
827 _mesa_free((void *) impl
->_obj
._container
._generic
.info_log
);
828 impl
->_obj
._container
._generic
.info_log
= NULL
;
829 _slang_program_rst(&impl
->_obj
.prog
);
831 #if USE_3DLABS_FRONTEND
833 (ShHandle
*) _mesa_malloc(impl
->_obj
._container
.attached_count
*
838 for (i
= 0; i
< impl
->_obj
._container
.attached_count
; i
++) {
839 struct gl2_generic_intf
**gen
= impl
->_obj
._container
.attached
[i
];
840 struct gl2_3dlabs_shhandle_intf
**sh
;
843 (struct gl2_3dlabs_shhandle_intf
**) (**gen
)._unknown
.
844 QueryInterface((struct gl2_unknown_intf
**) gen
,
845 UIID_3DLABS_SHHANDLE
);
847 handles
[i
] = (**sh
).GetShHandle(sh
);
848 (**sh
)._unknown
.Release((struct gl2_unknown_intf
**) sh
);
856 if (ShLink(impl
->_obj
.linker
, handles
, impl
->_obj
._container
.attached_count
,
857 impl
->_obj
.uniforms
, NULL
, NULL
))
858 impl
->_obj
.link_status
= GL_TRUE
;
860 impl
->_obj
._container
._generic
.info_log
=
861 _mesa_strdup(ShGetInfoLog(impl
->_obj
.linker
));
863 count
= impl
->_obj
._container
.attached_count
;
867 for (i
= 0; i
< count
; i
++) {
868 struct gl2_generic_intf
**obj
;
869 struct gl2_unknown_intf
**unk
;
870 struct gl2_shader_impl
*sha
;
872 obj
= impl
->_obj
._container
.attached
[i
];
874 (**obj
)._unknown
.QueryInterface((struct gl2_unknown_intf
**) obj
,
878 sha
= (struct gl2_shader_impl
*) unk
;
879 code
[i
] = &sha
->_obj
.code
;
880 all_compiled
= all_compiled
&& sha
->_obj
.compile_status
;
881 (**unk
).Release(unk
);
884 impl
->_obj
.link_status
= all_compiled
;
885 if (!impl
->_obj
.link_status
) {
886 impl
->_obj
._container
._generic
.info_log
=
888 ("Error: One or more shaders has not successfully compiled.\n");
892 impl
->_obj
.link_status
= _slang_link(&impl
->_obj
.prog
, code
, count
);
893 if (!impl
->_obj
.link_status
) {
894 impl
->_obj
._container
._generic
.info_log
=
895 _mesa_strdup("Link failed.\n");
899 impl
->_obj
._container
._generic
.info_log
= _mesa_strdup("Link OK.\n");
904 _program_Validate(struct gl2_program_intf
**intf
)
906 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
908 impl
->_obj
.validate_status
= GL_FALSE
;
909 _mesa_free((void *) impl
->_obj
._container
._generic
.info_log
);
910 impl
->_obj
._container
._generic
.info_log
= NULL
;
916 write_common_fixed(slang_program
* pro
, GLuint index
, const GLvoid
* src
,
917 GLuint off
, GLuint size
)
921 for (i
= 0; i
< SLANG_SHADER_MAX
; i
++) {
924 addr
= pro
->common_fixed_entries
[i
][index
];
928 dst
= (GLubyte
*) pro
->machines
[i
]->mem
+ addr
+ off
* size
;
929 _mesa_memcpy(dst
, src
, size
);
935 write_common_fixed_mat4(slang_program
* pro
, GLmatrix
* matrix
, GLuint off
,
936 GLuint i
, GLuint ii
, GLuint it
, GLuint iit
)
940 /* we want inverse matrix */
942 /* allocate inverse matrix and make it dirty */
943 _math_matrix_alloc_inv(matrix
);
944 _math_matrix_loadf(matrix
, matrix
->m
);
946 _math_matrix_analyse(matrix
);
948 write_common_fixed(pro
, i
, matrix
->m
, off
, 16 * sizeof(GLfloat
));
951 write_common_fixed(pro
, ii
, matrix
->inv
, off
, 16 * sizeof(GLfloat
));
954 _math_transposef(mat
, matrix
->m
);
955 write_common_fixed(pro
, it
, mat
, off
, 16 * sizeof(GLfloat
));
957 /* inverse transpose */
958 _math_transposef(mat
, matrix
->inv
);
959 write_common_fixed(pro
, iit
, mat
, off
, 16 * sizeof(GLfloat
));
963 write_common_fixed_material(GLcontext
* ctx
, slang_program
* pro
, GLuint i
,
964 GLuint e
, GLuint a
, GLuint d
, GLuint sp
,
969 COPY_4FV(v
, ctx
->Light
.Material
.Attrib
[e
]);
970 COPY_4FV((v
+ 4), ctx
->Light
.Material
.Attrib
[a
]);
971 COPY_4FV((v
+ 8), ctx
->Light
.Material
.Attrib
[d
]);
972 COPY_4FV((v
+ 12), ctx
->Light
.Material
.Attrib
[sp
]);
973 v
[16] = ctx
->Light
.Material
.Attrib
[sh
][0];
974 write_common_fixed(pro
, i
, v
, 0, 17 * sizeof(GLfloat
));
978 write_common_fixed_light_model_product(GLcontext
* ctx
, slang_program
* pro
,
979 GLuint i
, GLuint e
, GLuint a
)
983 SCALE_4V(v
, ctx
->Light
.Material
.Attrib
[a
], ctx
->Light
.Model
.Ambient
);
984 ACC_4V(v
, ctx
->Light
.Material
.Attrib
[e
]);
985 write_common_fixed(pro
, i
, v
, 0, 4 * sizeof(GLfloat
));
989 write_common_fixed_light_product(GLcontext
* ctx
, slang_program
* pro
,
990 GLuint off
, GLuint i
, GLuint a
, GLuint d
,
995 SCALE_4V(v
, ctx
->Light
.Light
[off
].Ambient
, ctx
->Light
.Material
.Attrib
[a
]);
996 SCALE_4V((v
+ 4), ctx
->Light
.Light
[off
].Diffuse
,
997 ctx
->Light
.Material
.Attrib
[d
]);
998 SCALE_4V((v
+ 8), ctx
->Light
.Light
[off
].Specular
,
999 ctx
->Light
.Material
.Attrib
[s
]);
1000 write_common_fixed(pro
, i
, v
, off
, 12 * sizeof(GLfloat
));
1004 _program_UpdateFixedUniforms(struct gl2_program_intf
**intf
)
1006 GET_CURRENT_CONTEXT(ctx
);
1007 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1008 slang_program
*pro
= &impl
->_obj
.prog
;
1013 /* MODELVIEW matrix */
1014 write_common_fixed_mat4(pro
, ctx
->ModelviewMatrixStack
.Top
, 0,
1015 SLANG_COMMON_FIXED_MODELVIEWMATRIX
,
1016 SLANG_COMMON_FIXED_MODELVIEWMATRIXINVERSE
,
1017 SLANG_COMMON_FIXED_MODELVIEWMATRIXTRANSPOSE
,
1018 SLANG_COMMON_FIXED_MODELVIEWMATRIXINVERSETRANSPOSE
);
1020 /* PROJECTION matrix */
1021 write_common_fixed_mat4(pro
, ctx
->ProjectionMatrixStack
.Top
, 0,
1022 SLANG_COMMON_FIXED_PROJECTIONMATRIX
,
1023 SLANG_COMMON_FIXED_PROJECTIONMATRIXINVERSE
,
1024 SLANG_COMMON_FIXED_PROJECTIONMATRIXTRANSPOSE
,
1025 SLANG_COMMON_FIXED_PROJECTIONMATRIXINVERSETRANSPOSE
);
1028 write_common_fixed_mat4(pro
, &ctx
->_ModelProjectMatrix
, 0,
1029 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIX
,
1030 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIXINVERSE
,
1031 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIXTRANSPOSE
,
1032 SLANG_COMMON_FIXED_MODELVIEWPROJECTIONMATRIXINVERSETRANSPOSE
);
1034 for (i
= 0; i
< ctx
->Const
.MaxTextureCoordUnits
; i
++) {
1035 /* TEXTURE matrix */
1036 write_common_fixed_mat4(pro
, ctx
->TextureMatrixStack
[i
].Top
, i
,
1037 SLANG_COMMON_FIXED_TEXTUREMATRIX
,
1038 SLANG_COMMON_FIXED_TEXTUREMATRIXINVERSE
,
1039 SLANG_COMMON_FIXED_TEXTUREMATRIXTRANSPOSE
,
1040 SLANG_COMMON_FIXED_TEXTUREMATRIXINVERSETRANSPOSE
);
1042 /* EYE_PLANE texture-coordinate generation */
1043 write_common_fixed(pro
, SLANG_COMMON_FIXED_EYEPLANES
,
1044 ctx
->Texture
.Unit
[i
].EyePlaneS
, i
,
1045 4 * sizeof(GLfloat
));
1046 write_common_fixed(pro
, SLANG_COMMON_FIXED_EYEPLANET
,
1047 ctx
->Texture
.Unit
[i
].EyePlaneT
, i
,
1048 4 * sizeof(GLfloat
));
1049 write_common_fixed(pro
, SLANG_COMMON_FIXED_EYEPLANER
,
1050 ctx
->Texture
.Unit
[i
].EyePlaneR
, i
,
1051 4 * sizeof(GLfloat
));
1052 write_common_fixed(pro
, SLANG_COMMON_FIXED_EYEPLANEQ
,
1053 ctx
->Texture
.Unit
[i
].EyePlaneQ
, i
,
1054 4 * sizeof(GLfloat
));
1056 /* OBJECT_PLANE texture-coordinate generation */
1057 write_common_fixed(pro
, SLANG_COMMON_FIXED_OBJECTPLANES
,
1058 ctx
->Texture
.Unit
[i
].ObjectPlaneS
, i
,
1059 4 * sizeof(GLfloat
));
1060 write_common_fixed(pro
, SLANG_COMMON_FIXED_OBJECTPLANET
,
1061 ctx
->Texture
.Unit
[i
].ObjectPlaneT
, i
,
1062 4 * sizeof(GLfloat
));
1063 write_common_fixed(pro
, SLANG_COMMON_FIXED_OBJECTPLANER
,
1064 ctx
->Texture
.Unit
[i
].ObjectPlaneR
, i
,
1065 4 * sizeof(GLfloat
));
1066 write_common_fixed(pro
, SLANG_COMMON_FIXED_OBJECTPLANEQ
,
1067 ctx
->Texture
.Unit
[i
].ObjectPlaneQ
, i
,
1068 4 * sizeof(GLfloat
));
1071 /* NORMAL matrix - upper 3x3 inverse transpose of MODELVIEW matrix */
1072 p
= ctx
->ModelviewMatrixStack
.Top
->inv
;
1082 write_common_fixed(pro
, SLANG_COMMON_FIXED_NORMALMATRIX
, v
, 0,
1083 9 * sizeof(GLfloat
));
1086 write_common_fixed(pro
, SLANG_COMMON_FIXED_NORMALSCALE
,
1087 &ctx
->_ModelViewInvScale
, 0, sizeof(GLfloat
));
1089 /* depth range parameters */
1090 v
[0] = ctx
->Viewport
.Near
;
1091 v
[1] = ctx
->Viewport
.Far
;
1092 v
[2] = ctx
->Viewport
.Far
- ctx
->Viewport
.Near
;
1093 write_common_fixed(pro
, SLANG_COMMON_FIXED_DEPTHRANGE
, v
, 0,
1094 3 * sizeof(GLfloat
));
1097 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
1098 write_common_fixed(pro
, SLANG_COMMON_FIXED_CLIPPLANE
,
1099 ctx
->Transform
.EyeUserPlane
[i
], i
,
1100 4 * sizeof(GLfloat
));
1103 /* point parameters */
1104 v
[0] = ctx
->Point
.Size
;
1105 v
[1] = ctx
->Point
.MinSize
;
1106 v
[2] = ctx
->Point
.MaxSize
;
1107 v
[3] = ctx
->Point
.Threshold
;
1108 COPY_3FV((v
+ 4), ctx
->Point
.Params
);
1109 write_common_fixed(pro
, SLANG_COMMON_FIXED_POINT
, v
, 0,
1110 7 * sizeof(GLfloat
));
1112 /* material parameters */
1113 write_common_fixed_material(ctx
, pro
, SLANG_COMMON_FIXED_FRONTMATERIAL
,
1114 MAT_ATTRIB_FRONT_EMISSION
,
1115 MAT_ATTRIB_FRONT_AMBIENT
,
1116 MAT_ATTRIB_FRONT_DIFFUSE
,
1117 MAT_ATTRIB_FRONT_SPECULAR
,
1118 MAT_ATTRIB_FRONT_SHININESS
);
1119 write_common_fixed_material(ctx
, pro
, SLANG_COMMON_FIXED_BACKMATERIAL
,
1120 MAT_ATTRIB_BACK_EMISSION
,
1121 MAT_ATTRIB_BACK_AMBIENT
,
1122 MAT_ATTRIB_BACK_DIFFUSE
,
1123 MAT_ATTRIB_BACK_SPECULAR
,
1124 MAT_ATTRIB_BACK_SHININESS
);
1126 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++) {
1127 /* light source parameters */
1128 COPY_4FV(v
, ctx
->Light
.Light
[i
].Ambient
);
1129 COPY_4FV((v
+ 4), ctx
->Light
.Light
[i
].Diffuse
);
1130 COPY_4FV((v
+ 8), ctx
->Light
.Light
[i
].Specular
);
1131 COPY_4FV((v
+ 12), ctx
->Light
.Light
[i
].EyePosition
);
1132 COPY_2FV((v
+ 16), ctx
->Light
.Light
[i
].EyePosition
);
1133 v
[18] = ctx
->Light
.Light
[i
].EyePosition
[2] + 1.0f
;
1134 NORMALIZE_3FV((v
+ 16));
1136 COPY_3V((v
+ 20), ctx
->Light
.Light
[i
].EyeDirection
);
1137 v
[23] = ctx
->Light
.Light
[i
].SpotExponent
;
1138 v
[24] = ctx
->Light
.Light
[i
].SpotCutoff
;
1139 v
[25] = ctx
->Light
.Light
[i
]._CosCutoffNeg
;
1140 v
[26] = ctx
->Light
.Light
[i
].ConstantAttenuation
;
1141 v
[27] = ctx
->Light
.Light
[i
].LinearAttenuation
;
1142 v
[28] = ctx
->Light
.Light
[i
].QuadraticAttenuation
;
1143 write_common_fixed(pro
, SLANG_COMMON_FIXED_LIGHTSOURCE
, v
, i
,
1144 29 * sizeof(GLfloat
));
1147 write_common_fixed_light_product(ctx
, pro
, i
,
1148 SLANG_COMMON_FIXED_FRONTLIGHTPRODUCT
,
1149 MAT_ATTRIB_FRONT_AMBIENT
,
1150 MAT_ATTRIB_FRONT_DIFFUSE
,
1151 MAT_ATTRIB_FRONT_SPECULAR
);
1152 write_common_fixed_light_product(ctx
, pro
, i
,
1153 SLANG_COMMON_FIXED_BACKLIGHTPRODUCT
,
1154 MAT_ATTRIB_BACK_AMBIENT
,
1155 MAT_ATTRIB_BACK_DIFFUSE
,
1156 MAT_ATTRIB_BACK_SPECULAR
);
1159 /* light model parameters */
1160 write_common_fixed(pro
, SLANG_COMMON_FIXED_LIGHTMODEL
,
1161 ctx
->Light
.Model
.Ambient
, 0, 4 * sizeof(GLfloat
));
1163 /* light model product */
1164 write_common_fixed_light_model_product(ctx
, pro
,
1165 SLANG_COMMON_FIXED_FRONTLIGHTMODELPRODUCT
,
1166 MAT_ATTRIB_FRONT_EMISSION
,
1167 MAT_ATTRIB_FRONT_AMBIENT
);
1168 write_common_fixed_light_model_product(ctx
, pro
,
1169 SLANG_COMMON_FIXED_BACKLIGHTMODELPRODUCT
,
1170 MAT_ATTRIB_BACK_EMISSION
,
1171 MAT_ATTRIB_BACK_AMBIENT
);
1173 /* TEXTURE_ENV_COLOR */
1174 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++) {
1175 write_common_fixed(pro
, SLANG_COMMON_FIXED_TEXTUREENVCOLOR
,
1176 ctx
->Texture
.Unit
[i
].EnvColor
, i
,
1177 4 * sizeof(GLfloat
));
1180 /* fog parameters */
1181 COPY_4FV(v
, ctx
->Fog
.Color
);
1182 v
[4] = ctx
->Fog
.Density
;
1183 v
[5] = ctx
->Fog
.Start
;
1184 v
[6] = ctx
->Fog
.End
;
1185 v
[7] = ctx
->Fog
._Scale
;
1186 write_common_fixed(pro
, SLANG_COMMON_FIXED_FOG
, v
, 0, 8 * sizeof(GLfloat
));
1190 _program_UpdateFixedAttrib(struct gl2_program_intf
**intf
, GLuint index
,
1191 GLvoid
* data
, GLuint offset
, GLuint size
,
1194 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1195 slang_program
*pro
= &impl
->_obj
.prog
;
1198 addr
= pro
->vertex_fixed_entries
[index
];
1203 (GLubyte
*) pro
->machines
[SLANG_SHADER_VERTEX
]->mem
+ addr
+
1206 _mesa_memcpy(mem
, data
, size
);
1208 _mesa_memcpy(data
, mem
, size
);
1214 * Called during fragment shader execution to either load a varying
1215 * register with values, or fetch values from a varying register.
1216 * \param intf the internal program?
1217 * \param index which varying register, one of the SLANG_FRAGMENT_FIXED_*
1218 * values for example.
1219 * \param data source values to load (or dest to write to)
1220 * \param offset indicates a texture unit or generic varying attribute
1221 * \param size number of bytes to copy
1222 * \param write if true, write to the varying register, else store values
1226 _program_UpdateFixedVarying(struct gl2_program_intf
**intf
, GLuint index
,
1228 GLuint offset
, GLuint size
, GLboolean write
)
1230 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1231 slang_program
*pro
= &impl
->_obj
.prog
;
1234 addr
= pro
->fragment_fixed_entries
[index
];
1239 (GLubyte
*) pro
->machines
[SLANG_SHADER_FRAGMENT
]->mem
+ addr
+
1242 _mesa_memcpy(mem
, data
, size
);
1244 _mesa_memcpy(data
, mem
, size
);
1249 _program_GetTextureImageUsage(struct gl2_program_intf
**intf
,
1250 GLbitfield
* teximageusage
)
1252 GET_CURRENT_CONTEXT(ctx
);
1253 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1254 slang_program
*pro
= &impl
->_obj
.prog
;
1257 for (i
= 0; i
< ctx
->Const
.MaxTextureImageUnits
; i
++)
1258 teximageusage
[i
] = 0;
1260 for (i
= 0; i
< pro
->texture_usage
.count
; i
++) {
1263 n
= slang_export_data_quant_elements(pro
->texture_usage
.table
[i
].quant
);
1264 addr
= pro
->texture_usage
.table
[i
].frag_address
;
1265 for (j
= 0; j
< n
; j
++) {
1270 (GLubyte
*) pro
->machines
[SLANG_SHADER_FRAGMENT
]->mem
+ addr
+
1272 image
= (GLuint
) * ((GLfloat
*) mem
);
1273 if (image
>= 0 && image
< ctx
->Const
.MaxTextureImageUnits
) {
1274 switch (slang_export_data_quant_type
1275 (pro
->texture_usage
.table
[i
].quant
)) {
1276 case GL_SAMPLER_1D_ARB
:
1277 case GL_SAMPLER_1D_SHADOW_ARB
:
1278 teximageusage
[image
] |= TEXTURE_1D_BIT
;
1280 case GL_SAMPLER_2D_ARB
:
1281 case GL_SAMPLER_2D_SHADOW_ARB
:
1282 teximageusage
[image
] |= TEXTURE_2D_BIT
;
1284 case GL_SAMPLER_3D_ARB
:
1285 teximageusage
[image
] |= TEXTURE_3D_BIT
;
1287 case GL_SAMPLER_CUBE_ARB
:
1288 teximageusage
[image
] |= TEXTURE_CUBE_BIT
;
1295 /* TODO: make sure that for 0<=i<=MaxTextureImageUint bitcount(teximageuint[i])<=0 */
1299 _program_IsShaderPresent(struct gl2_program_intf
**intf
, GLenum subtype
)
1301 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1302 slang_program
*pro
= &impl
->_obj
.prog
;
1305 case GL_VERTEX_SHADER_ARB
:
1306 return pro
->machines
[SLANG_SHADER_VERTEX
] != NULL
;
1307 case GL_FRAGMENT_SHADER_ARB
:
1308 return pro
->machines
[SLANG_SHADER_FRAGMENT
] != NULL
;
1315 get_active_variable(slang_active_variable
* var
, GLsizei maxLength
,
1316 GLsizei
* length
, GLint
* size
, GLenum
* type
,
1321 len
= _mesa_strlen(var
->name
);
1322 if (len
>= maxLength
)
1323 len
= maxLength
- 1;
1326 *size
= slang_export_data_quant_elements(var
->quant
);
1327 *type
= slang_export_data_quant_type(var
->quant
);
1328 _mesa_memcpy(name
, var
->name
, len
);
1333 get_active_variable_max_length(slang_active_variables
* vars
)
1337 for (i
= 0; i
< vars
->count
; i
++) {
1338 GLuint n
= _mesa_strlen(vars
->table
[i
].name
);
1346 _program_GetActiveUniform(struct gl2_program_intf
**intf
, GLuint index
,
1347 GLsizei maxLength
, GLsizei
* length
, GLint
* size
,
1348 GLenum
* type
, GLchar
* name
)
1350 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1351 slang_active_variable
*u
= &impl
->_obj
.prog
.active_uniforms
.table
[index
];
1353 get_active_variable(u
, maxLength
, length
, size
, type
, name
);
1357 _program_GetActiveUniformMaxLength(struct gl2_program_intf
**intf
)
1359 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1361 return get_active_variable_max_length(&impl
->_obj
.prog
.active_uniforms
);
1365 _program_GetActiveUniformCount(struct gl2_program_intf
**intf
)
1367 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1369 return impl
->_obj
.prog
.active_uniforms
.count
;
1373 _program_GetUniformLocation(struct gl2_program_intf
**intf
,
1374 const GLchar
* name
)
1376 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1377 slang_uniform_bindings
*bind
= &impl
->_obj
.prog
.uniforms
;
1380 for (i
= 0; i
< bind
->count
; i
++)
1381 if (_mesa_strcmp(bind
->table
[i
].name
, name
) == 0)
1387 * Write a uniform variable into program's memory.
1388 * \return GL_TRUE for success, GL_FALSE if error
1391 _program_WriteUniform(struct gl2_program_intf
**intf
, GLint loc
,
1392 GLsizei count
, const GLvoid
* data
, GLenum type
)
1394 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1395 slang_uniform_bindings
*uniforms
= &impl
->_obj
.prog
.uniforms
;
1396 slang_uniform_binding
*uniform
;
1398 GLboolean convert_float_to_bool
= GL_FALSE
;
1399 GLboolean convert_int_to_bool
= GL_FALSE
;
1400 GLboolean convert_int_to_float
= GL_FALSE
;
1401 GLboolean types_match
= GL_FALSE
;
1403 if (loc
< 0 || loc
>= uniforms
->count
)
1406 uniform
= &uniforms
->table
[loc
];
1407 /* TODO: check sizes */
1408 if (slang_export_data_quant_struct(uniform
->quant
))
1411 switch (slang_export_data_quant_type(uniform
->quant
)) {
1413 types_match
= (type
== GL_FLOAT
) || (type
== GL_INT
);
1414 if (type
== GL_FLOAT
)
1415 convert_float_to_bool
= GL_TRUE
;
1417 convert_int_to_bool
= GL_TRUE
;
1419 case GL_BOOL_VEC2_ARB
:
1420 types_match
= (type
== GL_FLOAT_VEC2_ARB
) || (type
== GL_INT_VEC2_ARB
);
1421 if (type
== GL_FLOAT_VEC2_ARB
)
1422 convert_float_to_bool
= GL_TRUE
;
1424 convert_int_to_bool
= GL_TRUE
;
1426 case GL_BOOL_VEC3_ARB
:
1427 types_match
= (type
== GL_FLOAT_VEC3_ARB
) || (type
== GL_INT_VEC3_ARB
);
1428 if (type
== GL_FLOAT_VEC3_ARB
)
1429 convert_float_to_bool
= GL_TRUE
;
1431 convert_int_to_bool
= GL_TRUE
;
1433 case GL_BOOL_VEC4_ARB
:
1434 types_match
= (type
== GL_FLOAT_VEC4_ARB
) || (type
== GL_INT_VEC4_ARB
);
1435 if (type
== GL_FLOAT_VEC4_ARB
)
1436 convert_float_to_bool
= GL_TRUE
;
1438 convert_int_to_bool
= GL_TRUE
;
1440 case GL_SAMPLER_1D_ARB
:
1441 case GL_SAMPLER_2D_ARB
:
1442 case GL_SAMPLER_3D_ARB
:
1443 case GL_SAMPLER_CUBE_ARB
:
1444 case GL_SAMPLER_1D_SHADOW_ARB
:
1445 case GL_SAMPLER_2D_SHADOW_ARB
:
1446 types_match
= (type
== GL_INT
);
1449 types_match
= (type
== slang_export_data_quant_type(uniform
->quant
));
1458 case GL_INT_VEC2_ARB
:
1459 case GL_INT_VEC3_ARB
:
1460 case GL_INT_VEC4_ARB
:
1461 convert_int_to_float
= GL_TRUE
;
1465 for (i
= 0; i
< SLANG_SHADER_MAX
; i
++) {
1466 if (uniform
->address
[i
] != ~0) {
1468 = &impl
->_obj
.prog
.machines
[i
]->mem
[uniform
->address
[i
] / 4];
1469 /* total number of values to copy */
1471 = count
* slang_export_data_quant_components(uniform
->quant
);
1473 if (convert_float_to_bool
) {
1474 const GLfloat
*src
= (GLfloat
*) (data
);
1475 GLfloat
*dst
= (GLfloat
*) dest
;
1476 for (j
= 0; j
< total
; j
++)
1477 dst
[j
] = src
[j
] != 0.0f
? 1.0f
: 0.0f
;
1480 else if (convert_int_to_bool
) {
1481 const GLint
*src
= (GLint
*) (data
);
1482 GLfloat
*dst
= (GLfloat
*) dest
;
1483 for (j
= 0; j
< total
; j
++)
1484 dst
[j
] = src
[j
] ? 1.0f
: 0.0f
;
1487 else if (convert_int_to_float
) {
1488 const GLint
*src
= (GLint
*) (data
);
1489 GLfloat
*dst
= (GLfloat
*) dest
;
1490 for (j
= 0; j
< total
; j
++)
1491 dst
[j
] = (GLfloat
) src
[j
];
1495 _mesa_memcpy(dest
, data
, total
* sizeof(GLfloat
));
1505 * Read a uniform variable from program's memory.
1506 * \return GL_TRUE for success, GL_FALSE if error
1509 _program_ReadUniform(struct gl2_program_intf
**intf
, GLint loc
,
1510 GLsizei count
, GLvoid
*data
, GLenum type
)
1512 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1513 const slang_uniform_bindings
*uniforms
= &impl
->_obj
.prog
.uniforms
;
1514 const slang_uniform_binding
*uniform
;
1516 GLboolean convert_bool_to_float
= GL_FALSE
;
1517 GLboolean convert_bool_to_int
= GL_FALSE
;
1518 GLboolean convert_float_to_int
= GL_FALSE
;
1519 GLboolean types_match
= GL_FALSE
;
1521 if (loc
< 0 || loc
>= uniforms
->count
)
1524 uniform
= &uniforms
->table
[loc
];
1526 if (slang_export_data_quant_struct(uniform
->quant
))
1529 switch (slang_export_data_quant_type(uniform
->quant
)) {
1531 types_match
= (type
== GL_FLOAT
) || (type
== GL_INT
);
1532 if (type
== GL_FLOAT
)
1533 convert_bool_to_float
= GL_TRUE
;
1535 convert_bool_to_int
= GL_TRUE
;
1537 case GL_BOOL_VEC2_ARB
:
1538 types_match
= (type
== GL_FLOAT_VEC2_ARB
) || (type
== GL_INT_VEC2_ARB
);
1539 if (type
== GL_FLOAT_VEC2_ARB
)
1540 convert_bool_to_float
= GL_TRUE
;
1542 convert_bool_to_int
= GL_TRUE
;
1544 case GL_BOOL_VEC3_ARB
:
1545 types_match
= (type
== GL_FLOAT_VEC3_ARB
) || (type
== GL_INT_VEC3_ARB
);
1546 if (type
== GL_FLOAT_VEC3_ARB
)
1547 convert_bool_to_float
= GL_TRUE
;
1549 convert_bool_to_int
= GL_TRUE
;
1551 case GL_BOOL_VEC4_ARB
:
1552 types_match
= (type
== GL_FLOAT_VEC4_ARB
) || (type
== GL_INT_VEC4_ARB
);
1553 if (type
== GL_FLOAT_VEC4_ARB
)
1554 convert_bool_to_float
= GL_TRUE
;
1556 convert_bool_to_int
= GL_TRUE
;
1558 case GL_SAMPLER_1D_ARB
:
1559 case GL_SAMPLER_2D_ARB
:
1560 case GL_SAMPLER_3D_ARB
:
1561 case GL_SAMPLER_CUBE_ARB
:
1562 case GL_SAMPLER_1D_SHADOW_ARB
:
1563 case GL_SAMPLER_2D_SHADOW_ARB
:
1564 types_match
= (type
== GL_INT
);
1567 /* uniform is a float type */
1568 types_match
= (type
== GL_FLOAT
);
1577 case GL_INT_VEC2_ARB
:
1578 case GL_INT_VEC3_ARB
:
1579 case GL_INT_VEC4_ARB
:
1580 convert_float_to_int
= GL_TRUE
;
1584 for (i
= 0; i
< SLANG_SHADER_MAX
; i
++) {
1585 if (uniform
->address
[i
] != ~0) {
1586 /* XXX if bools are really implemented as floats, some of this
1587 * could probably be culled out.
1590 = &impl
->_obj
.prog
.machines
[i
]->mem
[uniform
->address
[i
] / 4];
1591 /* total number of values to copy */
1593 = count
* slang_export_data_quant_components(uniform
->quant
);
1595 if (convert_bool_to_float
) {
1596 GLfloat
*dst
= (GLfloat
*) (data
);
1597 const GLfloat
*src
= (GLfloat
*) source
;
1598 for (j
= 0; j
< total
; j
++)
1599 dst
[j
] = src
[j
] == 0.0 ? 0.0 : 1.0;
1601 else if (convert_bool_to_int
) {
1602 GLint
*dst
= (GLint
*) (data
);
1603 const GLfloat
*src
= (GLfloat
*) source
;
1604 for (j
= 0; j
< total
; j
++)
1605 dst
[j
] = src
[j
] == 0.0 ? 0 : 1;
1607 else if (convert_float_to_int
) {
1608 GLint
*dst
= (GLint
*) (data
);
1609 const GLfloat
*src
= (GLfloat
*) source
;
1610 for (j
= 0; j
< total
; j
++)
1611 dst
[j
] = (GLint
) src
[j
];
1614 /* no type conversion needed */
1615 _mesa_memcpy(data
, source
, total
* sizeof(GLfloat
));
1626 _program_GetActiveAttrib(struct gl2_program_intf
**intf
, GLuint index
,
1627 GLsizei maxLength
, GLsizei
* length
, GLint
* size
,
1628 GLenum
* type
, GLchar
* name
)
1630 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1631 slang_active_variable
*a
= &impl
->_obj
.prog
.active_attribs
.table
[index
];
1633 get_active_variable(a
, maxLength
, length
, size
, type
, name
);
1637 _program_GetActiveAttribMaxLength(struct gl2_program_intf
**intf
)
1639 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1641 return get_active_variable_max_length(&impl
->_obj
.prog
.active_attribs
);
1645 _program_GetActiveAttribCount(struct gl2_program_intf
**intf
)
1647 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1649 return impl
->_obj
.prog
.active_attribs
.count
;
1653 _program_GetAttribLocation(struct gl2_program_intf
**intf
,
1654 const GLchar
* name
)
1656 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1657 slang_attrib_bindings
*attribs
= &impl
->_obj
.prog
.attribs
;
1660 for (i
= 0; i
< attribs
->binding_count
; i
++)
1661 if (_mesa_strcmp(attribs
->bindings
[i
].name
, name
) == 0)
1662 return attribs
->bindings
[i
].first_slot_index
;
1667 _program_OverrideAttribBinding(struct gl2_program_intf
**intf
, GLuint index
,
1668 const GLchar
* name
)
1670 GET_CURRENT_CONTEXT(ctx
);
1671 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1672 slang_program
*pro
= &impl
->_obj
.prog
;
1674 if (!_slang_attrib_overrides_add(&pro
->attrib_overrides
, index
, name
))
1675 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "_program_OverrideAttribBinding");
1679 _program_WriteAttrib(struct gl2_program_intf
**intf
, GLuint index
,
1680 const GLfloat
* value
)
1682 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) (intf
);
1683 slang_program
*pro
= &impl
->_obj
.prog
;
1684 slang_attrib_slot
*slot
= &pro
->attribs
.slots
[index
];
1687 * Generic attributes can be allocated in a shader with scalar, vec
1688 * or mat type. For scalar and vec types (specifically float, vec2
1689 * and vec3) this is simple - just ignore the extra components. For
1690 * mat type this is more complicated - the vertex_shader spec
1691 * requires to store every column of a matrix in a separate attrib
1692 * slot. To prvent from overwriting data from neighbouring matrix
1693 * columns, the "fill" information is kept to know how many
1694 * components to copy.
1697 if (slot
->addr
!= ~0)
1698 _mesa_memcpy(&pro
->machines
[SLANG_SHADER_VERTEX
]->mem
[slot
->addr
/ 4].
1699 _float
, value
, slot
->fill
* sizeof(GLfloat
));
1703 _program_UpdateVarying(struct gl2_program_intf
**intf
, GLuint index
,
1704 GLfloat
* value
, GLboolean vert
)
1706 struct gl2_program_impl
*impl
= (struct gl2_program_impl
*) intf
;
1707 slang_program
*pro
= &impl
->_obj
.prog
;
1710 if (index
>= pro
->varyings
.slot_count
)
1713 addr
= pro
->varyings
.slots
[index
].vert_addr
/ 4;
1715 addr
= pro
->varyings
.slots
[index
].frag_addr
/ 4;
1718 *value
= pro
->machines
[SLANG_SHADER_VERTEX
]->mem
[addr
]._float
;
1720 pro
->machines
[SLANG_SHADER_FRAGMENT
]->mem
[addr
]._float
= *value
;
1724 static struct gl2_program_intf _program_vftbl
= {
1730 _program_QueryInterface
1735 _generic_GetDeleteStatus
,
1736 _generic_GetInfoLog
,
1737 _generic_GetInfoLogLength
1741 _container_GetAttachedCount
,
1742 _container_GetAttached
1744 _program_GetLinkStatus
,
1745 _program_GetValidateStatus
,
1748 _program_UpdateFixedUniforms
,
1749 _program_UpdateFixedAttrib
,
1750 _program_UpdateFixedVarying
,
1751 _program_GetTextureImageUsage
,
1752 _program_IsShaderPresent
,
1753 _program_GetActiveUniform
,
1754 _program_GetActiveUniformMaxLength
,
1755 _program_GetActiveUniformCount
,
1756 _program_GetUniformLocation
,
1757 _program_WriteUniform
,
1758 _program_ReadUniform
,
1759 _program_GetActiveAttrib
,
1760 _program_GetActiveAttribMaxLength
,
1761 _program_GetActiveAttribCount
,
1762 _program_GetAttribLocation
,
1763 _program_OverrideAttribBinding
,
1764 _program_WriteAttrib
,
1765 _program_UpdateVarying
1769 _program_constructor(struct gl2_program_impl
*impl
)
1771 _container_constructor((struct gl2_container_impl
*) impl
);
1772 impl
->_vftbl
= &_program_vftbl
;
1773 impl
->_obj
._container
._generic
._unknown
._destructor
= _program_destructor
;
1774 impl
->_obj
.link_status
= GL_FALSE
;
1775 impl
->_obj
.validate_status
= GL_FALSE
;
1776 #if USE_3DLABS_FRONTEND
1777 impl
->_obj
.linker
= ShConstructLinker(EShExVertexFragment
, 0);
1778 impl
->_obj
.uniforms
= ShConstructUniformMap();
1780 _slang_program_ctr(&impl
->_obj
.prog
);
1783 struct gl2_fragment_shader_obj
1785 struct gl2_shader_obj _shader
;
1788 struct gl2_fragment_shader_impl
1790 struct gl2_fragment_shader_intf
*_vftbl
;
1791 struct gl2_fragment_shader_obj _obj
;
1795 _fragment_shader_destructor(struct gl2_unknown_intf
**intf
)
1797 struct gl2_fragment_shader_impl
*impl
=
1798 (struct gl2_fragment_shader_impl
*) intf
;
1801 /* TODO free fragment shader data */
1803 _shader_destructor(intf
);
1806 static struct gl2_unknown_intf
**
1807 _fragment_shader_QueryInterface(struct gl2_unknown_intf
**intf
,
1810 if (uiid
== UIID_FRAGMENT_SHADER
) {
1811 (**intf
).AddRef(intf
);
1814 return _shader_QueryInterface(intf
, uiid
);
1818 _fragment_shader_GetSubType(struct gl2_shader_intf
**intf
)
1820 return GL_FRAGMENT_SHADER_ARB
;
1823 static struct gl2_fragment_shader_intf _fragment_shader_vftbl
= {
1829 _fragment_shader_QueryInterface
1834 _generic_GetDeleteStatus
,
1836 _shader_GetInfoLogLength
1838 _fragment_shader_GetSubType
,
1839 _shader_GetCompileStatus
,
1847 _fragment_shader_constructor(struct gl2_fragment_shader_impl
*impl
)
1849 _shader_constructor((struct gl2_shader_impl
*) impl
);
1850 impl
->_vftbl
= &_fragment_shader_vftbl
;
1851 impl
->_obj
._shader
._generic
._unknown
._destructor
=
1852 _fragment_shader_destructor
;
1853 #if USE_3DLABS_FRONTEND
1854 impl
->_obj
._shader
._3dlabs_shhandle
._obj
.handle
=
1855 ShConstructCompiler(EShLangFragment
, 0);
1859 struct gl2_vertex_shader_obj
1861 struct gl2_shader_obj _shader
;
1864 struct gl2_vertex_shader_impl
1866 struct gl2_vertex_shader_intf
*_vftbl
;
1867 struct gl2_vertex_shader_obj _obj
;
1871 _vertex_shader_destructor(struct gl2_unknown_intf
**intf
)
1873 struct gl2_vertex_shader_impl
*impl
=
1874 (struct gl2_vertex_shader_impl
*) intf
;
1877 /* TODO free vertex shader data */
1879 _shader_destructor(intf
);
1882 static struct gl2_unknown_intf
**
1883 _vertex_shader_QueryInterface(struct gl2_unknown_intf
**intf
,
1886 if (uiid
== UIID_VERTEX_SHADER
) {
1887 (**intf
).AddRef(intf
);
1890 return _shader_QueryInterface(intf
, uiid
);
1894 _vertex_shader_GetSubType(struct gl2_shader_intf
**intf
)
1896 return GL_VERTEX_SHADER_ARB
;
1899 static struct gl2_vertex_shader_intf _vertex_shader_vftbl
= {
1905 _vertex_shader_QueryInterface
1910 _generic_GetDeleteStatus
,
1912 _shader_GetInfoLogLength
1914 _vertex_shader_GetSubType
,
1915 _shader_GetCompileStatus
,
1923 _vertex_shader_constructor(struct gl2_vertex_shader_impl
*impl
)
1925 _shader_constructor((struct gl2_shader_impl
*) impl
);
1926 impl
->_vftbl
= &_vertex_shader_vftbl
;
1927 impl
->_obj
._shader
._generic
._unknown
._destructor
=
1928 _vertex_shader_destructor
;
1929 #if USE_3DLABS_FRONTEND
1930 impl
->_obj
._shader
._3dlabs_shhandle
._obj
.handle
=
1931 ShConstructCompiler(EShLangVertex
, 0);
1935 struct gl2_debug_obj
1937 struct gl2_generic_obj _generic
;
1940 struct gl2_debug_impl
1942 struct gl2_debug_intf
*_vftbl
;
1943 struct gl2_debug_obj _obj
;
1947 _debug_destructor(struct gl2_unknown_intf
**intf
)
1949 struct gl2_debug_impl
*impl
= (struct gl2_debug_impl
*) (intf
);
1954 _generic_destructor(intf
);
1957 static struct gl2_unknown_intf
**
1958 _debug_QueryInterface(struct gl2_unknown_intf
**intf
, enum gl2_uiid uiid
)
1960 if (uiid
== UIID_DEBUG
) {
1961 (**intf
).AddRef(intf
);
1964 return _generic_QueryInterface(intf
, uiid
);
1968 _debug_GetType(struct gl2_generic_intf
**intf
)
1970 return /*GL_DEBUG_OBJECT_MESA */ 0;
1974 _debug_ClearDebugLog(struct gl2_debug_intf
**intf
, GLenum logType
,
1977 struct gl2_debug_impl
*impl
= (struct gl2_debug_impl
*) (intf
);
1984 _debug_GetDebugLog(struct gl2_debug_intf
**intf
, GLenum logType
,
1985 GLenum shaderType
, GLsizei maxLength
, GLsizei
* length
,
1986 GLcharARB
* infoLog
)
1988 struct gl2_debug_impl
*impl
= (struct gl2_debug_impl
*) (intf
);
1995 _debug_GetDebugLogLength(struct gl2_debug_intf
**intf
, GLenum logType
,
1998 struct gl2_debug_impl
*impl
= (struct gl2_debug_impl
*) (intf
);
2006 static struct gl2_debug_intf _debug_vftbl
= {
2011 _debug_QueryInterface
2016 _generic_GetDeleteStatus
,
2017 _generic_GetInfoLog
,
2018 _generic_GetInfoLogLength
2020 _debug_ClearDebugLog
,
2022 _debug_GetDebugLogLength
2026 _debug_constructor(struct gl2_debug_impl
*impl
)
2028 _generic_constructor((struct gl2_generic_impl
*) (impl
));
2029 impl
->_vftbl
= &_debug_vftbl
;
2030 impl
->_obj
._generic
._unknown
._destructor
= _debug_destructor
;
2034 _mesa_3dlabs_create_shader_object(GLenum shaderType
)
2036 switch (shaderType
) {
2037 case GL_FRAGMENT_SHADER_ARB
:
2039 struct gl2_fragment_shader_impl
*x
=
2040 (struct gl2_fragment_shader_impl
*)
2041 _mesa_malloc(sizeof(struct gl2_fragment_shader_impl
));
2044 _fragment_shader_constructor(x
);
2045 return x
->_obj
._shader
._generic
.name
;
2049 case GL_VERTEX_SHADER_ARB
:
2051 struct gl2_vertex_shader_impl
*x
= (struct gl2_vertex_shader_impl
*)
2052 _mesa_malloc(sizeof(struct gl2_vertex_shader_impl
));
2055 _vertex_shader_constructor(x
);
2056 return x
->_obj
._shader
._generic
.name
;
2066 _mesa_3dlabs_create_program_object(void)
2068 struct gl2_program_impl
*x
= (struct gl2_program_impl
*)
2069 _mesa_malloc(sizeof(struct gl2_program_impl
));
2072 _program_constructor(x
);
2073 return x
->_obj
._container
._generic
.name
;
2080 _mesa_3dlabs_create_debug_object(GLvoid
)
2082 struct gl2_debug_impl
*obj
;
2085 (struct gl2_debug_impl
*) (_mesa_malloc(sizeof(struct gl2_debug_impl
)));
2087 _debug_constructor(obj
);
2088 return obj
->_obj
._generic
.name
;
2093 #include "slang_assemble.h"
2094 #include "slang_execute.h"
2097 _slang_fetch_discard(struct gl2_program_intf
**pro
, GLboolean
* val
)
2099 struct gl2_program_impl
*impl
;
2101 impl
= (struct gl2_program_impl
*) pro
;
2103 impl
->_obj
.prog
.machines
[SLANG_SHADER_FRAGMENT
]->
2104 kill
? GL_TRUE
: GL_FALSE
;
2109 exec_shader(struct gl2_program_intf
**pro
, GLuint i
)
2111 struct gl2_program_impl
*impl
;
2114 impl
= (struct gl2_program_impl
*) pro
;
2115 p
= &impl
->_obj
.prog
;
2117 slang_machine_init(p
->machines
[i
]);
2118 p
->machines
[i
]->ip
= p
->code
[i
][SLANG_COMMON_CODE_MAIN
];
2120 _slang_execute2(p
->assemblies
[i
], p
->machines
[i
]);
2124 _slang_exec_fragment_shader(struct gl2_program_intf
**pro
)
2126 exec_shader(pro
, SLANG_SHADER_FRAGMENT
);
2130 _slang_exec_vertex_shader(struct gl2_program_intf
**pro
)
2132 exec_shader(pro
, SLANG_SHADER_VERTEX
);
2138 _mesa_init_shaderobjects_3dlabs(GLcontext
* ctx
)
2140 #if USE_3DLABS_FRONTEND
2141 _glslang_3dlabs_InitProcess();
2142 _glslang_3dlabs_ShInitialize();