Ejemplo n.º 1
0
void poOpenGLState::setBlend(po::BlendState state, bool forceAccept) {
	if(forceAccept) {
		state.enabled ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
		glBlendFuncSeparate(state.sourceFactor, state.destFactor, state.sourceAlphaFactor, state.destAlphaFactor);
		glBlendEquationSeparate(state.equation, state.alphaEquation);
		glBlendColor(state.color.R, state.color.G, state.color.B, state.color.A);
		blend = state;
	}
	else {
		if(state.enabled != blend.enabled) {
			state.enabled ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
			blend.enabled = state.enabled;
		}
		
		if(!blend.isBlendFuncSame(state)) {
			glBlendFuncSeparate(state.sourceFactor, state.destFactor, state.sourceAlphaFactor, state.destAlphaFactor);
			blend.copyBlendFuncFrom(state);
		}
		
		if(!blend.isBlendEquationSame(state)) {
			glBlendEquationSeparate(state.equation, state.alphaEquation);
			blend.copyBlendEquationFrom(state);
		}

		if(state.color != blend.color) {
			glBlendColor(state.color.R, state.color.G, state.color.B, state.color.A);
			blend.color = state.color;
		}
	}
}
Ejemplo n.º 2
0
void PGlState::setBlend(PGlStateEnum mode)
{
    if (m_blend == mode)
    {
        return ;
    }

    m_blend = mode;

    switch (mode)
    {
        case P_GLBLEND_OPAQUE:
            glDisable(GL_BLEND);
            break;
        case P_GLBLEND_ALPHA: 
            glEnable(GL_BLEND);
            glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            break;
        case P_GLBLEND_DSTALPHA: 
            glEnable(GL_BLEND);
            glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
            glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA);
            break;
        case P_GLBLEND_ADDITIVE:
            glEnable(GL_BLEND);
            glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
            glBlendFunc(GL_SRC_ALPHA, GL_ONE);
            break;
        default:
            PLOG_WARNINGX(P_LOG_CHANNEL_OPENGLEGL, "unknown blend mode");
            PASSERT(0);
            break;
    }
}
Ejemplo n.º 3
0
static bool set_opengl_blending(ALLEGRO_DISPLAY *d)
{
   const int blend_modes[4] = {
      GL_ZERO, GL_ONE, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
   };
   const int blend_equations[3] = {
      GL_FUNC_ADD, GL_FUNC_SUBTRACT, GL_FUNC_REVERSE_SUBTRACT
   };
   int op, src_color, dst_color, op_alpha, src_alpha, dst_alpha;

   (void)d;

   al_get_separate_blender(&op, &src_color, &dst_color, &op_alpha,
      &src_alpha, &dst_alpha);
#if defined ALLEGRO_IPHONE || defined ALLEGRO_GP2XWIZ
   if (al_get_opengl_version() >= _ALLEGRO_OPENGL_VERSION_2_0) {
      glEnable(GL_BLEND);
      glBlendFuncSeparate(blend_modes[src_color],
         blend_modes[dst_color], blend_modes[src_alpha],
         blend_modes[dst_alpha]);
      glBlendEquationSeparate(
         blend_equations[op],
         blend_equations[op_alpha]);
      return true;
   }
   else {
      glEnable(GL_BLEND);
      glBlendFunc(blend_modes[src_color], blend_modes[dst_color]);
      glBlendEquation(blend_equations[op]);
      return true;
   }
#else
   if (d->ogl_extras->ogl_info.version >= _ALLEGRO_OPENGL_VERSION_1_4) {
      glEnable(GL_BLEND);
      glBlendFuncSeparate(blend_modes[src_color],
         blend_modes[dst_color], blend_modes[src_alpha],
         blend_modes[dst_alpha]);
      if (d->ogl_extras->ogl_info.version >= _ALLEGRO_OPENGL_VERSION_2_0) {
         glBlendEquationSeparate(
            blend_equations[op],
            blend_equations[op_alpha]);
      }
      else
         glBlendEquation(blend_equations[op]);
      return true;
   }
   else {
      if (src_color == src_alpha && dst_color == dst_alpha) {
         glEnable(GL_BLEND);
         glBlendFunc(blend_modes[src_color], blend_modes[dst_color]);
         glBlendEquation(blend_equations[op]);
         return true;
      }
   }
#endif
   return false;
}
Ejemplo n.º 4
0
void SetBlendingMode(EBlendMode Mode)
{
    if (Mode == BLEND_ADD)
    {
        glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    }
    else if (Mode == BLEND_ALPHA)
    {
        glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }
}
Ejemplo n.º 5
0
void Renderer::DrawComponents()
{
	// TODO
    glEnable(GL_DEPTH_TEST);
    glDisable(GL_BLEND);
    
    for(auto drawComp : mDrawComponents){
        if(drawComp->IsVisible()){
            drawComp->Draw(*this);
        }
    }
    
    glEnable(GL_BLEND);
    glDisable(GL_DEPTH_TEST);
    glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
    glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
    
    for(auto drawComp : mDrawComponents2D){
        if(drawComp->IsVisible()){
            drawComp->Draw(*this);
        }
    }
    
    
}
Ejemplo n.º 6
0
HQ_FORCE_INLINE void HQStateManagerGL::ActiveBlendState(const HQSharedPtr<HQBlendStateGL> &state)
{
	if (this->bState == this->bStates.GetItemPointerNonCheck(0))//current state is default state
		glEnable(GL_BLEND);

	if (state->operation != this->bState->operation||
		state->alphaOperation != this->bState->alphaOperation)
	{
		glBlendEquationSeparate(state->operation , state->alphaOperation);
	}
	if (state->srcFactor != this->bState->srcFactor ||
		state->destFactor != this->bState->destFactor ||
		state->srcAlphaFactor != this->bState->srcAlphaFactor ||
		state->destAlphaFactor != this->bState->destAlphaFactor)
	{
		if (state->extState)
			glBlendFuncSeparate(state->srcFactor ,
								state->destFactor,
								state->srcAlphaFactor,
								state->destAlphaFactor);
		else
			glBlendFunc(state->srcFactor ,
						state->destFactor);
	}
}
Ejemplo n.º 7
0
/** 
 * Sets the renderer blend mode
 * @param pe_cmode_0 BPPECMode0 register to user for blend settings
 * @param pe_cmode_1 BPPECMode1 register to user for blend settings
 * @param blend_mode_ Forces blend mode to update
 */
void RendererGL3::SetBlendMode(const gp::BPPECMode0& pe_cmode_0, const gp::BPPECMode1& pe_cmode_1, 
    bool force_update) {

    /// OpenGL color source factors
    static const GLenum g_src_factors[8] = {
        GL_ZERO,       GL_ONE,                  GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
        GL_SRC1_ALPHA, GL_ONE_MINUS_SRC1_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA
    };
    /// OpenGL color destination factors
    static const GLenum g_dst_factors[8] = {
        GL_ZERO,       GL_ONE,                  GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
        GL_SRC1_ALPHA, GL_ONE_MINUS_SRC1_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA
    };
    u32 temp = pe_cmode_0.subtract << 2;
    bool use_dest_alpha = pe_cmode_1.enable && pe_cmode_0.alpha_update && 
        gp::g_bp_regs.zcontrol.is_efb_alpha_enabled();

    if (pe_cmode_0.subtract) {
        temp |= 0x0049;                             // Enable blending src 1 dst 1
    } else if (pe_cmode_0.blend_enable) {
        temp |= 1;                                  // Enable blending
        temp |= pe_cmode_0.src_factor << 3;
        temp |= pe_cmode_0.dst_factor << 6;
    }
    u32 changes = force_update ? 0xFFFFFFFF : temp ^ blend_mode_;

    // Blend enable change
    if (changes & 1) {
        (temp & 1) ? glEnable(GL_BLEND) : glDisable(GL_BLEND);
    }
    if (changes & 4) {
        GLenum equation = temp & 4 ? GL_FUNC_REVERSE_SUBTRACT : GL_FUNC_ADD;
        GLenum equation_alpha = use_dest_alpha ? GL_FUNC_ADD : equation;
        glBlendEquationSeparate(equation, equation_alpha);
    }
    if (changes & 0x1F8) {
        GLenum src_factor = g_src_factors[(temp >> 3) & 7];
        GLenum dst_factor = g_dst_factors[(temp >> 6) & 7];

        if (!gp::g_bp_regs.zcontrol.is_efb_alpha_enabled()) {
            if (src_factor == GL_DST_ALPHA) {
                src_factor = GL_ONE;
            } else if (src_factor == GL_ONE_MINUS_DST_ALPHA) {
                src_factor = GL_ZERO;
            }
            if (dst_factor == GL_DST_ALPHA) {
                dst_factor = GL_ONE;
            } else if (dst_factor == GL_ONE_MINUS_DST_ALPHA) {
                dst_factor = GL_ZERO;
            }
        }
        GLenum src_factor_alpha = src_factor;
        GLenum dst_factor_alpha = dst_factor;

        if (use_dest_alpha) {
            src_factor_alpha = GL_ONE;
            dst_factor_alpha = GL_ZERO;
        }
        glBlendFuncSeparate(src_factor, dst_factor, src_factor_alpha, dst_factor_alpha);
    }
Ejemplo n.º 8
0
static int BlendEquation(lua_State *L)
    {
    GLuint buf;
    GLenum mode, alpha;

    if(lua_isinteger(L, 1))
        {
        buf = luaL_checkinteger(L, 1);
        mode = checkblendmode(L, 2);
        if(lua_isstring(L, 3))
            {
            alpha = checkblendmode(L,3);
            glBlendEquationSeparatei(buf, mode, alpha);
            }
        else
            glBlendEquationi(buf, mode);
        }
    else
        {
        mode = checkblendmode(L, 1);
        if(lua_isstring(L, 2))
            {
            alpha = checkblendmode(L,2);
            glBlendEquationSeparate(mode, alpha);
            }
        else
            glBlendEquation(mode);
        }
    CheckError(L);
    return 0;
    }
void OGLBlendState::Enable ()
{
	if (m_EnableAlphaToCoverage)
		glEnable (GL_SAMPLE_COVERAGE);
	else
		glDisable (GL_SAMPLE_COVERAGE);

	if (m_EnableIndependentBlend)
	{
		for (int i = 0; i < BlendState::NUM_TARGETS; i++)
		{
			Target& target = m_Target[i];
			if (target.enable)
			{
				glEnable (GL_BLEND);
				glBlendFuncSeparate (target.srcColor, target.dstColor, target.srcAlpha, target.dstAlpha);
				glBlendEquationSeparate (target.opColor, target.opAlpha);
			}
			else
			{
				glDisable (GL_BLEND);
			}
			glColorMaski (i, target.rMask, target.gMask, target.bMask, target.aMask);
			glSampleMaski (i, m_SampleMask);
		}
	}
	else
	{
		Target& target = m_Target[0];
			if (target.enable)
			{
				glEnable (GL_BLEND);
				glBlendFuncSeparate (target.srcColor, target.dstColor, target.srcAlpha, target.dstAlpha);
				glBlendEquationSeparate (target.opColor, target.opAlpha);
			}
			else
			{
				glDisable (GL_BLEND);
			}
			glColorMask (target.rMask, target.gMask, target.bMask, target.aMask);
			glSampleMaski (0, m_SampleMask);
	}

	glBlendColor (m_BlendColor.x, m_BlendColor.y, m_BlendColor.z, m_BlendColor.w);
}
Ejemplo n.º 10
0
	void BlendEquationImplOGL::clear(const BlendEquation& eqn) const
	{
		if(eqn != BlendEquation()) {
			ASSERT_LOG(!get_equation_stack().empty(), "Something went badly wrong blend mode stack was empty.");
			get_equation_stack().pop();
			BlendEquation& eqn = get_equation_stack().top();
			glBlendEquationSeparate(convert_eqn(eqn.getRgbEquation()), convert_eqn(eqn.getAlphaEquation()));
		}
	}
 inline void VL_glBlendEquationSeparate( GLenum modeRGB, GLenum modeAlpha)
 {
   if (glBlendEquationSeparate)
     glBlendEquationSeparate(modeRGB, modeAlpha);
   else
   if(glBlendEquationSeparateEXT)
     glBlendEquationSeparateEXT(modeRGB, modeAlpha);
   else
     VL_UNSUPPORTED_FUNC();
 }
Ejemplo n.º 12
0
	BlendEquationScopeOGL::BlendEquationScopeOGL(const ScopeableValue& sv)
		: stored_(false)
	{
		const BlendEquation& eqn = sv.getBlendEquation();
		if(sv.isBlendEquationSet() && eqn != BlendEquation()) {
			get_equation_stack().emplace(eqn);
			glBlendEquationSeparate(convert_eqn(eqn.getRgbEquation()), convert_eqn(eqn.getAlphaEquation()));
			stored_ = true;
		}
	}
Ejemplo n.º 13
0
	void BlendEquationImplOGL::apply(const BlendEquation& eqn) const
	{
		if(eqn != BlendEquation()) {
			if(get_equation_stack().empty()) {
				get_equation_stack().emplace(BlendEquationConstants::BE_ADD, BlendEquationConstants::BE_ADD);
			}
			get_equation_stack().emplace(eqn);
			glBlendEquationSeparate(convert_eqn(eqn.getRgbEquation()), convert_eqn(eqn.getAlphaEquation()));
		}
	}
Ejemplo n.º 14
0
bool Renderer::InitFrameBuffer()
{
	// Enable alpha blending on the color buffer
	glEnable(GL_BLEND);
	glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
	glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);

	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	return true;
}
Ejemplo n.º 15
0
void sprite_effect_apply_blendstate(sprite_effect_t *effect)
{
    if (effect->BlendEnabled)
    {
        glEnable(GL_BLEND);
        glBlendColor(effect->BlendColor[0], effect->BlendColor[1], effect->BlendColor[2], effect->BlendColor[3]);
        glBlendFuncSeparate(effect->BlendSourceColor, effect->BlendTargetColor, effect->BlendSourceAlpha, effect->BlendTargetAlpha);
        glBlendEquationSeparate(effect->BlendFuncColor, effect->BlendFuncAlpha);
    }
    else glDisable(GL_BLEND);
}
Ejemplo n.º 16
0
void GLGraphicsImpl::enableBlend() {
    glEnable( GL_BLEND );

    //TEMP: enabling blend sets the blending mode to transparency.
    //NOTE: transparency is linear interpolation between d_rgb and s_rgb,
    //with s_a as the parameter:
    //  d_rgb + s_a*(s_rgb-d_rgb)     =
    //s_a*s_rgb + 1*d_rgb - s_a*d_rgb =
    //s_a*s_rgb + (1 - s_a) * d_rgb
    glBlendEquationSeparate( GL_ADD, GL_ADD );
    glBlendFuncSeparate( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE );
}
Ejemplo n.º 17
0
void RenderTarget::applyBlendMode(const BlendMode& mode)
{
    // Apply the blend mode
    glCheck(glBlendFuncSeparate(
                factorToGlConstant(mode.colorSrcFactor), factorToGlConstant(mode.colorDstFactor),
                factorToGlConstant(mode.alphaSrcFactor), factorToGlConstant(mode.alphaDstFactor)));

    glCheck(glBlendEquationSeparate(
                equationToGlConstant(mode.colorEquation),
                equationToGlConstant(mode.alphaEquation)));

    m_cache.lastBlendMode = mode;
}
//-----------------------------------------------------------------------------
void CPUTRenderStateBlockOGL::SetRenderStates( CPUTRenderParameters &renderParams )
{
    //
    // Set Depth and Stencil render states
    //
    mStateDesc.DepthStencilDesc.DepthEnable   ? glEnable(GL_DEPTH_TEST)   : glDisable(GL_DEPTH_TEST);
    mStateDesc.DepthStencilDesc.StencilEnable ? glEnable(GL_STENCIL_TEST) : glDisable(GL_STENCIL_TEST);
    GL_CHECK("Set Depth Stencil States");

    GL_CHECK(glDepthMask(mStateDesc.DepthStencilDesc.DepthWriteMask));
    GL_CHECK(glDepthFunc(mStateDesc.DepthStencilDesc.DepthFunc));
    
    GL_CHECK(glStencilMaskSeparate(GL_FRONT_AND_BACK, mStateDesc.DepthStencilDesc.StencilWriteMask));
    GL_CHECK(glStencilOpSeparate(GL_FRONT, mStateDesc.DepthStencilDesc.FrontFaceStencilFailOp, mStateDesc.DepthStencilDesc.FrontFaceStencilDepthFailOp, mStateDesc.DepthStencilDesc.FrontFaceStencilPassOp));
    GL_CHECK(glStencilOpSeparate(GL_BACK, mStateDesc.DepthStencilDesc.BackFaceStencilFailOp, mStateDesc.DepthStencilDesc.BackFaceStencilDepthFailOp, mStateDesc.DepthStencilDesc.BackFaceStencilPassOp));
    GL_CHECK(glStencilFuncSeparate(GL_FRONT, mStateDesc.DepthStencilDesc.FrontFaceStencilFunc, mStateDesc.DepthStencilDesc.FrontFaceStencilFuncRef, mStateDesc.DepthStencilDesc.FrontFaceStencilFuncMask));
    GL_CHECK(glStencilFuncSeparate(GL_BACK, mStateDesc.DepthStencilDesc.BackFaceStencilFunc, mStateDesc.DepthStencilDesc.BackFaceStencilFuncRef, mStateDesc.DepthStencilDesc.BackFaceStencilFuncMask));
    
    //
    // Set Rasterization states
    //
#ifndef CPUT_FOR_OGLES
    GL_CHECK(glPolygonMode(GL_FRONT_AND_BACK, mStateDesc.RasterizerDesc.FillMode));
#endif
    GL_CHECK(glCullFace(mStateDesc.RasterizerDesc.CullMode));
    GL_CHECK(glFrontFace(mStateDesc.RasterizerDesc.FrontCounterClockwise));
    //GL_CHECK(glPolygonOffset()); // used for depth bias
    mStateDesc.RasterizerDesc.CullingEnabled        ? glEnable(GL_CULL_FACE)    : glDisable(GL_CULL_FACE);
    mStateDesc.RasterizerDesc.ScissorEnable         ? glEnable(GL_SCISSOR_TEST) : glDisable(GL_SCISSOR_TEST); // is glScissor needed here as well?
#ifndef CPUT_FOR_OGLES
    mStateDesc.RasterizerDesc.DepthClipEnable       ? glDisable(GL_DEPTH_CLAMP) : glEnable(GL_DEPTH_CLAMP);
    mStateDesc.RasterizerDesc.MultisampleEnable     ? glEnable(GL_MULTISAMPLE)  : glDisable(GL_MULTISAMPLE);  // is glSampleCoverage() needed here as well?
    mStateDesc.RasterizerDesc.AntialiasedLineEnable ? glEnable(GL_LINE_SMOOTH)  : glDisable(GL_LINE_SMOOTH);
    
    //NOTE: Could not find the rendertarget being set to SRGB anywhere else; this might not be the best place
    GL_CHECK(glEnable(GL_FRAMEBUFFER_SRGB));
#endif
    GL_CHECK("Set Rasterization States");
    //glDisable(GL_CULL_FACE);

    //
    // Set Blend states
    //

	mStateDesc.RenderTargetBlendDesc.BlendEnable ? glEnable(GL_BLEND): glDisable(GL_BLEND);
    GL_CHECK(glBlendFuncSeparate(mStateDesc.RenderTargetBlendDesc.SrcBlend,mStateDesc.RenderTargetBlendDesc.DestBlend,mStateDesc.RenderTargetBlendDesc.SrcBlendAlpha,mStateDesc.RenderTargetBlendDesc.DestBlendAlpha));
	GL_CHECK(glBlendEquationSeparate(mStateDesc.RenderTargetBlendDesc.BlendOp,mStateDesc.RenderTargetBlendDesc.BlendOpAlpha));
    GL_CHECK("Set Blend States");


 } // CPUTRenderStateBlockOGL::SetRenderState()
Ejemplo n.º 19
0
	void OpenGL1_RenderSystem::_setDeviceBlendMode(BlendMode blendMode)
	{
#ifndef _WIN32
		if (this->blendSeparationSupported)
		{
			// blending for the new generations
			if (blendMode == BM_ALPHA || blendMode == BM_DEFAULT)
			{
				glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
				glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
			}
			else if (blendMode == BM_ADD)
			{
				glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
				glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
			}
			else if (blendMode == BM_SUBTRACT)
			{
				glBlendEquationSeparate(GL_FUNC_REVERSE_SUBTRACT, GL_FUNC_ADD);
				glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
			}
			else if (blendMode == BM_OVERWRITE)
			{
				glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
				glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ZERO);
			}
			else
			{
				hlog::warn(logTag, "Trying to set unsupported blend mode!");
			}
		}
		else
#endif
		{
			OpenGLC_RenderSystem::_setDeviceBlendMode(blendMode);
		}
	}
Ejemplo n.º 20
0
void GLGraphicsContext::updateBlendState(const BlendState& blendState)
{
	const BlendState& newState = blendState;
	const BlendState& currentState = getBlendState();
	
	if (newState.isBlendEnabled() != currentState.isBlendEnabled())
	{
		if (newState.isBlendEnabled())
		{
			glEnable(GL_BLEND);
		}
		else
		{
			glDisable(GL_BLEND);
		}
	}
	
	if (newState.getColorBlendFunction() != currentState.getColorBlendFunction() || newState.getAlphaBlendFunction() != currentState.getAlphaBlendFunction())
	{
		GLenum modeRGB = GLMapping::getBlendFunction(newState.getColorBlendFunction());
		GLenum modeAlpha = GLMapping::getBlendFunction(newState.getAlphaBlendFunction());
		
		if (modeRGB == modeAlpha)
		{
			glBlendEquation(modeRGB);
		}
		else
		{
			glBlendEquationSeparate(modeRGB, modeAlpha);
		}
	}
	
	if (newState.getColorSourceBlend() != currentState.getColorSourceBlend() || newState.getColorDestinationBlend() != currentState.getColorDestinationBlend() || newState.getAlphaSourceBlend() != currentState.getAlphaSourceBlend() || newState.getAlphaDestinationBlend() != currentState.getAlphaDestinationBlend())
	{
		GLenum srcRGB = GLMapping::getSourceBlend(newState.getColorSourceBlend());
		GLenum dstRGB = GLMapping::getDestinationBlend(newState.getColorDestinationBlend());
		GLenum srcAlpha = GLMapping::getSourceBlend(newState.getAlphaSourceBlend());
		GLenum dstAlpha = GLMapping::getDestinationBlend(newState.getAlphaDestinationBlend());
		
		if (srcRGB == srcAlpha && dstRGB == dstAlpha)
		{
			glBlendFunc(srcRGB, dstRGB);
		}
		else
		{
			glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
		}
	}
}
Ejemplo n.º 21
0
void CircleSprite::setRenderState( void )
{
	// Blends for sprites
	glEnable(GL_BLEND);
	glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);

	// Use the stock shader
	Matrix mvp = ModelView * Camera::getProjMatrix();

	// flat shader
	shaderManager.UseStockShader(GLT_SHADER_FLAT, 
						& mvp, 
						& this->color);

};
Ejemplo n.º 22
0
FGLPostProcessState::~FGLPostProcessState()
{
	if (blendEnabled)
		glEnable(GL_BLEND);
	else
		glDisable(GL_BLEND);

	if (scissorEnabled)
		glEnable(GL_SCISSOR_TEST);
	else
		glDisable(GL_SCISSOR_TEST);

	if (depthEnabled)
		glEnable(GL_DEPTH_TEST);
	else
		glDisable(GL_DEPTH_TEST);

	if (multisampleEnabled)
		glEnable(GL_MULTISAMPLE);
	else
		glDisable(GL_MULTISAMPLE);

	glBlendEquationSeparate(blendEquationRgb, blendEquationAlpha);
	glBlendFuncSeparate(blendSrcRgb, blendDestRgb, blendSrcAlpha, blendDestAlpha);

	glUseProgram(currentProgram);

	// Fully unbind to avoid incomplete texture warnings from Nvidia's driver when gl_debug_level 4 is active
	for (unsigned int i = 0; i < textureBinding.Size(); i++)
	{
		glActiveTexture(GL_TEXTURE0 + i);
		glBindTexture(GL_TEXTURE_2D, 0);
	}

	for (unsigned int i = 0; i < samplerBinding.Size(); i++)
	{
		glBindSampler(i, samplerBinding[i]);
	}

	for (unsigned int i = 0; i < textureBinding.Size(); i++)
	{
		glActiveTexture(GL_TEXTURE0 + i);
		glBindTexture(GL_TEXTURE_2D, textureBinding[i]);
	}

	glActiveTexture(activeTex);
}
    void GLStateCacheManagerImp::setBlendEquation(GLenum eqRGB, GLenum eqAlpha)
    {
        if(mBlendEquationRGB != eqRGB || mBlendEquationAlpha != eqAlpha)
        {
            mBlendEquationRGB = eqRGB;
            mBlendEquationAlpha = eqAlpha;

            if(GLEW_VERSION_2_0)
            {
                glBlendEquationSeparate(eqRGB, eqAlpha);
            }
            else if(GLEW_EXT_blend_equation_separate)
            {
                glBlendEquationSeparateEXT(eqRGB, eqAlpha);
            }
        }
    }
Ejemplo n.º 24
0
 void Material::setGLState() {
     //FIXME: causing problems for the shadow
     switch( this->blending ) {
         case BLENDING_MODE::NONE:
             glDisable( GL_BLEND );
             break;
             
         case BLENDING_MODE::ADDITIVE:
             glEnable( GL_BLEND );
             glBlendEquation( GL_FUNC_ADD );
             glBlendFunc( GL_SRC_ALPHA, GL_ONE );
             break;
             
         case BLENDING_MODE::SUBTRACTIVE:
             glEnable( GL_BLEND );
             glBlendEquation( GL_FUNC_ADD );
             glBlendFunc( GL_ZERO, GL_ONE_MINUS_SRC_ALPHA );
             break;
             
         case BLENDING_MODE::MULTIPLY:
             glEnable( GL_BLEND );
             glBlendEquation( GL_FUNC_ADD );
             glBlendFunc( GL_ZERO, GL_SRC_COLOR );
             break;
             
         case BLENDING_MODE::CUSTOM:
             //FIXME: do something
             throw runtime_error( "Unimplemented blending equation" );
             glEnable( GL_BLEND );
             break;
             
         default:
             glEnable( GL_BLEND );
             glBlendEquationSeparate( GL_FUNC_ADD, GL_FUNC_ADD );
             glBlendFuncSeparate( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA );
             break;
     }
     
     if( this->side == SIDE::DOUBLE_SIDE )  {
         glDisable( GL_CULL_FACE );
     }
     else {
         glEnable( GL_CULL_FACE );
         glCullFace( GL_BACK );
     }
 }
    void GLStateCacheManagerImp::initializeCache()
    {
        glBlendEquation(GL_FUNC_ADD);

        if(GLEW_VERSION_2_0)
        {
            glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
        }
        else if(GLEW_EXT_blend_equation_separate)
        {
            glBlendEquationSeparateEXT(GL_FUNC_ADD, GL_FUNC_ADD);
        }

        glBlendFunc(GL_ONE, GL_ZERO);
        
        glCullFace(mCullFace);

        glDepthFunc(mDepthFunc);

        glDepthMask(mDepthMask);

        glStencilMask(mStencilMask);

        glClearDepth(mClearDepth);

        glBindTexture(GL_TEXTURE_2D, 0);

        glBindBuffer(GL_ARRAY_BUFFER, 0);

        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

        glBindFramebufferEXT(GL_FRAMEBUFFER, 0);

        glBindRenderbufferEXT(GL_RENDERBUFFER, 0);

        glActiveTexture(GL_TEXTURE0);

        glClearColor(mClearColour[0], mClearColour[1], mClearColour[2], mClearColour[3]);

        glColorMask(mColourMask[0], mColourMask[1], mColourMask[2], mColourMask[3]);

        glPolygonMode(GL_FRONT_AND_BACK, mPolygonMode);
    }
void VR_Canvas::privRenderState(Camera * OrthoCamera)
{
	///////////////SetRenderState////////////////
	glViewport(0,0,1280,800);
	
	this->ModelView = this->LocalToWorld * OrthoCamera->getViewMatrix();
	Matrix mvp = this->ModelView * OrthoCamera->getProjMatrix();

	glEnable(GL_BLEND);
	glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
		
	Vect lightColor( 2.5f, 2.5f, 2.5f, 1.0f);
	Vect lightPos(0.0f, 0.0f, 5.0f);

	shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF, &ModelView, &OrthoCamera->getProjMatrix(), &lightPos, &lightColor, 0);
	/////////////////////////////////////////////

}
Ejemplo n.º 27
0
	void Apply() {
		if (enabled) {
			glEnable(GL_BLEND);
			glBlendEquationSeparate(eqCol, eqAlpha);
			glBlendFuncSeparate(srcCol, dstCol, srcAlpha, dstAlpha);
		} else {
			glDisable(GL_BLEND);
		}
		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
		// glColorMask(maskBits & 1, (maskBits >> 1) & 1, (maskBits >> 2) & 1, (maskBits >> 3) & 1);
		// glBlendColor(fixedColor);
		
#if !defined(USING_GLES2)
		if (logicEnabled) {
			glEnable(GL_COLOR_LOGIC_OP);
			glLogicOp(logicOp);
		} else {
			glDisable(GL_COLOR_LOGIC_OP);
		}
#endif
	}
Ejemplo n.º 28
0
void StateSystem::BlendState::applyGL() const
{
  if (separateEnable){
    for (GLuint i = 0; i < MAX_DRAWBUFFERS; i++){
      if (isBitSet(separateEnable,i)) glEnablei(GL_BLEND,i);
      else                            glDisablei(GL_BLEND,i);
    }
  }

  if (useSeparate){
    for (GLuint i = 0; i < MAX_DRAWBUFFERS; i++){
      glBlendFuncSeparatei(i,blends[i].rgb.srcw,blends[i].rgb.dstw,blends[i].alpha.srcw,blends[i].alpha.dstw);
      glBlendEquationSeparatei(i,blends[i].rgb.equ,blends[i].alpha.equ);
    }
  }
  else{
    glBlendFuncSeparate(blends[0].rgb.srcw,blends[0].rgb.dstw,blends[0].alpha.srcw,blends[0].alpha.dstw);
    glBlendEquationSeparate(blends[0].rgb.equ,blends[0].alpha.equ);
  }

  //glBlendColor(color[0],color[1],color[2],color[3]);
}
Ejemplo n.º 29
0
void apply_Rstate_blend( const Rstate_blend* blend ) {

	if( blend->enabled ) {

		glEnable( GL_BLEND );
		glBlendFuncSeparate( blend->srcColor, 
		                     blend->dstColor,
		                     blend->srcAlpha,
		                     blend->dstAlpha );

		glBlendEquationSeparate( blend->colorFunc,
		                         blend->alphaFunc );

		glBlendColor( blend->constColor.x,
		              blend->constColor.y,
		              blend->constColor.z,
		              blend->constColor.w );

	} else
		glDisable( GL_BLEND );

}
Ejemplo n.º 30
0
static void text_buffer_render_setup(const xpl_text_buffer_t *self) {
	glEnable(GL_BLEND);
	glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
	
	glDepthMask(GL_FALSE);
	glUseProgram(self->shader->id);
	
	//	if (self->font_manager->atlas->depth == 1) {
	//		glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ZERO);
	//	} else {
	// premultiplied alpha. Premultiply your alpha.
	glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
	//	}
#ifndef XPL_PLATFORM_IOS
	glUniform3f(xpl_shader_get_uniform(self->shader, "subpixel"),
                1.0f / self->font_manager->atlas->width,
                1.0f / self->font_manager->atlas->height,
                self->font_manager->atlas->depth);
#endif
	
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, self->font_manager->atlas->texture_id);
	glUniform1i(xpl_shader_get_uniform(self->shader, "tex"), 0); // Use texture unit zero.
}