diff options
Diffstat (limited to 'indra/llrender/llrender.cpp')
| -rw-r--r-- | indra/llrender/llrender.cpp | 149 |
1 files changed, 40 insertions, 109 deletions
diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index bfe0586ff0..c90169eddf 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -38,7 +38,11 @@ #include "hbxxh.h" #include "glm/gtc/type_ptr.hpp" -#if LL_WINDOWS +#if GL_ARB_debug_output +#ifndef APIENTRY +#define APIENTRY +#endif + extern void APIENTRY gl_debug_callback(GLenum source, GLenum type, GLuint id, @@ -67,20 +71,12 @@ S32 gGLViewport[4]; U32 LLRender::sUICalls = 0; U32 LLRender::sUIVerts = 0; U32 LLTexUnit::sWhiteTexture = 0; +F32 LLRender::sAnisotropicFilteringLevel = 0.f; bool LLRender::sGLCoreProfile = false; bool LLRender::sNsightDebugSupport = false; LLVector2 LLRender::sUIGLScaleFactor = LLVector2(1.f, 1.f); bool LLRender::sClassicMode = false; -struct LLVBCache -{ - LLPointer<LLVertexBuffer> vb; - std::chrono::steady_clock::time_point touched; -}; - -static std::unordered_map<U64, LLVBCache> sVBCache; -static thread_local std::list<LLVertexBufferData> *sBufferDataList = nullptr; - static const GLenum sGLTextureType[] = { GL_TEXTURE_2D, @@ -580,10 +576,12 @@ void LLTexUnit::setTextureFilteringOptionFast(LLTexUnit::eTextureFilterOptions o if (gGLManager.mHasAnisotropic) { - if (LLImageGL::sGlobalUseAnisotropic && option == TFO_ANISOTROPIC) + if (option == TFO_ANISOTROPIC && LLRender::sAnisotropicFilteringLevel > 1.f) { /* - glTexParameterf(sGLTextureType[tex_type], GL_TEXTURE_MAX_ANISOTROPY, gGLManager.mMaxAnisotropy); + F32 aniso_level = llclamp(LLRender::sAnisotropicFilteringLevel, 1.f, gGLManager.mMaxAnisotropy); + glTexParameterf(sGLTextureType[tex_type], GL_TEXTURE_MAX_ANISOTROPY, aniso_level); + } else { @@ -600,86 +598,6 @@ void LLTexUnit::setTextureFilteringOptionFast(LLTexUnit::eTextureFilterOptions o } } -GLint LLTexUnit::getTextureSource(eTextureBlendSrc src) -{ -#if GL_VERSION_1_3 - switch(src) - { - // All four cases should return the same value. - case TBS_PREV_COLOR: - case TBS_PREV_ALPHA: - case TBS_ONE_MINUS_PREV_COLOR: - case TBS_ONE_MINUS_PREV_ALPHA: - return GL_PREVIOUS; - - // All four cases should return the same value. - case TBS_TEX_COLOR: - case TBS_TEX_ALPHA: - case TBS_ONE_MINUS_TEX_COLOR: - case TBS_ONE_MINUS_TEX_ALPHA: -#endif - return GL_TEXTURE; - -#if GL_VERSION_1_3 - // All four cases should return the same value. - case TBS_VERT_COLOR: - case TBS_VERT_ALPHA: - case TBS_ONE_MINUS_VERT_COLOR: - case TBS_ONE_MINUS_VERT_ALPHA: - return GL_PRIMARY_COLOR; - - // All four cases should return the same value. - case TBS_CONST_COLOR: - case TBS_CONST_ALPHA: - case TBS_ONE_MINUS_CONST_COLOR: - case TBS_ONE_MINUS_CONST_ALPHA: - return GL_CONSTANT; - - default: - LL_WARNS() << "Unknown eTextureBlendSrc: " << src << ". Using Vertex Color instead." << LL_ENDL; - return GL_PRIMARY_COLOR; - } -#endif -} - -GLint LLTexUnit::getTextureSourceType(eTextureBlendSrc src, bool isAlpha) -{ - switch(src) - { - // All four cases should return the same value. - case TBS_PREV_COLOR: - case TBS_TEX_COLOR: - case TBS_VERT_COLOR: - case TBS_CONST_COLOR: - return (isAlpha) ? GL_SRC_ALPHA: GL_SRC_COLOR; - - // All four cases should return the same value. - case TBS_PREV_ALPHA: - case TBS_TEX_ALPHA: - case TBS_VERT_ALPHA: - case TBS_CONST_ALPHA: - return GL_SRC_ALPHA; - - // All four cases should return the same value. - case TBS_ONE_MINUS_PREV_COLOR: - case TBS_ONE_MINUS_TEX_COLOR: - case TBS_ONE_MINUS_VERT_COLOR: - case TBS_ONE_MINUS_CONST_COLOR: - return (isAlpha) ? GL_ONE_MINUS_SRC_ALPHA : GL_ONE_MINUS_SRC_COLOR; - - // All four cases should return the same value. - case TBS_ONE_MINUS_PREV_ALPHA: - case TBS_ONE_MINUS_TEX_ALPHA: - case TBS_ONE_MINUS_VERT_ALPHA: - case TBS_ONE_MINUS_CONST_ALPHA: - return GL_ONE_MINUS_SRC_ALPHA; - - default: - LL_WARNS() << "Unknown eTextureBlendSrc: " << src << ". Using Source Color or Alpha instead." << LL_ENDL; - return (isAlpha) ? GL_SRC_ALPHA: GL_SRC_COLOR; - } -} - // Useful for debugging that you've manually assigned a texture operation to the correct // texture unit based on the currently set active texture in opengl. void LLTexUnit::debugTextureUnit(void) @@ -909,7 +827,7 @@ LLRender::~LLRender() bool LLRender::init(bool needs_vertex_buffer) { -#if LL_WINDOWS +#if GL_ARB_debug_output && !LL_DARWIN if (gGLManager.mHasDebugOutput && gDebugGL) { //setup debug output callback //glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_LOW_ARB, 0, NULL, GL_TRUE); @@ -964,7 +882,9 @@ void LLRender::initVertexBuffer() void LLRender::resetVertexBuffer() { - mBuffer = NULL; + mBuffer = nullptr; + mBufferDataList = nullptr; + mVBCache.clear(); } void LLRender::shutdown() @@ -1107,7 +1027,7 @@ void LLRender::syncMatrices() shader->uniformMatrix3fv(LLShaderMgr::NORMAL_MATRIX, 1, GL_FALSE, norm_mat); } - if (shader->getUniformLocation(LLShaderMgr::INVERSE_MODELVIEW_MATRIX)) + if (shader->getUniformLocation(LLShaderMgr::INVERSE_MODELVIEW_MATRIX) >= 0) { shader->uniformMatrix4fv(LLShaderMgr::INVERSE_MODELVIEW_MATRIX, 1, GL_FALSE, glm::value_ptr(cached_inv_mdv)); } @@ -1139,14 +1059,14 @@ void LLRender::syncMatrices() // GZ: This was previously disabled seemingly due to a bug involving the deferred renderer's regular pushing and popping of mats. // We're reenabling this and cleaning up the code around that - that would've been the appropriate course initially. // Anything beyond the standard proj and inv proj mats are special cases. Please setup special uniforms accordingly in the future. - if (shader->getUniformLocation(LLShaderMgr::INVERSE_PROJECTION_MATRIX)) + if (shader->getUniformLocation(LLShaderMgr::INVERSE_PROJECTION_MATRIX) >= 0) { glm::mat4 inv_proj = glm::inverse(mat); shader->uniformMatrix4fv(LLShaderMgr::INVERSE_PROJECTION_MATRIX, 1, false, glm::value_ptr(inv_proj)); } // Used by some full screen effects - such as full screen lights, glow, etc. - if (shader->getUniformLocation(LLShaderMgr::IDENTITY_MATRIX)) + if (shader->getUniformLocation(LLShaderMgr::IDENTITY_MATRIX) >= 0) { shader->uniformMatrix4fv(LLShaderMgr::IDENTITY_MATRIX, 1, GL_FALSE, glm::value_ptr(glm::identity<glm::mat4>())); } @@ -1160,7 +1080,7 @@ void LLRender::syncMatrices() S32 loc = shader->getUniformLocation(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX); if (loc > -1) { - if (cached_mvp_mdv_hash != mMatHash[MM_PROJECTION] || cached_mvp_proj_hash != mMatHash[MM_PROJECTION]) + if (cached_mvp_mdv_hash != mMatHash[MM_MODELVIEW] || cached_mvp_proj_hash != mMatHash[MM_PROJECTION]) { U32 mdv = MM_MODELVIEW; cached_mvp = mat; @@ -1570,21 +1490,21 @@ void LLRender::clearErrors() void LLRender::beginList(std::list<LLVertexBufferData> *list) { - if (sBufferDataList) + if (mBufferDataList) { LL_ERRS() << "beginList called while another list is open." << LL_ENDL; } llassert(LLGLSLShader::sCurBoundShaderPtr == &gUIProgram); flush(); - sBufferDataList = list; + mBufferDataList = list; } void LLRender::endList() { - if (sBufferDataList) + if (mBufferDataList) { flush(); - sBufferDataList = nullptr; + mBufferDataList = nullptr; } else { @@ -1671,10 +1591,10 @@ void LLRender::flush(std::string comment_) U32 attribute_mask = LLGLSLShader::sCurBoundShaderPtr->mAttributeMask; - if (sBufferDataList) + if (mBufferDataList) { vb = genBuffer(attribute_mask, count); - sBufferDataList->emplace_back( + mBufferDataList->emplace_back( vb, mMode, count, @@ -1741,9 +1661,9 @@ LLVertexBuffer* LLRender::bufferfromCache(U32 attribute_mask, U32 count) // To leverage this, we maintain a running hash of the vertex stream being // built up before a flush, and then check that hash against a VB // cache just before creating a vertex buffer in VRAM - std::unordered_map<U64, LLVBCache>::iterator cache = sVBCache.find(vhash); + std::unordered_map<U64, LLVBCache>::iterator cache = mVBCache.find(vhash); - if (cache != sVBCache.end()) + if (cache != mVBCache.end()) { LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("vb cache hit"); // cache hit, just use the cached buffer @@ -1755,7 +1675,7 @@ LLVertexBuffer* LLRender::bufferfromCache(U32 attribute_mask, U32 count) LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("vb cache miss"); vb = genBuffer(attribute_mask, count); - sVBCache[vhash] = { vb , std::chrono::steady_clock::now() }; + mVBCache[vhash] = { vb , std::chrono::steady_clock::now() }; static U32 miss_count = 0; miss_count++; @@ -1767,11 +1687,11 @@ LLVertexBuffer* LLRender::bufferfromCache(U32 attribute_mask, U32 count) using namespace std::chrono_literals; // every 1024 misses, clean the cache of any VBs that haven't been touched in the last second - for (std::unordered_map<U64, LLVBCache>::iterator iter = sVBCache.begin(); iter != sVBCache.end(); ) + for (std::unordered_map<U64, LLVBCache>::iterator iter = mVBCache.begin(); iter != mVBCache.end(); ) { if (now - iter->second.touched > 1s) { - iter = sVBCache.erase(iter); + iter = mVBCache.erase(iter); } else { @@ -2086,6 +2006,17 @@ void LLRender::diffuseColor4ub(U8 r, U8 g, U8 b, U8 a) } } +void LLRender::setLineWidth(F32 width) +{ + gGL.flush(); + + width = llclamp(width, gGLManager.mAliasedLineRange[0], gGLManager.mAliasedLineRange[1]); + if(mLineWidth != width) + { + mLineWidth = width; + glLineWidth(width); + } +} void LLRender::debugTexUnits(void) { |
