1 /* 2 Inochi2D Common Data 3 4 Copyright © 2020, Inochi2D Project 5 Distributed under the 2-Clause BSD License, see LICENSE file. 6 7 Authors: Luna Nielsen 8 */ 9 module inochi2d.core.nodes.common; 10 import bindbc.opengl; 11 import inochi2d.fmt.serialize; 12 13 /** 14 Blending modes 15 */ 16 enum BlendMode { 17 // Normal blending mode 18 Normal, 19 20 // Multiply blending mode 21 Multiply, 22 23 // Color Dodge 24 ColorDodge, 25 26 // Linear Dodge 27 LinearDodge, 28 29 // Screen 30 Screen, 31 32 // Clip to Lower 33 // Special blending mode that clips the drawable 34 // to a lower rendered area. 35 ClipToLower, 36 37 // Slice from Lower 38 // Special blending mode that slices the drawable 39 // via a lower rendered area. 40 // Basically inverse ClipToLower 41 SliceFromLower 42 } 43 44 void inSetBlendMode(BlendMode blendingMode) { 45 switch(blendingMode) { 46 case BlendMode.Normal: 47 glBlendEquation(GL_FUNC_ADD); 48 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); break; 49 case BlendMode.Multiply: 50 glBlendEquation(GL_FUNC_ADD); 51 glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); break; 52 case BlendMode.ColorDodge: 53 glBlendEquation(GL_FUNC_ADD); 54 glBlendFunc(GL_DST_COLOR, GL_ONE); break; 55 case BlendMode.LinearDodge: 56 glBlendEquation(GL_FUNC_ADD); 57 glBlendFunc(GL_ONE, GL_ONE); break; 58 case BlendMode.Screen: 59 glBlendEquation(GL_FUNC_ADD); 60 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR); break; 61 case BlendMode.ClipToLower: 62 glBlendEquation(GL_FUNC_ADD); 63 glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA); break; 64 case BlendMode.SliceFromLower: 65 glBlendEquation(GL_FUNC_SUBTRACT); 66 glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA); break; 67 default: assert(0); 68 } 69 } 70 71 /** 72 Masking mode 73 */ 74 enum MaskingMode { 75 76 /** 77 The part should be masked by the drawables specified 78 */ 79 Mask, 80 81 /** 82 The path should be dodge masked by the drawables specified 83 */ 84 DodgeMask 85 } 86 87 /** 88 A binding between a mask and a mode 89 */ 90 struct MaskBinding { 91 public: 92 import inochi2d.core.nodes.drawable : Drawable; 93 @Name("source") 94 uint maskSrcUUID; 95 96 @Name("mode") 97 MaskingMode mode; 98 99 @Ignore 100 Drawable maskSrc; 101 }