diff options
author | Mike Erwin <significant.bit@gmail.com> | 2017-03-27 04:12:39 +0300 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2017-03-27 04:23:54 +0300 |
commit | 2a7e4c3040f259973a5209d0520bdb5d55e52f2d (patch) | |
tree | 76a2263434fdc26829dde8b04d7c876dd96b21c4 /source/blender/gpu/intern/gpu_matrix.c | |
parent | cc53c180acea384e451af547b1e6aeff3107adde (diff) |
OpenGL: fix & enhance new matrix lib
- init projection matrices with identity
- fix copy/paste mistake in GetProjectionMatrix3D
- add extra matrices needed by material GLSL
Working toward T49450
Diffstat (limited to 'source/blender/gpu/intern/gpu_matrix.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_matrix.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/source/blender/gpu/intern/gpu_matrix.c b/source/blender/gpu/intern/gpu_matrix.c index 5f6c1ed279b..064f31ed834 100644 --- a/source/blender/gpu/intern/gpu_matrix.c +++ b/source/blender/gpu/intern/gpu_matrix.c @@ -81,7 +81,7 @@ void gpuMatrixBegin2D(void) state.mode = MATRIX_MODE_2D; state.top = 0; unit_m3(ModelView2D); - gpuOrtho2D(-1.0f, +1.0f, -1.0f, +1.0f); // or identity? + unit_m3(Projection2D); } void gpuMatrixBegin3D(void) @@ -89,7 +89,7 @@ void gpuMatrixBegin3D(void) state.mode = MATRIX_MODE_3D; state.top = 0; unit_m4(ModelView3D); - gpuOrtho(-1.0f, +1.0f, -1.0f, +1.0f, -1.0f, +1.0f); // or identity? + unit_m4(Projection3D); } #if SUPPORT_LEGACY_MATRIX @@ -485,7 +485,7 @@ static void mat4_ortho_set(float m[4][4], float left, float right, float bottom, state.dirty = true; } -static void mat4_frustum_set(float m[][4], float left, float right, float bottom, float top, float near, float far) +static void mat4_frustum_set(float m[4][4], float left, float right, float bottom, float top, float near, float far) { m[0][0] = 2.0f * near / (right - left); m[1][0] = 0.0f; @@ -782,11 +782,11 @@ const float *gpuGetProjectionMatrix3D(float m[4][4]) BLI_assert(state.mode == MATRIX_MODE_3D); if (m) { - copy_m4_m4(m, ModelView3D); + copy_m4_m4(m, Projection3D); return (const float*)m; } else { - return (const float*)ModelView3D; + return (const float*)Projection3D; } } @@ -890,6 +890,27 @@ void gpuBindMatrices(GLuint program) glUniformMatrix3fv(loc_N, 1, GL_FALSE, gpuGetNormalMatrix(NULL)); } + /* also needed by material.glsl + * - ProjectionMatrixInverse + * - ModelViewMatrixInverse + */ + GLint loc_MV_inv = glGetUniformLocation(program, "ModelViewInverseMatrix"); + GLint loc_P_inv = glGetUniformLocation(program, "ProjectionInverseMatrix"); + + if (loc_MV_inv != -1) { + Mat4 m; + gpuGetModelViewMatrix3D(m); + invert_m4(m); + glUniformMatrix4fv(loc_MV_inv, 1, GL_FALSE, (const float*) m); + } + + if (loc_P_inv != -1) { + Mat4 m; + gpuGetProjectionMatrix3D(m); + invert_m4(m); + glUniformMatrix4fv(loc_P_inv, 1, GL_FALSE, (const float*) m); + } + state.dirty = false; } |