1 module nudsfml.graphics.blendmode; 2 3 struct BlendMode { 4 /** 5 * Enumeration of the blending factors. 6 * 7 * The factors are mapped directly to their OpenGL equivalents, 8 * specified by `glBlendFunc()` or `glBlendFuncSeparate()`. 9 */ 10 enum Factor { 11 /// (0, 0, 0, 0) 12 Zero, 13 /// (1, 1, 1, 1) 14 One, 15 /// (src.r, src.g, src.b, src.a) 16 SrcColor, 17 /// (1, 1, 1, 1) - (src.r, src.g, src.b, src.a) 18 OneMinunSrcColor, 19 /// (dst.r, dst.g, dst.b, dst.a) 20 DstColor, 21 /// (1, 1, 1, 1) - (dst.r, dst.g, dst.b, dst.a) 22 OneMinusDstColor, 23 /// (src.a, src.a, src.a, src.a) 24 SrcAlpha, 25 /// (1, 1, 1, 1) - (src.a, src.a, src.a, src.a) 26 OneMinusSrcAlpha, 27 /// (dst.a, dst.a, dst.a, dst.a) 28 DstAlpha, 29 /// (1, 1, 1, 1) - (dst.a, dst.a, dst.a, dst.a) 30 OneMinusDstAlpha 31 } 32 33 /** 34 * Enumeration of the blending equations 35 * 36 * The equations are mapped directly to their OpenGL equivalents, 37 * specified by glBlendEquation() or glBlendEquationSeparate(). 38 */ 39 enum Equation { 40 /// Pixel = Src * SrcFactor + Dst * DstFactor 41 Add, 42 /// Pixel = Src * SrcFactor - Dst * DstFactor 43 Subtract, 44 /// Pixel = Dst * DstFactor - Src * SrcFactor 45 ReverseSubtract 46 } 47 48 /// Blend source and dest according to dest alpha. 49 enum Alpha = BlendMode(Factor.SrcAlpha, Factor.OneMinusSrcAlpha, Equation.Add, Factor.One, Factor.OneMinusSrcAlpha, Equation.Add); 50 /// Add source to dest. 51 enum Add = BlendMode(Factor.SrcAlpha, Factor.One, Equation.Add, Factor.One, Factor.One, Equation.Add); 52 /// Multiply source and dest. 53 enum Multiply = BlendMode(Factor.DstColor, Factor.Zero, Equation.Add, Factor.DstColor, Factor.Zero, Equation.Add); 54 /// Overwrite dest with source. 55 enum None = BlendMode(Factor.One, Factor.Zero, Equation.Add, Factor.One, Factor.Zero, Equation.Add); 56 57 /// Source blending factor for the color channels. 58 Factor colorSrcFactor = Factor.SrcAlpha; 59 /// Destination blending factor for the color channels. 60 Factor colorDstFactor = Factor.OneMinusSrcAlpha; 61 /// Blending equation for the color channels. 62 Equation colorEquation = Equation.Add; 63 /// Source blending factor for the alpha channel. 64 Factor alphaSrcFactor = Factor.One; 65 /// Destination blending factor for the alpha channel. 66 Factor alphaDstFactor = Factor.OneMinusSrcAlpha; 67 /// Blending equation for the alpha channel. 68 Equation alphaEquation = Equation.Add; 69 70 /** 71 * Construct the blend mode given the factors and equation. 72 * 73 * This constructor uses the same factors and equation for both 74 * color and alpha components. It also defaults to the Add equation. 75 * 76 * Params: 77 * sourceFactor = Specifies how to compute the source factor for the 78 color and alpha channels 79 * destinationFactor = Specifies how to compute the destination factor for 80 the color and alpha channels 81 * blendEquation = Specifies how to combine the source and destination 82 colors and alpha 83 */ 84 this(Factor sourceFactor, Factor destinationFactor, Equation blendEquation = Equation.Add) { 85 colorSrcFactor = sourceFactor; 86 colorDstFactor = destinationFactor; 87 colorEquation = blendEquation; 88 89 alphaSrcFactor = sourceFactor; 90 alphaDstFactor = destinationFactor; 91 alphaEquation = blendEquation; 92 } 93 94 /** 95 * Construct the blend mode given the factors and equation. 96 * 97 * Params: 98 * colorSourceFactor = Specifies how to compute the source factor for 99 the color channels 100 * colorDestinationFactor = Specifies how to compute the destination factor 101 for the color channels 102 * colorBlendEquation = Specifies how to combine the source and 103 destination colors 104 * alphaSourceFactor = Specifies how to compute the source factor 105 * alphaDestinationFactor = Specifies how to compute the destination factor 106 * alphaBlendEquation = Specifies how to combine the source and 107 destination alphas 108 */ 109 this(Factor colorSourceFactor, Factor colorDestinationFactor, Equation colorBlendEquation, Factor alphaSourceFactor, Factor alphaDestinationFactor, Equation alphaBlendEquation) { 110 colorSrcFactor = colorSourceFactor; 111 colorDstFactor = colorDestinationFactor; 112 colorEquation = colorBlendEquation; 113 114 alphaSrcFactor = alphaSourceFactor; 115 alphaDstFactor = alphaDestinationFactor; 116 alphaEquation = alphaBlendEquation; 117 } 118 119 bool opEquals(BlendMode rhs) const { 120 return (colorSrcFactor == rhs.colorSrcFactor && 121 colorDstFactor == rhs.colorDstFactor && 122 colorEquation == rhs.colorEquation && 123 alphaSrcFactor == rhs.alphaSrcFactor && 124 alphaDstFactor == rhs.alphaDstFactor && 125 alphaEquation == rhs.alphaEquation ); 126 } 127 }