A game framework written with osu! in mind.

Moved blending factors into BlendingParameters.

Doddler 4f586e06 48d92285

+328 -204
+1 -1
osu.Framework.Tests/Visual/Audio/TestSceneSamples.cs
··· 98 98 Size = new Vector2(4, notes); 99 99 Colour = Color4.SkyBlue; 100 100 101 - Blending = BlendingMode.Additive; 101 + Blending = BlendingParameters.Additive; 102 102 103 103 InternalChildren = new Drawable[] 104 104 {
+1 -1
osu.Framework.Tests/Visual/Audio/TestSceneTrack.cs
··· 137 137 Anchor = Anchor.BottomLeft, 138 138 Origin = Anchor.Centre, 139 139 Icon = FontAwesome.Solid.CircleNotch, 140 - Blending = BlendingMode.Additive, 140 + Blending = BlendingParameters.Additive, 141 141 Colour = Color4.White, 142 142 Alpha = 0.2f, 143 143 Scale = new Vector2(20),
+8 -14
osu.Framework.Tests/Visual/Containers/TestSceneFrontToBackBox.cs
··· 40 40 [Test] 41 41 public void TestOpaqueBoxWithAdditiveBlending() 42 42 { 43 - createBox(b => b.Blending = BlendingMode.Additive); 43 + createBox(b => b.Blending = BlendingParameters.Additive); 44 44 AddAssert("doesn't render interior", () => !blendedBox.CanDrawOpaqueInterior); 45 45 } 46 46 ··· 49 49 { 50 50 createBox(b => 51 51 { 52 - b.Blending = BlendingMode.Additive; 52 + b.Blending = BlendingParameters.Additive; 53 53 b.Alpha = 0.5f; 54 54 }); 55 55 ··· 64 64 { 65 65 createBox(b => 66 66 { 67 - b.Blending = new BlendingParameters 68 - { 69 - Mode = BlendingMode.Inherit, 70 - AlphaEquation = BlendingEquation.Inherit, 71 - RGBEquation = equationMode 72 - }; 67 + var blending = BlendingParameters.Inherit; 68 + blending.RGBEquation = equationMode; 69 + b.Blending = blending; 73 70 }); 74 71 75 72 AddAssert("doesn't render interior", () => !blendedBox.CanDrawOpaqueInterior); ··· 83 80 { 84 81 createBox(b => 85 82 { 86 - b.Blending = new BlendingParameters 87 - { 88 - Mode = BlendingMode.Inherit, 89 - AlphaEquation = equationMode, 90 - RGBEquation = BlendingEquation.Inherit 91 - }; 83 + var blending = BlendingParameters.Inherit; 84 + blending.AlphaEquation = equationMode; 85 + b.Blending = blending; 92 86 }); 93 87 94 88 AddAssert("doesn't render interior", () => !blendedBox.CanDrawOpaqueInterior);
+52 -35
osu.Framework.Tests/Visual/Drawables/TestSceneBlending.cs
··· 2 2 // See the LICENCE file in the repository root for full licence text. 3 3 4 4 using System; 5 + using System.Collections.Generic; 5 6 using osu.Framework.Graphics; 6 7 using osu.Framework.Graphics.Colour; 7 8 using osu.Framework.Graphics.Containers; ··· 11 12 using osu.Framework.Logging; 12 13 using osuTK; 13 14 using osuTK.Graphics; 14 - using osuTK.Graphics.ES30; 15 15 16 16 namespace osu.Framework.Tests.Visual.Drawables 17 17 { 18 18 public class TestSceneBlending : FrameworkTestScene 19 19 { 20 - private readonly Dropdown<BlendingMode> colourModeDropdown; 20 + private readonly Dropdown<string> colourModeDropdown; 21 21 private readonly Dropdown<BlendingEquation> colourEquation; 22 22 private readonly Dropdown<BlendingEquation> alphaEquation; 23 23 private readonly BufferedContainer foregroundContainer; ··· 27 27 private readonly FillFlowContainer blendingAlphaSrcContainer; 28 28 private readonly FillFlowContainer blendingAlphaDestContainer; 29 29 30 - private readonly Dropdown<BlendingFactorSrc> blendingSrcDropdown; 31 - private readonly Dropdown<BlendingFactorDest> blendingDestDropdown; 32 - private readonly Dropdown<BlendingFactorSrc> blendingAlphaSrcDropdown; 33 - private readonly Dropdown<BlendingFactorDest> blendingAlphaDestDropdown; 30 + private readonly Dropdown<BlendingType> blendingSrcDropdown; 31 + private readonly Dropdown<BlendingType> blendingDestDropdown; 32 + private readonly Dropdown<BlendingType> blendingAlphaSrcDropdown; 33 + private readonly Dropdown<BlendingType> blendingAlphaDestDropdown; 34 34 35 35 private readonly FillFlowContainer settingsBox; 36 + 37 + private readonly Dictionary<string, BlendingParameters> blendingModes = new Dictionary<string, BlendingParameters> 38 + { 39 + { "Inherit", BlendingParameters.Inherit }, 40 + { "Additive", BlendingParameters.Additive }, 41 + { "Mixture", BlendingParameters.Mixture }, 42 + { "Custom", BlendingParameters.Mixture }, 43 + }; 36 44 37 45 private bool inCustomMode; 38 46 ··· 57 65 Children = new Drawable[] 58 66 { 59 67 new SpriteText { Text = "Blending mode" }, 60 - colourModeDropdown = new BasicDropdown<BlendingMode> { Width = 200 } 68 + colourModeDropdown = new BasicDropdown<string> { Width = 200 } 61 69 } 62 70 }, 63 71 new FillFlowContainer ··· 159 167 Children = new Drawable[] 160 168 { 161 169 new SpriteText { Text = "Custom: Source" }, 162 - blendingSrcDropdown = new BasicDropdown<BlendingFactorSrc> { Width = 200 } 170 + blendingSrcDropdown = new BasicDropdown<BlendingType> { Width = 200 } 163 171 }, 164 172 }; 165 173 ··· 171 179 Children = new Drawable[] 172 180 { 173 181 new SpriteText { Text = "Custom: Destination" }, 174 - blendingDestDropdown = new BasicDropdown<BlendingFactorDest> { Width = 200 } 182 + blendingDestDropdown = new BasicDropdown<BlendingType> { Width = 200 } 175 183 }, 176 184 }; 177 185 ··· 183 191 Children = new Drawable[] 184 192 { 185 193 new SpriteText { Text = "Custom: Alpha Source" }, 186 - blendingAlphaSrcDropdown = new BasicDropdown<BlendingFactorSrc> { Width = 200 } 194 + blendingAlphaSrcDropdown = new BasicDropdown<BlendingType> { Width = 200 } 187 195 }, 188 196 }; 189 197 ··· 195 203 Children = new Drawable[] 196 204 { 197 205 new SpriteText { Text = "Custom: Alpha Destination" }, 198 - blendingAlphaDestDropdown = new BasicDropdown<BlendingFactorDest> { Width = 200 } 206 + blendingAlphaDestDropdown = new BasicDropdown<BlendingType> { Width = 200 } 199 207 }, 200 208 }; 201 209 202 - colourModeDropdown.Items = (BlendingMode[])Enum.GetValues(typeof(BlendingMode)); 210 + colourModeDropdown.Items = blendingModes.Keys; 203 211 colourEquation.Items = (BlendingEquation[])Enum.GetValues(typeof(BlendingEquation)); 204 212 alphaEquation.Items = (BlendingEquation[])Enum.GetValues(typeof(BlendingEquation)); 205 213 206 - blendingSrcDropdown.Items = (BlendingFactorSrc[])Enum.GetValues(typeof(BlendingFactorSrc)); 207 - blendingDestDropdown.Items = (BlendingFactorDest[])Enum.GetValues(typeof(BlendingFactorDest)); 208 - blendingAlphaSrcDropdown.Items = (BlendingFactorSrc[])Enum.GetValues(typeof(BlendingFactorSrc)); 209 - blendingAlphaDestDropdown.Items = (BlendingFactorDest[])Enum.GetValues(typeof(BlendingFactorDest)); 214 + blendingSrcDropdown.Items = (BlendingType[])Enum.GetValues(typeof(BlendingType)); 215 + blendingDestDropdown.Items = (BlendingType[])Enum.GetValues(typeof(BlendingType)); 216 + blendingAlphaSrcDropdown.Items = (BlendingType[])Enum.GetValues(typeof(BlendingType)); 217 + blendingAlphaDestDropdown.Items = (BlendingType[])Enum.GetValues(typeof(BlendingType)); 210 218 211 - colourModeDropdown.Current.Value = foregroundContainer.Blending.Mode; 219 + colourModeDropdown.Current.Value = "Mixture"; 212 220 colourEquation.Current.Value = foregroundContainer.Blending.RGBEquation; 213 221 alphaEquation.Current.Value = foregroundContainer.Blending.AlphaEquation; 214 222 215 - blendingSrcDropdown.Current.Value = BlendingFactorSrc.SrcAlpha; 216 - blendingDestDropdown.Current.Value = BlendingFactorDest.OneMinusSrcAlpha; 217 - blendingAlphaSrcDropdown.Current.Value = BlendingFactorSrc.One; 218 - blendingAlphaDestDropdown.Current.Value = BlendingFactorDest.One; 223 + blendingSrcDropdown.Current.Value = BlendingType.SrcAlpha; 224 + blendingDestDropdown.Current.Value = BlendingType.OneMinusSrcAlpha; 225 + blendingAlphaSrcDropdown.Current.Value = BlendingType.One; 226 + blendingAlphaDestDropdown.Current.Value = BlendingType.One; 219 227 220 228 colourModeDropdown.Current.ValueChanged += v => updateBlending(); 221 229 colourEquation.Current.ValueChanged += v => updateBlending(); ··· 244 252 245 253 private void updateBlending() 246 254 { 247 - var newBlending = new BlendingParameters 248 - { 249 - Mode = colourModeDropdown.Current.Value, 250 - RGBEquation = colourEquation.Current.Value, 251 - AlphaEquation = alphaEquation.Current.Value 252 - }; 253 - 254 - if (colourModeDropdown.Current.Value == BlendingMode.Custom) 255 + if (colourModeDropdown.Current.Value == "Custom") 255 256 { 256 257 if (!inCustomMode) 257 258 switchToCustomBlending(); 258 259 259 - newBlending.BlendingFactors = new BlendingFactors(blendingSrcDropdown.Current.Value, blendingDestDropdown.Current.Value, 260 - blendingAlphaSrcDropdown.Current.Value, blendingAlphaDestDropdown.Current.Value); 260 + var blending = new BlendingParameters 261 + { 262 + Source = blendingSrcDropdown.Current.Value, 263 + Destination = blendingDestDropdown.Current.Value, 264 + SourceAlpha = blendingAlphaSrcDropdown.Current.Value, 265 + DestinationAlpha = blendingAlphaDestDropdown.Current.Value, 266 + RGBEquation = colourEquation.Current.Value, 267 + AlphaEquation = alphaEquation.Current.Value 268 + }; 269 + 270 + Logger.Log("Changed blending mode to: " + blending, LoggingTarget.Runtime, LogLevel.Debug); 271 + 272 + foregroundContainer.Blending = blending; 261 273 262 274 inCustomMode = true; 263 275 } ··· 266 278 if (inCustomMode) 267 279 switchOffCustomBlending(); 268 280 269 - inCustomMode = false; 270 - } 281 + var blending = blendingModes[colourModeDropdown.Current.Value]; 282 + 283 + blending.RGBEquation = colourEquation.Current.Value; 284 + blending.AlphaEquation = alphaEquation.Current.Value; 271 285 272 - Logger.Log("Changed blending mode to: " + newBlending, LoggingTarget.Runtime, LogLevel.Debug); 286 + Logger.Log("Changed blending mode to: " + blending, LoggingTarget.Runtime, LogLevel.Debug); 273 287 274 - foregroundContainer.Blending = newBlending; 288 + foregroundContainer.Blending = blending; 289 + 290 + inCustomMode = false; 291 + } 275 292 } 276 293 277 294 private class GradientPart : Box
+249 -114
osu.Framework/Graphics/BlendingParameters.cs
··· 11 11 /// </summary> 12 12 public struct BlendingParameters : IEquatable<BlendingParameters> 13 13 { 14 - private BlendingFactors blendingFactors; 15 - private BlendingMode mode; 14 + #region Public Members 16 15 17 16 /// <summary> 18 - /// The blending factors that represent the current blending mode. 17 + /// The blending factor for the source color of the blend. 19 18 /// </summary> 20 - public BlendingFactors BlendingFactors 21 - { 22 - get => blendingFactors; 23 - set 24 - { 25 - blendingFactors = value; 26 - mode = BlendingMode.Custom; 27 - } 28 - } 19 + public BlendingType Source; 29 20 30 21 /// <summary> 31 - /// Gets or sets <see cref="BlendingMode"/> to use. 22 + /// The blending factor for the destination color of the blend. 32 23 /// </summary> 33 - public BlendingMode Mode 34 - { 35 - get => mode; 36 - set 37 - { 38 - mode = value; 39 - if (mode != BlendingMode.Custom) 40 - blendingFactors = new BlendingFactors(value); 41 - } 42 - } 24 + public BlendingType Destination; 25 + 26 + /// <summary> 27 + /// The blending factor for the source alpha of the blend. 28 + /// </summary> 29 + public BlendingType SourceAlpha; 30 + 31 + /// <summary> 32 + /// The blending factor for the destination alpha of the blend. 33 + /// </summary> 34 + public BlendingType DestinationAlpha; 43 35 44 36 /// <summary> 45 37 /// Gets or sets the <see cref="BlendingEquation"/> to use for the RGB components of the blend. ··· 51 43 /// </summary> 52 44 public BlendingEquation AlphaEquation; 53 45 46 + #endregion 47 + 48 + #region Default Blending Parameter Types 49 + 50 + public static BlendingParameters None => new BlendingParameters 51 + { 52 + Source = BlendingType.One, 53 + Destination = BlendingType.Zero, 54 + SourceAlpha = BlendingType.One, 55 + DestinationAlpha = BlendingType.Zero, 56 + RGBEquation = BlendingEquation.Add, 57 + AlphaEquation = BlendingEquation.Add, 58 + }; 59 + 60 + public static BlendingParameters Inherit => new BlendingParameters 61 + { 62 + Source = BlendingType.Inherit, 63 + Destination = BlendingType.Inherit, 64 + SourceAlpha = BlendingType.Inherit, 65 + DestinationAlpha = BlendingType.Inherit, 66 + RGBEquation = BlendingEquation.Inherit, 67 + AlphaEquation = BlendingEquation.Inherit, 68 + }; 69 + 70 + public static BlendingParameters Mixture => new BlendingParameters 71 + { 72 + Source = BlendingType.SrcAlpha, 73 + Destination = BlendingType.OneMinusSrcAlpha, 74 + SourceAlpha = BlendingType.One, 75 + DestinationAlpha = BlendingType.One, 76 + RGBEquation = BlendingEquation.Add, 77 + AlphaEquation = BlendingEquation.Add, 78 + }; 79 + 80 + public static BlendingParameters Additive => new BlendingParameters 81 + { 82 + Source = BlendingType.SrcAlpha, 83 + Destination = BlendingType.One, 84 + SourceAlpha = BlendingType.One, 85 + DestinationAlpha = BlendingType.One, 86 + RGBEquation = BlendingEquation.Add, 87 + AlphaEquation = BlendingEquation.Add, 88 + }; 89 + 90 + #endregion 91 + 92 + #region GL Type Getters 93 + 54 94 /// <summary> 55 95 /// Gets the <see cref="BlendEquationMode"/> for the currently specified RGB Equation. 56 96 /// </summary> ··· 61 101 /// </summary> 62 102 public BlendEquationMode AlphaEquationMode => translateEquation(AlphaEquation); 63 103 104 + /// <summary> 105 + /// Gets the <see cref="BlendingFactorSrc"/> for the currently specified source blending mode. 106 + /// </summary> 107 + public BlendingFactorSrc SourceBlendingFactor => translateBlendingFactorSrc(Source); 108 + 109 + /// <summary> 110 + /// Gets the <see cref="BlendingFactorDest"/> for the currently specified destination blending mode. 111 + /// </summary> 112 + public BlendingFactorDest DestinationBlendingFactor => translateBlendingFactorDest(Destination); 113 + 114 + /// <summary> 115 + /// Gets the <see cref="BlendingFactorSrc"/> for the currently specified source alpha mode. 116 + /// </summary> 117 + public BlendingFactorSrc SourceAlphaBlendingFactor => translateBlendingFactorSrc(SourceAlpha); 118 + 119 + /// <summary> 120 + /// Gets the <see cref="BlendingFactorDest"/> for the currently specified destination alpha mode. 121 + /// </summary> 122 + public BlendingFactorDest DestinationAlphaBlendingFactor => translateBlendingFactorDest(DestinationAlpha); 123 + 124 + private static BlendingFactorSrc translateBlendingFactorSrc(BlendingType factor) 125 + { 126 + switch (factor) 127 + { 128 + case BlendingType.ConstantAlpha: 129 + return BlendingFactorSrc.ConstantAlpha; 130 + 131 + case BlendingType.ConstantColor: 132 + return BlendingFactorSrc.ConstantColor; 133 + 134 + case BlendingType.DstAlpha: 135 + return BlendingFactorSrc.DstAlpha; 136 + 137 + case BlendingType.DstColor: 138 + return BlendingFactorSrc.DstColor; 139 + 140 + case BlendingType.One: 141 + return BlendingFactorSrc.One; 142 + 143 + case BlendingType.OneMinusConstantAlpha: 144 + return BlendingFactorSrc.OneMinusConstantAlpha; 145 + 146 + case BlendingType.OneMinusConstantColor: 147 + return BlendingFactorSrc.OneMinusConstantColor; 148 + 149 + case BlendingType.OneMinusDstAlpha: 150 + return BlendingFactorSrc.OneMinusDstAlpha; 151 + 152 + case BlendingType.OneMinusDstColor: 153 + return BlendingFactorSrc.OneMinusDstColor; 154 + 155 + case BlendingType.OneMinusSrcAlpha: 156 + return BlendingFactorSrc.OneMinusSrcColor; 157 + 158 + case BlendingType.SrcAlpha: 159 + return BlendingFactorSrc.SrcAlpha; 160 + 161 + case BlendingType.SrcAlphaSaturate: 162 + return BlendingFactorSrc.SrcAlphaSaturate; 163 + 164 + case BlendingType.SrcColor: 165 + return BlendingFactorSrc.SrcColor; 166 + 167 + default: 168 + case BlendingType.Zero: 169 + return BlendingFactorSrc.Zero; 170 + } 171 + } 172 + 173 + private static BlendingFactorDest translateBlendingFactorDest(BlendingType factor) 174 + { 175 + switch (factor) 176 + { 177 + case BlendingType.ConstantAlpha: 178 + return BlendingFactorDest.ConstantAlpha; 179 + 180 + case BlendingType.ConstantColor: 181 + return BlendingFactorDest.ConstantColor; 182 + 183 + case BlendingType.DstAlpha: 184 + return BlendingFactorDest.DstAlpha; 185 + 186 + case BlendingType.DstColor: 187 + return BlendingFactorDest.DstColor; 188 + 189 + case BlendingType.One: 190 + return BlendingFactorDest.One; 191 + 192 + case BlendingType.OneMinusConstantAlpha: 193 + return BlendingFactorDest.OneMinusConstantAlpha; 194 + 195 + case BlendingType.OneMinusConstantColor: 196 + return BlendingFactorDest.OneMinusConstantColor; 197 + 198 + case BlendingType.OneMinusDstAlpha: 199 + return BlendingFactorDest.OneMinusDstAlpha; 200 + 201 + case BlendingType.OneMinusDstColor: 202 + return BlendingFactorDest.OneMinusDstColor; 203 + 204 + case BlendingType.OneMinusSrcAlpha: 205 + return BlendingFactorDest.OneMinusSrcAlpha; 206 + 207 + case BlendingType.OneMinusSrcColor: 208 + return BlendingFactorDest.OneMinusSrcColor; 209 + 210 + case BlendingType.SrcAlpha: 211 + return BlendingFactorDest.SrcAlpha; 212 + 213 + case BlendingType.SrcAlphaSaturate: 214 + return BlendingFactorDest.SrcAlphaSaturate; 215 + 216 + case BlendingType.SrcColor: 217 + return BlendingFactorDest.SrcColor; 218 + 219 + default: 220 + case BlendingType.Zero: 221 + return BlendingFactorDest.Zero; 222 + } 223 + } 224 + 64 225 private static BlendEquationMode translateEquation(BlendingEquation blendingEquation) 65 226 { 66 227 switch (blendingEquation) ··· 84 245 } 85 246 } 86 247 87 - public BlendingParameters(BlendingMode mode) 248 + #endregion 249 + 250 + /// <summary> 251 + /// Copy all properties that are marked as inherited from a parent <see cref="BlendingParameters"/> object. 252 + /// </summary> 253 + /// <param name="parent">The parent <see cref="BlendingParameters"/> from which to copy inherited properties.</param> 254 + public void CopyFromParent(BlendingParameters parent) 88 255 { 89 - RGBEquation = default; 90 - AlphaEquation = default; 91 - blendingFactors = new BlendingFactors(mode); 92 - this.mode = mode; 93 - } 256 + if (Source == BlendingType.Inherit) 257 + Source = parent.Source; 258 + 259 + if (Destination == BlendingType.Inherit) 260 + Destination = parent.Destination; 94 261 95 - public static implicit operator BlendingParameters(BlendingMode blendingMode) => new BlendingParameters { Mode = blendingMode }; 262 + if (SourceAlpha == BlendingType.Inherit) 263 + SourceAlpha = parent.SourceAlpha; 96 264 97 - public static implicit operator BlendingParameters(BlendingEquation blendingEquation) => new BlendingParameters 98 - { 99 - RGBEquation = blendingEquation, 100 - AlphaEquation = blendingEquation 101 - }; 265 + if (DestinationAlpha == BlendingType.Inherit) 266 + DestinationAlpha = parent.DestinationAlpha; 102 267 103 - public bool IsDisabled => 104 - BlendingFactors.IsDisabled 105 - && RGBEquation == BlendingEquation.Add 106 - && AlphaEquation == BlendingEquation.Add; 268 + if (RGBEquation == BlendingEquation.Inherit) 269 + RGBEquation = parent.RGBEquation; 107 270 108 - public bool Equals(BlendingParameters other) => 109 - other.BlendingFactors.Equals(BlendingFactors) 110 - && other.RGBEquation == RGBEquation 111 - && other.AlphaEquation == AlphaEquation; 271 + if (AlphaEquation == BlendingEquation.Inherit) 272 + AlphaEquation = parent.AlphaEquation; 273 + } 112 274 113 - public override string ToString() => $"BlendingParameter Mode: {Mode} BlendingFactor: {BlendingFactors} RGBEquation: {RGBEquation} AlphaEquation: {AlphaEquation}"; 114 - } 275 + /// <summary> 276 + /// Any properties marked as inherited will have their blending mode changed to the default type. This can occur when a root element is set to inherited. 277 + /// </summary> 278 + public void ApplyDefaultToInherited() 279 + { 280 + if (Source == BlendingType.Inherit) 281 + Source = BlendingType.SrcAlpha; 115 282 116 - public struct BlendingFactors : IEquatable<BlendingFactors> 117 - { 118 - public readonly BlendingFactorSrc Source; 119 - public readonly BlendingFactorDest Destination; 120 - public readonly BlendingFactorSrc SourceAlpha; 121 - public readonly BlendingFactorDest DestinationAlpha; 283 + if (Destination == BlendingType.Inherit) 284 + Destination = BlendingType.OneMinusSrcAlpha; 122 285 123 - public BlendingFactors(BlendingMode mode) 124 - { 125 - switch (mode) 126 - { 127 - case BlendingMode.Custom: 128 - case BlendingMode.Inherit: 129 - case BlendingMode.Mixture: 130 - Source = BlendingFactorSrc.SrcAlpha; 131 - Destination = BlendingFactorDest.OneMinusSrcAlpha; 132 - SourceAlpha = BlendingFactorSrc.One; 133 - DestinationAlpha = BlendingFactorDest.One; 134 - break; 286 + if (SourceAlpha == BlendingType.Inherit) 287 + SourceAlpha = BlendingType.One; 135 288 136 - case BlendingMode.Additive: 137 - Source = BlendingFactorSrc.SrcAlpha; 138 - Destination = BlendingFactorDest.One; 139 - SourceAlpha = BlendingFactorSrc.One; 140 - DestinationAlpha = BlendingFactorDest.One; 141 - break; 289 + if (DestinationAlpha == BlendingType.Inherit) 290 + DestinationAlpha = BlendingType.One; 142 291 143 - default: 144 - Source = BlendingFactorSrc.One; 145 - Destination = BlendingFactorDest.Zero; 146 - SourceAlpha = BlendingFactorSrc.One; 147 - DestinationAlpha = BlendingFactorDest.Zero; 148 - break; 149 - } 150 - } 292 + if (RGBEquation == BlendingEquation.Inherit) 293 + RGBEquation = BlendingEquation.Add; 151 294 152 - public BlendingFactors(BlendingFactorSrc source, BlendingFactorDest destination, BlendingFactorSrc sourceAlpha, BlendingFactorDest destinationAlpha) 153 - { 154 - Source = source; 155 - Destination = destination; 156 - SourceAlpha = sourceAlpha; 157 - DestinationAlpha = destinationAlpha; 295 + if (AlphaEquation == BlendingEquation.Inherit) 296 + AlphaEquation = BlendingEquation.Add; 158 297 } 159 298 160 - public bool Equals(BlendingFactors other) => 299 + public bool Equals(BlendingParameters other) => 161 300 other.Source == Source 162 301 && other.Destination == Destination 163 302 && other.SourceAlpha == SourceAlpha 164 - && other.DestinationAlpha == DestinationAlpha; 303 + && other.DestinationAlpha == DestinationAlpha 304 + && other.RGBEquation == RGBEquation 305 + && other.AlphaEquation == AlphaEquation; 165 306 166 307 public bool IsDisabled => 167 - Source == BlendingFactorSrc.One 168 - && Destination == BlendingFactorDest.Zero 169 - && SourceAlpha == BlendingFactorSrc.One 170 - && DestinationAlpha == BlendingFactorDest.Zero; 308 + Source == BlendingType.One 309 + && Destination == BlendingType.Zero 310 + && SourceAlpha == BlendingType.One 311 + && DestinationAlpha == BlendingType.Zero 312 + && RGBEquation == BlendingEquation.Add 313 + && AlphaEquation == BlendingEquation.Add; 171 314 172 - public override string ToString() => $"{Source}/{Destination}/{SourceAlpha}/{DestinationAlpha}"; 315 + public override string ToString() => $"BlendingParameter: Factor: {Source}/{Destination}/{SourceAlpha}/{DestinationAlpha} RGBEquation: {RGBEquation} AlphaEquation: {AlphaEquation}"; 173 316 } 174 317 175 - public enum BlendingMode 318 + public enum BlendingType 176 319 { 177 - /// <summary> 178 - /// Inherits from parent. 179 - /// </summary> 180 320 Inherit = 0, 181 - 182 - /// <summary> 183 - /// Mixes with existing colour by a factor of the colour's alpha. 184 - /// </summary> 185 - Mixture, 186 - 187 - /// <summary> 188 - /// Purely additive (by a factor of the colour's alpha) blending. 189 - /// </summary> 190 - Additive, 191 - 192 - /// <summary> 193 - /// The blending mode will be manually provided. 194 - /// </summary> 195 - Custom, 196 - 197 - /// <summary> 198 - /// No alpha blending whatsoever. 199 - /// </summary> 200 - None, 321 + ConstantAlpha, 322 + ConstantColor, 323 + DstAlpha, 324 + DstColor, 325 + One, 326 + OneMinusConstantAlpha, 327 + OneMinusConstantColor, 328 + OneMinusDstAlpha, 329 + OneMinusDstColor, 330 + OneMinusSrcAlpha, 331 + OneMinusSrcColor, 332 + SrcAlpha, 333 + SrcAlphaSaturate, 334 + SrcColor, 335 + Zero 201 336 } 202 337 203 338 public enum BlendingEquation
+5 -15
osu.Framework/Graphics/Containers/BufferedContainer.cs
··· 119 119 } 120 120 } 121 121 122 - private BlendingParameters effectBlending; 122 + private BlendingParameters effectBlending = BlendingParameters.Inherit; 123 123 124 124 /// <summary> 125 - /// The <see cref="BlendingParameters"/> to use after applying all effects. Default is <see cref="BlendingMode.Inherit"/>. 126 - /// <see cref="BlendingMode.Inherit"/> inherits the blending mode of the original, i.e. <see cref="Drawable.Blending"/> is used. 125 + /// The <see cref="BlendingParameters"/> to use after applying all effects. Default is <see cref="BlendingType.Inherit"/>. 126 + /// <see cref="BlendingType.Inherit"/> inherits the blending mode of the original, i.e. <see cref="Drawable.Blending"/> is used. 127 127 /// Does not affect the original which is drawn when <see cref="DrawOriginal"/> is true. 128 128 /// </summary> 129 129 public BlendingParameters EffectBlending ··· 287 287 { 288 288 BlendingParameters blending = EffectBlending; 289 289 290 - if (blending.Mode == BlendingMode.Inherit) 291 - { 292 - blending.Mode = Blending.Mode; 293 - if (Blending.Mode == BlendingMode.Custom) 294 - blending.BlendingFactors = Blending.BlendingFactors; //in custom mode we also need to copy blending factor 295 - } 296 - 297 - if (blending.RGBEquation == BlendingEquation.Inherit) 298 - blending.RGBEquation = Blending.RGBEquation; 299 - 300 - if (blending.AlphaEquation == BlendingEquation.Inherit) 301 - blending.AlphaEquation = Blending.AlphaEquation; 290 + blending.CopyFromParent(Blending); 291 + blending.ApplyDefaultToInherited(); 302 292 303 293 return blending; 304 294 }
+1 -1
osu.Framework/Graphics/Containers/BufferedContainer_DrawNode.cs
··· 97 97 FrameBuffer current = SharedData.CurrentEffectBuffer; 98 98 FrameBuffer target = SharedData.GetNextEffectBuffer(); 99 99 100 - GLWrapper.SetBlend(new BlendingParameters(BlendingMode.None)); 100 + GLWrapper.SetBlend(BlendingParameters.None); 101 101 102 102 using (BindFrameBuffer(target)) 103 103 {
+1 -1
osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs
··· 134 134 135 135 GLWrapper.PushMaskingInfo(edgeEffectMaskingInfo); 136 136 137 - GLWrapper.SetBlend(new BlendingParameters(edgeEffect.Type == EdgeEffectType.Glow ? BlendingMode.Additive : BlendingMode.Mixture)); 137 + GLWrapper.SetBlend(edgeEffect.Type == EdgeEffectType.Glow ? BlendingParameters.Additive : BlendingParameters.Mixture); 138 138 139 139 Shader.Bind(); 140 140
+1 -1
osu.Framework/Graphics/DrawColourInfo.cs
··· 15 15 public DrawColourInfo(ColourInfo? colour = null, BlendingParameters? blending = null) 16 16 { 17 17 Colour = colour ?? ColourInfo.SingleColour(Color4.White); 18 - Blending = blending ?? new BlendingParameters(BlendingMode.Inherit); 18 + Blending = blending ?? BlendingParameters.Inherit; 19 19 } 20 20 21 21 public bool Equals(DrawColourInfo other) => Colour.Equals(other.Colour) && Blending.Equals(other.Blending);
+2 -14
osu.Framework/Graphics/Drawable.cs
··· 1556 1556 BlendingParameters localBlending = Blending; 1557 1557 1558 1558 if (Parent != null) 1559 - { 1560 - if (localBlending.Mode == BlendingMode.Inherit) 1561 - { 1562 - localBlending.Mode = Parent.Blending.Mode; 1563 - 1564 - if (Parent.Blending.Mode == BlendingMode.Custom) 1565 - localBlending.BlendingFactors = Parent.Blending.BlendingFactors; //copy blending settings from parent if custom 1566 - } 1567 - 1568 - if (localBlending.RGBEquation == BlendingEquation.Inherit) 1569 - localBlending.RGBEquation = Parent.Blending.RGBEquation; 1559 + localBlending.CopyFromParent(Parent.Blending); 1570 1560 1571 - if (localBlending.AlphaEquation == BlendingEquation.Inherit) 1572 - localBlending.AlphaEquation = Parent.Blending.AlphaEquation; 1573 - } 1561 + localBlending.ApplyDefaultToInherited(); 1574 1562 1575 1563 ci.Blending = localBlending; 1576 1564
+1 -1
osu.Framework/Graphics/Effects/GlowEffect.cs
··· 31 31 /// <summary> 32 32 /// The blending mode of the glow. Default is additive. 33 33 /// </summary> 34 - public BlendingParameters Blending = BlendingMode.Additive; 34 + public BlendingParameters Blending = BlendingParameters.Additive; 35 35 36 36 /// <summary> 37 37 /// Whether to draw the glow <see cref="EffectPlacement.InFront"/> or <see cref="EffectPlacement.Behind"/> the glowing
+1 -1
osu.Framework/Graphics/Lines/Path_DrawNode.cs
··· 211 211 GLWrapper.PushDepthInfo(DepthInfo.Default); 212 212 213 213 // Blending is removed to allow for correct blending between the wedges of the path. 214 - GLWrapper.SetBlend(new BlendingParameters(BlendingMode.None)); 214 + GLWrapper.SetBlend(BlendingParameters.None); 215 215 216 216 pathShader.Bind(); 217 217
+2 -2
osu.Framework/Graphics/OpenGL/GLWrapper.cs
··· 340 340 lastBlendingEnabledState = true; 341 341 342 342 GL.BlendEquationSeparate(blendingParameters.RGBEquationMode, blendingParameters.AlphaEquationMode); 343 - GL.BlendFuncSeparate(blendingParameters.BlendingFactors.Source, blendingParameters.BlendingFactors.Destination, 344 - blendingParameters.BlendingFactors.SourceAlpha, blendingParameters.BlendingFactors.DestinationAlpha); 343 + GL.BlendFuncSeparate(blendingParameters.SourceBlendingFactor, blendingParameters.DestinationBlendingFactor, 344 + blendingParameters.SourceAlphaBlendingFactor, blendingParameters.DestinationAlphaBlendingFactor); 345 345 } 346 346 347 347 lastBlendingParameters = blendingParameters;
+1 -1
osu.Framework/Graphics/Shapes/Box.cs
··· 60 60 conservativeScreenSpaceDrawQuad = Source.conservativeScreenSpaceDrawQuad; 61 61 62 62 hasOpaqueInterior = DrawColourInfo.Colour.MinAlpha == 1 63 - && DrawColourInfo.Blending.Equals(new BlendingParameters(BlendingMode.Mixture)) 63 + && DrawColourInfo.Blending.Equals(BlendingParameters.Mixture) 64 64 && DrawColourInfo.Colour.HasSingleColour; 65 65 } 66 66
+1 -1
osu.Framework/Graphics/UserInterface/Button.cs
··· 76 76 Add(flash); 77 77 78 78 flash.Colour = Background.Colour; 79 - flash.Blending = BlendingMode.Additive; 79 + flash.Blending = BlendingParameters.Additive; 80 80 flash.FadeOutFromOne(200); 81 81 flash.Expire(); 82 82 }
+1 -1
osu.Framework/Testing/Drawables/Steps/StepSlider.cs
··· 72 72 { 73 73 RelativeSizeAxes = Axes.Both, 74 74 Colour = Color4.RoyalBlue, 75 - Blending = BlendingMode.Additive, 75 + Blending = BlendingParameters.Additive, 76 76 Alpha = 0.6f, 77 77 }; 78 78