From 335498df6dd7d5d95196c86603226d0757b1924c Mon Sep 17 00:00:00 2001 From: Chris Serino Date: Wed, 3 Feb 2021 17:31:55 -0600 Subject: [PATCH] [GLES2] Fix binding 3D Transforms to mat4 uniforms --- drivers/gles2/shader_gles2.cpp | 64 +++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/drivers/gles2/shader_gles2.cpp b/drivers/gles2/shader_gles2.cpp index 198c15e570a..bbe5109f05c 100644 --- a/drivers/gles2/shader_gles2.cpp +++ b/drivers/gles2/shader_gles2.cpp @@ -827,27 +827,49 @@ void ShaderGLES2::use_material(void *p_material) { case ShaderLanguage::TYPE_MAT4: { - Transform2D tr = V->get(); - GLfloat matrix[16] = { /* build a 16x16 matrix */ - tr.elements[0][0], - tr.elements[0][1], - 0, - 0, - tr.elements[1][0], - tr.elements[1][1], - 0, - 0, - 0, - 0, - 1, - 0, - tr.elements[2][0], - tr.elements[2][1], - 0, - 1 - }; - - glUniformMatrix4fv(location, 1, GL_FALSE, matrix); + if (V->get().get_type() == Variant::TRANSFORM) { + Transform tr = V->get(); + GLfloat matrix[16] = { /* build a 16x16 matrix */ + tr.basis.elements[0][0], + tr.basis.elements[1][0], + tr.basis.elements[2][0], + 0, + tr.basis.elements[0][1], + tr.basis.elements[1][1], + tr.basis.elements[2][1], + 0, + tr.basis.elements[0][2], + tr.basis.elements[1][2], + tr.basis.elements[2][2], + 0, + tr.origin.x, + tr.origin.y, + tr.origin.z, + 1 + }; + glUniformMatrix4fv(location, 1, GL_FALSE, matrix); + } else { + Transform2D tr = V->get(); + GLfloat matrix[16] = { /* build a 16x16 matrix */ + tr.elements[0][0], + tr.elements[0][1], + 0, + 0, + tr.elements[1][0], + tr.elements[1][1], + 0, + 0, + 0, + 0, + 1, + 0, + tr.elements[2][0], + tr.elements[2][1], + 0, + 1 + }; + glUniformMatrix4fv(location, 1, GL_FALSE, matrix); + } } break;