1 /* 2 ******************************************************************************************* 3 * Dgame (a D game framework) - Copyright (c) Randy Schütt 4 * 5 * This software is provided 'as-is', without any express or implied warranty. 6 * In no event will the authors be held liable for any damages arising from 7 * the use of this software. 8 * 9 * Permission is granted to anyone to use this software for any purpose, 10 * including commercial applications, and to alter it and redistribute it 11 * freely, subject to the following restrictions: 12 * 13 * 1. The origin of this software must not be misrepresented; you must not claim 14 * that you wrote the original software. If you use this software in a product, 15 * an acknowledgment in the product documentation would be appreciated but is 16 * not required. 17 * 18 * 2. Altered source versions must be plainly marked as such, and must not be 19 * misrepresented as being the original software. 20 * 21 * 3. This notice may not be removed or altered from any source distribution. 22 ******************************************************************************************* 23 */ 24 module Dgame.Graphic.Blend; 25 26 import derelict.opengl3.gl; 27 28 /** 29 * The Blending struct enables the use of OpenGl Blending 30 * 31 * Author: Randy Schuett (rswhite4@googlemail.com) 32 */ 33 struct Blend { 34 /** 35 * Both Factors (destination and source) are Factor.One 36 */ 37 static immutable Blend One = Blend(Factor.One, Factor.One); 38 /** 39 * Both Factors (destination and source) are Factor.Zero 40 */ 41 static immutable Blend Zero = Blend(Factor.Zero, Factor.Zero); 42 /** 43 * source is Factor.SrcAlpha and destination is Factor.OneMinusSrcAlpha 44 * This is the default Blending in Dgame 45 */ 46 static immutable Blend Default = Blend(Factor.SrcAlpha, Factor.OneMinusSrcAlpha); 47 48 /** 49 * The Factor enum 50 */ 51 enum Factor { 52 Zero = GL_ZERO, /// 53 One = GL_ONE, /// 54 SrcColor = GL_SRC_COLOR, /// 55 OneMinusSrcColor = GL_ONE_MINUS_SRC_COLOR, /// 56 DstColor = GL_DST_COLOR, /// 57 OneMinusDstColor = GL_ONE_MINUS_DST_COLOR, /// 58 SrcAlpha = GL_SRC_ALPHA, /// 59 OneMinusSrcAlpha = GL_ONE_MINUS_SRC_ALPHA, /// 60 DstAlpha = GL_DST_ALPHA, /// 61 OneMinusDstAlpha = GL_ONE_MINUS_DST_ALPHA /// 62 } 63 64 /** 65 * The source color Factor 66 */ 67 Factor srcColor = Factor.One; 68 /** 69 * The destination color Factor 70 */ 71 Factor dstColor = Factor.Zero; 72 73 /** 74 * Apply the Blending 75 */ 76 @nogc 77 void apply() const nothrow { 78 glBlendFunc(this.srcColor, this.dstColor); 79 } 80 }