using namespace std;
+namespace {
+
+const char builtins_src[] =
+ "////// vertex\n"
+ "out gl_PerVertex {\n"
+ " vec4 gl_Position;\n"
+ " float gl_ClipDistance[];\n"
+ "};"
+ "////// geometry\n"
+ "in gl_PerVertex {\n"
+ " vec4 gl_Position;\n"
+ " float gl_ClipDistance[];\n"
+ "} gl_in[];\n"
+ "out gl_PerVertex {\n"
+ " vec4 gl_Position;\n"
+ " float gl_ClipDistance[];\n"
+ "};\n";
+
+}
+
namespace Msp {
namespace GL {
program.bind_attribute(TEXCOORD4, "texcoord");
}
+Module *ProgramCompiler::create_builtins_module()
+{
+ ProgramParser parser;
+ Module *module = new Module(parser.parse(builtins_src));
+ for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
+ {
+ VariableResolver resolver;
+ i->content.visit(resolver);
+ for(map<string, VariableDeclaration *>::iterator j=i->content.variables.begin(); j!=i->content.variables.end(); ++j)
+ j->second->linked_declaration = j->second;
+ }
+ return module;
+}
+
+Module &ProgramCompiler::get_builtins_module()
+{
+ static RefPtr<Module> builtins_module = create_builtins_module();
+ return *builtins_module;
+}
+
+Stage *ProgramCompiler::get_builtins(StageType type)
+{
+ Module &module = get_builtins_module();
+ for(list<Stage>::iterator i=module.stages.begin(); i!=module.stages.end(); ++i)
+ if(i->type==type)
+ return &*i;
+ return 0;
+}
+
void ProgramCompiler::process()
{
for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
formatted += "const ";
if(!var.sampling.empty())
formatted += format("%s ", var.sampling);
- if(!var.interface.empty())
+ if(!var.interface.empty() && var.interface!=block_interface)
formatted += format("%s ", var.interface);
formatted += format("%s %s", var.type, var.name);
if(var.array)
void ProgramCompiler::Formatter::visit(InterfaceBlock &iface)
{
+ SetForScope<string> set(block_interface, iface.interface);
formatted += format("%s %s\n", iface.interface, iface.name);
iface.members.visit(*this);
formatted += ';';
anonymous(false)
{ }
+void ProgramCompiler::VariableResolver::apply(Stage &s)
+{
+ SetForScope<Stage *> set(stage, &s);
+ Stage *builtins = get_builtins(stage->type);
+ if(builtins)
+ blocks.push_back(&builtins->content);
+ stage->content.visit(*this);
+ if(builtins)
+ blocks.pop_back();
+}
+
void ProgramCompiler::VariableResolver::visit(Block &block)
{
blocks.push_back(&block);
var.type_declaration = j->second;
}
+ if(!block_interface.empty() && var.interface.empty())
+ var.interface = block_interface;
+
TraversingVisitor::visit(var);
blocks.back()->variables[var.name] = &var;
if(anonymous && blocks.size()>1)
void ProgramCompiler::VariableResolver::visit(InterfaceBlock &iface)
{
SetFlag set(anonymous);
+ SetForScope<string> set2(block_interface, iface.interface);
TraversingVisitor::visit(iface);
}
unsigned indent;
bool parameter_list;
bool else_if;
+ std::string block_interface;
Formatter();
std::vector<ProgramSyntax::Block *> blocks;
ProgramSyntax::StructDeclaration *type;
bool anonymous;
+ std::string block_interface;
VariableResolver();
+ virtual void apply(ProgramSyntax::Stage &);
virtual void visit(ProgramSyntax::Block &);
virtual void visit(ProgramSyntax::VariableReference &);
virtual void visit(ProgramSyntax::MemberAccess &);
void add_shaders(Program &);
private:
+ static ProgramSyntax::Module *create_builtins_module();
+ static ProgramSyntax::Module &get_builtins_module();
+ static ProgramSyntax::Stage *get_builtins(ProgramSyntax::StageType);
void process();
void generate(ProgramSyntax::Stage &);
bool optimize(ProgramSyntax::Stage &);