Пример #1
0
        private void ApplyStateCore(GraphicsContext ctx, ShaderProgram program, BlendState currentState)
        {
            if (Enabled)
            {
                // Enable blending
                if (currentState.Enabled == false)
                {
                    Gl.Enable(EnableCap.Blend);
                }

                // Set blending equation
                if (ctx.Extensions.BlendMinmax_EXT)
                {
                    if (EquationSeparated)
                    {
                        if (currentState.RgbEquation != RgbEquation || currentState.AlphaEquation != AlphaEquation)
                        {
                            Gl.BlendEquationSeparate(RgbEquation, AlphaEquation);
                        }
                    }
                    else
                    {
                        if (currentState.RgbEquation != RgbEquation)
                        {
                            Gl.BlendEquation(RgbEquation);
                        }
                    }
                }

                // Set blending function
                if (FunctionSeparated)
                {
                    if (currentState._RgbSrcFactor != _RgbSrcFactor || currentState._RgbDstFactor != _RgbDstFactor || currentState._AlphaSrcFactor != _AlphaSrcFactor || currentState._AlphaDstFactor != _AlphaDstFactor)
                    {
                        Gl.BlendFuncSeparate(_RgbSrcFactor, _RgbDstFactor, _AlphaSrcFactor, _AlphaDstFactor);
                    }
                }
                else
                {
                    if (currentState._RgbSrcFactor != _RgbSrcFactor || currentState._RgbDstFactor != _RgbDstFactor)
                    {
                        Gl.BlendFunc(_RgbSrcFactor, _RgbDstFactor);
                    }
                }

                // Set blend color, if required
                if (RequiresConstColor(_RgbSrcFactor) || RequiresConstColor(_AlphaSrcFactor) || RequiresConstColor(_RgbDstFactor) || RequiresConstColor(_AlphaDstFactor))
                {
                    Gl.BlendColor(_BlendColor.r, _BlendColor.g, _BlendColor.b, _BlendColor.a);
                }
            }
            else
            {
                // Disable blending
                if (currentState.Enabled == true)
                {
                    Gl.Disable(EnableCap.Blend);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Set ShaderProgram state.
        /// </summary>
        /// <param name="ctx">
        /// A <see cref="GraphicsContext"/> which has defined the shader program <paramref name="sProgram"/>.
        /// </param>
        /// <param name="sProgram">
        /// The <see cref="ShaderProgram"/> which has the state set.
        /// </param>
        public override void ApplyState(GraphicsContext ctx, ShaderProgram sProgram)
        {
            if (ctx == null)
            {
                throw new ArgumentNullException("ctx");
            }

            BlendState currentState = null;             // (BlendState)ctx.CurrentState[StateId];

            if (Enabled)
            {
                // Enable blending
                if (currentState == null || !currentState.Enabled)
                {
                    Gl.Enable(EnableCap.Blend);
                }

                // Set blending equation
                if (ctx.Caps.GlExtensions.BlendMinmax_EXT)
                {
                    if (EquationSeparated)
                    {
                        Gl.BlendEquationSeparate(RgbEquation, AlphaEquation);
                    }
                    else
                    {
                        Gl.BlendEquation((int)RgbEquation);
                    }
                }

                // Set blending function
                if (FunctionSeparated)
                {
                    Gl.BlendFuncSeparate((int)mRgbSrcFactor, (int)mRgbDstFactor, (int)mAlphaSrcFactor, (int)mAlphaDstFactor);
                }
                else
                {
                    Gl.BlendFunc(mRgbSrcFactor, mRgbDstFactor);
                }

                // Set blend color, if required
                if (RequiresConstColor(mRgbSrcFactor) || RequiresConstColor(mAlphaSrcFactor) || RequiresConstColor(mRgbDstFactor) || RequiresConstColor(mAlphaDstFactor))
                {
                    Gl.BlendColor(mBlendColor.Red, mBlendColor.Green, mBlendColor.Blue, mBlendColor.Alpha);
                }
            }
            else
            {
                // Disable blending
                if (currentState == null || currentState.Enabled)
                {
                    Gl.Disable(EnableCap.Blend);
                }
            }
        }
Пример #3
0
        private void ApplyStateCore(GraphicsContext ctx, ShaderProgram program)
        {
            if (Enabled)
            {
                // Enable blending
                Gl.Enable(EnableCap.Blend);

                // Set blending equation
                if (ctx.Extensions.BlendMinmax_EXT)
                {
                    if (EquationSeparated)
                    {
                        Gl.BlendEquationSeparate(RgbEquation, AlphaEquation);
                    }
                    else
                    {
                        Gl.BlendEquation((int)RgbEquation);
                    }
                }

                // Set blending function
                if (FunctionSeparated)
                {
                    Gl.BlendFuncSeparate((int)_RgbSrcFactor, (int)_RgbDstFactor, (int)_AlphaSrcFactor, (int)_AlphaDstFactor);
                }
                else
                {
                    Gl.BlendFunc(_RgbSrcFactor, _RgbDstFactor);
                }

                // Set blend color, if required
                if (RequiresConstColor(_RgbSrcFactor) || RequiresConstColor(_AlphaSrcFactor) || RequiresConstColor(_RgbDstFactor) || RequiresConstColor(_AlphaDstFactor))
                {
                    Gl.BlendColor(_BlendColor.Red, _BlendColor.Green, _BlendColor.Blue, _BlendColor.Alpha);
                }
            }
            else
            {
                // Disable blending
                Gl.Disable(EnableCap.Blend);
            }
        }