1 /** 2 Inochi2D Render State 3 4 Copyright: 5 Copyright © 2020-2026, Inochi2D Project 6 7 License: 8 $(LINK2 https://github.com/Inochi2D/inochi2d/blob/main/LICENSE, BSD 2-clause License) 9 10 Authors: 11 Luna Nielsen 12 */ 13 module inochi2d.core.render.state; 14 import numath; 15 16 /* 17 INFORMATION ABOUT BLENDING MODES 18 Blending is a complicated topic, especially once we get to mobile devices and games consoles. 19 20 The following blending modes are supported in Standard mode: 21 Normal 22 Multiply 23 Screen 24 Overlay 25 Darken 26 Lighten 27 Color Dodge 28 Linear Dodge 29 Add (Glow) 30 Color Burn 31 Hard Light 32 Soft Light 33 Difference 34 Exclusion 35 Subtract 36 Inverse 37 Destination In 38 Clip To Lower 39 Slice from Lower 40 Some of these blending modes behave better on Tiling GPUs. 41 42 The following blending modes are supported in Core mode: 43 Normal 44 Multiply 45 Screen 46 Lighten 47 Color Dodge 48 Linear Dodge 49 Add (Glow) 50 Inverse 51 Destination In 52 Clip to Lower 53 Slice from Lower 54 Tiling GPUs on older mobile devices don't have great drivers, we shouldn't tempt fate. 55 */ 56 57 /** 58 Blending modes 59 */ 60 enum BlendMode : uint { 61 // Normal blending mode 62 normal = 0x00, 63 64 // Multiply blending mode 65 multiply = 0x01, 66 67 // Screen 68 screen = 0x02, 69 70 // Overlay 71 overlay = 0x03, 72 73 // Darken 74 darken = 0x04, 75 76 // Lighten 77 lighten = 0x05, 78 79 // Color Dodge 80 colorDodge = 0x06, 81 82 // Linear Dodge 83 linearDodge = 0x07, 84 85 // Add (Glow) 86 addGlow = 0x08, 87 88 // Color Burn 89 colorBurn = 0x09, 90 91 // Hard Light 92 hardLight = 0x0A, 93 94 // Soft Light 95 softLight = 0x0B, 96 97 // Difference 98 difference = 0x0C, 99 100 // Exclusion 101 exclusion = 0x0D, 102 103 // Subtract 104 subtract = 0x0E, 105 106 // Inverse 107 inverse = 0x0F, 108 109 // Destination In 110 destinationIn = 0x10, 111 112 // Clip to Lower 113 // Special blending mode that clips the drawable 114 // to a lower rendered area. 115 sourceIn = 0x11, 116 117 // Slice from Lower 118 // Special blending mode that slices the drawable 119 // via a lower rendered area. 120 // Basically inverse ClipToLower 121 sourceOut = 0x12 122 } 123 124 BlendMode toBlendMode(string name) @nogc { 125 switch (name) with (BlendMode) { 126 default: 127 return normal; 128 case "Multiply": 129 return multiply; 130 case "Screen": 131 return screen; 132 case "Overlay": 133 return overlay; 134 case "Darken": 135 return darken; 136 case "Lighten": 137 return lighten; 138 case "ColorDodge": 139 return colorDodge; 140 case "LinearDodge": 141 return linearDodge; 142 case "AddGlow": 143 return addGlow; 144 case "ColorBurn": 145 return colorBurn; 146 case "HardLight": 147 return hardLight; 148 case "SoftLight": 149 return softLight; 150 case "Difference": 151 return difference; 152 case "Exclusion": 153 return exclusion; 154 case "Subtract": 155 return subtract; 156 case "Inverse": 157 return inverse; 158 case "DestinationIn": 159 return destinationIn; 160 case "ClipToLower": 161 return sourceIn; 162 case "SliceFromLower": 163 return sourceOut; 164 } 165 } 166 167 /** 168 Masking mode flags, used to tell the renderer how to render 169 a visual. 170 */ 171 enum MaskingMode : uint { 172 173 /** 174 The part should be masked by the drawables specified 175 */ 176 mask = 0, 177 178 /** 179 The path should be dodge masked by the drawables specified 180 */ 181 dodge = 1, 182 } 183 184 MaskingMode toMaskingMode(string name) @nogc { 185 switch (name) { 186 187 case "Mask": 188 case "mask": 189 return MaskingMode.mask; 190 191 case "DodgeMask": 192 case "dodgeMask": 193 return MaskingMode.dodge; 194 195 default: 196 return MaskingMode.mask; 197 } 198 }