- Precision *prec = new Precision;
- if(!type.compare(0, 7, "sampler"))
- prec->precision = "lowp";
- else if(stage->type==Stage::FRAGMENT)
- prec->precision = "mediump";
+ set<unsigned> &used = used_bindings[0];
+
+ unsigned bind_point = fold32(hash64(name))%range;
+ while(used.count(bind_point))
+ bind_point = (bind_point+1)%range;
+
+ add_layout_value(layout, "binding", bind_point);
+ uniforms[name].bind_point = bind_point;
+ used.insert(bind_point);
+ }
+}
+
+void LocationAllocator::add_layout_value(RefPtr<Layout> &layout, const string &name, unsigned value)
+{
+ if(!layout)
+ layout = new Layout;
+
+ Layout::Qualifier qual;
+ qual.name = name;
+ qual.has_value = true;
+ qual.value = value;
+ layout->qualifiers.push_back(qual);
+}
+
+void LocationAllocator::visit(VariableDeclaration &var)
+{
+ if(!var.name.compare(0, 3, "gl_"))
+ return;
+
+ if(!var.interface.empty())
+ {
+ int location = (var.layout ? get_layout_value(*var.layout, "location") : -1);
+
+ if(location<0 && var.linked_declaration && var.linked_declaration->layout)
+ {
+ location = get_layout_value(*var.linked_declaration->layout, "location");
+ if(location>=0)
+ add_layout_value(var.layout, "location", location);
+ }
+
+ if(location>=0)
+ {
+ unsigned size = LocationCounter().apply(var);
+ for(unsigned i=0; i<size; ++i)
+ used_locations[var.interface].insert(location+i);
+ if(var.interface=="uniform")
+ uniforms[var.name].location = location;
+ }