diff options
author | Dave Parks <davep@lindenlab.com> | 2011-09-15 00:54:25 -0500 |
---|---|---|
committer | Dave Parks <davep@lindenlab.com> | 2011-09-15 00:54:25 -0500 |
commit | 530981a2149a74e1dc003cea1bbc9dc392fcae60 (patch) | |
tree | f629a2dbc004d23e0f9f056366290e397ec51caf /indra/llrender/llrender.cpp | |
parent | 7c95af74f195c9ec4ebc0fc0264d98cd4a85be49 (diff) |
SH-2243 work in progress -- no more deprecated built-in matrix state when using shaders.
Diffstat (limited to 'indra/llrender/llrender.cpp')
-rw-r--r-- | indra/llrender/llrender.cpp | 106 |
1 files changed, 93 insertions, 13 deletions
diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 27d25c0d3a..359e6fd560 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -1018,6 +1018,8 @@ void LLRender::refreshState(void) void LLRender::syncMatrices() { + stop_glerror(); + GLenum mode[] = { GL_MODELVIEW, @@ -1028,27 +1030,105 @@ void LLRender::syncMatrices() GL_TEXTURE, }; - for (U32 i = 0; i < 2; ++i) + std::string name[] = + { + "modelview_matrix", + "projection_matrix", + "texture_matrix0", + "texture_matrix1", + "texture_matrix2", + "texture_matrix3", + }; + + LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr; + + if (shader) { - if (mMatHash[i] != mCurMatHash[i]) + + llassert(shader); + + bool do_normal = false; + bool do_mvp = false; + + for (U32 i = 0; i < NUM_MATRIX_MODES; ++i) { - glMatrixMode(mode[i]); - glLoadMatrixf(mMatrix[i][mMatIdx[i]].m); - mCurMatHash[i] = mMatHash[i]; + if (mMatHash[i] != shader->mMatHash[i]) + { + shader->uniformMatrix4fv(name[i], 1, GL_FALSE, mMatrix[i][mMatIdx[i]].m); + shader->mMatHash[i] = mMatHash[i]; + + if (i == MM_MODELVIEW) + { + do_normal = true; + do_mvp = true; + } + else if (i == MM_PROJECTION) + { + do_mvp = true; + } + } } - } - for (U32 i = 2; i < NUM_MATRIX_MODES; ++i) + if (do_normal) + { + S32 loc = shader->getUniformLocation("normal_matrix"); + if (loc > -1) + { + U32 i = MM_MODELVIEW; + + glh::matrix4f norm = mMatrix[i][mMatIdx[i]].inverse().transpose(); + + F32 norm_mat[] = + { + norm.m[0], norm.m[1], norm.m[2], + norm.m[4], norm.m[5], norm.m[6], + norm.m[8], norm.m[9], norm.m[10] + }; + + shader->uniformMatrix3fv("normal_matrix", 1, GL_FALSE, norm_mat); + } + } + + if (do_mvp) + { + S32 loc = shader->getUniformLocation("modelview_projection_matrix"); + if (loc > -1) + { + U32 mv = MM_MODELVIEW; + U32 proj = MM_PROJECTION; + + glh::matrix4f mvp = mMatrix[mv][mMatIdx[mv]]; + mvp.mult_left(mMatrix[proj][mMatIdx[proj]]); + + shader->uniformMatrix4fv("modelview_projection_matrix", 1, GL_FALSE, mvp.m); + } + } + } + else { - if (mMatHash[i] != mCurMatHash[i]) + for (U32 i = 0; i < 2; ++i) { - gGL.getTexUnit(i-2)->activate(); - glMatrixMode(mode[i]); - glLoadMatrixf(mMatrix[i][mMatIdx[i]].m); - mCurMatHash[i] = mMatHash[i]; + if (mMatHash[i] != mCurMatHash[i]) + { + glMatrixMode(mode[i]); + glLoadMatrixf(mMatrix[i][mMatIdx[i]].m); + mCurMatHash[i] = mMatHash[i]; + } + } + + for (U32 i = 2; i < NUM_MATRIX_MODES; ++i) + { + if (mMatHash[i] != mCurMatHash[i]) + { + gGL.getTexUnit(i-2)->activate(); + glMatrixMode(mode[i]); + glLoadMatrixf(mMatrix[i][mMatIdx[i]].m); + mCurMatHash[i] = mMatHash[i]; + } } } - + + stop_glerror(); } void LLRender::translatef(const GLfloat& x, const GLfloat& y, const GLfloat& z) |