convert_to(var.init_expression, *var_basic);
}
+void ExpressionResolver::visit(FunctionDeclaration &func)
+{
+ SetForScope<const FunctionDeclaration *> set_func(current_function, &func);
+ TraversingVisitor::visit(func);
+}
+
+void ExpressionResolver::visit(Return &ret)
+{
+ TraversingVisitor::visit(ret);
+ if(!current_function || !ret.expression)
+ return;
+
+ BasicTypeDeclaration *ret_basic = dynamic_cast<BasicTypeDeclaration *>(current_function->return_type_declaration);
+ BasicTypeDeclaration *expr_basic = dynamic_cast<BasicTypeDeclaration *>(ret.expression->type);
+ if(!ret_basic || !expr_basic)
+ return;
+
+ Compatibility compat = get_compatibility(*ret_basic, *expr_basic);
+ if(compat==RIGHT_CONVERTIBLE)
+ convert_to(ret.expression, *ret_basic);
+}
+
bool FunctionResolver::apply(Stage &s)
{
};
Stage *stage = 0;
+ const FunctionDeclaration *current_function = 0;
std::vector<BasicTypeDeclaration *> basic_types;
NodeList<Statement>::iterator insert_point;
bool r_any_resolved = false;
virtual void visit(FunctionCall &);
virtual void visit(BasicTypeDeclaration &);
virtual void visit(VariableDeclaration &);
+ virtual void visit(FunctionDeclaration &);
+ virtual void visit(Return &);
};
/** Resolves function declarations and calls. */
--- /dev/null
+uniform Shadow
+{
+ mat4 shadow_matrix;
+};
+uniform Camera
+{
+ mat4 viewproj_matrix;
+};
+uniform Surface
+{
+ vec4 color;
+};
+uniform mat4 model_matrix;
+uniform sampler2DShadow shadow_map;
+
+#pragma MSP stage(vertex)
+layout(location=0) in vec4 position;
+void main()
+{
+ out vec4 world_position = model_matrix*position;
+ gl_Position = viewproj_matrix*world_position;
+}
+
+#pragma MSP stage(fragment)
+layout(location=0) out vec4 frag_out;
+float get_shadow()
+{
+ vec3 shadow_coord = (shadow_matrix*world_position).xyz;
+ if(shadow_coord.x>=0 && shadow_coord.x<=1 && shadow_coord.y>=0 && shadow_coord.y<=1)
+ return texture(shadow_map, shadow_coord);
+ else
+ return 1;
+}
+void main()
+{
+ frag_out = vec4(color.rgb*get_shadow(), color.a);
+}
+
+/* Expected output: vertex
+layout(binding=72) uniform Camera
+{
+ mat4 viewproj_matrix;
+};
+layout(location=0) uniform mat4 model_matrix;
+layout(location=0) in vec4 position;
+layout(location=0) out vec4 world_position;
+void main()
+{
+ world_position = model_matrix*position;
+ gl_Position = viewproj_matrix*world_position;
+}
+*/
+
+/* Expected output: fragment
+layout(binding=71) uniform Shadow
+{
+ mat4 shadow_matrix;
+};
+layout(binding=77) uniform Surface
+{
+ vec4 color;
+};
+layout(location=4, binding=73) uniform sampler2DShadow shadow_map;
+layout(location=0) out vec4 frag_out;
+layout(location=0) in vec4 world_position;
+float get_shadow()
+{
+ vec3 shadow_coord = (shadow_matrix*world_position).xyz;
+ if(shadow_coord.x>=0.0&&shadow_coord.x<=1.0&&shadow_coord.y>=0.0&&shadow_coord.y<=1.0)
+ return texture(shadow_map, shadow_coord);
+ else
+ return 1.0;
+}
+void main()
+{
+ frag_out = vec4(color.rgb*get_shadow(), color.a);
+}
+*/