Beispiel #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   = ToOpenGL(blendStateDescription.RenderTarget0.ColorDestinationBlend);
            blendFactorDestAlpha   = 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);
        }
Beispiel #2
0
 /// <summary>
 /// Creates a simple <see cref="BlendState"/> with additive blending equation parameters.
 /// </summary>
 /// <param name="isOpaque">Whether this <see cref="BlendState"/> is opaque.</param>
 public BlendState(bool isOpaque)
 {
     IsOpaque          = isOpaque;
     EquationModeRGB   = BlendEquationModeEXT.FuncAdd;
     EquationModeAlpha = BlendEquationModeEXT.FuncAdd;
     SourceFactorRGB   = BlendingFactor.One;
     SourceFactorAlpha = BlendingFactor.One;
     DestFactorRGB     = BlendingFactor.One;
     DestFactorAlpha   = BlendingFactor.One;
 }
Beispiel #3
0
 /// <summary>
 /// Creates a <see cref="BlendState"/> with a simple color-blending equation.
 /// </summary>
 /// <param name="isOpaque">Whether this <see cref="BlendState"/> is opaque.</param>
 /// <param name="equationModeRgba">The equation mode to use for the RGBA values.</param>
 /// <param name="sourceFactorRgba">The source factor to use for the RGBA values.</param>
 /// <param name="destFactorRgba">The destination factor to use for the RGBA values.</param>
 /// <param name="blendColor">The equation-constant blending color.</param>
 public BlendState(bool isOpaque, BlendEquationModeEXT equationModeRgba, BlendingFactor sourceFactorRgba,
                   BlendingFactor destFactorRgba, Vector4 blendColor = default)
 {
     IsOpaque          = isOpaque;
     EquationModeRGB   = equationModeRgba;
     EquationModeAlpha = equationModeRgba;
     SourceFactorRGB   = sourceFactorRgba;
     SourceFactorAlpha = sourceFactorRgba;
     DestFactorRGB     = destFactorRgba;
     DestFactorAlpha   = destFactorRgba;
     BlendColor        = blendColor;
 }
Beispiel #4
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");
            }
        }
Beispiel #5
0
        /// <summary>
        /// Determine whether a blending function is supported.
        /// </summary>
        /// <param name="equation"></param>
        /// <returns></returns>
        private static bool IsSupportedEquation(BlendEquationModeEXT equation)
        {
            switch (equation)
            {
            case BlendEquationModeEXT.Min:
            case BlendEquationModeEXT.Max:
                return(GraphicsContext.CurrentCaps.GlExtensions.BlendMinmax_EXT);

            case BlendEquationModeEXT.FuncSubtract:
            case BlendEquationModeEXT.FuncReverseSubtract:
                return(GraphicsContext.CurrentCaps.GlExtensions.BlendSubtract_EXT);

            default:
                return(true);
            }
        }
Beispiel #6
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;
        }
Beispiel #7
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)
 {
 }
		public static void BlendEquationSeparate(BlendEquationModeEXT modeRGB, BlendEquationModeEXT modeAlpha)
		{
			Debug.Assert(Delegates.pglBlendEquationSeparate != null, "pglBlendEquationSeparate not implemented");
			Delegates.pglBlendEquationSeparate((Int32)modeRGB, (Int32)modeAlpha);
			LogFunction("glBlendEquationSeparate({0}, {1})", modeRGB, modeAlpha);
			DebugCheckErrors(null);
		}
Beispiel #9
0
 public static void qglBlendEquationSeparate(BlendEquationModeEXT modeRGB, BlendEquationModeEXT modeAlpha) => glBlendEquationSeparate(modeRGB, modeAlpha);
 public static void BlendEquationEXT( BlendEquationModeEXT mode )
 {
     if (_BlendEquationEXT == null) throw new Exception( "Extension method BlendEquationEXT not found" );
      _BlendEquationEXT( mode );
 }
Beispiel #11
0
 public partial void BlendEquationSeparate([Flow(FlowDirection.In)] uint buf, [Flow(FlowDirection.In)] BlendEquationModeEXT modeRGB, [Flow(FlowDirection.In)] BlendEquationModeEXT modeAlpha);
 public abstract void BlendEquationSeparateIndexed([Flow(FlowDirection.In)] uint buf, [Flow(FlowDirection.In)] BlendEquationModeEXT modeRGB, [Flow(FlowDirection.In)] BlendEquationModeEXT modeAlpha);
Beispiel #13
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())
		{
			
		}
Beispiel #14
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())
 {
 }
Beispiel #15
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)
		{
			
		}
Beispiel #16
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;
		}
Beispiel #17
0
		/// <summary>
		/// Determine whether a blending function is supported.
		/// </summary>
		/// <param name="equation"></param>
		/// <returns></returns>
		private static bool IsSupportedEquation(BlendEquationModeEXT equation)
		{
			switch (equation) {
				case BlendEquationModeEXT.Min:
				case BlendEquationModeEXT.Max:
					return (GraphicsContext.CurrentCaps.GlExtensions.BlendMinmax_EXT);
				case BlendEquationModeEXT.FuncSubtract:
				case BlendEquationModeEXT.FuncReverseSubtract:
					return (GraphicsContext.CurrentCaps.GlExtensions.BlendSubtract_EXT);
				default:
					return (true);
			}
		}
Beispiel #18
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");
		}
 public abstract void BlendEquationIndexed([Flow(FlowDirection.In)] uint buf, [Flow(FlowDirection.In)] BlendEquationModeEXT mode);
Beispiel #20
0
 public partial void BlendEquation([Flow(FlowDirection.In)] uint buf, [Flow(FlowDirection.In)] BlendEquationModeEXT mode);
Beispiel #21
0
 public static void qglBlendEquation(BlendEquationModeEXT mode) => glBlendEquation(mode);
 public abstract void BlendEquation([Flow(FlowDirection.In)] BlendEquationModeEXT mode);
 public static void BlendEquationSeparateEXT( BlendEquationModeEXT modeRGB, BlendEquationModeEXT modeAlpha )
 {
     if (_BlendEquationSeparateEXT == null) throw new Exception( "Extension method BlendEquationSeparateEXT not found" );
      _BlendEquationSeparateEXT( modeRGB, modeAlpha );
 }