X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fgenerate.cpp;h=f5b6b7adb91769277f95de93d56d605e38cc88f7;hb=5f6ee612cb83029de9559bae644c9a3b4e579259;hp=42694a8affeca317ec9e71bf4456dedd522b8bd0;hpb=3a2accb016c9cd01347c71d41e44d5ca45917209;p=libs%2Fgl.git diff --git a/source/glsl/generate.cpp b/source/glsl/generate.cpp index 42694a8a..f5b6b7ad 100644 --- a/source/glsl/generate.cpp +++ b/source/glsl/generate.cpp @@ -125,10 +125,21 @@ void TypeResolver::apply(Stage &s) s.content.visit(*this); } +TypeDeclaration *TypeResolver::resolve_type(const string &name) +{ + map::iterator i = stage->types.find(name); + if(i!=stage->types.end()) + { + map::iterator j = alias_map.find(i->second); + return (j!=alias_map.end() ? j->second : i->second); + } + else + return 0; +} + void TypeResolver::visit(BasicTypeDeclaration &type) { - map::iterator i = stage->types.find(type.base); - type.base_type = (i!=stage->types.end() ? i->second : 0); + type.base_type = resolve_type(type.base); if(type.kind==BasicTypeDeclaration::VECTOR && type.base_type) if(BasicTypeDeclaration *basic_base = dynamic_cast(type.base_type)) @@ -138,14 +149,15 @@ void TypeResolver::visit(BasicTypeDeclaration &type) type.size |= basic_base->size<<16; } + if(type.kind==BasicTypeDeclaration::ALIAS && type.base_type) + alias_map[&type] = type.base_type; + stage->types.insert(make_pair(type.name, &type)); } void TypeResolver::visit(ImageTypeDeclaration &type) { - map::iterator i = stage->types.find(type.base); - type.base_type = (i!=stage->types.end() ? i->second : 0); - + type.base_type = resolve_type(type.base); stage->types.insert(make_pair(type.name, &type)); } @@ -157,9 +169,13 @@ void TypeResolver::visit(StructDeclaration &strct) void TypeResolver::visit(VariableDeclaration &var) { - map::iterator i = stage->types.find(var.type); - if(i!=stage->types.end()) - var.type_declaration = i->second; + var.type_declaration = resolve_type(var.type); +} + +void TypeResolver::visit(FunctionDeclaration &func) +{ + func.return_type_declaration = resolve_type(func.return_type); + TraversingVisitor::visit(func); } @@ -197,12 +213,7 @@ void VariableResolver::visit(VariableReference &var) var.declaration = i->second; } - if(var.declaration) - { - if(StructDeclaration *strct = dynamic_cast(var.declaration->type_declaration)) - r_members = &strct->members.variables; - } - else + if(!var.declaration) { const map &blocks = stage->interface_blocks; map::const_iterator i = blocks.find("_"+var.name); @@ -230,6 +241,10 @@ void VariableResolver::visit(VariableReference &var) } } + if(var.declaration) + if(StructDeclaration *strct = dynamic_cast(var.declaration->type_declaration)) + r_members = &strct->members.variables; + if(record_target) { if(r_assignment_target)