diff --git a/indra/newview/llviewercamera.cpp b/indra/newview/llviewercamera.cpp index a3742ce608b768855a9b4448c1a90a552af9cc4f..a01bef902bc781e9731a1ef34d84b8e1c8260cef 100644 --- a/indra/newview/llviewercamera.cpp +++ b/indra/newview/llviewercamera.cpp @@ -65,53 +65,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); -} - -glh::matrix4f gl_perspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar) -{ - 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); -} - -glh::matrix4f gl_lookat(LLVector3 eye, LLVector3 center, LLVector3 up) -{ - LLVector3 f = center-eye; - f.normVec(); - up.normVec(); - LLVector3 s = f % up; - LLVector3 u = s % f; - - 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); - -} - // Build time optimization, generate this once in .cpp file template class LLViewerCamera* LLSingleton<class LLViewerCamera>::getInstance(); @@ -341,13 +294,14 @@ void LLViewerCamera::setPerspective(BOOL 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 = 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))); if (limit_select_distance) { @@ -389,7 +343,7 @@ void LLViewerCamera::setPerspective(BOOL for_selection, calcProjection(z_far); // Update the projection matrix cache - proj_mat *= gl_perspective(fov_y,aspect,z_near,z_far); + proj_mat *= glh::matrix4f(const_cast<float*>(glm::value_ptr(glm::perspective(glm::radians(fov_y), aspect, z_near, z_far)))); gGL.loadMatrix(proj_mat.m); diff --git a/indra/newview/llviewerdisplay.cpp b/indra/newview/llviewerdisplay.cpp index 4ca8e9186cd3f95a23ce68ed620c1c579fbb1252..5473e089399135d77ef660762ebb7cc03d793d88 100644 --- a/indra/newview/llviewerdisplay.cpp +++ b/indra/newview/llviewerdisplay.cpp @@ -80,6 +80,12 @@ #include "llwaterparammanager.h" #include "llscenemonitor.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> + extern LLPointer<LLViewerTexture> gStartTexture; extern bool gShiftFrame; @@ -1193,7 +1199,8 @@ 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 = 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; F32 aspect_ratio = LLViewerCamera::getInstance()->getAspect(); diff --git a/indra/newview/llwaterparammanager.cpp b/indra/newview/llwaterparammanager.cpp index 6d108c0bad61fe813a72e631878b74f67ae99b7c..4160eb46e6644a6227bda7f279f402b320f64984 100644 --- a/indra/newview/llwaterparammanager.cpp +++ b/indra/newview/llwaterparammanager.cpp @@ -230,13 +230,7 @@ void LLWaterParamManager::update(LLViewerCamera * cam) glh::vec3f norm(0.f, 0.f, 1.f); glh::vec3f p(0.f, 0.f, gAgent.getRegion()->getWaterHeight()+0.1f); - F32 modelView[16]; - for (U32 i = 0; i < 16; i++) - { - modelView[i] = (F32) gGLModelView[i]; - } - - glh::matrix4f mat(modelView); + glh::matrix4f mat(gGLModelView); glh::matrix4f invtrans = mat.inverse().transpose(); glh::vec3f enorm; glh::vec3f ep; diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index c5393816d477a8b28ad9485251f96a721d429959..de7d4074358e3f06cd6d40641458dcb7e8277921 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -112,6 +112,13 @@ #include "llscenemonitor.h" #include "llprogressview.h" +#include <glm/vec3.hpp> +#include <glm/vec4.hpp> +#include <glm/mat4x4.hpp> +#include <glm/gtc/matrix_inverse.hpp> +#include <glm/gtc/matrix_transform.hpp> +#include <glm/gtc/type_ptr.hpp> + #ifdef _DEBUG // Debug indices is disabled for now for debug performance - djs 4/24/02 //#define DEBUG_INDICES @@ -336,17 +343,6 @@ void glh_set_current_projection(glh::matrix4f& mat) glh_copy_matrix(mat, gGLProjection); } -glh::matrix4f gl_ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat znear, GLfloat zfar) -{ - 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; -} - void display_update_camera(); //---------------------------------------- @@ -637,7 +633,6 @@ void LLPipeline::init() connectRefreshCachedSettingsSafe("CameraMaxCoF"); connectRefreshCachedSettingsSafe("CameraDoFResScale"); connectRefreshCachedSettingsSafe("RenderAutoHideSurfaceAreaLimit"); - //gSavedSettings.getControl("RenderAutoHideSurfaceAreaLimit")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings)); } LLPipeline::~LLPipeline() @@ -7420,7 +7415,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield) if (channel > -1) { mDeferredLight.bindTexture(0, channel); - gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR); // scale fairly pleasantly <alchemy/> + gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR); // scale fairly pleasantly } shader->uniform1f(LLShaderMgr::DOF_MAX_COF, CameraMaxCoF); @@ -7470,9 +7465,9 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield) if (!LLViewerCamera::getInstance()->cameraUnderWater()) { - shader->uniform1f(LLShaderMgr::GLOBAL_GAMMA, 2.2f); // <alchemy/> + shader->uniform1f(LLShaderMgr::GLOBAL_GAMMA, 2.2f); } else { - shader->uniform1f(LLShaderMgr::GLOBAL_GAMMA, 1.0f); // <alchemy/> + shader->uniform1f(LLShaderMgr::GLOBAL_GAMMA, 1.0f); } shader->uniform1f(LLShaderMgr::DOF_MAX_COF, CameraMaxCoF); @@ -7519,9 +7514,9 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield) if (!LLViewerCamera::getInstance()->cameraUnderWater()) { - shader->uniform1f(LLShaderMgr::GLOBAL_GAMMA, 2.2f); // <alchemy/> + shader->uniform1f(LLShaderMgr::GLOBAL_GAMMA, 2.2f); } else { - shader->uniform1f(LLShaderMgr::GLOBAL_GAMMA, 1.0f); // <alchemy/> + shader->uniform1f(LLShaderMgr::GLOBAL_GAMMA, 1.0f); } gGL.begin(LLRender::TRIANGLE_STRIP); @@ -7905,10 +7900,10 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, U32 light_index, U32 n F32 ssao_factor = RenderSSAOFactor; shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_FACTOR, ssao_factor); - shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_FACTOR_INV, 1.f/ssao_factor); // <alchemy/> + shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_FACTOR_INV, 1.f/ssao_factor); LLVector3 ssao_effect = RenderSSAOEffect; - shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_EFFECT, ssao_effect[0]); // <alchemy/> + shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_EFFECT, ssao_effect[0]); shader.uniform1f(LLShaderMgr::SECONDS60, (F32) fmod(LLTimer::getElapsedSeconds(), 60.0)); // <alchemy/> @@ -9122,7 +9117,7 @@ void LLPipeline::setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep) n.normalize(); F32 proj_range = far_clip - near_clip; - glh::matrix4f light_proj = gl_perspective(fovy, aspect, near_clip, far_clip); + glh::matrix4f light_proj = glh::matrix4f(const_cast<float*>(glm::value_ptr(glm::perspective(glm::radians(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.uniform1f(LLShaderMgr::PROJECTOR_NEAR, near_clip); @@ -10447,9 +10442,10 @@ 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] = glh::matrix4f(const_cast<float*>( + glm::value_ptr(glm::ortho(min.mV[0], max.mV[0], min.mV[1], max.mV[1], - -max.mV[2], -min.mV[2]); + -max.mV[2], -min.mV[2])))); } else { @@ -10538,9 +10534,9 @@ 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] = glh::matrix4f(const_cast<float*>(glm::value_ptr(glm::ortho(min.mV[0], max.mV[0], min.mV[1], max.mV[1], - -max.mV[2], -min.mV[2]); + -max.mV[2], -min.mV[2])))); } else { @@ -10720,8 +10716,8 @@ void LLPipeline::generateSunShadow(LLCamera& camera) F32 fovy = fov * RAD_TO_DEG; F32 aspect = width/height; - - proj[i+4] = gl_perspective(fovy, aspect, near_clip, far_clip); + + proj[i+4] = glh::matrix4f(const_cast<float*>(glm::value_ptr(glm::perspective(glm::radians(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, @@ -10944,7 +10940,7 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar) 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); + 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); gGL.loadMatrix(persp.m); diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h index 948c6761e44b9ebe6b9c287881b894972cf81801..0c511cea02319517f75bbb14b6fe026e08e624cc 100644 --- a/indra/newview/pipeline.h +++ b/indra/newview/pipeline.h @@ -66,9 +66,6 @@ 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); -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); extern LLTrace::BlockTimerStatHandle FTM_RENDER_GEOMETRY; extern LLTrace::BlockTimerStatHandle FTM_RENDER_GRASS;