-
Notifications
You must be signed in to change notification settings - Fork 1
/
renderStates.go
125 lines (106 loc) · 4.19 KB
/
renderStates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright (C) 2012-2014 by krepa098. All rights reserved.
// Use of this source code is governed by a zlib-style
// license that can be found in the license.txt file.
package gosfml2
// #include <SFML/Graphics/RenderStates.h>
import "C"
/////////////////////////////////////
/// CONSTS
/////////////////////////////////////
// Blend equations
const (
EquationAdd BlendEquation = C.sfBlendEquationAdd
EquationSubtract BlendEquation = C.sfBlendEquationSubtract
)
type BlendEquation C.sfBlendEquation
// Blend factors
const (
FactorZero BlendFactor = C.sfBlendFactorZero ///< (0, 0, 0, 0)
FactorOne BlendFactor = C.sfBlendFactorOne ///< (1, 1, 1, 1)
FactorSrcColor BlendFactor = C.sfBlendFactorSrcColor ///< (src.r, src.g, src.b, src.a)
FactorOneMinusSrcColor BlendFactor = C.sfBlendFactorOneMinusSrcColor ///< (1, 1, 1, 1) - (src.r, src.g, src.b, src.a)
FactorDstColor BlendFactor = C.sfBlendFactorDstColor ///< (dst.r, dst.g, dst.b, dst.a)
FactorOneMinusDstColor BlendFactor = C.sfBlendFactorOneMinusDstColor ///< (1, 1, 1, 1) - (dst.r, dst.g, dst.b, dst.a)
FactorSrcAlpha BlendFactor = C.sfBlendFactorSrcAlpha ///< (src.a, src.a, src.a, src.a)
FactorOneMinusSrcAlpha BlendFactor = C.sfBlendFactorOneMinusSrcAlpha ///< (1, 1, 1, 1) - (src.a, src.a, src.a, src.a)
FactorDstAlpha BlendFactor = C.sfBlendFactorDstAlpha ///< (dst.a, dst.a, dst.a, dst.a)
FactorOneMinusDstAlpha BlendFactor = C.sfBlendFactorOneMinusDstAlpha ///< (1, 1, 1, 1) - (dst.a, dst.a, dst.a, dst.a)
)
type BlendFactor C.sfBlendFactor
var (
// Pixel = Src * a + Dest * (1 - a)
BlendAlpha = BlendMode{
ColorSrcFactor: FactorSrcAlpha,
ColorDstFactor: FactorOneMinusSrcAlpha,
ColorEquation: EquationAdd,
AlphaSrcFactor: FactorOne,
AlphaDstFactor: FactorOneMinusSrcAlpha,
AlphaEquation: EquationAdd,
}
// Pixel = Src + Dest
BlendAdd = BlendMode{
ColorSrcFactor: FactorSrcAlpha,
ColorDstFactor: FactorOne,
ColorEquation: EquationAdd,
AlphaSrcFactor: FactorOne,
AlphaDstFactor: FactorOne,
AlphaEquation: EquationAdd,
}
// Pixel = Src * Dest
BlendMultiply = BlendMode{
ColorSrcFactor: FactorDstColor,
ColorDstFactor: FactorZero,
ColorEquation: EquationAdd,
AlphaSrcFactor: FactorDstColor,
AlphaDstFactor: FactorZero,
AlphaEquation: EquationAdd,
}
// No blending
BlendNone = BlendMode{
ColorSrcFactor: FactorOne,
ColorDstFactor: FactorZero,
ColorEquation: EquationAdd,
AlphaSrcFactor: FactorOne,
AlphaDstFactor: FactorZero,
AlphaEquation: EquationAdd,
}
)
/////////////////////////////////////
/// STRUCTS
/////////////////////////////////////
type BlendMode struct {
ColorSrcFactor BlendFactor ///< Source blending factor for the color channels
ColorDstFactor BlendFactor ///< Destination blending factor for the color channels
ColorEquation BlendEquation ///< Blending equation for the color channels
AlphaSrcFactor BlendFactor ///< Source blending factor for the alpha channel
AlphaDstFactor BlendFactor ///< Destination blending factor for the alpha channel
AlphaEquation BlendEquation ///< Blending equation for the alpha channel
}
type RenderStates struct {
BlendMode BlendMode
Transform Transform
Shader *Shader
Texture *Texture
}
/////////////////////////////////////
/// FUNCS
/////////////////////////////////////
func DefaultRenderStates() RenderStates {
return RenderStates{Shader: nil, Texture: nil, BlendMode: BlendAlpha, Transform: TransformIdentity()}
}
/////////////////////////////////////
/// GO <-> C
/////////////////////////////////////
func (this *BlendMode) toC() C.sfBlendMode {
return C.sfBlendMode{
colorSrcFactor: C.sfBlendFactor(this.ColorSrcFactor),
colorDstFactor: C.sfBlendFactor(this.ColorDstFactor),
colorEquation: C.sfBlendEquation(this.ColorEquation),
alphaSrcFactor: C.sfBlendFactor(this.AlphaSrcFactor),
alphaDstFactor: C.sfBlendFactor(this.AlphaDstFactor),
alphaEquation: C.sfBlendEquation(this.AlphaEquation),
}
}
func (this *RenderStates) toC() C.sfRenderStates {
return C.sfRenderStates{blendMode: this.BlendMode.toC(), transform: this.Transform.toC(), texture: this.Texture.toCPtr(), shader: this.Shader.toCPtr()}
}