summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indra/cmake/CMakeLists.txt1
-rw-r--r--indra/llprimitive/CMakeLists.txt3
-rw-r--r--indra/llprimitive/lldaeloader.cpp9
-rw-r--r--indra/llprimitive/llgltfloader.cpp1
-rw-r--r--indra/llprimitive/llmodelloader.cpp1
-rw-r--r--indra/llrender/llgl.cpp43
-rw-r--r--indra/llrender/llgl.h12
-rw-r--r--indra/llrender/llrender.cpp216
-rw-r--r--indra/llrender/llrender.h35
-rw-r--r--indra/llrender/llvertexbuffer.cpp7
-rw-r--r--indra/llrender/llvertexbuffer.h12
-rw-r--r--indra/llwindow/CMakeLists.txt3
-rw-r--r--indra/newview/gltfscenemanager.cpp6
-rw-r--r--indra/newview/llface.cpp6
-rw-r--r--indra/newview/llgltfmaterialpreviewmgr.cpp8
-rw-r--r--indra/newview/llhudrender.cpp29
-rw-r--r--indra/newview/llmaniptranslate.cpp4
-rw-r--r--indra/newview/llmodelpreview.cpp6
-rw-r--r--indra/newview/llpanelprimmediacontrols.cpp17
-rw-r--r--indra/newview/llreflectionmap.cpp11
-rw-r--r--indra/newview/llsettingsvo.cpp41
-rw-r--r--indra/newview/llterrainpaintmap.cpp6
-rw-r--r--indra/newview/llviewercamera.cpp267
-rw-r--r--indra/newview/llviewerdisplay.cpp57
-rw-r--r--indra/newview/llviewerwindow.cpp4
-rw-r--r--indra/newview/llvoavatar.cpp30
-rw-r--r--indra/newview/llvotree.cpp9
-rw-r--r--indra/newview/pipeline.cpp314
-rw-r--r--indra/newview/pipeline.h10
29 files changed, 493 insertions, 675 deletions
diff --git a/indra/cmake/CMakeLists.txt b/indra/cmake/CMakeLists.txt
index 73b614e0af..cc217b0563 100644
--- a/indra/cmake/CMakeLists.txt
+++ b/indra/cmake/CMakeLists.txt
@@ -26,6 +26,7 @@ set(cmake_SOURCE_FILES
FreeType.cmake
GLEXT.cmake
GLH.cmake
+ GLM.cmake
Havok.cmake
Hunspell.cmake
LLAddBuildTest.cmake
diff --git a/indra/llprimitive/CMakeLists.txt b/indra/llprimitive/CMakeLists.txt
index 19a43839af..3d8e02cb16 100644
--- a/indra/llprimitive/CMakeLists.txt
+++ b/indra/llprimitive/CMakeLists.txt
@@ -7,7 +7,6 @@ include(LLCommon)
include(LLCoreHttp)
include(LLPhysicsExtensions)
include(LLPrimitive)
-include(GLH)
include(GLM)
include(TinyGLTF)
@@ -70,7 +69,7 @@ target_link_libraries(llprimitive
llrender
llphysicsextensions_impl
ll::colladadom
- ll::glh_linear
+ ll::glm
)
#add unit tests
diff --git a/indra/llprimitive/lldaeloader.cpp b/indra/llprimitive/lldaeloader.cpp
index 4f47f16e33..f286bff353 100644
--- a/indra/llprimitive/lldaeloader.cpp
+++ b/indra/llprimitive/lldaeloader.cpp
@@ -51,7 +51,8 @@
#include "llsdserialize.h"
#include "lljoint.h"
-#include "glh/glh_linear.h"
+#include "glm/mat4x4.hpp"
+#include "glm/gtc/type_ptr.hpp"
#include "llmatrix4a.h"
#include <boost/regex.hpp>
@@ -1218,9 +1219,9 @@ void LLDAELoader::processDomModel(LLModel* model, DAE* dae, daeElement* root, do
mesh_scale *= normalized_transformation;
normalized_transformation = mesh_scale;
- glh::matrix4f inv_mat((F32*) normalized_transformation.mMatrix);
- inv_mat = inv_mat.inverse();
- LLMatrix4 inverse_normalized_transformation(inv_mat.m);
+ glm::mat4 inv_mat = glm::make_mat4((F32*)normalized_transformation.mMatrix);
+ inv_mat = glm::inverse(inv_mat);
+ LLMatrix4 inverse_normalized_transformation(glm::value_ptr(inv_mat));
domSkin::domBind_shape_matrix* bind_mat = skin->getBind_shape_matrix();
diff --git a/indra/llprimitive/llgltfloader.cpp b/indra/llprimitive/llgltfloader.cpp
index 776f81cc01..480012699a 100644
--- a/indra/llprimitive/llgltfloader.cpp
+++ b/indra/llprimitive/llgltfloader.cpp
@@ -51,7 +51,6 @@
#include "llsdserialize.h"
#include "lljoint.h"
-#include "glh/glh_linear.h"
#include "llmatrix4a.h"
#include <boost/regex.hpp>
diff --git a/indra/llprimitive/llmodelloader.cpp b/indra/llprimitive/llmodelloader.cpp
index 9a194567d2..ae69c4f8ab 100644
--- a/indra/llprimitive/llmodelloader.cpp
+++ b/indra/llprimitive/llmodelloader.cpp
@@ -31,7 +31,6 @@
#include "lljoint.h"
#include "llcallbacklist.h"
-#include "glh/glh_linear.h"
#include "llmatrix4a.h"
#include <boost/bind.hpp>
diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp
index 0db1e27b01..c62cacdce6 100644
--- a/indra/llrender/llgl.cpp
+++ b/indra/llrender/llgl.cpp
@@ -50,6 +50,10 @@
#include "llglheaders.h"
#include "llglslshader.h"
+#include "glm/glm.hpp"
+#include <glm/gtc/matrix_access.hpp>
+#include "glm/gtc/type_ptr.hpp"
+
#if LL_WINDOWS
#include "lldxhardware.h"
#endif
@@ -2694,7 +2698,7 @@ void parse_glsl_version(S32& major, S32& minor)
LLStringUtil::convertToS32(minor_str, minor);
}
-LLGLUserClipPlane::LLGLUserClipPlane(const LLPlane& p, const glh::matrix4f& modelview, const glh::matrix4f& projection, bool apply)
+LLGLUserClipPlane::LLGLUserClipPlane(const LLPlane& p, const glm::mat4& modelview, const glm::mat4& projection, bool apply)
{
mApply = apply;
@@ -2721,13 +2725,12 @@ void LLGLUserClipPlane::disable()
void LLGLUserClipPlane::setPlane(F32 a, F32 b, F32 c, F32 d)
{
- glh::matrix4f& P = mProjection;
- glh::matrix4f& M = mModelview;
+ const glm::mat4& P = mProjection;
+ const glm::mat4& M = mModelview;
- glh::matrix4f invtrans_MVP = (P * M).inverse().transpose();
- glh::vec4f oplane(a,b,c,d);
- glh::vec4f cplane;
- invtrans_MVP.mult_matrix_vec(oplane, cplane);
+ glm::mat4 invtrans_MVP = glm::transpose(glm::inverse(P*M));
+ glm::vec4 oplane(a,b,c,d);
+ glm::vec4 cplane = invtrans_MVP * oplane;
cplane /= fabs(cplane[2]); // normalize such that depth is not scaled
cplane[3] -= 1;
@@ -2735,13 +2738,13 @@ void LLGLUserClipPlane::setPlane(F32 a, F32 b, F32 c, F32 d)
if(cplane[2] < 0)
cplane *= -1;
- glh::matrix4f suffix;
- suffix.set_row(2, cplane);
- glh::matrix4f newP = suffix * P;
+ glm::mat4 suffix;
+ suffix = glm::row(suffix, 2, cplane);
+ glm::mat4 newP = suffix * P;
gGL.matrixMode(LLRender::MM_PROJECTION);
gGL.pushMatrix();
- gGL.loadMatrix(newP.m);
- gGLObliqueProjectionInverse = LLMatrix4(newP.inverse().transpose().m);
+ gGL.loadMatrix(glm::value_ptr(newP));
+ gGLObliqueProjectionInverse = LLMatrix4(glm::value_ptr(glm::transpose(glm::inverse(newP))));
gGL.matrixMode(LLRender::MM_MODELVIEW);
}
@@ -2838,31 +2841,27 @@ void LLGLDepthTest::checkState()
LLGLSquashToFarClip::LLGLSquashToFarClip()
{
- glh::matrix4f proj = get_current_projection();
+ glm::mat4 proj = get_current_projection();
setProjectionMatrix(proj, 0);
}
-LLGLSquashToFarClip::LLGLSquashToFarClip(glh::matrix4f& P, U32 layer)
+LLGLSquashToFarClip::LLGLSquashToFarClip(const glm::mat4& P, U32 layer)
{
setProjectionMatrix(P, layer);
}
-
-void LLGLSquashToFarClip::setProjectionMatrix(glh::matrix4f& projection, U32 layer)
+void LLGLSquashToFarClip::setProjectionMatrix(glm::mat4 projection, U32 layer)
{
-
F32 depth = 0.99999f - 0.0001f * layer;
- for (U32 i = 0; i < 4; i++)
- {
- projection.element(2, i) = projection.element(3, i) * depth;
- }
+ glm::vec4 P_row_3 = glm::row(projection, 3) * depth;
+ projection = glm::row(projection, 2, P_row_3);
LLRender::eMatrixMode last_matrix_mode = gGL.getMatrixMode();
gGL.matrixMode(LLRender::MM_PROJECTION);
gGL.pushMatrix();
- gGL.loadMatrix(projection.m);
+ gGL.loadMatrix(glm::value_ptr(projection));
gGL.matrixMode(last_matrix_mode);
}
diff --git a/indra/llrender/llgl.h b/indra/llrender/llgl.h
index cd1ba55b16..17f825bd71 100644
--- a/indra/llrender/llgl.h
+++ b/indra/llrender/llgl.h
@@ -43,7 +43,7 @@
#include "llinstancetracker.h"
#include "llglheaders.h"
-#include "glh/glh_linear.h"
+#include "glm/mat4x4.hpp"
extern bool gDebugGL;
extern bool gDebugSession;
@@ -317,7 +317,7 @@ class LLGLUserClipPlane
{
public:
- LLGLUserClipPlane(const LLPlane& plane, const glh::matrix4f& modelview, const glh::matrix4f& projection, bool apply = true);
+ LLGLUserClipPlane(const LLPlane& plane, const glm::mat4& modelview, const glm::mat4& projection, bool apply = true);
~LLGLUserClipPlane();
void setPlane(F32 a, F32 b, F32 c, F32 d);
@@ -326,8 +326,8 @@ public:
private:
bool mApply;
- glh::matrix4f mProjection;
- glh::matrix4f mModelview;
+ glm::mat4 mProjection;
+ glm::mat4 mModelview;
};
/*
@@ -341,9 +341,9 @@ class LLGLSquashToFarClip
{
public:
LLGLSquashToFarClip();
- LLGLSquashToFarClip(glh::matrix4f& projection, U32 layer = 0);
+ LLGLSquashToFarClip(const glm::mat4& projection, U32 layer = 0);
- void setProjectionMatrix(glh::matrix4f& projection, U32 layer);
+ void setProjectionMatrix(glm::mat4 projection, U32 layer);
~LLGLSquashToFarClip();
};
diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp
index 828a509971..16a8309a9a 100644
--- a/indra/llrender/llrender.cpp
+++ b/indra/llrender/llrender.cpp
@@ -36,6 +36,7 @@
#include "lltexture.h"
#include "llshadermgr.h"
#include "hbxxh.h"
+#include "glm/gtc/type_ptr.hpp"
#if LL_WINDOWS
extern void APIENTRY gl_debug_callback(GLenum source,
@@ -57,8 +58,8 @@ F32 gGLLastProjection[16];
F32 gGLProjection[16];
// transform from last frame's camera space to this frame's camera space (and inverse)
-F32 gGLDeltaModelView[16];
-F32 gGLInverseDeltaModelView[16];
+glm::mat4 gGLDeltaModelView;
+glm::mat4 gGLInverseDeltaModelView;
S32 gGLViewport[4];
@@ -735,10 +736,10 @@ void LLLightState::setPosition(const LLVector4& position)
++gGL.mLightHash;
mPosition = position;
//transform position by current modelview matrix
- glh::vec4f pos(position.mV);
- const glh::matrix4f& mat = gGL.getModelviewMatrix();
- mat.mult_matrix_vec(pos);
- mPosition.set(pos.v);
+ glm::vec4 pos(glm::make_vec4(position.mV));
+ const glm::mat4& mat = gGL.getModelviewMatrix();
+ pos = mat * pos;
+ mPosition.set(glm::value_ptr(pos));
}
void LLLightState::setConstantAttenuation(const F32& atten)
@@ -790,13 +791,13 @@ void LLLightState::setSpotDirection(const LLVector3& direction)
{
//always set direction because modelview matrix may have changed
++gGL.mLightHash;
- mSpotDirection = direction;
+
//transform direction by current modelview matrix
- glh::vec3f dir(direction.mV);
- const glh::matrix4f& mat = gGL.getModelviewMatrix();
- mat.mult_matrix_dir(dir);
+ glm::vec3 dir(glm::make_vec3(direction.mV));
+ const glm::mat3 mat(gGL.getModelviewMatrix());
+ dir = mat * dir;
- mSpotDirection.set(dir.v);
+ mSpotDirection.set(glm::value_ptr(dir));
}
LLRender::LLRender()
@@ -830,6 +831,10 @@ LLRender::LLRender()
for (U32 i = 0; i < NUM_MATRIX_MODES; ++i)
{
+ for (U32 j = 0; j < LL_MATRIX_STACK_DEPTH; ++j)
+ {
+ mMatrix[i][j] = glm::identity<glm::mat4>();
+ }
mMatIdx[i] = 0;
mMatHash[i] = 0;
mCurMatHash[i] = 0xFFFFFFFF;
@@ -991,12 +996,12 @@ void LLRender::syncMatrices()
LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
- static glh::matrix4f cached_mvp;
- static glh::matrix4f cached_inv_mdv;
+ static glm::mat4 cached_mvp;
+ static glm::mat4 cached_inv_mdv;
static U32 cached_mvp_mdv_hash = 0xFFFFFFFF;
static U32 cached_mvp_proj_hash = 0xFFFFFFFF;
- static glh::matrix4f cached_normal;
+ static glm::mat4 cached_normal;
static U32 cached_normal_hash = 0xFFFFFFFF;
if (shader)
@@ -1006,15 +1011,15 @@ void LLRender::syncMatrices()
U32 i = MM_MODELVIEW;
if (mMatHash[MM_MODELVIEW] != shader->mMatHash[MM_MODELVIEW])
{ //update modelview, normal, and MVP
- glh::matrix4f& mat = mMatrix[MM_MODELVIEW][mMatIdx[MM_MODELVIEW]];
+ const glm::mat4& mat = mMatrix[MM_MODELVIEW][mMatIdx[MM_MODELVIEW]];
// if MDV has changed, update the cached inverse as well
if (cached_mvp_mdv_hash != mMatHash[MM_MODELVIEW])
{
- cached_inv_mdv = mat.inverse();
+ cached_inv_mdv = glm::inverse(mat);
}
- shader->uniformMatrix4fv(name[MM_MODELVIEW], 1, GL_FALSE, mat.m);
+ shader->uniformMatrix4fv(name[MM_MODELVIEW], 1, GL_FALSE, glm::value_ptr(mat));
shader->mMatHash[MM_MODELVIEW] = mMatHash[MM_MODELVIEW];
//update normal matrix
@@ -1023,17 +1028,17 @@ void LLRender::syncMatrices()
{
if (cached_normal_hash != mMatHash[i])
{
- cached_normal = cached_inv_mdv.transpose();
+ cached_normal = glm::transpose(cached_inv_mdv);
cached_normal_hash = mMatHash[i];
}
- glh::matrix4f& norm = cached_normal;
+ auto norm = glm::value_ptr(cached_normal);
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]
+ norm[0], norm[1], norm[2],
+ norm[4], norm[5], norm[6],
+ norm[8], norm[9], norm[10]
};
shader->uniformMatrix3fv(LLShaderMgr::NORMAL_MATRIX, 1, GL_FALSE, norm_mat);
@@ -1041,7 +1046,7 @@ void LLRender::syncMatrices()
if (shader->getUniformLocation(LLShaderMgr::INVERSE_MODELVIEW_MATRIX))
{
- shader->uniformMatrix4fv(LLShaderMgr::INVERSE_MODELVIEW_MATRIX, 1, GL_FALSE, cached_inv_mdv.m);
+ shader->uniformMatrix4fv(LLShaderMgr::INVERSE_MODELVIEW_MATRIX, 1, GL_FALSE, glm::value_ptr(cached_inv_mdv));
}
//update MVP matrix
@@ -1054,36 +1059,36 @@ void LLRender::syncMatrices()
if (cached_mvp_mdv_hash != mMatHash[i] || cached_mvp_proj_hash != mMatHash[MM_PROJECTION])
{
cached_mvp = mat;
- cached_mvp.mult_left(mMatrix[proj][mMatIdx[proj]]);
+ cached_mvp = mMatrix[proj][mMatIdx[proj]] * cached_mvp;
cached_mvp_mdv_hash = mMatHash[i];
cached_mvp_proj_hash = mMatHash[MM_PROJECTION];
}
- shader->uniformMatrix4fv(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX, 1, GL_FALSE, cached_mvp.m);
+ shader->uniformMatrix4fv(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX, 1, GL_FALSE, glm::value_ptr(cached_mvp));
}
}
i = MM_PROJECTION;
if (mMatHash[MM_PROJECTION] != shader->mMatHash[MM_PROJECTION])
{ //update projection matrix, normal, and MVP
- glh::matrix4f& mat = mMatrix[MM_PROJECTION][mMatIdx[MM_PROJECTION]];
+ const glm::mat4& mat = mMatrix[MM_PROJECTION][mMatIdx[MM_PROJECTION]];
// GZ: This was previously disabled seemingly due to a bug involving the deferred renderer's regular pushing and popping of mats.
// We're reenabling this and cleaning up the code around that - that would've been the appropriate course initially.
// Anything beyond the standard proj and inv proj mats are special cases. Please setup special uniforms accordingly in the future.
if (shader->getUniformLocation(LLShaderMgr::INVERSE_PROJECTION_MATRIX))
{
- glh::matrix4f inv_proj = mat.inverse();
- shader->uniformMatrix4fv(LLShaderMgr::INVERSE_PROJECTION_MATRIX, 1, false, inv_proj.m);
+ glm::mat4 inv_proj = glm::inverse(mat);
+ shader->uniformMatrix4fv(LLShaderMgr::INVERSE_PROJECTION_MATRIX, 1, false, glm::value_ptr(inv_proj));
}
// Used by some full screen effects - such as full screen lights, glow, etc.
if (shader->getUniformLocation(LLShaderMgr::IDENTITY_MATRIX))
{
- shader->uniformMatrix4fv(LLShaderMgr::IDENTITY_MATRIX, 1, GL_FALSE, glh::matrix4f::identity().m);
+ shader->uniformMatrix4fv(LLShaderMgr::IDENTITY_MATRIX, 1, GL_FALSE, glm::value_ptr(glm::identity<glm::mat4>()));
}
- shader->uniformMatrix4fv(name[MM_PROJECTION], 1, GL_FALSE, mat.m);
+ shader->uniformMatrix4fv(name[MM_PROJECTION], 1, GL_FALSE, glm::value_ptr(mat));
shader->mMatHash[MM_PROJECTION] = mMatHash[MM_PROJECTION];
if (!mvp_done)
@@ -1096,12 +1101,12 @@ void LLRender::syncMatrices()
{
U32 mdv = MM_MODELVIEW;
cached_mvp = mat;
- cached_mvp.mult_right(mMatrix[mdv][mMatIdx[mdv]]);
+ cached_mvp *= mMatrix[mdv][mMatIdx[mdv]];
cached_mvp_mdv_hash = mMatHash[MM_MODELVIEW];
cached_mvp_proj_hash = mMatHash[MM_PROJECTION];
}
- shader->uniformMatrix4fv(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX, 1, GL_FALSE, cached_mvp.m);
+ shader->uniformMatrix4fv(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX, 1, GL_FALSE, glm::value_ptr(cached_mvp));
}
}
}
@@ -1110,7 +1115,7 @@ void LLRender::syncMatrices()
{
if (mMatHash[i] != shader->mMatHash[i])
{
- shader->uniformMatrix4fv(name[i], 1, GL_FALSE, mMatrix[i][mMatIdx[i]].m);
+ shader->uniformMatrix4fv(name[i], 1, GL_FALSE, glm::value_ptr(mMatrix[i][mMatIdx[i]]));
shader->mMatHash[i] = mMatHash[i];
}
}
@@ -1129,12 +1134,7 @@ void LLRender::translatef(const GLfloat& x, const GLfloat& y, const GLfloat& z)
flush();
{
- glh::matrix4f trans_mat(1,0,0,x,
- 0,1,0,y,
- 0,0,1,z,
- 0,0,0,1);
-
- mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].mult_right(trans_mat);
+ mMatrix[mMatrixMode][mMatIdx[mMatrixMode]] = glm::translate(mMatrix[mMatrixMode][mMatIdx[mMatrixMode]], glm::vec3(x, y, z));
mMatHash[mMatrixMode]++;
}
}
@@ -1144,12 +1144,7 @@ void LLRender::scalef(const GLfloat& x, const GLfloat& y, const GLfloat& z)
flush();
{
- glh::matrix4f scale_mat(x,0,0,0,
- 0,y,0,0,
- 0,0,z,0,
- 0,0,0,1);
-
- mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].mult_right(scale_mat);
+ mMatrix[mMatrixMode][mMatIdx[mMatrixMode]] = glm::scale(mMatrix[mMatrixMode][mMatIdx[mMatrixMode]], glm::vec3(x, y, z));
mMatHash[mMatrixMode]++;
}
}
@@ -1159,13 +1154,7 @@ void LLRender::ortho(F32 left, F32 right, F32 bottom, F32 top, F32 zNear, F32 zF
flush();
{
-
- glh::matrix4f ortho_mat(2.f/(right-left),0,0, -(right+left)/(right-left),
- 0,2.f/(top-bottom),0, -(top+bottom)/(top-bottom),
- 0,0,-2.f/(zFar-zNear), -(zFar+zNear)/(zFar-zNear),
- 0,0,0,1);
-
- mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].mult_right(ortho_mat);
+ mMatrix[mMatrixMode][mMatIdx[mMatrixMode]] *= glm::ortho(left, right, bottom, top, zNear, zFar);
mMatHash[mMatrixMode]++;
}
}
@@ -1175,19 +1164,7 @@ void LLRender::rotatef(const GLfloat& a, const GLfloat& x, const GLfloat& y, con
flush();
{
- F32 r = a * DEG_TO_RAD;
-
- F32 c = cosf(r);
- F32 s = sinf(r);
-
- F32 ic = 1.f-c;
-
- glh::matrix4f rot_mat(x*x*ic+c, x*y*ic-z*s, x*z*ic+y*s, 0,
- x*y*ic+z*s, y*y*ic+c, y*z*ic-x*s, 0,
- x*z*ic-y*s, y*z*ic+x*s, z*z*ic+c, 0,
- 0,0,0,1);
-
- mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].mult_right(rot_mat);
+ mMatrix[mMatrixMode][mMatIdx[mMatrixMode]] = glm::rotate(mMatrix[mMatrixMode][mMatIdx[mMatrixMode]], glm::radians(a), glm::vec3(x,y,z));
mMatHash[mMatrixMode]++;
}
}
@@ -1229,7 +1206,7 @@ void LLRender::loadMatrix(const GLfloat* m)
{
flush();
{
- mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].set_value((GLfloat*) m);
+ mMatrix[mMatrixMode][mMatIdx[mMatrixMode]] = glm::make_mat4((GLfloat*) m);
mMatHash[mMatrixMode]++;
}
}
@@ -1238,9 +1215,7 @@ void LLRender::multMatrix(const GLfloat* m)
{
flush();
{
- glh::matrix4f mat((GLfloat*) m);
-
- mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].mult_right(mat);
+ mMatrix[mMatrixMode][mMatIdx[mMatrixMode]] *= glm::make_mat4(m);
mMatHash[mMatrixMode]++;
}
}
@@ -1283,17 +1258,17 @@ void LLRender::loadIdentity()
{
llassert_always(mMatrixMode < NUM_MATRIX_MODES) ;
- mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].make_identity();
+ mMatrix[mMatrixMode][mMatIdx[mMatrixMode]] = glm::identity<glm::mat4>();
mMatHash[mMatrixMode]++;
}
}
-const glh::matrix4f& LLRender::getModelviewMatrix()
+const glm::mat4& LLRender::getModelviewMatrix()
{
return mMatrix[MM_MODELVIEW][mMatIdx[MM_MODELVIEW]];
}
-const glh::matrix4f& LLRender::getProjectionMatrix()
+const glm::mat4& LLRender::getProjectionMatrix()
{
return mMatrix[MM_PROJECTION][mMatIdx[MM_PROJECTION]];
}
@@ -2214,85 +2189,90 @@ void LLRender::debugTexUnits(void)
LL_INFOS("TextureUnit") << "Active TexUnit Enabled : " << active_enabled << LL_ENDL;
}
-
-
-glh::matrix4f copy_matrix(F32* src)
-{
- glh::matrix4f ret;
- ret.set_value(src);
- return ret;
-}
-
-glh::matrix4f get_current_modelview()
+glm::mat4 get_current_modelview()
{
- return copy_matrix(gGLModelView);
+ return glm::make_mat4(gGLModelView);
}
-glh::matrix4f get_current_projection()
+glm::mat4 get_current_projection()
{
- return copy_matrix(gGLProjection);
+ return glm::make_mat4(gGLProjection);
}
-glh::matrix4f get_last_modelview()
+glm::mat4 get_last_modelview()
{
- return copy_matrix(gGLLastModelView);
+ return glm::make_mat4(gGLLastModelView);
}
-glh::matrix4f get_last_projection()
+glm::mat4 get_last_projection()
{
- return copy_matrix(gGLLastProjection);
+ return glm::make_mat4(gGLLastProjection);
}
-void copy_matrix(const glh::matrix4f& src, F32* dst)
+void copy_matrix(const glm::mat4& src, F32* dst)
{
+ auto matp = glm::value_ptr(src);
for (U32 i = 0; i < 16; i++)
{
- dst[i] = src.m[i];
+ dst[i] = matp[i];
}
}
-void set_current_modelview(const glh::matrix4f& mat)
+void set_current_modelview(const glm::mat4& mat)
{
copy_matrix(mat, gGLModelView);
}
-void set_current_projection(glh::matrix4f& mat)
+void set_current_projection(const glm::mat4& mat)
{
copy_matrix(mat, gGLProjection);
}
-glh::matrix4f gl_ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat znear, GLfloat zfar)
+void set_last_modelview(const glm::mat4& mat)
{
- glh::matrix4f ret(
- 2.f/(right-left), 0.f, 0.f, -(right+left)/(right-left),
- 0.f, 2.f/(top-bottom), 0.f, -(top+bottom)/(top-bottom),
- 0.f, 0.f, -2.f/(zfar-znear), -(zfar+znear)/(zfar-znear),
- 0.f, 0.f, 0.f, 1.f);
-
- return ret;
+ copy_matrix(mat, gGLLastModelView);
}
-glh::matrix4f gl_perspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar)
+void set_last_projection(const glm::mat4& mat)
{
- GLfloat f = 1.f/tanf(DEG_TO_RAD*fovy/2.f);
-
- return glh::matrix4f(f/aspect, 0, 0, 0,
- 0, f, 0, 0,
- 0, 0, (zFar+zNear)/(zNear-zFar), (2.f*zFar*zNear)/(zNear-zFar),
- 0, 0, -1.f, 0);
+ copy_matrix(mat, gGLLastProjection);
}
-glh::matrix4f gl_lookat(LLVector3 eye, LLVector3 center, LLVector3 up)
+glm::vec3 mul_mat4_vec3(const glm::mat4& mat, const glm::vec3& vec)
{
- LLVector3 f = center-eye;
- f.normVec();
- up.normVec();
- LLVector3 s = f % up;
- LLVector3 u = s % f;
+ //const float w = vec[0] * mat[0][3] + vec[1] * mat[1][3] + vec[2] * mat[2][3] + mat[3][3];
+ //return glm::vec3(
+ // (vec[0] * mat[0][0] + vec[1] * mat[1][0] + vec[2] * mat[2][0] + mat[3][0]) / w,
+ // (vec[0] * mat[0][1] + vec[1] * mat[1][1] + vec[2] * mat[2][1] + mat[3][1]) / w,
+ // (vec[0] * mat[0][2] + vec[1] * mat[1][2] + vec[2] * mat[2][2] + mat[3][2]) / w
+ //);
+ LLVector4a x, y, z, s, t, p, q;
+
+ x.splat(vec.x);
+ y.splat(vec.y);
+ z.splat(vec.z);
+
+ s.splat<3>(mat[0].data);
+ t.splat<3>(mat[1].data);
+ p.splat<3>(mat[2].data);
+ q.splat<3>(mat[3].data);
+
+ s.mul(x);
+ t.mul(y);
+ p.mul(z);
+ q.add(s);
+ t.add(p);
+ q.add(t);
- return glh::matrix4f(s[0], s[1], s[2], 0,
- u[0], u[1], u[2], 0,
- -f[0], -f[1], -f[2], 0,
- 0, 0, 0, 1);
+ x.mul(mat[0].data);
+ y.mul(mat[1].data);
+ z.mul(mat[2].data);
+ x.add(y);
+ z.add(mat[3].data);
+ LLVector4a res;
+ res.load3(glm::value_ptr(vec));
+ res.setAdd(x, z);
+ res.div(q);
+ return glm::make_vec3(res.getF32ptr());
}
diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h
index 39c13e328a..2645597b1a 100644
--- a/indra/llrender/llrender.h
+++ b/indra/llrender/llrender.h
@@ -42,7 +42,7 @@
#include "llpointer.h"
#include "llglheaders.h"
#include "llmatrix4a.h"
-#include "glh/glh_linear.h"
+#include "glm/mat4x4.hpp"
#include <array>
#include <list>
@@ -401,8 +401,8 @@ public:
void matrixMode(eMatrixMode mode);
eMatrixMode getMatrixMode();
- const glh::matrix4f& getModelviewMatrix();
- const glh::matrix4f& getProjectionMatrix();
+ const glm::mat4& getModelviewMatrix();
+ const glm::mat4& getProjectionMatrix();
void syncMatrices();
void syncLightState();
@@ -502,7 +502,7 @@ private:
eMatrixMode mMatrixMode;
U32 mMatIdx[NUM_MATRIX_MODES];
U32 mMatHash[NUM_MATRIX_MODES];
- glh::matrix4f mMatrix[NUM_MATRIX_MODES][LL_MATRIX_STACK_DEPTH];
+ glm::mat4 mMatrix[NUM_MATRIX_MODES][LL_MATRIX_STACK_DEPTH];
U32 mCurMatHash[NUM_MATRIX_MODES];
U32 mLightHash;
LLColor4 mAmbientLightColor;
@@ -536,8 +536,8 @@ extern F32 gGLLastModelView[16];
extern F32 gGLLastProjection[16];
extern F32 gGLProjection[16];
extern S32 gGLViewport[4];
-extern F32 gGLDeltaModelView[16];
-extern F32 gGLInverseDeltaModelView[16];
+extern glm::mat4 gGLDeltaModelView;
+extern glm::mat4 gGLInverseDeltaModelView;
extern thread_local LLRender gGL;
@@ -548,19 +548,20 @@ const F32 OGL_TO_CFR_ROTATION[16] = { 0.f, 0.f, -1.f, 0.f, // -Z becomes X
0.f, 1.f, 0.f, 0.f, // Y becomes Z
0.f, 0.f, 0.f, 1.f };
-glh::matrix4f copy_matrix(F32* src);
-glh::matrix4f get_current_modelview();
-glh::matrix4f get_current_projection();
-glh::matrix4f get_last_modelview();
-glh::matrix4f get_last_projection();
+glm::mat4 copy_matrix(F32* src);
+glm::mat4 get_current_modelview();
+glm::mat4 get_current_projection();
+glm::mat4 get_last_modelview();
+glm::mat4 get_last_projection();
-void copy_matrix(const glh::matrix4f& src, F32* dst);
-void set_current_modelview(const glh::matrix4f& mat);
-void set_current_projection(glh::matrix4f& mat);
+void copy_matrix(const glm::mat4& src, F32* dst);
+void set_current_modelview(const glm::mat4& mat);
+void set_current_projection(const glm::mat4& mat);
+void set_last_modelview(const glm::mat4& mat);
+void set_last_projection(const glm::mat4& mat);
-glh::matrix4f gl_ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat znear, GLfloat zfar);
-glh::matrix4f gl_perspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar);
-glh::matrix4f gl_lookat(LLVector3 eye, LLVector3 center, LLVector3 up);
+// glh compat
+glm::vec3 mul_mat4_vec3(const glm::mat4& mat, const glm::vec3& vec);
#define LL_SHADER_LOADING_WARNS(...) LL_WARNS()
diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp
index 666d792d1d..8524b470de 100644
--- a/indra/llrender/llvertexbuffer.cpp
+++ b/indra/llrender/llvertexbuffer.cpp
@@ -36,6 +36,7 @@
#include "llshadermgr.h"
#include "llglslshader.h"
#include "llmemory.h"
+#include <glm/gtc/type_ptr.hpp>
//Next Highest Power Of Two
//helper function, returns first number > v that is a power of 2, or v if v is already a power of 2
@@ -590,13 +591,13 @@ void LLVertexBufferData::draw()
gGL.matrixMode(LLRender::MM_MODELVIEW);
gGL.pushMatrix();
- gGL.loadMatrix(mModelView.m);
+ gGL.loadMatrix(glm::value_ptr(mModelView));
gGL.matrixMode(LLRender::MM_PROJECTION);
gGL.pushMatrix();
- gGL.loadMatrix(mProjection.m);
+ gGL.loadMatrix(glm::value_ptr(mProjection));
gGL.matrixMode(LLRender::MM_TEXTURE0);
gGL.pushMatrix();
- gGL.loadMatrix(mTexture0.m);
+ gGL.loadMatrix(glm::value_ptr(mTexture0));
mVB->setBuffer();
diff --git a/indra/llrender/llvertexbuffer.h b/indra/llrender/llvertexbuffer.h
index 9fe468f89e..d4c6fbaf18 100644
--- a/indra/llrender/llvertexbuffer.h
+++ b/indra/llrender/llvertexbuffer.h
@@ -38,6 +38,7 @@
#include <set>
#include <vector>
#include <list>
+#include <glm/gtc/matrix_transform.hpp>
#define LL_MAX_VERTEX_ATTRIB_LOCATION 64
@@ -63,8 +64,11 @@ public:
, mMode(0)
, mCount(0)
, mTexName(0)
+ , mProjection(glm::identity<glm::mat4>())
+ , mModelView(glm::identity<glm::mat4>())
+ , mTexture0(glm::identity<glm::mat4>())
{}
- LLVertexBufferData(LLVertexBuffer* buffer, U8 mode, U32 count, U32 tex_name, glh::matrix4f model_view, glh::matrix4f projection, glh::matrix4f texture0)
+ LLVertexBufferData(LLVertexBuffer* buffer, U8 mode, U32 count, U32 tex_name, const glm::mat4& model_view, const glm::mat4& projection, const glm::mat4& texture0)
: mVB(buffer)
, mMode(mode)
, mCount(count)
@@ -78,9 +82,9 @@ public:
U8 mMode;
U32 mCount;
U32 mTexName;
- glh::matrix4f mProjection;
- glh::matrix4f mModelView;
- glh::matrix4f mTexture0;
+ glm::mat4 mProjection;
+ glm::mat4 mModelView;
+ glm::mat4 mTexture0;
};
typedef std::list<LLVertexBufferData> buffer_data_list_t;
diff --git a/indra/llwindow/CMakeLists.txt b/indra/llwindow/CMakeLists.txt
index 7b1430c67c..2996f58fe0 100644
--- a/indra/llwindow/CMakeLists.txt
+++ b/indra/llwindow/CMakeLists.txt
@@ -17,6 +17,7 @@ include(LLImage)
include(LLWindow)
include(UI)
include(ViewerMiscLibs)
+include(GLM)
set(llwindow_SOURCE_FILES
llcursortypes.cpp
@@ -54,7 +55,7 @@ set(llwindow_LINK_LIBRARIES
llrender
llfilesystem
llxml
- ll::glh_linear
+ ll::glm
ll::glext
ll::uilibraries
ll::SDL
diff --git a/indra/newview/gltfscenemanager.cpp b/indra/newview/gltfscenemanager.cpp
index e55d630940..ce54fa4c12 100644
--- a/indra/newview/gltfscenemanager.cpp
+++ b/indra/newview/gltfscenemanager.cpp
@@ -807,10 +807,10 @@ void GLTFSceneManager::bind(Asset& asset, Material& material)
LLMatrix4a inverse(const LLMatrix4a& mat)
{
- glh::matrix4f m((F32*)mat.mMatrix);
- m = m.inverse();
+ glm::mat4 m = glm::make_mat4((F32*)mat.mMatrix);
+ m = glm::inverse(m);
LLMatrix4a ret;
- ret.loadu(m.m);
+ ret.loadu(glm::value_ptr(m));
return ret;
}
diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp
index a1ec75e34b..48fddc32db 100644
--- a/indra/newview/llface.cpp
+++ b/indra/newview/llface.cpp
@@ -1487,9 +1487,9 @@ bool LLFace::getGeometryVolume(const LLVolume& volume,
}
//TODO -- cache this (check profile marker above)?
- glh::matrix4f m((F32*) skin->mBindShapeMatrix.getF32ptr());
- m = m.inverse().transpose();
- mat_normal.loadu(m.m);
+ glm::mat4 m = glm::make_mat4((F32*)skin->mBindShapeMatrix.getF32ptr());
+ m = glm::transpose(glm::inverse(m));
+ mat_normal.loadu(glm::value_ptr(m));
}
else
{
diff --git a/indra/newview/llgltfmaterialpreviewmgr.cpp b/indra/newview/llgltfmaterialpreviewmgr.cpp
index e38ba8762a..294b445694 100644
--- a/indra/newview/llgltfmaterialpreviewmgr.cpp
+++ b/indra/newview/llgltfmaterialpreviewmgr.cpp
@@ -471,10 +471,10 @@ bool LLGLTFPreviewTexture::render()
PreviewSphere& preview_sphere = get_preview_sphere(mGLTFMaterial, object_transform);
gPipeline.setupHWLights();
- glh::matrix4f mat = copy_matrix(gGLModelView);
- glh::vec4f transformed_light_dir(light_dir.mV);
- mat.mult_matrix_vec(transformed_light_dir);
- SetTemporarily<LLVector4> force_sun_direction_high_graphics(&gPipeline.mTransformedSunDir, LLVector4(transformed_light_dir.v));
+ glm::mat4 mat = get_current_modelview();
+ glm::vec4 transformed_light_dir = glm::make_vec4(light_dir.mV);
+ transformed_light_dir = mat * transformed_light_dir;
+ SetTemporarily<LLVector4> force_sun_direction_high_graphics(&gPipeline.mTransformedSunDir, LLVector4(glm::value_ptr(transformed_light_dir)));
// Override lights to ensure the sun is always shining from a certain direction (low graphics)
// See also force_sun_direction_high_graphics and fixup_shader_constants
{
diff --git a/indra/newview/llhudrender.cpp b/indra/newview/llhudrender.cpp
index f027aa5552..4180e49e94 100644
--- a/indra/newview/llhudrender.cpp
+++ b/indra/newview/llhudrender.cpp
@@ -38,6 +38,9 @@
#include "llviewerwindow.h"
#include "llui.h"
+#include <glm/gtc/matrix_transform.hpp>
+#include <glm/gtc/type_ptr.hpp>
+
void hud_render_utf8text(const std::string &str, const LLVector3 &pos_agent,
LLFontVertexBuffer *font_buffer,
const LLFontGL &font,
@@ -102,26 +105,10 @@ void hud_render_text(const LLWString &wstr, const LLVector3 &pos_agent,
//get the render_pos in screen space
- F64 winX, winY, winZ;
LLRect world_view_rect = gViewerWindow->getWorldViewRectRaw();
- S32 viewport[4];
- viewport[0] = world_view_rect.mLeft;
- viewport[1] = world_view_rect.mBottom;
- viewport[2] = world_view_rect.getWidth();
- viewport[3] = world_view_rect.getHeight();
-
- F64 mdlv[16];
- F64 proj[16];
-
- for (U32 i = 0; i < 16; i++)
- {
- mdlv[i] = (F64) gGLModelView[i];
- proj[i] = (F64) gGLProjection[i];
- }
+ glm::ivec4 viewport(world_view_rect.mLeft, world_view_rect.mBottom, world_view_rect.getWidth(), world_view_rect.getHeight());
- gluProject(render_pos.mV[0], render_pos.mV[1], render_pos.mV[2],
- mdlv, proj, (GLint*) viewport,
- &winX, &winY, &winZ);
+ glm::vec3 win_coord = glm::project(glm::make_vec3(render_pos.mV), get_current_modelview(), get_current_projection(), viewport);
//fonts all render orthographically, set up projection``
gGL.matrixMode(LLRender::MM_PROJECTION);
@@ -133,11 +120,11 @@ void hud_render_text(const LLWString &wstr, const LLVector3 &pos_agent,
gl_state_for_2d(world_view_rect.getWidth(), world_view_rect.getHeight());
gViewerWindow->setup3DViewport();
- winX -= world_view_rect.mLeft;
- winY -= world_view_rect.mBottom;
+ win_coord.x -= world_view_rect.mLeft;
+ win_coord.y -= world_view_rect.mBottom;
LLUI::loadIdentity();
gGL.loadIdentity();
- LLUI::translate((F32) winX*1.0f/LLFontGL::sScaleX, (F32) winY*1.0f/(LLFontGL::sScaleY), -(((F32) winZ*2.f)-1.f));
+ LLUI::translate((F32) win_coord.x*1.0f/LLFontGL::sScaleX, (F32) win_coord.y*1.0f/(LLFontGL::sScaleY), -(((F32) win_coord.z*2.f)-1.f));
F32 right_x;
if (font_buffer)
diff --git a/indra/newview/llmaniptranslate.cpp b/indra/newview/llmaniptranslate.cpp
index c9c7d26d33..060fe0d600 100644
--- a/indra/newview/llmaniptranslate.cpp
+++ b/indra/newview/llmaniptranslate.cpp
@@ -1676,9 +1676,9 @@ void LLManipTranslate::highlightIntersection(LLVector3 normal,
normal = -normal;
}
F32 d = -(selection_center * normal);
- glh::vec4f plane(normal.mV[0], normal.mV[1], normal.mV[2], d );
+ glm::vec4 plane(normal.mV[0], normal.mV[1], normal.mV[2], d );
- gGL.getModelviewMatrix().inverse().mult_vec_matrix(plane);
+ plane = glm::inverse(gGL.getModelviewMatrix()) * plane;
static LLStaticHashedString sClipPlane("clip_plane");
gClipProgram.uniform4fv(sClipPlane, 1, plane.v);
diff --git a/indra/newview/llmodelpreview.cpp b/indra/newview/llmodelpreview.cpp
index df573bd785..ef09cfa55b 100644
--- a/indra/newview/llmodelpreview.cpp
+++ b/indra/newview/llmodelpreview.cpp
@@ -2828,9 +2828,9 @@ void LLModelPreview::genBuffers(S32 lod, bool include_skin_weights)
LLMatrix4a mat_normal;
if (skinned)
{
- glh::matrix4f m((F32*)mdl->mSkinInfo.mBindShapeMatrix.getF32ptr());
- m = m.inverse().transpose();
- mat_normal.loadu(m.m);
+ glm::mat4 m = glm::make_mat4((F32*)mdl->mSkinInfo.mBindShapeMatrix.getF32ptr());
+ m = glm::transpose(glm::inverse(m));
+ mat_normal.loadu(glm::value_ptr(m));
}
S32 num_faces = mdl->getNumVolumeFaces();
diff --git a/indra/newview/llpanelprimmediacontrols.cpp b/indra/newview/llpanelprimmediacontrols.cpp
index 4e905ae0fd..4db0a5b59d 100644
--- a/indra/newview/llpanelprimmediacontrols.cpp
+++ b/indra/newview/llpanelprimmediacontrols.cpp
@@ -63,11 +63,10 @@
#include "llfloatertools.h" // to enable hide if build tools are up
#include "llvector4a.h"
-// Functions pulled from pipeline.cpp
-glh::matrix4f get_current_modelview();
-glh::matrix4f get_current_projection();
+#include <glm/gtx/transform2.hpp>
+
// Functions pulled from llviewerdisplay.cpp
-bool get_hud_matrices(glh::matrix4f &proj, glh::matrix4f &model);
+bool get_hud_matrices(glm::mat4 &proj, glm::mat4 &model);
// Warning: make sure these two match!
const LLPanelPrimMediaControls::EZoomLevel LLPanelPrimMediaControls::kZoomLevels[] = { ZOOM_NONE, ZOOM_MEDIUM };
@@ -646,13 +645,13 @@ void LLPanelPrimMediaControls::updateShape()
vert_it = vect_face.begin();
vert_end = vect_face.end();
- glh::matrix4f mat;
+ glm::mat4 mat;
if (!is_hud)
{
mat = get_current_projection() * get_current_modelview();
}
else {
- glh::matrix4f proj, modelview;
+ glm::mat4 proj, modelview;
if (get_hud_matrices(proj, modelview))
mat = proj * modelview;
}
@@ -661,11 +660,11 @@ void LLPanelPrimMediaControls::updateShape()
for(; vert_it != vert_end; ++vert_it)
{
// project silhouette vertices into screen space
- glh::vec3f screen_vert = glh::vec3f(vert_it->mV);
- mat.mult_matrix_vec(screen_vert);
+ glm::vec3 screen_vert(glm::make_vec3(vert_it->mV));
+ screen_vert = mul_mat4_vec3(mat, screen_vert);
// add to screenspace bounding box
- update_min_max(min, max, LLVector3(screen_vert.v));
+ update_min_max(min, max, LLVector3(glm::value_ptr(screen_vert)));
}
// convert screenspace bbox to pixels (in screen coords)
diff --git a/indra/newview/llreflectionmap.cpp b/indra/newview/llreflectionmap.cpp
index 8d164b6883..f77d37f821 100644
--- a/indra/newview/llreflectionmap.cpp
+++ b/indra/newview/llreflectionmap.cpp
@@ -253,23 +253,22 @@ bool LLReflectionMap::getBox(LLMatrix4& box)
LLVolume* volume = mViewerObject->getVolume();
if (volume && mViewerObject->getReflectionProbeIsBox())
{
- glh::matrix4f mv(gGLModelView);
- glh::matrix4f scale;
+ glm::mat4 mv(get_current_modelview());
LLVector3 s = mViewerObject->getScale().scaledVec(LLVector3(0.5f, 0.5f, 0.5f));
mRadius = s.magVec();
- scale.set_scale(glh::vec3f(s.mV));
+ glm::mat4 scale = glm::scale(glm::make_vec3(s.mV));
if (mViewerObject->mDrawable != nullptr)
{
// object to agent space (no scale)
- glh::matrix4f rm((F32*)mViewerObject->mDrawable->getWorldMatrix().mMatrix);
+ glm::mat4 rm(glm::make_mat4((F32*)mViewerObject->mDrawable->getWorldMatrix().mMatrix));
// construct object to camera space (with scale)
mv = mv * rm * scale;
// inverse is camera space to object unit cube
- mv = mv.inverse();
+ mv = glm::inverse(mv);
- box = LLMatrix4(mv.m);
+ box = LLMatrix4(glm::value_ptr(mv));
return true;
}
diff --git a/indra/newview/llsettingsvo.cpp b/indra/newview/llsettingsvo.cpp
index e05b6f3736..6f9de57d2a 100644
--- a/indra/newview/llsettingsvo.cpp
+++ b/indra/newview/llsettingsvo.cpp
@@ -996,38 +996,33 @@ void LLSettingsVOWater::applySpecial(void *ptarget, bool force)
}
//transform water plane to eye space
- glh::vec3f norm(0.f, 0.f, 1.f);
- glh::vec3f p(0.f, 0.f, water_height);
+ glm::vec3 norm(0.f, 0.f, 1.f);
+ glm::vec3 p(0.f, 0.f, water_height);
- F32 modelView[16];
- for (U32 i = 0; i < 16; i++)
- {
- modelView[i] = (F32)gGLModelView[i];
- }
+ glm::mat4 mat = get_current_modelview();
+ glm::mat4 invtrans = glm::transpose(glm::inverse(mat));
+ invtrans[0][3] = invtrans[1][3] = invtrans[2][3] = 0.f;
- glh::matrix4f mat(modelView);
- glh::matrix4f invtrans = mat.inverse().transpose();
- invtrans.m[3] = invtrans.m[7] = invtrans.m[11] = 0.f;
- glh::vec3f enorm;
- glh::vec3f ep;
- invtrans.mult_matrix_vec(norm, enorm);
- enorm.normalize();
- mat.mult_matrix_vec(p, ep);
+ glm::vec3 enorm;
+ glm::vec3 ep;
+ enorm = mul_mat4_vec3(invtrans, norm);
+ enorm = glm::normalize(enorm);
+ ep = mul_mat4_vec3(mat, p);
- LLVector4 waterPlane(enorm.v[0], enorm.v[1], enorm.v[2], -ep.dot(enorm));
+ LLVector4 waterPlane(enorm.x, enorm.y, enorm.z, -glm::dot(ep, enorm));
- norm = glh::vec3f(gPipeline.mHeroProbeManager.mMirrorNormal.mV);
- p = glh::vec3f(gPipeline.mHeroProbeManager.mMirrorPosition.mV);
- invtrans.mult_matrix_vec(norm, enorm);
- enorm.normalize();
- mat.mult_matrix_vec(p, ep);
+ norm = glm::make_vec3(gPipeline.mHeroProbeManager.mMirrorNormal.mV);
+ p = glm::make_vec3(gPipeline.mHeroProbeManager.mMirrorPosition.mV);
+ enorm = mul_mat4_vec3(invtrans, norm);
+ enorm = glm::normalize(enorm);
+ ep = mul_mat4_vec3(mat, p);
- LLVector4 mirrorPlane(enorm.v[0], enorm.v[1], enorm.v[2], -ep.dot(enorm));
+ glm::vec4 mirrorPlane(enorm, -glm::dot(ep, enorm));
LLDrawPoolAlpha::sWaterPlane = waterPlane;
shader->uniform4fv(LLShaderMgr::WATER_WATERPLANE, waterPlane.mV);
- shader->uniform4fv(LLShaderMgr::CLIP_PLANE, mirrorPlane.mV);
+ shader->uniform4fv(LLShaderMgr::CLIP_PLANE, glm::value_ptr(mirrorPlane));
LLVector4 light_direction = env.getClampedLightNorm();
if (gPipeline.mHeroProbeManager.isMirrorPass())
diff --git a/indra/newview/llterrainpaintmap.cpp b/indra/newview/llterrainpaintmap.cpp
index 4381d14546..8ccde74c93 100644
--- a/indra/newview/llterrainpaintmap.cpp
+++ b/indra/newview/llterrainpaintmap.cpp
@@ -111,12 +111,12 @@ bool LLTerrainPaintMap::bakeHeightNoiseIntoPBRPaintMapRGB(const LLViewerRegion&
const LLRect texture_rect(0, scratch_target.getHeight(), scratch_target.getWidth(), 0);
glViewport(texture_rect.mLeft, texture_rect.mBottom, texture_rect.getWidth(), texture_rect.getHeight());
// Manually get modelview matrix from camera orientation.
- glh::matrix4f modelview((GLfloat *) OGL_TO_CFR_ROTATION);
+ glm::mat4 modelview(glm::make_mat4((GLfloat *) OGL_TO_CFR_ROTATION));
GLfloat ogl_matrix[16];
camera.getOpenGLTransform(ogl_matrix);
- modelview *= glh::matrix4f(ogl_matrix);
+ modelview *= glm::make_mat4(ogl_matrix);
gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.loadMatrix(modelview.m);
+ gGL.loadMatrix(glm::value_ptr(modelview));
// Override the projection matrix from the camera
gGL.matrixMode(LLRender::MM_PROJECTION);
gGL.pushMatrix();
diff --git a/indra/newview/llviewercamera.cpp b/indra/newview/llviewercamera.cpp
index 766280e145..aa43b2dbad 100644
--- a/indra/newview/llviewercamera.cpp
+++ b/indra/newview/llviewercamera.cpp
@@ -60,28 +60,6 @@ LLTrace::CountStatHandle<> LLViewerCamera::sAngularVelocityStat("camera_angular_
LLViewerCamera::eCameraID LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD;
-//glu pick matrix implementation borrowed from Mesa3D
-glh::matrix4f gl_pick_matrix(GLfloat x, GLfloat y, GLfloat width, GLfloat height, GLint* viewport)
-{
- GLfloat m[16];
- GLfloat sx, sy;
- GLfloat tx, ty;
-
- sx = viewport[2] / width;
- sy = viewport[3] / height;
- tx = (viewport[2] + 2.f * (viewport[0] - x)) / width;
- ty = (viewport[3] + 2.f * (viewport[1] - y)) / height;
-
- #define M(row,col) m[col*4+row]
- M(0,0) = sx; M(0,1) = 0.f; M(0,2) = 0.f; M(0,3) = tx;
- M(1,0) = 0.f; M(1,1) = sy; M(1,2) = 0.f; M(1,3) = ty;
- M(2,0) = 0.f; M(2,1) = 0.f; M(2,2) = 1.f; M(2,3) = 0.f;
- M(3,0) = 0.f; M(3,1) = 0.f; M(3,2) = 0.f; M(3,3) = 1.f;
- #undef M
-
- return glh::matrix4f(m);
-}
-
LLViewerCamera::LLViewerCamera() : LLCamera()
{
calcProjection(getFar());
@@ -204,59 +182,52 @@ void LLViewerCamera::calcProjection(const F32 far_distance) const
//static
void LLViewerCamera::updateFrustumPlanes(LLCamera& camera, bool ortho, bool zflip, bool no_hacks)
{
- GLint* viewport = (GLint*) gGLViewport;
- F64 model[16];
- F64 proj[16];
-
- for (U32 i = 0; i < 16; i++)
- {
- model[i] = (F64) gGLModelView[i];
- proj[i] = (F64) gGLProjection[i];
- }
-
- GLdouble objX,objY,objZ;
+ glm::ivec4 viewport = glm::make_vec4((GLint*) gGLViewport);
+ glm::mat4 model = get_current_modelview();
+ glm::mat4 proj = get_current_projection();
LLVector3 frust[8];
+ glm::vec3 obj;
if (no_hacks)
{
- gluUnProject(viewport[0],viewport[1],0,model,proj,viewport,&objX,&objY,&objZ);
- frust[0].setVec((F32)objX,(F32)objY,(F32)objZ);
- gluUnProject(viewport[0]+viewport[2],viewport[1],0,model,proj,viewport,&objX,&objY,&objZ);
- frust[1].setVec((F32)objX,(F32)objY,(F32)objZ);
- gluUnProject(viewport[0]+viewport[2],viewport[1]+viewport[3],0,model,proj,viewport,&objX,&objY,&objZ);
- frust[2].setVec((F32)objX,(F32)objY,(F32)objZ);
- gluUnProject(viewport[0],viewport[1]+viewport[3],0,model,proj,viewport,&objX,&objY,&objZ);
- frust[3].setVec((F32)objX,(F32)objY,(F32)objZ);
-
- gluUnProject(viewport[0],viewport[1],1,model,proj,viewport,&objX,&objY,&objZ);
- frust[4].setVec((F32)objX,(F32)objY,(F32)objZ);
- gluUnProject(viewport[0]+viewport[2],viewport[1],1,model,proj,viewport,&objX,&objY,&objZ);
- frust[5].setVec((F32)objX,(F32)objY,(F32)objZ);
- gluUnProject(viewport[0]+viewport[2],viewport[1]+viewport[3],1,model,proj,viewport,&objX,&objY,&objZ);
- frust[6].setVec((F32)objX,(F32)objY,(F32)objZ);
- gluUnProject(viewport[0],viewport[1]+viewport[3],1,model,proj,viewport,&objX,&objY,&objZ);
- frust[7].setVec((F32)objX,(F32)objY,(F32)objZ);
+ obj = glm::unProject(glm::vec3(viewport[0], viewport[1], 0), model, proj, viewport);
+ frust[0].setVec(glm::value_ptr(obj));
+ obj = glm::unProject(glm::vec3(viewport[0]+viewport[2],viewport[1],0),model,proj,viewport);
+ frust[1].setVec(glm::value_ptr(obj));
+ obj = glm::unProject(glm::vec3(viewport[0]+viewport[2],viewport[1]+viewport[3],0),model,proj,viewport);
+ frust[2].setVec(glm::value_ptr(obj));
+ obj = glm::unProject(glm::vec3(viewport[0],viewport[1]+viewport[3],0),model,proj,viewport);
+ frust[3].setVec(glm::value_ptr(obj));
+
+ obj = glm::unProject(glm::vec3(viewport[0],viewport[1],1),model,proj,viewport);
+ frust[4].setVec(glm::value_ptr(obj));
+ obj = glm::unProject(glm::vec3(viewport[0]+viewport[2],viewport[1],1),model,proj,viewport);
+ frust[5].setVec(glm::value_ptr(obj));
+ obj = glm::unProject(glm::vec3(viewport[0]+viewport[2],viewport[1]+viewport[3],1),model,proj,viewport);
+ frust[6].setVec(glm::value_ptr(obj));
+ obj = glm::unProject(glm::vec3(viewport[0],viewport[1]+viewport[3],1),model,proj,viewport);
+ frust[7].setVec(glm::value_ptr(obj));
}
else if (zflip)
{
- gluUnProject(viewport[0],viewport[1]+viewport[3],0,model,proj,viewport,&objX,&objY,&objZ);
- frust[0].setVec((F32)objX,(F32)objY,(F32)objZ);
- gluUnProject(viewport[0]+viewport[2],viewport[1]+viewport[3],0,model,proj,viewport,&objX,&objY,&objZ);
- frust[1].setVec((F32)objX,(F32)objY,(F32)objZ);
- gluUnProject(viewport[0]+viewport[2],viewport[1],0,model,proj,viewport,&objX,&objY,&objZ);
- frust[2].setVec((F32)objX,(F32)objY,(F32)objZ);
- gluUnProject(viewport[0],viewport[1],0,model,proj,viewport,&objX,&objY,&objZ);
- frust[3].setVec((F32)objX,(F32)objY,(F32)objZ);
-
- gluUnProject(viewport[0],viewport[1]+viewport[3],1,model,proj,viewport,&objX,&objY,&objZ);
- frust[4].setVec((F32)objX,(F32)objY,(F32)objZ);
- gluUnProject(viewport[0]+viewport[2],viewport[1]+viewport[3],1,model,proj,viewport,&objX,&objY,&objZ);
- frust[5].setVec((F32)objX,(F32)objY,(F32)objZ);
- gluUnProject(viewport[0]+viewport[2],viewport[1],1,model,proj,viewport,&objX,&objY,&objZ);
- frust[6].setVec((F32)objX,(F32)objY,(F32)objZ);
- gluUnProject(viewport[0],viewport[1],1,model,proj,viewport,&objX,&objY,&objZ);
- frust[7].setVec((F32)objX,(F32)objY,(F32)objZ);
+ obj = glm::unProject(glm::vec3(viewport[0],viewport[1]+viewport[3],0),model,proj,viewport);
+ frust[0].setVec(glm::value_ptr(obj));
+ obj = glm::unProject(glm::vec3(viewport[0]+viewport[2],viewport[1]+viewport[3],0),model,proj,viewport);
+ frust[1].setVec(glm::value_ptr(obj));
+ obj = glm::unProject(glm::vec3(viewport[0]+viewport[2],viewport[1],0),model,proj,viewport);
+ frust[2].setVec(glm::value_ptr(obj));
+ obj = glm::unProject(glm::vec3(viewport[0],viewport[1],0),model,proj,viewport);
+ frust[3].setVec(glm::value_ptr(obj));
+
+ obj = glm::unProject(glm::vec3(viewport[0],viewport[1]+viewport[3],1),model,proj,viewport);
+ frust[4].setVec(glm::value_ptr(obj));
+ obj = glm::unProject(glm::vec3(viewport[0]+viewport[2],viewport[1]+viewport[3],1),model,proj,viewport);
+ frust[5].setVec(glm::value_ptr(obj));
+ obj = glm::unProject(glm::vec3(viewport[0]+viewport[2],viewport[1],1),model,proj,viewport);
+ frust[6].setVec(glm::value_ptr(obj));
+ obj = glm::unProject(glm::vec3(viewport[0],viewport[1],1),model,proj,viewport);
+ frust[7].setVec(glm::value_ptr(obj));
for (U32 i = 0; i < 4; i++)
{
@@ -267,14 +238,14 @@ void LLViewerCamera::updateFrustumPlanes(LLCamera& camera, bool ortho, bool zfli
}
else
{
- gluUnProject(viewport[0],viewport[1],0,model,proj,viewport,&objX,&objY,&objZ);
- frust[0].setVec((F32)objX,(F32)objY,(F32)objZ);
- gluUnProject(viewport[0]+viewport[2],viewport[1],0,model,proj,viewport,&objX,&objY,&objZ);
- frust[1].setVec((F32)objX,(F32)objY,(F32)objZ);
- gluUnProject(viewport[0]+viewport[2],viewport[1]+viewport[3],0,model,proj,viewport,&objX,&objY,&objZ);
- frust[2].setVec((F32)objX,(F32)objY,(F32)objZ);
- gluUnProject(viewport[0],viewport[1]+viewport[3],0,model,proj,viewport,&objX,&objY,&objZ);
- frust[3].setVec((F32)objX,(F32)objY,(F32)objZ);
+ obj = glm::unProject(glm::vec3(viewport[0],viewport[1],0),model,proj,viewport);
+ frust[0].setVec(glm::value_ptr(obj));
+ obj = glm::unProject(glm::vec3(viewport[0]+viewport[2],viewport[1],0),model,proj,viewport);
+ frust[1].setVec(glm::value_ptr(obj));
+ obj = glm::unProject(glm::vec3(viewport[0]+viewport[2],viewport[1]+viewport[3],0),model,proj,viewport);
+ frust[2].setVec(glm::value_ptr(obj));
+ obj = glm::unProject(glm::vec3(viewport[0],viewport[1]+viewport[3],0),model,proj,viewport);
+ frust[3].setVec(glm::value_ptr(obj));
if (ortho)
{
@@ -304,7 +275,7 @@ void LLViewerCamera::setPerspective(bool for_selection,
F32 z_near, F32 z_far)
{
F32 fov_y, aspect;
- fov_y = RAD_TO_DEG * getView();
+ fov_y = getView();
bool z_default_far = false;
if (z_far <= 0)
{
@@ -321,20 +292,19 @@ void LLViewerCamera::setPerspective(bool for_selection,
gGL.matrixMode(LLRender::MM_PROJECTION);
gGL.loadIdentity();
- glh::matrix4f proj_mat;
+ glm::mat4 proj_mat = glm::identity<glm::mat4>();
if (for_selection)
{
// make a tiny little viewport
// anything drawn into this viewport will be "selected"
- GLint viewport[4];
- viewport[0] = gViewerWindow->getWorldViewRectRaw().mLeft;
- viewport[1] = gViewerWindow->getWorldViewRectRaw().mBottom;
- viewport[2] = gViewerWindow->getWorldViewRectRaw().getWidth();
- viewport[3] = gViewerWindow->getWorldViewRectRaw().getHeight();
+ glm::ivec4 viewport(gViewerWindow->getWorldViewRectRaw().mLeft,
+ gViewerWindow->getWorldViewRectRaw().mBottom,
+ gViewerWindow->getWorldViewRectRaw().getWidth(),
+ gViewerWindow->getWorldViewRectRaw().getHeight());
- proj_mat = gl_pick_matrix(x+width/2.f, y_from_bot+height/2.f, (GLfloat) width, (GLfloat) height, viewport);
+ proj_mat = glm::pickMatrix(glm::vec2(x + width / 2.f, y_from_bot + height / 2.f), glm::vec2((GLfloat)width, (GLfloat)height), viewport);
if (limit_select_distance)
{
@@ -365,37 +335,35 @@ void LLViewerCamera::setPerspective(bool for_selection,
float offset = mZoomFactor - 1.f;
int pos_y = mZoomSubregion / llceil(mZoomFactor);
int pos_x = mZoomSubregion - (pos_y*llceil(mZoomFactor));
- glh::matrix4f translate;
- translate.set_translate(glh::vec3f(offset - (F32)pos_x * 2.f, offset - (F32)pos_y * 2.f, 0.f));
- glh::matrix4f scale;
- scale.set_scale(glh::vec3f(mZoomFactor, mZoomFactor, 1.f));
- proj_mat = scale*proj_mat;
- proj_mat = translate*proj_mat;
+ glm::mat4 translate;
+ translate = glm::translate(glm::vec3(offset - (F32)pos_x * 2.f, offset - (F32)pos_y * 2.f, 0.f));
+ glm::mat4 scale;
+ scale = glm::scale(glm::vec3(mZoomFactor, mZoomFactor, 1.f));
+
+ proj_mat = scale * proj_mat;
+ proj_mat = translate * proj_mat;
}
calcProjection(z_far); // Update the projection matrix cache
- proj_mat *= gl_perspective(fov_y,aspect,z_near,z_far);
+ proj_mat *= glm::perspective(fov_y,aspect,z_near,z_far);
- gGL.loadMatrix(proj_mat.m);
+ gGL.loadMatrix(glm::value_ptr(proj_mat));
- for (U32 i = 0; i < 16; i++)
- {
- gGLProjection[i] = proj_mat.m[i];
- }
+ set_current_projection(proj_mat);
gGL.matrixMode(LLRender::MM_MODELVIEW);
- glh::matrix4f modelview((GLfloat*) OGL_TO_CFR_ROTATION);
+ glm::mat4 modelview(glm::make_mat4((GLfloat*) OGL_TO_CFR_ROTATION));
GLfloat ogl_matrix[16];
getOpenGLTransform(ogl_matrix);
- modelview *= glh::matrix4f(ogl_matrix);
+ modelview *= glm::make_mat4(ogl_matrix);
- gGL.loadMatrix(modelview.m);
+ gGL.loadMatrix(glm::value_ptr(modelview));
if (for_selection && (width > 1 || height > 1))
{
@@ -413,10 +381,7 @@ void LLViewerCamera::setPerspective(bool for_selection,
if (!for_selection && mZoomFactor == 1.f)
{
// Save GL matrices for access elsewhere in code, especially project_world_to_screen
- for (U32 i = 0; i < 16; i++)
- {
- gGLModelView[i] = modelview.m[i];
- }
+ set_current_modelview(modelview);
}
updateFrustumPlanes(*this);
@@ -427,24 +392,8 @@ void LLViewerCamera::setPerspective(bool for_selection,
// screen coordinates to the agent's region.
void LLViewerCamera::projectScreenToPosAgent(const S32 screen_x, const S32 screen_y, LLVector3* pos_agent) const
{
- GLdouble x, y, z;
-
- F64 mdlv[16];
- F64 proj[16];
-
- for (U32 i = 0; i < 16; i++)
- {
- mdlv[i] = (F64) gGLModelView[i];
- proj[i] = (F64) gGLProjection[i];
- }
-
- gluUnProject(
- GLdouble(screen_x), GLdouble(screen_y), 0.0,
- mdlv, proj, (GLint*)gGLViewport,
- &x,
- &y,
- &z );
- pos_agent->setVec( (F32)x, (F32)y, (F32)z );
+ glm::vec3 agent_coord = glm::unProject(glm::vec3(screen_x, screen_y, 0.f), get_current_modelview(), get_current_projection(), glm::make_vec4(gGLViewport));
+ pos_agent->setVec( (F32)agent_coord.x, (F32)agent_coord.y, (F32)agent_coord.z );
}
// Uses the last GL matrices set in set_perspective to project a point from
@@ -453,7 +402,6 @@ void LLViewerCamera::projectScreenToPosAgent(const S32 screen_x, const S32 scree
bool LLViewerCamera::projectPosAgentToScreen(const LLVector3 &pos_agent, LLCoordGL &out_point, const bool clamp) const
{
bool in_front = true;
- GLdouble x, y, z; // object's window coords, GL-style
LLVector3 dir_to_point = pos_agent - getOrigin();
dir_to_point /= dir_to_point.magVec();
@@ -471,35 +419,20 @@ bool LLViewerCamera::projectPosAgentToScreen(const LLVector3 &pos_agent, LLCoord
}
LLRect world_view_rect = gViewerWindow->getWorldViewRectRaw();
- S32 viewport[4];
- viewport[0] = world_view_rect.mLeft;
- viewport[1] = world_view_rect.mBottom;
- viewport[2] = world_view_rect.getWidth();
- viewport[3] = world_view_rect.getHeight();
-
- F64 mdlv[16];
- F64 proj[16];
-
- for (U32 i = 0; i < 16; i++)
- {
- mdlv[i] = (F64) gGLModelView[i];
- proj[i] = (F64) gGLProjection[i];
- }
+ glm::ivec4 viewport(world_view_rect.mLeft, world_view_rect.mBottom, world_view_rect.getWidth(), world_view_rect.getHeight());
+ glm::vec3 win_coord = glm::project(glm::make_vec3(pos_agent.mV), get_current_modelview(), get_current_projection(), viewport);
- if (GL_TRUE == gluProject(pos_agent.mV[VX], pos_agent.mV[VY], pos_agent.mV[VZ],
- mdlv, proj, (GLint*)viewport,
- &x, &y, &z))
{
// convert screen coordinates to virtual UI coordinates
- x /= gViewerWindow->getDisplayScale().mV[VX];
- y /= gViewerWindow->getDisplayScale().mV[VY];
+ win_coord.x /= gViewerWindow->getDisplayScale().mV[VX];
+ win_coord.y /= gViewerWindow->getDisplayScale().mV[VY];
// should now have the x,y coords of grab_point in screen space
LLRect world_rect = gViewerWindow->getWorldViewRectScaled();
// convert to pixel coordinates
- S32 int_x = lltrunc(x);
- S32 int_y = lltrunc(y);
+ S32 int_x = lltrunc(win_coord.x);
+ S32 int_y = lltrunc(win_coord.y);
bool valid = true;
@@ -561,10 +494,6 @@ bool LLViewerCamera::projectPosAgentToScreen(const LLVector3 &pos_agent, LLCoord
return in_front && valid;
}
}
- else
- {
- return false;
- }
}
// Uses the last GL matrices set in set_perspective to project a point from
@@ -583,49 +512,33 @@ bool LLViewerCamera::projectPosAgentToScreenEdge(const LLVector3 &pos_agent,
}
LLRect world_view_rect = gViewerWindow->getWorldViewRectRaw();
- S32 viewport[4];
- viewport[0] = world_view_rect.mLeft;
- viewport[1] = world_view_rect.mBottom;
- viewport[2] = world_view_rect.getWidth();
- viewport[3] = world_view_rect.getHeight();
- GLdouble x, y, z; // object's window coords, GL-style
- F64 mdlv[16];
- F64 proj[16];
-
- for (U32 i = 0; i < 16; i++)
- {
- mdlv[i] = (F64) gGLModelView[i];
- proj[i] = (F64) gGLProjection[i];
- }
+ glm::ivec4 viewport(world_view_rect.mLeft, world_view_rect.mBottom, world_view_rect.getWidth(), world_view_rect.getHeight());
+ glm::vec3 win_coord = glm::project(glm::make_vec3(pos_agent.mV), get_current_modelview(), get_current_projection(), viewport);
- if (GL_TRUE == gluProject(pos_agent.mV[VX], pos_agent.mV[VY],
- pos_agent.mV[VZ], mdlv,
- proj, (GLint*)viewport,
- &x, &y, &z))
{
- x /= gViewerWindow->getDisplayScale().mV[VX];
- y /= gViewerWindow->getDisplayScale().mV[VY];
+ win_coord.x /= gViewerWindow->getDisplayScale().mV[VX];
+ win_coord.y /= gViewerWindow->getDisplayScale().mV[VY];
// should now have the x,y coords of grab_point in screen space
const LLRect& world_rect = gViewerWindow->getWorldViewRectScaled();
// ...sanity check
- S32 int_x = lltrunc(x);
- S32 int_y = lltrunc(y);
+ S32 int_x = lltrunc(win_coord.x);
+ S32 int_y = lltrunc(win_coord.y);
// find the center
- GLdouble center_x = (GLdouble)world_rect.getCenterX();
- GLdouble center_y = (GLdouble)world_rect.getCenterY();
+ F32 center_x = (F32)world_rect.getCenterX();
+ F32 center_y = (F32)world_rect.getCenterY();
- if (x == center_x && y == center_y)
+ if (win_coord.x == center_x && win_coord.y == center_y)
{
// can't project to edge from exact center
return false;
}
// find the line from center to local
- GLdouble line_x = x - center_x;
- GLdouble line_y = y - center_y;
+ F32 line_x = win_coord.x - center_x;
+ F32 line_y = win_coord.y - center_y;
int_x = lltrunc(center_x);
int_y = lltrunc(center_y);
@@ -646,11 +559,11 @@ bool LLViewerCamera::projectPosAgentToScreenEdge(const LLVector3 &pos_agent,
else if (0 == world_rect.getWidth())
{
// the diagonal slope of the view is undefined
- if (y < world_rect.mBottom)
+ if (win_coord.y < world_rect.mBottom)
{
int_y = world_rect.mBottom;
}
- else if ( y > world_rect.mTop)
+ else if (win_coord.y > world_rect.mTop)
{
int_y = world_rect.mTop;
}
@@ -672,7 +585,7 @@ bool LLViewerCamera::projectPosAgentToScreenEdge(const LLVector3 &pos_agent,
// top
int_y = world_rect.mTop;
}
- int_x = lltrunc(((GLdouble)int_y - center_y) / line_slope + center_x);
+ int_x = lltrunc(((F32)int_y - center_y) / line_slope + center_x);
}
else if (fabs(line_slope) < rect_slope)
{
@@ -686,7 +599,7 @@ bool LLViewerCamera::projectPosAgentToScreenEdge(const LLVector3 &pos_agent,
// right
int_x = world_rect.mRight;
}
- int_y = lltrunc(((GLdouble)int_x - center_x) * line_slope + center_y);
+ int_y = lltrunc(((F32)int_x - center_x) * line_slope + center_y);
}
else
{
diff --git a/indra/newview/llviewerdisplay.cpp b/indra/newview/llviewerdisplay.cpp
index 9bd0973cc0..301ea5c5f6 100644
--- a/indra/newview/llviewerdisplay.cpp
+++ b/indra/newview/llviewerdisplay.cpp
@@ -81,6 +81,10 @@
#include "llenvironment.h"
#include "llperfstats.h"
+#include <glm/glm.hpp>
+#include <glm/gtc/matrix_transform.hpp>
+#include <glm/gtc/type_ptr.hpp>
+
extern LLPointer<LLViewerTexture> gStartTexture;
extern bool gShiftFrame;
@@ -760,8 +764,8 @@ void display(bool rebuild, F32 zoom_factor, int subfield, bool for_snapshot)
LLGLState::checkStates();
- glh::matrix4f proj = get_current_projection();
- glh::matrix4f mod = get_current_modelview();
+ glm::mat4 proj = get_current_projection();
+ glm::mat4 mod = get_current_modelview();
glViewport(0,0,512,512);
LLVOAvatar::updateImpostors();
@@ -769,9 +773,9 @@ void display(bool rebuild, F32 zoom_factor, int subfield, bool for_snapshot)
set_current_projection(proj);
set_current_modelview(mod);
gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.loadMatrix(proj.m);
+ gGL.loadMatrix(glm::value_ptr(proj));
gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.loadMatrix(mod.m);
+ gGL.loadMatrix(glm::value_ptr(mod));
gViewerWindow->setup3DViewport();
LLGLState::checkStates();
@@ -1148,8 +1152,8 @@ void render_hud_attachments()
gGL.matrixMode(LLRender::MM_MODELVIEW);
gGL.pushMatrix();
- glh::matrix4f current_proj = get_current_projection();
- glh::matrix4f current_mod = get_current_modelview();
+ glm::mat4 current_proj = get_current_projection();
+ glm::mat4 current_mod = get_current_modelview();
// clamp target zoom level to reasonable values
gAgentCamera.mHUDTargetZoom = llclamp(gAgentCamera.mHUDTargetZoom, 0.1f, 1.f);
@@ -1273,7 +1277,7 @@ LLRect get_whole_screen_region()
return whole_screen;
}
-bool get_hud_matrices(const LLRect& screen_region, glh::matrix4f &proj, glh::matrix4f &model)
+bool get_hud_matrices(const LLRect& screen_region, glm::mat4 &proj, glm::mat4&model)
{
if (isAgentAvatarValid() && gAgentAvatarp->hasHUDAttachment())
{
@@ -1281,28 +1285,29 @@ bool get_hud_matrices(const LLRect& screen_region, glh::matrix4f &proj, glh::mat
LLBBox hud_bbox = gAgentAvatarp->getHUDBBox();
F32 hud_depth = llmax(1.f, hud_bbox.getExtentLocal().mV[VX] * 1.1f);
- proj = gl_ortho(-0.5f * LLViewerCamera::getInstance()->getAspect(), 0.5f * LLViewerCamera::getInstance()->getAspect(), -0.5f, 0.5f, 0.f, hud_depth);
- proj.element(2,2) = -0.01f;
+ proj = glm::ortho(-0.5f * LLViewerCamera::getInstance()->getAspect(), 0.5f * LLViewerCamera::getInstance()->getAspect(), -0.5f, 0.5f, 0.f, hud_depth);
+ proj[2][2] = -0.01f;
F32 aspect_ratio = LLViewerCamera::getInstance()->getAspect();
- glh::matrix4f mat;
F32 scale_x = (F32)gViewerWindow->getWorldViewWidthScaled() / (F32)screen_region.getWidth();
F32 scale_y = (F32)gViewerWindow->getWorldViewHeightScaled() / (F32)screen_region.getHeight();
- mat.set_scale(glh::vec3f(scale_x, scale_y, 1.f));
- mat.set_translate(
- glh::vec3f(clamp_rescale((F32)(screen_region.getCenterX() - screen_region.mLeft), 0.f, (F32)gViewerWindow->getWorldViewWidthScaled(), 0.5f * scale_x * aspect_ratio, -0.5f * scale_x * aspect_ratio),
- clamp_rescale((F32)(screen_region.getCenterY() - screen_region.mBottom), 0.f, (F32)gViewerWindow->getWorldViewHeightScaled(), 0.5f * scale_y, -0.5f * scale_y),
- 0.f));
- proj *= mat;
-
- glh::matrix4f tmp_model((GLfloat*) OGL_TO_CFR_ROTATION);
- mat.set_scale(glh::vec3f(zoom_level, zoom_level, zoom_level));
- mat.set_translate(glh::vec3f(-hud_bbox.getCenterLocal().mV[VX] + (hud_depth * 0.5f), 0.f, 0.f));
+ glm::mat4 mat = glm::identity<glm::mat4>();
+ mat = glm::translate(mat,
+ glm::vec3(clamp_rescale((F32)(screen_region.getCenterX() - screen_region.mLeft), 0.f, (F32)gViewerWindow->getWorldViewWidthScaled(), 0.5f * scale_x * aspect_ratio, -0.5f * scale_x * aspect_ratio),
+ clamp_rescale((F32)(screen_region.getCenterY() - screen_region.mBottom), 0.f, (F32)gViewerWindow->getWorldViewHeightScaled(), 0.5f * scale_y, -0.5f * scale_y),
+ 0.f));
+ mat = glm::scale(mat, glm::vec3(scale_x, scale_y, 1.f));
+ proj *= mat;
+ glm::mat4 tmp_model = glm::make_mat4(OGL_TO_CFR_ROTATION);
+ mat = glm::identity<glm::mat4>();
+ mat = glm::translate(mat, glm::vec3(-hud_bbox.getCenterLocal().mV[VX] + (hud_depth * 0.5f), 0.f, 0.f));
+ mat = glm::scale(mat, glm::vec3(zoom_level));
tmp_model *= mat;
model = tmp_model;
+
return true;
}
else
@@ -1311,7 +1316,7 @@ bool get_hud_matrices(const LLRect& screen_region, glh::matrix4f &proj, glh::mat
}
}
-bool get_hud_matrices(glh::matrix4f &proj, glh::matrix4f &model)
+bool get_hud_matrices(glm::mat4 &proj, glm::mat4&model)
{
LLRect whole_screen = get_whole_screen_region();
return get_hud_matrices(whole_screen, proj, model);
@@ -1325,17 +1330,17 @@ bool setup_hud_matrices()
bool setup_hud_matrices(const LLRect& screen_region)
{
- glh::matrix4f proj, model;
+ glm::mat4 proj, model;
bool result = get_hud_matrices(screen_region, proj, model);
if (!result) return result;
// set up transform to keep HUD objects in front of camera
gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.loadMatrix(proj.m);
+ gGL.loadMatrix(glm::value_ptr(proj));
set_current_projection(proj);
gGL.matrixMode(LLRender::MM_MODELVIEW);
- gGL.loadMatrix(model.m);
+ gGL.loadMatrix(glm::value_ptr(model));
set_current_modelview(model);
return true;
}
@@ -1347,13 +1352,13 @@ void render_ui(F32 zoom_factor, int subfield)
LL_PROFILE_GPU_ZONE("ui");
LLGLState::checkStates();
- glh::matrix4f saved_view = get_current_modelview();
+ glm::mat4 saved_view = get_current_modelview();
if (!gSnapshot)
{
gGL.pushMatrix();
gGL.loadMatrix(gGLLastModelView);
- set_current_modelview(copy_matrix(gGLLastModelView));
+ set_current_modelview(glm::make_mat4(gGLLastModelView));
}
if(LLSceneMonitor::getInstance()->needsUpdate())
diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp
index 8ea8fbf905..1be80a5e02 100644
--- a/indra/newview/llviewerwindow.cpp
+++ b/indra/newview/llviewerwindow.cpp
@@ -5358,8 +5358,8 @@ bool LLViewerWindow::cubeSnapshot(const LLVector3& origin, LLCubeMapArray* cubea
LLViewerCamera* camera = LLViewerCamera::getInstance();
LLViewerCamera saved_camera = LLViewerCamera::instance();
- glh::matrix4f saved_proj = get_current_projection();
- glh::matrix4f saved_mod = get_current_modelview();
+ glm::mat4 saved_proj = get_current_projection();
+ glm::mat4 saved_mod = get_current_modelview();
// camera constants for the square, cube map capture image
camera->setAspect(1.0); // must set aspect ratio first to avoid undesirable clamping of vertical FoV
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index 929a29829d..1b52e4f870 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -1847,36 +1847,36 @@ bool LLVOAvatar::lineSegmentIntersect(const LLVector4a& start, const LLVector4a&
{
mCollisionVolumes[i].updateWorldMatrix();
- glh::matrix4f mat((F32*) mCollisionVolumes[i].getXform()->getWorldMatrix().mMatrix);
- glh::matrix4f inverse = mat.inverse();
- glh::matrix4f norm_mat = inverse.transpose();
+ glm::mat4 mat(glm::make_mat4((F32*) mCollisionVolumes[i].getXform()->getWorldMatrix().mMatrix));
+ glm::mat4 inverse = glm::inverse(mat);
+ glm::mat4 norm_mat = glm::transpose(inverse);
- glh::vec3f p1(start.getF32ptr());
- glh::vec3f p2(end.getF32ptr());
+ glm::vec3 p1(glm::make_vec3(start.getF32ptr()));
+ glm::vec3 p2(glm::make_vec3(end.getF32ptr()));
- inverse.mult_matrix_vec(p1);
- inverse.mult_matrix_vec(p2);
+ p1 = mul_mat4_vec3(inverse, p1);
+ p2 = mul_mat4_vec3(inverse, p2);
LLVector3 position;
LLVector3 norm;
- if (linesegment_sphere(LLVector3(p1.v), LLVector3(p2.v), LLVector3(0,0,0), 1.f, position, norm))
+ if (linesegment_sphere(LLVector3(glm::value_ptr(p1)), LLVector3(glm::value_ptr(p2)), LLVector3(0,0,0), 1.f, position, norm))
{
- glh::vec3f res_pos(position.mV);
- mat.mult_matrix_vec(res_pos);
+ glm::vec3 res_pos(glm::make_vec3(position.mV));
+ res_pos = mul_mat4_vec3(mat, res_pos);
- norm.normalize();
- glh::vec3f res_norm(norm.mV);
- norm_mat.mult_matrix_dir(res_norm);
+ glm::vec3 res_norm(glm::make_vec3(norm.mV));
+ res_norm = glm::normalize(res_norm);
+ res_norm = glm::mat3(norm_mat) * res_norm;
if (intersection)
{
- intersection->load3(res_pos.v);
+ intersection->load3(glm::value_ptr(res_pos));
}
if (normal)
{
- normal->load3(res_norm.v);
+ normal->load3(glm::value_ptr(res_norm));
}
return true;
diff --git a/indra/newview/llvotree.cpp b/indra/newview/llvotree.cpp
index d982592ee7..14b4273b02 100644
--- a/indra/newview/llvotree.cpp
+++ b/indra/newview/llvotree.cpp
@@ -1047,10 +1047,9 @@ void LLVOTree::genBranchPipeline(LLStrider<LLVector3>& vertices,
scale_mat.mMatrix[2][2] = scale*length;
scale_mat *= matrix;
- glh::matrix4f norm((F32*) scale_mat.mMatrix);
- LLMatrix4 norm_mat = LLMatrix4(norm.inverse().transpose().m);
+ glm::mat4 norm(glm::make_mat4((F32*) scale_mat.mMatrix));
+ LLMatrix4 norm_mat = LLMatrix4(glm::value_ptr(glm::transpose(glm::inverse(norm))));
- norm_mat.invert();
appendMesh(vertices, normals, tex_coords, colors, indices, index_offset, scale_mat, norm_mat,
sLODVertexOffset[trunk_LOD], sLODVertexCount[trunk_LOD], sLODIndexCount[trunk_LOD], sLODIndexOffset[trunk_LOD]);
}
@@ -1097,8 +1096,8 @@ void LLVOTree::genBranchPipeline(LLStrider<LLVector3>& vertices,
scale_mat *= matrix;
- glh::matrix4f norm((F32*) scale_mat.mMatrix);
- LLMatrix4 norm_mat = LLMatrix4(norm.inverse().transpose().m);
+ glm::mat4 norm(glm::make_mat4((F32*)scale_mat.mMatrix));
+ LLMatrix4 norm_mat = LLMatrix4(glm::value_ptr(glm::transpose(glm::inverse(norm))));
appendMesh(vertices, normals, tex_coords, colors, indices, index_offset, scale_mat, norm_mat, 0, LEAF_VERTICES, LEAF_INDICES, 0);
}
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index f37257feb0..081f4a3564 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -3894,20 +3894,17 @@ void LLPipeline::renderGeomDeferred(LLCamera& camera, bool do_occlusion)
if (&camera == LLViewerCamera::getInstance())
{ // a bit hacky, this is the start of the main render frame, figure out delta between last modelview matrix and
// current modelview matrix
- glh::matrix4f last_modelview(gGLLastModelView);
- glh::matrix4f cur_modelview(gGLModelView);
+ glm::mat4 last_modelview = get_last_modelview();
+ glm::mat4 cur_modelview = get_current_modelview();
// goal is to have a matrix here that goes from the last frame's camera space to the current frame's camera space
- glh::matrix4f m = last_modelview.inverse(); // last camera space to world space
- m.mult_left(cur_modelview); // world space to camera space
+ glm::mat4 m = glm::inverse(last_modelview); // last camera space to world space
+ m = cur_modelview * m; // world space to camera space
- glh::matrix4f n = m.inverse();
+ glm::mat4 n = glm::inverse(m);
- for (U32 i = 0; i < 16; ++i)
- {
- gGLDeltaModelView[i] = m.m[i];
- gGLInverseDeltaModelView[i] = n.m[i];
- }
+ gGLDeltaModelView = m;
+ gGLInverseDeltaModelView = n;
}
bool occlude = LLPipeline::sUseOcclusion > 1 && do_occlusion && !LLGLSLShader::sProfileEnabled;
@@ -8074,7 +8071,7 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_
if (sReflectionRender && !shader.getUniformLocation(LLShaderMgr::MODELVIEW_MATRIX))
{
- shader.uniformMatrix4fv(LLShaderMgr::MODELVIEW_MATRIX, 1, false, mReflectionModelView.m);
+ shader.uniformMatrix4fv(LLShaderMgr::MODELVIEW_MATRIX, 1, false, glm::value_ptr(mReflectionModelView));
}
channel = shader.enableTexture(LLShaderMgr::DEFERRED_NOISE);
@@ -8111,12 +8108,12 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_
F32 mat[16*6];
for (U32 i = 0; i < 16; i++)
{
- mat[i] = mSunShadowMatrix[0].m[i];
- mat[i+16] = mSunShadowMatrix[1].m[i];
- mat[i+32] = mSunShadowMatrix[2].m[i];
- mat[i+48] = mSunShadowMatrix[3].m[i];
- mat[i+64] = mSunShadowMatrix[4].m[i];
- mat[i+80] = mSunShadowMatrix[5].m[i];
+ mat[i] = glm::value_ptr(mSunShadowMatrix[0])[i];
+ mat[i+16] = glm::value_ptr(mSunShadowMatrix[1])[i];
+ mat[i+32] = glm::value_ptr(mSunShadowMatrix[2])[i];
+ mat[i+48] = glm::value_ptr(mSunShadowMatrix[3])[i];
+ mat[i+64] = glm::value_ptr(mSunShadowMatrix[4])[i];
+ mat[i+80] = glm::value_ptr(mSunShadowMatrix[5])[i];
}
shader.uniformMatrix4fv(LLShaderMgr::DEFERRED_SHADOW_MATRIX, 6, false, mat);
@@ -8222,15 +8219,15 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_
shader.uniform1f(LLShaderMgr::DEFERRED_DEPTH_CUTOFF, RenderEdgeDepthCutoff);
shader.uniform1f(LLShaderMgr::DEFERRED_NORM_CUTOFF, RenderEdgeNormCutoff);
- shader.uniformMatrix4fv(LLShaderMgr::MODELVIEW_DELTA_MATRIX, 1, GL_FALSE, gGLDeltaModelView);
- shader.uniformMatrix4fv(LLShaderMgr::INVERSE_MODELVIEW_DELTA_MATRIX, 1, GL_FALSE, gGLInverseDeltaModelView);
+ shader.uniformMatrix4fv(LLShaderMgr::MODELVIEW_DELTA_MATRIX, 1, GL_FALSE, glm::value_ptr(gGLDeltaModelView));
+ shader.uniformMatrix4fv(LLShaderMgr::INVERSE_MODELVIEW_DELTA_MATRIX, 1, GL_FALSE, glm::value_ptr(gGLInverseDeltaModelView));
shader.uniform1i(LLShaderMgr::CUBE_SNAPSHOT, gCubeSnapshot ? 1 : 0);
if (shader.getUniformLocation(LLShaderMgr::DEFERRED_NORM_MATRIX) >= 0)
{
- glh::matrix4f norm_mat = get_current_modelview().inverse().transpose();
- shader.uniformMatrix4fv(LLShaderMgr::DEFERRED_NORM_MATRIX, 1, false, norm_mat.m);
+ glm::mat4 norm_mat = glm::transpose(glm::inverse(get_current_modelview()));
+ shader.uniformMatrix4fv(LLShaderMgr::DEFERRED_NORM_MATRIX, 1, false, glm::value_ptr(norm_mat));
}
// auto adjust legacy sun color if needed
@@ -8304,17 +8301,17 @@ void LLPipeline::renderDeferredLighting()
LLGLEnable cull(GL_CULL_FACE);
LLGLEnable blend(GL_BLEND);
- glh::matrix4f mat = copy_matrix(gGLModelView);
+ glm::mat4 mat = get_current_modelview();
setupHWLights(); // to set mSun/MoonDir;
- glh::vec4f tc(mSunDir.mV);
- mat.mult_matrix_vec(tc);
- mTransformedSunDir.set(tc.v);
+ glm::vec4 tc(glm::make_vec4(mSunDir.mV));
+ tc = mat * tc;
+ mTransformedSunDir.set(glm::value_ptr(tc));
- glh::vec4f tc_moon(mMoonDir.mV);
- mat.mult_matrix_vec(tc_moon);
- mTransformedMoonDir.set(tc_moon.v);
+ glm::vec4 tc_moon(glm::make_vec4(mMoonDir.mV));
+ tc_moon = mat * tc_moon;
+ mTransformedMoonDir.set(glm::value_ptr(tc_moon));
if ((RenderDeferredSSAO && !gCubeSnapshot) || RenderShadowDetail > 0)
{
@@ -8330,26 +8327,6 @@ void LLPipeline::renderDeferredLighting()
deferred_light_target->clear(GL_COLOR_BUFFER_BIT);
glClearColor(0, 0, 0, 0);
- glh::matrix4f inv_trans = get_current_modelview().inverse().transpose();
-
- const U32 slice = 32;
- F32 offset[slice * 3];
- for (U32 i = 0; i < 4; i++)
- {
- for (U32 j = 0; j < 8; j++)
- {
- glh::vec3f v;
- v.set_value(sinf(6.284f / 8 * j), cosf(6.284f / 8 * j), -(F32) i);
- v.normalize();
- inv_trans.mult_matrix_vec(v);
- v.normalize();
- offset[(i * 8 + j) * 3 + 0] = v.v[0];
- offset[(i * 8 + j) * 3 + 1] = v.v[2];
- offset[(i * 8 + j) * 3 + 2] = v.v[1];
- }
- }
-
- sun_shader.uniform3fv(sOffset, slice, offset);
sun_shader.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES,
(GLfloat)deferred_light_target->getWidth(),
(GLfloat)deferred_light_target->getHeight());
@@ -8582,10 +8559,10 @@ void LLPipeline::renderDeferredLighting()
continue;
}
- glh::vec3f tc(c);
- mat.mult_matrix_vec(tc);
+ glm::vec3 tc(glm::make_vec3(c));
+ tc = mul_mat4_vec3(mat, tc);
- fullscreen_lights.push_back(LLVector4(tc.v[0], tc.v[1], tc.v[2], s));
+ fullscreen_lights.push_back(LLVector4(tc.x, tc.y, tc.z, s));
light_colors.push_back(LLVector4(col.mV[0], col.mV[1], col.mV[2], volume->getLightFalloff(DEFERRED_LIGHT_FALLOFF)));
}
}
@@ -8692,15 +8669,15 @@ void LLPipeline::renderDeferredLighting()
sVisibleLightCount++;
- glh::vec3f tc(c);
- mat.mult_matrix_vec(tc);
+ glm::vec3 tc(glm::make_vec3(c));
+ tc = mul_mat4_vec3(mat, tc);
setupSpotLight(gDeferredMultiSpotLightProgram, drawablep);
// send light color to shader in linear space
LLColor3 col = volume->getLightLinearColor() * light_scale;
- gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, tc.v);
+ gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, glm::value_ptr(tc));
gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, light_size_final);
gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV);
gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, light_falloff_final);
@@ -8943,10 +8920,10 @@ void LLPipeline::setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep)
//matrix from volume space to agent space
LLMatrix4 light_mat(quat, LLVector4(origin,1.f));
- glh::matrix4f light_to_agent((F32*) light_mat.mMatrix);
- glh::matrix4f light_to_screen = get_current_modelview() * light_to_agent;
+ glm::mat4 light_to_agent(glm::make_mat4((F32*) light_mat.mMatrix));
+ glm::mat4 light_to_screen = get_current_modelview() * light_to_agent;
- glh::matrix4f screen_to_light = light_to_screen.inverse();
+ glm::mat4 screen_to_light = glm::inverse(light_to_screen);
F32 s = volume->getLightRadius()*1.5f;
F32 near_clip = dist;
@@ -8954,34 +8931,34 @@ void LLPipeline::setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep)
F32 height = scale.mV[VY];
F32 far_clip = s+dist-scale.mV[VZ];
- F32 fovy = fov * RAD_TO_DEG;
+ F32 fovy = fov; // radians
F32 aspect = width/height;
- glh::matrix4f trans(0.5f, 0.f, 0.f, 0.5f,
- 0.f, 0.5f, 0.f, 0.5f,
- 0.f, 0.f, 0.5f, 0.5f,
- 0.f, 0.f, 0.f, 1.f);
+ glm::mat4 trans(0.5f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 0.5f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 0.5f, 0.0f,
+ 0.5f, 0.5f, 0.5f, 1.0f);
- glh::vec3f p1(0, 0, -(near_clip+0.01f));
- glh::vec3f p2(0, 0, -(near_clip+1.f));
+ glm::vec3 p1(0, 0, -(near_clip+0.01f));
+ glm::vec3 p2(0, 0, -(near_clip+1.f));
- glh::vec3f screen_origin(0, 0, 0);
+ glm::vec3 screen_origin(0, 0, 0);
- light_to_screen.mult_matrix_vec(p1);
- light_to_screen.mult_matrix_vec(p2);
- light_to_screen.mult_matrix_vec(screen_origin);
+ p1 = mul_mat4_vec3(light_to_screen, p1);
+ p2 = mul_mat4_vec3(light_to_screen, p2);
+ screen_origin = mul_mat4_vec3(light_to_screen, screen_origin);
- glh::vec3f n = p2-p1;
- n.normalize();
+ glm::vec3 n = p2-p1;
+ n = glm::normalize(n);
F32 proj_range = far_clip - near_clip;
- glh::matrix4f light_proj = gl_perspective(fovy, aspect, near_clip, far_clip);
+ glm::mat4 light_proj = glm::perspective(fovy, aspect, near_clip, far_clip);
screen_to_light = trans * light_proj * screen_to_light;
- shader.uniformMatrix4fv(LLShaderMgr::PROJECTOR_MATRIX, 1, false, screen_to_light.m);
+ shader.uniformMatrix4fv(LLShaderMgr::PROJECTOR_MATRIX, 1, false, glm::value_ptr(screen_to_light));
shader.uniform1f(LLShaderMgr::PROJECTOR_NEAR, near_clip);
- shader.uniform3fv(LLShaderMgr::PROJECTOR_P, 1, p1.v);
- shader.uniform3fv(LLShaderMgr::PROJECTOR_N, 1, n.v);
- shader.uniform3fv(LLShaderMgr::PROJECTOR_ORIGIN, 1, screen_origin.v);
+ shader.uniform3fv(LLShaderMgr::PROJECTOR_P, 1, glm::value_ptr(p1));
+ shader.uniform3fv(LLShaderMgr::PROJECTOR_N, 1, glm::value_ptr(n));
+ shader.uniform3fv(LLShaderMgr::PROJECTOR_ORIGIN, 1, glm::value_ptr(screen_origin));
shader.uniform1f(LLShaderMgr::PROJECTOR_RANGE, proj_range);
shader.uniform1f(LLShaderMgr::PROJECTOR_AMBIANCE, params.mV[2]);
S32 s_idx = -1;
@@ -9219,10 +9196,8 @@ inline float sgn(float a)
return (0.0F);
}
-glh::matrix4f look(const LLVector3 pos, const LLVector3 dir, const LLVector3 up)
+glm::mat4 look(const LLVector3 pos, const LLVector3 dir, const LLVector3 up)
{
- glh::matrix4f ret;
-
LLVector3 dirN;
LLVector3 upN;
LLVector3 lftN;
@@ -9236,53 +9211,28 @@ glh::matrix4f look(const LLVector3 pos, const LLVector3 dir, const LLVector3 up)
dirN = dir;
dirN.normVec();
- ret.m[ 0] = lftN[0];
- ret.m[ 1] = upN[0];
- ret.m[ 2] = -dirN[0];
- ret.m[ 3] = 0.f;
+ F32 ret[16];
+ ret[ 0] = lftN[0];
+ ret[ 1] = upN[0];
+ ret[ 2] = -dirN[0];
+ ret[ 3] = 0.f;
- ret.m[ 4] = lftN[1];
- ret.m[ 5] = upN[1];
- ret.m[ 6] = -dirN[1];
- ret.m[ 7] = 0.f;
+ ret[ 4] = lftN[1];
+ ret[ 5] = upN[1];
+ ret[ 6] = -dirN[1];
+ ret[ 7] = 0.f;
- ret.m[ 8] = lftN[2];
- ret.m[ 9] = upN[2];
- ret.m[10] = -dirN[2];
- ret.m[11] = 0.f;
+ ret[ 8] = lftN[2];
+ ret[ 9] = upN[2];
+ ret[10] = -dirN[2];
+ ret[11] = 0.f;
- ret.m[12] = -(lftN*pos);
- ret.m[13] = -(upN*pos);
- ret.m[14] = dirN*pos;
- ret.m[15] = 1.f;
+ ret[12] = -(lftN*pos);
+ ret[13] = -(upN*pos);
+ ret[14] = dirN*pos;
+ ret[15] = 1.f;
- return ret;
-}
-
-glh::matrix4f scale_translate_to_fit(const LLVector3 min, const LLVector3 max)
-{
- glh::matrix4f ret;
- ret.m[ 0] = 2/(max[0]-min[0]);
- ret.m[ 4] = 0;
- ret.m[ 8] = 0;
- ret.m[12] = -(max[0]+min[0])/(max[0]-min[0]);
-
- ret.m[ 1] = 0;
- ret.m[ 5] = 2/(max[1]-min[1]);
- ret.m[ 9] = 0;
- ret.m[13] = -(max[1]+min[1])/(max[1]-min[1]);
-
- ret.m[ 2] = 0;
- ret.m[ 6] = 0;
- ret.m[10] = 2/(max[2]-min[2]);
- ret.m[14] = -(max[2]+min[2])/(max[2]-min[2]);
-
- ret.m[ 3] = 0;
- ret.m[ 7] = 0;
- ret.m[11] = 0;
- ret.m[15] = 1;
-
- return ret;
+ return glm::make_mat4(ret);
}
static LLTrace::BlockTimerStatHandle FTM_SHADOW_RENDER("Render Shadows");
@@ -9296,7 +9246,7 @@ static LLTrace::BlockTimerStatHandle FTM_SHADOW_ALPHA_TREE("Alpha Tree");
static LLTrace::BlockTimerStatHandle FTM_SHADOW_ALPHA_GRASS("Alpha Grass");
static LLTrace::BlockTimerStatHandle FTM_SHADOW_FULLBRIGHT_ALPHA_MASKED("Fullbright Alpha Masked");
-void LLPipeline::renderShadow(glh::matrix4f& view, glh::matrix4f& proj, LLCamera& shadow_cam, LLCullResult& result, bool depth_clamp)
+void LLPipeline::renderShadow(const glm::mat4& view, const glm::mat4& proj, LLCamera& shadow_cam, LLCullResult& result, bool depth_clamp)
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE; //LL_RECORD_BLOCK_TIME(FTM_SHADOW_RENDER);
LL_PROFILE_GPU_ZONE("renderShadow");
@@ -9339,10 +9289,10 @@ void LLPipeline::renderShadow(glh::matrix4f& view, glh::matrix4f& proj, LLCamera
//generate shadow map
gGL.matrixMode(LLRender::MM_PROJECTION);
gGL.pushMatrix();
- gGL.loadMatrix(proj.m);
+ gGL.loadMatrix(glm::value_ptr(proj));
gGL.matrixMode(LLRender::MM_MODELVIEW);
gGL.pushMatrix();
- gGL.loadMatrix(view.m);
+ gGL.loadMatrix(glm::value_ptr(view));
stop_glerror();
gGLLastMatrix = NULL;
@@ -9752,13 +9702,8 @@ void LLPipeline::generateSunShadow(LLCamera& camera)
gAgentAvatarp->updateAttachmentVisibility(CAMERA_MODE_THIRD_PERSON);
}
- F64 last_modelview[16];
- F64 last_projection[16];
- for (U32 i = 0; i < 16; i++)
- { //store last_modelview of world camera
- last_modelview[i] = gGLLastModelView[i];
- last_projection[i] = gGLLastProjection[i];
- }
+ glm::mat4 last_modelview = get_last_modelview();
+ glm::mat4 last_projection = get_last_projection();
pushRenderTypeMask();
andRenderTypeMask(LLPipeline::RENDER_TYPE_SIMPLE,
@@ -9837,12 +9782,12 @@ void LLPipeline::generateSunShadow(LLCamera& camera)
//get sun view matrix
//store current projection/modelview matrix
- glh::matrix4f saved_proj = get_current_projection();
- glh::matrix4f saved_view = get_current_modelview();
- glh::matrix4f inv_view = saved_view.inverse();
+ glm::mat4 saved_proj = get_current_projection();
+ glm::mat4 saved_view = get_current_modelview();
+ glm::mat4 inv_view = glm::inverse(saved_view);
- glh::matrix4f view[6];
- glh::matrix4f proj[6];
+ glm::mat4 view[6];
+ glm::mat4 proj[6];
LLVector3 caster_dir(environment.getIsSunUp() ? mSunDir : mMoonDir);
@@ -9857,7 +9802,7 @@ void LLPipeline::generateSunShadow(LLCamera& camera)
LLVector3 lightDir = -caster_dir;
lightDir.normVec();
- glh::vec3f light_dir(lightDir.mV);
+ glm::vec3 light_dir(glm::make_vec3(lightDir.mV));
//create light space camera matrix
@@ -9912,9 +9857,9 @@ void LLPipeline::generateSunShadow(LLCamera& camera)
//get good split distances for frustum
for (U32 i = 0; i < fp.size(); ++i)
{
- glh::vec3f v(fp[i].mV);
- saved_view.mult_matrix_vec(v);
- fp[i].setVec(v.v);
+ glm::vec3 v(glm::make_vec3(fp[i].mV));
+ v = mul_mat4_vec3(saved_view, v);
+ fp[i].setVec(glm::value_ptr(v));
}
min = fp[0];
@@ -10063,9 +10008,9 @@ void LLPipeline::generateSunShadow(LLCamera& camera)
for (U32 i = 0; i < fp.size(); i++)
{
- glh::vec3f p = glh::vec3f(fp[i].mV);
- view[j].mult_matrix_vec(p);
- wpf.push_back(LLVector3(p.v));
+ glm::vec3 p = glm::make_vec3(fp[i].mV);
+ p = mul_mat4_vec3(view[j], p);
+ wpf.push_back(LLVector3(glm::value_ptr(p)));
}
min = wpf[0];
@@ -10165,7 +10110,7 @@ void LLPipeline::generateSunShadow(LLCamera& camera)
{ //just use ortho projection
mShadowFOV.mV[j] = -1.f;
origin.clearVec();
- proj[j] = gl_ortho(min.mV[0], max.mV[0],
+ proj[j] = glm::ortho(min.mV[0], max.mV[0],
min.mV[1], max.mV[1],
-max.mV[2], -min.mV[2]);
}
@@ -10256,37 +10201,37 @@ void LLPipeline::generateSunShadow(LLCamera& camera)
{ //just use ortho projection
origin.clearVec();
mShadowError.mV[j] = -1.f;
- proj[j] = gl_ortho(min.mV[0], max.mV[0],
+ proj[j] = glm::ortho(min.mV[0], max.mV[0],
min.mV[1], max.mV[1],
-max.mV[2], -min.mV[2]);
}
else
{
//get perspective projection
- view[j] = view[j].inverse();
+ view[j] = glm::inverse(view[j]);
//llassert(origin.isFinite());
- glh::vec3f origin_agent(origin.mV);
+ glm::vec3 origin_agent(glm::make_vec3(origin.mV));
//translate view to origin
- view[j].mult_matrix_vec(origin_agent);
+ origin_agent = mul_mat4_vec3(view[j], origin_agent);
- eye = LLVector3(origin_agent.v);
+ eye = LLVector3(glm::value_ptr(origin_agent));
//llassert(eye.isFinite());
if (!hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA) && !gCubeSnapshot)
{
mShadowFrustOrigin[j] = eye;
}
- view[j] = look(LLVector3(origin_agent.v), lightDir, -up);
+ view[j] = look(LLVector3(glm::value_ptr(origin_agent)), lightDir, -up);
F32 fx = 1.f/tanf(fovx);
F32 fz = 1.f/tanf(fovz);
- proj[j] = glh::matrix4f(-fx, 0, 0, 0,
- 0, (yfar+ynear)/(ynear-yfar), 0, (2.f*yfar*ynear)/(ynear-yfar),
- 0, 0, -fz, 0,
- 0, -1.f, 0, 0);
+ proj[j] = glm::mat4(-fx, 0, 0, 0,
+ 0, (yfar + ynear) / (ynear - yfar), 0, -1.0f,
+ 0, 0, -fz, 0,
+ 0, (2.f * yfar * ynear) / (ynear - yfar), 0, 0);
}
}
}
@@ -10305,19 +10250,16 @@ void LLPipeline::generateSunShadow(LLCamera& camera)
shadow_cam.getAgentPlane(LLCamera::AGENT_PLANE_NEAR).set(shadow_near_clip);
//translate and scale to from [-1, 1] to [0, 1]
- glh::matrix4f trans(0.5f, 0.f, 0.f, 0.5f,
- 0.f, 0.5f, 0.f, 0.5f,
- 0.f, 0.f, 0.5f, 0.5f,
- 0.f, 0.f, 0.f, 1.f);
+ glm::mat4 trans(0.5f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 0.5f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 0.5f, 0.0f,
+ 0.5f, 0.5f, 0.5f, 1.0f);
set_current_modelview(view[j]);
set_current_projection(proj[j]);
- for (U32 i = 0; i < 16; i++)
- {
- gGLLastModelView[i] = mShadowModelview[j].m[i];
- gGLLastProjection[i] = mShadowProjection[j].m[i];
- }
+ set_last_modelview(mShadowModelview[j]);
+ set_last_projection(mShadowProjection[j]);
mShadowModelview[j] = view[j];
mShadowProjection[j] = proj[j];
@@ -10432,9 +10374,9 @@ void LLPipeline::generateSunShadow(LLCamera& camera)
LLMatrix4 mat(quat, LLVector4(origin, 1.f));
- view[i + 4] = glh::matrix4f((F32*)mat.mMatrix);
+ view[i + 4] = glm::make_mat4((F32*)mat.mMatrix);
- view[i + 4] = view[i + 4].inverse();
+ view[i + 4] = glm::inverse(view[i + 4]);
//get perspective matrix
F32 near_clip = dist + 0.01f;
@@ -10442,27 +10384,24 @@ void LLPipeline::generateSunShadow(LLCamera& camera)
F32 height = scale.mV[VY];
F32 far_clip = dist + volume->getLightRadius() * 1.5f;
- F32 fovy = fov * RAD_TO_DEG;
+ F32 fovy = fov; // radians
F32 aspect = width / height;
- proj[i + 4] = gl_perspective(fovy, aspect, near_clip, far_clip);
+ proj[i + 4] = glm::perspective(fovy, aspect, near_clip, far_clip);
//translate and scale to from [-1, 1] to [0, 1]
- glh::matrix4f trans(0.5f, 0.f, 0.f, 0.5f,
- 0.f, 0.5f, 0.f, 0.5f,
- 0.f, 0.f, 0.5f, 0.5f,
- 0.f, 0.f, 0.f, 1.f);
+ glm::mat4 trans(0.5f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 0.5f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 0.5f, 0.0f,
+ 0.5f, 0.5f, 0.5f, 1.0f);
set_current_modelview(view[i + 4]);
set_current_projection(proj[i + 4]);
mSunShadowMatrix[i + 4] = trans * proj[i + 4] * view[i + 4] * inv_view;
- for (U32 j = 0; j < 16; j++)
- {
- gGLLastModelView[j] = mShadowModelview[i + 4].m[j];
- gGLLastProjection[j] = mShadowProjection[i + 4].m[j];
- }
+ set_last_modelview(mShadowModelview[i + 4]);
+ set_last_projection(mShadowProjection[i + 4]);
mShadowModelview[i + 4] = view[i + 4];
mShadowProjection[i + 4] = proj[i + 4];
@@ -10510,18 +10449,15 @@ void LLPipeline::generateSunShadow(LLCamera& camera)
{
set_current_modelview(view[1]);
set_current_projection(proj[1]);
- gGL.loadMatrix(view[1].m);
+ gGL.loadMatrix(glm::value_ptr(view[1]));
gGL.matrixMode(LLRender::MM_PROJECTION);
- gGL.loadMatrix(proj[1].m);
+ gGL.loadMatrix(glm::value_ptr(proj[1]));
gGL.matrixMode(LLRender::MM_MODELVIEW);
}
gGL.setColorMask(true, true);
- for (U32 i = 0; i < 16; i++)
- {
- gGLLastModelView[i] = (F32)last_modelview[i];
- gGLLastProjection[i] = (F32)last_projection[i];
- }
+ set_last_modelview(last_modelview);
+ set_last_projection(last_projection);
popRenderTypeMask();
@@ -10821,18 +10757,18 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar, bool preview_avatar, bool
F32 distance = (pos-camera.getOrigin()).length();
F32 fov = atanf(tdim.mV[1]/distance)*2.f*RAD_TO_DEG;
F32 aspect = tdim.mV[0]/tdim.mV[1];
- glh::matrix4f persp = gl_perspective(fov, aspect, 1.f, 256.f);
+ glm::mat4 persp = glm::perspective(glm::radians(fov), aspect, 1.f, 256.f);
set_current_projection(persp);
- gGL.loadMatrix(persp.m);
+ gGL.loadMatrix(glm::value_ptr(persp));
gGL.matrixMode(LLRender::MM_MODELVIEW);
gGL.pushMatrix();
- glh::matrix4f mat;
- camera.getOpenGLTransform(mat.m);
- mat = glh::matrix4f((GLfloat*) OGL_TO_CFR_ROTATION) * mat;
+ F32 ogl_mat[16];
+ camera.getOpenGLTransform(ogl_mat);
+ glm::mat4 mat = glm::make_mat4((GLfloat*) OGL_TO_CFR_ROTATION) * glm::make_mat4(ogl_mat);
- gGL.loadMatrix(mat.m);
+ gGL.loadMatrix(glm::value_ptr(mat));
set_current_modelview(mat);
glClearColor(0.0f,0.0f,0.0f,0.0f);
diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h
index 3687ab32fa..a3ecab3208 100644
--- a/indra/newview/pipeline.h
+++ b/indra/newview/pipeline.h
@@ -345,7 +345,7 @@ public:
void renderHighlight(const LLViewerObject* obj, F32 fade);
- void renderShadow(glh::matrix4f& view, glh::matrix4f& proj, LLCamera& camera, LLCullResult& result, bool depth_clamp);
+ void renderShadow(const glm::mat4& view, const glm::mat4& proj, LLCamera& camera, LLCullResult& result, bool depth_clamp);
void renderSelectedFaces(const LLColor4& color);
void renderHighlights();
void renderDebug();
@@ -760,10 +760,10 @@ public:
LLCamera mShadowCamera[8];
LLVector3 mShadowExtents[4][2];
// TODO : separate Sun Shadow and Spot Shadow matrices
- glh::matrix4f mSunShadowMatrix[6];
- glh::matrix4f mShadowModelview[6];
- glh::matrix4f mShadowProjection[6];
- glh::matrix4f mReflectionModelView;
+ glm::mat4 mSunShadowMatrix[6];
+ glm::mat4 mShadowModelview[6];
+ glm::mat4 mShadowProjection[6];
+ glm::mat4 mReflectionModelView;
LLPointer<LLDrawable> mShadowSpotLight[2];
F32 mSpotLightFade[2];