]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/finalize.cpp
Remove set layout qualifiers on OpenGL
[libs/gl.git] / source / glsl / finalize.cpp
index 29eef60fb3342d12c31374441ed7a076d343ea2c..87e185024f3175c669a639dd14032b04e0cee79e 100644 (file)
@@ -168,12 +168,11 @@ void LocationAllocator::bind_uniform(RefPtr<Layout> &layout, const string &name,
 
 bool LocationAllocator::visit_uniform(const string &name, RefPtr<Layout> &layout)
 {
-       int desc_set = 0;
+       int desc_set = get_layout_value(layout.get(), "set");
        int bind_point = get_layout_value(layout.get(), "binding");
 
        if(features.target_api==VULKAN)
        {
-               desc_set = get_layout_value(layout.get(), "set");
                if(desc_set<0 && bind_point>=0)
                {
                        desc_set = 0;
@@ -183,6 +182,11 @@ bool LocationAllocator::visit_uniform(const string &name, RefPtr<Layout> &layout
                if(desc_set>=0)
                        uniforms[name].desc_set = desc_set;
        }
+       else if(desc_set>=0 && bind_point<0)
+       {
+               auto i = find_member(layout->qualifiers, string("set"), &Layout::Qualifier::name);
+               layout->qualifiers.erase(i);
+       }
 
        if(bind_point>=0)
        {
@@ -239,6 +243,56 @@ void LocationAllocator::visit(VariableDeclaration &var)
 }
 
 
+void DepthRangeConverter::apply(Stage &stage, const Features &features)
+{
+       if(stage.type!=Stage::VERTEX || features.target_api==VULKAN)
+               return;
+
+       stage.content.visit(*this);
+}
+
+void DepthRangeConverter::visit(FunctionDeclaration &func)
+{
+       if(func.definition==&func && func.name=="main")
+       {
+               VariableReference *position = new VariableReference;
+               position->name = "gl_Position";
+
+               MemberAccess *z = new MemberAccess;
+               z->left = position;
+               z->member = "z";
+
+               Literal *scale = new Literal;
+               scale->token = "2.0";
+               scale->value = 2.0f;
+
+               BinaryExpression *multiply = new BinaryExpression;
+               multiply->oper = &Operator::get_operator("*", Operator::BINARY);
+               multiply->left = z;
+               multiply->right = scale;
+
+               MemberAccess *w = new MemberAccess;
+               w->left = position->clone();
+               w->member = "w";
+
+               BinaryExpression *subtract = new BinaryExpression;
+               subtract->oper = &Operator::get_operator("-", Operator::BINARY);
+               subtract->left = multiply;
+               subtract->right = w;
+
+               Assignment *assign = new Assignment;
+               assign->oper = &Operator::get_operator("=", Operator::BINARY);
+               assign->left = z->clone();
+               assign->right = subtract;
+
+               ExpressionStatement *statement = new ExpressionStatement;
+               statement->expression = assign;
+
+               func.body.body.push_back(statement);
+       }
+}
+
+
 void PrecisionConverter::apply(Stage &s)
 {
        stage = &s;