Exemple #1
0
        internal unsafe BlendState(BlendStateDescription blendStateDescription, bool hasRenderTarget)
        {
            var renderTargets = &blendStateDescription.RenderTarget0;

            for (int i = 1; i < 8; ++i)
            {
                if (renderTargets[i].BlendEnable || renderTargets[i].ColorWriteChannels != ColorWriteChannels.All)
                {
                    throw new NotSupportedException();
                }
            }

            ColorWriteChannels = blendStateDescription.RenderTarget0.ColorWriteChannels;
            if (!hasRenderTarget)
            {
                ColorWriteChannels = 0;
            }

            blendEnable = blendStateDescription.RenderTarget0.BlendEnable;

            blendEquationModeColor = ToOpenGL(blendStateDescription.RenderTarget0.ColorBlendFunction);
            blendEquationModeAlpha = ToOpenGL(blendStateDescription.RenderTarget0.AlphaBlendFunction);
            blendFactorSrcColor    = ToOpenGL(blendStateDescription.RenderTarget0.ColorSourceBlend);
            blendFactorSrcAlpha    = ToOpenGL(blendStateDescription.RenderTarget0.AlphaSourceBlend);
            blendFactorDestColor   = (BlendingFactorDest)ToOpenGL(blendStateDescription.RenderTarget0.ColorDestinationBlend);
            blendFactorDestAlpha   = (BlendingFactorDest)ToOpenGL(blendStateDescription.RenderTarget0.AlphaDestinationBlend);

            blendEquationHash = (uint)blendStateDescription.RenderTarget0.ColorBlendFunction
                                | ((uint)blendStateDescription.RenderTarget0.AlphaBlendFunction << 8);

            blendFuncHash = (uint)blendStateDescription.RenderTarget0.ColorSourceBlend
                            | ((uint)blendStateDescription.RenderTarget0.AlphaSourceBlend << 8)
                            | ((uint)blendStateDescription.RenderTarget0.ColorDestinationBlend << 16)
                            | ((uint)blendStateDescription.RenderTarget0.AlphaDestinationBlend << 24);
        }
Exemple #2
0
        public BlendingInfo(BlendingMode blendingMode)
        {
            switch (blendingMode)
            {
            case BlendingMode.Inherit:
            case BlendingMode.Mixture:
                Source           = BlendingFactorSrc.SrcAlpha;
                Destination      = BlendingFactorDest.OneMinusSrcAlpha;
                SourceAlpha      = BlendingFactorSrc.One;
                DestinationAlpha = BlendingFactorDest.One;
                break;

            case BlendingMode.Additive:
                Source           = BlendingFactorSrc.SrcAlpha;
                Destination      = BlendingFactorDest.One;
                SourceAlpha      = BlendingFactorSrc.One;
                DestinationAlpha = BlendingFactorDest.One;
                break;

            default:
                Source           = BlendingFactorSrc.One;
                Destination      = BlendingFactorDest.Zero;
                SourceAlpha      = BlendingFactorSrc.One;
                DestinationAlpha = BlendingFactorDest.Zero;
                break;
            }
        }
Exemple #3
0
        internal BlendState(GraphicsDevice device, BlendStateDescription blendStateDescription) : base(device)
        {
            Description = blendStateDescription;

            for (int i = 1; i < Description.RenderTargets.Length; ++i)
            {
                if (Description.RenderTargets[i].BlendEnable || Description.RenderTargets[i].ColorWriteChannels != ColorWriteChannels.All)
                {
                    throw new NotSupportedException();
                }
            }

            blendEnable = Description.RenderTargets[0].BlendEnable;

            blendEquationModeColor = ToOpenGL(Description.RenderTargets[0].ColorBlendFunction);
            blendEquationModeAlpha = ToOpenGL(Description.RenderTargets[0].AlphaBlendFunction);
            blendFactorSrcColor    = ToOpenGL(Description.RenderTargets[0].ColorSourceBlend);
            blendFactorSrcAlpha    = ToOpenGL(Description.RenderTargets[0].AlphaSourceBlend);
            blendFactorDestColor   = (BlendingFactorDest)ToOpenGL(Description.RenderTargets[0].ColorDestinationBlend);
            blendFactorDestAlpha   = (BlendingFactorDest)ToOpenGL(Description.RenderTargets[0].AlphaDestinationBlend);
            EnabledColors[0]       = (Description.RenderTargets[0].ColorWriteChannels & ColorWriteChannels.Red) != 0;
            EnabledColors[1]       = (Description.RenderTargets[0].ColorWriteChannels & ColorWriteChannels.Green) != 0;
            EnabledColors[2]       = (Description.RenderTargets[0].ColorWriteChannels & ColorWriteChannels.Blue) != 0;
            EnabledColors[3]       = (Description.RenderTargets[0].ColorWriteChannels & ColorWriteChannels.Alpha) != 0;

            blendEquationHash = (uint)Description.RenderTargets[0].ColorBlendFunction
                                | ((uint)Description.RenderTargets[0].AlphaBlendFunction << 8);

            blendFuncHash = (uint)Description.RenderTargets[0].ColorSourceBlend
                            | ((uint)Description.RenderTargets[0].AlphaSourceBlend << 8)
                            | ((uint)Description.RenderTargets[0].ColorDestinationBlend << 16)
                            | ((uint)Description.RenderTargets[0].AlphaDestinationBlend << 24);
        }
        internal unsafe BlendState(BlendStateDescription blendStateDescription, bool hasRenderTarget)
        {
            var renderTargets = &blendStateDescription.RenderTarget0;
            for (int i = 1; i < 8; ++i)
            {
                if (renderTargets[i].BlendEnable || renderTargets[i].ColorWriteChannels != ColorWriteChannels.All)
                    throw new NotSupportedException();
            }

            ColorWriteChannels = blendStateDescription.RenderTarget0.ColorWriteChannels;
            if (!hasRenderTarget)
                ColorWriteChannels = 0;

            blendEnable = blendStateDescription.RenderTarget0.BlendEnable;

            blendEquationModeColor = ToOpenGL(blendStateDescription.RenderTarget0.ColorBlendFunction);
            blendEquationModeAlpha = ToOpenGL(blendStateDescription.RenderTarget0.AlphaBlendFunction);
            blendFactorSrcColor = ToOpenGL(blendStateDescription.RenderTarget0.ColorSourceBlend);
            blendFactorSrcAlpha = ToOpenGL(blendStateDescription.RenderTarget0.AlphaSourceBlend);
            blendFactorDestColor = (BlendingFactorDest)ToOpenGL(blendStateDescription.RenderTarget0.ColorDestinationBlend);
            blendFactorDestAlpha = (BlendingFactorDest)ToOpenGL(blendStateDescription.RenderTarget0.AlphaDestinationBlend);

            blendEquationHash = (uint)blendStateDescription.RenderTarget0.ColorBlendFunction
                             | ((uint)blendStateDescription.RenderTarget0.AlphaBlendFunction << 8);

            blendFuncHash = (uint)blendStateDescription.RenderTarget0.ColorSourceBlend
                         | ((uint)blendStateDescription.RenderTarget0.AlphaSourceBlend << 8)
                         | ((uint)blendStateDescription.RenderTarget0.ColorDestinationBlend << 16)
                         | ((uint)blendStateDescription.RenderTarget0.AlphaDestinationBlend << 24);
        }
 /// <summary>
 /// Initializes a new custom instance of the <see cref="SurfaceBlendSetting"/> class.
 /// </summary>
 /// <param name="src">The <see cref="BlendingFactorSrc"/>.</param>
 /// <param name="dest">The <see cref="BlendingFactorDest"/>.</param>
 /// <param name="equation">The <see cref="BlendEquationMode"/>.</param>
 public SurfaceBlendSetting(BlendingFactorSrc src, BlendingFactorDest dest, BlendEquationMode equation)
     : base(true)
 {
     this.srcBlend = src;
     this.destBlend = dest;
     this.equation = equation;
 }
Exemple #6
0
 /// <summary>
 /// Initializes a new custom instance of the <see cref="SurfaceBlendSetting"/> class.
 /// </summary>
 /// <param name="src">The <see cref="BlendingFactorSrc"/>.</param>
 /// <param name="dest">The <see cref="BlendingFactorDest"/>.</param>
 /// <param name="equation">The <see cref="BlendEquationMode"/>.</param>
 public SurfaceBlendSetting(BlendingFactorSrc src, BlendingFactorDest dest, BlendEquationMode equation)
     : base(true)
 {
     this.srcBlend  = src;
     this.destBlend = dest;
     this.equation  = equation;
 }
        internal BlendState(GraphicsDevice device, BlendStateDescription blendStateDescription) : base(device)
        {
            Description = blendStateDescription;

            for (int i = 1; i < Description.RenderTargets.Length; ++i)
            {
                if (Description.RenderTargets[i].BlendEnable || Description.RenderTargets[i].ColorWriteChannels != ColorWriteChannels.All)
                    throw new NotSupportedException();
            }

            blendEnable = Description.RenderTargets[0].BlendEnable;

            blendEquationModeColor = ToOpenGL(Description.RenderTargets[0].ColorBlendFunction);
            blendEquationModeAlpha = ToOpenGL(Description.RenderTargets[0].AlphaBlendFunction);
            blendFactorSrcColor = ToOpenGL(Description.RenderTargets[0].ColorSourceBlend);
            blendFactorSrcAlpha = ToOpenGL(Description.RenderTargets[0].AlphaSourceBlend);
            blendFactorDestColor = (BlendingFactorDest)ToOpenGL(Description.RenderTargets[0].ColorDestinationBlend);
            blendFactorDestAlpha = (BlendingFactorDest)ToOpenGL(Description.RenderTargets[0].AlphaDestinationBlend);
            EnabledColors[0] = (Description.RenderTargets[0].ColorWriteChannels & ColorWriteChannels.Red  ) != 0;
            EnabledColors[1] = (Description.RenderTargets[0].ColorWriteChannels & ColorWriteChannels.Green) != 0;
            EnabledColors[2] = (Description.RenderTargets[0].ColorWriteChannels & ColorWriteChannels.Blue ) != 0;
            EnabledColors[3] = (Description.RenderTargets[0].ColorWriteChannels & ColorWriteChannels.Alpha) != 0;

            blendEquationHash = (uint)Description.RenderTargets[0].ColorBlendFunction
                             | ((uint)Description.RenderTargets[0].AlphaBlendFunction << 8);

            blendFuncHash = (uint)Description.RenderTargets[0].ColorSourceBlend
                         | ((uint)Description.RenderTargets[0].AlphaSourceBlend << 8)
                         | ((uint)Description.RenderTargets[0].ColorDestinationBlend << 16)
                         | ((uint)Description.RenderTargets[0].AlphaDestinationBlend << 24);
        }
Exemple #8
0
        public BlendingInfo(BlendingParameters parameters)
        {
            switch (parameters.Mode)
            {
            case BlendingMode.Inherit:
            case BlendingMode.Mixture:
                Source           = BlendingFactorSrc.SrcAlpha;
                Destination      = BlendingFactorDest.OneMinusSrcAlpha;
                SourceAlpha      = BlendingFactorSrc.One;
                DestinationAlpha = BlendingFactorDest.One;
                break;

            case BlendingMode.Additive:
                Source           = BlendingFactorSrc.SrcAlpha;
                Destination      = BlendingFactorDest.One;
                SourceAlpha      = BlendingFactorSrc.One;
                DestinationAlpha = BlendingFactorDest.One;
                break;

            default:
                Source           = BlendingFactorSrc.One;
                Destination      = BlendingFactorDest.Zero;
                SourceAlpha      = BlendingFactorSrc.One;
                DestinationAlpha = BlendingFactorDest.Zero;
                break;
            }

            RGBEquation   = translateEquation(parameters.RGBEquation);
            AlphaEquation = translateEquation(parameters.AlphaEquation);
        }
Exemple #9
0
 public BlendingFactorState(BlendingFactorSrc src, BlendingFactorDest dest, BlendingFactorSrc alphaSrc, BlendingFactorDest alphaDest)
 {
     this.src       = src;
     this.dest      = dest;
     this.alphaSrc  = alphaSrc;
     this.alphaDest = alphaDest;
 }
Exemple #10
0
        public static void BlendFunc(BlendingFactorSrc sfactor, BlendingFactorDest dfactor)
        {
#if USE_OPENGL
            OpenTK.Graphics.OpenGL.GL.BlendFunc((OpenTK.Graphics.OpenGL.BlendingFactorSrc)sfactor, (OpenTK.Graphics.OpenGL.BlendingFactorDest)dfactor);
#else
            OpenTK.Graphics.ES11.GL.BlendFunc((OpenTK.Graphics.ES11.All)sfactor, (OpenTK.Graphics.ES11.All)dfactor);
#endif
        }
Exemple #11
0
 public static void BlendFunc(BlendingFactorSrc blendingFactorSrc, BlendingFactorDest blendingFactorDest)
 {
     if (blendFactorSrc != blendingFactorSrc || blendFactorDest != blendingFactorDest)
     {
         blendFactorSrc  = blendingFactorSrc;
         blendFactorDest = blendingFactorDest;
         GL.BlendFunc(blendingFactorSrc, blendingFactorDest);
     }
 }
Exemple #12
0
 public static void BlendFunc(BlendingFactorSrc blendingFactorSrc, BlendingFactorDest blendingFactorDest)
 {
     if (blendFactorSrc != blendingFactorSrc || blendFactorDest != blendingFactorDest)
     {
         blendFactorSrc = blendingFactorSrc;
         blendFactorDest = blendingFactorDest;
         GL.BlendFunc(blendingFactorSrc, blendingFactorDest);
     }
 }
Exemple #13
0
 public BlendMode(BlendingFactorSrc srcRgb, BlendingFactorDest dstRgb, BlendingFactorSrc srcAlpha, BlendingFactorDest dstAlpha, BlendEquationMode modeRgb = BlendEquationMode.FuncAdd, BlendEquationMode modeAlpha = BlendEquationMode.FuncAdd)
 {
     BlendSrcRgb    = srcRgb;
     BlendDstRgb    = dstRgb;
     BlendSrcAlpha  = srcAlpha;
     BlendDstAlpha  = dstAlpha;
     BlendModeRgb   = modeRgb;
     BlendModeAlpha = modeAlpha;
 }
 public IBlendState CreateBlendState(
     BlendingFactorSrc colorSource,
     BlendEquationMode colorEquation,
     BlendingFactorDest colorDest,
     BlendingFactorSrc alphaSource,
     BlendEquationMode alphaEquation,
     BlendingFactorDest alphaDest)
 {
     return(new CacheBlendState(true, colorSource, colorEquation, colorDest, alphaSource, alphaEquation, alphaDest));
 }
Exemple #15
0
        public static void BlendFunc(BlendingFactorSrc source, BlendingFactorDest dest)
        {
            if (source != _blendFuncSource && dest != _blendFuncDest)
            {
                source = _blendFuncSource;
                dest   = _blendFuncDest;

                GL.BlendFunc(source, dest);
            }
        }
Exemple #16
0
        public static void BlendFunc(BlendingFactorSrc source, BlendingFactorDest dest)
        {
            if (source != _blendFuncSource && dest != _blendFuncDest)
            {
                source = _blendFuncSource;
                dest = _blendFuncDest;

                GL.BlendFunc(source, dest);
            }
        }
Exemple #17
0
        public static void BlendFunc(BlendingFactorSrc sfactor, BlendingFactorDest dfactor)
        {
#if USE_OPENGL
            if (openGlHardwareAvailable)
            {
                OpenTK.Graphics.OpenGL.GL.BlendFunc((OpenTK.Graphics.OpenGL.BlendingFactorSrc)sfactor, (OpenTK.Graphics.OpenGL.BlendingFactorDest)dfactor);
            }
#else
            OpenTK.Graphics.ES11.GL.BlendFunc((OpenTK.Graphics.ES11.All)sfactor, (OpenTK.Graphics.ES11.All)dfactor);
#endif
        }
Exemple #18
0
 public GLState(CullFaceMode cullFaceMode, DepthFunction depthFunction, BlendingFactorSrc blendingFactorSrc,
                BlendingFactorDest blendingFactorDest, params EnableCap[] enableCaps)
 {
     CullFaceMode       = cullFaceMode;
     DepthFunction      = depthFunction;
     BlendingFactorSrc  = blendingFactorSrc;
     BlendingFactorDest = blendingFactorDest;
     EnableCaps         = enableCaps;
     _fullHash          = "{" + CullFaceMode + "}{" + DepthFunction + "}{" + BlendingFactorSrc + "}{" + BlendingFactorDest +
                          "}{" + EnableCaps.Aggregate("", (left, cap) => left + cap.ToString()) + "}";
 }
Exemple #19
0
        /// <summary>
        /// Construct a BlendState with separated RGB/Alpha functions.
        /// </summary>
        /// <param name="rgbEquation">
        /// A <see cref="BlendEquationModeEXT"/> flag indicating which equation to used for blending RGB color components.
        /// </param>
        /// <param name="alphaEquation">
        /// A <see cref="BlendEquationModeEXT"/> flag indicating which equation to used for blending Alpha color component.
        /// </param>
        /// <param name="srcRgbFactor">
        /// A <see cref="BlendingFactorSrc"/> that specify the scaling factors applied to the source color (alpha component excluded).
        /// </param>
        /// <param name="srcAlphaFactor">
        /// A <see cref="BlendingFactorSrc"/> that specify the scaling factors applied to only the source alpha component.
        /// </param>
        /// <param name="dstRgbFactor">
        /// A <see cref="BlendingFactorDest"/> that specify the scaling factors applied to the destination color (alpha component excluded).
        /// </param>
        /// <param name="dstAlphaFactor">
        /// A <see cref="BlendingFactorDest"/> that specify the scaling factors applied to only the destination alpha component.
        /// </param>
        /// <param name="constColor">
        /// A <see cref="ColorRGBAF"/> that specify the constant color used in blending functions.
        /// </param>
        public BlendState(BlendEquationModeEXT rgbEquation, BlendEquationModeEXT alphaEquation, BlendingFactorSrc srcRgbFactor, BlendingFactorSrc srcAlphaFactor, BlendingFactorDest dstRgbFactor, BlendingFactorDest dstAlphaFactor, ColorRGBAF constColor)
        {
            if (IsSupportedEquation(rgbEquation) == false)
            {
                throw new ArgumentException("not supported blending equation " + srcRgbFactor, "rgbEquation");
            }
            if (IsSupportedEquation(alphaEquation) == false)
            {
                throw new ArgumentException("not supported blending equation " + alphaEquation, "rgbEquation");
            }
            if (IsSupportedFunction(srcRgbFactor) == false)
            {
                throw new ArgumentException("not supported blending function " + srcRgbFactor, "srcRgbFactor");
            }
            if (IsSupportedFunction(srcAlphaFactor) == false)
            {
                throw new ArgumentException("not supported blending function " + srcAlphaFactor, "srcAlphaFactor");
            }
            if (IsSupportedFunction(dstRgbFactor) == false)
            {
                throw new ArgumentException("not supported blending function " + dstRgbFactor, "dstRgbFactor");
            }
            if (IsSupportedFunction(dstAlphaFactor) == false)
            {
                throw new ArgumentException("not supported blending function " + dstAlphaFactor, "dstAlphaFactor");
            }

            // Blend enabled
            mEnabled = true;

            // Store RGB separate equation
            mRgbEquation = rgbEquation;
            // Store alpha separate equation
            mAlphaEquation = alphaEquation;

            // Store rgb separate function
            mRgbSrcFactor = srcRgbFactor;
            mRgbDstFactor = dstRgbFactor;
            // Store alpha separate function
            mAlphaSrcFactor = srcAlphaFactor;
            mAlphaDstFactor = dstAlphaFactor;
            // Store blend color
            mBlendColor = constColor;

            if (EquationSeparated && !GraphicsContext.CurrentCaps.GlExtensions.BlendEquationSeparate_EXT)
            {
                throw new InvalidOperationException("not supported separated blending equations");
            }
            if (FunctionSeparated && !GraphicsContext.CurrentCaps.GlExtensions.BlendFuncSeparate_EXT)
            {
                throw new InvalidOperationException("not supported separated blending functions");
            }
        }
Exemple #20
0
 public BlendState()
 {
     _alphaBlendFunction    = BlendEquationMode.FuncAdd;
     _alphaDestinationBlend = BlendingFactorDest.Zero;
     _alphaSourceBlend      = BlendingFactorSrc.One;
     _colorBlendFunction    = BlendEquationMode.FuncAdd;
     _colorDestinationBlend = BlendingFactorDest.Zero;
     _colorSourceBlend      = BlendingFactorSrc.One;
     _colorWriteChannels    = ColorWriteChannels.All;
     _blendColor            = new Color4(0, 0, 0, 0);
     _dirty = true;
 }
Exemple #21
0
        public NiAlphaProperty(NiFile file, BinaryReader reader) : base(file, reader)
        {
            Flags                = reader.ReadUInt16();
            Threshold            = reader.ReadByte();
            AlphaBlendingEnabled = (Flags & 0x01) == 1;

            SourceBlendMode = GetSrc((Flags & 0x1E) >> 1);
            TargetBlendMode = GetTarget((Flags & 0x1E0) >> 5);

            AlphaTestEnabled       = (Flags & 0x200) == 0x200;
            AlphaTestMode          = GetTestMode((Flags & 0x1C00) >> 10);
            DisableTriangleSorting = (Flags & 0x2000) == 0x2000;
        }
Exemple #22
0
        private static bool RequiresConstColor(BlendingFactorDest func)
        {
            switch (func)
            {
            case BlendingFactorDest.ConstantColor:
            case BlendingFactorDest.OneMinusConstantColor:
            case BlendingFactorDest.ConstantAlpha:
            case BlendingFactorDest.OneMinusConstantAlpha:
                return(true);

            default:
                return(false);
            }
        }
Exemple #23
0
        /// <summary>
        /// Sets the blending function to draw with.
        /// </summary>
        /// <param name="src">The source blending factor.</param>
        /// <param name="dest">The destination blending factor.</param>
        public static void SetBlend(BlendingFactorSrc src, BlendingFactorDest dest)
        {
            if (lastSrcBlend == src && lastDestBlend == dest)
            {
                return;
            }

            lastActiveBatch?.Draw();

            GL.BlendFunc(src, dest);

            lastSrcBlend  = src;
            lastDestBlend = dest;
        }
Exemple #24
0
 /// <summary>
 /// Construct a new BlendType
 /// </summary>
 /// <param name="srcColor">Source RGB factor</param>
 /// <param name="destColor">Destination RGB factor</param>
 /// <param name="srcAlpha">Source alpha factor</param>
 /// <param name="destAlpha">Destination alpha factor</param>
 /// <param name="equationColor">RGB equation</param>
 /// <param name="equationAlpha">Alpha equation</param>
 public BlendType(
     BlendingFactorSrc srcColor, BlendingFactorDest destColor,
     BlendingFactorSrc srcAlpha, BlendingFactorDest destAlpha,
     BlendEquationMode equationColor = BlendEquationMode.FuncAdd,
     BlendEquationMode equationAlpha = BlendEquationMode.FuncAdd
     )
 {
     SrcColor      = srcColor;
     DestColor     = destColor;
     SrcAlpha      = srcAlpha;
     DestAlpha     = destAlpha;
     EquationColor = equationColor;
     EquationAlpha = equationAlpha;
 }
Exemple #25
0
        /// <summary>
        /// Determine whether a blending function is supported.
        /// </summary>
        /// <param name="func"></param>
        /// <returns></returns>
        private static bool IsSupportedFunction(BlendingFactorDest func)
        {
            switch (func)
            {
            case BlendingFactorDest.ConstantColor:
            case BlendingFactorDest.OneMinusConstantColor:
            case BlendingFactorDest.ConstantAlpha:
            case BlendingFactorDest.OneMinusConstantAlpha:
                return(GraphicsContext.CurrentCaps.GlExtensions.BlendColor_EXT);

            default:
                return(true);
            }
        }
Exemple #26
0
        public static void SetBlendStates(BlendState state)
        {
            // Set blending mode
            BlendEquationMode blendMode = state.ColorBlendFunction.GetBlendEquationMode();

            GL.BlendEquation(blendMode);

            // Set blending function
            BlendingFactorSrc  bfs = state.ColorSourceBlend.GetBlendFactorSrc();
            BlendingFactorDest bfd = state.ColorDestinationBlend.GetBlendFactorDest();

            GL.BlendFunc(bfs, bfd);

            GL.Enable(EnableCap.Blend);
        }
Exemple #27
0
 public CacheBlendState(
     bool enabled,
     BlendingFactorSrc colorSource,
     BlendEquationMode colorEquation,
     BlendingFactorDest colorDest,
     BlendingFactorSrc alphaSource,
     BlendEquationMode alphaEquation,
     BlendingFactorDest alphaDest)
 {
     this.Enabled       = enabled;
     this.colorSource   = colorSource;
     this.colorEquation = colorEquation;
     this.colorDest     = colorDest;
     this.alphaSource   = alphaSource;
     this.alphaEquation = alphaEquation;
     this.alphaDest     = alphaDest;
 }
Exemple #28
0
        internal static void SetBlend(BlendingFactorSrc src, BlendingFactorDest dest)
        {
            if (ConfigManager.dDisableBlendingModes)
            {
                return;
            }

            if (lastSrcBlend == src && lastDestBlend == dest)
            {
                return;
            }

            GL.BlendFunc(src, dest);

            lastSrcBlend  = src;
            lastDestBlend = dest;
        }
Exemple #29
0
        public BlendingFactorState(BlendingMode mode)
        {
            switch (mode)
            {
            case BlendingMode.Off:
                enabled = false;
                break;

            case BlendingMode.Alphablend:
                src  = alphaSrc = BlendingFactorSrc.SrcAlpha;
                dest = alphaDest = BlendingFactorDest.OneMinusSrcAlpha;
                break;

            case BlendingMode.Color:
                src       = BlendingFactorSrc.SrcAlpha;
                dest      = BlendingFactorDest.OneMinusSrcAlpha;
                alphaSrc  = BlendingFactorSrc.Zero;
                alphaDest = BlendingFactorDest.One;
                break;

            case BlendingMode.Additive:
                src  = alphaSrc = BlendingFactorSrc.SrcAlpha;
                dest = alphaDest = BlendingFactorDest.One;
                break;

            case BlendingMode.Premultiply:
                src       = BlendingFactorSrc.SrcAlpha;
                dest      = BlendingFactorDest.OneMinusSrcAlpha;
                alphaSrc  = BlendingFactorSrc.One;
                alphaDest = BlendingFactorDest.OneMinusSrcAlpha;
                break;

            case BlendingMode.Premultiplied:
                src  = alphaSrc = BlendingFactorSrc.One;
                dest = alphaDest = BlendingFactorDest.OneMinusSrcAlpha;
                break;
            }
        }
Exemple #30
0
        /// <summary>
        /// Merge this state with another one.
        /// </summary>
        /// <param name="state">
        /// A <see cref="IGraphicsState"/> having the same <see cref="StateIdentifier"/> of this state.
        /// </param>
        public override void Merge(IGraphicsState state)
        {
            if (state == null)
            {
                throw new ArgumentNullException("state");
            }

            BlendState otherState = state as BlendState;

            if (otherState == null)
            {
                throw new ArgumentException("not a BlendState", "state");
            }

            mEnabled        = otherState.mEnabled;
            mRgbEquation    = otherState.mRgbEquation;
            mAlphaEquation  = otherState.mAlphaEquation;
            mRgbSrcFactor   = otherState.mRgbSrcFactor;
            mAlphaSrcFactor = otherState.mAlphaSrcFactor;
            mRgbDstFactor   = otherState.mRgbDstFactor;
            mAlphaDstFactor = otherState.mAlphaDstFactor;
            mBlendColor     = otherState.mBlendColor;
        }
Exemple #31
0
 public BlendMode(BlendingFactorSrc source, BlendingFactorDest destination)
     : this()
 {
     Source = source;
     Destination = destination;
 }
Exemple #32
0
		/// <summary>
		/// Construct a BlendState with separated RGB/Alpha functions.
		/// </summary>
		/// <param name="rgbEquation">
		/// A <see cref="BlendEquationModeEXT"/> flag indicating which equation to used for blending RGB color components.
		/// </param>
		/// <param name="alphaEquation">
		/// A <see cref="BlendEquationModeEXT"/> flag indicating which equation to used for blending Alpha color component.
		/// </param>
		/// <param name="srcRgbFactor">
		/// A <see cref="BlendingFactorSrc"/> that specify the scaling factors applied to the source color (alpha component excluded).
		/// </param>
		/// <param name="srcAlphaFactor">
		/// A <see cref="BlendingFactorSrc"/> that specify the scaling factors applied to only the source alpha component.
		/// </param>
		/// <param name="dstRgbFactor">
		/// A <see cref="BlendingFactorDest"/> that specify the scaling factors applied to the destination color (alpha component excluded).
		/// </param>
		/// <param name="dstAlphaFactor">
		/// A <see cref="BlendingFactorDest"/> that specify the scaling factors applied to only the destination alpha component.
		/// </param>
		/// <param name="constColor">
		/// A <see cref="ColorRGBAF"/> that specify the constant color used in blending functions.
		/// </param>
		public BlendState(BlendEquationModeEXT rgbEquation, BlendEquationModeEXT alphaEquation, BlendingFactorSrc srcRgbFactor, BlendingFactorSrc srcAlphaFactor, BlendingFactorDest dstRgbFactor, BlendingFactorDest dstAlphaFactor, ColorRGBAF constColor)
		{
			if (IsSupportedEquation(rgbEquation) == false)
				throw new ArgumentException("not supported blending equation " + srcRgbFactor, "rgbEquation");
			if (IsSupportedEquation(alphaEquation) == false)
				throw new ArgumentException("not supported blending equation " + alphaEquation, "rgbEquation");
			if (IsSupportedFunction(srcRgbFactor) == false)
				throw new ArgumentException("not supported blending function " + srcRgbFactor, "srcRgbFactor");
			if (IsSupportedFunction(srcAlphaFactor) == false)
				throw new ArgumentException("not supported blending function " + srcAlphaFactor, "srcAlphaFactor");
			if (IsSupportedFunction(dstRgbFactor) == false)
				throw new ArgumentException("not supported blending function " + dstRgbFactor, "dstRgbFactor");
			if (IsSupportedFunction(dstAlphaFactor) == false)
				throw new ArgumentException("not supported blending function " + dstAlphaFactor, "dstAlphaFactor");

			// Blend enabled
			mEnabled = true;

			// Store RGB separate equation
			mRgbEquation = rgbEquation;
			// Store alpha separate equation
			mAlphaEquation = alphaEquation;

			// Store rgb separate function
			mRgbSrcFactor = srcRgbFactor;
			mRgbDstFactor = dstRgbFactor;
			// Store alpha separate function
			mAlphaSrcFactor = srcAlphaFactor;
			mAlphaDstFactor = dstAlphaFactor;
			// Store blend color
			mBlendColor = constColor;

			if (EquationSeparated && !GraphicsContext.CurrentCaps.GlExtensions.BlendEquationSeparate_EXT)
				throw new InvalidOperationException("not supported separated blending equations");
			if (FunctionSeparated && !GraphicsContext.CurrentCaps.GlExtensions.BlendFuncSeparate_EXT)
				throw new InvalidOperationException("not supported separated blending functions");
		}
Exemple #33
0
		internal static extern void glBlendFunc(BlendingFactorSrc sfactor, BlendingFactorDest dfactor);
Exemple #34
0
		/// <summary>
		/// Determine whether a blending function is supported.
		/// </summary>
		/// <param name="func"></param>
		/// <returns></returns>
		private static bool IsSupportedFunction(BlendingFactorDest func)
		{
			switch (func) {
				case BlendingFactorDest.ConstantColor:
				case BlendingFactorDest.OneMinusConstantColor:
				case BlendingFactorDest.ConstantAlpha:
				case BlendingFactorDest.OneMinusConstantAlpha:
					return (GraphicsContext.CurrentCaps.GlExtensions.BlendColor_EXT);
				default:
					return (true);
			}
		}
Exemple #35
0
		/// <summary>
		/// Construct a BlendState with unified RGB/Alpha function.
		/// </summary>
		/// <param name="equation">
		/// A <see cref="BlendEquationModeEXT"/> flag indicating which equation to used for blending.
		/// </param>
		/// <param name="srcFactor">
		/// A <see cref="BlendingFactorSrc"/> that specify the scaling factors applied to the source color (including alpha).
		/// </param>
		/// <param name="dstFactor">
		/// A <see cref="BlendingFactorDest"/> that specify the scaling factors applied to the destination color (including alpha).
		/// </param>
		/// <param name="constColor">
		/// A <see cref="ColorRGBAF"/> that specify the constant color used in blending functions.
		/// </param>
		public BlendState(BlendEquationModeEXT equation, BlendingFactorSrc srcFactor, BlendingFactorDest dstFactor, ColorRGBAF constColor)
			: this(equation, equation, srcFactor, srcFactor, dstFactor, dstFactor, constColor)
		{
			
		}
Exemple #36
0
		public static void SetBlendMode(BlendingFactorSrc source, BlendingFactorDest destination)
		{
			GL.Enable(EnableCap.Blend);
			GL.BlendFunc(source, destination);
		}
Exemple #37
0
        /// <summary>
        /// Set the OpenGL BlendFunc state
        /// </summary>
        /// <param name="src">BlendingFactorSrc</param>
        /// <param name="dst">BlendingFactorDest</param>
        public static void BlendFunc(BlendingFactorSrc src, BlendingFactorDest dst)
        {
            if (!(alphaDst != dst || alphaSrc != src))
                return;

            GL.BlendFunc(src, dst);
            alphaSrc = src;
            alphaDst = dst;
        }
Exemple #38
0
		public static void BlendFuncSeparate(BlendingFactorSrc srcRGB, BlendingFactorDest dstRGB, BlendingFactorSrc srcAlpha, BlendingFactorDest dstAlpha)
		{
			glBlendFuncSeparate deleg = BaseGraphicsContext.Current.Loader.Get<glBlendFuncSeparate>();
			if (deleg != null)
				deleg(srcRGB, dstRGB, srcAlpha, dstAlpha);
		}
Exemple #39
0
 public GLBlendFunc(GraphicsInterface gi, BlendingFactorSrc srcBlend, BlendingFactorDest dstBlend)
     :base(gi)
 {
     fSrcBlendFactor = srcBlend;
     fDstBlendFactor = dstBlend;
 }
Exemple #40
0
 public virtual void SetDestinationBlendFactor(BlendingFactorDest aFactor)
 {
     fDstBlendFactor = aFactor;
     Realize();
 }
Exemple #41
0
		public IBlendState CreateBlendState(BlendingFactorSrc colorSource, BlendEquationMode colorEquation, BlendingFactorDest colorDest,
			BlendingFactorSrc alphaSource, BlendEquationMode alphaEquation, BlendingFactorDest alphaDest)
		{
			return new CacheBlendState(true, colorSource, colorEquation, colorDest, alphaSource, alphaEquation, alphaDest);
		}
Exemple #42
0
		public static void BlendFunc(BlendingFactorSrc sfactor, BlendingFactorDest dfactor)
		{
			Debug.Assert(Delegates.pglBlendFunc != null, "pglBlendFunc not implemented");
			Delegates.pglBlendFunc((Int32)sfactor, (Int32)dfactor);
			CallLog("glBlendFunc({0}, {1})", sfactor, dfactor);
			DebugCheckErrors();
		}
 public void BlendFunc(BlendingFactorSrc sfactor, BlendingFactorDest dfactor)
 {
     gl.glBlendFunc((int)sfactor, (int)dfactor);
     CheckException();
 }
Exemple #44
0
 public int CreateRenderState(bool enableAlphaBlend = false, bool enableDepthWrite = true, bool enableDepthTest = true, BlendingFactorSrc src = BlendingFactorSrc.Zero, BlendingFactorDest dest = BlendingFactorDest.One, CullFaceMode cullFaceMode = CullFaceMode.Back, bool enableCullFace = true, DepthFunction depthFunction = DepthFunction.Less)
 {
     return RenderSystem.CreateRenderState(enableAlphaBlend, enableDepthWrite, enableDepthTest, src, dest, cullFaceMode, enableCullFace, depthFunction);
 }
Exemple #45
0
 public static void BlendFunc(BlendingFactorSrc src, BlendingFactorDest dst)
 {
     ES20.GL.BlendFunc(src, dst);
     CheckError();
 }
Exemple #46
0
 internal static extern void glBlendFunc(BlendingFactorSrc sfactor, BlendingFactorDest dfactor);
Exemple #47
0
		/// <summary>
		/// Construct a BlendState with separated RGB/Alpha functions.
		/// </summary>
		/// <param name="rgbEquation">
		/// A <see cref="BlendEquationModeEXT"/> flag indicating which equation to used for blending RGB color components.
		/// </param>
		/// <param name="alphaEquation">
		/// A <see cref="BlendEquationModeEXT"/> flag indicating which equation to used for blending Alpha color component.
		/// </param>
		/// <param name="srcRgbFactor">
		/// A <see cref="BlendingFactorSrc"/> that specify the scaling factors applied to the source color (alpha component excluded).
		/// </param>
		/// <param name="srcAlphaFactor">
		/// A <see cref="BlendingFactorSrc"/> that specify the scaling factors applied to only the source alpha component.
		/// </param>
		/// <param name="dstRgbFactor">
		/// A <see cref="BlendingFactorDest"/> that specify the scaling factors applied to the destination color (alpha component excluded).
		/// </param>
		/// <param name="dstAlphaFactor">
		/// A <see cref="BlendingFactorDest"/> that specify the scaling factors applied to only the destination alpha component.
		/// </param>
		public BlendState(BlendEquationModeEXT rgbEquation, BlendEquationModeEXT alphaEquation, BlendingFactorSrc srcRgbFactor, BlendingFactorSrc srcAlphaFactor, BlendingFactorDest dstRgbFactor, BlendingFactorDest dstAlphaFactor)
			: this(rgbEquation, alphaEquation, srcRgbFactor, srcAlphaFactor, dstRgbFactor, dstAlphaFactor, new ColorRGBAF())
		{
			
		}
Exemple #48
0
 public static Reaction <T> Blending <T> (this Reaction <T> render,
                                          BlendingFactorSrc source       = BlendingFactorSrc.SrcAlpha,
                                          BlendingFactorDest destination = BlendingFactorDest.OneMinusSrcAlpha)
 {
     return(render.Blending(i => Tuple.Create(source, destination)));
 }
 public static extern void BlendFunc( BlendingFactorSrc sfactor, BlendingFactorDest dfactor );
Exemple #50
0
			public MyBlendState(bool enabled, BlendingFactorSrc colorSource, BlendEquationMode colorEquation, BlendingFactorDest colorDest,
				BlendingFactorSrc alphaSource, BlendEquationMode alphaEquation, BlendingFactorDest alphaDest)
			{
				this.enabled = enabled;
				this.colorSource = (global::OpenTK.Graphics.OpenGL.BlendingFactorSrc)colorSource;
				this.colorEquation = (global::OpenTK.Graphics.OpenGL.BlendEquationMode)colorEquation;
				this.colorDest = (global::OpenTK.Graphics.OpenGL.BlendingFactorDest)colorDest;
				this.alphaSource = (global::OpenTK.Graphics.OpenGL.BlendingFactorSrc)alphaSource;
				this.alphaEquation = (global::OpenTK.Graphics.OpenGL.BlendEquationMode)alphaEquation;
				this.alphaDest = (global::OpenTK.Graphics.OpenGL.BlendingFactorDest)alphaDest;
			}
Exemple #51
0
		public static void BlendFunc(BlendingFactorSrc sfactor, BlendingFactorDest dfactor)
		{
			glBlendFunc deleg = BaseGraphicsContext.Current.Loader.Get<glBlendFunc>();
			if (deleg != null)
				deleg(sfactor, dfactor);
		}
Exemple #52
0
 public IBlendState CreateBlendState(BlendingFactorSrc colorSource, BlendEquationMode colorEquation, BlendingFactorDest colorDest,
     BlendingFactorSrc alphaSource, BlendEquationMode alphaEquation, BlendingFactorDest alphaDest)
 {
     return null;
 }
Exemple #53
0
 public Blender(BlendingFactorSrc source, BlendingFactorDest destination)
 {
     GL.BlendFunc(source, destination);
     GL.Enable(EnableCap.Blend);
 }
Exemple #54
0
		public static void BlendFunc(BlendingFactorSrc sfactor, BlendingFactorDest dfactor)
		{
#if USE_OPENGL
			if (openGlHardwareAvailable)
			{
				OpenTK.Graphics.OpenGL.GL.BlendFunc((OpenTK.Graphics.OpenGL.BlendingFactorSrc)sfactor, (OpenTK.Graphics.OpenGL.BlendingFactorDest)dfactor);
			}
#else
			OpenTK.Graphics.ES11.GL.BlendFunc((OpenTK.Graphics.ES11.All)sfactor, (OpenTK.Graphics.ES11.All)dfactor);
#endif
		}
Exemple #55
0
		/// <summary>
		/// Merge this state with another one.
		/// </summary>
		/// <param name="state">
		/// A <see cref="IGraphicsState"/> having the same <see cref="StateIdentifier"/> of this state.
		/// </param>
		public override void Merge(IGraphicsState state)
		{
			if (state == null)
				throw new ArgumentNullException("state");

			BlendState otherState = state as BlendState;

			if (otherState == null)
				throw new ArgumentException("not a BlendState", "state");

			mEnabled = otherState.mEnabled;
			mRgbEquation = otherState.mRgbEquation;
			mAlphaEquation = otherState.mAlphaEquation;
			mRgbSrcFactor = otherState.mRgbSrcFactor;
			mAlphaSrcFactor = otherState.mAlphaSrcFactor;
			mRgbDstFactor = otherState.mRgbDstFactor;
			mAlphaDstFactor = otherState.mAlphaDstFactor;
			mBlendColor = otherState.mBlendColor;
		}
Exemple #56
0
		private static bool RequiresConstColor(BlendingFactorDest func)
		{
			switch (func) {
				case BlendingFactorDest.ConstantColor:
				case BlendingFactorDest.OneMinusConstantColor:
				case BlendingFactorDest.ConstantAlpha:
				case BlendingFactorDest.OneMinusConstantAlpha:
					return (true);
				default:
					return (false);
			}
		}
Exemple #57
0
 public static void BlendFunc(BlendingFactorSrc sfactor, BlendingFactorDest dfactor)
 {
     gl.glBlendFunc((int)sfactor, (int)dfactor);
 }
Exemple #58
0
 public static void BlendFunc(BlendingFactorSrc sfactor, BlendingFactorDest dfactor)
 {
     Instance?.BlendFunc(sfactor, dfactor);
 }
Exemple #59
0
 public void BlendFunc(BlendingFactorSrc src, BlendingFactorDest dest)
 {
     GL.BlendFunc(src, dest);
 }