Skip to content

Commit

Permalink
Fix GLSL code generation for arithmetic with matrices that are not fl…
Browse files Browse the repository at this point in the history
…oating point
  • Loading branch information
crosire committed Dec 5, 2019
1 parent e5adee2 commit 82ea07b
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion source/effect_codegen_glsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ class codegen_glsl final : public codegen
{
// TODO: Implement matrix to vector swizzles
assert(false);
expr_code += "_NOT_IMPLEMENTED_"; // Make sure compilation fails
}
}
else
Expand All @@ -761,6 +762,14 @@ class codegen_glsl final : public codegen
}
}

// GLSL matrices are always floating point, so need to cast result to the target type
if (!exp.chain.empty() && exp.chain[0].from.is_matrix() && !exp.chain[0].from.is_floating_point())
{
type.clear();
write_type<false, false>(type, exp.type);
expr_code = type + '(' + expr_code + ')';
}

if (force_new_id)
{
// Need to store value in a new variable to comply with request for a new ID
Expand Down Expand Up @@ -820,6 +829,7 @@ class codegen_glsl final : public codegen
{
// TODO: Implement matrix to vector swizzles
assert(false);
code += "_NOT_IMPLEMENTED_"; // Make sure compilation fails
}
}
else
Expand All @@ -832,7 +842,14 @@ class codegen_glsl final : public codegen
}
}

code += " = " + id_to_name(value) + ";\n";
code += " = ";

// GLSL matrices are always floating point, so need to cast type
if (!exp.chain.empty() && exp.chain[0].from.is_matrix() && !exp.chain[0].from.is_floating_point())
// Only supporting scalar assignments to matrices currently, so can assume to always cast to float
code += "float(" + id_to_name(value) + ");\n";
else
code += id_to_name(value) + ";\n";
}

id emit_constant(const type &type, const constant &data) override
Expand Down

0 comments on commit 82ea07b

Please sign in to comment.