Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Andros Baphomet
2013-10-19 10:03:17 -04:00
29 changed files with 304 additions and 368 deletions

View File

@@ -81,7 +81,7 @@ void LLCubeMap::initGL()
{
U32 texname = 0;
LLImageGL::generateTextures(LLTexUnit::TT_CUBE_MAP, GL_RGB8, 1, &texname);
LLImageGL::generateTextures(1, &texname);
for (int i = 0; i < 6; i++)
{

View File

@@ -54,8 +54,6 @@ S32 LLImageGL::sGlobalTextureMemoryInBytes = 0;
S32 LLImageGL::sBoundTextureMemoryInBytes = 0;
S32 LLImageGL::sCurBoundTextureMemory = 0;
S32 LLImageGL::sCount = 0;
LLImageGL::dead_texturelist_t LLImageGL::sDeadTextureList[LLTexUnit::TT_NONE];
U32 LLImageGL::sCurTexName = 1;
BOOL LLImageGL::sGlobalUseAnisotropic = FALSE;
F32 LLImageGL::sLastFrameTime = 0.f;
@@ -791,8 +789,13 @@ void LLImageGL::setImage(const U8* data_in, BOOL data_hasmips)
mMipLevels = wpo2(llmax(w, h));
//use legacy mipmap generation mode
glTexParameteri(mTarget, GL_GENERATE_MIPMAP, GL_TRUE);
//use legacy mipmap generation mode (note: making this condional can cause rendering issues)
// -- but making it not conditional triggers deprecation warnings when core profile is enabled
// (some rendering issues while core profile is enabled are acceptable at this point in time)
if (!LLRender::sGLCoreProfile)
{
glTexParameteri(mTarget, GL_GENERATE_MIPMAP, GL_TRUE);
}
LLImageGL::setManualImage(mTarget, 0, mFormatInternal,
w, h,
@@ -1055,66 +1058,19 @@ BOOL LLImageGL::setSubImageFromFrameBuffer(S32 fb_x, S32 fb_y, S32 x_pos, S32 y_
// static
static LLFastTimer::DeclareTimer FTM_GENERATE_TEXTURES("generate textures");
void LLImageGL::generateTextures(LLTexUnit::eTextureType type, U32 format, S32 numTextures, U32 *textures)
void LLImageGL::generateTextures(S32 numTextures, U32 *textures)
{
LLFastTimer t(FTM_GENERATE_TEXTURES);
bool empty = true;
dead_texturelist_t::iterator iter = sDeadTextureList[type].find(format);
if (iter != sDeadTextureList[type].end())
{
empty = iter->second.empty();
}
for (S32 i = 0; i < numTextures; ++i)
{
if (!empty)
{
textures[i] = iter->second.front();
iter->second.pop_front();
empty = iter->second.empty();
}
else
{
textures[i] = sCurTexName++;
}
}
glGenTextures(numTextures, textures);
}
// static
void LLImageGL::deleteTextures(LLTexUnit::eTextureType type, U32 format, S32 mip_levels, S32 numTextures, U32 *textures, bool immediate)
void LLImageGL::deleteTextures(S32 numTextures, U32 *textures)
{
if (gGLManager.mInited)
{
if (format == 0 || type == LLTexUnit::TT_CUBE_MAP || mip_levels == -1)
{ //unknown internal format or unknown number of mip levels, not safe to reuse
glDeleteTextures(numTextures, textures);
}
else
{
for (S32 i = 0; i < numTextures; ++i)
{ //remove texture from VRAM by setting its size to zero
for (S32 j = 0; j <= mip_levels; j++)
{
gGL.getTexUnit(0)->bindManual(type, textures[i]);
glTexImage2D(LLTexUnit::getInternalType(type), j, format, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
}
llassert(std::find(sDeadTextureList[type][format].begin(),
sDeadTextureList[type][format].end(), textures[i]) ==
sDeadTextureList[type][format].end());
sDeadTextureList[type][format].push_back(textures[i]);
}
}
glDeleteTextures(numTextures, textures);
}
/*if (immediate)
{
LLImageGL::deleteDeadTextures();
}*/
}
// static
@@ -1242,11 +1198,11 @@ BOOL LLImageGL::createGLTexture()
if(mTexName)
{
LLImageGL::deleteTextures(mBindTarget, mFormatInternal, mMipLevels, 1, (reinterpret_cast<GLuint*>(&mTexName))) ;
LLImageGL::deleteTextures(1, (reinterpret_cast<GLuint*>(&mTexName))) ;
}
LLImageGL::generateTextures(mBindTarget, mFormatInternal, 1, &mTexName);
LLImageGL::generateTextures(1, &mTexName);
stop_glerror();
if (!mTexName)
{
@@ -1363,7 +1319,7 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_
}
else
{
LLImageGL::generateTextures(mBindTarget, mFormatInternal, 1, &mTexName);
LLImageGL::generateTextures(1, &mTexName);
stop_glerror();
{
llverify(gGL.getTexUnit(0)->bind(this));
@@ -1413,7 +1369,7 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_
decTextureCounter(mTextureMemory, mComponents, mCategory) ;
}
LLImageGL::deleteTextures(mBindTarget, mFormatInternal, mMipLevels, 1, &old_name);
LLImageGL::deleteTextures(1, &old_name);
stop_glerror();
}
@@ -1548,34 +1504,6 @@ void LLImageGL::deleteDeadTextures()
{
bool reset = false;
/*for(U32 i=0;i<LLTexUnit::TT_NONE;++i)
{
for(dead_texturelist_t::iterator it=sDeadTextureList[i].begin();it!=sDeadTextureList[i].end();++it)
{
while(!it->second.empty())
{
GLuint tex = it->second.front();
it->second.pop_front();
for (int j = 0; j < gGLManager.mNumTextureImageUnits; j++)
{
LLTexUnit* tex_unit = gGL.getTexUnit(j);
if (tex_unit && tex_unit->getCurrTexture() == tex)
{
tex_unit->unbind(tex_unit->getCurrType());
stop_glerror();
if (i > 0)
{
reset = true;
}
}
}
glDeleteTextures(1, &tex);
stop_glerror();
}
}
}*/
if (reset)
{
gGL.getTexUnit(0)->activate();
@@ -1596,7 +1524,7 @@ void LLImageGL::destroyGLTexture()
mTextureMemory = 0;
}
LLImageGL::deleteTextures(mBindTarget, mFormatInternal, mMipLevels, 1, &mTexName);
LLImageGL::deleteTextures(1, &mTexName);
mCurrentDiscardLevel = -1 ; //invalidate mCurrentDiscardLevel.
mTexName = 0;
mGLTextureCreated = FALSE ;

View File

@@ -45,16 +45,9 @@ class LLImageGL : public LLRefCount
{
friend class LLTexUnit;
public:
static U32 sCurTexName;
//previously used but now available texture names
// sDeadTextureList[<usage>][<internal format>]
typedef std::map<U32, std::list<U32> > dead_texturelist_t;
static dead_texturelist_t sDeadTextureList[LLTexUnit::TT_NONE];
// These 2 functions replace glGenTextures() and glDeleteTextures()
static void generateTextures(LLTexUnit::eTextureType type, U32 format, S32 numTextures, U32 *textures);
static void deleteTextures(LLTexUnit::eTextureType type, U32 format, S32 mip_levels, S32 numTextures, U32 *textures, bool immediate = false);
static void generateTextures(S32 numTextures, U32 *textures);
static void deleteTextures(S32 numTextures, U32 *textures);
static void deleteDeadTextures();
// Size calculation

View File

@@ -407,13 +407,13 @@ void LLPostProcess::createScreenTextures()
stop_glerror();
if(mDepthTexture)
LLImageGL::deleteTextures(type, 0, 0, 1, &mDepthTexture, true);
LLImageGL::deleteTextures(1, &mDepthTexture);
for(std::list<LLPointer<LLPostProcessShader> >::iterator it=mShaders.begin();it!=mShaders.end();++it)
{
if((*it)->getDepthChannel()>=0)
{
LLImageGL::generateTextures(type, GL_DEPTH_COMPONENT24, 1, &mDepthTexture);
LLImageGL::generateTextures(1, &mDepthTexture);
gGL.getTexUnit(0)->bindManual(type, mDepthTexture);
LLImageGL::setManualImage(LLTexUnit::getInternalType(type), 0, GL_DEPTH_COMPONENT24, mScreenWidth, mScreenHeight, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL, false);
stop_glerror();
@@ -438,7 +438,7 @@ void LLPostProcess::createNoiseTexture()
if(mNoiseTexture->createGLTexture())
{
gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mNoiseTexture->getTexName());
LLImageGL::setManualImage(GL_TEXTURE_2D, 0, GL_LUMINANCE, NOISE_SIZE, NOISE_SIZE, GL_LUMINANCE, GL_UNSIGNED_BYTE, &buffer[0]);
LLImageGL::setManualImage(GL_TEXTURE_2D, 0, GL_RED, NOISE_SIZE, NOISE_SIZE, GL_RED, GL_UNSIGNED_BYTE, &buffer[0]);
stop_glerror();
gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_WRAP);
@@ -451,7 +451,7 @@ void LLPostProcess::destroyGL()
mRenderTarget[0].release();
mRenderTarget[1].release();
if(mDepthTexture)
LLImageGL::deleteTextures(LLTexUnit::TT_RECT_TEXTURE, 0, 0, 1, &mDepthTexture, true);
LLImageGL::deleteTextures(1, &mDepthTexture);
mDepthTexture=0;
mNoiseTexture = NULL ;
mVBO = NULL ;

View File

@@ -51,7 +51,7 @@ void check_framebuffer_status()
}
bool LLRenderTarget::sUseFBO = false;
U32 LLRenderTarget::sCurFBO = 0;
LLRenderTarget* LLRenderTarget::sCurFBO = 0;
LLRenderTarget::LLRenderTarget() :
mResX(0),
@@ -161,7 +161,7 @@ bool LLRenderTarget::allocate(U32 resx, U32 resy, U32 color_fmt, bool depth, boo
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, LLTexUnit::getInternalType(mUsage), mDepth, 0);
stop_glerror();
}
glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO);
glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO ? sCurFBO->getFBO() : 0);
}
stop_glerror();
@@ -194,7 +194,7 @@ bool LLRenderTarget::addColorAttachment(U32 color_fmt)
}
U32 tex;
LLImageGL::generateTextures(mUsage, color_fmt, 1, &tex);
LLImageGL::generateTextures(1, &tex);
gGL.getTexUnit(0)->bindManual(mUsage, tex);
stop_glerror();
@@ -248,7 +248,7 @@ bool LLRenderTarget::addColorAttachment(U32 color_fmt)
check_framebuffer_status();
glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO);
glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO ? sCurFBO->getFBO() : 0);
}
mTex.push_back(tex);
@@ -277,10 +277,7 @@ bool LLRenderTarget::allocateDepth()
}
else
{
if(!mStencil)
LLImageGL::generateTextures(mUsage, GL_DEPTH_COMPONENT24, 1, &mDepth);
else
LLImageGL::generateTextures(mUsage, GL_DEPTH24_STENCIL8, 1, &mDepth);
LLImageGL::generateTextures(1, &mDepth);
gGL.getTexUnit(0)->bindManual(mUsage, mDepth);
U32 internal_type = LLTexUnit::getInternalType(mUsage);
@@ -343,7 +340,7 @@ void LLRenderTarget::shareDepthBuffer(LLRenderTarget& target)
check_framebuffer_status();
glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO);
glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO ? sCurFBO->getFBO() : 0);
target.mUseDepth = true;
}
@@ -365,8 +362,9 @@ void LLRenderTarget::release()
{
glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, LLTexUnit::getInternalType(mUsage), 0, 0);
glBindFramebuffer(GL_FRAMEBUFFER,0);
}
LLImageGL::deleteTextures(mUsage, 0, 0, 1, &mDepth, true);
LLImageGL::deleteTextures(1, &mDepth);
stop_glerror();
}
mDepth = 0;
@@ -386,6 +384,7 @@ void LLRenderTarget::release()
{ //attached as a texture
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, LLTexUnit::getInternalType(mUsage), 0, 0);
}
glBindFramebuffer(GL_FRAMEBUFFER,0);
mUseDepth = false;
}
@@ -398,7 +397,7 @@ void LLRenderTarget::release()
if (mTex.size() > 0)
{
sBytesAllocated -= mResX*mResY*4*mTex.size();
LLImageGL::deleteTextures(mUsage, mInternalFormat[0], 0, mTex.size(), &mTex[0], true);
LLImageGL::deleteTextures(mTex.size(), &mTex[0]);
mTex.clear();
mInternalFormat.clear();
}
@@ -414,17 +413,18 @@ void LLRenderTarget::bindTarget()
if (mFBO)
{
stop_glerror();
mPreviousFBO = sCurFBO;
if (mSampleBuffer)
{
mSampleBuffer->bindTarget(this);
sCurFBO = mSampleBuffer->mFBO;
sCurFBO = mSampleBuffer;
stop_glerror();
}
else
{
glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
sCurFBO = mFBO;
sCurFBO = this;
stop_glerror();
if (gGLManager.mHasDrawBuffers)
@@ -577,8 +577,18 @@ void LLRenderTarget::flush(bool fetch_depth)
}
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
}
glBindFramebuffer(GL_FRAMEBUFFER, mPreviousFBO);
glBindFramebuffer(GL_FRAMEBUFFER, mPreviousFBO ? mPreviousFBO->getFBO() : 0);
sCurFBO = mPreviousFBO;
if(mPreviousFBO)
{
glViewport(0, 0, mPreviousFBO->mResX, mPreviousFBO->mResY);
mPreviousFBO = NULL;
}
else
{
glViewport(gGLViewport[0],gGLViewport[1],gGLViewport[2],gGLViewport[3]);
}
stop_glerror();
}
}
@@ -613,7 +623,7 @@ void LLRenderTarget::copyContents(LLRenderTarget& source, S32 srcX0, S32 srcY0,
stop_glerror();
glCopyTexSubImage2D(LLTexUnit::getInternalType(mUsage), 0, srcX0, srcY0, dstX0, dstY0, dstX1, dstY1);
stop_glerror();
glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO);
glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO ? sCurFBO->getFBO() : 0);
stop_glerror();
}
else
@@ -636,7 +646,7 @@ void LLRenderTarget::copyContents(LLRenderTarget& source, S32 srcX0, S32 srcY0,
stop_glerror();
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
stop_glerror();
glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO);
glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO ? sCurFBO->getFBO() : 0);
stop_glerror();
}
}
@@ -670,7 +680,7 @@ void LLRenderTarget::copyContentsToFramebuffer(LLRenderTarget& source, S32 srcX0
if(mask)
glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
stop_glerror();
glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO);
glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO ? sCurFBO->getFBO() : 0);
stop_glerror();
}
}
@@ -819,7 +829,7 @@ bool LLMultisampleBuffer::allocate(U32 resx, U32 resy, U32 color_fmt, bool depth
}
stop_glerror();
glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO);
glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO ? sCurFBO->getFBO() : 0);
stop_glerror();
@@ -898,7 +908,7 @@ bool LLMultisampleBuffer::addColorAttachment(U32 color_fmt)
glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+offset, GL_RENDERBUFFER, tex);
check_framebuffer_status();
glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO);
glBindFramebuffer(GL_FRAMEBUFFER, sCurFBO ? sCurFBO->getFBO() : 0);
}
mTex.push_back(tex);

View File

@@ -65,7 +65,7 @@ public:
//whether or not to use FBO implementation
static bool sUseFBO;
static U32 sBytesAllocated;
static U32 sCurFBO;
static LLRenderTarget* sCurFBO;
LLRenderTarget();
virtual ~LLRenderTarget();
@@ -154,7 +154,7 @@ protected:
std::vector<U32> mTex;
std::vector<U32> mInternalFormat;
U32 mFBO;
U32 mPreviousFBO;
LLRenderTarget* mPreviousFBO;
U32 mDepth;
bool mStencil;
bool mUseDepth;

View File

@@ -90,7 +90,6 @@ LLVBOPool LLVertexBuffer::sDynamicIBOPool(GL_DYNAMIC_DRAW_ARB, GL_ELEMENT_ARRAY_
U32 LLVBOPool::sBytesPooled = 0;
U32 LLVBOPool::sIndexBytesPooled = 0;
U32 LLVBOPool::sCurGLName = 1;
std::list<U32> LLVertexBuffer::sAvailableVAOName;
U32 LLVertexBuffer::sCurVAOName = 1;
@@ -124,16 +123,8 @@ U32 LLVBOPool::genBuffer()
{
U32 ret = 0;
if (mGLNamePool.empty())
{
ret = sCurGLName++;
}
else
{
ret = mGLNamePool.front();
mGLNamePool.pop_front();
}
glGenBuffersARB(1, &ret);
return ret;
}
@@ -145,12 +136,9 @@ void LLVBOPool::deleteBuffer(U32 name)
glBindBufferARB(mType, name);
glBufferDataARB(mType, 0, NULL, mUsage);
llassert(std::find(mGLNamePool.begin(), mGLNamePool.end(), name) == mGLNamePool.end());
mGLNamePool.push_back(name);
glBindBufferARB(mType, 0);
glDeleteBuffersARB(1, &name);
}
}
@@ -1304,7 +1292,7 @@ void LLVertexBuffer::allocateBuffer(S32 nverts, S32 nindices, bool create)
//actually allocate space for the vertex buffer if using VBO mapping
flush();
if (gGLManager.mHasVertexArrayObject && useVBOs() && (LLRender::sGLCoreProfile || sUseVAO))
if (gGLManager.mHasVertexArrayObject && useVBOs() && sUseVAO)
{
#if GL_ARB_vertex_array_object
mGLArray = getVAOName();

View File

@@ -57,8 +57,6 @@ public:
static U32 sBytesPooled;
static U32 sIndexBytesPooled;
static U32 sCurGLName;
LLVBOPool(U32 vboUsage, U32 vboType);
const U32 mUsage;
@@ -86,8 +84,6 @@ public:
volatile U8* mClientData;
};
std::list<U32> mGLNamePool;
typedef std::list<Record> record_list_t;
std::vector<record_list_t> mFreeList;
std::vector<U32> mMissCount;