X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fglsl%2Freflect.cpp;h=c2a913f982acfcb61c6ca7a0289f3233f3d434e9;hp=c38e3aecbb3d487c6c7c2f10f510b6495092e872;hb=523491787b2b0321748a53f139c1a4355d2f9e85;hpb=03b21dc33ad615efa26849323a2018dd989218c3 diff --git a/source/glsl/reflect.cpp b/source/glsl/reflect.cpp index c38e3aec..c2a913f9 100644 --- a/source/glsl/reflect.cpp +++ b/source/glsl/reflect.cpp @@ -6,6 +6,44 @@ namespace Msp { namespace GL { namespace SL { +bool is_scalar(const BasicTypeDeclaration &type) +{ + return (type.kind==BasicTypeDeclaration::INT || type.kind==BasicTypeDeclaration::FLOAT); +} + +bool is_vector_or_matrix(const BasicTypeDeclaration &type) +{ + return (type.kind==BasicTypeDeclaration::VECTOR || type.kind==BasicTypeDeclaration::MATRIX); +} + +BasicTypeDeclaration *get_element_type(BasicTypeDeclaration &type) +{ + if(is_vector_or_matrix(type) || type.kind==BasicTypeDeclaration::ARRAY) + { + BasicTypeDeclaration *basic_base = dynamic_cast(type.base_type); + return (basic_base ? get_element_type(*basic_base) : 0); + } + else + return &type; +} + +bool can_convert(const BasicTypeDeclaration &from, const BasicTypeDeclaration &to) +{ + if(from.kind==BasicTypeDeclaration::INT && to.kind==BasicTypeDeclaration::FLOAT) + return from.size<=to.size; + else if(from.kind!=to.kind) + return false; + else if(is_vector_or_matrix(from) && from.size==to.size) + { + BasicTypeDeclaration *from_base = dynamic_cast(from.base_type); + BasicTypeDeclaration *to_base = dynamic_cast(to.base_type); + return (from_base && to_base && can_convert(*from_base, *to_base)); + } + else + return false; +} + + unsigned TypeComparer::next_tag = 1; TypeComparer::TypeComparer():