stage.content.visit(*this);
}
+void DepthRangeConverter::visit(VariableReference &var)
+{
+ const StructDeclaration *strct = dynamic_cast<const StructDeclaration *>(var.type);
+ r_gl_pervertex = (strct && strct->block_name=="gl_PerVertex");
+}
+
+void DepthRangeConverter::visit(MemberAccess &memacc)
+{
+ r_gl_pervertex = false;
+ memacc.left->visit(*this);
+ r_gl_position = (r_gl_pervertex && memacc.member=="gl_Position");
+}
+
+void DepthRangeConverter::visit(Swizzle &swiz)
+{
+ r_gl_position = false;
+ swiz.left->visit(*this);
+ if(assignment_target && r_gl_position && swiz.count==1 && swiz.components[0]==2)
+ r_position_z_assigned = true;
+}
+
+void DepthRangeConverter::visit(Assignment &assign)
+{
+ {
+ SetFlag set_target(assignment_target);
+ assign.left->visit(*this);
+ }
+ assign.right->visit(*this);
+}
+
void DepthRangeConverter::visit(FunctionDeclaration &func)
{
- if(func.definition==&func && func.name=="main")
+ r_position_z_assigned = false;
+ TraversingVisitor::visit(func);
+
+ if(func.definition==&func && func.name=="main" && !r_position_z_assigned)
{
VariableReference *position = new VariableReference;
position->name = "gl_Position";
*/
class DepthRangeConverter: private TraversingVisitor
{
+private:
+ bool assignment_target = false;
+ bool r_gl_pervertex = false;
+ bool r_gl_position = false;
+ bool r_position_z_assigned = false;
+
public:
void apply(Stage &, const Features &);
private:
+ virtual void visit(VariableReference &);
+ virtual void visit(MemberAccess &);
+ virtual void visit(Swizzle &);
+ virtual void visit(Assignment &);
virtual void visit(FunctionDeclaration &);
};