From de191d3ce52e374563ddb78be6799f08cccf16e3 Mon Sep 17 00:00:00 2001 From: Drake Arconis <drake@alchemyviewer.org> Date: Mon, 12 Sep 2016 21:54:28 -0400 Subject: [PATCH] More GLH to GLM --- indra/llmath/CMakeLists.txt | 1 + indra/llmath/llglmhelpers.h | 34 +++++++ indra/llrender/llgl.cpp | 2 +- indra/newview/lldrawpoolavatar.cpp | 16 ++-- indra/newview/lldrawpoolground.cpp | 2 +- indra/newview/lldrawpoolsky.cpp | 2 +- indra/newview/lldrawpoolwater.cpp | 2 +- indra/newview/lldrawpoolwlsky.cpp | 4 +- indra/newview/llmaniptranslate.cpp | 16 ++-- indra/newview/llpanelprimmediacontrols.cpp | 30 +++--- indra/newview/llviewercamera.cpp | 31 +++---- indra/newview/llviewerdisplay.cpp | 68 +++++++------- indra/newview/llvieweroctree.cpp | 2 +- indra/newview/llvoavatar.cpp | 37 ++++---- indra/newview/llvotree.cpp | 12 ++- indra/newview/llwaterparammanager.cpp | 29 +++--- indra/newview/pipeline.cpp | 101 ++++++++++----------- indra/newview/pipeline.h | 11 ++- 18 files changed, 219 insertions(+), 181 deletions(-) create mode 100644 indra/llmath/llglmhelpers.h diff --git a/indra/llmath/CMakeLists.txt b/indra/llmath/CMakeLists.txt index 71a87d0f40..3240f1d0ca 100644 --- a/indra/llmath/CMakeLists.txt +++ b/indra/llmath/CMakeLists.txt @@ -57,6 +57,7 @@ set(llmath_HEADER_FILES llcamera.h llcoord.h llcoordframe.h + llglmhelpers.h llinterp.h llline.h llmath.h diff --git a/indra/llmath/llglmhelpers.h b/indra/llmath/llglmhelpers.h new file mode 100644 index 0000000000..8fe01f0193 --- /dev/null +++ b/indra/llmath/llglmhelpers.h @@ -0,0 +1,34 @@ +/** +* @file llglmhelpers.h +* @brief Helper functions for glm +* +* $LicenseInfo:firstyear=2016&license=viewerlgpl$ +* Copyright (C) 2016 Drake Arconis +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; +* version 2.1 of the License only. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* $/LicenseInfo$ +*/ + +#include <glm/vec3.hpp> +#include <glm/mat4x4.hpp> + +namespace llglmhelpers +{ + static inline glm::vec3 perspectiveTransform(const glm::mat4& mat, const glm::vec3& vec) + { + 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 + ); + } +} \ No newline at end of file diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index 260f25849c..a75d7c6869 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -752,7 +752,7 @@ void LLGLManager::initExtensions() mHasGpuShader5 = extensions.find("GL_ARB_gpu_shader5") != extensions.end(); #endif -#else // LL_MESA_HEADLESS //important, gGLHExts.mSysExts is uninitialized until after glh_init_extensions is called +#else // LL_MESA_HEADLESS mHasMultitexture = GLEW_ARB_multitexture; mHasATIMemInfo = GLEW_ATI_meminfo; mHasNVXMemInfo = GLEW_NVX_gpu_memory_info; diff --git a/indra/newview/lldrawpoolavatar.cpp b/indra/newview/lldrawpoolavatar.cpp index b58aaf0f54..70ffc52524 100644 --- a/indra/newview/lldrawpoolavatar.cpp +++ b/indra/newview/lldrawpoolavatar.cpp @@ -52,6 +52,11 @@ #include "llviewercontrol.h" // for gSavedSettings #include "llviewertexturelist.h" +#include <glm/mat3x3.hpp> +#include <glm/mat4x4.hpp> +#include <glm/gtc/matrix_inverse.hpp> +#include <glm/gtc/type_ptr.hpp> + static U32 sDataMask = LLDrawPoolAvatar::VERTEX_DATA_MASK; static U32 sBufferUsage = GL_STREAM_DRAW_ARB; static U32 sShaderLevel = 0; @@ -1479,15 +1484,8 @@ void LLDrawPoolAvatar::getRiggedGeometry(LLFace* face, LLPointer<LLVertexBuffer> U16 offset = 0; LLMatrix4 mat_vert = skin->mBindShapeMatrix; - glh::matrix4f m((F32*) mat_vert.mMatrix); - m = m.inverse().transpose(); - - F32 mat3[] = - { m.m[0], m.m[1], m.m[2], - m.m[4], m.m[5], m.m[6], - m.m[8], m.m[9], m.m[10] }; - - LLMatrix3 mat_normal(mat3); + glm::mat3 mat3(glm::transpose(glm::inverse(glm::make_mat4((F32*) mat_vert.mMatrix)))); + LLMatrix3 mat_normal(glm::value_ptr(mat3)); //let getGeometryVolume know if alpha should override shiny U32 type = gPipeline.getPoolTypeFromTE(face->getTextureEntry(), face->getTexture()); diff --git a/indra/newview/lldrawpoolground.cpp b/indra/newview/lldrawpoolground.cpp index b998e3ceac..c3627f2147 100644 --- a/indra/newview/lldrawpoolground.cpp +++ b/indra/newview/lldrawpoolground.cpp @@ -71,7 +71,7 @@ void LLDrawPoolGround::render(S32 pass) LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE); - LLGLSquashToFarClip far_clip(glm::make_mat4(glh_get_current_projection().m)); + LLGLSquashToFarClip far_clip(glm_get_current_projection()); F32 water_height = gAgent.getRegion()->getWaterHeight(); gGL.pushMatrix(); diff --git a/indra/newview/lldrawpoolsky.cpp b/indra/newview/lldrawpoolsky.cpp index 404404d052..68613cfbff 100644 --- a/indra/newview/lldrawpoolsky.cpp +++ b/indra/newview/lldrawpoolsky.cpp @@ -104,7 +104,7 @@ void LLDrawPoolSky::render(S32 pass) LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE); - LLGLSquashToFarClip far_clip(glm::make_mat4(glh_get_current_projection().m)); + LLGLSquashToFarClip far_clip(glm_get_current_projection()); LLGLEnable fog_enable( (mVertexShaderLevel < 1 && LLViewerCamera::getInstance()->cameraUnderWater()) ? GL_FOG : 0); diff --git a/indra/newview/lldrawpoolwater.cpp b/indra/newview/lldrawpoolwater.cpp index afe4ffa02a..e291485e2a 100644 --- a/indra/newview/lldrawpoolwater.cpp +++ b/indra/newview/lldrawpoolwater.cpp @@ -694,7 +694,7 @@ void LLDrawPoolWater::shade() } else { - LLGLSquashToFarClip far_clip(glm::make_mat4(glh_get_current_projection().m)); + LLGLSquashToFarClip far_clip(glm_get_current_projection()); face->renderIndexed(); } } diff --git a/indra/newview/lldrawpoolwlsky.cpp b/indra/newview/lldrawpoolwlsky.cpp index 301b644135..a425fd4713 100644 --- a/indra/newview/lldrawpoolwlsky.cpp +++ b/indra/newview/lldrawpoolwlsky.cpp @@ -327,7 +327,7 @@ void LLDrawPoolWLSky::renderDeferred(S32 pass) gGL.setColorMask(true, false); - LLGLSquashToFarClip far_clip(glm::make_mat4(glh_get_current_projection().m)); + LLGLSquashToFarClip far_clip(glm_get_current_projection()); renderSkyHaze(camHeightLocal); @@ -372,7 +372,7 @@ void LLDrawPoolWLSky::render(S32 pass) LLGLDepthTest depth(GL_TRUE, GL_FALSE); LLGLDisable clip(GL_CLIP_PLANE0); - LLGLSquashToFarClip far_clip(glm::make_mat4(glh_get_current_projection().m)); + LLGLSquashToFarClip far_clip(glm_get_current_projection()); renderSkyHaze(camHeightLocal); diff --git a/indra/newview/llmaniptranslate.cpp b/indra/newview/llmaniptranslate.cpp index 9c6bfecc88..1d8dfa7ebc 100644 --- a/indra/newview/llmaniptranslate.cpp +++ b/indra/newview/llmaniptranslate.cpp @@ -63,6 +63,9 @@ #include "llviewershadermgr.h" #include "lltrans.h" +#include <glm/vec4.hpp> // glm::vec4, glm::ivec4 +#include <glm/mat4x4.hpp> // glm::mat4 +#include <glm/gtc/matrix_inverse.hpp> #include <glm/gtc/type_ptr.hpp> const S32 NUM_AXES = 3; @@ -1677,12 +1680,12 @@ 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 ); - glh::matrix4f(const_cast<float*>(glm::value_ptr(gGL.getModelviewMatrix()))).inverse().mult_vec_matrix(plane); + glm::vec4 plane(normal.mV[0], normal.mV[1], normal.mV[2], d ); + plane = plane * glm::inverse(gGL.getModelviewMatrix()); static LLStaticHashedString sClipPlane("clip_plane"); - gClipProgram.uniform4fv(sClipPlane, 1, plane.v); + gClipProgram.uniform4fv(sClipPlane, 1, glm::value_ptr(plane)); BOOL particles = gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_PARTICLES); BOOL clouds = gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_CLOUDS); @@ -1739,13 +1742,6 @@ void LLManipTranslate::highlightIntersection(LLVector3 normal, shader->bind(); } - // <alchemy> - LL Merge Derp. - //if (shader) - //{ - // shader->bind(); - //} - // </alchemy> - //draw volume/plane intersections { gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); diff --git a/indra/newview/llpanelprimmediacontrols.cpp b/indra/newview/llpanelprimmediacontrols.cpp index edea36b822..6adadf5633 100644 --- a/indra/newview/llpanelprimmediacontrols.cpp +++ b/indra/newview/llpanelprimmediacontrols.cpp @@ -60,12 +60,17 @@ #include "llwindowshade.h" #include "llfloatertools.h" // to enable hide if build tools are up #include "llvector4a.h" +#include <llglmhelpers.h> + +#include <glm/vec3.hpp> +#include <glm/mat4x4.hpp> +#include <glm/gtc/type_ptr.hpp> // Functions pulled from pipeline.cpp -glh::matrix4f glh_get_current_modelview(); -glh::matrix4f glh_get_current_projection(); +glm::mat4 glm_get_current_modelview(); +glm::mat4 glm_get_current_projection(); // 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 }; @@ -631,13 +636,14 @@ void LLPanelPrimMediaControls::updateShape() vert_it = vect_face.begin(); vert_end = vect_face.end(); - glh::matrix4f mat; + glm::mat4 mat; if (!is_hud) { - mat = glh_get_current_projection() * glh_get_current_modelview(); + mat = glm_get_current_projection() * glm_get_current_modelview(); } - else { - glh::matrix4f proj, modelview; + else + { + glm::mat4 proj, modelview; if (get_hud_matrices(proj, modelview)) mat = proj * modelview; } @@ -646,11 +652,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 = llglmhelpers::perspectiveTransform(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) @@ -793,7 +799,7 @@ void LLPanelPrimMediaControls::draw() // ignore space from right bookend padding controls_bg_area.mRight -= mRightBookend->getRect().getWidth() - space - 2; - + // draw control background UI image LLViewerObject* objectp = getTargetObject(); diff --git a/indra/newview/llviewercamera.cpp b/indra/newview/llviewercamera.cpp index a01bef902b..47bb93b2a7 100644 --- a/indra/newview/llviewercamera.cpp +++ b/indra/newview/llviewercamera.cpp @@ -287,7 +287,7 @@ void LLViewerCamera::setPerspective(BOOL for_selection, gGL.matrixMode(LLRender::MM_PROJECTION); gGL.loadIdentity(); - glh::matrix4f proj_mat; + glm::mat4 proj_mat; if (for_selection) { @@ -300,8 +300,7 @@ void LLViewerCamera::setPerspective(BOOL for_selection, gViewerWindow->getWorldViewRectRaw().getWidth(), gViewerWindow->getWorldViewRectRaw().getHeight()); - proj_mat = glh::matrix4f((float*)glm::value_ptr(glm::pickMatrix( - glm::vec2(x+width/2.f, y_from_bot+height/2.f), glm::vec2((F32) width, (F32) height), viewport))); + proj_mat = glm::pickMatrix(glm::vec2(x+width/2.f, y_from_bot+height/2.f), glm::vec2((F32) width, (F32) height), viewport); if (limit_select_distance) { @@ -332,37 +331,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; + proj_mat = glm::translate(proj_mat, glm::vec3(offset - (F32) pos_x * 2.f, offset - (F32) pos_y * 2.f, 0.f)); + proj_mat = glm::scale(proj_mat, glm::vec3(mZoomFactor, mZoomFactor, 1.f)); } calcProjection(z_far); // Update the projection matrix cache - proj_mat *= glh::matrix4f(const_cast<float*>(glm::value_ptr(glm::perspective(glm::radians(fov_y), aspect, z_near, z_far)))); + proj_mat *= glm::perspective(glm::radians(fov_y), aspect, z_near, z_far); - gGL.loadMatrix(proj_mat.m); + F32* proj_matp = glm::value_ptr(proj_mat); + + gGL.loadMatrix(proj_matp); for (U32 i = 0; i < 16; i++) { - gGLProjection[i] = proj_mat.m[i]; + gGLProjection[i] = proj_matp[i]; } 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); + F32* modelviewp = glm::value_ptr(modelview); + gGL.loadMatrix(modelviewp); if (for_selection && (width > 1 || height > 1)) { @@ -382,7 +379,7 @@ void LLViewerCamera::setPerspective(BOOL for_selection, // 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]; + gGLModelView[i] = modelviewp[i]; } } diff --git a/indra/newview/llviewerdisplay.cpp b/indra/newview/llviewerdisplay.cpp index 5473e08939..c85047fd1b 100644 --- a/indra/newview/llviewerdisplay.cpp +++ b/indra/newview/llviewerdisplay.cpp @@ -727,8 +727,8 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot) LLGLState::checkTextureChannels(); LLGLState::checkClientArrays(); - glh::matrix4f proj = glh_get_current_projection(); - glh::matrix4f mod = glh_get_current_modelview(); + glm::mat4 proj = glm_get_current_projection(); + glm::mat4 mod = glm_get_current_modelview(); glViewport(0,0,512,512); LLVOAvatar::updateFreezeCounter() ; @@ -737,12 +737,12 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot) LLVOAvatar::updateImpostors(); } - glh_set_current_projection(proj); - glh_set_current_modelview(mod); + glm_set_current_projection(proj); + glm_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(); @@ -1075,8 +1075,8 @@ void render_hud_attachments() gGL.matrixMode(LLRender::MM_MODELVIEW); gGL.pushMatrix(); - glh::matrix4f current_proj = glh_get_current_projection(); - glh::matrix4f current_mod = glh_get_current_modelview(); + glm::mat4 current_proj = glm_get_current_projection(); + glm::mat4 current_mod = glm_get_current_modelview(); // clamp target zoom level to reasonable values gAgentCamera.mHUDTargetZoom = llclamp(gAgentCamera.mHUDTargetZoom, 0.1f, 1.f); @@ -1167,8 +1167,8 @@ void render_hud_attachments() gGL.matrixMode(LLRender::MM_MODELVIEW); gGL.popMatrix(); - glh_set_current_projection(current_proj); - glh_set_current_modelview(current_mod); + glm_set_current_projection(current_proj); + glm_set_current_modelview(current_mod); } LLRect get_whole_screen_region() @@ -1191,7 +1191,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()) { @@ -1199,29 +1199,23 @@ 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 = glh::matrix4f(const_cast<float*>(glm::value_ptr(glm::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; + proj = glm::translate(proj, + 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)); + proj = glm::scale(proj, glm::vec3(scale_x, scale_y, 1.f)); - 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)); - - tmp_model *= mat; - model = tmp_model; + model = glm::make_mat4(OGL_TO_CFR_ROTATION); + model = glm::translate(model, glm::vec3(-hud_bbox.getCenterLocal().mV[VX] + (hud_depth * 0.5f), 0.f, 0.f)); + model = glm::scale(model, glm::vec3(zoom_level)); + return TRUE; } else @@ -1230,7 +1224,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); @@ -1244,18 +1238,18 @@ 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); - glh_set_current_projection(proj); + gGL.loadMatrix(glm::value_ptr(proj)); + glm_set_current_projection(proj); gGL.matrixMode(LLRender::MM_MODELVIEW); - gGL.loadMatrix(model.m); - glh_set_current_modelview(model); + gGL.loadMatrix(glm::value_ptr(model)); + glm_set_current_modelview(model); return TRUE; } @@ -1263,13 +1257,13 @@ void render_ui(F32 zoom_factor, int subfield) { LLGLState::checkStates(); - glh::matrix4f saved_view = glh_get_current_modelview(); + glm::mat4 saved_view = glm_get_current_modelview(); if (!gSnapshot) { gGL.pushMatrix(); gGL.loadMatrix(gGLLastModelView); - glh_set_current_modelview(glh_copy_matrix(gGLLastModelView)); + glm_set_current_modelview(glm_copy_matrix(gGLLastModelView)); } if(LLSceneMonitor::getInstance()->needsUpdate()) @@ -1332,7 +1326,7 @@ void render_ui(F32 zoom_factor, int subfield) if (!gSnapshot) { - glh_set_current_modelview(saved_view); + glm_set_current_modelview(saved_view); gGL.popMatrix(); } } diff --git a/indra/newview/llvieweroctree.cpp b/indra/newview/llvieweroctree.cpp index 207bf0ac12..ffcb67c74b 100644 --- a/indra/newview/llvieweroctree.cpp +++ b/indra/newview/llvieweroctree.cpp @@ -1272,7 +1272,7 @@ void LLOcclusionCullingGroup::doOcclusion(LLCamera* camera, const LLVector4a* sh { LL_RECORD_BLOCK_TIME(FTM_OCCLUSION_DRAW_WATER); - LLGLSquashToFarClip squash(glm::make_mat4(glh_get_current_projection().m), 1); + LLGLSquashToFarClip squash(glm_get_current_projection(), 1); if (camera->getOrigin().isExactlyZero()) { //origin is invalid, draw entire box gPipeline.mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, 0); diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp index c2487d4c86..dc0b2ac9ca 100644 --- a/indra/newview/llvoavatar.cpp +++ b/indra/newview/llvoavatar.cpp @@ -31,11 +31,17 @@ #include <stdio.h> #include <ctype.h> #include <sstream> +#include <glm/vec3.hpp> +#include <glm/mat4x4.hpp> +#include <glm/gtc/matrix_inverse.hpp> +#include <glm/gtc/matrix_transform.hpp> +#include <glm/gtc/type_ptr.hpp> #include "llaudioengine.h" #include "noise.h" #include "sound_ids.h" #include "raytrace.h" +#include "llglmhelpers.h" #include "alavatarcolormgr.h" #include "llagent.h" // Get state values from here @@ -1545,36 +1551,35 @@ 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 = llglmhelpers::perspectiveTransform(inverse, p1); + p2 = llglmhelpers::perspectiveTransform(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 = llglmhelpers::perspectiveTransform(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 = llglmhelpers::perspectiveTransform(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 884b241c61..2a9e3c468b 100644 --- a/indra/newview/llvotree.cpp +++ b/indra/newview/llvotree.cpp @@ -53,6 +53,10 @@ #include "raytrace.h" #include "llglslshader.h" +#include <glm/mat4x4.hpp> +#include <glm/gtc/matrix_inverse.hpp> +#include <glm/gtc/type_ptr.hpp> + extern LLPipeline gPipeline; const S32 MAX_SLICES = 32; @@ -990,8 +994,8 @@ 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)))); appendMesh(vertices, normals, tex_coords, indices, index_offset, scale_mat, norm_mat, sLODVertexOffset[trunk_LOD], sLODVertexCount[trunk_LOD], sLODIndexCount[trunk_LOD], sLODIndexOffset[trunk_LOD]); @@ -1039,8 +1043,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, indices, index_offset, scale_mat, norm_mat, 0, LEAF_VERTICES, LEAF_INDICES, 0); } diff --git a/indra/newview/llwaterparammanager.cpp b/indra/newview/llwaterparammanager.cpp index 4160eb46e6..137a439d14 100644 --- a/indra/newview/llwaterparammanager.cpp +++ b/indra/newview/llwaterparammanager.cpp @@ -53,8 +53,13 @@ #include "llwlparammanager.h" #include "llwaterparamset.h" +#include "llglmhelpers.h" -#include "curl/curl.h" +#include <glm/vec3.hpp> +#include <glm/mat4x4.hpp> +#include <glm/gtc/matrix_inverse.hpp> +#include <glm/gtc/matrix_transform.hpp> +#include <glm/gtc/type_ptr.hpp> LLWaterParamManager::LLWaterParamManager() : mFogColor(22.f/255.f, 43.f/255.f, 54.f/255.f, 0.0f, 0.0f, "waterFogColor", "WaterFogColor"), @@ -227,18 +232,18 @@ void LLWaterParamManager::update(LLViewerCamera * cam) if(gPipeline.canUseVertexShaders()) { //transform water plane to eye space - glh::vec3f norm(0.f, 0.f, 1.f); - glh::vec3f p(0.f, 0.f, gAgent.getRegion()->getWaterHeight()+0.1f); + glm::vec3 norm(0.f, 0.f, 1.f); + glm::vec3 p(0.f, 0.f, gAgent.getRegion()->getWaterHeight() + 0.1f); - glh::matrix4f mat(gGLModelView); - glh::matrix4f invtrans = mat.inverse().transpose(); - glh::vec3f enorm; - glh::vec3f ep; - invtrans.mult_matrix_vec(norm, enorm); - enorm.normalize(); - mat.mult_matrix_vec(p, ep); - - mWaterPlane = LLVector4(enorm.v[0], enorm.v[1], enorm.v[2], -ep.dot(enorm)); + glm::mat4 mat(glm::make_mat4(gGLModelView)); + glm::mat4 invtrans = glm::transpose(glm::inverse(mat)); + + norm = llglmhelpers::perspectiveTransform(invtrans, norm); + norm = glm::normalize(norm); + + p = llglmhelpers::perspectiveTransform(mat, p); + + mWaterPlane = LLVector4(norm[0], norm[1], norm[2], -glm::dot(p, norm)); LLVector3 sunMoonDir; if (gSky.getSunDirection().mV[2] > LLSky::NIGHTTIME_ELEVATION_COS) diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index aa27d74c1c..f7574111c5 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -112,6 +112,8 @@ #include "llscenemonitor.h" #include "llprogressview.h" +#include "llglmhelpers.h" + #include <glm/vec3.hpp> #include <glm/vec4.hpp> #include <glm/mat4x4.hpp> @@ -301,46 +303,44 @@ void drawBoxOutline(const LLVector3& pos, const LLVector3& size); U32 nhpo2(U32 v); LLVertexBuffer* ll_create_cube_vb(U32 type_mask, U32 usage); -glh::matrix4f glh_copy_matrix(F32* src) +glm::mat4 glm_copy_matrix(F32* src) { - glh::matrix4f ret; - ret.set_value(src); - return ret; + return glm::make_mat4(src); } -glh::matrix4f glh_get_current_modelview() +glm::mat4 glm_get_current_modelview() { - return glh_copy_matrix(gGLModelView); + return glm_copy_matrix(gGLModelView); } -glh::matrix4f glh_get_current_projection() +glm::mat4 glm_get_current_projection() { - return glh_copy_matrix(gGLProjection); + return glm_copy_matrix(gGLProjection); } -glh::matrix4f glh_get_last_modelview() +glm::mat4 glm_get_last_modelview() { - return glh_copy_matrix(gGLLastModelView); + return glm_copy_matrix(gGLLastModelView); } -glh::matrix4f glh_get_last_projection() +glm::mat4 glm_get_last_projection() { - return glh_copy_matrix(gGLLastProjection); + return glm_copy_matrix(gGLLastProjection); } -void glh_copy_matrix(const glh::matrix4f& src, F32* dst) +void glm_copy_matrix(const glm::mat4& src, F32* dst) { - memcpy(dst, src.m, sizeof(F32) * 16); + memcpy(dst, glm::value_ptr(src), sizeof(F32) * 16); } -void glh_set_current_modelview(const glh::matrix4f& mat) +void glm_set_current_modelview(const glm::mat4& mat) { - glh_copy_matrix(mat, gGLModelView); + glm_copy_matrix(mat, gGLModelView); } -void glh_set_current_projection(glh::matrix4f& mat) +void glm_set_current_projection(const glm::mat4& mat) { - glh_copy_matrix(mat, gGLProjection); + glm_copy_matrix(mat, gGLProjection); } void display_update_camera(); @@ -2428,9 +2428,7 @@ void LLPipeline::updateCull(LLCamera& camera, LLCullResult& result, S32 water_cl } } - glm::mat4 modelview = glm::make_mat4(glh_get_last_modelview().m); - glm::mat4 proj = glm::make_mat4(glh_get_last_projection().m); - LLGLUserClipPlane clip(plane, modelview, proj, water_clip != 0 && LLPipeline::sReflectionRender); + LLGLUserClipPlane clip(plane, glm_get_last_modelview(), glm_get_last_projection(), water_clip != 0 && LLPipeline::sReflectionRender); LLGLDepthTest depth(GL_TRUE, GL_FALSE); @@ -7774,10 +7772,9 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, U32 light_index, U32 n stop_glerror(); - glh::matrix4f projection = glh_get_current_projection(); - glh::matrix4f inv_proj = projection.inverse(); + glm::mat4 inv_proj = glm::inverse(glm_get_current_projection()); - shader.uniformMatrix4fv(LLShaderMgr::INVERSE_PROJECTION_MATRIX, 1, FALSE, inv_proj.m); + shader.uniformMatrix4fv(LLShaderMgr::INVERSE_PROJECTION_MATRIX, 1, FALSE, glm::value_ptr(inv_proj)); shader.uniform4f(LLShaderMgr::VIEWPORT, (F32) gGLViewport[0], (F32) gGLViewport[1], (F32) gGLViewport[2], @@ -7926,8 +7923,8 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, U32 light_index, U32 n if (shader.getUniformLocation(LLShaderMgr::DEFERRED_NORM_MATRIX) >= 0) { - glh::matrix4f norm_mat = glh_get_current_modelview().inverse().transpose(); - shader.uniformMatrix4fv(LLShaderMgr::DEFERRED_NORM_MATRIX, 1, FALSE, norm_mat.m); + glm::mat4 norm_mat = glm::transpose(glm::inverse(glm_get_current_modelview())); + shader.uniformMatrix4fv(LLShaderMgr::DEFERRED_NORM_MATRIX, 1, FALSE, glm::value_ptr(norm_mat)); } } @@ -7996,7 +7993,7 @@ void LLPipeline::renderDeferredLighting() LLGLEnable cull(GL_CULL_FACE); LLGLEnable blend(GL_BLEND); - glh::matrix4f mat = glh_copy_matrix(gGLModelView); + glh::matrix4f mat = glh::matrix4f(const_cast<float*>(glm::value_ptr(glm_get_current_modelview()))); LLStrider<LLVector3> vert; mDeferredVB->getVertexStrider(vert); @@ -8586,7 +8583,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) LLGLEnable cull(GL_CULL_FACE); LLGLEnable blend(GL_BLEND); - glh::matrix4f mat = glh_copy_matrix(gGLModelView); + glh::matrix4f mat = glh::matrix4f(const_cast<float*>(glm::value_ptr(glm_get_current_modelview()))); LLStrider<LLVector3> vert; mDeferredVB->getVertexStrider(vert); @@ -9086,7 +9083,7 @@ void LLPipeline::setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep) LLMatrix4 light_mat(quat, LLVector4(origin,1.f)); glh::matrix4f light_to_agent((F32*) light_mat.mMatrix); - glh::matrix4f light_to_screen = glh_get_current_modelview() * light_to_agent; + glh::matrix4f light_to_screen = glh::matrix4f(const_cast<float*>(glm::value_ptr(glm_get_current_modelview()))) * light_to_agent; glh::matrix4f screen_to_light = light_to_screen.inverse(); @@ -9273,7 +9270,7 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) gPipeline.pushRenderTypeMask(); - glh::matrix4f projection = glh_get_current_projection(); + glh::matrix4f projection = glh::matrix4f(const_cast<float*>(glm::value_ptr(glm_get_current_projection()))); glh::matrix4f mat; stop_glerror(); @@ -9334,11 +9331,11 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) mat.set_scale(glh::vec3f(1,1,-1)); mat.set_translate(glh::vec3f(0,0,height*2.f)); - glh::matrix4f current = glh_get_current_modelview(); + glh::matrix4f current = glh::matrix4f(const_cast<float*>(glm::value_ptr(glm_get_current_modelview()))); mat = current * mat; - glh_set_current_modelview(mat); + glm_set_current_modelview(glm::make_mat4(mat.m)); gGL.loadMatrix(mat.m); LLViewerCamera::updateFrustumPlanes(camera, FALSE, TRUE); @@ -9449,7 +9446,7 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) glCullFace(GL_BACK); gGL.popMatrix(); mWaterRef.flush(); - glh_set_current_modelview(current); + glm_set_current_modelview(glm::make_mat4(current.m)); LLPipeline::sUseOcclusion = occlusion; } @@ -9489,7 +9486,7 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) if (!LLPipeline::sUnderWaterRender || LLDrawPoolWater::sNeedsReflectionUpdate) { //clip out geometry on the same side of water as the camera - mat = glh_get_current_modelview(); + mat = glh::matrix4f(const_cast<float*>(glm::value_ptr(glm_get_current_modelview()))); LLPlane plane(-pnorm, -(pd+pad)); LLGLUserClipPlane clip_plane(plane, glm::make_mat4(mat.m), glm::make_mat4(projection.m)); @@ -10100,8 +10097,8 @@ void LLPipeline::generateSunShadow(LLCamera& camera) //get sun view matrix //store current projection/modelview matrix - glh::matrix4f saved_proj = glh_get_current_projection(); - glh::matrix4f saved_view = glh_get_current_modelview(); + glh::matrix4f saved_proj = glh::matrix4f(const_cast<float*>(glm::value_ptr(glm_get_current_projection()))); + glh::matrix4f saved_view = glh::matrix4f(const_cast<float*>(glm::value_ptr(glm_get_current_modelview()))); glh::matrix4f inv_view = saved_view.inverse(); glh::matrix4f view[6]; @@ -10258,8 +10255,8 @@ void LLPipeline::generateSunShadow(LLCamera& camera) LLViewerCamera::sCurCameraID = (LLViewerCamera::eCameraID)(LLViewerCamera::CAMERA_SHADOW0+j); //restore render matrices - glh_set_current_modelview(saved_view); - glh_set_current_projection(saved_proj); + glm_set_current_modelview(glm::make_mat4(saved_view.m)); + glm_set_current_projection(glm::make_mat4(saved_proj.m)); LLVector3 eye = camera.getOrigin(); @@ -10573,8 +10570,8 @@ void LLPipeline::generateSunShadow(LLCamera& camera) shadow_cam.setOrigin(0,0,0); - glh_set_current_modelview(view[j]); - glh_set_current_projection(proj[j]); + glm_set_current_modelview(glm::make_mat4(view[j].m)); + glm_set_current_projection(glm::make_mat4(proj[j].m)); LLViewerCamera::updateFrustumPlanes(shadow_cam, FALSE, FALSE, TRUE); @@ -10587,8 +10584,8 @@ void LLPipeline::generateSunShadow(LLCamera& camera) 0.f, 0.f, 0.5f, 0.5f, 0.f, 0.f, 0.f, 1.f); - glh_set_current_modelview(view[j]); - glh_set_current_projection(proj[j]); + glm_set_current_modelview(glm::make_mat4(view[j].m)); + glm_set_current_projection(glm::make_mat4(proj[j].m)); memcpy(gGLLastModelView, mShadowModelview[j].m, sizeof(F32) * 16); memcpy(gGLLastProjection, mShadowProjection[j].m, sizeof(F32) * 16); @@ -10664,8 +10661,8 @@ void LLPipeline::generateSunShadow(LLCamera& camera) for (S32 i = 0; i < 2; i++) { - glh_set_current_modelview(saved_view); - glh_set_current_projection(saved_proj); + glm_set_current_modelview(glm::make_mat4(saved_view.m)); + glm_set_current_projection(glm::make_mat4(saved_proj.m)); if (mShadowSpotLight[i].isNull()) { @@ -10725,8 +10722,8 @@ void LLPipeline::generateSunShadow(LLCamera& camera) 0.f, 0.f, 0.5f, 0.5f, 0.f, 0.f, 0.f, 1.f); - glh_set_current_modelview(view[i+4]); - glh_set_current_projection(proj[i+4]); + glm_set_current_modelview(glm::make_mat4(view[i+4].m)); + glm_set_current_projection(glm::make_mat4(proj[i+4].m)); mSunShadowMatrix[i+4] = trans*proj[i+4]*view[i+4]*inv_view; @@ -10767,13 +10764,13 @@ void LLPipeline::generateSunShadow(LLCamera& camera) if (!CameraOffset) { - glh_set_current_modelview(saved_view); - glh_set_current_projection(saved_proj); + glm_set_current_modelview(glm::make_mat4(saved_view.m)); + glm_set_current_projection(glm::make_mat4(saved_proj.m)); } else { - glh_set_current_modelview(view[1]); - glh_set_current_projection(proj[1]); + glm_set_current_modelview(glm::make_mat4(view[1].m)); + glm_set_current_projection(glm::make_mat4(proj[1].m)); gGL.loadMatrix(view[1].m); gGL.matrixMode(LLRender::MM_PROJECTION); gGL.loadMatrix(proj[1].m); @@ -10941,7 +10938,7 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar) F32 fov = atanf(tdim.mV[1]/distance)*2.f*RAD_TO_DEG; F32 aspect = tdim.mV[0]/tdim.mV[1]; glh::matrix4f persp = glh::matrix4f(const_cast<float*>(glm::value_ptr(glm::perspective(glm::radians(fov), aspect, 1.f, 256.f)))); - glh_set_current_projection(persp); + glm_set_current_projection(glm::make_mat4(persp.m)); gGL.loadMatrix(persp.m); gGL.matrixMode(LLRender::MM_MODELVIEW); @@ -10952,7 +10949,7 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar) mat = glh::matrix4f((GLfloat*) OGL_TO_CFR_ROTATION) * mat; gGL.loadMatrix(mat.m); - glh_set_current_modelview(mat); + glm_set_current_modelview(glm::make_mat4(mat.m)); glClearColor(0.0f,0.0f,0.0f,0.0f); gGL.setColorMask(true, true); diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h index 0c511cea02..1e411d286b 100644 --- a/indra/newview/pipeline.h +++ b/indra/newview/pipeline.h @@ -40,6 +40,7 @@ #include "llrendertarget.h" #include <stack> +#include <glm/mat4x4.hpp> class LLViewerTexture; class LLFace; @@ -61,11 +62,11 @@ BOOL compute_min_max(LLMatrix4& box, LLVector2& min, LLVector2& max); // Shouldn bool LLRayAABB(const LLVector3 ¢er, const LLVector3 &size, const LLVector3& origin, const LLVector3& dir, LLVector3 &coord, F32 epsilon = 0); BOOL setup_hud_matrices(); // use whole screen to render hud BOOL setup_hud_matrices(const LLRect& screen_region); // specify portion of screen (in pixels) to render hud attachments from (for picking) -glh::matrix4f glh_copy_matrix(F32* src); -glh::matrix4f glh_get_current_modelview(); -void glh_set_current_modelview(const glh::matrix4f& mat); -glh::matrix4f glh_get_current_projection(); -void glh_set_current_projection(glh::matrix4f& mat); +glm::mat4 glm_copy_matrix(F32* src); +glm::mat4 glm_get_current_modelview(); +void glm_set_current_modelview(const glm::mat4& mat); +glm::mat4 glm_get_current_projection(); +void glm_set_current_projection(const glm::mat4& mat); extern LLTrace::BlockTimerStatHandle FTM_RENDER_GEOMETRY; extern LLTrace::BlockTimerStatHandle FTM_RENDER_GRASS; -- GitLab