return *builtins_module;
}
-Stage *get_builtins(StageType type)
+Stage *get_builtins(Stage::Type type)
{
Module &module = get_builtins_module();
for(list<Stage>::iterator i=module.stages.begin(); i!=module.stages.end(); ++i)
namespace GL {
namespace SL {
-Stage *get_builtins(StageType);
+Stage *get_builtins(Stage::Type);
} // namespace SL
} // namespace GL
Precision *prec = new Precision;
if(!type.compare(0, 7, "sampler"))
prec->precision = "lowp";
- else if(stage->type==FRAGMENT)
+ else if(stage->type==Stage::FRAGMENT)
prec->precision = "mediump";
else
prec->precision = "highp";
if(i!=var.layout->qualifiers.end())
{
unsigned location = lexical_cast<unsigned>(i->value);
- if(stage->type==VERTEX && var.interface=="in")
+ if(stage->type==Stage::VERTEX && var.interface=="in")
{
stage->locations[var.name] = location;
var.layout->qualifiers.erase(i);
}
- else if(stage->type==FRAGMENT && var.interface=="out")
+ else if(stage->type==Stage::FRAGMENT && var.interface=="out")
{
if(location!=0)
static Require _req(EXT_gpu_shader4);
if((var.interface=="in" || var.interface=="out") && !supports_unified_interface_syntax())
{
- if(stage->type==FRAGMENT && var.interface=="out")
+ if(stage->type==Stage::FRAGMENT && var.interface=="out")
{
frag_out = &var;
remove_node = true;
{
for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
{
- if(i->type==VERTEX)
+ if(i->type==Stage::VERTEX)
{
program.attach_shader_owned(new VertexShader(apply<Formatter>(*i)));
for(map<string, unsigned>::iterator j=i->locations.begin(); j!=i->locations.end(); ++j)
program.bind_attribute(j->second, j->first);
}
- else if(i->type==GEOMETRY)
+ else if(i->type==Stage::GEOMETRY)
program.attach_shader_owned(new GeometryShader(apply<Formatter>(*i)));
- else if(i->type==FRAGMENT)
+ else if(i->type==Stage::FRAGMENT)
{
program.attach_shader_owned(new FragmentShader(apply<Formatter>(*i)));
if(EXT_gpu_shader4)
void Compiler::append_stage(Stage &stage)
{
Stage *target = 0;
- if(stage.type==SHARED)
+ if(stage.type==Stage::SHARED)
target = &module->shared;
else
{
scope_level(0)
{ }
-string InterfaceGenerator::get_out_prefix(StageType type)
+string InterfaceGenerator::get_out_prefix(Stage::Type type)
{
- if(type==VERTEX)
+ if(type==Stage::VERTEX)
return "_vs_out_";
- else if(type==GEOMETRY)
+ else if(type==Stage::GEOMETRY)
return "_gs_out_";
else
return string();
iface_var->type = var.type;
iface_var->type_declaration = var.type_declaration;
iface_var->name = name;
- if(stage->type==GEOMETRY)
+ if(stage->type==Stage::GEOMETRY)
iface_var->array = ((var.array && var.interface!="in") || iface=="in");
else
iface_var->array = var.array;
}
}
- if(stage->type==GEOMETRY)
+ if(stage->type==Stage::GEOMETRY)
{
VariableReference *ref = new VariableReference;
ref->name = "gl_in";
public:
InterfaceGenerator();
- static std::string get_out_prefix(StageType);
+ static std::string get_out_prefix(Stage::Type);
virtual void apply(Stage &);
using StageVisitor::visit;
virtual void visit(Block &);
BlockVariableMap &global_variables = variables.back();
for(BlockVariableMap::iterator i=global_variables.begin(); i!=global_variables.end(); ++i)
{
- if(i->first->interface=="out" && (s.type==FRAGMENT || i->first->linked_declaration || !i->first->name.compare(0, 3, "gl_")))
+ if(i->first->interface=="out" && (s.type==Stage::FRAGMENT || i->first->linked_declaration || !i->first->name.compare(0, 3, "gl_")))
continue;
if(!i->second.referenced)
{
string interface = var.interface;
if(stage->required_version<Version(1, 30))
{
- if(stage->type==VERTEX && var.interface=="in")
+ if(stage->type==Stage::VERTEX && var.interface=="in")
interface = "attribute";
- else if((stage->type==VERTEX && var.interface=="out") || (stage->type==FRAGMENT && var.interface=="in"))
+ else if((stage->type==Stage::VERTEX && var.interface=="out") || (stage->type==Stage::FRAGMENT && var.interface=="in"))
interface = "varying";
}
append(format("%s ", interface));
cur_stage->required_version = ver;
}
-void Parser::stage_change(StageType stage)
+void Parser::stage_change(Stage::Type stage)
{
if(!allow_stage_change)
throw invalid_shader_source(tokenizer.get_location(), "Changing stage not allowed here");
module->stages.push_back(stage);
- if(cur_stage->type!=SHARED)
+ if(cur_stage->type!=Stage::SHARED)
module->stages.back().previous = cur_stage;
cur_stage = &module->stages.back();
}
RefPtr<Import> Parser::parse_import()
{
- if(cur_stage->type!=SHARED)
+ if(cur_stage->type!=Stage::SHARED)
throw invalid_shader_source(tokenizer.get_location(), "Imports are only allowed in the shared section");
tokenizer.expect("import");
RefPtr<Passthrough> pass = new Passthrough;
pass->source = source_index;
pass->line = tokenizer.get_location().line;
- if(cur_stage->type==GEOMETRY)
+ if(cur_stage->type==Stage::GEOMETRY)
{
tokenizer.expect("[");
pass->subscript = parse_expression();
private:
void parse_source(const std::string &);
void set_required_version(const Version &);
- void stage_change(StageType);
+ void stage_change(Stage::Type);
std::string expect_type();
std::string expect_identifier();
tokenizer.expect("stage");
tokenizer.expect("(");
string token = tokenizer.parse_token();
- StageType stage = SHARED;
+ Stage::Type stage = Stage::SHARED;
if(token=="vertex")
- stage = VERTEX;
+ stage = Stage::VERTEX;
else if(token=="geometry")
- stage = GEOMETRY;
+ stage = Stage::GEOMETRY;
else if(token=="fragment")
- stage = FRAGMENT;
+ stage = Stage::FRAGMENT;
else
throw parse_error(tokenizer.get_location(), token, "stage identifier");
tokenizer.expect(")");
{
public:
sigc::signal<void, const Version &> signal_version;
- sigc::signal<void, StageType> signal_stage_change;
+ sigc::signal<void, Stage::Type> signal_stage_change;
private:
Tokenizer &tokenizer;
}
-Stage::Stage(StageType t):
+Stage::Stage(Stage::Type t):
type(t),
previous(0)
{ }
Module::Module():
- shared(SHARED)
+ shared(Stage::SHARED)
{ }
} // namespace SL
virtual void visit(NodeVisitor &);
};
-enum StageType
-{
- SHARED,
- VERTEX,
- GEOMETRY,
- FRAGMENT
-};
-
struct Stage
{
- StageType type;
+ enum Type
+ {
+ SHARED,
+ VERTEX,
+ GEOMETRY,
+ FRAGMENT
+ };
+
+ Type type;
Stage *previous;
Block content;
std::map<std::string, VariableDeclaration *> in_variables;
Version required_version;
std::vector<const Extension *> required_extensions;
- Stage(StageType);
+ Stage(Type);
};
struct Module