Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Erwin <significant.bit@gmail.com>2016-10-24 06:37:53 +0300
committerMike Erwin <significant.bit@gmail.com>2016-10-24 06:37:53 +0300
commit1abdb0c2eea513de3803b9ef8a0211d40dec30d1 (patch)
tree584a8de07c6ca1bc59f1bf1a053922ce10b9abbc /source/blender/gpu
parent2cb45c993886c16b5b8e0e3187e1db5b92032d4f (diff)
OpenGL: add NormalMatrix & inverse to new API
Part of T49450
Diffstat (limited to 'source/blender/gpu')
-rw-r--r--source/blender/gpu/GPU_matrix.h3
-rw-r--r--source/blender/gpu/intern/gpu_matrix.c37
2 files changed, 40 insertions, 0 deletions
diff --git a/source/blender/gpu/GPU_matrix.h b/source/blender/gpu/GPU_matrix.h
index f3118495239..4390b62379e 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 f55f9f01ae6..19ff856b688 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;
}