diff --git a/indra/newview/lllegacyatmospherics.h b/indra/newview/lllegacyatmospherics.h index 03c8efb91aed629c3abbb433238fe8aec9557ba1..ebe111b6dce3f6d6f76ad10aa6da6e0eb39932e2 100644 --- a/indra/newview/lllegacyatmospherics.h +++ b/indra/newview/lllegacyatmospherics.h @@ -43,16 +43,16 @@ // Will clean these up at some point... // -const F32 HORIZON_DIST = 1024.0f; -const F32 ATM_EXP_FALLOFF = 0.000126f; -const F32 ATM_SEA_LEVEL_NDENS = 2.55e25f; -const F32 ATM_HEIGHT = 100000.f; +constexpr F32 HORIZON_DIST = 1024.0f; +constexpr F32 ATM_EXP_FALLOFF = 0.000126f; +constexpr F32 ATM_SEA_LEVEL_NDENS = 2.55e25f; +constexpr F32 ATM_HEIGHT = 100000.f; // constants used in calculation of scattering coeff of clear air -const F32 sigma = 0.035f; -const F32 fsigma = (6.f + 3.f * sigma) / (6.f-7.f*sigma); -const F64 Ndens = 2.55e25; -const F64 Ndens2 = Ndens*Ndens; +constexpr F32 sigma = 0.035f; +constexpr F32 fsigma = (6.f + 3.f * sigma) / (6.f-7.f*sigma); +constexpr F64 Ndens = 2.55e25; +constexpr F64 Ndens2 = Ndens*Ndens; class LLFace; class LLHaze; diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 66d56068a0ba10195433ab9360a9ee3f28c19e56..dd93ab5ae992aa305ac4ce7b376d3b26abafad4f 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -61,42 +61,39 @@ namespace { - const S32 NUM_TILES_X = 8; - const S32 NUM_TILES_Y = 4; - const S32 NUM_TILES = NUM_TILES_X * NUM_TILES_Y; - const S32 NUM_CUBEMAP_FACES = 6; // See sResolution for face dimensions - const S32 TOTAL_TILES = NUM_CUBEMAP_FACES * NUM_TILES; - const S32 MAX_TILES = TOTAL_TILES + 1; + constexpr S32 NUM_TILES_X = 8; + constexpr S32 NUM_TILES_Y = 4; + constexpr S32 NUM_TILES = NUM_TILES_X * NUM_TILES_Y; + constexpr S32 NUM_CUBEMAP_FACES = 6; // See sResolution for face dimensions + constexpr S32 TOTAL_TILES = NUM_CUBEMAP_FACES * NUM_TILES; + constexpr S32 MAX_TILES = TOTAL_TILES + 1; // Heavenly body constants - const F32 SUN_DISK_RADIUS = 0.5f; - const F32 MOON_DISK_RADIUS = SUN_DISK_RADIUS * 0.9f; - const F32 SUN_INTENSITY = 1e5; + constexpr F32 SUN_DISK_RADIUS = 0.5f; + constexpr F32 MOON_DISK_RADIUS = SUN_DISK_RADIUS * 0.9f; + constexpr F32 SUN_INTENSITY = 1e5; // Texture coordinates: - const LLVector2 TEX00 = LLVector2(0.f, 0.f); - const LLVector2 TEX01 = LLVector2(0.f, 1.f); - const LLVector2 TEX10 = LLVector2(1.f, 0.f); - const LLVector2 TEX11 = LLVector2(1.f, 1.f); + constexpr LLVector2 TEX00 = LLVector2(0.f, 0.f); + constexpr LLVector2 TEX01 = LLVector2(0.f, 1.f); + constexpr LLVector2 TEX10 = LLVector2(1.f, 0.f); + constexpr LLVector2 TEX11 = LLVector2(1.f, 1.f); LLTrace::BlockTimerStatHandle FTM_VOSKY_UPDATETIMER("VOSky Update Timer Tick"); LLTrace::BlockTimerStatHandle FTM_VOSKY_CALC("VOSky Update Calculations"); LLTrace::BlockTimerStatHandle FTM_VOSKY_CREATETEXTURES("VOSky Update Textures"); LLTrace::BlockTimerStatHandle FTM_VOSKY_UPDATEFORCED("VOSky Update Forced"); - F32Seconds UPDATE_EXPRY(0.25f); + constexpr F32Seconds UPDATE_EXPRY(0.25f); - const F32 UPDATE_MIN_DELTA_THRESHOLD = 0.0005f; + constexpr F32 UPDATE_MIN_DELTA_THRESHOLD = 0.0005f; } /*************************************** SkyTex ***************************************/ -S32 LLSkyTex::sComponents = 4; -S32 LLSkyTex::sResolution = 64; S32 LLSkyTex::sCurrent = 0; - LLSkyTex::LLSkyTex() : mSkyData(NULL), mSkyDirs(NULL), @@ -107,14 +104,14 @@ LLSkyTex::LLSkyTex() : void LLSkyTex::init(bool isShiny) { mIsShiny = isShiny; - mSkyData = new LLColor4[sResolution * sResolution]; - mSkyDirs = new LLVector3[sResolution * sResolution]; + mSkyData = new LLColor4[SKYTEX_RES * SKYTEX_RES]; + mSkyDirs = new LLVector3[SKYTEX_RES * SKYTEX_RES]; for (S32 i = 0; i < 2; ++i) { mTexture[i] = LLViewerTextureManager::getLocalTexture(FALSE); mTexture[i]->setAddressMode(LLTexUnit::TAM_CLAMP); - mImageRaw[i] = new LLImageRaw(sResolution, sResolution, sComponents); + mImageRaw[i] = new LLImageRaw(SKYTEX_RES, SKYTEX_RES, SKYTEX_COMPONENTS); initEmpty(i); } @@ -146,7 +143,7 @@ LLSkyTex::~LLSkyTex() S32 LLSkyTex::getResolution() { - return sResolution; + return SKYTEX_RES; } S32 LLSkyTex::getCurrent() @@ -174,12 +171,12 @@ S32 LLSkyTex::getWhich(const BOOL curr) void LLSkyTex::initEmpty(const S32 tex) { U8* data = mImageRaw[tex]->getData(); - for (S32 i = 0; i < sResolution; ++i) + for (S32 i = 0; i < SKYTEX_RES; ++i) { - for (S32 j = 0; j < sResolution; ++j) + for (S32 j = 0; j < SKYTEX_RES; ++j) { - const S32 basic_offset = (i * sResolution + j); - S32 offset = basic_offset * sComponents; + const S32 basic_offset = (i * SKYTEX_RES + j); + S32 offset = basic_offset * SKYTEX_COMPONENTS; data[offset] = 0; data[offset+1] = 0; data[offset+2] = 0; @@ -195,12 +192,12 @@ void LLSkyTex::initEmpty(const S32 tex) void LLSkyTex::create() { U8* data = mImageRaw[sCurrent]->getData(); - for (S32 i = 0; i < sResolution; ++i) + for (S32 i = 0; i < SKYTEX_RES; ++i) { - for (S32 j = 0; j < sResolution; ++j) + for (S32 j = 0; j < SKYTEX_RES; ++j) { - const S32 basic_offset = (i * sResolution + j); - S32 offset = basic_offset * sComponents; + const S32 basic_offset = (i * SKYTEX_RES + j); + S32 offset = basic_offset * SKYTEX_COMPONENTS; U32* pix = (U32*)(data + offset); LLColor4U temp = LLColor4U(mSkyData[basic_offset]); *pix = temp.asRGBA(); @@ -397,10 +394,12 @@ const LLVector3* LLHeavenBody::corners() const Sky ***************************************/ - -S32 LLVOSky::sResolution = LLSkyTex::getResolution(); -S32 LLVOSky::sTileResX = sResolution/NUM_TILES_X; -S32 LLVOSky::sTileResY = sResolution/NUM_TILES_Y; +namespace +{ + constexpr S32 VOSKY_RES = SKYTEX_RES; + constexpr S32 VOSKY_TILE_RES_X = VOSKY_RES / NUM_TILES_X; + constexpr S32 VOSKY_TILE_RES_Y = VOSKY_RES / NUM_TILES_Y; +} LLVOSky::LLVOSky(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) : LLStaticViewerObject(id, pcode, regionp, TRUE), @@ -600,8 +599,8 @@ void LLVOSky::initSkyTextureDirs(const S32 side, const S32 tile) S32 tile_x = tile % NUM_TILES_X; S32 tile_y = tile / NUM_TILES_X; - S32 tile_x_pos = tile_x * sTileResX; - S32 tile_y_pos = tile_y * sTileResY; + S32 tile_x_pos = tile_x * VOSKY_TILE_RES_X; + S32 tile_y_pos = tile_y * VOSKY_TILE_RES_Y; F32 coeff[3] = {0, 0, 0}; const S32 curr_coef = side >> 1; // 0/1 = Z axis, 2/3 = Y, 4/5 = X @@ -611,11 +610,11 @@ void LLVOSky::initSkyTextureDirs(const S32 side, const S32 tile) coeff[curr_coef] = (F32)side_dir; - F32 inv_res = 1.f/sResolution; + F32 inv_res = 1.f/ VOSKY_RES; S32 x, y; - for (y = tile_y_pos; y < (tile_y_pos + sTileResY); ++y) + for (y = tile_y_pos; y < (tile_y_pos + VOSKY_TILE_RES_Y); ++y) { - for (x = tile_x_pos; x < (tile_x_pos + sTileResX); ++x) + for (x = tile_x_pos; x < (tile_x_pos + VOSKY_TILE_RES_X); ++x) { coeff[x_coef] = F32((x<<1) + 1) * inv_res - 1.f; coeff[y_coef] = F32((y<<1) + 1) * inv_res - 1.f; @@ -632,13 +631,13 @@ void LLVOSky::createSkyTexture(const LLSettingsSky::ptr_t& psky, AtmosphericsVar S32 tile_x = tile % NUM_TILES_X; S32 tile_y = tile / NUM_TILES_X; - S32 tile_x_pos = tile_x * sTileResX; - S32 tile_y_pos = tile_y * sTileResY; + S32 tile_x_pos = tile_x * VOSKY_TILE_RES_X; + S32 tile_y_pos = tile_y * VOSKY_TILE_RES_Y; S32 x, y; - for (y = tile_y_pos; y < (tile_y_pos + sTileResY); ++y) + for (y = tile_y_pos; y < (tile_y_pos + VOSKY_TILE_RES_Y); ++y) { - for (x = tile_x_pos; x < (tile_x_pos + sTileResX); ++x) + for (x = tile_x_pos; x < (tile_x_pos + VOSKY_TILE_RES_X); ++x) { mSkyTex[side].setPixel(m_legacyAtmospherics.calcSkyColorInDir(psky, vars, mSkyTex[side].getDir(x, y), false), x, y); mShinyTex[side].setPixel(m_legacyAtmospherics.calcSkyColorInDir(psky, vars, mShinyTex[side].getDir(x, y), true), x, y); diff --git a/indra/newview/llvosky.h b/indra/newview/llvosky.h index db65e3217d7b3e338e6c9f4554190d1a9a0493c1..ea863384b5164a0136320042935605f09998bfa5 100644 --- a/indra/newview/llvosky.h +++ b/indra/newview/llvosky.h @@ -38,10 +38,16 @@ #include "llsettingssky.h" #include "lllegacyatmospherics.h" -const F32 SKY_BOX_MULT = 16.0f; -const F32 HEAVENLY_BODY_DIST = HORIZON_DIST - 20.f; -const F32 HEAVENLY_BODY_FACTOR = 0.1f; -const F32 HEAVENLY_BODY_SCALE = HEAVENLY_BODY_DIST * HEAVENLY_BODY_FACTOR; +namespace +{ + constexpr F32 SKY_BOX_MULT = 16.0f; + constexpr F32 HEAVENLY_BODY_DIST = HORIZON_DIST - 20.f; + constexpr F32 HEAVENLY_BODY_FACTOR = 0.1f; + constexpr F32 HEAVENLY_BODY_SCALE = HEAVENLY_BODY_DIST * HEAVENLY_BODY_FACTOR; + + constexpr S32 SKYTEX_COMPONENTS = 4; + constexpr S32 SKYTEX_RES = 64; +} class LLEnvironment; class LLFace; @@ -51,8 +57,6 @@ class LLSkyTex { friend class LLVOSky; private: - static S32 sResolution; - static S32 sComponents; LLPointer<LLViewerTexture> mTexture[2]; LLPointer<LLImageRaw> mImageRaw[2]; LLColor4 *mSkyData; @@ -83,25 +87,25 @@ class LLSkyTex void setDir(const LLVector3 &dir, const S32 i, const S32 j) { - S32 offset = i * sResolution + j; + S32 offset = i * SKYTEX_RES + j; mSkyDirs[offset] = dir; } const LLVector3 &getDir(const S32 i, const S32 j) const { - S32 offset = i * sResolution + j; + S32 offset = i * SKYTEX_RES + j; return mSkyDirs[offset]; } void setPixel(const LLColor4 &col, const S32 i, const S32 j) { - S32 offset = i * sResolution + j; + S32 offset = i * SKYTEX_RES + j; mSkyData[offset] = col; } void setPixel(const LLColor4U &col, const S32 i, const S32 j) { - S32 offset = (i * sResolution + j) * sComponents; + S32 offset = (i * SKYTEX_RES + j) * SKYTEX_COMPONENTS; U32* pix = (U32*) &(mImageRaw[sCurrent]->getData()[offset]); *pix = col.asRGBA(); } @@ -109,7 +113,7 @@ class LLSkyTex LLColor4U getPixel(const S32 i, const S32 j) { LLColor4U col; - S32 offset = (i * sResolution + j) * sComponents; + S32 offset = (i * SKYTEX_RES + j) * SKYTEX_COMPONENTS; U32* pix = (U32*) &(mImageRaw[sCurrent]->getData()[offset]); col.fromRGBA( *pix ); return col; @@ -316,9 +320,6 @@ class LLVOSky final : public LLStaticViewerObject F32 mSunScale = 1.0f; F32 mMoonScale = 1.0f; - static S32 sResolution; - static S32 sTileResX; - static S32 sTileResY; LLSkyTex mSkyTex[6]; LLSkyTex mShinyTex[6]; LLHeavenBody mSun; diff --git a/indra/newview/llvowlsky.cpp b/indra/newview/llvowlsky.cpp index 6ea91fbfc7d98fe5e98e57ad1433c1e3c631d5e0..4ff2300bffd42e45dc425dbe03ccce19fbdac8f8 100644 --- a/indra/newview/llvowlsky.cpp +++ b/indra/newview/llvowlsky.cpp @@ -36,8 +36,8 @@ #include "llenvironment.h" #include "llsettingssky.h" -static const U32 MIN_SKY_DETAIL = 8; -static const U32 MAX_SKY_DETAIL = 180; +constexpr U32 MIN_SKY_DETAIL = 8; +constexpr U32 MAX_SKY_DETAIL = 180; inline U32 LLVOWLSky::getNumStacks(void) {