/
blendmode.go
126 lines (102 loc) · 4.96 KB
/
blendmode.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
126
package sdl
/*
#include "sdl_wrapper.h"
#if !(SDL_VERSION_ATLEAST(2,0,6))
#if defined(WARN_OUTDATED)
#pragma message("SDL_BLENDMODE_INVALID is not supported before SDL 2.0.6")
#endif
#define SDL_BLENDMODE_INVALID (0x7FFFFFFF)
#if defined(WARN_OUTDATED)
#pragma message("SDL_BlendOperation is not supported before SDL 2.0.6")
#endif
typedef enum
{
SDL_BLENDOPERATION_ADD = 0x1,
SDL_BLENDOPERATION_SUBTRACT = 0x2,
SDL_BLENDOPERATION_REV_SUBTRACT = 0x3,
SDL_BLENDOPERATION_MINIMUM = 0x4,
SDL_BLENDOPERATION_MAXIMUM = 0x5
} SDL_BlendOperation;
#if defined(WARN_OUTDATED)
#pragma message("SDL_BlendFactor is not supported before SDL 2.0.6")
#endif
typedef enum
{
SDL_BLENDFACTOR_ZERO = 0x1,
SDL_BLENDFACTOR_ONE = 0x2,
SDL_BLENDFACTOR_SRC_COLOR = 0x3,
SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR = 0x4,
SDL_BLENDFACTOR_SRC_ALPHA = 0x5,
SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA = 0x6,
SDL_BLENDFACTOR_DST_COLOR = 0x7,
SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR = 0x8,
SDL_BLENDFACTOR_DST_ALPHA = 0x9,
SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA = 0xA
} SDL_BlendFactor;
#if defined(WARN_OUTDATED)
#pragma message("SDL_ComposeCustomBlendMode is not supported before SDL 2.0.6")
#endif
SDL_BlendMode SDLCALL SDL_ComposeCustomBlendMode(SDL_BlendFactor srcColorFactor, SDL_BlendFactor dstColorFactor, SDL_BlendOperation colorOperation, SDL_BlendFactor srcAlphaFactor, SDL_BlendFactor dstAlphaFactor, SDL_BlendOperation alphaOperation)
{
return SDL_BLENDMODE_NONE;
}
#endif
*/
import "C"
import "unsafe"
// BlendMode is an enumeration of blend modes used in Render.Copy() and drawing operations.
// (https://wiki.libsdl.org/SDL_BlendMode)
type BlendMode uint32
const (
BLENDMODE_NONE = C.SDL_BLENDMODE_NONE // no blending
BLENDMODE_BLEND = C.SDL_BLENDMODE_BLEND // alpha blending
BLENDMODE_ADD = C.SDL_BLENDMODE_ADD // additive blending
BLENDMODE_MOD = C.SDL_BLENDMODE_MOD // color modulate
BLENDMODE_INVALID = C.SDL_BLENDMODE_INVALID
)
func (bm BlendMode) c() C.SDL_BlendMode {
return C.SDL_BlendMode(C.Uint32(bm))
}
func (bm *BlendMode) cptr() *C.SDL_BlendMode {
return (*C.SDL_BlendMode)(unsafe.Pointer(bm))
}
// BlendOperation is an enumeration of blend operations used when creating a custom blend mode with ComposeCustomBlendMode().
// (https://wiki.libsdl.org/SDL_BlendOperation)
type BlendOperation C.SDL_BlendOperation
const (
BLENDOPERATION_ADD = C.SDL_BLENDOPERATION_ADD
BLENDOPERATION_SUBTRACT = C.SDL_BLENDOPERATION_SUBTRACT
BLENDOPERATION_REV_SUBTRACT = C.SDL_BLENDOPERATION_REV_SUBTRACT
BLENDOPERATION_MINIMUM = C.SDL_BLENDOPERATION_MINIMUM
BLENDOPERATION_MAXIMUM = C.SDL_BLENDOPERATION_MAXIMUM
)
// BlendFactor is an enumeration of blend factors used when creating a custom blend mode with ComposeCustomBlendMode().
// (https://wiki.libsdl.org/SDL_BlendFactor)
type BlendFactor C.SDL_BlendFactor
const (
BLENDFACTOR_ZERO = C.SDL_BLENDFACTOR_ZERO // 0, 0, 0, 0
BLENDFACTOR_ONE = C.SDL_BLENDFACTOR_ONE // 1, 1, 1, 1
BLENDFACTOR_SRC_COLOR = C.SDL_BLENDFACTOR_SRC_COLOR // srcR, srcG, srcB, srcA
BLENDFACTOR_ONE_MINUS_SRC_COLOR = C.SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR // 1-srcR, 1-srcG, 1-srcB, 1-srcA
BLENDFACTOR_SRC_ALPHA = C.SDL_BLENDFACTOR_SRC_ALPHA // srcA, srcA, srcA, srcA
BLENDFACTOR_ONE_MINUS_SRC_ALPHA = C.SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA // 1-srcA, 1-srcA, 1-srcA, 1-srcA
BLENDFACTOR_DST_COLOR = C.SDL_BLENDFACTOR_DST_COLOR // dstR, dstG, dstB, dstA
BLENDFACTOR_ONE_MINUS_DST_COLOR = C.SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR // 1-dstR, 1-dstG, 1-dstB, 1-dstA
BLENDFACTOR_DST_ALPHA = C.SDL_BLENDFACTOR_DST_ALPHA // dstA, dstA, dstA, dstA
BLENDFACTOR_ONE_MINUS_DST_ALPHA = C.SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA // 1-dstA, 1-dstA, 1-dstA, 1-dstA
)
// ComposeCustomBlendMode creates a custom blend mode, which may or may not be supported by a given renderer
// The result of the blend mode operation will be:
// dstRGB = dstRGB * dstColorFactor colorOperation srcRGB * srcColorFactor
// and
// dstA = dstA * dstAlphaFactor alphaOperation srcA * srcAlphaFactor
// (https://wiki.libsdl.org/SDL_ComposeCustomBlendMode)
func ComposeCustomBlendMode(srcColorFactor, dstColorFactor BlendFactor, colorOperation BlendOperation, srcAlphaFactor, dstAlphaFactor BlendFactor, alphaOperation BlendOperation) BlendMode {
_srcColorFactor := C.SDL_BlendFactor(srcColorFactor)
_dstColorFactor := C.SDL_BlendFactor(dstColorFactor)
_colorOperation := C.SDL_BlendOperation(colorOperation)
_srcAlphaFactor := C.SDL_BlendFactor(srcAlphaFactor)
_dstAlphaFactor := C.SDL_BlendFactor(dstAlphaFactor)
_alphaOperation := C.SDL_BlendOperation(alphaOperation)
return BlendMode(C.SDL_ComposeCustomBlendMode(_srcColorFactor, _dstColorFactor, _colorOperation, _srcAlphaFactor, _dstAlphaFactor, _alphaOperation))
}