diff options
Diffstat (limited to 'indra/llrender')
| -rw-r--r-- | indra/llrender/CMakeLists.txt | 12 | ||||
| -rw-r--r-- | indra/llrender/llatmosphere.cpp | 221 | ||||
| -rw-r--r-- | indra/llrender/llatmosphere.h | 72 | ||||
| -rw-r--r-- | indra/llrender/llgl.cpp | 15 | ||||
| -rw-r--r-- | indra/llrender/llglslshader.cpp | 326 | ||||
| -rw-r--r-- | indra/llrender/llglslshader.h | 35 | ||||
| -rw-r--r-- | indra/llrender/llgltexture.cpp | 198 | ||||
| -rw-r--r-- | indra/llrender/llgltexture.h | 10 | ||||
| -rw-r--r-- | indra/llrender/llimagegl.cpp | 39 | ||||
| -rw-r--r-- | indra/llrender/llimagegl.h | 9 | ||||
| -rw-r--r-- | indra/llrender/llrender.cpp | 4 | ||||
| -rw-r--r-- | indra/llrender/llrender.h | 10 | ||||
| -rw-r--r-- | indra/llrender/llshadermgr.cpp | 32 | ||||
| -rw-r--r-- | indra/llrender/llshadermgr.h | 18 | ||||
| -rw-r--r-- | indra/llrender/lltexture.cpp | 12 | ||||
| -rw-r--r-- | indra/llrender/lltexture.h | 22 | 
16 files changed, 694 insertions, 341 deletions
| diff --git a/indra/llrender/CMakeLists.txt b/indra/llrender/CMakeLists.txt index 331f988382..26aaf10d07 100644 --- a/indra/llrender/CMakeLists.txt +++ b/indra/llrender/CMakeLists.txt @@ -13,6 +13,7 @@ include(LLVFS)  include(LLWindow)  include(LLXML)  include(LLVFS) +include(Atmosphere)  include_directories(      ${FREETYPE_INCLUDE_DIRS} @@ -24,6 +25,7 @@ include_directories(      ${LLWINDOW_INCLUDE_DIRS}      ${LLXML_INCLUDE_DIRS}      ${LLVFS_INCLUDE_DIRS} +    ${ATMOSPHERE_INCLUDE_DIR}      )  include_directories(SYSTEM      ${LLCOMMON_SYSTEM_INCLUDE_DIRS} @@ -31,6 +33,7 @@ include_directories(SYSTEM      )  set(llrender_SOURCE_FILES +    llatmosphere.cpp      llcubemap.cpp      llfontbitmapcache.cpp      llfontfreetype.cpp @@ -56,6 +59,7 @@ set(llrender_SOURCE_FILES  set(llrender_HEADER_FILES      CMakeLists.txt +    llatmosphere.h      llcubemap.h      llfontgl.h      llfontfreetype.h @@ -103,7 +107,9 @@ if (BUILD_HEADLESS)      ${LLXML_LIBRARIES}      ${LLVFS_LIBRARIES}      ${LLWINDOW_HEADLESS_LIBRARIES} -    ${OPENGL_HEADLESS_LIBRARIES}) +    ${LIBATMOSPHERE_LIBRARIES} +    ${OPENGL_HEADLESS_LIBRARIES} +    )  endif (BUILD_HEADLESS) @@ -126,5 +132,7 @@ target_link_libraries(llrender      ${LLVFS_LIBRARIES}      ${LLWINDOW_LIBRARIES}      ${FREETYPE_LIBRARIES} -    ${OPENGL_LIBRARIES}) +    ${LIBATMOSPHERE_LIBRARIES} +    ${OPENGL_LIBRARIES} +    ) diff --git a/indra/llrender/llatmosphere.cpp b/indra/llrender/llatmosphere.cpp new file mode 100644 index 0000000000..6ce5292839 --- /dev/null +++ b/indra/llrender/llatmosphere.cpp @@ -0,0 +1,221 @@ +/**  + * @file llatmosphere.cpp + * @brief LLAtmosphere integration impl + * + * $LicenseInfo:firstyear=2018&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2018, Linden Research, Inc. + *  + * 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. + *  + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA + *  + * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" + +#include "llatmosphere.h" +#include "llfasttimer.h" +#include "llsys.h" +#include "llglheaders.h" +#include "llrender.h" +#include "llshadermgr.h" +#include "llglslshader.h" + +LLAtmosphere* gAtmosphere = nullptr; + +void LLAtmosphere::initClass() +{ +    if (!gAtmosphere) +    {  +        gAtmosphere = new LLAtmosphere;  +    } +} + +void LLAtmosphere::cleanupClass() +{ +    if(gAtmosphere) +    { +        delete gAtmosphere; +    } +    gAtmosphere = NULL; +} + +LLAtmosphere::LLAtmosphere() +{ +    // Init libatmosphere model +    m_config.num_scattering_orders = 4; + +    // Values from "Reference Solar Spectral Irradiance: ASTM G-173", ETR column +    // (see http://rredc.nrel.gov/solar/spectra/am1.5/ASTMG173/ASTMG173.html), +    // summed and averaged in each bin (e.g. the value for 360nm is the average +    // of the ASTM G-173 values for all wavelengths between 360 and 370nm). +    // Values in W.m^-2. +    const int kLambdaMin = 360; +    const int kLambdaMax = 830; +    const double kSolarIrradiance[48] = { +        1.11776, 1.14259, 1.01249, 1.14716, 1.72765, 1.73054, 1.6887, 1.61253, +        1.91198, 2.03474, 2.02042, 2.02212, 1.93377, 1.95809, 1.91686, 1.8298, +        1.8685, 1.8931, 1.85149, 1.8504, 1.8341, 1.8345, 1.8147, 1.78158, 1.7533, +        1.6965, 1.68194, 1.64654, 1.6048, 1.52143, 1.55622, 1.5113, 1.474, 1.4482, +        1.41018, 1.36775, 1.34188, 1.31429, 1.28303, 1.26758, 1.2367, 1.2082, +        1.18737, 1.14683, 1.12362, 1.1058, 1.07124, 1.04992 +    }; + +    // Values from http://www.iup.uni-bremen.de/gruppen/molspec/databases/ +    // referencespectra/o3spectra2011/index.html for 233K, summed and averaged in +    // each bin (e.g. the value for 360nm is the average of the original values +    // for all wavelengths between 360 and 370nm). Values in m^2. +    const double kOzoneCrossSection[48] = { +        1.18e-27, 2.182e-28, 2.818e-28, 6.636e-28, 1.527e-27, 2.763e-27, 5.52e-27, +        8.451e-27, 1.582e-26, 2.316e-26, 3.669e-26, 4.924e-26, 7.752e-26, 9.016e-26, +        1.48e-25, 1.602e-25, 2.139e-25, 2.755e-25, 3.091e-25, 3.5e-25, 4.266e-25, +        4.672e-25, 4.398e-25, 4.701e-25, 5.019e-25, 4.305e-25, 3.74e-25, 3.215e-25, +        2.662e-25, 2.238e-25, 1.852e-25, 1.473e-25, 1.209e-25, 9.423e-26, 7.455e-26, +        6.566e-26, 5.105e-26, 4.15e-26, 4.228e-26, 3.237e-26, 2.451e-26, 2.801e-26, +        2.534e-26, 1.624e-26, 1.465e-26, 2.078e-26, 1.383e-26, 7.105e-27 +    }; + +    // From https://en.wikipedia.org/wiki/Dobson_unit, in molecules.m^-2. +    const double kDobsonUnit = 2.687e20; + +    // Maximum number density of ozone molecules, in m^-3 (computed so at to get +    // 300 Dobson units of ozone - for this we divide 300 DU by the integral of +    // the ozone density profile defined below, which is equal to 15km). +    const double kMaxOzoneNumberDensity = 300.0 * kDobsonUnit / 15000.0; +  +    const double kSunAngularRadius = 0.00935 / 2.0; +    const double kBottomRadius = 6360000.0; +    const double kTopRadius = 6420000.0; +    const double kRayleigh = 1.24062e-6; +    const double kRayleighScaleHeight = 8000.0; +    const double kMieScaleHeight = 1200.0; +    const double kMieAngstromAlpha = 0.0; +    const double kMieAngstromBeta = 5.328e-3; +    const double kMieSingleScatteringAlbedo = 0.9; +    const double kMiePhaseFunctionG = 0.8; +    const double max_sun_zenith_angle = F_PI * 2.0 / 3.0; + +    atmosphere::DensityProfileLayer rayleigh_density(0.0, 1.0, -1.0 / kRayleighScaleHeight, 0.0, 0.0); +    atmosphere::DensityProfileLayer mie_density(0.0, 1.0, -1.0 / kMieScaleHeight, 0.0, 0.0); + +    // Density profile increasing linearly from 0 to 1 between 10 and 25km, and +    // decreasing linearly from 1 to 0 between 25 and 40km. This is an approximate +    // profile from http://www.kln.ac.lk/science/Chemistry/Teaching_Resources/ +    // Documents/Introduction%20to%20atmospheric%20chemistry.pdf (page 10). +    std::vector<atmosphere::DensityProfileLayer> ozone_density; +    ozone_density.push_back(atmosphere::DensityProfileLayer(25000.0, 0.0, 0.0, 1.0 / 15000.0, -2.0 / 3.0)); +    ozone_density.push_back(atmosphere::DensityProfileLayer(0.0, 0.0, 0.0, -1.0 / 15000.0, 8.0 / 3.0)); + +    std::vector<double> wavelengths; +    std::vector<double> solar_irradiance; +    std::vector<double> rayleigh_scattering; +    std::vector<double> mie_scattering; +    std::vector<double> mie_extinction; +    std::vector<double> absorption_extinction; +    std::vector<double> ground_albedo; + +    for (int l = kLambdaMin; l <= kLambdaMax; l += 10) +    { +        double lambda = static_cast<double>(l) * 1e-3;  // micro-meters +        double mie    = kMieAngstromBeta / kMieScaleHeight * pow(lambda, -kMieAngstromAlpha); +        wavelengths.push_back(l); +        solar_irradiance.push_back(kSolarIrradiance[(l - kLambdaMin) / 10]); +        rayleigh_scattering.push_back(kRayleigh * pow(lambda, -4)); +        mie_scattering.push_back(mie * kMieSingleScatteringAlbedo); +        mie_extinction.push_back(mie); +        absorption_extinction.push_back(kMaxOzoneNumberDensity * kOzoneCrossSection[(l - kLambdaMin) / 10]); +        ground_albedo.push_back(0.1f); +    } + +    m_model = new atmosphere::Model( +                                wavelengths, +                                solar_irradiance, +                                kSunAngularRadius, +                                kBottomRadius, +                                kTopRadius, +                                {rayleigh_density}, +                                rayleigh_scattering, +                                {mie_density}, +                                mie_scattering, +                                mie_extinction, +                                kMiePhaseFunctionG, +                                ozone_density, +                                absorption_extinction, +                                ground_albedo, +                                max_sun_zenith_angle, +                                1000.0,    +                                15, +                                false, +                                true); + +    m_model->Init(m_config, m_textures); + +    m_transmittance  = new LLGLTexture; +    m_scattering     = new LLGLTexture; +    m_mie_scattering = new LLGLTexture; + +    m_transmittance->generateGLTexture(); +    m_transmittance->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); +    m_transmittance->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); +    m_transmittance->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); +    m_transmittance->setTexName(m_textures.transmittance_texture); +    m_transmittance->setTarget(GL_TEXTURE_2D, LLTexUnit::TT_TEXTURE); + +    m_scattering->generateGLTexture(); +    m_scattering->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); +    m_scattering->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); +    m_scattering->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); +    m_scattering->setTexName(m_textures.transmittance_texture); +    m_scattering->setTarget(GL_TEXTURE_3D, LLTexUnit::TT_TEXTURE_3D); + +    m_mie_scattering->generateGLTexture(); +    m_mie_scattering->setAddressMode(LLTexUnit::eTextureAddressMode::TAM_CLAMP); +    m_mie_scattering->setFilteringOption(LLTexUnit::eTextureFilterOptions::TFO_BILINEAR); +    m_mie_scattering->setExplicitFormat(GL_RGB16F_ARB, GL_RGB, GL_FLOAT); +    m_mie_scattering->setTexName(m_textures.transmittance_texture); +    m_mie_scattering->setTarget(GL_TEXTURE_3D, LLTexUnit::TT_TEXTURE_3D); +}; + +LLAtmosphere::~LLAtmosphere() +{ +    // Cease referencing textures from atmosphere::model from our LLGLTextures wrappers for same. +    m_transmittance->setTexName(0); +    m_scattering->setTexName(0); +    m_mie_scattering->setTexName(0); + +    delete m_model; +    m_model = nullptr; +} + +LLGLTexture* LLAtmosphere::getTransmittance() const +{ +    return m_transmittance; +} + +LLGLTexture* LLAtmosphere::getScattering() const +{ +    return m_scattering; +} + +LLGLTexture* LLAtmosphere::getMieScattering() const +{ +    return m_mie_scattering; +} + +GLhandleARB LLAtmosphere::getAtmosphericShaderForLink() const +{ +    return m_model ? m_model->GetShader() : 0; +} diff --git a/indra/llrender/llatmosphere.h b/indra/llrender/llatmosphere.h new file mode 100644 index 0000000000..6a9d1a4438 --- /dev/null +++ b/indra/llrender/llatmosphere.h @@ -0,0 +1,72 @@ +/**  + * @file llatmosphere.h + * @brief LLAtmosphere class for integration with libatmosphere + * + * $LicenseInfo:firstyear=2018&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2018, Linden Research, Inc. + *  + * 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. + *  + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA + *  + * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA + * $/LicenseInfo$ + */ + +#ifndef LL_ATMOSPHERE_H +#define LL_ATMOSPHERE_H + +#include "llglheaders.h" +#include "llgltexture.h" +#include "libatmosphere/model.h" + +class LLAtmosphere +{ +public: +     LLAtmosphere(); +    ~LLAtmosphere(); + +    static void initClass(); +    static void cleanupClass(); + +    const LLAtmosphere& operator=(const LLAtmosphere& rhs) +    { +        LL_ERRS() << "Illegal operation!" << LL_ENDL; +        return *this; +    } + +    LLGLTexture* getTransmittance() const; +    LLGLTexture* getScattering() const; +    LLGLTexture* getMieScattering() const; + +    GLhandleARB getAtmosphericShaderForLink() const; + +protected:     +    LLAtmosphere(const LLAtmosphere& rhs) +    { +        *this = rhs; +    } + +    atmosphere::ModelConfig         m_config;     +    atmosphere::PrecomputedTextures m_textures; +    atmosphere::Model*              m_model = nullptr; + +    LLPointer<LLGLTexture> m_transmittance; +    LLPointer<LLGLTexture> m_scattering; +    LLPointer<LLGLTexture> m_mie_scattering; +}; + +extern LLAtmosphere* gAtmosphere; + +#endif // LL_ATMOSPHERE_H diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index 155c2402bd..2f78b6e104 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -1348,8 +1348,19 @@ void LLGLManager::initExtensions()  	if (mHasVertexShader)  	{  		LL_INFOS() << "initExtensions() VertexShader-related procs..." << LL_ENDL; -		glGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetAttribLocationARB"); -		glBindAttribLocationARB = (PFNGLBINDATTRIBLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glBindAttribLocationARB"); + +        // nSight doesn't support use of ARB funcs that have been normalized in the API +        if (!LLRender::sNsightDebugSupport) +        { +		    glGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetAttribLocationARB"); +		    glBindAttribLocationARB = (PFNGLBINDATTRIBLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glBindAttribLocationARB"); +        } +        else +        { +            glGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGetAttribLocation"); +            glBindAttribLocationARB = (PFNGLBINDATTRIBLOCATIONARBPROC)GLH_EXT_GET_PROC_ADDRESS("glBindAttribLocation"); +        } +  		glGetActiveAttribARB = (PFNGLGETACTIVEATTRIBARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetActiveAttribARB");  		glVertexAttrib1dARB = (PFNGLVERTEXATTRIB1DARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1dARB");  		glVertexAttrib1dvARB = (PFNGLVERTEXATTRIB1DVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1dvARB"); diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index 970502f2d6..b09ec53bc0 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -154,8 +154,7 @@ void LLGLSLShader::clearStats()      mSamplesDrawn = 0;      mDrawCalls = 0;      mTextureStateFetched = false; -    mTextureMagFilter.clear(); -    mTextureMinFilter.clear(); +    mTextureMagMinFilter.clear();  }  void LLGLSLShader::dumpStats() @@ -168,14 +167,16 @@ void LLGLSLShader::dumpStats()          {              LL_INFOS() << mShaderFiles[i].first << LL_ENDL;          } -        for (U32 i = 0; i < mTexture.size(); ++i) +        for (uniforms_index_t::iterator it = mTexture.begin(); it != mTexture.end(); ++it)          { -            GLint idx = mTexture[i]; +            S32 i = (*it).first; +            GLint idx = (*it).second;              if (idx >= 0)              {                  GLint uniform_idx = getUniformLocation(i); -                LL_INFOS() << mUniformNameMap[uniform_idx] << " - " << std::hex << mTextureMagFilter[i] << "/" << mTextureMinFilter[i] << std::dec << LL_ENDL; +                magmin_filter_t::iterator it = mTextureMagMinFilter.find(i); +                LL_INFOS() << mUniformNameMap[uniform_idx] << " - " << std::hex << (*it).second.second << "/" << (*it).second.first << std::dec << LL_ENDL;              }          }          LL_INFOS() << "=============================================" << LL_ENDL; @@ -232,14 +233,13 @@ void LLGLSLShader::placeProfileQuery()      if (!mTextureStateFetched)      {          mTextureStateFetched = true; -        mTextureMagFilter.resize(mTexture.size()); -        mTextureMinFilter.resize(mTexture.size());          U32 cur_active = gGL.getCurrentTexUnitIndex(); -        for (U32 i = 0; i < mTexture.size(); ++i) +        for (uniforms_index_t::iterator it = mTexture.begin(); it != mTexture.end(); ++it)          { -            GLint idx = mTexture[i]; +            S32 i = (*it).first; +            GLint idx = (*it).second;              if (idx >= 0)              { @@ -253,8 +253,7 @@ void LLGLSLShader::placeProfileQuery()                  glGetTexParameteriv(type, GL_TEXTURE_MAG_FILTER, (GLint*) &mag);                  glGetTexParameteriv(type, GL_TEXTURE_MIN_FILTER, (GLint*) &min); -                mTextureMagFilter[i] = mag; -                mTextureMinFilter[i] = min; +                mTextureMagMinFilter[i] = magmin_values_t(mag, min);              }          } @@ -402,12 +401,17 @@ BOOL LLGLSLShader::createShader(std::vector<LLStaticHashedString> * attributes,      mDefines["OLD_SELECT"] = "1";  #endif +    if (mExtraLinkObject) +    { +        attachObject(mExtraLinkObject); +    } +      //compile new source      vector< pair<string,GLenum> >::iterator fileIter = mShaderFiles.begin();      for ( ; fileIter != mShaderFiles.end(); fileIter++ )      {          GLhandleARB shaderhandle = LLShaderMgr::instance()->loadShaderFile((*fileIter).first, mShaderLevel, (*fileIter).second, &mDefines, mFeatures.mIndexedTextureChannels); -        LL_DEBUGS("ShaderLoading") << "SHADER FILE: " << (*fileIter).first << " mShaderLevel=" << mShaderLevel << LL_ENDL; +        LL_DEBUGS("ShaderLoading") << "SHADER FILE: " << (*fileIter).first << " mShaderLevel=" << mShaderLevel << " shaderhandle=" << shaderhandle << LL_ENDL;          if (shaderhandle)          {              attachObject(shaderhandle); @@ -470,13 +474,14 @@ BOOL LLGLSLShader::createShader(std::vector<LLStaticHashedString> * attributes,          }          S32 cur_tex = channel_count; //adjust any texture channels that might have been overwritten -        for (U32 i = 0; i < mTexture.size(); i++) +        for (uniforms_index_t::iterator it = mTexture.begin(); it != mTexture.end(); ++it)          { -            if (mTexture[i] > -1 && mTexture[i] < channel_count) +            int i = (*it).first; +            if (((*it).second >= 0) && ((*it).second < channel_count))              {                  llassert(cur_tex < gGLManager.mNumTextureImageUnits);                  uniform1i(i, cur_tex); -                mTexture[i] = cur_tex++; +                (*it).second = cur_tex++;              }          }          unbind(); @@ -655,13 +660,16 @@ void LLGLSLShader::mapUniform(GLint index, const vector<LLStaticHashedString> *          //find the index of this uniform          for (S32 i = 0; i < (S32) LLShaderMgr::instance()->mReservedUniforms.size(); i++)          { -            if ( (mUniform[i] == -1) -                && (LLShaderMgr::instance()->mReservedUniforms[i] == name)) +            if (LLShaderMgr::instance()->mReservedUniforms[i] == name)              { -                //found it -                mUniform[i] = location; -                mTexture[i] = mapUniformTextureChannel(location, type); -                return; +                std::pair<uniforms_index_t::iterator, bool> result; + +                result = mUniform.insert(uniforms_index_t::value_type(i, location)); +                if (result.second) +                { +                    mTexture[i] = mapUniformTextureChannel(location, type); +                    return; +                }              }          } @@ -669,13 +677,17 @@ void LLGLSLShader::mapUniform(GLint index, const vector<LLStaticHashedString> *          {              for (U32 i = 0; i < uniforms->size(); i++)              { -                if ( (mUniform[i+LLShaderMgr::instance()->mReservedUniforms.size()] == -1) -                    && ((*uniforms)[i].String() == name)) +                std::pair<uniforms_index_t::iterator, bool> result; +                S32 index = i + LLShaderMgr::instance()->mReservedUniforms.size(); + +                if ((*uniforms)[i].String() == name)                  { -                    //found it -                    mUniform[i+LLShaderMgr::instance()->mReservedUniforms.size()] = location; -                    mTexture[i+LLShaderMgr::instance()->mReservedUniforms.size()] = mapUniformTextureChannel(location, type); -                    return; +                    result = mUniform.insert(uniforms_index_t::value_type(index, location)); +                    if (result.second) +                    { +                        mTexture[index] = mapUniformTextureChannel(location, type); +                        return; +                    }                  }              }          } @@ -715,10 +727,6 @@ BOOL LLGLSLShader::mapUniforms(const vector<LLStaticHashedString> * uniforms)  	mUniformNameMap.clear();  	mTexture.clear();  	mValue.clear(); -	//initialize arrays -	U32 numUniforms = (uniforms == NULL) ? 0 : uniforms->size(); -	mUniform.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1); -	mTexture.resize(numUniforms + LLShaderMgr::instance()->mReservedUniforms.size(), -1);  	bind(); @@ -910,20 +918,14 @@ S32 LLGLSLShader::bindTexture(const std::string &uniform, LLTexture *texture, LL  S32 LLGLSLShader::bindTexture(S32 uniform, LLTexture *texture, LLTexUnit::eTextureType mode)  { -    if (uniform < 0 || uniform >= (S32)mTexture.size()) -    { -        UNIFORM_ERRS << "Uniform out of range: " << uniform << LL_ENDL; -        return -1; -    } +    GLint channel = getTexChannelForIndex(uniform); -    uniform = mTexture[uniform]; -     -    if (uniform > -1) +    if (channel > -1)      { -        gGL.getTexUnit(uniform)->bind(texture, mode); +        gGL.getTexUnit(channel)->bind(texture, mode);      } -    return uniform; +    return channel;  }  S32 LLGLSLShader::unbindTexture(const std::string &uniform, LLTexUnit::eTextureType mode) @@ -936,82 +938,64 @@ S32 LLGLSLShader::unbindTexture(const std::string &uniform, LLTexUnit::eTextureT  S32 LLGLSLShader::unbindTexture(S32 uniform, LLTexUnit::eTextureType mode)  { -    if (uniform < 0 || uniform >= (S32)mTexture.size()) -    { -        UNIFORM_ERRS << "Uniform out of range: " << uniform << LL_ENDL; -        return -1; -    } -     -    uniform = mTexture[uniform]; -     -    if (uniform > -1) +    GLint channel = getTexChannelForIndex(uniform); + +    if (channel > -1)      { -        gGL.getTexUnit(uniform)->unbind(mode); +        gGL.getTexUnit(channel)->unbind(mode);      } -    return uniform; +    return channel;  }  S32 LLGLSLShader::enableTexture(S32 uniform, LLTexUnit::eTextureType mode)  { -    if (uniform < 0 || uniform >= (S32)mTexture.size()) -    { -        UNIFORM_ERRS << "Uniform out of range: " << uniform << LL_ENDL; -        return -1; -    } -    S32 index = mTexture[uniform]; -    if (index != -1) +    GLint channel = getTexChannelForIndex(uniform); + +    if (channel != -1)      { -        gGL.getTexUnit(index)->activate(); -        gGL.getTexUnit(index)->enable(mode); +        gGL.getTexUnit(channel)->activate(); +        gGL.getTexUnit(channel)->enable(mode);      } -    return index; +    return channel;  }  S32 LLGLSLShader::disableTexture(S32 uniform, LLTexUnit::eTextureType mode)  { -    if (uniform < 0 || uniform >= (S32)mTexture.size()) -    { -        UNIFORM_ERRS << "Uniform out of range: " << uniform << LL_ENDL; -        return -1; -    } -    S32 index = mTexture[uniform]; -    if (index != -1 && gGL.getTexUnit(index)->getCurrType() != LLTexUnit::TT_NONE) +    GLint channel = getTexChannelForIndex(uniform); + +    if (channel != -1 && gGL.getTexUnit(channel)->getCurrType() != LLTexUnit::TT_NONE)      { -        if (gDebugGL && gGL.getTexUnit(index)->getCurrType() != mode) +        if (gDebugGL && gGL.getTexUnit(channel)->getCurrType() != mode)          {              if (gDebugSession)              { -                gFailLog << "Texture channel " << index << " texture type corrupted." << std::endl; +                gFailLog << "Texture channel " << channel << " texture type corrupted." << std::endl;                  ll_fail("LLGLSLShader::disableTexture failed");              }              else              { -                LL_ERRS() << "Texture channel " << index << " texture type corrupted." << LL_ENDL; +                LL_ERRS() << "Texture channel " << channel << " texture type corrupted." << LL_ENDL;              }          } -        gGL.getTexUnit(index)->disable(); +        gGL.getTexUnit(channel)->disable();      } -    return index; +    return channel;  }  void LLGLSLShader::uniform1i(U32 index, GLint x)  {      if (mProgramObject)      {    -        if (mUniform.size() <= index) -        { -            UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; -            return; -        } +        GLint location = getLocationForIndex(index); -        if (mUniform[index] >= 0) +        if (location >= 0)          { -            std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]); +            std::map<GLint, LLVector4>::iterator iter = mValue.find(location);              if (iter == mValue.end() || iter->second.mV[0] != x)              { -                glUniform1iARB(mUniform[index], x); -                mValue[mUniform[index]] = LLVector4(x,0.f,0.f,0.f); +                glUniform1iARB(location, x); +                mValue[location] = LLVector4(x,0.f,0.f,0.f);              }          }      } @@ -1021,19 +1005,15 @@ void LLGLSLShader::uniform1f(U32 index, GLfloat x)  {      if (mProgramObject)      {    -        if (mUniform.size() <= index) -        { -            UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; -            return; -        } +        GLint location = getLocationForIndex(index); -        if (mUniform[index] >= 0) +        if (location >= 0)          { -            std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]); +            std::map<GLint, LLVector4>::iterator iter = mValue.find(location);              if (iter == mValue.end() || iter->second.mV[0] != x)              { -                glUniform1fARB(mUniform[index], x); -                mValue[mUniform[index]] = LLVector4(x,0.f,0.f,0.f); +                glUniform1fARB(location, x); +                mValue[location] = LLVector4(x,0.f,0.f,0.f);              }          }      } @@ -1043,20 +1023,16 @@ void LLGLSLShader::uniform2f(U32 index, GLfloat x, GLfloat y)  {      if (mProgramObject)      {    -        if (mUniform.size() <= index) -        { -            UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; -            return; -        } +        GLint location = getLocationForIndex(index); -        if (mUniform[index] >= 0) +        if (location >= 0)          { -            std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]); +            std::map<GLint, LLVector4>::iterator iter = mValue.find(location);              LLVector4 vec(x,y,0.f,0.f);              if (iter == mValue.end() || shouldChange(iter->second,vec))              { -                glUniform2fARB(mUniform[index], x, y); -                mValue[mUniform[index]] = vec; +                glUniform2fARB(location, x, y); +                mValue[location] = vec;              }          }      } @@ -1066,20 +1042,16 @@ void LLGLSLShader::uniform3f(U32 index, GLfloat x, GLfloat y, GLfloat z)  {      if (mProgramObject)      {    -        if (mUniform.size() <= index) -        { -            UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; -            return; -        } +        GLint location = getLocationForIndex(index); -        if (mUniform[index] >= 0) +        if (location >= 0)          { -            std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]); +            std::map<GLint, LLVector4>::iterator iter = mValue.find(location);              LLVector4 vec(x,y,z,0.f);              if (iter == mValue.end() || shouldChange(iter->second,vec))              { -                glUniform3fARB(mUniform[index], x, y, z); -                mValue[mUniform[index]] = vec; +                glUniform3fARB(location, x, y, z); +                mValue[location] = vec;              }          }      } @@ -1089,20 +1061,16 @@ void LLGLSLShader::uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat  {      if (mProgramObject)      {    -        if (mUniform.size() <= index) -        { -            UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; -            return; -        } +        GLint location = getLocationForIndex(index); -        if (mUniform[index] >= 0) +        if (location >= 0)          { -            std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]); +            std::map<GLint, LLVector4>::iterator iter = mValue.find(location);              LLVector4 vec(x,y,z,w);              if (iter == mValue.end() || shouldChange(iter->second,vec))              { -                glUniform4fARB(mUniform[index], x, y, z, w); -                mValue[mUniform[index]] = vec; +                glUniform4fARB(location, x, y, z, w); +                mValue[location] = vec;              }          }      } @@ -1112,20 +1080,16 @@ void LLGLSLShader::uniform1iv(U32 index, U32 count, const GLint* v)  {      if (mProgramObject)      {    -        if (mUniform.size() <= index) -        { -            UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; -            return; -        } +        GLint location = getLocationForIndex(index); -        if (mUniform[index] >= 0) +        if (location >= 0)          { -            std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]); +            std::map<GLint, LLVector4>::iterator iter = mValue.find(location);              LLVector4 vec(v[0],0.f,0.f,0.f);              if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1)              { -                glUniform1ivARB(mUniform[index], count, v); -                mValue[mUniform[index]] = vec; +                glUniform1ivARB(location, count, v); +                mValue[location] = vec;              }          }      } @@ -1135,20 +1099,16 @@ void LLGLSLShader::uniform1fv(U32 index, U32 count, const GLfloat* v)  {      if (mProgramObject)      {    -        if (mUniform.size() <= index) -        { -            UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; -            return; -        } +        GLint location = getLocationForIndex(index); -        if (mUniform[index] >= 0) +        if (location >= 0)          { -            std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]); +            std::map<GLint, LLVector4>::iterator iter = mValue.find(location);              LLVector4 vec(v[0],0.f,0.f,0.f);              if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1)              { -                glUniform1fvARB(mUniform[index], count, v); -                mValue[mUniform[index]] = vec; +                glUniform1fvARB(location, count, v); +                mValue[location] = vec;              }          }      } @@ -1158,20 +1118,16 @@ void LLGLSLShader::uniform2fv(U32 index, U32 count, const GLfloat* v)  {      if (mProgramObject)      {    -        if (mUniform.size() <= index) -        { -            UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; -            return; -        } +        GLint location = getLocationForIndex(index); -        if (mUniform[index] >= 0) +        if (location >= 0)          { -            std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]); +            std::map<GLint, LLVector4>::iterator iter = mValue.find(location);              LLVector4 vec(v[0],v[1],0.f,0.f);              if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1)              { -                glUniform2fvARB(mUniform[index], count, v); -                mValue[mUniform[index]] = vec; +                glUniform2fvARB(location, count, v); +                mValue[location] = vec;              }          }      } @@ -1181,20 +1137,16 @@ void LLGLSLShader::uniform3fv(U32 index, U32 count, const GLfloat* v)  {      if (mProgramObject)      {    -        if (mUniform.size() <= index) -        { -            UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; -            return; -        } +        GLint location = getLocationForIndex(index); -        if (mUniform[index] >= 0) +        if (location >= 0)          { -            std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]); +            std::map<GLint, LLVector4>::iterator iter = mValue.find(location);              LLVector4 vec(v[0],v[1],v[2],0.f);              if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1)              { -                glUniform3fvARB(mUniform[index], count, v); -                mValue[mUniform[index]] = vec; +                glUniform3fvARB(location, count, v); +                mValue[location] = vec;              }          }      } @@ -1204,20 +1156,16 @@ void LLGLSLShader::uniform4fv(U32 index, U32 count, const GLfloat* v)  {      if (mProgramObject)      {    -        if (mUniform.size() <= index) -        { -            UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; -            return; -        } +        GLint location = getLocationForIndex(index); -        if (mUniform[index] >= 0) +        if (location >= 0)          { -            std::map<GLint, LLVector4>::iterator iter = mValue.find(mUniform[index]); +            std::map<GLint, LLVector4>::iterator iter = mValue.find(location);              LLVector4 vec(v[0],v[1],v[2],v[3]);              if (iter == mValue.end() || shouldChange(iter->second,vec) || count != 1)              { -                glUniform4fvARB(mUniform[index], count, v); -                mValue[mUniform[index]] = vec; +                glUniform4fvARB(location, count, v); +                mValue[location] = vec;              }          }      } @@ -1227,15 +1175,11 @@ void LLGLSLShader::uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, c  {      if (mProgramObject)      {    -        if (mUniform.size() <= index) -        { -            UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; -            return; -        } +        GLint location = getLocationForIndex(index); -        if (mUniform[index] >= 0) +        if (location >= 0)          { -            glUniformMatrix2fvARB(mUniform[index], count, transpose, v); +            glUniformMatrix2fvARB(location, count, transpose, v);          }      }  } @@ -1244,15 +1188,11 @@ void LLGLSLShader::uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, c  {      if (mProgramObject)      {    -        if (mUniform.size() <= index) -        { -            UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; -            return; -        } +        GLint location = getLocationForIndex(index); -        if (mUniform[index] >= 0) +        if (location >= 0)          { -            glUniformMatrix3fvARB(mUniform[index], count, transpose, v); +            glUniformMatrix3fvARB(location, count, transpose, v);          }      }  } @@ -1261,15 +1201,11 @@ void LLGLSLShader::uniformMatrix3x4fv(U32 index, U32 count, GLboolean transpose,  {  	if (mProgramObject)  	{	 -		if (mUniform.size() <= index) -		{ -			UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; -			return; -		} +        GLint location = getLocationForIndex(index); -		if (mUniform[index] >= 0) +		if (location >= 0)  		{ -			glUniformMatrix3x4fv(mUniform[index], count, transpose, v); +			glUniformMatrix3x4fv(location, count, transpose, v);  		}  	}  } @@ -1278,15 +1214,11 @@ void LLGLSLShader::uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, c  {      if (mProgramObject)      {    -        if (mUniform.size() <= index) -        { -            UNIFORM_ERRS << "Uniform index out of bounds." << LL_ENDL; -            return; -        } +        GLint location = getLocationForIndex(index); -        if (mUniform[index] >= 0) +        if (location >= 0)          { -            glUniformMatrix4fvARB(mUniform[index], count, transpose, v); +            glUniformMatrix4fvARB(location, count, transpose, v);          }      }  } @@ -1317,14 +1249,8 @@ GLint LLGLSLShader::getUniformLocation(const LLStaticHashedString& uniform)  GLint LLGLSLShader::getUniformLocation(U32 index)  { -    GLint ret = -1; -    if (mProgramObject) -    { -        llassert(index < mUniform.size()); -        return mUniform[index]; -    } - -    return ret; +    /*TODO: flatten this... change calls to gUL(U32) */ +    return getLocationForIndex(index);  }  GLint LLGLSLShader::getAttribLocation(U32 attrib) diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index 6f10d122cb..a7a9e27fcd 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -166,14 +166,20 @@ public:  	U32 mMatHash[LLRender::NUM_MATRIX_MODES];  	U32 mLightHash; +    typedef std::map<S32, GLint> uniforms_index_t; +    typedef std::pair<U32, U32>  magmin_values_t; + +    typedef std::map < S32, magmin_values_t> magmin_filter_t; +  	GLhandleARB mProgramObject;  	std::vector<GLint> mAttribute; //lookup table of attribute enum to attribute channel  	U32 mAttributeMask;  //mask of which reserved attributes are set (lines up with LLVertexBuffer::getTypeMask()) -	std::vector<GLint> mUniform;   //lookup table of uniform enum to uniform location +    uniforms_index_t mUniform; +    uniforms_index_t mTexture; +  	LLStaticStringTable<GLint> mUniformMap; //lookup map of uniform name to uniform location  	std::map<GLint, std::string> mUniformNameMap; //lookup map of uniform location to uniform name  	std::map<GLint, LLVector4> mValue; //lookup map of uniform location to last known value -	std::vector<GLint> mTexture;  	S32 mTotalUniformSize;  	S32 mActiveTextureChannels;  	S32 mShaderLevel; @@ -197,11 +203,32 @@ public:  	static U32 sTotalDrawCalls;  	bool mTextureStateFetched; -	std::vector<U32> mTextureMagFilter; -	std::vector<U32> mTextureMinFilter; +    magmin_filter_t mTextureMagMinFilter; + +    GLhandleARB mExtraLinkObject = 0;  private:  	void unloadInternal(); + +    inline GLint getLocationForIndex(S32 index) +    { +        if (!mProgramObject) +            return -1; +        uniforms_index_t::iterator it = mUniform.find(index); +        if (it == mUniform.end()) +            return -1; +        return (*it).second; +    } + +    inline GLint getTexChannelForIndex(S32 index) +    { +        if (!mProgramObject) +            return -1; +        uniforms_index_t::iterator it = mTexture.find(index); +        if (it == mTexture.end()) +            return -1; +        return (*it).second; +    }  };  //UI shader (declared here so llui_libtest will link properly) diff --git a/indra/llrender/llgltexture.cpp b/indra/llrender/llgltexture.cpp index 3a6eebebba..c0e5477cea 100644 --- a/indra/llrender/llgltexture.cpp +++ b/indra/llrender/llgltexture.cpp @@ -30,20 +30,20 @@  // static  S32 LLGLTexture::getTotalNumOfCategories()   { -	return MAX_GL_IMAGE_CATEGORY - (BOOST_HIGH - BOOST_SCULPTED) + 2 ; +	return MAX_GL_IMAGE_CATEGORY - (BOOST_HIGH - BOOST_SCULPTED) + 2;  }  // static  //index starts from zero.  S32 LLGLTexture::getIndexFromCategory(S32 category)   { -	return (category < BOOST_HIGH) ? category : category - (BOOST_HIGH - BOOST_SCULPTED) + 1 ; +	return (category < BOOST_HIGH) ? category : category - (BOOST_HIGH - BOOST_SCULPTED) + 1;  }  //static   S32 LLGLTexture::getCategoryFromIndex(S32 index)  { -	return (index < BOOST_HIGH) ? index : index + (BOOST_HIGH - BOOST_SCULPTED) - 1 ; +	return (index < BOOST_HIGH) ? index : index + (BOOST_HIGH - BOOST_SCULPTED) - 1;  }  LLGLTexture::LLGLTexture(BOOL usemipmaps) @@ -55,19 +55,19 @@ LLGLTexture::LLGLTexture(BOOL usemipmaps)  LLGLTexture::LLGLTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps)  {  	init(); -	mFullWidth = width ; -	mFullHeight = height ; +	mFullWidth = width; +	mFullHeight = height;  	mUseMipMaps = usemipmaps; -	mComponents = components ; +	mComponents = components;  	setTexelsPerImage();  }  LLGLTexture::LLGLTexture(const LLImageRaw* raw, BOOL usemipmaps)  {  	init(); -	mUseMipMaps = usemipmaps ; +	mUseMipMaps = usemipmaps;  	// Create an empty image of the specified size and width -	mGLTexturep = new LLImageGL(raw, usemipmaps) ; +	mGLTexturep = new LLImageGL(raw, usemipmaps);  }  LLGLTexture::~LLGLTexture() @@ -81,13 +81,13 @@ void LLGLTexture::init()  	mFullWidth = 0;  	mFullHeight = 0; -	mTexelsPerImage = 0 ; -	mUseMipMaps = FALSE ; -	mComponents = 0 ; +	mTexelsPerImage = 0; +	mUseMipMaps = FALSE; +	mComponents = 0; -	mTextureState = NO_DELETE ; +	mTextureState = NO_DELETE;  	mDontDiscard = FALSE; -	mNeedsGLTexture = FALSE ; +	mNeedsGLTexture = FALSE;  }  void LLGLTexture::cleanup() @@ -111,287 +111,301 @@ void LLGLTexture::setBoostLevel(S32 level)  {  	if(mBoostLevel != level)  	{ -		mBoostLevel = level ; +		mBoostLevel = level;  		if(mBoostLevel != LLGLTexture::BOOST_NONE  		   && mBoostLevel != LLGLTexture::BOOST_ICON)  		{ -			setNoDelete() ;		 +			setNoDelete();		  		}  	}  }  void LLGLTexture::forceActive()  { -	mTextureState = ACTIVE ;  +	mTextureState = ACTIVE;   }  void LLGLTexture::setActive()   {   	if(mTextureState != NO_DELETE)  	{ -		mTextureState = ACTIVE ;  +		mTextureState = ACTIVE;   	}  }  //set the texture to stay in memory  void LLGLTexture::setNoDelete()   {  -	mTextureState = NO_DELETE ; +	mTextureState = NO_DELETE;  }  void LLGLTexture::generateGLTexture()   {	  	if(mGLTexturep.isNull())  	{ -		mGLTexturep = new LLImageGL(mFullWidth, mFullHeight, mComponents, mUseMipMaps) ; +		mGLTexturep = new LLImageGL(mFullWidth, mFullHeight, mComponents, mUseMipMaps);  	}  }  LLImageGL* LLGLTexture::getGLTexture() const  { -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); -	return mGLTexturep ; +	return mGLTexturep;  }  BOOL LLGLTexture::createGLTexture()   {  	if(mGLTexturep.isNull())  	{ -		generateGLTexture() ; +		generateGLTexture();  	} -	return mGLTexturep->createGLTexture() ; +	return mGLTexturep->createGLTexture();  }  BOOL LLGLTexture::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename, BOOL to_create, S32 category)  { -	llassert(mGLTexturep.notNull()) ;	 +	llassert(mGLTexturep.notNull());	 -	BOOL ret = mGLTexturep->createGLTexture(discard_level, imageraw, usename, to_create, category) ; +	BOOL ret = mGLTexturep->createGLTexture(discard_level, imageraw, usename, to_create, category);  	if(ret)  	{ -		mFullWidth = mGLTexturep->getCurrentWidth() ; -		mFullHeight = mGLTexturep->getCurrentHeight() ;  -		mComponents = mGLTexturep->getComponents() ;	 +		mFullWidth = mGLTexturep->getCurrentWidth(); +		mFullHeight = mGLTexturep->getCurrentHeight();  +		mComponents = mGLTexturep->getComponents();	  		setTexelsPerImage();  	} -	return ret ; +	return ret;  }  void LLGLTexture::setExplicitFormat(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format, BOOL swap_bytes)  { -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); -	mGLTexturep->setExplicitFormat(internal_format, primary_format, type_format, swap_bytes) ; +	mGLTexturep->setExplicitFormat(internal_format, primary_format, type_format, swap_bytes);  }  void LLGLTexture::setAddressMode(LLTexUnit::eTextureAddressMode mode)  { -	llassert(mGLTexturep.notNull()) ; -	mGLTexturep->setAddressMode(mode) ; +	llassert(mGLTexturep.notNull()); +	mGLTexturep->setAddressMode(mode);  }  void LLGLTexture::setFilteringOption(LLTexUnit::eTextureFilterOptions option)  { -	llassert(mGLTexturep.notNull()) ; -	mGLTexturep->setFilteringOption(option) ; +	llassert(mGLTexturep.notNull()); +	mGLTexturep->setFilteringOption(option);  }  //virtual  S32	LLGLTexture::getWidth(S32 discard_level) const  { -	llassert(mGLTexturep.notNull()) ; -	return mGLTexturep->getWidth(discard_level) ; +	llassert(mGLTexturep.notNull()); +	return mGLTexturep->getWidth(discard_level);  }  //virtual  S32	LLGLTexture::getHeight(S32 discard_level) const  { -	llassert(mGLTexturep.notNull()) ; -	return mGLTexturep->getHeight(discard_level) ; +	llassert(mGLTexturep.notNull()); +	return mGLTexturep->getHeight(discard_level);  }  S32 LLGLTexture::getMaxDiscardLevel() const  { -	llassert(mGLTexturep.notNull()) ; -	return mGLTexturep->getMaxDiscardLevel() ; +	llassert(mGLTexturep.notNull()); +	return mGLTexturep->getMaxDiscardLevel();  }  S32 LLGLTexture::getDiscardLevel() const  { -	llassert(mGLTexturep.notNull()) ; -	return mGLTexturep->getDiscardLevel() ; +	llassert(mGLTexturep.notNull()); +	return mGLTexturep->getDiscardLevel();  }  S8  LLGLTexture::getComponents() const   {  -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); -	return mGLTexturep->getComponents() ; +	return mGLTexturep->getComponents();  }  LLGLuint LLGLTexture::getTexName() const   {  -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); -	return mGLTexturep->getTexName() ;  +	return mGLTexturep->getTexName();   }  BOOL LLGLTexture::hasGLTexture() const   {  	if(mGLTexturep.notNull())  	{ -		return mGLTexturep->getHasGLTexture() ; +		return mGLTexturep->getHasGLTexture();  	} -	return FALSE ; +	return FALSE;  }  BOOL LLGLTexture::getBoundRecently() const  {  	if(mGLTexturep.notNull())  	{ -		return mGLTexturep->getBoundRecently() ; +		return mGLTexturep->getBoundRecently();  	} -	return FALSE ; +	return FALSE;  }  LLTexUnit::eTextureType LLGLTexture::getTarget(void) const  { -	llassert(mGLTexturep.notNull()) ; -	return mGLTexturep->getTarget() ; +	llassert(mGLTexturep.notNull()); +	return mGLTexturep->getTarget();  }  BOOL LLGLTexture::setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height)  { -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); -	return mGLTexturep->setSubImage(imageraw, x_pos, y_pos, width, height) ; +	return mGLTexturep->setSubImage(imageraw, x_pos, y_pos, width, height);  }  BOOL LLGLTexture::setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height)  { -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); -	return mGLTexturep->setSubImage(datap, data_width, data_height, x_pos, y_pos, width, height) ; +	return mGLTexturep->setSubImage(datap, data_width, data_height, x_pos, y_pos, width, height);  }  void LLGLTexture::setGLTextureCreated (bool initialized)  { -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); -	mGLTexturep->setGLTextureCreated (initialized) ; +	mGLTexturep->setGLTextureCreated (initialized);  }  void  LLGLTexture::setCategory(S32 category)   { -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); + +	mGLTexturep->setCategory(category); +} -	mGLTexturep->setCategory(category) ; +void LLGLTexture::setTexName(LLGLuint texName) +{ +    llassert(mGLTexturep.notNull()); +    return mGLTexturep->setTexName(texName);  +} + +void LLGLTexture::setTarget(const LLGLenum target, const LLTexUnit::eTextureType bind_target) +{ +    llassert(mGLTexturep.notNull()); +    return mGLTexturep->setTarget(target, bind_target);   }  LLTexUnit::eTextureAddressMode LLGLTexture::getAddressMode(void) const  { -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); -	return mGLTexturep->getAddressMode() ; +	return mGLTexturep->getAddressMode();  }  S32Bytes LLGLTexture::getTextureMemory() const  { -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); -	return mGLTexturep->mTextureMemory ; +	return mGLTexturep->mTextureMemory;  }  LLGLenum LLGLTexture::getPrimaryFormat() const  { -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); -	return mGLTexturep->getPrimaryFormat() ; +	return mGLTexturep->getPrimaryFormat();  }  BOOL LLGLTexture::getIsAlphaMask() const  { -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); -	return mGLTexturep->getIsAlphaMask() ; +	return mGLTexturep->getIsAlphaMask();  }  BOOL LLGLTexture::getMask(const LLVector2 &tc)  { -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); -	return mGLTexturep->getMask(tc) ; +	return mGLTexturep->getMask(tc);  }  F32 LLGLTexture::getTimePassedSinceLastBound()  { -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); -	return mGLTexturep->getTimePassedSinceLastBound() ; +	return mGLTexturep->getTimePassedSinceLastBound();  }  BOOL LLGLTexture::getMissed() const   { -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); -	return mGLTexturep->getMissed() ; +	return mGLTexturep->getMissed();  }  BOOL LLGLTexture::isJustBound() const  { -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); -	return mGLTexturep->isJustBound() ; +	return mGLTexturep->isJustBound();  }  void LLGLTexture::forceUpdateBindStats(void) const  { -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); -	return mGLTexturep->forceUpdateBindStats() ; +	return mGLTexturep->forceUpdateBindStats();  }  U32 LLGLTexture::getTexelsInAtlas() const  { -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); -	return mGLTexturep->getTexelsInAtlas() ; +	return mGLTexturep->getTexelsInAtlas();  }  U32 LLGLTexture::getTexelsInGLTexture() const  { -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); -	return mGLTexturep->getTexelsInGLTexture() ; +	return mGLTexturep->getTexelsInGLTexture();  }  BOOL LLGLTexture::isGLTextureCreated() const  { -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); -	return mGLTexturep->isGLTextureCreated() ; +	return mGLTexturep->isGLTextureCreated();  }  S32  LLGLTexture::getDiscardLevelInAtlas() const  { -	llassert(mGLTexturep.notNull()) ; +	llassert(mGLTexturep.notNull()); -	return mGLTexturep->getDiscardLevelInAtlas() ; +	return mGLTexturep->getDiscardLevelInAtlas();  }  void LLGLTexture::destroyGLTexture()   {  	if(mGLTexturep.notNull() && mGLTexturep->getHasGLTexture())  	{ -		mGLTexturep->destroyGLTexture() ; -		mTextureState = DELETED ; +		mGLTexturep->destroyGLTexture(); +		mTextureState = DELETED;  	}  }  void LLGLTexture::setTexelsPerImage()  { -	S32 fullwidth = llmin(mFullWidth,(S32)MAX_IMAGE_SIZE_DEFAULT); -	S32 fullheight = llmin(mFullHeight,(S32)MAX_IMAGE_SIZE_DEFAULT); -	mTexelsPerImage = (F32)fullwidth * fullheight; +    U32 fullwidth = llmin(mFullWidth, (U32)MAX_IMAGE_SIZE_DEFAULT); +    U32 fullheight = llmin(mFullHeight, (U32)MAX_IMAGE_SIZE_DEFAULT); +	mTexelsPerImage = (U32)fullwidth * fullheight;  } +static LLUUID sStubUUID; +const LLUUID& LLGLTexture::getID() const { return sStubUUID; }
\ No newline at end of file diff --git a/indra/llrender/llgltexture.h b/indra/llrender/llgltexture.h index 45592ee077..b8d646ed15 100644 --- a/indra/llrender/llgltexture.h +++ b/indra/llrender/llgltexture.h @@ -103,7 +103,7 @@ public:  	virtual void dump();	// debug info to LL_INFOS() -	virtual const LLUUID& getID() const = 0; +	virtual const LLUUID& getID() const;  	void setBoostLevel(S32 level);  	S32  getBoostLevel() { return mBoostLevel; } @@ -132,6 +132,8 @@ public:  	BOOL       setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height);  	void       setGLTextureCreated (bool initialized);  	void       setCategory(S32 category) ; +    void       setTexName(LLGLuint); // for forcing w/ externally created textures only +    void       setTarget(const LLGLenum target, const LLTexUnit::eTextureType bind_target);  	LLTexUnit::eTextureAddressMode getAddressMode(void) const ;  	S32        getMaxDiscardLevel() const; @@ -178,11 +180,11 @@ protected:  protected:  	S32 mBoostLevel;				// enum describing priority level -	S32 mFullWidth; -	S32 mFullHeight; +	U32 mFullWidth; +	U32 mFullHeight;  	BOOL mUseMipMaps;  	S8  mComponents; -	F32 mTexelsPerImage;			// Texels per image. +	U32 mTexelsPerImage;			// Texels per image.  	mutable S8  mNeedsGLTexture;  	//GL texture diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 89500dcc04..9b545bca0a 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -352,10 +352,9 @@ BOOL LLImageGL::create(LLPointer<LLImageGL>& dest, const LLImageRaw* imageraw, B  }  //---------------------------------------------------------------------------- -  LLImageGL::LLImageGL(BOOL usemipmaps)  :	LLTrace::MemTrackable<LLImageGL>("LLImageGL"), -	mSaveData(0) +    mSaveData(0), mExternalTexture(FALSE)  {  	init(usemipmaps);  	setSize(0, 0, 0); @@ -365,7 +364,7 @@ LLImageGL::LLImageGL(BOOL usemipmaps)  LLImageGL::LLImageGL(U32 width, U32 height, U8 components, BOOL usemipmaps)  :	LLTrace::MemTrackable<LLImageGL>("LLImageGL"), -	mSaveData(0) +    mSaveData(0), mExternalTexture(FALSE)  {  	llassert( components <= 4 );  	init(usemipmaps); @@ -376,7 +375,7 @@ LLImageGL::LLImageGL(U32 width, U32 height, U8 components, BOOL usemipmaps)  LLImageGL::LLImageGL(const LLImageRaw* imageraw, BOOL usemipmaps)  :	LLTrace::MemTrackable<LLImageGL>("LLImageGL"), -	mSaveData(0) +    mSaveData(0), mExternalTexture(FALSE)  {  	init(usemipmaps);  	setSize(0, 0, 0); @@ -386,12 +385,36 @@ LLImageGL::LLImageGL(const LLImageRaw* imageraw, BOOL usemipmaps)  	createGLTexture(0, imageraw);   } +LLImageGL::LLImageGL( +    LLGLuint texName, +    U32 components, +    LLGLenum target, +    LLGLint  formatInternal, +    LLGLenum formatPrimary, +    LLGLenum formatType, +    LLTexUnit::eTextureAddressMode addressMode) +    : LLTrace::MemTrackable<LLImageGL>("LLImageGL"), mSaveData(0), mExternalTexture(TRUE) +{ +    init(false); +    mTexName = texName; +    mTarget = target; +    mComponents = components; +    mAddressMode = addressMode; +    mFormatType = formatType; +    mFormatInternal = formatInternal; +    mFormatPrimary = formatPrimary; +} + +  LLImageGL::~LLImageGL()  { -	LLImageGL::cleanup(); -	sImageList.erase(this); -	freePickMask(); -	sCount--; +    if (!mExternalTexture) +    { +	    LLImageGL::cleanup(); +	    sImageList.erase(this); +	    freePickMask(); +	    sCount--; +    }  }  void LLImageGL::init(BOOL usemipmaps) diff --git a/indra/llrender/llimagegl.h b/indra/llrender/llimagegl.h index 2be54be062..4f3d7eed0a 100644 --- a/indra/llrender/llimagegl.h +++ b/indra/llrender/llimagegl.h @@ -84,7 +84,10 @@ public:  	LLImageGL(BOOL usemipmaps = TRUE);  	LLImageGL(U32 width, U32 height, U8 components, BOOL usemipmaps = TRUE);  	LLImageGL(const LLImageRaw* imageraw, BOOL usemipmaps = TRUE); -	 + +    // For wrapping textures created via GL elsewhere with our API only. Use with caution. +    LLImageGL(LLGLuint mTexName, U32 components, LLGLenum target, LLGLint  formatInternal, LLGLenum formatPrimary, LLGLenum formatType, LLTexUnit::eTextureAddressMode addressMode); +  protected:  	virtual ~LLImageGL(); @@ -234,6 +237,8 @@ protected:  	LLGLenum mFormatType;  	BOOL	 mFormatSwapBytes;// if true, use glPixelStorei(GL_UNPACK_SWAP_BYTES, 1) +    BOOL mExternalTexture; +  	// STATICS  public:	  	static std::set<LLImageGL*> sImageList; @@ -279,6 +284,8 @@ public:  	void setCategory(S32 category) {mCategory = category;}  	S32  getCategory()const {return mCategory;} +    void setTexName(GLuint texName) { mTexName = texName; } +  	//for debug use: show texture size distribution   	//----------------------------------------  	static S32 sCurTexSizeBar ; diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 76f28bb43f..a8f622d3ff 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -49,6 +49,7 @@ U32 LLRender::sUICalls = 0;  U32 LLRender::sUIVerts = 0;  U32 LLTexUnit::sWhiteTexture = 0;  bool LLRender::sGLCoreProfile = false; +bool LLRender::sNsightDebugSupport = false;  static const U32 LL_NUM_TEXTURE_LAYERS = 32;   static const U32 LL_NUM_LIGHT_UNITS = 8; @@ -58,7 +59,8 @@ static const GLenum sGLTextureType[] =  	GL_TEXTURE_2D,  	GL_TEXTURE_RECTANGLE_ARB,  	GL_TEXTURE_CUBE_MAP_ARB, -	GL_TEXTURE_2D_MULTISAMPLE +	GL_TEXTURE_2D_MULTISAMPLE, +    GL_TEXTURE_3D  };  static const GLint sGLAddressMode[] = diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h index a67fb8da52..9ad3a6e593 100644 --- a/indra/llrender/llrender.h +++ b/indra/llrender/llrender.h @@ -61,10 +61,11 @@ public:  	typedef enum  	{  		TT_TEXTURE = 0,			// Standard 2D Texture -		TT_RECT_TEXTURE,	// Non power of 2 texture -		TT_CUBE_MAP,		// 6-sided cube map texture +		TT_RECT_TEXTURE,	    // Non power of 2 texture +		TT_CUBE_MAP,		    // 6-sided cube map texture  		TT_MULTISAMPLE_TEXTURE, // see GL_ARB_texture_multisample -		TT_NONE 		// No texture type is currently enabled +        TT_TEXTURE_3D,          // standard 3D Texture +		TT_NONE, 		        // No texture type is currently enabled          	} eTextureType;  	typedef enum @@ -438,7 +439,8 @@ public:  	static U32 sUICalls;  	static U32 sUIVerts;  	static bool sGLCoreProfile; -	 +    static bool sNsightDebugSupport; +  private:  	friend class LLLightState; diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index e721ad93fa..287f22783f 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -512,16 +512,16 @@ static std::string get_object_log(GLhandleARB ret)  void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns, const std::string& filename)   {  	std::string log = get_object_log(ret); +    std::string fname = filename; +    if (filename.empty()) +    { +        fname = "unknown shader file"; +    } -	if (log.length() > 0 || warns) +	if (log.length() > 0)  	{ -        LL_DEBUGS("ShaderLoading") << "Shader loading "; -         -		if (!filename.empty()) -		{ -            LL_CONT << "From " << filename << ":\n"; -		} -        LL_CONT << log << LL_ENDL; +        LL_INFOS() << "Shader loading from " << fname << ":\n" << LL_ENDL; +        LL_INFOS() << log << LL_ENDL;  	}   } @@ -953,7 +953,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade  		// Add shader file to map  		mShaderObjects[filename] = ret;  		shader_level = try_gpu_class; -	} +    }  	else  	{  		if (shader_level > 1) @@ -1114,10 +1114,10 @@ void LLShaderMgr::initAttribsAndUniforms()  	mReservedUniforms.push_back("specularMap");  	mReservedUniforms.push_back("bumpMap");  	mReservedUniforms.push_back("environmentMap"); -	mReservedUniforms.push_back("cloude_noise_texture"); +	mReservedUniforms.push_back("cloud_noise_texture");  	mReservedUniforms.push_back("fullbright");  	mReservedUniforms.push_back("lightnorm"); -	mReservedUniforms.push_back("sunlight_color_copy"); +	mReservedUniforms.push_back("sunlight_color");  	mReservedUniforms.push_back("ambient");  	mReservedUniforms.push_back("blue_horizon");  	mReservedUniforms.push_back("blue_density"); @@ -1267,6 +1267,16 @@ void LLShaderMgr::initAttribsAndUniforms()  	mReservedUniforms.push_back("origin");  	mReservedUniforms.push_back("display_gamma"); + +    mReservedUniforms.push_back("inscatter"); +    mReservedUniforms.push_back("sun_size"); +    mReservedUniforms.push_back("fog_color"); + +    mReservedUniforms.push_back("transmittance_texture"); +    mReservedUniforms.push_back("scattering_texture"); +    mReservedUniforms.push_back("irradiance_texture"); +    mReservedUniforms.push_back("single_mie_scattering_texture"); +  	llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS);  	std::set<std::string> dupe_check; diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 394b38f832..ac3f7d58d5 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -30,6 +30,11 @@  #include "llgl.h"  #include "llglslshader.h" +/*RIDER: TODO: + * This should use the LL Singleton<> template... but not a quick conversion. + * (llviewershadermgr derives from this) + */ +  class LLShaderMgr  {  public: @@ -215,7 +220,18 @@ public:  		TERRAIN_ALPHARAMP,  		SHINY_ORIGIN, -DISPLAY_GAMMA, +        DISPLAY_GAMMA, + +        INSCATTER_RT, +        SUN_SIZE, +        FOG_COLOR, + +        // precomputed textures from libatmosphere +        TRANSMITTANCE_TEX, +        SCATTER_TEX, +        ILLUMINANCE_TEX, +        SINGLE_MIE_SCATTER_TEX, +  		END_RESERVED_UNIFORMS  	} eGLSLReservedUniforms; diff --git a/indra/llrender/lltexture.cpp b/indra/llrender/lltexture.cpp index 90fbcec2be..787a09a159 100644 --- a/indra/llrender/lltexture.cpp +++ b/indra/llrender/lltexture.cpp @@ -29,3 +29,15 @@  LLTexture::~LLTexture()  {  } + +S8   LLTexture::getType() const { llassert(false); return 0; } +void LLTexture::setKnownDrawSize(S32 width, S32 height) { llassert(false); } +bool LLTexture::bindDefaultImage(const S32 stage) { llassert(false); return false; } +bool LLTexture::bindDebugImage(const S32 stage) { llassert(false); return false; } +void LLTexture::forceImmediateUpdate() { llassert(false); } +void LLTexture::setActive() { llassert(false);  } +S32	 LLTexture::getWidth(S32 discard_level) const { llassert(false); return 0; } +S32	 LLTexture::getHeight(S32 discard_level) const { llassert(false); return 0; } +bool LLTexture::isActiveFetching() { llassert(false); return false; } +LLImageGL* LLTexture::getGLTexture() const { llassert(false); return nullptr; } +void LLTexture::updateBindStatsForTester() { }
\ No newline at end of file diff --git a/indra/llrender/lltexture.h b/indra/llrender/lltexture.h index 9fca8b8cd3..41481fb8a7 100644 --- a/indra/llrender/lltexture.h +++ b/indra/llrender/lltexture.h @@ -58,21 +58,21 @@ public:  	//  	//interfaces to access LLGLTexture  	// -	virtual S8         getType() const = 0 ; -	virtual void       setKnownDrawSize(S32 width, S32 height) = 0 ; -	virtual bool       bindDefaultImage(const S32 stage = 0) = 0 ; -	virtual bool       bindDebugImage(const S32 stage = 0) = 0; -	virtual void       forceImmediateUpdate() = 0 ; -	virtual void       setActive() = 0 ; -	virtual S32	       getWidth(S32 discard_level = -1) const = 0 ; -	virtual S32	       getHeight(S32 discard_level = -1) const = 0 ; -	virtual bool       isActiveFetching() = 0; +	virtual S8         getType() const; +	virtual void       setKnownDrawSize(S32 width, S32 height); +	virtual bool       bindDefaultImage(const S32 stage = 0); +	virtual bool       bindDebugImage(const S32 stage = 0); +	virtual void       forceImmediateUpdate(); +	virtual void       setActive(); +	virtual S32	       getWidth(S32 discard_level = -1) const; +	virtual S32	       getHeight(S32 discard_level = -1) const; +	virtual bool       isActiveFetching();  private:  	//note: do not make this function public. -	virtual LLImageGL* getGLTexture() const = 0 ; +	virtual LLImageGL* getGLTexture() const; -	virtual void updateBindStatsForTester() = 0 ; +	virtual void updateBindStatsForTester();  };  #endif | 
