Esempio n. 1
0
void LLRender::blendFunc(eBlendFactor color_sfactor, eBlendFactor color_dfactor,
			 eBlendFactor alpha_sfactor, eBlendFactor alpha_dfactor)
{
	llassert(color_sfactor < BF_UNDEF);
	llassert(color_dfactor < BF_UNDEF);
	llassert(alpha_sfactor < BF_UNDEF);
	llassert(alpha_dfactor < BF_UNDEF);
	if (!gGLManager.mHasBlendFuncSeparate)
	{
		LL_WARNS_ONCE("render") << "no glBlendFuncSeparateEXT(), using color-only blend func" << llendl;
		blendFunc(color_sfactor, color_dfactor);
		return;
	}
	if (mCurrBlendColorSFactor != color_sfactor || mCurrBlendColorDFactor != color_dfactor ||
	    mCurrBlendAlphaSFactor != alpha_sfactor || mCurrBlendAlphaDFactor != alpha_dfactor)
	{
		mCurrBlendColorSFactor = color_sfactor;
		mCurrBlendAlphaSFactor = alpha_sfactor;
		mCurrBlendColorDFactor = color_dfactor;
		mCurrBlendAlphaDFactor = alpha_dfactor;
		flush();
		glBlendFuncSeparateEXT(sGLBlendFactor[color_sfactor], sGLBlendFactor[color_dfactor],
				       sGLBlendFactor[alpha_sfactor], sGLBlendFactor[alpha_dfactor]);
	}
}
Esempio n. 2
0
void RenderTarget::applyBlendMode(BlendMode mode)
{
    switch (mode)
    {
        // Alpha blending
        // glBlendFuncSeparateEXT is used when available to avoid an incorrect alpha value when the target
        // is a RenderTexture -- in this case the alpha value must be written directly to the target buffer
        default :
        case BlendAlpha :
            if (GLEW_EXT_blend_func_separate)
                glCheck(glBlendFuncSeparateEXT(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
            else
                glCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
            break;

        // Additive blending
        case BlendAdd :
            glCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE));
            break;

        // Multiplicative blending
        case BlendMultiply :
            glCheck(glBlendFunc(GL_DST_COLOR, GL_ZERO));
            break;

        // No blending
        case BlendNone :
            glCheck(glBlendFunc(GL_ONE, GL_ZERO));
            break;
    }

    m_cache.lastBlendMode = mode;
}
//----------------------------------------------------------------------------//
void OpenGLRenderer::setupRenderingBlendMode(const BlendMode mode,
                                             const bool force)
{
    // exit if mode is already set up (and update not forced)
    if ((d_activeBlendMode == mode) && !force)
        return;

    d_activeBlendMode = mode;

    if (d_activeBlendMode == BM_RTT_PREMULTIPLIED)
    {
        glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    }
    else
    {
        if (GLEW_VERSION_1_4)
            glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
                                GL_ONE_MINUS_DST_ALPHA, GL_ONE);
        else if (GLEW_EXT_blend_func_separate)
            glBlendFuncSeparateEXT(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
                                   GL_ONE_MINUS_DST_ALPHA, GL_ONE);
        else
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }
}
 inline void VL_glBlendFuncSeparate( GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
 {
   if (glBlendFuncSeparate)
     glBlendFuncSeparate( srcRGB, dstRGB, srcAlpha, dstAlpha);
   else
   if (glBlendFuncSeparateEXT)
     glBlendFuncSeparateEXT( srcRGB, dstRGB, srcAlpha, dstAlpha);
   else
     VL_UNSUPPORTED_FUNC();
 }
bool RawVolumeModelRenderer::render( const eq::Range& range,
                                     const eq::Matrix4d& modelviewM,
                                     const eq::Matrix4f& invRotationM,
                                     const eq::Vector4f& taintColor,
                                     const int normalsQuality )
{
    VolumeInfo volumeInfo;

    if( !_rawModel.getVolumeInfo( volumeInfo, range ))
    {
        LBERROR << "Can't get volume data" << std::endl;
        return false;
    }

    glScalef( volumeInfo.volScaling.W,
              volumeInfo.volScaling.H,
              volumeInfo.volScaling.D );

    // Enable shaders
    glUseProgramObjectARB( _shaders.getProgram( ));

    // Calculate and put necessary data to shaders

    const uint32_t resolution    = _rawModel.getResolution();
    const double   sliceDistance = 3.6 / ( resolution * _precision );

    _putVolumeDataToShader( volumeInfo, float( sliceDistance ),
                            invRotationM, taintColor, normalsQuality );

    _sliceClipper.updatePerFrameInfo( modelviewM, sliceDistance, range );

    //Render slices
    glEnable( GL_BLEND );
    glBlendFuncSeparateEXT( GL_ONE, GL_SRC_ALPHA, GL_ZERO, GL_SRC_ALPHA );

    renderSlices( _sliceClipper );

    glDisable( GL_BLEND );

    // Disable shader
    glUseProgramObjectARB( 0 );

    return true;
}
Esempio n. 6
0
void Renderer::SetBlendMode(Blend::Mode mode)
{
    if ((mode != myBlendMode) || !myBlendModeIsValid)
    {
        // Apply the new blending mode
        if (mode == Blend::None)
        {
            GLCheck(glDisable(GL_BLEND));
        }
        else
        {
            GLCheck(glEnable(GL_BLEND));

            switch (mode)
            {
                // Alpha blending
                // glBlendFuncSeparateEXT is used when available to avoid an incorrect alpha value when the target
                // is a RenderImage -- in this case the alpha value must be written directly to the target buffer
                default :
                case Blend::Alpha :
                    if (GLEW_EXT_blend_func_separate)
                        GLCheck(glBlendFuncSeparateEXT(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
                    else
                        GLCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
                    break;

                // Additive blending
                case Blend::Add :
                    GLCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE));
                    break;

                // Multiplicative blending
                case Blend::Multiply :
                    GLCheck(glBlendFunc(GL_DST_COLOR, GL_ZERO));
                    break;
            }
        }

        // Store it
        myBlendMode = mode;
        myBlendModeIsValid = true;
    }
}