X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fgenerate.cpp;h=13f67d8cade070a4349bb2335080b27d1a2c790c;hb=518f751d385b733adbf43fe4056403740709edec;hp=ff863824055ae76ef51cc9fdd08521b2b3548aa2;hpb=39141d961e55f56d540b3678f9f8fe94868f2652;p=libs%2Fgl.git diff --git a/source/glsl/generate.cpp b/source/glsl/generate.cpp index ff863824..13f67d8c 100644 --- a/source/glsl/generate.cpp +++ b/source/glsl/generate.cpp @@ -99,15 +99,9 @@ void ConstantSpecializer::visit(VariableDeclaration &var) { RefPtr literal = new Literal; if(var.type=="bool") - { literal->token = (i->second ? "true" : "false"); - literal->value = static_cast(i->second); - } else if(var.type=="int") - { literal->token = lexical_cast(i->second); - literal->value = i->second; - } var.init_expression = literal; } } @@ -122,7 +116,6 @@ void BlockHierarchyResolver::enter(Block &block) VariableResolver::VariableResolver(): stage(0), - builtins(0), members(0), record_target(false), assignment_target(0), @@ -132,16 +125,11 @@ VariableResolver::VariableResolver(): void VariableResolver::apply(Stage &s) { stage = &s; - Stage *builtin_stage = get_builtins(s.type); - builtins = (builtin_stage ? &builtin_stage->content : 0); + s.types.clear(); + s.interface_blocks.clear(); s.content.visit(*this); } -Block *VariableResolver::next_block(Block &block) -{ - return block.parent ? block.parent : &block!=builtins ? builtins : 0; -} - void VariableResolver::enter(Block &block) { block.variables.clear(); @@ -151,7 +139,7 @@ void VariableResolver::visit(VariableReference &var) { var.declaration = 0; members = 0; - for(Block *block=current_block; (!var.declaration && block); block=next_block(*block)) + for(Block *block=current_block; (!var.declaration && block); block=block->parent) { map::iterator i = block->variables.find(var.name); if(i!=block->variables.end()) @@ -203,7 +191,7 @@ void VariableResolver::visit(VariableReference &var) void VariableResolver::visit(InterfaceBlockReference &iface) { iface.declaration = 0; - for(Block *block=current_block; block; block=next_block(*block)) + for(Block *block=current_block; block; block=block->parent) { map::iterator i = stage->interface_blocks.find(iface.name); if(i!=stage->interface_blocks.end()) @@ -312,6 +300,7 @@ void VariableResolver::visit(InterfaceBlock &iface) void FunctionResolver::apply(Stage &s) { stage = &s; + s.functions.clear(); s.content.visit(*this); } @@ -666,111 +655,6 @@ void InterfaceGenerator::visit(Passthrough &pass) nodes_to_remove.insert(&pass); } - -DeclarationReorderer::DeclarationReorderer(): - kind(NO_DECLARATION) -{ } - -void DeclarationReorderer::visit(FunctionCall &call) -{ - FunctionDeclaration *def = call.declaration; - if(def) - def = def->definition; - if(def && !ordered_funcs.count(def)) - needed_funcs.insert(def); -} - -void DeclarationReorderer::visit(Block &block) -{ - if(block.parent) - return TraversingVisitor::visit(block); - - NodeList::iterator struct_insert_point = block.body.end(); - NodeList::iterator variable_insert_point = block.body.end(); - NodeList::iterator function_insert_point = block.body.end(); - unsigned unordered_func_count = 0; - bool ordered_any_funcs = false; - - for(NodeList::iterator i=block.body.begin(); i!=block.body.end(); ) - { - kind = NO_DECLARATION; - (*i)->visit(*this); - - bool moved = false; - if(kind==STRUCT && struct_insert_point!=block.body.end()) - { - block.body.insert(struct_insert_point, *i); - moved = true; - } - else if(kind>STRUCT && struct_insert_point==block.body.end()) - struct_insert_point = i; - - if(kind==VARIABLE && variable_insert_point!=block.body.end()) - { - block.body.insert(variable_insert_point, *i); - moved = true; - } - else if(kind>VARIABLE && variable_insert_point==block.body.end()) - variable_insert_point = i; - - if(kind==FUNCTION) - { - if(function_insert_point==block.body.end()) - function_insert_point = i; - - if(needed_funcs.empty()) - { - ordered_funcs.insert(i->get()); - if(i!=function_insert_point) - { - block.body.insert(function_insert_point, *i); - moved = true; - } - else - ++function_insert_point; - ordered_any_funcs = true; - } - else - ++unordered_func_count; - } - - if(moved) - { - if(function_insert_point==i) - ++function_insert_point; - block.body.erase(i++); - } - else - ++i; - - if(i==block.body.end() && unordered_func_count) - { - if(!ordered_any_funcs) - // A subset of the remaining functions forms a recursive loop - /* TODO pick a function and move it up, adding any necessary - declarations */ - break; - - i = function_insert_point; - unordered_func_count = 0; - } - } -} - -void DeclarationReorderer::visit(VariableDeclaration &var) -{ - TraversingVisitor::visit(var); - kind = VARIABLE; -} - -void DeclarationReorderer::visit(FunctionDeclaration &func) -{ - needed_funcs.clear(); - func.body.visit(*this); - needed_funcs.erase(&func); - kind = FUNCTION; -} - } // namespace SL } // namespace GL } // namespace Msp