diff options
Diffstat (limited to 'indra/llrender')
| -rw-r--r-- | indra/llrender/llgl.cpp | 43 | ||||
| -rw-r--r-- | indra/llrender/llgl.h | 12 | ||||
| -rw-r--r-- | indra/llrender/llrender.cpp | 216 | ||||
| -rw-r--r-- | indra/llrender/llrender.h | 35 | ||||
| -rw-r--r-- | indra/llrender/llvertexbuffer.cpp | 7 | ||||
| -rw-r--r-- | indra/llrender/llvertexbuffer.h | 12 | 
6 files changed, 155 insertions, 170 deletions
| 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; | 
