summaryrefslogtreecommitdiff
path: root/indra/llrender
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llrender')
-rw-r--r--indra/llrender/llfontfreetype.cpp201
-rw-r--r--indra/llrender/llfontfreetype.h23
-rw-r--r--indra/llrender/llgl.cpp13
-rw-r--r--indra/llrender/llglslshader.cpp23
-rw-r--r--indra/llrender/llglslshader.h4
-rw-r--r--indra/llrender/llrender.cpp122
-rw-r--r--indra/llrender/llrender.h17
-rw-r--r--indra/llrender/llrendertarget.cpp23
-rw-r--r--indra/llrender/llshadermgr.cpp63
-rw-r--r--indra/llrender/llshadermgr.h4
-rw-r--r--indra/llrender/llvertexbuffer.cpp8
-rw-r--r--indra/llrender/llvertexbuffer.h4
12 files changed, 264 insertions, 241 deletions
diff --git a/indra/llrender/llfontfreetype.cpp b/indra/llrender/llfontfreetype.cpp
index e93c98970b..9d6773ac5b 100644
--- a/indra/llrender/llfontfreetype.cpp
+++ b/indra/llrender/llfontfreetype.cpp
@@ -58,9 +58,9 @@
FT_Render_Mode gFontRenderMode = FT_RENDER_MODE_NORMAL;
-LLFontManager *gFontManagerp = NULL;
+LLFontManager *gFontManagerp = nullptr;
-FT_Library gFTLibrary = NULL;
+FT_Library gFTLibrary = nullptr;
//static
void LLFontManager::initClass()
@@ -75,7 +75,7 @@ void LLFontManager::initClass()
void LLFontManager::cleanupClass()
{
delete gFontManagerp;
- gFontManagerp = NULL;
+ gFontManagerp = nullptr;
}
LLFontManager::LLFontManager()
@@ -103,6 +103,7 @@ LLFontManager::LLFontManager()
LLFontManager::~LLFontManager()
{
FT_Done_FreeType(gFTLibrary);
+ unloadAllFonts();
}
@@ -141,12 +142,8 @@ LLFontFreetype::LLFontFreetype()
mAscender(0.f),
mDescender(0.f),
mLineHeight(0.f),
-#ifdef LL_WINDOWS
- pFileStream(NULL),
- pFtStream(NULL),
-#endif
mIsFallback(false),
- mFTFace(NULL),
+ mFTFace(nullptr),
mRenderGlyphCount(0),
mStyle(0),
mPointSize(0)
@@ -159,35 +156,16 @@ LLFontFreetype::~LLFontFreetype()
// Clean up freetype libs.
if (mFTFace)
FT_Done_Face(mFTFace);
- mFTFace = NULL;
+ mFTFace = nullptr;
// Delete glyph info
std::for_each(mCharGlyphInfoMap.begin(), mCharGlyphInfoMap.end(), DeletePairedPointer());
mCharGlyphInfoMap.clear();
-#ifdef LL_WINDOWS
- delete pFileStream; // closed by FT_Done_Face
- delete pFtStream;
-#endif
delete mFontBitmapCachep;
// mFallbackFonts cleaned up by LLPointer destructor
}
-#ifdef LL_WINDOWS
-unsigned long ft_read_cb(FT_Stream stream, unsigned long offset, unsigned char *buffer, unsigned long count) {
- if (count <= 0) return count;
- llifstream *file_stream = static_cast<llifstream *>(stream->descriptor.pointer);
- file_stream->seekg(offset, std::ios::beg);
- file_stream->read((char*)buffer, count);
- return (unsigned long)file_stream->gcount();
-}
-
-void ft_close_cb(FT_Stream stream) {
- llifstream *file_stream = static_cast<llifstream *>(stream->descriptor.pointer);
- file_stream->close();
-}
-#endif
-
bool LLFontFreetype::loadFace(const std::string& filename, F32 point_size, F32 vert_dpi, F32 horz_dpi, bool is_fallback, S32 face_n)
{
// Don't leak face objects. This is also needed to deal with
@@ -195,26 +173,21 @@ bool LLFontFreetype::loadFace(const std::string& filename, F32 point_size, F32 v
if (mFTFace)
{
FT_Done_Face(mFTFace);
- mFTFace = NULL;
+ mFTFace = nullptr;
}
- int error;
-#ifdef LL_WINDOWS
- error = ftOpenFace(filename, face_n);
-#else
- error = FT_New_Face( gFTLibrary,
- filename.c_str(),
- 0,
- &mFTFace);
-#endif
+ FT_Open_Args openArgs;
+ memset( &openArgs, 0, sizeof( openArgs ) );
+ openArgs.memory_base = gFontManagerp->loadFont( filename, openArgs.memory_size );
+
+ if( !openArgs.memory_base )
+ return false;
+
+ openArgs.flags = FT_OPEN_MEMORY;
+ int error = FT_Open_Face( gFTLibrary, &openArgs, 0, &mFTFace );
if (error)
- {
-#ifdef LL_WINDOWS
- clearFontStreams();
-#endif
return false;
- }
mIsFallback = is_fallback;
F32 pixels_per_em = (point_size / 72.f)*vert_dpi; // Size in inches * dpi
@@ -229,10 +202,8 @@ bool LLFontFreetype::loadFace(const std::string& filename, F32 point_size, F32 v
{
// Clean up freetype libs.
FT_Done_Face(mFTFace);
-#ifdef LL_WINDOWS
- clearFontStreams();
-#endif
- mFTFace = NULL;
+
+ mFTFace = nullptr;
return false;
}
@@ -288,73 +259,30 @@ S32 LLFontFreetype::getNumFaces(const std::string& filename)
if (mFTFace)
{
FT_Done_Face(mFTFace);
- mFTFace = NULL;
+ mFTFace = nullptr;
}
S32 num_faces = 1;
-#ifdef LL_WINDOWS
- int error = ftOpenFace(filename, 0);
+ FT_Open_Args openArgs;
+ memset( &openArgs, 0, sizeof( openArgs ) );
+ openArgs.memory_base = gFontManagerp->loadFont( filename, openArgs.memory_size );
+ if( !openArgs.memory_base )
+ return 0;
+ openArgs.flags = FT_OPEN_MEMORY;
+ int error = FT_Open_Face( gFTLibrary, &openArgs, 0, &mFTFace );
if (error)
- {
return 0;
- }
else
- {
num_faces = mFTFace->num_faces;
- }
FT_Done_Face(mFTFace);
- clearFontStreams();
- mFTFace = NULL;
-#endif
+ mFTFace = nullptr;
return num_faces;
}
-#ifdef LL_WINDOWS
-S32 LLFontFreetype::ftOpenFace(const std::string& filename, S32 face_n)
-{
- S32 error = -1;
- pFileStream = new llifstream(filename, std::ios::binary);
- if (pFileStream->is_open())
- {
- std::streampos beg = pFileStream->tellg();
- pFileStream->seekg(0, std::ios::end);
- std::streampos end = pFileStream->tellg();
- std::size_t file_size = end - beg;
- pFileStream->seekg(0, std::ios::beg);
-
- pFtStream = new LLFT_Stream();
- pFtStream->base = 0;
- pFtStream->pos = 0;
- pFtStream->size = static_cast<unsigned long>(file_size);
- pFtStream->descriptor.pointer = pFileStream;
- pFtStream->read = ft_read_cb;
- pFtStream->close = ft_close_cb;
-
- FT_Open_Args args;
- args.flags = FT_OPEN_STREAM;
- args.stream = (FT_StreamRec*)pFtStream;
- error = FT_Open_Face(gFTLibrary, &args, face_n, &mFTFace);
- }
- return error;
-}
-
-void LLFontFreetype::clearFontStreams()
-{
- if (pFileStream)
- {
- pFileStream->close();
- }
- delete pFileStream;
- delete pFtStream;
- pFileStream = NULL;
- pFtStream = NULL;
-}
-#endif
-
void LLFontFreetype::addFallbackFont(const LLPointer<LLFontFreetype>& fallback_font,
const char_functor_t& functor)
{
@@ -378,7 +306,7 @@ F32 LLFontFreetype::getDescenderHeight() const
F32 LLFontFreetype::getXAdvance(llwchar wch) const
{
- if (mFTFace == NULL)
+ if (mFTFace == nullptr)
return 0.0;
// Return existing info only if it is current
@@ -402,7 +330,7 @@ F32 LLFontFreetype::getXAdvance(llwchar wch) const
F32 LLFontFreetype::getXAdvance(const LLFontGlyphInfo* glyph) const
{
- if (mFTFace == NULL)
+ if (mFTFace == nullptr)
return 0.0;
return glyph->mXAdvance;
@@ -410,7 +338,7 @@ F32 LLFontFreetype::getXAdvance(const LLFontGlyphInfo* glyph) const
F32 LLFontFreetype::getXKerning(llwchar char_left, llwchar char_right) const
{
- if (mFTFace == NULL)
+ if (mFTFace == nullptr)
return 0.0;
//llassert(!mIsFallback);
@@ -429,7 +357,7 @@ F32 LLFontFreetype::getXKerning(llwchar char_left, llwchar char_right) const
F32 LLFontFreetype::getXKerning(const LLFontGlyphInfo* left_glyph_info, const LLFontGlyphInfo* right_glyph_info) const
{
- if (mFTFace == NULL)
+ if (mFTFace == nullptr)
return 0.0;
U32 left_glyph = left_glyph_info ? left_glyph_info->mGlyphIndex : 0;
@@ -452,7 +380,7 @@ LLFontGlyphInfo* LLFontFreetype::addGlyph(llwchar wch, EFontGlyphType glyph_type
{
if (!mFTFace)
{
- return NULL;
+ return nullptr;
}
llassert(!mIsFallback);
@@ -543,14 +471,14 @@ LLFontGlyphInfo* LLFontFreetype::addGlyph(llwchar wch, EFontGlyphType glyph_type
{
return addGlyphFromFont(this, wch, glyph_index, glyph_type);
}
- return NULL;
+ return nullptr;
}
LLFontGlyphInfo* LLFontFreetype::addGlyphFromFont(const LLFontFreetype *fontp, llwchar wch, U32 glyph_index, EFontGlyphType requested_glyph_type) const
{
LL_PROFILE_ZONE_SCOPED;
- if (mFTFace == NULL)
- return NULL;
+ if (mFTFace == nullptr)
+ return nullptr;
llassert(!mIsFallback);
fontp->renderGlyph(requested_glyph_type, glyph_index, wch);
@@ -602,7 +530,7 @@ LLFontGlyphInfo* LLFontFreetype::addGlyphFromFont(const LLFontFreetype *fontp, l
{
U8 *buffer_data = fontp->mFTFace->glyph->bitmap.buffer;
S32 buffer_row_stride = fontp->mFTFace->glyph->bitmap.pitch;
- U8 *tmp_graydata = NULL;
+ U8 *tmp_graydata = nullptr;
if (fontp->mFTFace->glyph->bitmap.pixel_mode
== FT_PIXEL_MODE_MONO)
@@ -706,7 +634,7 @@ void LLFontFreetype::insertGlyphInfo(llwchar wch, LLFontGlyphInfo* gi) const
void LLFontFreetype::renderGlyph(EFontGlyphType bitmap_type, U32 glyph_index, llwchar wch) const
{
- if (mFTFace == NULL)
+ if (mFTFace == nullptr)
return;
FT_Int32 load_flags = FT_LOAD_FORCE_AUTOHINT;
@@ -920,3 +848,58 @@ void LLFontFreetype::setSubImageLuminanceAlpha(U32 x, U32 y, U32 bitmap_num, U32
}
}
+
+namespace ll
+{
+ namespace fonts
+ {
+ class LoadedFont
+ {
+ public:
+ LoadedFont( std::string aName , std::string const &aAddress, std::size_t aSize )
+ : mAddress( aAddress )
+ {
+ mName = aName;
+ mSize = aSize;
+ mRefs = 1;
+ }
+ std::string mName;
+ std::string mAddress;
+ std::size_t mSize;
+ U32 mRefs;
+ };
+ }
+}
+
+U8 const* LLFontManager::loadFont( std::string const &aFilename, long &a_Size)
+{
+ a_Size = 0;
+ std::map< std::string, std::shared_ptr<ll::fonts::LoadedFont> >::iterator itr = m_LoadedFonts.find( aFilename );
+ if( itr != m_LoadedFonts.end() )
+ {
+ ++itr->second->mRefs;
+ // A possible overflow cannot happen here, as it is asserted that the size is less than std::numeric_limits<long>::max() a few lines below.
+ a_Size = static_cast<long>(itr->second->mSize);
+ return reinterpret_cast<U8 const*>(itr->second->mAddress.c_str());
+ }
+
+ auto strContent = LLFile::getContents(aFilename);
+
+ if( strContent.empty() )
+ return nullptr;
+
+ // For fontconfig a type of long is required, std::string::size() returns size_t. I think it is safe to limit this to 2GiB and not support fonts that huge (can that even be a thing?)
+ llassert_always( strContent.size() < std::numeric_limits<long>::max() );
+
+ a_Size = static_cast<long>(strContent.size());
+
+ auto pCache = std::make_shared<ll::fonts::LoadedFont>( aFilename, strContent, a_Size );
+ itr = m_LoadedFonts.insert( std::make_pair( aFilename, pCache ) ).first;
+
+ return reinterpret_cast<U8 const*>(itr->second->mAddress.c_str());
+}
+
+void LLFontManager::unloadAllFonts()
+{
+ m_LoadedFonts.clear();
+}
diff --git a/indra/llrender/llfontfreetype.h b/indra/llrender/llfontfreetype.h
index 783bf4a4b3..a9b3a944ee 100644
--- a/indra/llrender/llfontfreetype.h
+++ b/indra/llrender/llfontfreetype.h
@@ -43,15 +43,28 @@ typedef struct FT_FaceRec_* LLFT_Face;
struct FT_StreamRec_;
typedef struct FT_StreamRec_ LLFT_Stream;
+namespace ll
+{
+ namespace fonts
+ {
+ class LoadedFont;
+ }
+}
+
class LLFontManager
{
public:
static void initClass();
static void cleanupClass();
+ U8 const *loadFont( std::string const &aFilename, long &a_Size );
+
private:
LLFontManager();
~LLFontManager();
+
+ void unloadAllFonts();
+ std::map< std::string, std::shared_ptr<ll::fonts::LoadedFont> > m_LoadedFonts;
};
struct LLFontGlyphInfo
@@ -90,11 +103,6 @@ public:
S32 getNumFaces(const std::string& filename);
-#ifdef LL_WINDOWS
- S32 ftOpenFace(const std::string& filename, S32 face_n);
- void clearFontStreams();
-#endif
-
typedef std::function<bool(llwchar)> char_functor_t;
void addFallbackFont(const LLPointer<LLFontFreetype>& fallback_font, const char_functor_t& functor = nullptr);
@@ -170,11 +178,6 @@ private:
LLFT_Face mFTFace;
-#ifdef LL_WINDOWS
- llifstream *pFileStream;
- LLFT_Stream *pFtStream;
-#endif
-
bool mIsFallback;
typedef std::pair<LLPointer<LLFontFreetype>, char_functor_t> fallback_font_t;
typedef std::vector<fallback_font_t> fallback_font_vector_t;
diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp
index cc619e2086..b002d183ef 100644
--- a/indra/llrender/llgl.cpp
+++ b/indra/llrender/llgl.cpp
@@ -1123,17 +1123,6 @@ bool LLGLManager::initGL()
if (mGLVersion >= 2.f)
{
parse_glsl_version(mGLSLVersionMajor, mGLSLVersionMinor);
-
-#if 0 && LL_DARWIN
- // TODO maybe switch to using a core profile for GL 3.2?
- // https://stackoverflow.com/a/19868861
- //never use GLSL greater than 1.20 on OSX
- if (mGLSLVersionMajor > 1 || mGLSLVersionMinor > 30)
- {
- mGLSLVersionMajor = 1;
- mGLSLVersionMinor = 30;
- }
-#endif
}
#if GL_VERSION_1_3
@@ -2748,7 +2737,7 @@ void LLGLUserClipPlane::setPlane(F32 a, F32 b, F32 c, F32 d)
if(cplane[2] < 0)
cplane *= -1;
- glm::mat4 suffix;
+ glm::mat4 suffix = glm::identity<glm::mat4>();
suffix = glm::row(suffix, 2, cplane);
glm::mat4 newP = suffix * P;
gGL.matrixMode(LLRender::MM_PROJECTION);
diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp
index aac5e3abc8..5a0281eeb5 100644
--- a/indra/llrender/llglslshader.cpp
+++ b/indra/llrender/llglslshader.cpp
@@ -450,8 +450,11 @@ bool LLGLSLShader::createShader()
llassert_always(!mShaderFiles.empty());
#if LL_DARWIN
- // work-around missing mix(vec3,vec3,bvec3)
- mDefines["OLD_SELECT"] = "1";
+ if(!gGLManager.mIsApple)
+ {
+ // work-around missing mix(vec3,vec3,bvec3)
+ mDefines["OLD_SELECT"] = "1";
+ }
#endif
mShaderHash = hash();
@@ -572,7 +575,7 @@ bool LLGLSLShader::createShader()
}
}
-#ifdef LL_PROFILER_ENABLE_RENDER_DOC
+#if LL_PROFILER_ENABLE_RENDER_DOC
setLabel(mName.c_str());
#endif
@@ -1190,22 +1193,22 @@ S32 LLGLSLShader::bindTexture(S32 uniform, LLRenderTarget* texture, bool depth,
return -1;
}
- uniform = getTextureChannel(uniform);
+ S32 channel = getTextureChannel(uniform);
- if (uniform > -1)
+ if (channel > -1)
{
if (depth) {
- gGL.getTexUnit(uniform)->bind(texture, true);
+ gGL.getTexUnit(channel)->bind(texture, true);
}
else {
bool has_mips = mode == LLTexUnit::TFO_TRILINEAR || mode == LLTexUnit::TFO_ANISOTROPIC;
- gGL.getTexUnit(uniform)->bindManual(texture->getUsage(), texture->getTexture(index), has_mips);
+ gGL.getTexUnit(channel)->bindManual(texture->getUsage(), texture->getTexture(index), has_mips);
}
- gGL.getTexUnit(uniform)->setTextureFilteringOption(mode);
+ gGL.getTexUnit(channel)->setTextureFilteringOption(mode);
}
- return uniform;
+ return channel;
}
S32 LLGLSLShader::bindTexture(const std::string& uniform, LLRenderTarget* texture, bool depth, LLTexUnit::eTextureFilterOptions mode)
@@ -2116,7 +2119,7 @@ LLUUID LLGLSLShader::hash()
return hash_obj.digest();
}
-#ifdef LL_PROFILER_ENABLE_RENDER_DOC
+#if LL_PROFILER_ENABLE_RENDER_DOC
void LLGLSLShader::setLabel(const char* label) {
LL_LABEL_OBJECT_GL(GL_PROGRAM, mProgramObject, strlen(label), label);
}
diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h
index 873ab0cff5..4702a27cc5 100644
--- a/indra/llrender/llglslshader.h
+++ b/indra/llrender/llglslshader.h
@@ -361,7 +361,7 @@ public:
// hacky flag used for optimization in LLDrawPoolAlpha
bool mCanBindFast = false;
-#ifdef LL_PROFILER_ENABLE_RENDER_DOC
+#if LL_PROFILER_ENABLE_RENDER_DOC
void setLabel(const char* label);
#endif
@@ -381,7 +381,7 @@ extern LLGLSLShader gSolidColorProgram;
//Alpha mask shader (declared here so llappearance can access properly)
extern LLGLSLShader gAlphaMaskProgram;
-#ifdef LL_PROFILER_ENABLE_RENDER_DOC
+#if LL_PROFILER_ENABLE_RENDER_DOC
#define LL_SET_SHADER_LABEL(shader) shader.setLabel(#shader)
#else
#define LL_SET_SHADER_LABEL(shader, label)
diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp
index 332d15f76c..658947d531 100644
--- a/indra/llrender/llrender.cpp
+++ b/indra/llrender/llrender.cpp
@@ -124,7 +124,7 @@ static const GLenum sGLBlendFactor[] =
LLTexUnit::LLTexUnit(S32 index)
: mCurrTexType(TT_NONE),
- mCurrColorScale(1), mCurrAlphaScale(1), mCurrTexture(0),
+ mCurrTexture(0),
mHasMipMaps(false),
mIndex(index)
{
@@ -214,6 +214,14 @@ void LLTexUnit::bindFast(LLTexture* texture)
}
glBindTexture(sGLTextureType[gl_tex->getTarget()], mCurrTexture);
mHasMipMaps = gl_tex->mHasMipMaps;
+/*
+ if (gl_tex->mTexOptionsDirty)
+ {
+ gl_tex->mTexOptionsDirty = false;
+ setTextureAddressModeFast(gl_tex->mAddressMode, gl_tex->getTarget());
+ setTextureFilteringOptionFast(gl_tex->mFilterOption, gl_tex->getTarget());
+ }
+*/
}
bool LLTexUnit::bind(LLTexture* texture, bool for_rendering, bool forceBind)
@@ -468,11 +476,24 @@ void LLTexUnit::setTextureAddressMode(eTextureAddressMode mode)
activate();
- glTexParameteri (sGLTextureType[mCurrTexType], GL_TEXTURE_WRAP_S, sGLAddressMode[mode]);
- glTexParameteri (sGLTextureType[mCurrTexType], GL_TEXTURE_WRAP_T, sGLAddressMode[mode]);
+/*
+ setTextureAddressModeFast(mode, mCurrTexType);
+}
+
+void LLTexUnit::setTextureAddressModeFast(eTextureAddressMode mode, eTextureType tex_type)
+{
+ glTexParameteri(sGLTextureType[tex_type], GL_TEXTURE_WRAP_S, sGLAddressMode[mode]);
+ glTexParameteri(sGLTextureType[tex_type], GL_TEXTURE_WRAP_T, sGLAddressMode[mode]);
+ if (tex_type == TT_CUBE_MAP || tex_type == TT_CUBE_MAP_ARRAY || tex_type == TT_TEXTURE_3D)
+ {
+ glTexParameteri(sGLTextureType[tex_type], GL_TEXTURE_WRAP_R, sGLAddressMode[mode]);
+ }
+*/
+ glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_WRAP_S, sGLAddressMode[mode]);
+ glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_WRAP_T, sGLAddressMode[mode]);
if (mCurrTexType == TT_CUBE_MAP)
{
- glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, sGLAddressMode[mode]);
+ glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_WRAP_R, sGLAddressMode[mode]);
}
}
@@ -490,8 +511,22 @@ void LLTexUnit::setTextureFilteringOption(LLTexUnit::eTextureFilterOptions optio
gGL.flush();
+/*
+ setTextureFilteringOptionFast(option, mCurrTexType);
+}
+
+void LLTexUnit::setTextureFilteringOptionFast(LLTexUnit::eTextureFilterOptions option, eTextureType tex_type)
+{
+*/
if (option == TFO_POINT)
{
+/*
+ glTexParameteri(sGLTextureType[tex_type], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ }
+ else
+ {
+ glTexParameteri(sGLTextureType[tex_type], GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+*/
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
else
@@ -501,12 +536,22 @@ void LLTexUnit::setTextureFilteringOption(LLTexUnit::eTextureFilterOptions optio
if (option >= TFO_TRILINEAR && mHasMipMaps)
{
+/*
+ glTexParameteri(sGLTextureType[tex_type], GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+*/
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
}
else if (option >= TFO_BILINEAR)
{
if (mHasMipMaps)
{
+/*
+ glTexParameteri(sGLTextureType[tex_type], GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
+ }
+ else
+ {
+ glTexParameteri(sGLTextureType[tex_type], GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+*/
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
}
else
@@ -518,6 +563,13 @@ void LLTexUnit::setTextureFilteringOption(LLTexUnit::eTextureFilterOptions optio
{
if (mHasMipMaps)
{
+/*
+ glTexParameteri(sGLTextureType[tex_type], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
+ }
+ else
+ {
+ glTexParameteri(sGLTextureType[tex_type], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+*/
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
}
else
@@ -530,6 +582,13 @@ void LLTexUnit::setTextureFilteringOption(LLTexUnit::eTextureFilterOptions optio
{
if (LLImageGL::sGlobalUseAnisotropic && option == TFO_ANISOTROPIC)
{
+/*
+ glTexParameterf(sGLTextureType[tex_type], GL_TEXTURE_MAX_ANISOTROPY, gGLManager.mMaxAnisotropy);
+ }
+ else
+ {
+ glTexParameterf(sGLTextureType[tex_type], GL_TEXTURE_MAX_ANISOTROPY, 1.f);
+*/
//glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, gGLManager.mMaxAnisotropy);
//We plan to add a setting. For now we stick to a low value.
glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, 4.0);
@@ -621,30 +680,6 @@ GLint LLTexUnit::getTextureSourceType(eTextureBlendSrc src, bool isAlpha)
}
}
-void LLTexUnit::setColorScale(S32 scale)
-{
- if (mCurrColorScale != scale || gGL.mDirty)
- {
- mCurrColorScale = scale;
- gGL.flush();
-#if GL_VERSION_1_1
- glTexEnvi( GL_TEXTURE_ENV, GL_RGB_SCALE, scale );
-#endif
- }
-}
-
-void LLTexUnit::setAlphaScale(S32 scale)
-{
- if (mCurrAlphaScale != scale || gGL.mDirty)
- {
- mCurrAlphaScale = scale;
- gGL.flush();
-#if GL_VERSION_1_1
- glTexEnvi( GL_TEXTURE_ENV, GL_ALPHA_SCALE, scale );
-#endif
- }
-}
-
// 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)
@@ -1308,9 +1343,7 @@ void LLRender::translateUI(F32 x, F32 y, F32 z)
LL_ERRS() << "Need to push a UI translation frame before offsetting" << LL_ENDL;
}
- mUIOffset.back().mV[0] += x;
- mUIOffset.back().mV[1] += y;
- mUIOffset.back().mV[2] += z;
+ mUIOffset.back().add(LLVector4a(x, y, z));
}
void LLRender::scaleUI(F32 x, F32 y, F32 z)
@@ -1320,14 +1353,14 @@ void LLRender::scaleUI(F32 x, F32 y, F32 z)
LL_ERRS() << "Need to push a UI transformation frame before scaling." << LL_ENDL;
}
- mUIScale.back().scaleVec(LLVector3(x,y,z));
+ mUIScale.back().mul(LLVector4a(x, y, z));
}
void LLRender::pushUIMatrix()
{
if (mUIOffset.empty())
{
- mUIOffset.emplace_back(0.f,0.f,0.f);
+ mUIOffset.emplace_back(0.f);
}
else
{
@@ -1336,7 +1369,7 @@ void LLRender::pushUIMatrix()
if (mUIScale.empty())
{
- mUIScale.emplace_back(1.f,1.f,1.f);
+ mUIScale.emplace_back(1.f);
}
else
{
@@ -1358,18 +1391,20 @@ LLVector3 LLRender::getUITranslation()
{
if (mUIOffset.empty())
{
- return LLVector3(0,0,0);
+ return LLVector3::zero;
}
- return mUIOffset.back();
+
+ return LLVector3(mUIOffset.back().getF32ptr());
}
LLVector3 LLRender::getUIScale()
{
if (mUIScale.empty())
{
- return LLVector3(1,1,1);
+ return LLVector3::all_one;
}
- return mUIScale.back();
+
+ return LLVector3(mUIScale.back().getF32ptr());
}
@@ -1379,8 +1414,9 @@ void LLRender::loadUIIdentity()
{
LL_ERRS() << "Need to push UI translation frame before clearing offset." << LL_ENDL;
}
- mUIOffset.back().setVec(0,0,0);
- mUIScale.back().setVec(1,1,1);
+
+ mUIOffset.back().clear();
+ mUIScale.back().splat(1);
}
void LLRender::setColorMask(bool writeColor, bool writeAlpha)
@@ -1816,8 +1852,10 @@ void LLRender::vertex3f(const GLfloat& x, const GLfloat& y, const GLfloat& z)
}
else
{
- LLVector3 vert = (LLVector3(x,y,z)+mUIOffset.back()).scaledVec(mUIScale.back());
- mVerticesp[mCount].set(vert.mV[VX], vert.mV[VY], vert.mV[VZ]);
+ LLVector4a vert(x, y, z);
+ vert.add(mUIOffset.back());
+ vert.mul(mUIScale.back());
+ mVerticesp[mCount] = vert;
}
mCount++;
diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h
index a755ddd2b1..e6ae3baac6 100644
--- a/indra/llrender/llrender.h
+++ b/indra/llrender/llrender.h
@@ -44,6 +44,7 @@
#include "llglheaders.h"
#include "llmatrix4a.h"
#include "glm/mat4x4.hpp"
+#include <boost/align/aligned_allocator.hpp>
#include <array>
#include <list>
@@ -214,11 +215,19 @@ public:
// Warning: this stays set for the bound texture forever,
// make sure you want to permanently change the address mode for the bound texture.
void setTextureAddressMode(eTextureAddressMode mode);
+/*
+ // MUST already be active and bound
+ void setTextureAddressModeFast(eTextureAddressMode mode, eTextureType tex_type);
+*/
// Sets the filtering options used to sample the texture
// Warning: this stays set for the bound texture forever,
// make sure you want to permanently change the filtering for the bound texture.
void setTextureFilteringOption(LLTexUnit::eTextureFilterOptions option);
+/*
+ // MUST already be active and bound
+ void setTextureFilteringOptionFast(LLTexUnit::eTextureFilterOptions option, eTextureType tex_type);
+*/
static U32 getInternalType(eTextureType type);
@@ -234,13 +243,9 @@ protected:
S32 mIndex;
U32 mCurrTexture;
eTextureType mCurrTexType;
- S32 mCurrColorScale;
- S32 mCurrAlphaScale;
bool mHasMipMaps;
void debugTextureUnit(void);
- void setColorScale(S32 scale);
- void setAlphaScale(S32 scale);
GLint getTextureSource(eTextureBlendSrc src);
GLint getTextureSourceType(eTextureBlendSrc src, bool isAlpha = false);
};
@@ -534,8 +539,8 @@ private:
eBlendFactor mCurrBlendAlphaSFactor;
eBlendFactor mCurrBlendAlphaDFactor;
- std::vector<LLVector3> mUIOffset;
- std::vector<LLVector3> mUIScale;
+ std::vector<LLVector4a, boost::alignment::aligned_allocator<LLVector4a, 16> > mUIOffset;
+ std::vector<LLVector4a, boost::alignment::aligned_allocator<LLVector4a, 16> > mUIScale;
};
extern F32 gGLModelView[16];
diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp
index e898e03feb..ebdc609f94 100644
--- a/indra/llrender/llrendertarget.cpp
+++ b/indra/llrender/llrendertarget.cpp
@@ -524,13 +524,12 @@ void LLRenderTarget::bindTarget(std::string name_, U32 mode_)
else if(mMode == 1)
{
glDrawBuffers(static_cast<GLsizei>(mTex.size()), drawbuffers);
- glReadBuffer(GL_NONE);
+ //glReadBuffer(GL_NONE);
LOG_GLERROR(mName+" draw buffer");
}
else if(mMode == 2)
{
- GLenum buffers[] = {GL_NONE};
- glDrawBuffers(0, buffers);
+ //glDrawBuffer(GL_NONE);
glReadBuffer(GL_COLOR_ATTACHMENT0);
LOG_GLERROR(mName+" read buffer");
}
@@ -592,24 +591,6 @@ U32 LLRenderTarget::getNumTextures() const
void LLRenderTarget::bindTexture(U32 index, S32 channel, LLTexUnit::eTextureFilterOptions filter_options)
{
gGL.getTexUnit(channel)->bindManual(mUsage, getTexture(index), filter_options == LLTexUnit::TFO_TRILINEAR || filter_options == LLTexUnit::TFO_ANISOTROPIC);
-
- bool isSRGB = false;
- llassert(mInternalFormat.size() > index);
- switch (mInternalFormat[index])
- {
- case GL_SRGB:
- case GL_SRGB8:
-#if GL_VERSION_2_1
- case GL_SRGB_ALPHA:
-#endif
- case GL_SRGB8_ALPHA8:
- isSRGB = true;
- break;
-
- default:
- break;
- }
-
gGL.getTexUnit(channel)->setTextureFilteringOption(filter_options);
LOG_GLERROR(mName + " bindTexture()");
diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp
index 81d45bc431..6dd3634309 100644
--- a/indra/llrender/llshadermgr.cpp
+++ b/indra/llrender/llshadermgr.cpp
@@ -263,6 +263,7 @@ bool LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
}
}
+ /*
if (features->hasGamma || features->isDeferred)
{
if (!shader->attachFragmentObject("windlight/gammaF.glsl"))
@@ -270,6 +271,7 @@ bool LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
return false;
}
}
+ */
if (features->hasAtmospherics || features->isDeferred)
{
@@ -458,7 +460,7 @@ GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_lev
// endsure work-around for missing GLSL funcs gets propogated to feature shader files (e.g. srgbF.glsl)
#if LL_DARWIN
- if (defines)
+ if (!gGLManager.mIsApple && defines)
{
(*defines)["OLD_SELECT"] = "1";
}
@@ -989,16 +991,17 @@ bool LLShaderMgr::validateProgramObject(GLuint obj)
return success;
}
-void LLShaderMgr::initShaderCache(bool enabled, const LLUUID& old_cache_version, const LLUUID& current_cache_version)
+void LLShaderMgr::initShaderCache(bool enabled, const LLUUID& old_cache_version, const LLUUID& current_cache_version, bool second_instance)
{
- LL_INFOS() << "Initializing shader cache" << LL_ENDL;
+ LL_PROFILE_ZONE_SCOPED;
+ LL_INFOS("ShaderMgr") << "Initializing shader cache" << LL_ENDL;
mShaderCacheEnabled = gGLManager.mGLVersion >= 4.09 && enabled;
- if(!mShaderCacheEnabled || mShaderCacheInitialized)
+ if(!mShaderCacheEnabled || mShaderCacheVersion.notNull())
return;
- mShaderCacheInitialized = true;
+ mShaderCacheVersion = current_cache_version;
mShaderCacheDir = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "shader_cache");
LLFile::mkdir(mShaderCacheDir);
@@ -1007,16 +1010,19 @@ void LLShaderMgr::initShaderCache(bool enabled, const LLUUID& old_cache_version,
std::string meta_out_path = gDirUtilp->add(mShaderCacheDir, "shaderdata.llsd");
if (gDirUtilp->fileExists(meta_out_path))
{
- LL_INFOS() << "Loading shader cache metadata" << LL_ENDL;
+ LL_PROFILE_ZONE_NAMED("shader_cache");
+ LL_INFOS("ShaderMgr") << "Loading shader cache metadata" << LL_ENDL;
- llifstream instream(meta_out_path);
+ llifstream instream(meta_out_path, std::ifstream::in | std::ifstream::binary);
LLSD in_data;
- LLSDSerialize::fromNotation(in_data, instream, LLSDSerialize::SIZE_UNLIMITED);
+ // todo: this is likely very expensive to parse, should use binary
+ LLSDSerialize::fromBinary(in_data, instream, LLSDSerialize::SIZE_UNLIMITED);
instream.close();
- if (old_cache_version == current_cache_version)
+ if (old_cache_version == current_cache_version
+ && in_data["version"].asUUID() == current_cache_version)
{
- for (const auto& data_pair : llsd::inMap(in_data))
+ for (const auto& data_pair : llsd::inMap(in_data["shaders"]))
{
ProgramBinaryData binary_info = ProgramBinaryData();
binary_info.mBinaryFormat = data_pair.second["binary_format"].asInteger();
@@ -1025,11 +1031,15 @@ void LLShaderMgr::initShaderCache(bool enabled, const LLUUID& old_cache_version,
mShaderBinaryCache.insert_or_assign(LLUUID(data_pair.first), binary_info);
}
}
- else
+ else if (!second_instance)
{
- LL_INFOS() << "Shader cache version mismatch detected. Purging." << LL_ENDL;
+ LL_INFOS("ShaderMgr") << "Shader cache version mismatch detected. Purging." << LL_ENDL;
clearShaderCache();
}
+ else
+ {
+ LL_INFOS("ShaderMgr") << "Shader cache version mismatch detected." << LL_ENDL;
+ }
}
}
}
@@ -1037,7 +1047,7 @@ void LLShaderMgr::initShaderCache(bool enabled, const LLUUID& old_cache_version,
void LLShaderMgr::clearShaderCache()
{
std::string shader_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "shader_cache");
- LL_INFOS() << "Removing shader cache at " << shader_cache << LL_ENDL;
+ LL_INFOS("ShaderMgr") << "Removing shader cache at " << shader_cache << LL_ENDL;
const std::string mask = "*";
gDirUtilp->deleteFilesInDir(shader_cache, mask);
mShaderBinaryCache.clear();
@@ -1046,10 +1056,22 @@ void LLShaderMgr::clearShaderCache()
void LLShaderMgr::persistShaderCacheMetadata()
{
if(!mShaderCacheEnabled) return;
+ if (mShaderCacheVersion.isNull())
+ {
+ LL_WARNS("ShaderMgr") << "Attempted to save shader cache with no version set" << LL_ENDL;
+ return;
+ }
- LL_INFOS() << "Persisting shader cache metadata to disk" << LL_ENDL;
+ LL_INFOS("ShaderMgr") << "Persisting shader cache metadata to disk" << LL_ENDL;
- LLSD out = LLSD::emptyMap();
+ LLSD out;
+ // Settings and shader cache get saved at different time, thus making
+ // RenderShaderCacheVersion unreliable when running multiple viewer
+ // instances, or for cases where viewer crashes before saving settings.
+ // Dupplicate version to the cache itself.
+ out["version"] = mShaderCacheVersion;
+ out["shaders"] = LLSD::emptyMap();
+ LLSD &shaders = out["shaders"];
static const F32 LRU_TIME = (60.f * 60.f) * 24.f * 7.f; // 14 days
const F32 current_time = (F32)LLTimer::getTotalSeconds();
@@ -1068,14 +1090,19 @@ void LLShaderMgr::persistShaderCacheMetadata()
data["binary_format"] = LLSD::Integer(shader_metadata.mBinaryFormat);
data["binary_size"] = LLSD::Integer(shader_metadata.mBinaryLength);
data["last_used"] = LLSD::Real(shader_metadata.mLastUsedTime);
- out[it->first.asString()] = data;
+ shaders[it->first.asString()] = data;
++it;
}
}
std::string meta_out_path = gDirUtilp->add(mShaderCacheDir, "shaderdata.llsd");
- llofstream outstream(meta_out_path);
- LLSDSerialize::toNotation(out, outstream);
+ llofstream outstream(meta_out_path, std::ios_base::out | std::ios_base::binary);
+ if (!outstream.is_open())
+ {
+ LL_WARNS("ShaderMgr") << "Failed to open file. Unable to save shader cache to: " << mShaderCacheDir << LL_ENDL;
+ return;
+ }
+ LLSDSerialize::toBinary(out, outstream);
outstream.close();
}
diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h
index 19416066a5..4cfa78632b 100644
--- a/indra/llrender/llshadermgr.h
+++ b/indra/llrender/llshadermgr.h
@@ -377,7 +377,7 @@ public:
// Implemented in the application to actually update out of date uniforms for a particular shader
virtual void updateShaderUniforms(LLGLSLShader * shader) = 0; // Pure Virtual
- void initShaderCache(bool enabled, const LLUUID& old_cache_version, const LLUUID& current_cache_version);
+ void initShaderCache(bool enabled, const LLUUID& old_cache_version, const LLUUID& current_cache_version, bool second_instance);
void clearShaderCache();
void persistShaderCacheMetadata();
@@ -401,7 +401,7 @@ public:
F32 mLastUsedTime = 0.0;
};
std::map<LLUUID, ProgramBinaryData> mShaderBinaryCache;
- bool mShaderCacheInitialized = false;
+ LLUUID mShaderCacheVersion;
bool mShaderCacheEnabled = false;
std::string mShaderCacheDir;
diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp
index 1bd7a57cd9..4b62c3476f 100644
--- a/indra/llrender/llvertexbuffer.cpp
+++ b/indra/llrender/llvertexbuffer.cpp
@@ -794,12 +794,6 @@ void LLVertexBuffer::drawElements(U32 mode, const LLVector4a* pos, const LLVecto
gGL.syncMatrices();
- U32 mask = LLVertexBuffer::MAP_VERTEX;
- if (tc)
- {
- mask = mask | LLVertexBuffer::MAP_TEXCOORD0;
- }
-
unbind();
gGL.begin(mode);
@@ -892,7 +886,7 @@ bool LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_of
return true;
}
-#ifdef LL_PROFILER_ENABLE_RENDER_DOC
+#if LL_PROFILER_ENABLE_RENDER_DOC
void LLVertexBuffer::setLabel(const char* label) {
LL_LABEL_OBJECT_GL(GL_BUFFER, mGLBuffer, strlen(label), label);
}
diff --git a/indra/llrender/llvertexbuffer.h b/indra/llrender/llvertexbuffer.h
index bf5f2b5ab6..b0f6ae7d8d 100644
--- a/indra/llrender/llvertexbuffer.h
+++ b/indra/llrender/llvertexbuffer.h
@@ -281,7 +281,7 @@ public:
//for debugging, validate data in given range is valid
bool validateRange(U32 start, U32 end, U32 count, U32 offset) const;
- #ifdef LL_PROFILER_ENABLE_RENDER_DOC
+ #if LL_PROFILER_ENABLE_RENDER_DOC
void setLabel(const char* label);
#endif
@@ -342,7 +342,7 @@ public:
static U32 sVertexCount;
};
-#ifdef LL_PROFILER_ENABLE_RENDER_DOC
+#if LL_PROFILER_ENABLE_RENDER_DOC
#define LL_LABEL_VERTEX_BUFFER(buf, name) buf->setLabel(name)
#else
#define LL_LABEL_VERTEX_BUFFER(buf, name)