1 module nudsfml.graphics.renderstates; 2 3 import nudsfml.graphics.blendmode; 4 import nudsfml.graphics.transform; 5 import nudsfml.graphics.texture; 6 import nudsfml.graphics.shader; 7 import std.typecons:Rebindable; 8 9 /** 10 * Define the states used for drawing to a RenderTarget. 11 */ 12 struct RenderStates { 13 /// The blending mode. 14 BlendMode blendMode; 15 /// The transform. 16 Transform transform; 17 private { 18 Rebindable!(const(Texture)) m_texture; 19 Rebindable!(const(Shader)) m_shader; 20 } 21 22 /** 23 * Construct a default set of render states with a custom blend mode. 24 * 25 * Params: 26 * theBlendMode = Blend mode to use 27 */ 28 this(BlendMode theBlendMode) { 29 blendMode = theBlendMode; 30 transform = Transform(); 31 32 m_texture = null; 33 m_shader = null; 34 } 35 36 /** 37 * Construct a default set of render states with a custom transform. 38 * 39 * Params: 40 * theTransform = Transform to use 41 */ 42 this(Transform theTransform) { 43 transform = theTransform; 44 45 blendMode = BlendMode.Alpha; 46 47 m_texture = null; 48 m_shader = null; 49 } 50 51 /** 52 * Construct a default set of render states with a custom texture 53 * 54 * Params: 55 * theTexture = Texture to use 56 */ 57 this(const(Texture) theTexture) { 58 m_texture = theTexture; 59 60 blendMode = BlendMode.Alpha; 61 62 transform = Transform(); 63 m_shader = null; 64 } 65 66 /** 67 * Construct a default set of render states with a custom shader 68 * 69 * Params: 70 * theShader = Shader to use 71 */ 72 this(const(Shader) theShader) { 73 m_shader = theShader; 74 } 75 76 /** 77 * Construct a set of render states with all its attributes 78 * 79 * Params: 80 * theBlendMode = Blend mode to use 81 * theTransform = Transform to use 82 * theTexture = Texture to use 83 * theShader = Shader to use 84 */ 85 this(BlendMode theBlendMode, Transform theTransform, const(Texture) theTexture, const(Shader) theShader) { 86 blendMode = theBlendMode; 87 transform = theTransform; 88 m_texture = theTexture; 89 m_shader = theShader; 90 } 91 92 @property { 93 /// The shader to apply while rendering. 94 const(Shader) shader(const(Shader) theShader) { 95 m_shader = theShader; 96 return theShader; 97 } 98 99 /// ditto 100 const(Shader) shader() const { 101 return m_shader; 102 } 103 } 104 105 @property { 106 /// The texture to apply while rendering. 107 const(Texture) texture(const(Texture) theTexture) { 108 m_texture = theTexture; 109 return theTexture; 110 } 111 112 /// ditto 113 const(Texture) texture() const{ 114 return m_texture; 115 } 116 } 117 }