}
}
+template<typename T>
+void ConstantFolder::convert_to_result(const Variant &value)
+{
+ if(value.check_type<bool>())
+ set_result(static_cast<T>(value.value<bool>()));
+ else if(value.check_type<int>())
+ set_result(static_cast<T>(value.value<int>()));
+ else if(value.check_type<float>())
+ set_result(static_cast<T>(value.value<float>()));
+}
+
void ConstantFolder::set_result(const Variant &value, bool literal)
{
r_constant_value = value;
void ConstantFolder::visit(FunctionCall &call)
{
+ if(call.constructor && call.type && call.arguments.size()==1)
+ {
+ const BasicTypeDeclaration *basic = dynamic_cast<const BasicTypeDeclaration *>(call.type);
+ if(basic)
+ {
+ call.arguments[0]->visit(*this);
+ bool can_fold = r_constant;
+ r_constant = false;
+ if(!can_fold)
+ return;
+
+ if(basic->kind==BasicTypeDeclaration::BOOL)
+ convert_to_result<bool>(r_constant_value);
+ else if(basic->kind==BasicTypeDeclaration::INT && basic->size==32)
+ convert_to_result<int>(r_constant_value);
+ else if(basic->kind==BasicTypeDeclaration::FLOAT && basic->size==32)
+ convert_to_result<float>(r_constant_value);
+
+ return;
+ }
+ }
+
TraversingVisitor::visit(call);
r_constant = false;
}
static T evaluate_arithmetic(char, T, T);
template<typename T>
static T evaluate_int_special_op(char, T, T);
+ template<typename T>
+ void convert_to_result(const Variant &);
void set_result(const Variant &, bool = false);
virtual void visit(RefPtr<Expression> &);
mat2x4 m2;
vec4 v1 = vec4(1.0);
vec2 v3;
- v3 = v1*m2+(m2*m1*float(5)*v1).xy+vec2(iv);
+ v3 = v1*m2+(m2*m1*5.0*v1).xy+vec2(iv);
if(b)
++v3;
}
{
mat3 normal_matrix = mat3(model[0].xyz, model[1].xyz, model[2].xyz);
tbn_light_dir = mat3(normal_matrix*tangent, normal_matrix*binormal, normal_matrix*normal)*light_dir;
- gl_Position = view_projection*model*vec4(position, float(1));
+ gl_Position = view_projection*model*vec4(position, 1.0);
_vs_out_texcoord = texcoord;
}
*/
layout(location=0) in vec3 tbn_light_dir;
void main()
{
- frag_color = vec4(vec3(dot(vec3(texture(normalmap, _vs_out_texcoord).xyz)*2.0-1.0, normalize(tbn_light_dir))), float(1));
+ frag_color = vec4(vec3(dot(vec3(texture(normalmap, _vs_out_texcoord).xyz)*2.0-1.0, normalize(tbn_light_dir))), 1.0);
}
*/
layout(location=0) in vec4 position;
void main()
{
- gl_Position = vec4(position.xy*float(2), 0.0, 1.0);
+ gl_Position = vec4(position.xy*2.0, 0.0, 1.0);
}
*/