| 1 | package SDL2::blendmode 0.01 { | ||
| 2 | use SDL2::Utils; | ||
| 3 | # | ||
| 4 | enum | ||
| 5 | SDL_BlendMode => [ | ||
| 6 | [ SDL_BLENDMODE_NONE => 0x00000000 ], | ||
| 7 | [ SDL_BLENDMODE_BLEND => 0x00000001 ], | ||
| 8 | [ SDL_BLENDMODE_ADD => 0x00000002, ], | ||
| 9 | [ SDL_BLENDMODE_MOD => 0x00000004, ], | ||
| 10 | [ SDL_BLENDMODE_MUL => 0x00000008, ], | ||
| 11 | [ SDL_BLENDMODE_INVALID => 0x7FFFFFFF ] | ||
| 12 | ], | ||
| 13 | SDL_BlendOperation => [ | ||
| 14 | [ SDL_BLENDOPERATION_ADD => 0x1 ], | ||
| 15 | [ SDL_BLENDOPERATION_SUBTRACT => 0x2 ], | ||
| 16 | [ SDL_BLENDOPERATION_REV_SUBTRACT => 0x3 ], | ||
| 17 | [ SDL_BLENDOPERATION_MINIMUM => 0x4 ], | ||
| 18 | [ SDL_BLENDOPERATION_MAXIMUM => 0x5 ] | ||
| 19 | ], | ||
| 20 | SDL_BlendFactor => [ | ||
| 21 | [ SDL_BLENDFACTOR_ZERO => 0x1 ], | ||
| 22 | [ SDL_BLENDFACTOR_ONE => 0x2 ], | ||
| 23 | [ SDL_BLENDFACTOR_SRC_COLOR => 0x3 ], | ||
| 24 | [ SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR => 0x4 ], | ||
| 25 | [ SDL_BLENDFACTOR_SRC_ALPHA => 0x5 ], | ||
| 26 | [ SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA => 0x6 ], | ||
| 27 | [ SDL_BLENDFACTOR_DST_COLOR => 0x7 ], | ||
| 28 | [ SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR => 0x8 ], | ||
| 29 | [ SDL_BLENDFACTOR_DST_ALPHA => 0x9 ], | ||
| 30 | [ SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA => 0xA ] | ||
| 31 | ]; | ||
| 32 | attach blendmode => { | ||
| 33 | SDL_ComposeCustomBlendMode => [ | ||
| 34 | [ 'SDL_BlendFactor', 'SDL_BlendFactor', | ||
| 35 | 'SDL_BlendOperation', 'SDL_BlendFactor', | ||
| 36 | 'SDL_BlendFactor', 'SDL_BlendOperation' | ||
| 37 | ], | ||
| 38 | 'SDL_BlendMode' | ||
| 39 | ], | ||
| 40 | }; | ||
| 41 | |||
| 42 | =encoding utf-8 | ||
| 43 | |||
| 44 | =head1 NAME | ||
| 45 | |||
| 46 | SDL2::blendmode - SDL2 BlendMode Enumerations and Declarations | ||
| 47 | |||
| 48 | =head1 SYNOPSIS | ||
| 49 | |||
| 50 | use SDL2 qw[:blendMode]; | ||
| 51 | |||
| 52 | =head1 DESCRIPTION | ||
| 53 | |||
| 54 | SDL2::blendmode | ||
| 55 | |||
| 56 | =head1 Functions | ||
| 57 | |||
| 58 | These may be imported by name or with the C<:blendMode> tag. | ||
| 59 | |||
| 60 | =head2 C<SDL_ComposeCustomBlendMode( ... )> | ||
| 61 | |||
| 62 | Compose a custom blend mode for renderers. | ||
| 63 | |||
| 64 | A blend mode controls how the pixels from a drawing operation (source) get | ||
| 65 | combined with the pixels from the render target (destination). First, the | ||
| 66 | components of the source and destination pixels get multiplied with their blend | ||
| 67 | factors. Then, the blend operation takes the two products and calculates the | ||
| 68 | result that will get stored in the render target. | ||
| 69 | |||
| 70 | Expressed in pseudocode, it would look like this: | ||
| 71 | |||
| 72 | $dstRGB = colorOperation( $srcRGB * $srcColorFactor, $dstRGB * $dstColorFactor ); | ||
| 73 | $dstA = alphaOperation( $srcA * $srcAlphaFactor, $dstA * $dstAlphaFactor ); | ||
| 74 | |||
| 75 | Where the functions C<colorOperation( $src, $dst)> and C<alphaOperation( $src, | ||
| 76 | $dst )> can return one of the following: | ||
| 77 | |||
| 78 | =over | ||
| 79 | |||
| 80 | =item - C<$src + $dst> | ||
| 81 | |||
| 82 | =item - C<$src - $dst> | ||
| 83 | |||
| 84 | =item - C<$dst - $src> | ||
| 85 | |||
| 86 | =item - C<min($src, $dst)> | ||
| 87 | |||
| 88 | =item - C<max($src, $dst)> | ||
| 89 | |||
| 90 | =back | ||
| 91 | |||
| 92 | The red, green, and blue components are always multiplied with the first, | ||
| 93 | second, and third components of the C<SDL_BlendFactor>, respectively. The | ||
| 94 | fourth component is not used. | ||
| 95 | |||
| 96 | The alpha component is always multiplied with the fourth component of the | ||
| 97 | C<SDL_BlendFactor>. The other components are not used in the alpha calculation. | ||
| 98 | |||
| 99 | Support for these blend modes varies for each renderer. To check if a specific | ||
| 100 | C<SDL_BlendMode> is supported, create a renderer and pass it to either | ||
| 101 | C<SDL_SetRenderDrawBlendMode> or C<SDL_SetTextureBlendMode>. They will return | ||
| 102 | with an error if the blend mode is not supported. | ||
| 103 | |||
| 104 | This list describes the support of custom blend modes for each renderer in SDL | ||
| 105 | 2.0.6. All renderers support the four blend modes listed in the | ||
| 106 | C<SDL_BlendMode> enumeration. | ||
| 107 | |||
| 108 | =over | ||
| 109 | |||
| 110 | =item B<direct3d>: Supports C<SDL_BLENDOPERATION_ADD> with all factors. | ||
| 111 | |||
| 112 | =item B<direct3d11>: Supports all operations with all factors. However, some factors produce unexpected results with C<SDL_BLENDOPERATION_MINIMUM> and C<SDL_BLENDOPERATION_MAXIMUM>. | ||
| 113 | |||
| 114 | =item B<opengl>: Supports the C<SDL_BLENDOPERATION_ADD> operation with all factors. OpenGL versions 1.1, 1.2, and 1.3 do not work correctly with SDL 2.0.6. | ||
| 115 | |||
| 116 | =item B<opengles>: Supports the C<SDL_BLENDOPERATION_ADD> operation with all factors. Color and alpha factors need to be the same. OpenGL ES 1 implementation specific: May also support C<SDL_BLENDOPERATION_SUBTRACT> and C<SDL_BLENDOPERATION_REV_SUBTRACT>. May support color and alpha operations being different from each other. May support color and alpha factors being different from each other. | ||
| 117 | |||
| 118 | =item B<opengles2>: Supports the C<SDL_BLENDOPERATION_ADD>, C<SDL_BLENDOPERATION_SUBTRACT>, C<SDL_BLENDOPERATION_REV_SUBTRACT> operations with all factors. | ||
| 119 | |||
| 120 | =item B<psp>: No custom blend mode support. | ||
| 121 | |||
| 122 | =item B<software>: No custom blend mode support. | ||
| 123 | |||
| 124 | =back | ||
| 125 | |||
| 126 | Some renderers do not provide an alpha component for the default render target. | ||
| 127 | The C<SDL_BLENDFACTOR_DST_ALPHA> and C<SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA> | ||
| 128 | factors do not have an effect in this case. | ||
| 129 | |||
| 130 | Expected parameters include: | ||
| 131 | |||
| 132 | =over | ||
| 133 | |||
| 134 | =item C<srcColorFactor> - the SDL_BlendFactor applied to the red, green, and blue components of the source pixels | ||
| 135 | |||
| 136 | =item C<dstColorFactor> - the SDL_BlendFactor applied to the red, green, and blue components of the destination pixels | ||
| 137 | |||
| 138 | =item C<colorOperation> - the SDL_BlendOperation used to combine the red, green, and blue components of the source and destination pixels | ||
| 139 | |||
| 140 | =item C<srcAlphaFactor> - the C<SDL_BlendFactor> applied to the alpha component of the source pixels | ||
| 141 | |||
| 142 | =item C<dstAlphaFactor> - the C<SDL_BlendFactor> applied to the alpha component of the destination pixels | ||
| 143 | |||
| 144 | =item C<alphaOperation> - the C<SDL_BlendOperation> used to combine the alpha component of the source and destination pixels | ||
| 145 | |||
| 146 | =back | ||
| 147 | |||
| 148 | Returns an C<SDL_BlendMode> that represents the chosen factors and operations. | ||
| 149 | |||
| 150 | =head1 Defined Values and Enumerations | ||
| 151 | |||
| 152 | These may be imported by name. | ||
| 153 | |||
| 154 | =head2 C<SDL_BlendMode> | ||
| 155 | |||
| 156 | The blend mode used in C<SDL_RenderCopy( )> and drawing operations. These may | ||
| 157 | be imported by name or with the C<:blendMode> tag. | ||
| 158 | |||
| 159 | =over | ||
| 160 | |||
| 161 | =item C<SDL_BLENDMODE_NONE> - no blending | ||
| 162 | |||
| 163 | dstRGBA = srcRGBA | ||
| 164 | |||
| 165 | =item C<SDL_BLENDMODE_BLEND> - alpha blending | ||
| 166 | |||
| 167 | dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA)) | ||
| 168 | dstA = srcA + (dstA * (1-srcA)) | ||
| 169 | |||
| 170 | =item C<SDL_BLENDMODE_ADD> - additive blending | ||
| 171 | |||
| 172 | dstRGB = (srcRGB * srcA) + dstRGB | ||
| 173 | dstA = dstA | ||
| 174 | |||
| 175 | =item C<SDL_BLENDMODE_MOD> - color modulate | ||
| 176 | |||
| 177 | dstRGB = srcRGB * dstRGB | ||
| 178 | dstA = dstA | ||
| 179 | |||
| 180 | =item C<SDL_BLENDMODE_MUL> - color multiply | ||
| 181 | |||
| 182 | dstRGB = (srcRGB * dstRGB) + (dstRGB * (1-srcA)) | ||
| 183 | dstA = (srcA * dstA) + (dstA * (1-srcA)) | ||
| 184 | |||
| 185 | =item C<SDL_BLENDMODE_INVALID> | ||
| 186 | |||
| 187 | =back | ||
| 188 | |||
| 189 | Additional custom blend modes can be returned by L<< | ||
| 190 | C<SDL_ComposeCustomBlendMode( ... )>|/C<SDL_ComposeCustomBlendMode( ... )> >>. | ||
| 191 | |||
| 192 | =head2 C<SDL_BlendOperation> | ||
| 193 | |||
| 194 | The blend operation used when combining source and destination pixel | ||
| 195 | components. These may be imported with the C<:blendOperation> tag. | ||
| 196 | |||
| 197 | =over | ||
| 198 | |||
| 199 | =item C<SDL_BLENDOPERATION_ADD> - supported by all renderers | ||
| 200 | |||
| 201 | dst + src | ||
| 202 | |||
| 203 | =item C<SDL_BLENDOPERATION_SUBTRACT> - supported by D3D9, D3D11, OpenGL, OpenGLES | ||
| 204 | |||
| 205 | dst - src | ||
| 206 | |||
| 207 | =item C<SDL_BLENDOPERATION_REV_SUBTRACT> - supported by D3D9, D3D11, OpenGL, OpenGLES | ||
| 208 | |||
| 209 | src - dst | ||
| 210 | |||
| 211 | =item C<SDL_BLENDOPERATION_MINIMUM> - supported by D3D11 | ||
| 212 | |||
| 213 | min(dst, src) | ||
| 214 | |||
| 215 | =item C<SDL_BLENDOPERATION_MAXIMUM> - supported by D3D11 | ||
| 216 | |||
| 217 | max(dst, src) | ||
| 218 | |||
| 219 | =back | ||
| 220 | |||
| 221 | =head2 C<SDL_BlendFactor> | ||
| 222 | |||
| 223 | The normalized factor used to multiply pixel components. These may be imported | ||
| 224 | with the C<:blendfactor> tag. | ||
| 225 | |||
| 226 | =over | ||
| 227 | |||
| 228 | =item C<SDL_BLENDFACTOR_ZERO> - C< 0, 0, 0, 0 > | ||
| 229 | |||
| 230 | =item C<SDL_BLENDFACTOR_ONE> - C< 1, 1, 1, 1 > | ||
| 231 | |||
| 232 | =item C<SDL_BLENDFACTOR_SRC_COLOR> - C< srcR, srcG, srcB, srcA > | ||
| 233 | |||
| 234 | =item C<SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR> - C< 1-srcR, 1-srcG, 1-srcB, 1-srcA > | ||
| 235 | |||
| 236 | =item C<SDL_BLENDFACTOR_SRC_ALPHA> - C< srcA, srcA, srcA, srcA > | ||
| 237 | |||
| 238 | =item C<SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA> - C< 1-srcA, 1-srcA, 1-srcA, 1-srcA > | ||
| 239 | |||
| 240 | =item C<SDL_BLENDFACTOR_DST_COLOR> - C< dstR, dstG, dstB, dstA > | ||
| 241 | |||
| 242 | =item C<SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR> - C< 1-dstR, 1-dstG, 1-dstB, 1-dstA > | ||
| 243 | |||
| 244 | =item C<SDL_BLENDFACTOR_DST_ALPHA> - C< dstA, dstA, dstA, dstA > | ||
| 245 | |||
| 246 | =item C<SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA> - C< 1-dstA, 1-dstA, 1-dstA, 1-dstA > | ||
| 247 | |||
| 248 | =back | ||
| 249 | |||
| 250 | =head1 LICENSE | ||
| 251 | |||
| 252 | Copyright (C) Sanko Robinson. | ||
| 253 | |||
| 254 | This library is free software; you can redistribute it and/or modify it under | ||
| 255 | the terms found in the Artistic License 2. Other copyrights, terms, and | ||
| 256 | conditions may apply to data transmitted through this module. | ||
| 257 | |||
| 258 | =head1 AUTHOR | ||
| 259 | |||
| 260 | Sanko Robinson E<lt>sanko@cpan.orgE<gt> | ||
| 261 | |||
| 262 | =begin stopwords | ||
| 263 | |||
| 264 | pseudocode opengl opengls opengles opengles2 psp OpenGLES | ||
| 265 | |||
| 266 | =end stopwords | ||
| 267 | |||
| 268 | =cut | ||
| 269 | |||
| 270 | }; | ||
| 271 | 1; |