diff --git a/includes/xna/enumerations.hpp b/includes/xna/enumerations.hpp index c458edc..8ede1a2 100644 --- a/includes/xna/enumerations.hpp +++ b/includes/xna/enumerations.hpp @@ -43,36 +43,6 @@ namespace xna { Max }; - enum class Blend { - Zero, - One, - SourceColor, - InverseSourceColor, - SourceAlpha, - InverseSourceAlpha, - DestinationAlpha, - InverseDestinationAlpha, - DestinationColor, - InverseDestinationColor, - SourceAlphaSaturation, - BlendFactor, - InverseBlendFactor, - Source1Color, - InverseSource1Color, - Source1Alpha, - InverseSource1Alpha - }; - - enum class BlendFunction { - Add = 0, - Subtract = 1, - ReverseSubtract = 2, - Min = 3, - Max = 4, - }; - - using BlendOperation = BlendFunction; - enum class BufferUsage { Default, Immutable, @@ -84,15 +54,6 @@ namespace xna { DepthBuffer, Stencil, Target, - }; - - enum class ColorWriteChannels { - Red, - Green, - Blue, - Alpha, - All, - None }; enum class ComparisonFunction { diff --git a/includes/xna/graphics/blendstate.hpp b/includes/xna/graphics/blendstate.hpp index e420c44..b1bf160 100644 --- a/includes/xna/graphics/blendstate.hpp +++ b/includes/xna/graphics/blendstate.hpp @@ -1,12 +1,93 @@ -#ifndef XNA_GRAPHICS_BLENDSTATE_HPP +#ifndef XNA_GRAPHICS_BLENDSTATE_HPP #define XNA_GRAPHICS_BLENDSTATE_HPP #include "../common/color.hpp" -#include "../default.hpp" #include "../platform.hpp" #include "gresource.hpp" +#include +#include namespace xna { + //Defines color blending factors. + enum class Blend { + //Each component of the color is multiplied by (0, 0, 0, 0). + Zero, + //Each component of the color is multiplied by (1, 1, 1, 1) + One, + //Each component of the color is multiplied by the source color. This can be represented as (Rs, Gs, Bs, As), + // where R, G, B, and A respectively stand for the red, green, blue, and alpha source values. + SourceColor, + //Each component of the color is multiplied by the inverse of the source color. + //This can be represented as (1 − Rs, 1 − Gs, 1 − Bs, 1 − As) where R, G, B, and A respectively stand for the red, green, blue, and alpha destination values. + InverseSourceColor, + //Each component of the color is multiplied by the alpha value of the source. + //This can be represented as (As, As, As, As), where As is the alpha source value. + SourceAlpha, + //Each component of the color is multiplied by the inverse of the alpha value of the source. + //This can be represented as (1 − As, 1 − As, 1 − As, 1 − As), where As is the alpha destination value. + InverseSourceAlpha, + //Each component of the color is multiplied by the alpha value of the destination. + //This can be represented as (Ad, Ad, Ad, Ad), where Ad is the destination alpha value. + DestinationAlpha, + //Each component of the color is multiplied by the inverse of the destination color. + //This can be represented as (1 − Rd, 1 − Gd, 1 − Bd, 1 − Ad), where Rd, Gd, Bd, and Ad respectively stand for the red, green, blue, and alpha destination values. + InverseDestinationAlpha, + //Each component color is multiplied by the destination color. + //This can be represented as (Rd, Gd, Bd, Ad), where R, G, B, and A respectively stand for red, green, blue, and alpha destination values. + DestinationColor, + //Each component of the color is multiplied by the inverse of the destination color. + // This can be represented as (1 − Rd, 1 − Gd, 1 − Bd, 1 − Ad), where Rd, Gd, Bd, and Ad respectively stand for the red, green, blue, and alpha destination values. + InverseDestinationColor, + //Each component of the color is multiplied by either the alpha of the source color, or the inverse of the alpha of the source color, whichever is greater. + // This can be represented as (f, f, f, 1), where f = min(A, 1 − Ad). + SourceAlphaSaturation, + //Each component of the color is multiplied by a constant set in BlendFactor. + BlendFactor, + //Each component of the color is multiplied by the inverse of a constant set in BlendFactor. + InverseBlendFactor, + Source1Color, + InverseSource1Color, + Source1Alpha, + InverseSource1Alpha + }; + + //Defines how to combine a source color with the destination color already on the render target for color blending. + enum class BlendFunction { + //The result is the destination added to the source. + //Result = (Source Color * Source Blend) + (Destination Color * Destination Blend) + Add = 0, + //The result is the destination subtracted from the source. + //Result = (Source Color * Source Blend) −(Destination Color * Destination Blend) + Subtract = 1, + //The result is the source subtracted from the destination. + //Result = (Destination Color * Destination Blend) −(Source Color * Source Blend) + ReverseSubtract = 2, + //The result is the minimum of the source and destination. + //Result = min((Source Color * Source Blend), (Destination Color * Destination Blend)) + Min = 3, + //The result is the maximum of the source and destination. + //Result = max((Source Color * Source Blend), (Destination Color * Destination Blend)) + Max = 4, + }; + + //Defines the color channels that can be chosen for a per-channel write to a render target color buffer. + enum class ColorWriteChannels { + //Red channel of a buffer. + Red, + //Green channel of a buffer. + Green, + //Blue channel of a buffer. + Blue, + //Alpha channel of a buffer. + Alpha, + //All buffer channels. + All, + //No channel selected. + None + }; + + using BlendOperation = BlendFunction; + struct BlendRenderTarget { bool Enabled{ true }; Blend Source{ Blend::SourceAlpha }; @@ -26,7 +107,7 @@ namespace xna { class BlendState : public GraphicsResource, public ImplementationBase { public: BlendState(); - BlendState(sptr const& device); + BlendState(std::shared_ptr const& device); //Gets or sets the arithmetic operation when blending alpha values. The default is BlendFunction.Add. BlendFunction AlphaBlendFunction() const; @@ -60,9 +141,9 @@ namespace xna { void BlendFactor(Color const& value); //Gets or sets a bitmask which defines which samples can be written during multisampling. The default is 0xffffffff. - Int MultiSampleMask() const; + int32_t MultiSampleMask() const; //Gets or sets a bitmask which defines which samples can be written during multisampling. The default is 0xffffffff. - void MultiSampleMast(Int value); + void MultiSampleMask(int32_t value); //Specifies whether to use alpha-to-coverage as a multisampling technique when setting a pixel to a render target. void AlphaToCoverageEnable(bool value); @@ -75,19 +156,19 @@ namespace xna { //A built-in state object with settings for opaque blend, //that is overwriting the source with the destination data. - static uptr Opaque(); + static std::unique_ptr Opaque(); //A built-in state object with settings for alpha blend, //that is blending the source and destination data using alpha. - static uptr AlphaBlend(); + static std::unique_ptr AlphaBlend(); //A built-in state object with settings for additive blend, //that is adding the destination data to the source data without using alpha. - static uptr Additive(); + static std::unique_ptr Additive(); //A built-in state object with settings for blending with non-premultipled alpha, //that is blending source and destination data using alpha while assuming the color data contains no alpha information. - static uptr NonPremultiplied(); + static std::unique_ptr NonPremultiplied(); }; - using PBlendState = sptr; + using PBlendState = std::shared_ptr; } #endif \ No newline at end of file diff --git a/sources/framework-dx/blendstate.cpp b/sources/framework-dx/blendstate.cpp index 3e98284..c6994cd 100644 --- a/sources/framework-dx/blendstate.cpp +++ b/sources/framework-dx/blendstate.cpp @@ -91,7 +91,7 @@ namespace xna { return static_cast(Implementation->SampleMask); } - void BlendState::MultiSampleMast(Int value) { + void BlendState::MultiSampleMask(Int value) { Implementation->SampleMask = static_cast(value); }