void LLMultisampleBuffer::bindTarget()
{
	bindTarget(this);
}
bool LLRenderTarget::addColorAttachment(U32 color_fmt)
{
	if (color_fmt == 0)
	{
		return true;
	}

	U32 offset = mTex.size();
	if (offset >= 4 ||
		(offset > 0 && (mFBO == 0 || !gGLManager.mHasDrawBuffers)))
	{
		llerrs << "Too many color attachments!" << llendl;
	}

	U32 tex;
	LLImageGL::generateTextures(1, &tex);
	gGL.getTexUnit(0)->bindManual(mUsage, tex);

	stop_glerror();


	{
		clear_glerror();
		LLImageGL::setManualImage(LLTexUnit::getInternalType(mUsage), 0, color_fmt, mResX, mResY, GL_RGBA, GL_UNSIGNED_BYTE, NULL, false);
		if (glGetError() != GL_NO_ERROR)
		{
			llwarns << "Could not allocate color buffer for render target." << llendl;
			return false;
		}
	}

	sBytesAllocated += mResX*mResY*4;

	stop_glerror();

	
	if (offset == 0)
		{ //use bilinear filtering on single texture render targets that aren't multisampled
		gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
			stop_glerror();
	}
	else
	{ //don't filter data attachments
		gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
			stop_glerror();
	}
	if (mUsage != LLTexUnit::TT_RECT_TEXTURE)
	{
		gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_MIRROR);
			stop_glerror();
	}
	else
	{
		// ATI doesn't support mirrored repeat for rectangular textures.
		gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
			stop_glerror();
	}
		
	if (mFBO)
	{
		stop_glerror();
		glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+offset,
			LLTexUnit::getInternalType(mUsage), tex, 0);
			stop_glerror();

		check_framebuffer_status();
		
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
	}

	mTex.push_back(tex);

	if (gDebugGL)
	{ //bind and unbind to validate target
		bindTarget();
		flush();
	}

	return true;
}
Пример #3
0
void LLRenderTarget::addColorAttachment(U32 color_fmt)
{
    if (color_fmt == 0)
    {
        return;
    }

    U32 offset = mTex.size();
    if (offset >= 4 ||
            (offset > 0 && (mFBO == 0 || !gGLManager.mHasDrawBuffers)))
    {
        llerrs << "Too many color attachments!" << llendl;
    }

    U32 tex;
    LLImageGL::generateTextures(1, &tex);
    gGL.getTexUnit(0)->bindManual(mUsage, tex);

    stop_glerror();


#ifdef GL_ARB_texture_multisample
    if (mSamples > 1)
    {
        glTexImage2DMultisample(LLTexUnit::getInternalType(mUsage), mSamples, color_fmt, mResX, mResY, GL_TRUE);
    }
    else
#else
    llassert_always(mSamples <= 1);
#endif
    {
        LLImageGL::setManualImage(LLTexUnit::getInternalType(mUsage), 0, color_fmt, mResX, mResY, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
    }

    stop_glerror();

    if (mSamples == 0)
    {
        if (offset == 0)
        {   //use bilinear filtering on single texture render targets that aren't multisampled
            gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
            stop_glerror();
        }
        else
        {   //don't filter data attachments
            gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
            stop_glerror();
        }

        if (mUsage != LLTexUnit::TT_RECT_TEXTURE)
        {
            gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_MIRROR);
            stop_glerror();
        }
        else
        {
            // ATI doesn't support mirrored repeat for rectangular textures.
            gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
            stop_glerror();
        }
    }

    if (mFBO)
    {
        stop_glerror();
        glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+offset,
                               LLTexUnit::getInternalType(mUsage), tex, 0);
        stop_glerror();

        check_framebuffer_status();

        glBindFramebuffer(GL_FRAMEBUFFER, 0);
    }

    mTex.push_back(tex);

    if (gDebugGL)
    {   //bind and unbind to validate target
        bindTarget();
        flush();
    }

}