OpenGL: add NormalMatrix & inverse to new API
Part of T49450
This commit is contained in:
parent
2cb45c9938
commit
1abdb0c2ee
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue