From: Mikko Rasa Date: Sat, 16 Dec 2023 22:33:39 +0000 (+0200) Subject: Convert matrix columns to the appropriate element type X-Git-Url: https://git.tdb.fi/?a=commitdiff_plain;h=ebb0858f00fd90dd571258945a098418ea4cef78;p=libs%2Fgl.git Convert matrix columns to the appropriate element type --- diff --git a/source/glsl/resolve.cpp b/source/glsl/resolve.cpp index 7c6d2bad..d89ac642 100644 --- a/source/glsl/resolve.cpp +++ b/source/glsl/resolve.cpp @@ -1035,6 +1035,8 @@ void ExpressionResolver::visit_constructor(FunctionCall &call) size. */ if(args.size()!=column_count) return; + + convert_args = true; } else if(arg_component_total==column_count*row_count && !has_matrices) { @@ -1057,8 +1059,11 @@ void ExpressionResolver::visit_constructor(FunctionCall &call) { const ArgumentInfo &info = args[j]; if(!column_component_count && info.component_count==row_count) + { // A vector filling the entire column can be used as is. columns.push_back(call.arguments[j]); + convert_args = true; + } else { column_args.push_back(call.arguments[j]); diff --git a/tests/glsl/matrix_constructors.glsl b/tests/glsl/matrix_constructors.glsl new file mode 100644 index 00000000..fc523094 --- /dev/null +++ b/tests/glsl/matrix_constructors.glsl @@ -0,0 +1,20 @@ +uniform ivec3 columns[3]; + +#pragma MSP stage(vertex) +layout(location=0) in vec3 vertex; +void main() +{ + mat3 m1 = mat3(columns[0], columns[1], columns[2]); + mat4 m2 = mat4(columns[0], 0.0, ivec4(columns[1], 0), columns[2], 0, 0, 0.0, false, true); + gl_Position = m2*vec4(m1*vertex, 0); +} + +/* Expected output: vertex +layout(location=0) uniform ivec3 columns[3]; +layout(location=0) in vec3 vertex; +void main() +{ + gl_Position = mat4(vec4(vec3(columns[0]), 0.0), vec4(ivec4(columns[1], 0)), vec4(vec3(columns[2]), 0.0), vec4(0.0, 0.0, 0.0, 1.0))*vec4(mat3(vec3(columns[0]), vec3(columns[1]), vec3(columns[2]))*vertex, 0.0); + gl_Position.z = gl_Position.z*2.0-gl_Position.w; +} +*/