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 slang_assemble_typeinfo.c
32 #include "slang_typeinfo.h"
33 #include "slang_compile.h"
34 #include "slang_log.h"
35 #include "slang_mem.h"
36 #include "prog_instruction.h"
40 * Checks if a field selector is a general swizzle (an r-value swizzle
41 * with replicated components or an l-value swizzle mask) for a
42 * vector. Returns GL_TRUE if this is the case, <swz> is filled with
43 * swizzle information. Returns GL_FALSE otherwise.
46 _slang_is_swizzle(const char *field
, GLuint rows
, slang_swizzle
* swz
)
49 GLboolean xyzw
= GL_FALSE
, rgba
= GL_FALSE
, stpq
= GL_FALSE
;
52 * We rely on undefined/nil values to distinguish between
53 * regular swizzles and writemasks.
54 * For example, the swizzle ".xNNN" is the writemask ".x".
55 * That's different than the swizzle ".xxxx".
57 for (i
= 0; i
< 4; i
++)
58 swz
->swizzle
[i
] = SWIZZLE_NIL
;
60 /* the swizzle can be at most 4-component long */
61 swz
->num_components
= slang_string_length(field
);
62 if (swz
->num_components
> 4)
65 for (i
= 0; i
< swz
->num_components
; i
++) {
66 /* mark which swizzle group is used */
90 /* collect swizzle component */
114 /* check if the component is valid for given vector's row count */
115 if (rows
<= swz
->swizzle
[i
])
119 /* only one swizzle group can be used */
120 if ((xyzw
&& rgba
) || (xyzw
&& stpq
) || (rgba
&& stpq
))
129 * Checks if a general swizzle is an l-value swizzle - these swizzles
130 * do not have duplicated fields. Returns GL_TRUE if this is a
131 * swizzle mask. Returns GL_FALSE otherwise
134 _slang_is_swizzle_mask(const slang_swizzle
* swz
, GLuint rows
)
138 /* the swizzle may not be longer than the vector dim */
139 if (swz
->num_components
> rows
)
142 /* the swizzle components cannot be duplicated */
143 for (i
= 0; i
< swz
->num_components
; i
++) {
144 if ((c
& (1 << swz
->swizzle
[i
])) != 0)
146 c
|= 1 << swz
->swizzle
[i
];
154 * Combines (multiplies) two swizzles to form single swizzle.
155 * Example: "vec.wzyx.yx" --> "vec.zw".
158 _slang_multiply_swizzles(slang_swizzle
* dst
, const slang_swizzle
* left
,
159 const slang_swizzle
* right
)
163 dst
->num_components
= right
->num_components
;
164 for (i
= 0; i
< right
->num_components
; i
++)
165 dst
->swizzle
[i
] = left
->swizzle
[right
->swizzle
[i
]];
170 slang_type_specifier_ctr(slang_type_specifier
* self
)
172 self
->type
= SLANG_SPEC_VOID
;
173 self
->_struct
= NULL
;
178 slang_type_specifier_dtr(slang_type_specifier
* self
)
180 if (self
->_struct
!= NULL
) {
181 slang_struct_destruct(self
->_struct
);
183 _slang_free(self
->_struct
);
185 slang_alloc_free(self
->_struct
);
188 if (self
->_array
!= NULL
) {
189 slang_type_specifier_dtr(self
->_array
);
191 _slang_free(self
->_array
);
193 slang_alloc_free(self
->_array
);
199 slang_type_specifier_copy(slang_type_specifier
* x
,
200 const slang_type_specifier
* y
)
202 slang_type_specifier z
;
204 slang_type_specifier_ctr(&z
);
206 if (z
.type
== SLANG_SPEC_STRUCT
) {
208 z
._struct
= (slang_struct
*) _slang_alloc(sizeof(slang_struct
));
210 z
._struct
= (slang_struct
*) slang_alloc_malloc(sizeof(slang_struct
));
212 if (z
._struct
== NULL
) {
213 slang_type_specifier_dtr(&z
);
216 if (!slang_struct_construct(z
._struct
)) {
218 _slang_free(z
._struct
);
220 slang_alloc_free(z
._struct
);
222 slang_type_specifier_dtr(&z
);
225 if (!slang_struct_copy(z
._struct
, y
->_struct
)) {
226 slang_type_specifier_dtr(&z
);
230 else if (z
.type
== SLANG_SPEC_ARRAY
) {
232 (slang_type_specifier
*)
234 _slang_alloc(sizeof(slang_type_specifier
));
236 slang_alloc_malloc(sizeof(slang_type_specifier
));
238 if (z
._array
== NULL
) {
239 slang_type_specifier_dtr(&z
);
242 slang_type_specifier_ctr(z
._array
);
243 if (!slang_type_specifier_copy(z
._array
, y
->_array
)) {
244 slang_type_specifier_dtr(&z
);
248 slang_type_specifier_dtr(x
);
255 * Test if two types are equal.
258 slang_type_specifier_equal(const slang_type_specifier
* x
,
259 const slang_type_specifier
* y
)
261 if (x
->type
!= y
->type
)
263 if (x
->type
== SLANG_SPEC_STRUCT
)
264 return slang_struct_equal(x
->_struct
, y
->_struct
);
265 if (x
->type
== SLANG_SPEC_ARRAY
)
266 return slang_type_specifier_equal(x
->_array
, y
->_array
);
272 * As above, but allow float/int casting.
275 slang_type_specifier_compatible(const slang_type_specifier
* x
,
276 const slang_type_specifier
* y
)
278 /* special case: float == int */
279 if (x
->type
== SLANG_SPEC_INT
&& y
->type
== SLANG_SPEC_FLOAT
) {
282 /* XXX may need to add bool/int compatibility, etc */
284 if (x
->type
!= y
->type
)
286 if (x
->type
== SLANG_SPEC_STRUCT
)
287 return slang_struct_equal(x
->_struct
, y
->_struct
);
288 if (x
->type
== SLANG_SPEC_ARRAY
)
289 return slang_type_specifier_compatible(x
->_array
, y
->_array
);
295 slang_typeinfo_construct(slang_typeinfo
* ti
)
297 slang_type_specifier_ctr(&ti
->spec
);
303 slang_typeinfo_destruct(slang_typeinfo
* ti
)
305 slang_type_specifier_dtr(&ti
->spec
);
311 * Determine the return type of a function.
312 * \param a_name the function name
313 * \param param function parameters (overloading)
314 * \param num_params number of parameters to function
315 * \param space namespace to search
316 * \param spec returns the type
317 * \param funFound returns pointer to the function, or NULL if not found.
318 * \return GL_TRUE for success, GL_FALSE if failure (bad function name)
321 _slang_typeof_function(slang_atom a_name
,
322 slang_operation
* params
, GLuint num_params
,
323 const slang_name_space
* space
,
324 slang_type_specifier
* spec
,
325 slang_function
**funFound
,
326 slang_atom_pool
*atoms
, slang_info_log
*log
)
328 *funFound
= _slang_locate_function(space
->funcs
, a_name
, params
,
329 num_params
, space
, atoms
, log
);
331 return GL_TRUE
; /* yes, not false */
332 return slang_type_specifier_copy(spec
, &(*funFound
)->header
.type
.specifier
);
337 * Determine the type of a math function.
338 * \param name name of the operator, one of +,-,*,/ or unary -
339 * \param params array of function parameters
340 * \param num_params number of parameters
341 * \param space namespace to use
342 * \param spec returns the function's type
343 * \param atoms atom pool
344 * \return GL_TRUE for success, GL_FALSE if failure
347 typeof_math_call(const char *name
, slang_operation
*call
,
348 const slang_name_space
* space
,
349 slang_type_specifier
* spec
,
350 slang_atom_pool
* atoms
,
354 /* we've previously resolved this function call */
355 slang_type_specifier_copy(spec
, &call
->fun
->header
.type
.specifier
);
362 /* number of params: */
363 assert(call
->num_children
== 1 || call
->num_children
== 2);
365 atom
= slang_atom_pool_atom(atoms
, name
);
366 if (!_slang_typeof_function(atom
, call
->children
, call
->num_children
,
367 space
, spec
, &fun
, atoms
, log
))
371 /* Save pointer to save time in future */
380 _slang_typeof_operation(const slang_assemble_ctx
* A
,
381 slang_operation
* op
,
384 return _slang_typeof_operation_(op
, &A
->space
, ti
, A
->atoms
, A
->log
);
389 * Determine the return type of an operation.
390 * \param op the operation node
391 * \param space the namespace to use
392 * \param ti the returned type
393 * \param atoms atom pool
394 * \return GL_TRUE for success, GL_FALSE if failure
397 _slang_typeof_operation_(slang_operation
* op
,
398 const slang_name_space
* space
,
400 slang_atom_pool
* atoms
,
403 ti
->can_be_referenced
= GL_FALSE
;
404 ti
->is_swizzled
= GL_FALSE
;
407 case SLANG_OPER_BLOCK_NO_NEW_SCOPE
:
408 case SLANG_OPER_BLOCK_NEW_SCOPE
:
409 case SLANG_OPER_VARIABLE_DECL
:
411 case SLANG_OPER_BREAK
:
412 case SLANG_OPER_CONTINUE
:
413 case SLANG_OPER_DISCARD
:
414 case SLANG_OPER_RETURN
:
416 case SLANG_OPER_WHILE
:
419 case SLANG_OPER_VOID
:
420 ti
->spec
.type
= SLANG_SPEC_VOID
;
422 case SLANG_OPER_EXPRESSION
:
423 case SLANG_OPER_ASSIGN
:
424 case SLANG_OPER_ADDASSIGN
:
425 case SLANG_OPER_SUBASSIGN
:
426 case SLANG_OPER_MULASSIGN
:
427 case SLANG_OPER_DIVASSIGN
:
428 case SLANG_OPER_PREINCREMENT
:
429 case SLANG_OPER_PREDECREMENT
:
430 if (!_slang_typeof_operation_(op
->children
, space
, ti
, atoms
, log
))
433 case SLANG_OPER_LITERAL_BOOL
:
434 if (op
->literal_size
== 1)
435 ti
->spec
.type
= SLANG_SPEC_BOOL
;
436 else if (op
->literal_size
== 2)
437 ti
->spec
.type
= SLANG_SPEC_BVEC2
;
438 else if (op
->literal_size
== 3)
439 ti
->spec
.type
= SLANG_SPEC_BVEC3
;
440 else if (op
->literal_size
== 4)
441 ti
->spec
.type
= SLANG_SPEC_BVEC4
;
444 "Unexpected bool literal_size %d in _slang_typeof_operation()",
446 ti
->spec
.type
= SLANG_SPEC_BOOL
;
449 case SLANG_OPER_LOGICALOR
:
450 case SLANG_OPER_LOGICALXOR
:
451 case SLANG_OPER_LOGICALAND
:
452 case SLANG_OPER_EQUAL
:
453 case SLANG_OPER_NOTEQUAL
:
454 case SLANG_OPER_LESS
:
455 case SLANG_OPER_GREATER
:
456 case SLANG_OPER_LESSEQUAL
:
457 case SLANG_OPER_GREATEREQUAL
:
459 ti
->spec
.type
= SLANG_SPEC_BOOL
;
461 case SLANG_OPER_LITERAL_INT
:
462 if (op
->literal_size
== 1)
463 ti
->spec
.type
= SLANG_SPEC_INT
;
464 else if (op
->literal_size
== 2)
465 ti
->spec
.type
= SLANG_SPEC_IVEC2
;
466 else if (op
->literal_size
== 3)
467 ti
->spec
.type
= SLANG_SPEC_IVEC3
;
468 else if (op
->literal_size
== 4)
469 ti
->spec
.type
= SLANG_SPEC_IVEC4
;
472 "Unexpected int literal_size %d in _slang_typeof_operation()",
474 ti
->spec
.type
= SLANG_SPEC_INT
;
477 case SLANG_OPER_LITERAL_FLOAT
:
478 if (op
->literal_size
== 1)
479 ti
->spec
.type
= SLANG_SPEC_FLOAT
;
480 else if (op
->literal_size
== 2)
481 ti
->spec
.type
= SLANG_SPEC_VEC2
;
482 else if (op
->literal_size
== 3)
483 ti
->spec
.type
= SLANG_SPEC_VEC3
;
484 else if (op
->literal_size
== 4)
485 ti
->spec
.type
= SLANG_SPEC_VEC4
;
488 "Unexpected float literal_size %d in _slang_typeof_operation()",
490 ti
->spec
.type
= SLANG_SPEC_FLOAT
;
493 case SLANG_OPER_IDENTIFIER
:
496 var
= _slang_locate_variable(op
->locals
, op
->a_id
, GL_TRUE
);
498 slang_info_log_error(log
, "undefined variable '%s'",
502 if (!slang_type_specifier_copy(&ti
->spec
, &var
->type
.specifier
)) {
503 slang_info_log_memory(log
);
506 ti
->can_be_referenced
= GL_TRUE
;
507 ti
->array_len
= var
->array_len
;
510 case SLANG_OPER_SEQUENCE
:
511 /* TODO: check [0] and [1] if they match */
512 if (!_slang_typeof_operation_(&op
->children
[1], space
, ti
, atoms
, log
)) {
515 ti
->can_be_referenced
= GL_FALSE
;
516 ti
->is_swizzled
= GL_FALSE
;
518 /*case SLANG_OPER_MODASSIGN: */
519 /*case SLANG_OPER_LSHASSIGN: */
520 /*case SLANG_OPER_RSHASSIGN: */
521 /*case SLANG_OPER_ORASSIGN: */
522 /*case SLANG_OPER_XORASSIGN: */
523 /*case SLANG_OPER_ANDASSIGN: */
524 case SLANG_OPER_SELECT
:
525 /* TODO: check [1] and [2] if they match */
526 if (!_slang_typeof_operation_(&op
->children
[1], space
, ti
, atoms
, log
)) {
529 ti
->can_be_referenced
= GL_FALSE
;
530 ti
->is_swizzled
= GL_FALSE
;
532 /*case SLANG_OPER_BITOR: */
533 /*case SLANG_OPER_BITXOR: */
534 /*case SLANG_OPER_BITAND: */
535 /*case SLANG_OPER_LSHIFT: */
536 /*case SLANG_OPER_RSHIFT: */
538 assert(op
->num_children
== 2);
539 if (!typeof_math_call("+", op
, space
, &ti
->spec
, atoms
, log
))
542 case SLANG_OPER_SUBTRACT
:
543 assert(op
->num_children
== 2);
544 if (!typeof_math_call("-", op
, space
, &ti
->spec
, atoms
, log
))
547 case SLANG_OPER_MULTIPLY
:
548 assert(op
->num_children
== 2);
549 if (!typeof_math_call("*", op
, space
, &ti
->spec
, atoms
, log
))
552 case SLANG_OPER_DIVIDE
:
553 assert(op
->num_children
== 2);
554 if (!typeof_math_call("/", op
, space
, &ti
->spec
, atoms
, log
))
557 /*case SLANG_OPER_MODULUS: */
558 case SLANG_OPER_PLUS
:
559 if (!_slang_typeof_operation_(op
->children
, space
, ti
, atoms
, log
))
561 ti
->can_be_referenced
= GL_FALSE
;
562 ti
->is_swizzled
= GL_FALSE
;
564 case SLANG_OPER_MINUS
:
565 assert(op
->num_children
== 1);
566 if (!typeof_math_call("-", op
, space
, &ti
->spec
, atoms
, log
))
569 /*case SLANG_OPER_COMPLEMENT: */
570 case SLANG_OPER_SUBSCRIPT
:
574 if (!slang_typeinfo_construct(&_ti
))
576 if (!_slang_typeof_operation_(op
->children
, space
, &_ti
, atoms
, log
)) {
577 slang_typeinfo_destruct(&_ti
);
580 ti
->can_be_referenced
= _ti
.can_be_referenced
;
581 if (_ti
.spec
.type
== SLANG_SPEC_ARRAY
) {
582 if (!slang_type_specifier_copy(&ti
->spec
, _ti
.spec
._array
)) {
583 slang_typeinfo_destruct(&_ti
);
588 if (!_slang_type_is_vector(_ti
.spec
.type
)
589 && !_slang_type_is_matrix(_ti
.spec
.type
)) {
590 slang_typeinfo_destruct(&_ti
);
591 slang_info_log_error(log
, "cannot index a non-array type");
594 ti
->spec
.type
= _slang_type_base(_ti
.spec
.type
);
596 slang_typeinfo_destruct(&_ti
);
599 case SLANG_OPER_CALL
:
601 /* we've resolved this call before */
602 slang_type_specifier_copy(&ti
->spec
, &op
->fun
->header
.type
.specifier
);
606 if (!_slang_typeof_function(op
->a_id
, op
->children
, op
->num_children
,
607 space
, &ti
->spec
, &fun
, atoms
, log
))
610 /* save result for future use */
615 slang_struct_scope_find(space
->structs
, op
->a_id
, GL_TRUE
);
617 /* struct initializer */
618 ti
->spec
.type
= SLANG_SPEC_STRUCT
;
621 (slang_struct
*) _slang_alloc(sizeof(slang_struct
));
623 (slang_struct
*) slang_alloc_malloc(sizeof(slang_struct
));
625 if (ti
->spec
._struct
== NULL
)
627 if (!slang_struct_construct(ti
->spec
._struct
)) {
629 _slang_free(ti
->spec
._struct
);
631 slang_alloc_free(ti
->spec
._struct
);
633 ti
->spec
._struct
= NULL
;
636 if (!slang_struct_copy(ti
->spec
._struct
, s
))
640 /* float, int, vec4, mat3, etc. constructor? */
642 slang_type_specifier_type type
;
644 name
= slang_atom_pool_id(atoms
, op
->a_id
);
645 type
= slang_type_specifier_type_from_string(name
);
646 if (type
== SLANG_SPEC_VOID
) {
647 slang_info_log_error(log
, "undefined function '%s'", name
);
650 ti
->spec
.type
= type
;
655 case SLANG_OPER_FIELD
:
659 if (!slang_typeinfo_construct(&_ti
))
661 if (!_slang_typeof_operation_(op
->children
, space
, &_ti
, atoms
, log
)) {
662 slang_typeinfo_destruct(&_ti
);
665 if (_ti
.spec
.type
== SLANG_SPEC_STRUCT
) {
666 slang_variable
*field
;
668 field
= _slang_locate_variable(_ti
.spec
._struct
->fields
, op
->a_id
,
671 slang_typeinfo_destruct(&_ti
);
674 if (!slang_type_specifier_copy(&ti
->spec
, &field
->type
.specifier
)) {
675 slang_typeinfo_destruct(&_ti
);
678 ti
->can_be_referenced
= _ti
.can_be_referenced
;
683 slang_type_specifier_type base
;
685 /* determine the swizzle of the field expression */
686 if (!_slang_type_is_vector(_ti
.spec
.type
)) {
687 slang_typeinfo_destruct(&_ti
);
688 slang_info_log_error(log
, "Can't swizzle scalar expression");
691 rows
= _slang_type_dim(_ti
.spec
.type
);
692 swizzle
= slang_atom_pool_id(atoms
, op
->a_id
);
693 if (!_slang_is_swizzle(swizzle
, rows
, &ti
->swz
)) {
694 slang_typeinfo_destruct(&_ti
);
695 slang_info_log_error(log
, "bad swizzle '%s'", swizzle
);
698 ti
->is_swizzled
= GL_TRUE
;
699 ti
->can_be_referenced
= _ti
.can_be_referenced
700 && _slang_is_swizzle_mask(&ti
->swz
, rows
);
701 if (_ti
.is_swizzled
) {
704 /* swizzle the swizzle */
705 _slang_multiply_swizzles(&swz
, &_ti
.swz
, &ti
->swz
);
708 base
= _slang_type_base(_ti
.spec
.type
);
709 switch (ti
->swz
.num_components
) {
711 ti
->spec
.type
= base
;
715 case SLANG_SPEC_FLOAT
:
716 ti
->spec
.type
= SLANG_SPEC_VEC2
;
719 ti
->spec
.type
= SLANG_SPEC_IVEC2
;
721 case SLANG_SPEC_BOOL
:
722 ti
->spec
.type
= SLANG_SPEC_BVEC2
;
730 case SLANG_SPEC_FLOAT
:
731 ti
->spec
.type
= SLANG_SPEC_VEC3
;
734 ti
->spec
.type
= SLANG_SPEC_IVEC3
;
736 case SLANG_SPEC_BOOL
:
737 ti
->spec
.type
= SLANG_SPEC_BVEC3
;
745 case SLANG_SPEC_FLOAT
:
746 ti
->spec
.type
= SLANG_SPEC_VEC4
;
749 ti
->spec
.type
= SLANG_SPEC_IVEC4
;
751 case SLANG_SPEC_BOOL
:
752 ti
->spec
.type
= SLANG_SPEC_BVEC4
;
762 slang_typeinfo_destruct(&_ti
);
765 case SLANG_OPER_POSTINCREMENT
:
766 case SLANG_OPER_POSTDECREMENT
:
767 if (!_slang_typeof_operation_(op
->children
, space
, ti
, atoms
, log
))
769 ti
->can_be_referenced
= GL_FALSE
;
770 ti
->is_swizzled
= GL_FALSE
;
781 * Lookup a function according to name and parameter count/types.
784 _slang_locate_function(const slang_function_scope
* funcs
, slang_atom a_name
,
785 slang_operation
* args
, GLuint num_args
,
786 const slang_name_space
* space
, slang_atom_pool
* atoms
,
791 for (i
= 0; i
< funcs
->num_functions
; i
++) {
792 slang_function
*f
= &funcs
->functions
[i
];
793 const GLuint haveRetValue
= _slang_function_has_return_value(f
);
796 if (a_name
!= f
->header
.a_name
)
798 if (f
->param_count
- haveRetValue
!= num_args
)
801 /* compare parameter / argument types */
802 for (j
= 0; j
< num_args
; j
++) {
805 if (!slang_typeinfo_construct(&ti
))
807 if (!_slang_typeof_operation_(&args
[j
], space
, &ti
, atoms
, log
)) {
808 slang_typeinfo_destruct(&ti
);
811 if (!slang_type_specifier_compatible(&ti
.spec
,
812 &f
->parameters
->variables
[j
]->type
.specifier
)) {
813 slang_typeinfo_destruct(&ti
);
816 slang_typeinfo_destruct(&ti
);
818 /* "out" and "inout" formal parameter requires the actual
819 * parameter to be l-value.
821 if (!ti
.can_be_referenced
&&
822 (f
->parameters
->variables
[j
]->type
.qualifier
== SLANG_QUAL_OUT
||
823 f
->parameters
->variables
[j
]->type
.qualifier
== SLANG_QUAL_INOUT
))
829 if (funcs
->outer_scope
!= NULL
)
830 return _slang_locate_function(funcs
->outer_scope
, a_name
, args
,
831 num_args
, space
, atoms
, log
);
837 * Determine if a type is a matrix.
838 * \return GL_TRUE if is a matrix, GL_FALSE otherwise.
841 _slang_type_is_matrix(slang_type_specifier_type ty
)
844 case SLANG_SPEC_MAT2
:
845 case SLANG_SPEC_MAT3
:
846 case SLANG_SPEC_MAT4
:
847 case SLANG_SPEC_MAT23
:
848 case SLANG_SPEC_MAT32
:
849 case SLANG_SPEC_MAT24
:
850 case SLANG_SPEC_MAT42
:
851 case SLANG_SPEC_MAT34
:
852 case SLANG_SPEC_MAT43
:
861 * Determine if a type is a vector.
862 * \return GL_TRUE if is a vector, GL_FALSE otherwise.
865 _slang_type_is_vector(slang_type_specifier_type ty
)
868 case SLANG_SPEC_VEC2
:
869 case SLANG_SPEC_VEC3
:
870 case SLANG_SPEC_VEC4
:
871 case SLANG_SPEC_IVEC2
:
872 case SLANG_SPEC_IVEC3
:
873 case SLANG_SPEC_IVEC4
:
874 case SLANG_SPEC_BVEC2
:
875 case SLANG_SPEC_BVEC3
:
876 case SLANG_SPEC_BVEC4
:
885 * Given a vector type, return the type of the vector's elements.
886 * For a matrix, return the type of the columns.
888 slang_type_specifier_type
889 _slang_type_base(slang_type_specifier_type ty
)
892 case SLANG_SPEC_FLOAT
:
893 case SLANG_SPEC_VEC2
:
894 case SLANG_SPEC_VEC3
:
895 case SLANG_SPEC_VEC4
:
896 return SLANG_SPEC_FLOAT
;
898 case SLANG_SPEC_IVEC2
:
899 case SLANG_SPEC_IVEC3
:
900 case SLANG_SPEC_IVEC4
:
901 return SLANG_SPEC_INT
;
902 case SLANG_SPEC_BOOL
:
903 case SLANG_SPEC_BVEC2
:
904 case SLANG_SPEC_BVEC3
:
905 case SLANG_SPEC_BVEC4
:
906 return SLANG_SPEC_BOOL
;
907 case SLANG_SPEC_MAT2
:
908 return SLANG_SPEC_VEC2
;
909 case SLANG_SPEC_MAT3
:
910 return SLANG_SPEC_VEC3
;
911 case SLANG_SPEC_MAT4
:
912 return SLANG_SPEC_VEC4
;
913 case SLANG_SPEC_MAT23
:
914 return SLANG_SPEC_VEC3
;
915 case SLANG_SPEC_MAT32
:
916 return SLANG_SPEC_VEC2
;
917 case SLANG_SPEC_MAT24
:
918 return SLANG_SPEC_VEC4
;
919 case SLANG_SPEC_MAT42
:
920 return SLANG_SPEC_VEC2
;
921 case SLANG_SPEC_MAT34
:
922 return SLANG_SPEC_VEC4
;
923 case SLANG_SPEC_MAT43
:
924 return SLANG_SPEC_VEC3
;
926 return SLANG_SPEC_VOID
;
932 * Return the dimensionality of a vector, or for a matrix, return number
936 _slang_type_dim(slang_type_specifier_type ty
)
939 case SLANG_SPEC_FLOAT
:
941 case SLANG_SPEC_BOOL
:
943 case SLANG_SPEC_VEC2
:
944 case SLANG_SPEC_IVEC2
:
945 case SLANG_SPEC_BVEC2
:
946 case SLANG_SPEC_MAT2
:
948 case SLANG_SPEC_VEC3
:
949 case SLANG_SPEC_IVEC3
:
950 case SLANG_SPEC_BVEC3
:
951 case SLANG_SPEC_MAT3
:
953 case SLANG_SPEC_VEC4
:
954 case SLANG_SPEC_IVEC4
:
955 case SLANG_SPEC_BVEC4
:
956 case SLANG_SPEC_MAT4
:
959 case SLANG_SPEC_MAT23
:
961 case SLANG_SPEC_MAT32
:
963 case SLANG_SPEC_MAT24
:
965 case SLANG_SPEC_MAT42
:
967 case SLANG_SPEC_MAT34
:
969 case SLANG_SPEC_MAT43
:
979 * Return the GL_* type that corresponds to a SLANG_SPEC_* type.
982 _slang_gltype_from_specifier(const slang_type_specifier
*type
)
984 switch (type
->type
) {
985 case SLANG_SPEC_BOOL
:
987 case SLANG_SPEC_BVEC2
:
989 case SLANG_SPEC_BVEC3
:
991 case SLANG_SPEC_BVEC4
:
995 case SLANG_SPEC_IVEC2
:
997 case SLANG_SPEC_IVEC3
:
999 case SLANG_SPEC_IVEC4
:
1001 case SLANG_SPEC_FLOAT
:
1003 case SLANG_SPEC_VEC2
:
1004 return GL_FLOAT_VEC2
;
1005 case SLANG_SPEC_VEC3
:
1006 return GL_FLOAT_VEC3
;
1007 case SLANG_SPEC_VEC4
:
1008 return GL_FLOAT_VEC4
;
1009 case SLANG_SPEC_MAT2
:
1010 return GL_FLOAT_MAT2
;
1011 case SLANG_SPEC_MAT3
:
1012 return GL_FLOAT_MAT3
;
1013 case SLANG_SPEC_MAT4
:
1014 return GL_FLOAT_MAT4
;
1015 case SLANG_SPEC_MAT23
:
1016 return GL_FLOAT_MAT2x3
;
1017 case SLANG_SPEC_MAT32
:
1018 return GL_FLOAT_MAT3x2
;
1019 case SLANG_SPEC_MAT24
:
1020 return GL_FLOAT_MAT2x4
;
1021 case SLANG_SPEC_MAT42
:
1022 return GL_FLOAT_MAT4x2
;
1023 case SLANG_SPEC_MAT34
:
1024 return GL_FLOAT_MAT3x4
;
1025 case SLANG_SPEC_MAT43
:
1026 return GL_FLOAT_MAT4x3
;
1027 case SLANG_SPEC_SAMPLER1D
:
1028 return GL_SAMPLER_1D
;
1029 case SLANG_SPEC_SAMPLER2D
:
1030 return GL_SAMPLER_2D
;
1031 case SLANG_SPEC_SAMPLER3D
:
1032 return GL_SAMPLER_3D
;
1033 case SLANG_SPEC_SAMPLERCUBE
:
1034 return GL_SAMPLER_CUBE
;
1035 case SLANG_SPEC_SAMPLER1DSHADOW
:
1036 return GL_SAMPLER_1D_SHADOW
;
1037 case SLANG_SPEC_SAMPLER2DSHADOW
:
1038 return GL_SAMPLER_2D_SHADOW
;
1039 case SLANG_SPEC_SAMPLER2DRECT
:
1040 return GL_SAMPLER_2D_RECT_ARB
;
1041 case SLANG_SPEC_SAMPLER2DRECTSHADOW
:
1042 return GL_SAMPLER_2D_RECT_SHADOW_ARB
;
1043 case SLANG_SPEC_ARRAY
:
1044 return _slang_gltype_from_specifier(type
->_array
);
1045 case SLANG_SPEC_STRUCT
: