X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Freflect.cpp;h=91e8fa55dde940020c5255e97e48eb69abbf7afb;hb=59347f76bc985e8c9c769d4a3eee672cba9c920b;hp=e63553163c8435f23e2199effa17cc91eb5e52ee;hpb=3ffa465364a36477b81b1b644ae8d19ee3bac8c2;p=libs%2Fgl.git diff --git a/source/glsl/reflect.cpp b/source/glsl/reflect.cpp index e6355316..91e8fa55 100644 --- a/source/glsl/reflect.cpp +++ b/source/glsl/reflect.cpp @@ -6,6 +6,46 @@ 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(from.kind==BasicTypeDeclaration::INT && from.sign!=to.sign) + return from.sign && from.size<=to.size; + 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(): @@ -85,7 +125,7 @@ void TypeComparer::visit(BasicTypeDeclaration &basic) { if(BasicTypeDeclaration *basic1 = multi_visit(basic)) { - if(basic1->kind!=basic.kind || basic1->size!=basic.size) + if(basic1->kind!=basic.kind || basic1->size!=basic.size || basic1->sign!=basic.sign) r_result = false; else if(basic1->base_type && basic.base_type) compare(*basic1->base_type, *basic.base_type); @@ -279,7 +319,11 @@ void DependencyCollector::visit(InterfaceBlockReference &iface) void DependencyCollector::visit(FunctionCall &call) { if(call.declaration) + { dependencies.insert(call.declaration); + if(call.declaration->definition) + call.declaration->definition->visit(*this); + } TraversingVisitor::visit(call); } @@ -295,6 +339,15 @@ void DependencyCollector::visit(VariableDeclaration &var) TraversingVisitor::visit(var); } +void DependencyCollector::visit(FunctionDeclaration &func) +{ + if(!visited_functions.count(&func)) + { + visited_functions.insert(&func); + TraversingVisitor::visit(func); + } +} + } // namespace SL } // namespace GL } // namespace Msp