X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Ffinalize.cpp;h=fb136e33c7dbc79fd03706ba6ef3450d4906fe5c;hb=ae423e6ef278388f92802fbae34b1c7ec339292f;hp=5307cff93ed1461d1da9c5eab9de770fd6fcd8b0;hpb=03b2ea5c9c611cfa5f02afb49ed7e05743e691b4;p=libs%2Fgl.git diff --git a/source/glsl/finalize.cpp b/source/glsl/finalize.cpp index 5307cff9..fb136e33 100644 --- a/source/glsl/finalize.cpp +++ b/source/glsl/finalize.cpp @@ -239,6 +239,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; @@ -588,7 +638,7 @@ bool QualifierConverter::supports_sample_sampling() const bool QualifierConverter::supports_uniform_location() const { if(features.target_api==VULKAN) - return true; + return false; else if(features.target_api==OPENGL_ES) return check_version(Version(3, 10)); else if(check_version(Version(4, 30)))