Skip to content

Commit 06d75f3

Browse files
committed
Added SDLTexture.setAlphaModulation()
1 parent d783ac3 commit 06d75f3

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Sources/SDL/Texture.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,40 @@ public final class SDLTexture {
8181
try SDL_SetTextureBlendMode(internalPointer, SDL_BlendMode(newValue.rawValue)).sdlThrow(type: type(of: self))
8282
}
8383

84+
/**
85+
Get the additional alpha value used in render copy operations.
86+
87+
- Note:
88+
When this texture is rendered, during the copy operation the source alpha value is modulated by this alpha value according to the following formula:
89+
90+
`srcA = srcA * (alpha / 255)`
91+
92+
Alpha modulation is not always supported by the renderer; it will return -1 if alpha modulation is not supported.
93+
*/
94+
public func alphaModulation() throws -> UInt8 {
95+
96+
var alpha: UInt8 = 0
97+
try SDL_GetTextureAlphaMod(internalPointer, &alpha).sdlThrow(type: type(of: self))
98+
return alpha
99+
}
100+
101+
/**
102+
Set an additional alpha value used in render copy operations.
103+
104+
- Parameter alpha: the source alpha value multiplied into copy operations.
105+
106+
- Note:
107+
When this texture is rendered, during the copy operation the source alpha value is modulated by this alpha value according to the following formula:
108+
109+
`srcA = srcA * (alpha / 255)`
110+
111+
Alpha modulation is not always supported by the renderer; it will return -1 if alpha modulation is not supported.
112+
*/
113+
public func setAlphaModulation(_ alpha: UInt8) throws {
114+
115+
try SDL_SetTextureAlphaMod(internalPointer, alpha).sdlThrow(type: type(of: self))
116+
}
117+
84118
// MARK: - Methods
85119

86120
/// Lock a portion of the texture for write-only pixel access (only valid for streaming textures).

0 commit comments

Comments
 (0)