Added LLRenderTarget::resize and did a little cleanup.

This commit is contained in:
Shyotl
2012-07-26 03:05:22 -05:00
parent 726d8248c5
commit 701230b49c
3 changed files with 166 additions and 81 deletions

View File

@@ -76,6 +76,42 @@ LLRenderTarget::~LLRenderTarget()
release();
}
void LLRenderTarget::resize(U32 resx, U32 resy, U32 color_fmt)
{
//for accounting, get the number of pixels added/subtracted
S32 pix_diff = (resx*resy)-(mResX*mResY);
mResX = resx;
mResY = resy;
for (U32 i = 0; i < mTex.size(); ++i)
{ //resize color attachments
gGL.getTexUnit(0)->bindManual(mUsage, mTex[i]);
LLImageGL::setManualImage(LLTexUnit::getInternalType(mUsage), 0, color_fmt, mResX, mResY, GL_RGBA, GL_UNSIGNED_BYTE, NULL, false);
sBytesAllocated += pix_diff*4;
}
if (mDepth)
{ //resize depth attachment
if (mStencil)
{
//use render buffers where stencil buffers are in play
glBindRenderbuffer(GL_RENDERBUFFER, mDepth);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, mResX, mResY);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
}
else
{
gGL.getTexUnit(0)->bindManual(mUsage, mDepth);
U32 internal_type = LLTexUnit::getInternalType(mUsage);
LLImageGL::setManualImage(internal_type, 0, GL_DEPTH_COMPONENT24, mResX, mResY, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL, false);
}
sBytesAllocated += pix_diff*4;
}
if(mSampleBuffer)
mSampleBuffer->resize(resx,resy);
}
void LLRenderTarget::setSampleBuffer(LLMultisampleBuffer* buffer)
{
@@ -241,14 +277,14 @@ bool LLRenderTarget::allocateDepth()
gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
}
sBytesAllocated += mResX*mResY*4;
if (glGetError() != GL_NO_ERROR)
{
llwarns << "Unable to allocate depth buffer for render target." << llendl;
return false;
}
sBytesAllocated += mResX*mResY*4;
return true;
}
@@ -309,7 +345,11 @@ void LLRenderTarget::release()
else
{
//Release before delete.
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, LLTexUnit::getInternalType(mUsage), 0, 0);
if(mFBO)
{
glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, LLTexUnit::getInternalType(mUsage), 0, 0);
}
LLImageGL::deleteTextures(mUsage, 0, 0, 1, &mDepth, true);
stop_glerror();
}
@@ -341,9 +381,6 @@ void LLRenderTarget::release()
if (mTex.size() > 0)
{
//Release before delete.
for (U32 i = 0; i < mTex.size(); ++i)
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+i, LLTexUnit::getInternalType(mUsage), 0, 0);
sBytesAllocated -= mResX*mResY*4*mTex.size();
LLImageGL::deleteTextures(mUsage, mInternalFormat[0], 0, mTex.size(), &mTex[0], true);
mTex.clear();
@@ -472,7 +509,7 @@ void LLRenderTarget::flush(bool fetch_depth)
stop_glerror();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
stop_glerror();
if (mSampleBuffer)
{
LLGLEnable multisample(GL_MULTISAMPLE);
@@ -482,7 +519,7 @@ void LLRenderTarget::flush(bool fetch_depth)
check_framebuffer_status();
glBindFramebuffer(GL_READ_FRAMEBUFFER, mSampleBuffer->mFBO);
check_framebuffer_status();
stop_glerror();
if(gGLManager.mIsATI)
{
@@ -532,7 +569,6 @@ void LLRenderTarget::flush(bool fetch_depth)
}
}
}
void LLRenderTarget::copyContents(LLRenderTarget& source, S32 srcX0, S32 srcY0, S32 srcX1, S32 srcY1,
S32 dstX0, S32 dstY0, S32 dstX1, S32 dstY1, U32 mask, U32 filter)
{
@@ -642,7 +678,8 @@ void LLRenderTarget::getViewport(S32* viewport)
// LLMultisampleBuffer implementation
//==================================================
LLMultisampleBuffer::LLMultisampleBuffer() :
mSamples(0)
mSamples(0),
mColorFormat(0)
{
}
@@ -743,6 +780,7 @@ bool LLMultisampleBuffer::allocate(U32 resx, U32 resy, U32 color_fmt, bool depth
mUsage = usage;
mUseDepth = depth;
mStencil = stencil;
mColorFormat = color_fmt;
{
@@ -780,6 +818,42 @@ bool LLMultisampleBuffer::allocate(U32 resx, U32 resy, U32 color_fmt, bool depth
return addColorAttachment(color_fmt);
}
void LLMultisampleBuffer::resize(U32 resx, U32 resy)
{
//for accounting, get the number of pixels added/subtracted
S32 pix_diff = (resx*resy)-(mResX*mResY);
mResX = resx;
mResY = resy;
for (U32 i = 0; i < mTex.size(); ++i)
{ //resize color attachments
glBindRenderbuffer(GL_RENDERBUFFER, mTex[i]);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, mSamples, mColorFormat, mResX, mResY);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
sBytesAllocated += pix_diff*4;
}
if (mDepth)
{ //resize depth attachment
if (mStencil)
{
//use render buffers where stencil buffers are in play
glBindRenderbuffer(GL_RENDERBUFFER, mDepth);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, mSamples, GL_DEPTH24_STENCIL8, mResX, mResY);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
}
else
{
glBindRenderbuffer(GL_RENDERBUFFER, mDepth);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, mSamples, GL_DEPTH_COMPONENT24, mResX, mResY);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
}
sBytesAllocated += pix_diff*4;
}
}
bool LLMultisampleBuffer::addColorAttachment(U32 color_fmt)
{
if (color_fmt == 0)
@@ -829,12 +903,13 @@ bool LLMultisampleBuffer::allocateDepth()
clear_glerror();
if (mStencil)
{
glRenderbufferStorageMultisample(GL_RENDERBUFFER, mSamples, GL_DEPTH24_STENCIL8, mResX, mResY);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, mSamples, GL_DEPTH24_STENCIL8, mResX, mResY);
}
else
{
glRenderbufferStorageMultisample(GL_RENDERBUFFER, mSamples, GL_DEPTH_COMPONENT16_ARB, mResX, mResY);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, mSamples, GL_DEPTH_COMPONENT24, mResX, mResY);
}
if (glGetError() != GL_NO_ERROR)
{
llwarns << "Unable to allocate depth buffer for multisample render target." << llendl;
@@ -845,4 +920,3 @@ bool LLMultisampleBuffer::allocateDepth()
return true;
}