Commit: 1abdb0c2eea513de3803b9ef8a0211d40dec30d1
Author: Mike Erwin
Date:   Sun Oct 23 23:37:53 2016 -0400
Branches: blender2.8
https://developer.blender.org/rB1abdb0c2eea513de3803b9ef8a0211d40dec30d1

OpenGL: add NormalMatrix & inverse to new API

Part of T49450

===================================================================

M       source/blender/gpu/GPU_matrix.h
M       source/blender/gpu/intern/gpu_matrix.c

===================================================================

diff --git a/source/blender/gpu/GPU_matrix.h b/source/blender/gpu/GPU_matrix.h
index f311849..4390b62 100644
--- a/source/blender/gpu/GPU_matrix.h
+++ b/source/blender/gpu/GPU_matrix.h
@@ -126,6 +126,9 @@ const float *gpuGetModelViewMatrix3D(float m[4][4]);
 const float *gpuGetProjectionMatrix3D(float m[4][4]);
 const float *gpuGetModelViewProjectionMatrix3D(float m[4][4]);
 
+const float *gpuGetNormalMatrix(float m[3][3]);
+const float *gpuGetNormalMatrixInverse(float m[3][3]);
+
 
 #if SUPPORT_LEGACY_MATRIX
 /* copy top matrix from each legacy stack into new fresh stack */
diff --git a/source/blender/gpu/intern/gpu_matrix.c 
b/source/blender/gpu/intern/gpu_matrix.c
index f55f9f0..19ff856 100644
--- a/source/blender/gpu/intern/gpu_matrix.c
+++ b/source/blender/gpu/intern/gpu_matrix.c
@@ -615,6 +615,34 @@ const float *gpuGetModelViewProjectionMatrix3D(float 
m[4][4])
        return (const float*)m;
 }
 
+const float *gpuGetNormalMatrix(float m[3][3])
+{
+       if (m == NULL) {
+               static Mat3 temp3;
+               m = temp3;
+       }
+
+       copy_m3_m4(m, gpuGetModelViewMatrix3D(NULL));
+
+       invert_m3(m);
+       transpose_m3(m);
+
+       return (const float*)m;
+}
+
+const float *gpuGetNormalMatrixInverse(float m[3][3])
+{
+       if (m == NULL) {
+               static Mat3 temp3;
+               m = temp3;
+       }
+
+       gpuGetNormalMatrix(m);
+       invert_m3(m);
+
+       return (const float*)m;
+}
+
 void gpuBindMatrices(GLuint program)
 {
        /* TODO: split this into 2 functions
@@ -623,6 +651,7 @@ void gpuBindMatrices(GLuint program)
        GLint loc_MV = glGetUniformLocation(program, "ModelViewMatrix");
        GLint loc_P = glGetUniformLocation(program, "ProjectionMatrix");
        GLint loc_MVP = glGetUniformLocation(program, 
"ModelViewProjectionMatrix");
+       GLint loc_N = glGetUniformLocation(program, "NormalMatrix");
 
        /* 2) set uniform values to matrix stack values
         * program needs to be bound
@@ -655,6 +684,14 @@ void gpuBindMatrices(GLuint program)
                glUniformMatrix4fv(loc_MVP, 1, GL_FALSE, 
gpuGetModelViewProjectionMatrix3D(NULL));
        }
 
+       if (loc_N != -1) {
+               #if DEBUG_MATRIX_BIND
+               puts("setting 3D normal matrix");
+               #endif
+
+               glUniformMatrix3fv(loc_N, 1, GL_FALSE, 
gpuGetNormalMatrix(NULL));
+       }
+
        state.dirty = false;
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to