throw invalid_operation("Compiler::get_fragment_outputs");
}
+const map<string, unsigned> &Compiler::get_texture_bindings() const
+{
+ if(!compiled)
+ throw invalid_operation("Compiler::get_texture_bindings");
+ return module->shared.texture_bindings;
+}
+
+const map<string, unsigned> &Compiler::get_uniform_block_bindings() const
+{
+ if(!compiled)
+ throw invalid_operation("Compiler::get_uniform_block_bindings");
+ return module->shared.uniform_block_bindings;
+}
+
const SourceMap &Compiler::get_source_map() const
{
return module->source_map;
resolve(stage, RESOLVE_VARIABLES|RESOLVE_FUNCTIONS);
PrecisionConverter().apply(stage);
}
+
+ // Collect bindings from all stages into the shared stage's maps
+ module->shared.texture_bindings.insert(stage.texture_bindings.begin(), stage.texture_bindings.end());
+ module->shared.uniform_block_bindings.insert(stage.uniform_block_bindings.begin(), stage.uniform_block_bindings.end());
}
void Compiler::inject_block(Block &target, const Block &source)
GLSL soucre). */
const std::map<std::string, unsigned> &get_fragment_outputs() const;
+ /** Returns a map of texture bindings. If the target GLSL version supports
+ bindings, the map is empty (bindings are included in the GLSL source). */
+ const std::map<std::string, unsigned> &get_texture_bindings() const;
+
+ /** Returns a map of uniform block bindings. If the target GLSL version
+ supports bindings, the map is empty (bindings are included in the GLSL
+ source). */
+ const std::map<std::string, unsigned> &get_uniform_block_bindings() const;
+
/** Returns the mapping of source indices to filenames. Can be used to
translate error messages. */
const SourceMap &get_source_map() const;
return check_extension(&Features::arb_explicit_uniform_location);
}
+bool LegacyConverter::supports_binding() const
+{
+ if(features.gl_api==OPENGL_ES2)
+ return check_version(Version(3, 10));
+ else
+ return check_version(Version(4, 20));
+}
+
void LegacyConverter::visit(VariableDeclaration &var)
{
if(var.layout)
else
++i;
}
+ else if(i->name=="binding" && !supports_binding())
+ {
+ const TypeDeclaration *type = var.type_declaration;
+ while(const BasicTypeDeclaration *basic = dynamic_cast<const BasicTypeDeclaration *>(type))
+ type = basic->base_type;
+ if(dynamic_cast<const ImageTypeDeclaration *>(type))
+ stage->texture_bindings[var.name] = i->value;
+
+ i = var.layout->qualifiers.erase(i);
+ }
else
++i;
}
{
if(i->name=="location" && !supports_interface_block_location())
i = iface.layout->qualifiers.erase(i);
+ else if(i->name=="binding" && !supports_binding())
+ {
+ stage->uniform_block_bindings[iface.block_name] = i->value;
+ i = iface.layout->qualifiers.erase(i);
+ }
else
++i;
}
bool supports_centroid_sampling() const;
bool supports_sample_sampling() const;
bool supports_uniform_location() const;
+ bool supports_binding() const;
virtual void visit(VariableDeclaration &);
bool supports_interface_blocks(const std::string &) const;
bool supports_interface_block_location() const;
std::map<std::string, InterfaceBlock *> interface_blocks;
std::map<std::string, FunctionDeclaration *> functions;
std::map<std::string, unsigned> locations;
+ std::map<std::string, unsigned> texture_bindings;
+ std::map<std::string, unsigned> uniform_block_bindings;
Features required_features;
std::vector<Diagnostic> diagnostics;