blib/lib/SDL2/FFI.pm untested

filter: Statementstmt 0.0% 0 / 1017 Branchbran 0.0% 0 / 44 Conditioncond 0.0% 0 / 75 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 134 Podpod 0.0% 0 / 62 totaltotal 0.0% 0 / 1332 CC 3 SCAR 8.0
CC
3
Cov
0%
SDL_BYTESPERPIXEL
12.0
bigendian
2.0
SDL_LoadBMP
2.0
CRAP 2.2
1 package SDL2::FFI 0.04 {
2 use lib '../lib', 'lib';
3  
4 # ABSTRACT: FFI Wrapper for SDL (Simple DirectMedia Layer) Development Library
5 use strictures 2;
6 use experimental 'signatures';
7 use base 'Exporter::Tiny';
8 use SDL2::Utils;
9 use Config;
10 sub bigendian () { CORE::state $bigendian //= ( $Config{byteorder} != 4321 ); $bigendian }
11 our %EXPORT_TAGS;
12  
13 # I need these first
14 attach version => { SDL_GetVersion => [ ['SDL_version'] ] };
15 #
16 SDL_GetVersion( my $ver = SDL2::version->new() );
17 my $platform = $^O; # https://perldoc.perl.org/perlport#PLATFORMS
18 my $Windows = !!( $platform eq 'MSWin32' );
19 #
20 use SDL2::version;
21 use SDL2::Enum;
22 use SDL2::AudioCVT;
23 use SDL2::AudioSpec;
24 use SDL2::CommonEvent;
25 use SDL2::DisplayEvent;
26 use SDL2::KeyboardEvent;
27 use SDL2::MouseButtonEvent;
28 use SDL2::MouseMotionEvent;
29 use SDL2::MouseWheelEvent;
30 use SDL2::JoyAxisEvent;
31 use SDL2::JoyBallEvent;
32 use SDL2::JoyHatEvent;
33 use SDL2::JoyButtonEvent;
34 use SDL2::JoyDeviceEvent;
35 use SDL2::ControllerAxisEvent;
36 use SDL2::ControllerButtonEvent;
37 use SDL2::ControllerDeviceEvent;
38 use SDL2::AudioDeviceEvent;
39 use SDL2::TouchFingerEvent;
40 use SDL2::TextEditingEvent;
41 use SDL2::TextInputEvent;
42 use SDL2::WindowEvent;
43 use SDL2::Point;
44 use SDL2::FPoint;
45 use SDL2::FRect;
46 use SDL2::Rect;
47 use SDL2::DisplayMode;
48 use SDL2::Surface;
49 use SDL2::Window;
50 use SDL2::WindowShaper;
51 use SDL2::Texture;
52 use SDL2::Renderer;
53 use SDL2::RendererInfo;
54 use Data::Dump;
55  
56 # https://github.com/libsdl-org/SDL/blob/main/include/SDL.h
57 push @{ $EXPORT_TAGS{default} }, qw[:init];
58 attach init => {
59 SDL_Init => [ ['uint32'] => 'int' ],
60 SDL_InitSubSystem => [ ['uint32'] => 'int' ],
61 SDL_Quit => [ [] ],
62 SDL_QuitSubSystem => [ ['uint32'] ],
63 SDL_WasInit => [ ['uint32'] => 'uint32' ]
64 };
65 #
66 ffi->type( '(opaque,string,string,string)->void' => 'SDL_HintCallback' );
67 attach hints => {
68 SDL_SetHintWithPriority => [ [ 'string', 'string', 'int' ] => 'bool' ],
69 SDL_SetHint => [ [ 'string', 'string' ] => 'bool' ],
70 SDL_GetHint => [ ['string'] => 'string' ],
71 $ver->patch >= 5 ? ( SDL_GetHintBoolean => [ [ 'string', 'bool' ] => 'bool' ] ) : (),
72 SDL_AddHintCallback => [
73 [ 'string', 'SDL_HintCallback', 'opaque' ] => 'void' =>
74 sub ( $xsub, $name, $callback, $userdata ) { # Fake void pointer
75 my $cb = FFI::Platypus::Closure->new(
76 sub ( $ptr, @etc ) { $callback->( $userdata, @etc ) } );
77 $cb->sticky;
78 $xsub->( $name, $cb, $userdata );
79 return $cb;
80 }
81 ],
82 SDL_DelHintCallback => [
83 [ 'string', 'SDL_HintCallback', 'opaque' ] => 'void' =>
84 sub ( $xsub, $name, $callback, $userdata ) { # Fake void pointer
85 my $cb = $callback;
86 $cb->unstick;
87 $xsub->( $name, $cb, $userdata );
88 return $cb;
89 }
90 ],
91 SDL_ClearHints => [ [] => 'void' ],
92 },
93 error => {
94 SDL_SetError => [
95 ['string'] => 'int' =>
96 sub ( $inner, $fmt, @params ) { $inner->( sprintf( $fmt, @params ) ); }
97 ],
98 SDL_GetError => [ [] => 'string' ],
99 SDL_GetErrorMsg => [
100 [ 'string', 'int' ] => 'string' => sub ( $inner, $errstr, $maxlen = length $errstr ) {
101 $_[1] = ' ' x $maxlen if !defined $_[1] || length $errstr != $maxlen;
102 $inner->( $_[1], $maxlen );
103 }
104 ],
105 SDL_ClearError => [ [] => 'void' ]
106 };
107 ffi->type( '(opaque,int,int,string)->void' => 'SDL_LogOutputFunction' );
108 attach log => {
109 SDL_LogSetAllPriority => [ ['SDL_LogPriority'] ],
110 SDL_LogSetPriority => [ [ 'SDL_LogCategory', 'SDL_LogPriority' ] ],
111 SDL_LogGetPriority => [ ['SDL_LogCategory'] => 'SDL_LogPriority' ],
112 SDL_LogResetPriorities => [ [] ],
113 SDL_Log => [
114 ['string'] => 'string' =>
115 sub ( $inner, $fmt, @args ) { $inner->( sprintf( $fmt, @args ) ) }
116 ],
117 SDL_LogVerbose => => [
118 [ 'SDL_LogCategory', 'string' ] => sub ( $inner, $category, $fmt, @args ) {
119 $inner->( $category, sprintf( $fmt, @args ) );
120 }
121 ],
122 SDL_LogDebug => => [
123 [ 'SDL_LogCategory', 'string' ] => sub ( $inner, $category, $fmt, @args ) {
124 $inner->( $category, sprintf( $fmt, @args ) );
125 }
126 ],
127 SDL_LogInfo => => [
128 [ 'SDL_LogCategory', 'string' ] => sub ( $inner, $category, $fmt, @args ) {
129 $inner->( $category, sprintf( $fmt, @args ) );
130 }
131 ],
132 SDL_LogWarn => => [
133 [ 'SDL_LogCategory', 'string' ] => sub ( $inner, $category, $fmt, @args ) {
134 $inner->( $category, sprintf( $fmt, @args ) );
135 }
136 ],
137 SDL_LogError => => [
138 [ 'SDL_LogCategory', 'string' ] => sub ( $inner, $category, $fmt, @args ) {
139 $inner->( $category, sprintf( $fmt, @args ) );
140 }
141 ],
142 SDL_LogCritical => => [
143 [ 'SDL_LogCategory', 'string' ] => sub ( $inner, $category, $fmt, @args ) {
144 $inner->( $category, sprintf( $fmt, @args ) );
145 }
146 ],
147 SDL_LogMessage => [
148 [ 'SDL_LogCategory', 'SDL_LogPriority', 'string' ] =>
149 sub ( $inner, $category, $priority, $fmt, @args ) {
150 $inner->( $category, $priority, sprintf( $fmt, @args ) );
151 }
152 ],
153  
154 # TODO
155 SDL_LogGetOutputFunction => [ [ 'SDL_LogOutputFunction', 'opaque' ] ],
156 SDL_LogSetOutputFunction => [
157 [ 'SDL_LogOutputFunction', 'opaque' ] => 'void' => sub ( $xsub, $callback, $userdata )
158 { # Fake void pointer
159 my $cb = FFI::Platypus::Closure->new(
160 sub ( $ptr, @etc ) { $callback->( $userdata, @etc ) } );
161 $cb->sticky;
162 $xsub->( $cb, $userdata );
163 return $cb;
164 }
165 ]
166 };
167 #
168 package SDL2::AssertData {
169 use SDL2::Utils;
170 has
171 always_ignore => 'int',
172 trigger_count => 'uint',
173 condition => 'opaque', # string
174 filename => 'opaque', # string
175 linenum => 'int',
176 function => 'opaque', # string
177 next => 'opaque' # const struct SDL_AssertData *next
178 };
179 attach assert => {
180 SDL_ReportAssertion => [ [ 'opaque', 'string', 'string', 'int' ], 'opaque' ],
181 SDL_GetAssertionReport => [ ['SDL_AssertData'] ],
182 };
183 FFI::C::ArrayDef->new( # Used sparingly when I need to pass a list of SDL_Point objects
184 ffi,
185 name => 'SDL2x_PointList',
186 class => 'SDL2x::PointList',
187 members => ['SDL_Point'],
188 );
189 FFI::C::ArrayDef->new( # Used sparingly when I need to pass a list of SDL_Point objects
190 ffi,
191 name => 'SDL2x_FPointList',
192 class => 'SDL2x::FPointList',
193 members => ['SDL_Point'],
194 );
195 FFI::C::ArrayDef->new( # Used sparingly when I need to pass a list of SDL_Rect objects
196 ffi,
197 name => 'SDL2x_RectList',
198 class => 'SDL2x::RectList',
199 members => ['SDL_Rect'],
200 );
201 FFI::C::ArrayDef->new( # Used sparingly when I need to pass a list of SDL_Rect objects
202 ffi,
203 name => 'SDL2x_FRectList',
204 class => 'SDL2x::FRectList',
205 members => ['SDL_FRect'],
206 );
207 #
208 ffi->type( '(opaque,opaque,opaque)->int' => 'SDL_HitTest' );
209  
210 # An opaque handle to an OpenGL context.
211 package SDL2::GLContext { use SDL2::Utils; has() };
212 attach video => {
213 SDL_GetNumVideoDrivers => [ [], 'int' ],
214 SDL_GetVideoDriver => [ ['int'], 'string' ],
215 SDL_VideoInit => [ ['string'], 'int' ],
216 SDL_VideoQuit => [ [] ],
217 SDL_GetCurrentVideoDriver => [ [], 'string' ],
218 SDL_GetNumVideoDisplays => [ [], 'int' ],
219 SDL_GetDisplayName => [ ['int'], 'string' ],
220 SDL_GetDisplayBounds => [ [ 'int', 'SDL_Rect' ], 'int' ],
221 SDL_GetDisplayUsableBounds => [ [ 'int', 'SDL_Rect' ], 'int' ],
222 SDL_GetDisplayDPI => [ [ 'int', 'float *', 'float *', 'float *' ], 'int' ],
223 SDL_GetDisplayOrientation => [ ['int'], 'int' ],
224 SDL_GetNumDisplayModes => [ ['int'], 'int' ],
225 SDL_GetDisplayMode => [ [ 'int', 'int', 'SDL_DisplayMode' ], 'int' ],
226 SDL_GetDesktopDisplayMode => [ [ 'int', 'SDL_DisplayMode' ], 'int' ],
227 SDL_GetCurrentDisplayMode => [ [ 'int', 'SDL_DisplayMode' ], 'int' ],
228 SDL_GetClosestDisplayMode => [ [ 'int', 'SDL_DisplayMode', 'SDL_DisplayMode' ], 'opaque' ],
229 SDL_GetWindowDisplayIndex => [ ['SDL_Window'], 'int' ],
230 SDL_SetWindowDisplayMode => [ [ 'SDL_Window', 'SDL_DisplayMode' ], 'int' ],
231 SDL_GetWindowDisplayMode => [ [ 'SDL_Window', 'SDL_DisplayMode' ], 'int' ],
232 SDL_GetWindowPixelFormat => [ ['SDL_Window'], 'uint32' ],
233 SDL_CreateWindow => [ [ 'string', 'int', 'int', 'int', 'int', 'uint32' ] => 'SDL_Window' ],
234 SDL_CreateWindowFrom => [ ['opaque'] => 'SDL_Window' ],
235 SDL_GetWindowID => [ ['SDL_Window'] => 'uint32' ],
236 SDL_GetWindowFromID => [ ['uint32'] => 'SDL_Window' ],
237 SDL_GetWindowFlags => [ ['SDL_Window'] => 'uint32' ],
238 SDL_SetWindowTitle => [ [ 'SDL_Window', 'string' ] ],
239 SDL_GetWindowTitle => [ ['SDL_Window'], 'string' ],
240 SDL_SetWindowIcon => [ [ 'SDL_Window', 'SDL_Surface' ] ],
241  
242 # These don't work correctly yet. (cast issues)
243 SDL_SetWindowData => [ [ 'SDL_Window', 'string', 'opaque*' ], 'opaque*' ],
244 SDL_GetWindowData => [ [ 'SDL_Window', 'string' ], 'opaque*' ],
245 SDL_SetWindowPosition => [ [ 'SDL_Window', 'int', 'int' ] ],
246 SDL_GetWindowPosition => [ [ 'SDL_Window', 'int*', 'int*' ] ],
247 SDL_SetWindowSize => [ [ 'SDL_Window', 'int', 'int' ] ],
248 SDL_GetWindowSize => [ [ 'SDL_Window', 'int*', 'int*' ] ],
249 SDL_GetWindowBordersSize => [ [ 'SDL_Window', 'int*', 'int*', 'int*', 'int*' ], 'int' ],
250 SDL_SetWindowMinimumSize => [ [ 'SDL_Window', 'int', 'int' ] ],
251 SDL_GetWindowMinimumSize => [ [ 'SDL_Window', 'int*', 'int*' ] ],
252 SDL_SetWindowMaximumSize => [ [ 'SDL_Window', 'int', 'int' ] ],
253 SDL_GetWindowMaximumSize => [ [ 'SDL_Window', 'int*', 'int*' ] ],
254 SDL_SetWindowBordered => [ [ 'SDL_Window', 'bool' ] ],
255 SDL_SetWindowResizable => [ [ 'SDL_Window', 'bool' ] ],
256 SDL_ShowWindow => [ ['SDL_Window'] ],
257 SDL_HideWindow => [ ['SDL_Window'] ],
258 SDL_RaiseWindow => [ ['SDL_Window'] ],
259 SDL_MaximizeWindow => [ ['SDL_Window'] ],
260 SDL_MinimizeWindow => [ ['SDL_Window'] ],
261 SDL_RestoreWindow => [ ['SDL_Window'] ],
262 SDL_SetWindowFullscreen => [ [ 'SDL_Window', 'uint32' ], 'int' ],
263 SDL_GetWindowSurface => [ ['SDL_Window'], 'SDL_Surface' ],
264 SDL_UpdateWindowSurface => [ ['SDL_Window'], 'int' ],
265 SDL_UpdateWindowSurfaceRects => [ [ 'SDL_Window', 'opaque*', 'int' ], 'int' ],
266 SDL_SetWindowGrab => [ [ 'SDL_Window', 'bool' ] ],
267 ( $ver->patch >= 15 ? ( SDL_SetWindowKeyboardGrab => [ [ 'SDL_Window', 'bool' ] ] ) : () ),
268 ( $ver->patch >= 15 ? ( SDL_SetWindowMouseGrab => [ [ 'SDL_Window', 'bool' ] ] ) : () ),
269 SDL_GetWindowGrab => [ ['SDL_Window'], 'bool' ],
270 ( $ver->patch >= 15 ? ( SDL_GetWindowKeyboardGrab => [ ['SDL_Window'], 'bool' ] ) : () ),
271 ( $ver->patch >= 15 ? ( SDL_GetWindowMouseGrab => [ ['SDL_Window'], 'bool' ] ) : () ),
272 SDL_GetGrabbedWindow => [ [], 'SDL_Window' ],
273 SDL_SetWindowBrightness => [ [ 'SDL_Window', 'float' ], 'int' ],
274 SDL_GetWindowBrightness => [ ['SDL_Window'], 'float' ],
275 SDL_SetWindowOpacity => [ [ 'SDL_Window', 'float' ], 'int' ],
276 SDL_GetWindowOpacity => [ [ 'SDL_Window', 'float*' ], 'int' ],
277 SDL_SetWindowModalFor => [ [ 'SDL_Window', 'SDL_Window' ], 'int' ],
278 SDL_SetWindowInputFocus => [ ['SDL_Window'], 'int' ],
279 SDL_SetWindowGammaRamp =>
280 [ [ 'SDL_Window', 'uint32[256]', 'uint32[256]', 'uint32[256]' ], 'int' ],
281 SDL_GetWindowGammaRamp => [
282 [ 'SDL_Window', 'uint32[256]', 'uint32[256]', 'uint32[256]' ], 'int'
283  
284 #=> sub ( $inner, $window ) {
285 # my @red = my @blue = my @green = map { \0 } 1 .. 256;
286 # my $ok = $inner->( $window, \@red, \@green, \@blue );
287 # $ok == 0 ? ( \@red, \@green, \@blue ) : $ok;
288 #}
289 ],
290 SDL_SetWindowHitTest => [
291 [ 'SDL_Window', 'SDL_HitTest', 'opaque' ],
292 'int' => sub ( $xsub, $window, $callback, $callback_data = () ) { # Fake void pointer
293 my $cb = $callback;
294 if ( defined $callback ) {
295 $cb = FFI::Platypus::Closure->new(
296 sub ( $win, $area, $data ) {
297 $callback->(
298 ffi->cast( 'opaque' => 'SDL_Window', $win ),
299 ffi->cast( 'opaque' => 'SDL_Point', $area ),
300 $callback_data
301 );
302 }
303 );
304 $cb->sticky;
305 }
306 $xsub->( $window, $cb, $callback_data );
307 return $cb;
308 }
309 ],
310 ( $ver->patch >= 15 ? ( SDL_FlashWindow => [ [ 'SDL_Window', 'uint32' ], 'int' ] ) : () ),
311 SDL_DestroyWindow => [ ['SDL_Window'] ],
312 SDL_IsScreenSaverEnabled => [ [], 'bool' ],
313 SDL_EnableScreenSaver => [ [] ],
314 SDL_DisableScreenSaver => [ [] ],
315 },
316 opengl => {
317 SDL_GL_LoadLibrary => [ ['string'], 'int' ],
318 SDL_GL_GetProcAddress => [ ['string'], 'opaque' ],
319 SDL_GL_UnloadLibrary => [ [] ],
320 SDL_GL_ExtensionSupported => [ ['string'], 'bool' ],
321 SDL_GL_ResetAttributes => [ [] ],
322 SDL_GL_SetAttribute => [ [ 'SDL_GLattr', 'int' ], 'int' ],
323 SDL_GL_GetAttribute => [ [ 'SDL_GLattr', 'int*' ], 'int' ],
324 SDL_GL_CreateContext => [ ['SDL_Window'], 'SDL_GLContext' ],
325 SDL_GL_MakeCurrent => [ [ 'SDL_Window', 'SDL_GLContext' ], 'int' ],
326 SDL_GL_GetCurrentWindow => [ [], 'SDL_Window' ],
327 SDL_GL_GetCurrentContext => [ [], 'SDL_GLContext' ],
328 SDL_GL_GetDrawableSize => [ [ 'SDL_Window', 'int*', 'int*' ], ],
329 SDL_GL_SetSwapInterval => [ ['int'], 'int' ],
330 SDL_GL_GetSwapInterval => [ [], 'int' ],
331 SDL_GL_SwapWindow => [ ['SDL_Window'] ],
332 SDL_GL_DeleteContext => [ ['SDL_GLContext'] ]
333 };
334 attach render => {
335 SDL_GetNumRenderDrivers => [ [], 'int' ],
336 SDL_GetRenderDriverInfo => [ [ 'int', 'SDL_RendererInfo' ], 'int' ],
337 SDL_CreateWindowAndRenderer => [
338 [ 'int', 'int', 'uint32', 'opaque*', 'opaque*' ], 'int'
339  
340 #=> sub ( $inner, $width, $height, $window_flags ) {
341 # my $window = SDL2::Window->new;
342 # my $renderer = SDL2::Renderer->new;
343 # my $ok = $inner->( $width, $height, $window_flags, \$window, \$renderer );
344 # $ok == 0 ? (
345 # ffi->cast( 'opaque' => 'SDL_Window', $window ),
346 # ffi->cast( 'opaque' => 'SDL_Renderer', $renderer ),
347 # ) :
348 # $ok;
349 #}
350 ],
351 SDL_CreateRenderer => [ [ 'SDL_Window', 'int', 'uint32' ], 'SDL_Renderer' ],
352 SDL_CreateSoftwareRenderer => [ ['SDL_Surface'], 'SDL_Renderer' ],
353 SDL_GetRenderer => [ ['SDL_Window'], 'SDL_Renderer' ],
354 SDL_GetRendererInfo => [ [ 'SDL_Renderer', 'SDL_RendererInfo' ], 'int' ],
355 SDL_GetRendererOutputSize => [ [ 'SDL_Renderer', 'int*', 'int*' ], 'int' ],
356 SDL_CreateTexture => [ [ 'SDL_Renderer', 'uint32', 'int', 'int', 'int' ], 'SDL_Texture' ],
357 SDL_CreateTextureFromSurface => [ [ 'SDL_Renderer', 'SDL_Surface' ], 'SDL_Texture' ],
358 SDL_QueryTexture => [ [ 'SDL_Texture', 'uint32*', 'int*', 'int*', 'int*' ], 'int' ],
359 SDL_SetTextureColorMod => [ [ 'SDL_Texture', 'uint8', 'uint8', 'uint8' ], 'int' ],
360 SDL_GetTextureColorMod => [ [ 'SDL_Texture', 'uint8*', 'uint8*', 'uint8*' ], 'int' ],
361 SDL_SetTextureAlphaMod => [ [ 'SDL_Texture', 'uint8' ], 'int' ],
362 SDL_GetTextureAlphaMod => [ [ 'SDL_Texture', 'uint8*' ], 'int' ],
363 SDL_SetTextureBlendMode => [ [ 'SDL_Texture', 'SDL_BlendMode' ], 'int' ],
364 SDL_GetTextureBlendMode => [ [ 'SDL_Texture', 'int*' ], 'int' ],
365 SDL_UpdateTexture => [ [ 'SDL_Texture', 'SDL_Rect', 'opaque*', 'int' ], 'int' ],
366 SDL_UpdateYUVTexture => [
367 [ 'SDL_Texture', 'SDL_Rect', 'uint8*', 'int', 'uint8*', 'int', 'uint8*', 'int' ], 'int'
368 ], (
369 $ver->patch >= 15 ?
370 ( SDL_UpdateNVTexture =>
371 [ [ 'SDL_Texture', 'SDL_Rect', 'uint8*', 'int', 'uint8*', 'int' ], 'int' ] ) :
372 ()
373 ),
374 SDL_LockTexture => [ [ 'SDL_Texture', 'SDL_Rect', 'opaque*' ], 'int' ],
375 SDL_LockTextureToSurface => [ [ 'SDL_Texture', 'SDL_Rect', 'SDL_Surface' ], 'int' ],
376 SDL_UnlockTexture => [ ['SDL_Texture'] ],
377 SDL_RenderTargetSupported => [ ['SDL_Renderer'], 'bool' ],
378 SDL_SetRenderTarget => [ [ 'SDL_Renderer', 'SDL_Texture' ], 'int' ],
379 SDL_GetRenderTarget => [ ['SDL_Renderer'], 'SDL_Texture' ],
380 SDL_RenderSetLogicalSize => [ [ 'SDL_Renderer', 'int', 'int' ], 'int' ],
381 SDL_RenderGetLogicalSize => [ [ 'SDL_Renderer', 'int*', 'int*' ], 'int' ],
382 SDL_RenderSetIntegerScale => [ [ 'SDL_Renderer', 'bool' ], 'int' ],
383 SDL_RenderGetIntegerScale => [ ['SDL_Renderer'], 'bool' ],
384 SDL_RenderSetViewport => [ [ 'SDL_Renderer', 'SDL_Rect' ], 'int' ],
385 SDL_RenderGetViewport => [ [ 'SDL_Renderer', 'SDL_Rect' ], 'int' ],
386 SDL_RenderSetClipRect => [ [ 'SDL_Renderer', 'SDL_Rect' ], 'int' ],
387 SDL_RenderGetClipRect => [ [ 'SDL_Renderer', 'SDL_Rect' ] ],
388 SDL_RenderIsClipEnabled => [ ['SDL_Renderer'], 'bool' ],
389 SDL_RenderSetScale => [ [ 'SDL_Renderer', 'float', 'float' ], 'int' ],
390 SDL_RenderGetScale => [ [ 'SDL_Renderer', 'float*', 'float*' ], ],
391 SDL_SetRenderDrawColor => [ [ 'SDL_Renderer', 'uint8', 'uint8', 'uint8', 'uint8' ], 'int' ],
392 SDL_GetRenderDrawColor =>
393 [ [ 'SDL_Renderer', 'uint8*', 'uint8*', 'uint8*', 'uint8*' ], 'int' ],
394 SDL_SetRenderDrawBlendMode => [ [ 'SDL_Renderer', 'SDL_BlendMode' ], 'int' ],
395 SDL_GetRenderDrawBlendMode => [ [ 'SDL_Renderer', 'int*' ], 'int' ],
396 SDL_RenderClear => [ ['SDL_Renderer'], 'int' ],
397 SDL_RenderDrawPoint => [ [ 'SDL_Renderer', 'int', 'int' ], 'int' ],
398 SDL_RenderDrawPoints => [
399 [ 'SDL_Renderer', 'SDL2x_PointList', 'int' ],
400 'int' => sub ( $inner, $renderer, @points ) {
401  
402 # XXX - This is a workaround for FFI::C::Array not being able to accept a list of objects
403 # XXX - I can rethink this map when https://github.com/PerlFFI/FFI-C/issues/53 is resolved
404 $inner->(
405 $renderer,
406 SDL2x::PointList->new(
407 [ map { ref $_ eq 'HASH' ? $_ : { x => $_->x, y => $_->y } } @points ]
408 ),
409 scalar @points
410 );
411 }
412 ],
413 SDL_RenderDrawLine => [ [ 'SDL_Renderer', 'int', 'int', 'int', 'int' ], 'int' ],
414 SDL_RenderDrawLines => [
415 [ 'SDL_Renderer', 'SDL2x_PointList', 'int' ],
416 'int' => sub ( $inner, $renderer, @points ) {
417  
418 # XXX - This is a workaround for FFI::C::Array not being able to accept a list of objects
419 # XXX - I can rethink this map when https://github.com/PerlFFI/FFI-C/issues/53 is resolved
420 $inner->(
421 $renderer,
422 SDL2x::PointList->new(
423 [ map { ref $_ eq 'HASH' ? $_ : { x => $_->x, y => $_->y } } @points ]
424 ),
425 scalar @points
426 );
427 }
428 ],
429 SDL_RenderDrawRect => [ [ 'SDL_Renderer', 'SDL_Rect' ], 'int' ],
430 SDL_RenderDrawRects => [
431 [ 'SDL_Renderer', 'SDL2x_RectList', 'int' ],
432 'int' => sub ( $inner, $renderer, @rects ) {
433  
434 # XXX - This is a workaround for FFI::C::Array not being able to accept a list of objects
435 # XXX - I can rethink this map when https://github.com/PerlFFI/FFI-C/issues/53 is resolved
436 $inner->(
437 $renderer,
438 SDL2x::RectList->new(
439 [ map {
440 ref $_ eq 'HASH' ? $_ :
441 { x => $_->x, y => $_->y, w => $_->w, h => $_->h }
442 } @rects
443 ]
444 ),
445 scalar @rects
446 );
447 }
448 ],
449 SDL_RenderFillRect => [ [ 'SDL_Renderer', 'SDL_Rect' ], 'int' ],
450 SDL_RenderFillRects => [
451 [ 'SDL_Renderer', 'SDL2x_RectList', 'int' ],
452 'int' => sub ( $inner, $renderer, @rects ) {
453  
454 # XXX - This is a workaround for FFI::C::Array not being able to accept a list of objects
455 # XXX - I can rethink this map when https://github.com/PerlFFI/FFI-C/issues/53 is resolved
456 $inner->(
457 $renderer,
458 SDL2x::RectList->new(
459 [ map {
460 ref $_ eq 'HASH' ? $_ :
461 { x => $_->x, y => $_->y, w => $_->w, h => $_->h }
462 } @rects
463 ]
464 ),
465 scalar @rects
466 );
467 }
468 ],
469 SDL_RenderCopy => [ [ 'SDL_Renderer', 'SDL_Texture', 'SDL_Rect', 'SDL_Rect' ], 'int' ],
470  
471 # XXX - I do not have an example for this function in docs
472 SDL_RenderCopyEx => [
473 [ 'SDL_Renderer', 'SDL_Texture', 'SDL_Rect', 'SDL_Rect',
474 'double', 'SDL_Point', 'SDL_RendererFlip'
475 ],
476 'int'
477 ],
478 SDL_RenderDrawPointF => [ [ 'SDL_Renderer', 'float', 'float' ], 'int' ],
479 SDL_RenderDrawPointsF => [
480 [ 'SDL_Renderer', 'SDL2x_FPointList', 'int' ],
481 'int' => sub ( $inner, $renderer, @points ) {
482  
483 # XXX - This is a workaround for FFI::C::Array not being able to accept a list of objects
484 # XXX - I can rethink this map when https://github.com/PerlFFI/FFI-C/issues/53 is resolved
485 $inner->(
486 $renderer,
487 SDL2x::PointFList->new(
488 [ map { ref $_ eq 'HASH' ? $_ : { x => $_->x, y => $_->y } } @points ]
489 ),
490 scalar @points
491 );
492 }
493 ],
494 SDL_RenderDrawLineF => [ [ 'SDL_Renderer', 'float', 'float', 'float', 'float' ], 'int' ],
495 SDL_RenderDrawLinesF => [
496 [ 'SDL_Renderer', 'SDL2x_FPointList', 'int' ],
497 'int' => sub ( $inner, $renderer, @points ) {
498  
499 # XXX - This is a workaround for FFI::C::Array not being able to accept a list of objects
500 # XXX - I can rethink this map when https://github.com/PerlFFI/FFI-C/issues/53 is resolved
501 $inner->(
502 $renderer,
503 SDL2x::FPointList->new(
504 [ map { ref $_ eq 'HASH' ? $_ : { x => $_->x, y => $_->y } } @points ]
505 ),
506 scalar @points
507 );
508 }
509 ],
510 SDL_RenderDrawRectF => [
511 [ 'SDL_Renderer', 'SDL2x_FRectList', 'int' ],
512 'int' => sub ( $inner, $renderer, @rects ) {
513  
514 # XXX - This is a workaround for FFI::C::Array not being able to accept a list of objects
515 # XXX - I can rethink this map when https://github.com/PerlFFI/FFI-C/issues/53 is resolved
516 $inner->(
517 $renderer,
518 SDL2x::FRectList->new(
519 [ map {
520 ref $_ eq 'HASH' ? $_ :
521 { x => $_->x, y => $_->y, w => $_->w, h => $_->h }
522 } @rects
523 ]
524 ),
525 scalar @rects
526 );
527 }
528 ],
529 SDL_RenderDrawRectsF => [
530 [ 'SDL_Renderer', 'SDL2x_FRectList', 'int' ],
531 'int' => sub ( $inner, $renderer, @rects ) {
532  
533 # XXX - This is a workaround for FFI::C::Array not being able to accept a list of objects
534 # XXX - I can rethink this map when https://github.com/PerlFFI/FFI-C/issues/53 is resolved
535 $inner->(
536 $renderer,
537 SDL2x::FRectList->new(
538 [ map {
539 ref $_ eq 'HASH' ? $_ :
540 { x => $_->x, y => $_->y, w => $_->w, h => $_->h }
541 } @rects
542 ]
543 ),
544 scalar @rects
545 );
546 }
547 ],
548 SDL_RenderFillRectsF => [
549 [ 'SDL_Renderer', 'SDL2x_FRectList', 'int' ],
550 'int' => sub ( $inner, $renderer, @rects ) {
551  
552 # XXX - This is a workaround for FFI::C::Array not being able to accept a list of objects
553 # XXX - I can rethink this map when https://github.com/PerlFFI/FFI-C/issues/53 is resolved
554 $inner->(
555 $renderer,
556 SDL2x::FRectList->new(
557 [ map {
558 ref $_ eq 'HASH' ? $_ :
559 { x => $_->x, y => $_->y, w => $_->w, h => $_->h }
560 } @rects
561 ]
562 ),
563 scalar @rects
564 );
565 }
566 ],
567  
568 # XXX - I do not have an example for this function in docs
569 SDL_RenderCopyF => [ [ 'SDL_Renderer', 'SDL_Texture', 'SDL_Rect', 'SDL_FRect' ], 'int' ],
570  
571 # XXX - I do not have an example for this function in docs
572 SDL_RenderCopyExF => [
573 [ 'SDL_Renderer', 'SDL_Texture', 'SDL_Rect', 'SDL_FRect',
574 'double', 'SDL_FPoint', 'SDL_RendererFlip'
575 ],
576 'int'
577 ],
578 SDL_RenderReadPixels =>
579 [ [ 'SDL_Renderer', 'SDL_Rect', 'uint32', 'opaque', 'int' ], 'int' ],
580 SDL_RenderPresent => [ ['SDL_Renderer'] ],
581 SDL_DestroyTexture => [ ['SDL_Texture'] ],
582 SDL_DestroyRenderer => [ ['SDL_Renderer'] ],
583 SDL_RenderFlush => [ ['SDL_Renderer'], 'int' ],
584 SDL_GL_BindTexture => [ [ 'SDL_Texture', 'float*', 'float*' ], 'int' ],
585 SDL_GL_UnbindTexture => [ ['SDL_Texture'], 'int' ],
586 SDL_RenderGetMetalLayer => [ ['SDL_Renderer'], 'opaque' ],
587 SDL_RenderGetMetalCommandEncoder => [ ['SDL_Renderer'], 'opaque' ]
588 };
589 ffi->type( '(int,opaque)->uint32' => 'SDL_TimerCallback' );
590 attach timer => {
591 SDL_GetTicks => [ [], 'uint32' ],
592 SDL_GetPerformanceCounter => [ [], 'uint64' ],
593 SDL_GetPerformanceFrequency => [ [], 'uint64' ],
594 SDL_Delay => [ ['uint32'] ],
595 SDL_AddTimer => [
596 [ 'uint32', 'SDL_TimerCallback', 'opaque' ],
597 'int' => sub ( $xsub, $interval, $callback, $param = () ) {
598  
599 # Fake void pointer
600 my $cb = FFI::Platypus::Closure->new( sub { $callback->(@_); } );
601 $cb->sticky;
602 $xsub->( $interval, $cb, $param );
603 }
604 ],
605 SDL_RemoveTimer => [ ['uint32'] => 'bool' ],
606 };
607 ffi->type( '(opaque,string,int)->void' => 'SDL_AudioCallback' );
608 ffi->type( 'int' => 'SDL_AudioFormat' );
609 ffi->type( '(opaque,uint16)->void' => 'SDL_AudioFilter' );
610  
611 package SDL2::AudioStream {
612 use SDL2::Utils;
613 has();
614 };
615  
616 package SDL2::AudioDeviceID {
617 use SDL2::Utils;
618 has();
619 };
620  
621 package SDL2::RWops { # TODO: https://github.com/libsdl-org/SDL/blob/main/include/SDL_rwops.h
622 use SDL2::Utils;
623 has();
624 };
625 define audio => [ [ SDL_AUDIOCVT_MAX_FILTERS => 9 ], ];
626 attach audio => {
627 SDL_AudioInit => [ ["string"], "int" ],
628 SDL_AudioQuit => [ [] ],
629 SDL_AudioStreamAvailable => [ ["SDL_AudioStream"], "int" ],
630 SDL_AudioStreamClear => [ ["SDL_AudioStream"] ],
631 SDL_AudioStreamFlush => [ ["SDL_AudioStream"], "int" ],
632 SDL_AudioStreamGet => [ [ "SDL_AudioStream", "opaque*", "int" ], "int" ],
633 SDL_AudioStreamPut => [ [ "SDL_AudioStream", "opaque*", "int" ], "int" ],
634 SDL_BuildAudioCVT => [
635 [ "SDL_AudioCVT", "SDL_AudioFormat", "uint8", "int",
636 "SDL_AudioFormat", "uint8", "int",
637 ],
638 "int",
639 ],
640 SDL_ClearQueuedAudio => [ ["SDL_AudioDeviceID"] ],
641 SDL_CloseAudio => [ [] ],
642 SDL_CloseAudioDevice => [ ["SDL_AudioDeviceID"] ],
643 SDL_ConvertAudio => [ ["SDL_AudioCVT"], "int" ],
644 SDL_DequeueAudio => [ [ "SDL_AudioDeviceID", "opaque*", "uint32" ], "uint32" ],
645 SDL_FreeAudioStream => [ ["SDL_AudioStream"] ],
646 SDL_FreeWAV => [ ["uint8 *"] ],
647 SDL_GetAudioDeviceName => [ [ "int", "int" ], "string" ], (
648 $ver->patch >= 15 ?
649 ( SDL_GetAudioDeviceSpec => [ [ "int", "int", "SDL_AudioSpec" ], "int" ] ) :
650 ()
651 ),
652 SDL_GetAudioDeviceStatus => [ ["SDL_AudioDeviceID"], "SDL_AudioStatus" ],
653 SDL_GetAudioDriver => [ ["int"], "string" ],
654 SDL_GetAudioStatus => [ [], "SDL_AudioStatus" ],
655 SDL_GetCurrentAudioDriver => [ [], "string" ],
656 SDL_GetNumAudioDevices => [ ["int"], "int" ],
657 SDL_GetNumAudioDrivers => [ [], "int" ],
658 SDL_GetQueuedAudioSize => [ ["SDL_AudioDeviceID"], "uint32" ],
659  
660 #SDL_LoadWAV_RW => [
661 # ["SDL_RWops", "int", "SDL_AudioSpec", "uint8**", "uint32 *"],
662 # "SDL_AudioSpec",
663 # ],
664 SDL_LockAudio => [ [] ],
665 SDL_LockAudioDevice => [ ["SDL_AudioDeviceID"] ],
666 SDL_MixAudio => [ [ "uint8 *", "uint8 *", "uint32", "int" ] ],
667 SDL_MixAudioFormat => [ [ "uint8 *", "uint8 *", "SDL_AudioFormat", "uint32", "int" ] ],
668 SDL_NewAudioStream => [
669 [ "SDL_AudioFormat", "uint8", "int", "SDL_AudioFormat", "uint8", "int", ],
670 "SDL_AudioStream",
671 ],
672 SDL_OpenAudio => [
673 [ 'SDL_AudioSpec', 'SDL_AudioSpec' ],
674 'int' => sub ( $inner, $desired, $obtained = () ) {
675 deprecate <<'END';
676 SDL_OpenAudio( ... ) remains for compatibility with SDL 1.2. The new, more
677 powerful, and preferred way to do this is SDL_OpenAudioDevice( ... );
678 END
679 $inner->( $desired, $obtained );
680 }
681 ],
682 SDL_OpenAudioDevice =>
683 [ [ "string", "int", "SDL_AudioSpec", "SDL_AudioSpec", "int" ], "SDL_AudioDeviceID", ],
684 SDL_PauseAudio => [ ["int"] ],
685 SDL_PauseAudioDevice => [ [ "SDL_AudioDeviceID", "int" ] ],
686 SDL_QueueAudio => [ [ "SDL_AudioDeviceID", "opaque*", "uint32" ], "int" ],
687 SDL_UnlockAudio => [ [] ],
688 SDL_UnlockAudioDevice => [ ["SDL_AudioDeviceID"] ],
689 };
690  
691 # Everything below this line will be rewritten!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
692 #
693 #https://github.com/libsdl-org/SDL/blob/main/include/SDL_surface.h#L327
694 push @{ $EXPORT_TAGS{'surface'} }, 'SDL_LoadBMP';
695 attach surface => { SDL_LoadBMP_RW => [ [ 'SDL_RWops', 'int' ], 'SDL_Surface' ], };
696 sub SDL_LoadBMP ($file) { SDL_LoadBMP_RW( SDL_RWFromFile( $file, "rb" ), 1 ) }
697 push @{ $EXPORT_TAGS{'surface'} }, 'SDL_FreeSurface';
698 ffi->attach( SDL_FreeSurface => ['SDL_Surface'] );
699 ffi->attach( SDL_SaveBMP_RW => [ 'SDL_Surface', 'SDL_RWops', 'int' ], 'int' );
700 attach future => {
701 SDL_ComposeCustomBlendMode => [
702 [ 'SDL_BlendFactor', 'SDL_BlendFactor',
703 'SDL_BlendOperation', 'SDL_BlendFactor',
704 'SDL_BlendFactor', 'SDL_BlendOperation'
705 ],
706 'SDL_BlendMode'
707 ],
708 };
709 ffi->attach( SDL_RWFromFile => [ 'string', 'string' ], 'SDL_RWops' );
710  
711 sub SDL_SaveBMP ( $surface, $file ) {
712 SDL_SaveBMP_RW( $surface, SDL_RWFromFile( $file, 'wb' ), 1 );
713 }
714 ffi->attach( SDL_GetPlatform => [] => 'string' );
715 ffi->attach( SDL_CreateRGBSurface =>
716 [ 'uint32', 'int', 'int', 'int', 'uint32', 'uint32', 'uint32', 'uint32' ] =>
717 'SDL_Surface' );
718  
719 # https://wiki.libsdl.org/CategoryCPU
720 ffi->attach( SDL_GetCPUCacheLineSize => [] => 'int' );
721 ffi->attach( SDL_GetCPUCount => [] => 'int' );
722 ffi->attach( SDL_GetSystemRAM => [] => 'int' );
723 ffi->attach( SDL_Has3DNow => [] => 'bool' );
724 ffi->attach( SDL_HasAVX => [] => 'bool' );
725 ffi->attach( SDL_HasAVX2 => [] => 'bool' );
726 ffi->attach( SDL_HasAltiVec => [] => 'bool' );
727 ffi->attach( SDL_HasMMX => [] => 'bool' );
728 ffi->attach( SDL_HasRDTSC => [] => 'bool' );
729 ffi->attach( SDL_HasSSE => [] => 'bool' );
730 ffi->attach( SDL_HasSSE2 => [] => 'bool' );
731 ffi->attach( SDL_HasSSE3 => [] => 'bool' );
732 ffi->attach( SDL_HasSSE41 => [] => 'bool' );
733 ffi->attach( SDL_HasSSE42 => [] => 'bool' );
734 ffi->attach( SDL_GetPowerInfo => [ 'int*', 'int*' ] => 'int' );
735  
736 # https://wiki.libsdl.org/CategoryStandard
737 ffi->attach( SDL_acos => ['double'] => 'double' );
738 ffi->attach( SDL_asin => ['double'] => 'double' ); # Not in wiki
739  
740 # https://wiki.libsdl.org/CategoryVideo
741 # Macros defined in SDL_video.h
742 define video => [
743 [ SDL_WINDOWPOS_UNDEFINED_MASK => 0x1FFF0000 ],
744 [ SDL_WINDOWPOS_UNDEFINED_DISPLAY =>
745 sub ($X) { ( SDL_WINDOWPOS_UNDEFINED_MASK() | ($X) ) }
746 ],
747 [ SDL_WINDOWPOS_UNDEFINED => sub () { SDL_WINDOWPOS_UNDEFINED_DISPLAY(0) } ],
748 [ SDL_WINDOWPOS_ISUNDEFINED =>
749 sub ($X) { ( ( ($X) & 0xFFFF0000 ) == SDL_WINDOWPOS_UNDEFINED_MASK() ) }
750 ],
751 #
752 [ SDL_WINDOWPOS_CENTERED_MASK => sub () {0x2FFF0000} ],
753 [ SDL_WINDOWPOS_CENTERED_DISPLAY => sub ($X) { ( SDL_WINDOWPOS_CENTERED_MASK() | ($X) ) } ],
754 [ SDL_WINDOWPOS_CENTERED => sub() { SDL_WINDOWPOS_CENTERED_DISPLAY(0) } ],
755 [ SDL_WINDOWPOS_ISCENTERED =>
756 sub ($X) { ( ( ($X) & 0xFFFF0000 ) == SDL_WINDOWPOS_CENTERED_MASK() ) }
757 ],
758 ];
759  
760 # https://wiki.libsdl.org/CategoryPixels
761 package SDL2::Color {
762 use SDL2::Utils;
763 has r => 'uint8', g => 'uint8', b => 'uint8', a => 'uint8';
764 };
765  
766 package SDL2::Palette {
767 use SDL2::Utils;
768 has
769 ncolors => 'int',
770 colors => 'SDL_Color';
771 };
772  
773 package SDL2::PixelFormat {
774 use SDL2::Utils;
775 has
776 format => 'uint32',
777 palette => 'SDL_Palette',
778 BitsPerPixel => 'uint8',
779 BytesPerPixel => 'uint8',
780 padding => 'uint32[2]',
781 Rmask => 'uint32',
782 Gmask => 'uint32',
783 Bmask => 'uint32',
784 Amask => 'uint32',
785 Rloss => 'uint8',
786 Gloss => 'uint8',
787 Bloss => 'uint8',
788 Aloss => 'uint8',
789 Rshift => 'uint8',
790 Gshift => 'uint8',
791 Bshift => 'uint8',
792 Ashift => 'uint8',
793 refcount => 'int',
794 next => 'opaque' # SDL_PixelFormat *
795 };
796 attach future => {
797 SDL_FillRect => [ [ 'SDL_Surface', 'opaque', 'uint32' ], 'int' ],
798 SDL_MapRGB => [
799 [ 'SDL_PixelFormat', 'uint8', 'uint8', 'uint8' ] => 'uint32' =>
800 sub ( $inner, $format, $r, $g, $b ) {
801 $format = ffi->cast( 'opaque', 'SDL_PixelFormat', $format ) if !ref $format;
802 $inner->( $format, $r, $g, $b );
803 }
804 ]
805 };
806  
807 package SDL2::MultiGestureEvent {
808 use SDL2::Utils;
809 has
810 type => 'uint32',
811 timestamp => 'uint32',
812 touchId => 'opaque', # SDL_TouchID
813 dTheta => 'float',
814 dDist => 'float',
815 x => 'float',
816 y => 'float',
817 numFingers => 'uint16',
818 padding => 'uint16';
819 };
820  
821 package SDL2::DollarGestureEvent {
822 use SDL2::Utils;
823 has
824 type => 'uint32',
825 timestamp => 'uint32',
826 touchId => 'opaque', # SDL_TouchID
827 gestureId => 'opaque', # SDL_GestureID
828 numFingers => 'uint32',
829 error => 'float',
830 x => 'float',
831 y => 'float';
832 };
833  
834 package SDL2::DropEvent {
835 use SDL2::Utils;
836 has
837 type => 'uint32',
838 timestamp => 'uint32',
839 file => 'char[256]',
840 windowID => 'uint32';
841 };
842  
843 package SDL2::SensorEvent {
844 use SDL2::Utils;
845 has
846 type => 'uint32',
847 timestamp => 'uint32',
848 which => 'sint32',
849 data => 'float[6]';
850 };
851  
852 package SDL2::QuitEvent {
853 use SDL2::Utils;
854 has type => 'uint32', timestamp => 'uint32';
855 };
856  
857 package SDL2::OSEvent {
858 use SDL2::Utils;
859 has
860 type => 'uint32',
861 timestamp => 'uint32';
862 };
863  
864 package SDL2::UserEvent {
865 use SDL2::Utils;
866 has
867 type => 'uint32',
868 timestamp => 'uint32',
869 windowID => 'uint32',
870 code => 'sint32',
871 data1 => 'opaque', # void *
872 data2 => 'opaque' # void *
873 };
874  
875 package SDL2::SysWMmsg {
876 use SDL2::Utils;
877 has();
878 };
879  
880 package SDL2::SysWMEvent {
881 use SDL2::Utils;
882 has
883 type => 'uint32',
884 timestamp => 'uint32',
885 msg => 'opaque' # SDL_SysWMmsg
886 };
887 use FFI::C::UnionDef;
888  
889 package SDL2::Event { use SDL2::Utils; };
890 FFI::C::UnionDef->new( ffi,
891 name => 'SDL_Event',
892 class => 'SDL2::Event',
893 members => [
894 type => 'uint32',
895 common => 'SDL_CommonEvent',
896 display => 'SDL_DisplayEvent',
897 window => 'SDL_WindowEvent',
898 key => 'SDL_KeyboardEvent',
899 edit => 'SDL_TextEditingEvent',
900 text => 'SDL_TextInputEvent',
901 motion => 'SDL_MouseMotionEvent',
902 button => 'SDL_MouseButtonEvent',
903 wheel => 'SDL_MouseWheelEvent',
904 jaxis => 'SDL_JoyAxisEvent',
905 jball => 'SDL_JoyBallEvent',
906 jhat => 'SDL_JoyHatEvent',
907 jbutton => 'SDL_JoyButtonEvent',
908 jdevice => 'SDL_JoyDeviceEvent',
909 caxis => 'SDL_ControllerAxisEvent',
910 cbutton => 'SDL_ControllerButtonEvent',
911 cdevice => 'SDL_ControllerDeviceEvent',
912 adevice => 'SDL_AudioDeviceEvent',
913 sensor => 'SDL_SensorEvent',
914 quit => 'SDL_QuitEvent',
915 user => 'SDL_UserEvent',
916 syswm => 'SDL_SysWMEvent',
917 tfinger => 'SDL_TouchFingerEvent',
918 mgesture => 'SDL_MultiGestureEvent',
919 dgesture => 'SDL_DollarGestureEvent',
920 drop => 'SDL_DropEvent',
921 padding => 'uint8[56]'
922 ]
923 );
924 ffi->type( '(opaque, opaque)->int' => 'SDL_EventFilter' );
925 attach events => {
926 SDL_PeepEvents =>
927 [ [ 'SDL_Event', 'int', 'SDL_EventAction', 'uint32', 'uint32' ] => 'int' ],
928 SDL_HasEvent => [ ['uint32'] => 'bool' ],
929 SDL_HasEvents => [ [ 'uint32', 'uint32' ] => 'bool' ],
930 SDL_FlushEvent => [ ['uint32'] ],
931 SDL_FlushEvents => [ [ 'uint32', 'uint32' ] ],
932 SDL_PollEvent => [ ['SDL_Event'] => 'int' ],
933 SDL_WaitEvent => [ ['SDL_Event'] => 'int' ],
934 SDL_WaitEventTimeout => [ [ 'SDL_Event', 'int' ] => 'int' ],
935 SDL_PushEvent => [ ['SDL_Event'] => 'int' ],
936 SDL_SetEventFilter => [ [ 'SDL_EventFilter', 'opaque' ] ],
937 SDL_GetEventFilter => [ [ 'SDL_EventFilter', 'opaque' ] => 'bool' ],
938 SDL_AddEventWatch => [ [ 'SDL_EventFilter', 'opaque' ] ],
939 SDL_DelEventWatch => [ [ 'SDL_EventFilter', 'opaque' ] ],
940 SDL_FilterEvents => [ [ 'SDL_EventFilter', 'opaque' ] ]
941 };
942 #
943 sub SDL_QUERY () {-1}
944 sub SDL_IGNORE () {0}
945 sub SDL_DISABLE () {0}
946 sub SDL_ENABLE () {1}
947 #
948 ffi->attach( SDL_EventState => [ 'uint32', 'int' ] => 'uint8' );
949 sub SDL_GetEventState ($type) { SDL_EventState( $type, SDL_QUERY ) }
950 ffi->attach( SDL_RegisterEvents => ['int'] => 'uint32' );
951  
952 # From src/events/SDL_mouse_c.h
953 package SDL2::Cursor {
954 use SDL2::Utils;
955 has
956 next => 'opaque', # SDL_Cursor
957 driverdata => 'opaque' # void
958 };
959  
960 # From SDL_mouse.h
961 ffi->attach( SDL_GetMouseFocus => [] => 'SDL_Window' );
962 ffi->attach( SDL_GetMouseState => [ 'int', 'int' ] => 'uint32' );
963 ffi->attach( SDL_GetGlobalMouseState => [ 'int', 'int' ] => 'uint32' );
964 ffi->attach( SDL_GetRelativeMouseState => [ 'int', 'int' ] => 'uint32' );
965 ffi->attach( SDL_WarpMouseInWindow => [ 'SDL_Window', 'int', 'int' ] );
966 ffi->attach( SDL_SetRelativeMouseMode => ['bool'] => 'int' );
967 ffi->attach( SDL_CaptureMouse => ['bool'] => 'int' );
968 ffi->attach( SDL_GetRelativeMouseMode => [] => 'bool' );
969 ffi->attach(
970 SDL_CreateCursor => [ 'uint8', 'uint8', 'int', 'int', 'int', 'int' ] => 'SDL_Cursor' );
971 ffi->attach( SDL_CreateSystemCursor => ['SDL_SystemCursor'] => 'SDL_Cursor' );
972 ffi->attach( SDL_SetCursor => ['SDL_Cursor'] );
973 ffi->attach( SDL_GetCursor => [] => 'SDL_Cursor' );
974 ffi->attach( SDL_GetDefaultCursor => [] => 'SDL_Cursor' );
975 ffi->attach( SDL_FreeCursor => [] => 'SDL_Cursor' );
976 ffi->attach( SDL_ShowCursor => ['int'] => 'int' );
977  
978 # https://wiki.libsdl.org/CategoryPixels
979 sub SDL_ALPHA_OPAQUE() {255}
980 sub SDL_ALPHA_TRANSPARENT() {0}
981 sub SDL_DEFINE_PIXELFOURCC ( $A, $B, $C, $D ) { SDL_FOURCC( $A, $B, $C, $D ) }
982  
983 sub SDL_DEFINE_PIXELFORMAT ( $type, $order, $layout, $bits, $bytes ) {
984 ( ( 1 << 28 ) | ( ($type) << 24 ) | ( ($order) << 20 ) | ( ($layout) << 16 )
985 | ( ($bits) << 8 ) | ( ($bytes) << 0 ) )
986 }
987 sub SDL_PIXELFLAG ($X) { ( ( ($X) >> 28 ) & 0x0F ) }
988 sub SDL_PIXELTYPE ($X) { ( ( ($X) >> 24 ) & 0x0F ) }
989 sub SDL_PIXELORDER ($X) { ( ( ($X) >> 20 ) & 0x0F ) }
990 sub SDL_PIXELLAYOUT ($X) { ( ( ($X) >> 16 ) & 0x0F ) }
991 sub SDL_BITSPERPIXEL ($X) { ( ( ($X) >> 8 ) & 0xFF ) }
992  
993 sub SDL_BYTESPERPIXEL ($X) {
994 (
995 SDL_ISPIXELFORMAT_FOURCC($X) ? (
996 (
997 ( ($X) == SDL_PIXELFORMAT_YUY2() ) ||
998 ( ($X) == SDL_PIXELFORMAT_UYVY() ) ||
999 ( ($X) == SDL_PIXELFORMAT_YVYU() )
1000 ) ? 2 : 1
1001 ) :
1002 ( ( ($X) >> 0 ) & 0xFF )
1003 )
1004 }
1005  
1006 sub SDL_ISPIXELFORMAT_INDEXED ($format) {
1007 (
1008 !SDL_ISPIXELFORMAT_FOURCC($format) &&
1009 ( ( SDL_PIXELTYPE($format) == SDL_PIXELTYPE_INDEX1() ) ||
1010 ( SDL_PIXELTYPE($format) == SDL_PIXELTYPE_INDEX4() ) ||
1011 ( SDL_PIXELTYPE($format) == SDL_PIXELTYPE_INDEX8() ) )
1012 )
1013 }
1014  
1015 sub SDL_ISPIXELFORMAT_PACKED ($format) {
1016 (
1017 !SDL_ISPIXELFORMAT_FOURCC($format) &&
1018 ( ( SDL_PIXELTYPE($format) == SDL_PIXELTYPE_PACKED8() ) ||
1019 ( SDL_PIXELTYPE($format) == SDL_PIXELTYPE_PACKED16() ) ||
1020 ( SDL_PIXELTYPE($format) == SDL_PIXELTYPE_PACKED32() ) )
1021 )
1022 }
1023  
1024 sub SDL_ISPIXELFORMAT_ARRAY ($format) {
1025 (
1026 !SDL_ISPIXELFORMAT_FOURCC($format) &&
1027 ( ( SDL_PIXELTYPE($format) == SDL_PIXELTYPE_ARRAYU8() ) ||
1028 ( SDL_PIXELTYPE($format) == SDL_PIXELTYPE_ARRAYU16() ) ||
1029 ( SDL_PIXELTYPE($format) == SDL_PIXELTYPE_ARRAYU32() ) ||
1030 ( SDL_PIXELTYPE($format) == SDL_PIXELTYPE_ARRAYF16() ) ||
1031 ( SDL_PIXELTYPE($format) == SDL_PIXELTYPE_ARRAYF32() ) )
1032 )
1033 }
1034  
1035 sub SDL_ISPIXELFORMAT_ALPHA ($format) {
1036 (
1037 (
1038 SDL_ISPIXELFORMAT_PACKED($format) &&
1039 ( ( SDL_PIXELORDER($format) == SDL_PACKEDORDER_ARGB() ) ||
1040 ( SDL_PIXELORDER($format) == SDL_PACKEDORDER_RGBA() ) ||
1041 ( SDL_PIXELORDER($format) == SDL_PACKEDORDER_ABGR() ) ||
1042 ( SDL_PIXELORDER($format) == SDL_PACKEDORDER_BGRA() ) )
1043 ) ||
1044 (
1045 SDL_ISPIXELFORMAT_ARRAY($format) &&
1046 ( ( SDL_PIXELORDER($format) == SDL_ARRAYORDER_ARGB() ) ||
1047 ( SDL_PIXELORDER($format) == SDL_ARRAYORDER_RGBA() ) ||
1048 ( SDL_PIXELORDER($format) == SDL_ARRAYORDER_ABGR() ) ||
1049 ( SDL_PIXELORDER($format) == SDL_ARRAYORDER_BGRA() ) )
1050 )
1051 )
1052 }
1053  
1054 #/* The flag is set to 1 because 0x1? is not in the printable ASCII range */
1055 sub SDL_ISPIXELFORMAT_FOURCC ($format) { ( ($format) && ( SDL_PIXELFLAG($format) != 1 ) ) }
1056 sub SDL_PIXELFORMAT_UNKNOWN () {0}
1057  
1058 sub SDL_PIXELFORMAT_INDEX1LSB () {
1059 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_INDEX1(), SDL_BITMAPORDER_4321(), 0, 1, 0 );
1060 }
1061  
1062 sub SDL_PIXELFORMAT_INDEX1MSB () {
1063 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_INDEX1(), SDL_BITMAPORDER_1234(), 0, 1, 0 );
1064 }
1065  
1066 sub SDL_PIXELFORMAT_INDEX4LSB () {
1067 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_INDEX4(), SDL_BITMAPORDER_4321(), 0, 4, 0 );
1068 }
1069  
1070 sub SDL_PIXELFORMAT_INDEX4MSB () {
1071 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_INDEX4(), SDL_BITMAPORDER_1234(), 0, 4, 0 );
1072 }
1073  
1074 sub SDL_PIXELFORMAT_INDEX8 () {
1075 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_INDEX8(), 0, 0, 8, 1 );
1076 }
1077  
1078 sub SDL_PIXELFORMAT_RGB332 () {
1079 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED8(), SDL_PACKEDORDER_XRGB(),
1080 SDL_PACKEDLAYOUT_332(), 8, 1 );
1081 }
1082  
1083 sub SDL_PIXELFORMAT_RGB444 () {
1084 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED16(), SDL_PACKEDORDER_XRGB(),
1085 SDL_PACKEDLAYOUT_4444(), 12, 2 );
1086 }
1087  
1088 sub SDL_PIXELFORMAT_RGB555 () {
1089 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED16(), SDL_PACKEDORDER_XRGB(),
1090 SDL_PACKEDLAYOUT_1555(), 15, 2 );
1091 }
1092  
1093 sub SDL_PIXELFORMAT_BGR555 () {
1094 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED16(), SDL_PACKEDORDER_XBGR(),
1095 SDL_PACKEDLAYOUT_1555(), 15, 2 );
1096 }
1097  
1098 sub SDL_PIXELFORMAT_ARGB4444 () {
1099 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED16(), SDL_PACKEDORDER_ARGB(),
1100 SDL_PACKEDLAYOUT_4444(), 16, 2 );
1101 }
1102  
1103 sub SDL_PIXELFORMAT_RGBA4444 () {
1104 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED16(), SDL_PACKEDORDER_RGBA(),
1105 SDL_PACKEDLAYOUT_4444(), 16, 2 );
1106 }
1107  
1108 sub SDL_PIXELFORMAT_ABGR4444 () {
1109 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED16(), SDL_PACKEDORDER_ABGR(),
1110 SDL_PACKEDLAYOUT_4444(), 16, 2 );
1111 }
1112  
1113 sub SDL_PIXELFORMAT_BGRA4444 () {
1114 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED16(), SDL_PACKEDORDER_BGRA(),
1115 SDL_PACKEDLAYOUT_4444(), 16, 2 );
1116 }
1117  
1118 sub SDL_PIXELFORMAT_ARGB1555 () {
1119 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED16(), SDL_PACKEDORDER_ARGB(),
1120 SDL_PACKEDLAYOUT_1555(), 16, 2 );
1121 }
1122  
1123 sub SDL_PIXELFORMAT_RGBA5551 () {
1124 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED16(), SDL_PACKEDORDER_RGBA(),
1125 SDL_PACKEDLAYOUT_5551(), 16, 2 );
1126 }
1127  
1128 sub SDL_PIXELFORMAT_ABGR1555 () {
1129 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED16(), SDL_PACKEDORDER_ABGR(),
1130 SDL_PACKEDLAYOUT_1555(), 16, 2 );
1131 }
1132  
1133 sub SDL_PIXELFORMAT_BGRA5551 () {
1134 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED16(), SDL_PACKEDORDER_BGRA(),
1135 SDL_PACKEDLAYOUT_5551(), 16, 2 );
1136 }
1137  
1138 sub SDL_PIXELFORMAT_RGB565 () {
1139 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED16(), SDL_PACKEDORDER_XRGB(),
1140 SDL_PACKEDLAYOUT_565(), 16, 2 );
1141 }
1142  
1143 sub SDL_PIXELFORMAT_BGR565 () {
1144 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED16(), SDL_PACKEDORDER_XBGR(),
1145 SDL_PACKEDLAYOUT_565(), 16, 2 );
1146 }
1147  
1148 sub SDL_PIXELFORMAT_RGB24 () {
1149 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_ARRAYU8(), SDL_ARRAYORDER_RGB(), 0, 24, 3 );
1150 }
1151  
1152 sub SDL_PIXELFORMAT_BGR24 () {
1153 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_ARRAYU8(), SDL_ARRAYORDER_BGR(), 0, 24, 3 );
1154 }
1155  
1156 sub SDL_PIXELFORMAT_RGB888 () {
1157 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED32(), SDL_PACKEDORDER_XRGB(),
1158 SDL_PACKEDLAYOUT_8888(), 24, 4 );
1159 }
1160  
1161 sub SDL_PIXELFORMAT_RGBX8888 () {
1162 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED32(), SDL_PACKEDORDER_RGBX(),
1163 SDL_PACKEDLAYOUT_8888(), 24, 4 );
1164 }
1165  
1166 sub SDL_PIXELFORMAT_BGR888 () {
1167 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED32(), SDL_PACKEDORDER_XBGR(),
1168 SDL_PACKEDLAYOUT_8888(), 24, 4 );
1169 }
1170  
1171 sub SDL_PIXELFORMAT_BGRX8888 () {
1172 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED32(), SDL_PACKEDORDER_BGRX(),
1173 SDL_PACKEDLAYOUT_8888(), 24, 4 );
1174 }
1175 define pixel_format => [
1176 [ SDL_PIXELFORMAT_ARGB8888 => sub () {
1177 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED32(), SDL_PACKEDORDER_ARGB(),
1178 SDL_PACKEDLAYOUT_8888(), 32, 4 );
1179 }
1180 ]
1181 ];
1182  
1183 sub SDL_PIXELFORMAT_RGBA8888 () {
1184 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED32(), SDL_PACKEDORDER_RGBA(),
1185 SDL_PACKEDLAYOUT_8888(), 32, 4 );
1186 }
1187  
1188 sub SDL_PIXELFORMAT_ABGR8888 () {
1189 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED32(), SDL_PACKEDORDER_ABGR(),
1190 SDL_PACKEDLAYOUT_8888(), 32, 4 );
1191 }
1192  
1193 sub SDL_PIXELFORMAT_BGRA8888 () {
1194 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED32(), SDL_PACKEDORDER_BGRA(),
1195 SDL_PACKEDLAYOUT_8888(), 32, 4 );
1196 }
1197  
1198 sub SDL_PIXELFORMAT_ARGB2101010 () {
1199 SDL_DEFINE_PIXELFORMAT( SDL_PIXELTYPE_PACKED32(), SDL_PACKEDORDER_ARGB(),
1200 SDL_PACKEDLAYOUT_2101010(),
1201 32, 4 );
1202 }
1203  
1204 # /* Aliases for RGBA byte arrays of color data, for the current platform */
1205 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
1206 # SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_RGBA8888,
1207 # SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_ARGB8888,
1208 # SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_BGRA8888,
1209 # SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_ABGR8888,
1210 #else
1211 # SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_ABGR8888,
1212 # SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_BGRA8888,
1213 # SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_ARGB8888,
1214 # SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_RGBA8888,
1215 #endif
1216 sub SDL_PIXELFORMAT_YV12 () {
1217 SDL_DEFINE_PIXELFOURCC( 'Y', 'V', '1', '2' );
1218 }
1219  
1220 sub SDL_PIXELFORMAT_IYUV () {
1221 SDL_DEFINE_PIXELFOURCC( 'I', 'Y', 'U', 'V' );
1222 }
1223  
1224 sub SDL_PIXELFORMAT_YUY2 () {
1225 SDL_DEFINE_PIXELFOURCC( 'Y', 'U', 'Y', '2' );
1226 }
1227  
1228 sub SDL_PIXELFORMAT_UYVY () {
1229 SDL_DEFINE_PIXELFOURCC( 'U', 'Y', 'V', 'Y' );
1230 }
1231  
1232 sub SDL_PIXELFORMAT_YVYU () {
1233 SDL_DEFINE_PIXELFOURCC( 'Y', 'V', 'Y', 'U' );
1234 }
1235  
1236 sub SDL_PIXELFORMAT_NV12 () {
1237 SDL_DEFINE_PIXELFOURCC( 'N', 'V', '1', '2' );
1238 }
1239  
1240 sub SDL_PIXELFORMAT_NV21 () {
1241 SDL_DEFINE_PIXELFOURCC( 'N', 'V', '2', '1' );
1242 }
1243  
1244 sub SDL_PIXELFORMAT_EXTERNAL_OES () {
1245 SDL_DEFINE_PIXELFOURCC( 'O', 'E', 'S', ' ' );
1246 }
1247  
1248 # include/SDL_stdinc.h
1249 sub SDL_FOURCC ( $A, $B, $C, $D ) { $A << 0 | $B << 8 | $C << 16 | $D << 24 }
1250  
1251 # Unsorted - https://github.com/libsdl-org/SDL/blob/c59d4dcd38c382a1e9b69b053756f1139a861574/include/SDL_keycode.h
1252 # https://github.com/libsdl-org/SDL/blob/c59d4dcd38c382a1e9b69b053756f1139a861574/include/SDL_scancode.h#L151
1253 attach(
1254 all => {
1255  
1256 # Unknown...
1257 SDL_SetMainReady => [ [] => 'void' ]
1258 }
1259 );
1260 define SDL_Mouse => [
1261 [ SDL_BUTTON => sub ($x) { 1 << ( ($x) - 1 ) } ],
1262 [ SDL_BUTTON_LEFT => 1 ],
1263 [ SDL_BUTTON_MIDDLE => 2 ],
1264 [ SDL_BUTTON_RIGHT => 3 ],
1265 [ SDL_BUTTON_X1 => 4 ],
1266 [ SDL_BUTTON_X2 => 5 ],
1267 [ SDL_BUTTON_LMASK => sub () { SDL_BUTTON( SDL_BUTTON_LEFT() ); } ],
1268 [ SDL_BUTTON_MMASK => sub () { SDL_BUTTON( SDL_BUTTON_MIDDLE() ); } ],
1269 [ SDL_BUTTON_RMASK => sub () { SDL_BUTTON( SDL_BUTTON_RIGHT() ); } ],
1270 [ SDL_BUTTON_X1MASK => sub () { SDL_BUTTON( SDL_BUTTON_X1() ); } ],
1271 [ SDL_BUTTON_X2MASK => sub () { SDL_BUTTON( SDL_BUTTON_X2() ); } ]
1272 ];
1273  
1274 # TODO
1275 package SDL2::assert_data { };
1276  
1277 package SDL2::atomic_t {
1278 use SDL2::Utils;
1279 has value => 'int';
1280 };
1281  
1282 package SDL2::AudioDeviceEvent { };
1283  
1284 package SDL2::AudioStream { };
1285  
1286 package SDL2::Color { };
1287  
1288 package SDL2::ControllerAxisEvent { };
1289  
1290 package SDL2::ControllerButtonEvent { };
1291  
1292 package SDL2::ControllerDeviceEvent { };
1293  
1294 package SDL2::DisplayMode { };
1295  
1296 package SDL2::DollarGestureEvent { };
1297  
1298 package SDL2::DropEvent { };
1299  
1300 package SDL2::Event { };
1301  
1302 package SDL2::Finger {
1303 use SDL2::Utils;
1304 has
1305 id => 'sint64', # SDL_FingerID
1306 x => 'float',
1307 y => 'float',
1308 pressure => 'float';
1309 };
1310  
1311 package SDL2::GameControllerButtonBind { };
1312  
1313 package SDL2::_GameController { };
1314  
1315 package SDL2::GameCrontroller { };
1316  
1317 package SDL2::_Haptic { };
1318  
1319 package SDL2::Haptic { };
1320  
1321 package SDL2::HapticCondition { };
1322  
1323 package SDL2::HapticConstant { };
1324  
1325 package SDL2::HapticCustom { };
1326  
1327 package SDL2::HapticDirection { };
1328  
1329 package SDL2::HapticEffect { };
1330  
1331 package SDL2::HapticLeftRight { };
1332  
1333 package SDL2::HapticPeriodic { };
1334  
1335 package SDL2::HapticRamp { };
1336  
1337 package SDL2::JoyAxisEvent { };
1338  
1339 package SDL2::JoyBallEvent { };
1340  
1341 package SDL2::JoyButtonEvent { };
1342  
1343 package SDL2::JoyDeviceEvent { };
1344  
1345 package SDL2::JoyHatEvent { };
1346  
1347 package SDL2::Joystick { };
1348  
1349 package SDL2::JoystickGUID { };
1350  
1351 package SDL2::JoystickID { };
1352  
1353 package SDL2::_JoyStick { };
1354  
1355 package SDL2::KeyboardEvent { };
1356  
1357 package SDL2::Keysym {
1358 use SDL2::Utils;
1359 has
1360 scancode => 'opaque', # SDL_Scancode
1361 sym => 'opaque', # SDL_Keycode
1362 mod => 'uint16',
1363 unused => 'uint32';
1364 };
1365  
1366 package SDL2::MessageBoxButtonData {
1367 use SDL2::Utils;
1368 has
1369 flags => 'uint32',
1370 buttonid => 'int',
1371 text => 'opaque' # 'string'
1372 };
1373  
1374 package SDL2::MessageBoxColor {
1375 use SDL2::Utils;
1376 has
1377 r => 'uint8',
1378 g => 'uint8',
1379 b => 'uint8';
1380 };
1381  
1382 package SDL2::MessageBoxColorScheme {
1383 use SDL2::Utils;
1384 has colors => 'opaque' # SDL_MessageBoxColor colors[SDL_MESSAGEBOX_COLOR_MAX];
1385 };
1386 attach messagebox => {
1387  
1388 #SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, ("R.E.L.I.V.E. " + BuildString()).c_str(), msg, nullptr);
1389 SDL_ShowSimpleMessageBox => [ [ 'uint32', 'string', 'string', 'SDL_Window' ], 'int' ]
1390 };
1391  
1392 package SDL2::MessageBoxData {
1393 use SDL2::Utils;
1394 has
1395 flags => 'uint32',
1396 window => 'opaque', # SDL_Window*
1397 title => 'opaque', # string
1398 message => 'opaque', # string
1399 numbuttons => 'int',
1400 buttons => 'opaque', # SDL_MessageBoxButtonData*
1401 colorScheme => 'opaque' # SDL_MessageBoxColorScheme *
1402 };
1403  
1404 package SDL2::MouseButtonEvent { };
1405  
1406 package SDL2::MouseMotionEvent { };
1407  
1408 package SDL2::MouseWheelEvent { };
1409  
1410 package SDL2::MultiGestureEvent { };
1411  
1412 package SDL2::Palette { };
1413  
1414 package SDL2::PixelFormat { };
1415  
1416 package SDL2::QuitEvent { };
1417  
1418 package SDL2::Renderer { };
1419  
1420 package SDL2::RendererInfo { };
1421  
1422 package SDL2::RWops { };
1423  
1424 package SDL2::SensorEvent { };
1425  
1426 package SDL2::SysWMEvent { };
1427  
1428 package SDL2::SysWMinfo { };
1429  
1430 package SDL2::Sensor { };
1431  
1432 package SDL2::SensorID { }; # type
1433  
1434 package SDL2::TextEditingEvent { };
1435  
1436 package SDL2::TextInputEvent { };
1437  
1438 package SDL2::TouchFingerEvent { };
1439  
1440 package SDL2::ControllerTouchpadEvent { };
1441  
1442 package SDL2::UserEvent { };
1443  
1444 package SDL2::WindowEvent { };
1445  
1446 package SDL2::Mixer { };
1447  
1448 package SDL2::Mixer::Mix::Chunk { };
1449  
1450 package SDL2::Mixer::Mix::Fading { };
1451  
1452 package SDL2::Mixer::Mix::MusicType { };
1453  
1454 package SDL2::Mixer::Mix::Music { };
1455  
1456 package SDL2::Mixer::Mix::Chunk { };
1457  
1458 package SDL2::Mixer::Chunk { };
1459  
1460 package SDL2::Mixer::Fading { };
1461  
1462 package SDL2::Mixer::MusicType { };
1463  
1464 package SDL2::Mixer::Music { };
1465  
1466 package SDL2::Mixer::Chunk { };
1467  
1468 package SDL2::Image { };
1469  
1470 package SDL2::iconv_t { }; # int ptr
1471  
1472 package SDL2::WindowShapeMode { };
1473  
1474 package SDL2::WindowShapeParams { }; # union
1475  
1476 package SDL2::TTF { };
1477  
1478 package SDL2::TTF::Image { };
1479  
1480 package SDL2::TTF::Font { };
1481  
1482 package SDL2::TTF::PosBuf { };
1483  
1484 package SDL2::Net { };
1485  
1486 package SDL2::RTF { };
1487  
1488 package SDL2::RTF::Context { };
1489  
1490 package SDL2::RTF::FontEngine { };
1491  
1492 package SDL2::Mutex { };
1493  
1494 package SDL2::Semaphore { };
1495  
1496 package SDL2::Sem { };
1497  
1498 package SDL2::Cond { };
1499  
1500 package SDL2::Thread {
1501 use SDL2::Utils;
1502 has();
1503 }
1504  
1505 package SDL2::Locale {
1506 use SDL2::Utils;
1507 has
1508 language => 'opaque', # string
1509 country => 'opaque' # string
1510 };
1511  
1512 package SDL2::ShapeDriver { };
1513  
1514 package SDL2::VideoDisplay {
1515 use SDL2::Utils;
1516 has name => 'opaque', # string
1517 max_display_modes => 'int',
1518 num_display_modes => 'int',
1519 display_modes => 'opaque', # SDL_DisplayMode
1520 desktop_mode => 'opaque', # SDL_DisplayMode
1521 orientation => 'opaque', # SDL_DisplayOrientation
1522 fullscreen_window => 'opaque', # SDL_Window
1523 device => 'opaque', # SDL_VideoDevice
1524 driverdata => 'opaque'; # void *
1525 };
1526  
1527 package SDL2::VideoDevice { };
1528  
1529 package SDL2::WindowUserData {
1530 use SDL2::Utils;
1531 has name => 'opaque', # string
1532 data => 'opaque', # void *
1533 next => 'opaque'; # SDL_WindowUserData
1534 };
1535  
1536 package SDL2::SysWMinfo { };
1537  
1538 package SDL2::VideoBootStrap { };
1539  
1540 package SDL2::SpinLock { };
1541  
1542 package SDL2::AtomicLock { };
1543  
1544 package SDL2::AudioFormat { };
1545  
1546 #warn SDL2::SDLK_UP();
1547 #warn SDL2::SDLK_DOWN();
1548 # https://github.com/libsdl-org/SDL/blob/main/include/SDL_hints.h
1549 # Export symbols!
1550 our @EXPORT_OK = map {@$_} values %EXPORT_TAGS;
1551  
1552 #$EXPORT_TAGS{default} = []; # Export nothing by default
1553 $EXPORT_TAGS{all} = \@EXPORT_OK; # Export everything with :all tag
1554  
1555 #use Data::Dump;
1556 #ddx \%EXPORT_TAGS;
1557 #ddx \%SDL2::;
1558 # plan for the future
1559 package SDL3 { };
1560 };
1561 1;
1562  
1563 =encoding utf-8
1564  
1565 =head1 NAME
1566  
1567 SDL2::FFI - FFI Wrapper for SDL (Simple DirectMedia Layer) Development Library
1568  
1569 =head1 SYNOPSIS
1570  
1571 use SDL2::FFI qw[:all];
1572 die 'Error initializing SDL: ' . SDL_GetError() unless SDL_Init(SDL_INIT_VIDEO) == 0;
1573 my $win = SDL_CreateWindow( 'Example window!',
1574 SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_RESIZABLE );
1575 die 'Could not create window: ' . SDL_GetError() unless $win;
1576 my $event = SDL2::Event->new;
1577 SDL_Init(SDL_INIT_VIDEO);
1578 my $renderer = SDL_CreateRenderer( $win, -1, 0 );
1579 SDL_SetRenderDrawColor( $renderer, 242, 242, 242, 255 );
1580 do {
1581 SDL_WaitEventTimeout( $event, 10 );
1582 SDL_RenderClear($renderer);
1583 SDL_RenderPresent($renderer);
1584 } until $event->type == SDL_QUIT;
1585 SDL_DestroyRenderer($renderer);
1586 SDL_DestroyWindow($win);
1587 SDL_Quit();
1588  
1589 =head1 DESCRIPTION
1590  
1591 SDL2::FFI is an L<FFI::Platypus> backed bindings to the B<S>imple
1592 B<D>irectMedia B<L>ayer - a cross-platform development library designed to
1593 provide low level access to audio, keyboard, mouse, joystick, and graphics
1594 hardware.
1595  
1596 =head1 Initialization and Shutdown
1597  
1598 The functions in this category are used to set SDL up for use and generally
1599 have global effects in your program. These functions may be imported with the
1600 C<:init> or C<:default> tag.
1601  
1602 =head2 C<SDL_Init( ... )>
1603  
1604 Initializes the SDL library. This must be called before using most other SDL
1605 functions.
1606  
1607 SDL_Init( SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS );
1608  
1609 C<SDL_Init( ... )> simply forwards to calling L<< C<SDL_InitSubSystem( ...
1610 )>|/C<SDL_InitSubSystem( ... )> >>. Therefore, the two may be used
1611 interchangeably. Though for readability of your code L<< C<SDL_InitSubSystem(
1612 ... )>|/C<SDL_InitSubSystem( ... )> >> might be preferred.
1613  
1614 The file I/O (for example: L<< C<SDL_RWFromFile( ... )>|/C<SDL_RWFromFile( ...
1615 )> >>) and threading (L<< C<SDL_CreateThread( ... )>|/C<SDL_CreateThread( ...
1616 )> >>) subsystems are initialized by default. Message boxes ( L<<
1617 C<SDL_ShowSimpleMessageBox( ... )>|/C<SDL_ShowSimpleMessageBox( ... )> >> )
1618 also attempt to work without initializing the video subsystem, in hopes of
1619 being useful in showing an error dialog when SDL_Init fails. You must
1620 specifically initialize other subsystems if you use them in your application.
1621  
1622 Logging (such as L<< C<SDL_Log( ... )>|/C<SDL_Log( ... )> >> ) works without
1623 initialization, too.
1624  
1625 Expected parameters include:
1626  
1627 =over
1628  
1629 =item C<flags> which may be any be imported with the L<< C<:init>|SDL2::Enum/C<:init> >> tag and may be OR'd together
1630  
1631 =back
1632  
1633 Subsystem initialization is ref-counted, you must call L<< C<SDL_QuitSubSystem(
1634 ... )>|/C<SDL_QuitSubSystem( ... )> >> for each L<< C<SDL_InitSubSystem( ...
1635 )>|/C<SDL_InitSubSystem( ... )> >> to correctly shutdown a subsystem manually
1636 (or call L<< C<SDL_Quit( )>|/C<SDL_Quit( )> >> to force shutdown). If a
1637 subsystem is already loaded then this call will increase the ref-count and
1638 return.
1639  
1640 Returns C<0> on success or a negative error code on failure; call L<<
1641 C<SDL_GetError( )>|/C<SDL_GetError( )> >> for more information.
1642  
1643 =head2 C<SDL_InitSubSystem( ... )>
1644  
1645 Compatibility function to initialize the SDL library.
1646  
1647 In SDL2, this function and L<< C<SDL_Init( ... )>|/C<SDL_Init( ... )> >> are
1648 interchangeable.
1649  
1650 SDL_InitSubSystem( SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS );
1651  
1652 Expected parameters include:
1653  
1654 =over
1655  
1656 =item C<flags> which may be any be imported with the L<< C<:init>|SDL2::Enum/C<:init> >> tag and may be OR'd together.
1657  
1658 =back
1659  
1660 Returns C<0> on success or a negative error code on failure; call L<<
1661 C<SDL_GetError( )>|/C<SDL_GetError( )> >> for more information.
1662  
1663 =head2 C<SDL_Quit( )>
1664  
1665 Clean up all initialized subsystems.
1666  
1667 SDL_Quit( );
1668  
1669 You should call this function even if you have already shutdown each
1670 initialized subsystem with L<< C<SDL_QuitSubSystem( )>|/C<SDL_QuitSubSystem( )>
1671 >>. It is safe to call this function even in the case of errors in
1672 initialization.
1673  
1674 If you start a subsystem using a call to that subsystem's init function (for
1675 example L<< C<SDL_VideoInit( )>|/C<SDL_VideoInit( )> >>) instead of L<<
1676 C<SDL_Init( ... )>|/C<SDL_Init( ... )> >> or L<< C<SDL_InitSubSystem( ...
1677 )>|/C<SDL_InitSubSystem( ... )> >>, then you must use that subsystem's quit
1678 function (L<< C<SDL_VideoQuit( )>|/C<SDL_VideoQuit( )> >>) to shut it down
1679 before calling C<SDL_Quit( )>. But generally, you should not be using those
1680 functions directly anyhow; use L<< C<SDL_Init( ... )>|/C<SDL_Init( ... )> >>
1681 instead.
1682  
1683 You can use this function in an C<END { ... }> block to ensure that it is run
1684 when your application is shutdown.
1685  
1686 =head2 C<SDL_QuitSubSystem( ... )>
1687  
1688 Shut down specific SDL subsystems.
1689  
1690 SDL_QuitSubSystem( SDL_INIT_VIDEO );
1691  
1692 If you start a subsystem using a call to that subsystem's init function (for
1693 example L<< C<SDL_VideoInit( )> |/C<SDL_VideoInit( )> >>) instead of L<<
1694 C<SDL_Init( ... )>|/C<SDL_Init( ... )> >> or L<< C<SDL_InitSubSystem( ...
1695 )>|/C<SDL_InitSubSystem( ... )> >>, L<< C<SDL_QuitSubSystem( ...
1696 )>|/C<SDL_QuitSubSystem( ... )> >> and L<< C<SDL_WasInit( ...
1697 )>|/C<SDL_WasInit( ... )> >> will not work. You will need to use that
1698 subsystem's quit function ( L<< C<SDL_VideoQuit( )>|/C<SDL_VideoQuit( )> >>
1699 directly instead. But generally, you should not be using those functions
1700 directly anyhow; use L<< C<SDL_Init( ... )>|/C<SDL_Init( ... )> >> instead.
1701  
1702 You still need to call L<< C<SDL_Quit( )>|/C<SDL_Quit( )> >> even if you close
1703 all open subsystems with L<< C<SDL_QuitSubSystem( ... )>|/C<SDL_QuitSubSystem(
1704 ... )> >>.
1705  
1706 Expected parameters include:
1707  
1708 =over
1709  
1710 =item C<flags> which may be any be imported with the L<< C<:init>|SDL2::Enum/C<:init> >> tag and may be OR'd together.
1711  
1712 =back
1713  
1714 =head2 C<SDL_WasInit( ... )>
1715  
1716 Get a mask of the specified subsystems which are currently initialized.
1717  
1718 SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO );
1719 warn SDL_WasInit( SDL_INIT_TIMER ); # false
1720 warn SDL_WasInit( SDL_INIT_VIDEO ); # true (32 == SDL_INIT_VIDEO)
1721 my $mask = SDL_WasInit( );
1722 warn 'video init!' if ($mask & SDL_INIT_VIDEO); # yep
1723 warn 'video timer!' if ($mask & SDL_INIT_TIMER); # nope
1724  
1725 Expected parameters include:
1726  
1727 =over
1728  
1729 =item C<flags> which may be any be imported with the L<< C<:init>|SDL2::Enum/C<:init> >> tag and may be OR'd together.
1730  
1731 =back
1732  
1733 If C<flags> is C<0>, it returns a mask of all initialized subsystems, otherwise
1734 it returns the initialization status of the specified subsystems.
1735  
1736 The return value does not include C<SDL_INIT_NOPARACHUTE>.
1737  
1738 =head1 Configuration Variables
1739  
1740 This category contains functions to set and get configuration hints, as well as
1741 listing each of them alphabetically.
1742  
1743 The convention for naming hints is C<SDL_HINT_X>, where C<SDL_X> is the
1744 environment variable that can be used to override the default. You may import
1745 those recognised by SDL2 with the L<< C<:hints>|SDL2::Enum/C<:hints> >> tag.
1746  
1747 In general these hints are just that - they may or may not be supported or
1748 applicable on any given platform, but they provide a way for an application or
1749 user to give the library a hint as to how they would like the library to work.
1750  
1751 =head2 C<SDL_SetHintWithPriority( ... )>
1752  
1753 Set a hint with a specific priority.
1754  
1755 SDL_SetHintWithPriority( SDL_EVENT_LOGGING, 2, SDL_HINT_OVERRIDE );
1756  
1757 The priority controls the behavior when setting a hint that already has a
1758 value. Hints will replace existing hints of their priority and lower.
1759 Environment variables are considered to have override priority.
1760  
1761 Expected parameters include:
1762  
1763 =over
1764  
1765 =item C<name>
1766  
1767 the hint to set
1768  
1769 =item C<value>
1770  
1771 the value of the hint variable
1772  
1773 =item C<priority>
1774  
1775 the priority level for the hint
1776  
1777 =back
1778  
1779 Returns a true if the hint was set, untrue otherwise.
1780  
1781 =head2 C<SDL_SetHint( ... )>
1782  
1783 Set a hint with normal priority.
1784  
1785 SDL_SetHint( SDL_HINT_XINPUT_ENABLED, 1 );
1786  
1787 Hints will not be set if there is an existing override hint or environment
1788 variable that takes precedence. You can use SDL_SetHintWithPriority( ) to set
1789 the hint with override priority instead.
1790  
1791 Expected parameters:
1792  
1793 =over
1794  
1795 =item C<name>
1796  
1797 the hint to set
1798  
1799 =item C<value>
1800  
1801 the value of the hint variable
1802  
1803 =back
1804  
1805 Returns a true value if the hint was set, untrue otherwise.
1806  
1807 =head2 C<SDL_GetHint( ... )>
1808  
1809 Get the value of a hint.
1810  
1811 SDL_GetHint( SDL_HINT_XINPUT_ENABLED );
1812  
1813 Expected parameters:
1814  
1815 =over
1816  
1817 =item C<name>
1818  
1819 the hint to query
1820  
1821 =back
1822  
1823 Returns the string value of a hint or an undefined value if the hint isn't set.
1824  
1825 =head2 C<SDL_GetHintBoolean( ... )>
1826  
1827 Get the boolean value of a hint variable.
1828  
1829 SDL_GetHintBoolean( SDL_HINT_XINPUT_ENABLED, 0);
1830  
1831 Expected parameters:
1832  
1833 =over
1834  
1835 =item C<name>
1836  
1837 the name of the hint to get the boolean value from
1838  
1839 =item C<default_value>
1840  
1841 the value to return if the hint does not exist
1842  
1843 =back
1844  
1845 Returns the boolean value of a hint or the provided default value if the hint
1846 does not exist.
1847  
1848 =head2 C<SDL_AddHintCallback( ... )>
1849  
1850 Add a function to watch a particular hint.
1851  
1852 my $cb = SDL_AddHintCallback(
1853 SDL_HINT_XINPUT_ENABLED,
1854 sub {
1855 my ($userdata, $name, $oldvalue, $newvalue) = @_;
1856 ...;
1857 },
1858 { time => time( ), clicks => 3 }
1859 );
1860  
1861 Expected parameters:
1862  
1863 =over
1864  
1865 =item C<name>
1866  
1867 the hint to watch
1868  
1869 =item C<callback>
1870  
1871 a code reference that will be called when the hint value changes
1872  
1873 =item C<userdata>
1874  
1875 a pointer to pass to the callback function
1876  
1877 =back
1878  
1879 Returns a pointer to a L<FFI::Platypus::Closure> which you may pass to L<<
1880 C<SDL_DelHintCallback( ... )>|/C<SDL_DelHintCallback( ... )> >>.
1881  
1882 =head2 C<SDL_DelHintCallback( ... )>
1883  
1884 Remove a callback watching a particular hint.
1885  
1886 SDL_AddHintCallback(
1887 SDL_HINT_XINPUT_ENABLED,
1888 $cb,
1889 { time => time( ), clicks => 3 }
1890 );
1891  
1892 Expected parameters:
1893  
1894 =over
1895  
1896 =item C<name>
1897  
1898 the hint to watch
1899  
1900 =item C<callback>
1901  
1902 L<FFI::Platypus::Closure> object returned by L<< C<SDL_AddHintCallback( ...
1903 )>|/C<SDL_AddHintCallback( ... )> >>
1904  
1905 =item C<userdata>
1906  
1907 a pointer to pass to the callback function
1908  
1909 =back
1910  
1911 =head2 C<SDL_ClearHints( )>
1912  
1913 Clear all hints.
1914  
1915 SDL_ClearHints( );
1916  
1917 This function is automatically called during L<< C<SDL_Quit( )>|/C<SDL_Quit( )>
1918 >>.
1919  
1920 =head1 Error Handling
1921  
1922 Functions in this category provide simple error message routines for SDL. L<<
1923 C<SDL_GetError( )>|/C<SDL_GetError( )> >> can be called for almost all SDL
1924 functions to determine what problems are occurring. Check the wiki page of each
1925 specific SDL function to see whether L<< C<SDL_GetError( )>|/C<SDL_GetError( )>
1926 >> is meaningful for them or not. These functions may be imported with the
1927 C<:error> tag.
1928  
1929 The SDL error messages are in English.
1930  
1931 =head2 C<SDL_SetError( ... )>
1932  
1933 Set the SDL error message for the current thread.
1934  
1935 Calling this function will replace any previous error message that was set.
1936  
1937 This function always returns C<-1>, since SDL frequently uses C<-1> to signify
1938 an failing result, leading to this idiom:
1939  
1940 if ($error_code) {
1941 return SDL_SetError( 'This operation has failed: %d', $error_code );
1942 }
1943  
1944 Expected parameters:
1945  
1946 =over
1947  
1948 =item C<fmt>
1949  
1950 a C<printf( )>-style message format string
1951  
1952 =item C<@params>
1953  
1954 additional parameters matching % tokens in the C<fmt> string, if any
1955  
1956 =back
1957  
1958 =head2 C<SDL_GetError( )>
1959  
1960 Retrieve a message about the last error that occurred on the current thread.
1961  
1962 warn SDL_GetError( );
1963  
1964 It is possible for multiple errors to occur before calling C<SDL_GetError( )>.
1965 Only the last error is returned.
1966  
1967 The message is only applicable when an SDL function has signaled an error. You
1968 must check the return values of SDL function calls to determine when to
1969 appropriately call C<SDL_GetError( )>. You should B<not> use the results of
1970 C<SDL_GetError( )> to decide if an error has occurred! Sometimes SDL will set
1971 an error string even when reporting success.
1972  
1973 SDL will B<not> clear the error string for successful API calls. You B<must>
1974 check return values for failure cases before you can assume the error string
1975 applies.
1976  
1977 Error strings are set per-thread, so an error set in a different thread will
1978 not interfere with the current thread's operation.
1979  
1980 The returned string is internally allocated and must not be freed by the
1981 application.
1982  
1983 Returns a message with information about the specific error that occurred, or
1984 an empty string if there hasn't been an error message set since the last call
1985 to L<< C<SDL_ClearError( )>|/C<SDL_ClearError( )> >>. The message is only
1986 applicable when an SDL function has signaled an error. You must check the
1987 return values of SDL function calls to determine when to appropriately call
1988 C<SDL_GetError( )>.
1989  
1990 =head2 C<SDL_GetErrorMsg( ... )>
1991  
1992 Get the last error message that was set for the current thread.
1993  
1994 my $x;
1995 warn SDL_GetErrorMsg($x, 300);
1996  
1997 This allows the caller to copy the error string into a provided buffer, but
1998 otherwise operates exactly the same as L<< C<SDL_GetError( )>|/C<SDL_GetError(
1999 )> >>.
2000  
2001 =over
2002  
2003 =item C<errstr>
2004  
2005 A buffer to fill with the last error message that was set for the current
2006 thread
2007  
2008 =item C<maxlen>
2009  
2010 The size of the buffer pointed to by the errstr parameter
2011  
2012 =back
2013  
2014 Returns the pointer passed in as the C<errstr> parameter.
2015  
2016 =head2 C<SDL_ClearError( )>
2017  
2018 Clear any previous error message for this thread.
2019  
2020 =head1 Log Handling
2021  
2022 Simple log messages with categories and priorities. These functions may be
2023 imported with the C<:logging> tag.
2024  
2025 By default, logs are quiet but if you're debugging SDL you might want:
2026  
2027 SDL_LogSetAllPriority( SDL_LOG_PRIORITY_WARN );
2028  
2029 Here's where the messages go on different platforms:
2030  
2031 Windows debug output stream
2032 Android log output
2033 Others standard error output (STDERR)
2034  
2035 Messages longer than the maximum size (4096 bytes) will be truncated.
2036  
2037 =head2 C<SDL_LogSetAllPriority( ... )>
2038  
2039 Set the priority of all log categories.
2040  
2041 SDL_LogSetAllPriority( SDL_LOG_PRIORITY_WARN );
2042  
2043 Expected parameters:
2044  
2045 =over
2046  
2047 =item C<priority>
2048  
2049 The SDL_LogPriority to assign. These may be imported with the L<<
2050 C<:logpriority>|/C<:logpriority> >> tag.
2051  
2052 =back
2053  
2054 =head2 C<SDL_LogSetPriority( ... )>
2055  
2056 Set the priority of all log categories.
2057  
2058 SDL_LogSetPriority( SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN );
2059  
2060 Expected parameters:
2061  
2062 =over
2063  
2064 =item C<category>
2065  
2066 The category to assign a priority to. These may be imported with the L<<
2067 C<:logcategory>|/C<:logcategory> >> tag.
2068  
2069 =item C<priority>
2070  
2071 The SDL_LogPriority to assign. These may be imported with the L<<
2072 C<:logpriority>|/C<:logpriority> >> tag.
2073  
2074 =back
2075  
2076 =head2 C<SDL_LogGetPriority( ... )>
2077  
2078 Get the priority of a particular log category.
2079  
2080 SDL_LogGetPriority( SDL_LOG_CATEGORY_ERROR );
2081  
2082 Expected parameters:
2083  
2084 =over
2085  
2086 =item C<category>
2087  
2088 The SDL_LogCategory to query. These may be imported with the L<<
2089 C<:logcategory>|/C<:logcategory> >> tag.
2090  
2091 =back
2092  
2093 =head2 C<SDL_LogGetPriority( ... )>
2094  
2095 Get the priority of a particular log category.
2096  
2097 SDL_LogGetPriority( SDL_LOG_CATEGORY_ERROR );
2098  
2099 Expected parameters:
2100  
2101 =over
2102  
2103 =item C<category>
2104  
2105 The SDL_LogCategory to query. These may be imported with the L<<
2106 C<:logcategory>|/C<:logcategory> >> tag.
2107  
2108 =back
2109  
2110 =head2 C<SDL_LogResetPriorities( )>
2111  
2112 Reset all priorities to default.
2113  
2114 SDL_LogResetPriorities( );
2115  
2116 This is called by L<< C<SDL_Quit( )>|/C<SDL_Quit( )> >>.
2117  
2118 =head2 C<SDL_Log( ... )>
2119  
2120 Log a message with C<SDL_LOG_CATEGORY_APPLICATION> and
2121 C<SDL_LOG_PRIORITY_INFO>.
2122  
2123 SDL_Log( 'HTTP Status: %s', $http->status );
2124  
2125 Expected parameters:
2126  
2127 =over
2128  
2129 =item C<fmt>
2130  
2131 A C<sprintf( )> style message format string.
2132  
2133 =item C<...>
2134  
2135 Any additional parameters matching C<%> tokens in the C<fmt> string, if any.
2136  
2137 =back
2138  
2139 =head2 C<SDL_LogVerbose( ... )>
2140  
2141 Log a message with C<SDL_LOG_PRIORITY_VERBOSE>.
2142  
2143 SDL_LogVerbose( 'Current time: %s [%ds exec]', +localtime( ), time - $^T );
2144  
2145 Expected parameters:
2146  
2147 =over
2148  
2149 =item C<category>
2150  
2151 The category of the message.
2152  
2153 =item C<fmt>
2154  
2155 A C<sprintf( )> style message format string.
2156  
2157 =item C<...>
2158  
2159 Additional parameters matching C<%> tokens in the C<fmt> string, if any.
2160  
2161 =back
2162  
2163 =head2 C<SDL_LogDebug( ... )>
2164  
2165 Log a message with C<SDL_LOG_PRIORITY_DEBUG>.
2166  
2167 SDL_LogDebug( 'Current time: %s [%ds exec]', +localtime( ), time - $^T );
2168  
2169 Expected parameters:
2170  
2171 =over
2172  
2173 =item C<category>
2174  
2175 The category of the message.
2176  
2177 =item C<fmt>
2178  
2179 A C<sprintf( )> style message format string.
2180  
2181 =item C<...>
2182  
2183 Additional parameters matching C<%> tokens in the C<fmt> string, if any.
2184  
2185 =back
2186  
2187 =head2 C<SDL_LogInfo( ... )>
2188  
2189 Log a message with C<SDL_LOG_PRIORITY_INFO>.
2190  
2191 SDL_LogInfo( 'Current time: %s [%ds exec]', +localtime( ), time - $^T );
2192  
2193 Expected parameters:
2194  
2195 =over
2196  
2197 =item C<category>
2198  
2199 The category of the message.
2200  
2201 =item C<fmt>
2202  
2203 A C<sprintf( )> style message format string.
2204  
2205 =item C<...>
2206  
2207 Additional parameters matching C<%> tokens in the C<fmt> string, if any.
2208  
2209 =back
2210  
2211 =head2 C<SDL_LogWarn( ... )>
2212  
2213 Log a message with C<SDL_LOG_PRIORITY_WARN>.
2214  
2215 SDL_LogWarn( 'Current time: %s [%ds exec]', +localtime( ), time - $^T );
2216  
2217 Expected parameters:
2218  
2219 =over
2220  
2221 =item C<category>
2222  
2223 The category of the message.
2224  
2225 =item C<fmt>
2226  
2227 A C<sprintf( )> style message format string.
2228  
2229 =item C<...>
2230  
2231 Additional parameters matching C<%> tokens in the C<fmt> string, if any.
2232  
2233 =back
2234  
2235 =head2 C<SDL_LogError( ... )>
2236  
2237 Log a message with C<SDL_LOG_PRIORITY_ERROR>.
2238  
2239 SDL_LogError( 'Current time: %s [%ds exec]', +localtime( ), time - $^T );
2240  
2241 Expected parameters:
2242  
2243 =over
2244  
2245 =item C<category>
2246  
2247 The category of the message.
2248  
2249 =item C<fmt>
2250  
2251 A C<sprintf( )> style message format string.
2252  
2253 =item C<...>
2254  
2255 Additional parameters matching C<%> tokens in the C<fmt> string, if any.
2256  
2257 =back
2258  
2259 =head2 C<SDL_LogCritical( ... )>
2260  
2261 Log a message with C<SDL_LOG_PRIORITY_CRITICAL>.
2262  
2263 SDL_LogCritical( 'Current time: %s [%ds exec]', +localtime( ), time - $^T );
2264  
2265 Expected parameters:
2266  
2267 =over
2268  
2269 =item C<category>
2270  
2271 The category of the message.
2272  
2273 =item C<fmt>
2274  
2275 A C<sprintf( )> style message format string.
2276  
2277 =item C<...>
2278  
2279 Additional parameters matching C<%> tokens in the C<fmt> string, if any.
2280  
2281 =back
2282  
2283 =head2 C<SDL_LogMessage( ... )>
2284  
2285 Log a message with the specified category and priority.
2286  
2287 SDL_LogMessage( SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_CRITICAL,
2288 'Current time: %s [%ds exec]', +localtime( ), time - $^T );
2289  
2290 Expected parameters:
2291  
2292 =over
2293  
2294 =item C<category>
2295  
2296 The category of the message.
2297  
2298 =item C<priority>
2299  
2300 The priority of the message.
2301  
2302 =item C<fmt>
2303  
2304 A C<sprintf( )> style message format string.
2305  
2306 =item C<...>
2307  
2308 Additional parameters matching C<%> tokens in the C<fmt> string, if any.
2309  
2310 =back
2311  
2312 =head2 C<SDL_LogSetOutputFunction( ... )>
2313  
2314 Replace the default log output function with one of your own.
2315  
2316 my $cb = SDL_LogSetOutputFunction( sub { ... }, {} );
2317  
2318 Expected parameters:
2319  
2320 =over
2321  
2322 =item C<callback>
2323  
2324 A coderef to call instead of the default callback.
2325  
2326 This coderef should expect the following parameters:
2327  
2328 =over
2329  
2330 =item C<userdata>
2331  
2332 What was passed as C<userdata> to C<SDL_LogSetOutputFunction( )>.
2333  
2334 =item C<category>
2335  
2336 The category of the message.
2337  
2338 =item C<priority>
2339  
2340 The priority of the message.
2341  
2342 =item C<message>
2343  
2344 The message being output.
2345  
2346 =back
2347  
2348 =item C<userdata>
2349  
2350 Data passed to the C<callback>.
2351  
2352 =back
2353  
2354 =head1 Querying SDL Version
2355  
2356 These functions are used to collect or display information about the version of
2357 SDL that is currently being used by the program or that it was compiled
2358 against.
2359  
2360 The version consists of three segments (C<X.Y.Z>)
2361  
2362 =over
2363  
2364 =item X - Major Version, which increments with massive changes, additions, and enhancements
2365  
2366 =item Y - Minor Version, which increments with backwards-compatible changes to the major revision
2367  
2368 =item Z - Patchlevel, which increments with fixes to the minor revision
2369  
2370 =back
2371  
2372 Example: The first version of SDL 2 was 2.0.0
2373  
2374 The version may also be reported as a 4-digit numeric value where the thousands
2375 place represents the major version, the hundreds place represents the minor
2376 version, and the tens and ones places represent the patchlevel (update
2377 version).
2378  
2379 Example: The first version number of SDL 2 was 2000
2380  
2381 =head2 C<SDL_GetVersion( ... )>
2382  
2383 Get the version of SDL that is linked against your program.
2384  
2385 my $ver = SDL2::Version->new;
2386 SDL_GetVersion( $ver );
2387  
2388 This function may be called safely at any time, even before L<< C<SDL_Init(
2389 )>|/C<SDL_Init( )> >>.
2390  
2391 Expected parameters include:
2392  
2393 =over
2394  
2395 =item C<version> - An SDL2::Version object which will be filled with the proper values
2396  
2397 =back
2398  
2399 =head1 Display and Window Management
2400  
2401 This category contains functions for handling display and window actions.
2402  
2403 These functions may be imported with the C<:video> tag.
2404  
2405 =head2 C<SDL_GetNumVideoDrivers( )>
2406  
2407 my $num = SDL_GetNumVideoDrivers( );
2408  
2409 Get the number of video drivers compiled into SDL.
2410  
2411 Returns a number >= 1 on success or a negative error code on failure; call L<<
2412 C<SDL_GetError( )>|/C<SDL_GetError( )> >> for more information.
2413  
2414 =head2 C<SDL_GetVideoDriver( ... )>
2415  
2416 Get the name of a built in video driver.
2417  
2418 CORE::say SDL_GetVideoDriver($_) for 0 .. SDL_GetNumVideoDrivers( ) - 1;
2419  
2420 The video drivers are presented in the order in which they are normally checked
2421 during initialization.
2422  
2423 Expected parameters include:
2424  
2425 =over
2426  
2427 =item C<index> - the index of a video driver
2428  
2429 =back
2430  
2431 Returns the name of the video driver with the given C<index>.
2432  
2433 =cut
2434  
2435 =head2 C<SDL_VideoInit( ... )>
2436  
2437 Initialize the video subsystem, optionally specifying a video driver.
2438  
2439 SDL_VideoInit( 'x11' );
2440  
2441 This function initializes the video subsystem, setting up a connection to the
2442 window manager, etc, and determines the available display modes and pixel
2443 formats, but does not initialize a window or graphics mode.
2444  
2445 If you use this function and you haven't used the SDL_INIT_VIDEO flag with
2446 either SDL_Init( ) or SDL_InitSubSystem( ), you should call SDL_VideoQuit( )
2447 before calling SDL_Quit( ).
2448  
2449 It is safe to call this function multiple times. SDL_VideoInit( ) will call
2450 SDL_VideoQuit( ) itself if the video subsystem has already been initialized.
2451  
2452 You can use SDL_GetNumVideoDrivers( ) and SDL_GetVideoDriver( ) to find a
2453 specific `driver_name`.
2454  
2455 Expected parameters include:
2456  
2457 =over
2458  
2459 =item C<driver_name> - the name of a video driver to initialize, or undef for the default driver
2460  
2461 =back
2462  
2463 Returns C<0> on success or a negative error code on failure; call L<<
2464 C<SDL_GetError( )>|/C<SDL_GetError( )> >> for more information.
2465  
2466 =head2 C<SDL_VideoQuit( )>
2467  
2468 Shut down the video subsystem, if initialized with L<< C<SDL_VideoInit(
2469 )>|/C<SDL_VideoInit( )> >>.
2470  
2471 SDL_VideoQuit( );
2472  
2473 This function closes all windows, and restores the original video mode.
2474  
2475 =head2 C<SDL_GetCurrentVideoDriver( )>
2476  
2477 Get the name of the currently initialized video driver.
2478  
2479 my $driver = SDL_GetCurrentVideoDriver( );
2480  
2481 Returns the name of the current video driver or NULL if no driver has been
2482 initialized.
2483  
2484 =head2 C<SDL_GetNumVideoDisplays( )>
2485  
2486 Get the number of available video displays.
2487  
2488 my $screens = SDL_GetNumVideoDisplays( );
2489  
2490 Returns a number >= 1 or a negative error code on failure; call L<<
2491 C<SDL_GetError( )>|/C<SDL_GetError( )> >> for more information.
2492  
2493 =head2 C<SDL_GetDisplayName( ... )>
2494  
2495  
2496 Get the name of a display in UTF-8 encoding.
2497  
2498 my $screen = SDL_GetDisplayName( 0 );
2499  
2500 Expected parameters include:
2501  
2502 =over
2503  
2504 =item C<displayIndex> - the index of display from which the name should be queried
2505  
2506 =back
2507  
2508 Returns the name of a display or undefined for an invalid display index or
2509 failure; call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >> for more
2510 information.
2511  
2512 =head2 C<SDL_GetDisplayBounds( ... )>
2513  
2514 Get the desktop area represented by a display.
2515  
2516 my $rect = SDL_GetDisplayBounds( 0 );
2517  
2518 The primary display (C<displayIndex == 0>) is always located at 0,0.
2519  
2520 Expected parameters include:
2521  
2522 =over
2523  
2524 =item C<displayIndex> - the index of the display to query
2525  
2526 =back
2527  
2528 Returns the SDL2::Rect structure filled in with the display bounds on success
2529 or a negative error code on failure; call L<< C<SDL_GetError(
2530 )>|/C<SDL_GetError( )> >> for more information.
2531  
2532  
2533 =head2 C<SDL_GetDisplayUsableBounds( ... )>
2534  
2535 Get the usable desktop area represented by a display.
2536  
2537 my $rect = SDL_GetDisplayUsableBounds( 0 );
2538  
2539 The primary display (C<displayIndex == 0>) is always located at 0,0.
2540  
2541 This is the same area as L<< C<SDL_GetDisplayBounds( ...
2542 )>|/C<SDL_GetDisplayBounds( ... )> >> reports, but with portions reserved by
2543 the system removed. For example, on Apple's macOS, this subtracts the area
2544 occupied by the menu bar and dock.
2545  
2546 Setting a window to be fullscreen generally bypasses these unusable areas, so
2547 these are good guidelines for the maximum space available to a non-fullscreen
2548 window.
2549  
2550 Expected parameters include:
2551  
2552 =over
2553  
2554 =item C<displayIndex> - the index of the display to query
2555  
2556 =back
2557  
2558 Returns the SDL2::Rect structure filled in with the display bounds on success
2559 or a negative error code on failure; call L<< C<SDL_GetError(
2560 )>|/C<SDL_GetError( )> >> for more information. This function also returns
2561 C<-1> if the parameter C<displayIndex> is out of range.
2562  
2563 =head2 C<SDL_GetDisplayDPI( ... )>
2564  
2565 Get the dots/pixels-per-inch for a display.
2566  
2567 my ( $ddpi, $hdpi, $vdpi ) = SDL_GetDisplayDPI( 0 );
2568  
2569 Diagonal, horizontal and vertical DPI can all be optionally returned if the
2570 appropriate parameter is non-NULL.
2571  
2572 A failure of this function usually means that either no DPI information is
2573 available or the C<displayIndex> is out of range.
2574  
2575 Expected parameters include:
2576  
2577 =over
2578  
2579 =item C<displayIndex> - the index of the display from which DPI information should be queried
2580  
2581 =back
2582  
2583 Returns C<[ddpi, hdpi, vdip]> on success or a negative error code on failure;
2584 call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >> for more information.
2585  
2586 C<ddpi> is the diagonal DPI of the display, C<hdpi> is the horizontal DPI of
2587 the display, C<vdpi> is the vertical DPI of the display.
2588  
2589 =head2 C<SDL_GetDisplayOrientation( ... )>
2590  
2591 Get the orientation of a display.
2592  
2593 my $orientation = SDL_GetDisplayOrientation( 0 );
2594  
2595 Expected parameters include:
2596  
2597 =over
2598  
2599 =item C<displayIndex> - the index of the display to query
2600  
2601 =back
2602  
2603 Returns a value which may be imported with C<:displayOrientation> or
2604 C<SDL_ORIENTATION_UNKNOWN> if it isn't available.
2605  
2606 =head2 C<SDL_GetNumDisplayModes( ... )>
2607  
2608 Get the number of available display modes.
2609  
2610 my $modes = SDL_GetNumDisplayModes( 0 );
2611  
2612 The C<displayIndex> needs to be in the range from C<0> to
2613 C<SDL_GetNumVideoDisplays( ) - 1>.
2614  
2615 Expected parameters include:
2616  
2617 =over
2618  
2619 =item C<displayIndex> - the index of the display to query
2620  
2621 =back
2622  
2623 Returns a number >= 1 on success or a negative error code on failure; call L<<
2624 C<SDL_GetError( )>|/C<SDL_GetError( > >> for more information.
2625  
2626  
2627 =head2 C<SDL_GetDisplayMode( ... )>
2628  
2629 Get information about a specific display mode.
2630  
2631 my $mode = SDL_GetDisplayMode( 0, 0 );
2632  
2633 The display modes are sorted in this priority:
2634  
2635 =over
2636  
2637 =item width - largest to smallest
2638  
2639 =item height - largest to smallest
2640  
2641 =item bits per pixel - more colors to fewer colors
2642  
2643 =item packed pixel layout - largest to smallest
2644  
2645 =item refresh rate - highest to lowest
2646  
2647 =back
2648  
2649 Expected parameters include:
2650  
2651 =over
2652  
2653 =item C<displayIndex> - the index of the display to query
2654  
2655 =item C<modeIndex> - the index of the display mode to query
2656  
2657 =back
2658  
2659 Returns an L<SDL2::DisplayMode> structure filled in with the mode at
2660 C<modeIndex> on success or a negative error code on failure; call L<<
2661 C<SDL_GetError( )>|/C<SDL_GetError( )> >> for more information.
2662  
2663 =head2 C<SDL_GetDesktopDisplayMode( ... )>
2664  
2665 Get information about the desktop's display mode.
2666  
2667 my $mode = SDL_GetDesktopDisplayMode( 0 );
2668  
2669 There's a difference between this function and L<< C<SDL_GetCurrentDisplayMode(
2670 ... )>|/C<SDL_GetCurrentDisplayMode( ... )> >> when SDL runs fullscreen and has
2671 changed the resolution. In that case this function will return the previous
2672 native display mode, and not the current display mode.
2673  
2674 Expected parameters include:
2675  
2676 =over
2677  
2678 =item C<displayIndex> - the index of the display to query
2679  
2680 =back
2681  
2682 Returns an L<SDL2::DisplayMode> structure filled in with the current display
2683 mode on success or a negative error code on failure; call L<< C<SDL_GetError(
2684 )>|/C<SDL_GetError( )> >> for more information.
2685  
2686 =head2 C<SDL_GetCurrentDisplayMode( ... )>
2687  
2688 my $mode = SDL_GetCurrentDisplayMode( 0 );
2689  
2690 There's a difference between this function and L<< C<SDL_GetDesktopDisplayMode(
2691 ... )>|/C<SDL_GetDesktopDisplayMode( ... )> >> when SDL runs fullscreen and has
2692 changed the resolution. In that case this function will return the current
2693 display mode, and not the previous native display mode.
2694  
2695 Expected parameters include:
2696  
2697 =over
2698  
2699 =item C<displayIndex> - the index of the display to query
2700  
2701 =back
2702  
2703 Returns an L<SDL2::DisplayMode> structure filled in with the current display
2704 mode on success or a negative error code on failure; call L<< C<SDL_GetError(
2705 )>|/C<SDL_GetError( )> >> for more information.
2706  
2707 =head2 C<SDL_GetClosestDisplayMode( ... )>
2708  
2709 Get the closes match to the requested display mode.
2710  
2711 $mode = SDL_GetClosestDisplayMode( 0, $mode );
2712  
2713 The available display modes are scanned and he closest mode matching the
2714 requested mode is returned. The mode format and refresh rate default to the
2715 desktop mode if they are set to 0. The modes are scanned with size being first
2716 priority, format being second priority, and finally checking the refresh rate.
2717 If all the available modes are too small, then an undefined value is returned.
2718  
2719 Expected parameters include:
2720  
2721 =over
2722  
2723 =item C<displayIndex> - index of the display to query
2724  
2725 =item C<mode> - an L<SDL2::DisplayMode> structure containing the desired display mode
2726  
2727 =item C<closest> - an L<SDL2::DisplayMode> structure filled in with the closest match of the available display modes
2728  
2729 =back
2730  
2731 Returns the passed in value C<closest> or an undefined value if no matching
2732 video mode was available; call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >>
2733 for more information.
2734  
2735 =head2 C<SDL_GetWindowDisplayIndex( ... )>
2736  
2737 Get the index of the display associated with a window.
2738  
2739 my $index = SDL_GetWindowDisplayIndex( $window );
2740  
2741 Expected parameters include:
2742  
2743 =over
2744  
2745 =item C<window> - the window to query
2746  
2747 =back
2748  
2749 Returns the index of the display containing the center of the window on success
2750 or a negative error code on failure; call L<< C<SDL_GetError(
2751 )>|/C<SDL_GetError( )> >> for more information.
2752  
2753 =head2 C<SDL_SetWindowDisplayMode( ... )>
2754  
2755 Set the display mode to use when a window is visible at fullscreen.
2756  
2757 my $ok = !SDL_SetWindowDisplayMode( $window, $mode );
2758  
2759 This only affects the display mode used when the window is fullscreen. To
2760 change the window size when the window is not fullscreen, use L<<
2761 C<SDL_SetWindowSize( ... )>|/C<SDL_SetWindowSize( ... )> >>.
2762  
2763 =head2 C<SDL_GetWindowDisplayMode( ... )>
2764  
2765 Query the display mode to use when a window is visible at fullscreen.
2766  
2767 my $mode = SDL_GetWindowDisplayMode( $window );
2768  
2769 Expected parameters include:
2770  
2771 =over
2772  
2773 =item C<window> - the window to query
2774  
2775 =back
2776  
2777 Returns a L<SDL2::DisplayMode> structure on success or a negative error code on
2778 failure; call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >> for more
2779 information.
2780  
2781 =head2 C<SDL_GetWindowPixelFormat( ... )>
2782  
2783 Get the pixel format associated with the window.
2784  
2785 my $format = SDL_GetWindowPixelFormat( $window );
2786  
2787 Expected parameters include:
2788  
2789 =over
2790  
2791 =item C<window> - the window to query
2792  
2793 =back
2794  
2795 Returns the pixel format of the window on success or C<SDL_PIXELFORMAT_UNKNOWN>
2796 on failure; call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >> for more
2797 information.
2798  
2799 =head2 C<SDL_CreateWindow( ... )>
2800  
2801 Create a window with the specified position, dimensions, and flags.
2802  
2803 my $window = SDL_CreateWindow( 'Example',
2804 SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
2805 1280, 720,
2806 SDL_WINDOW_SHOWN
2807 );
2808  
2809 C<flags> may be any of the following OR'd together:
2810  
2811 =over
2812  
2813 =item C<SDL_WINDOW_FULLSCREEN> - fullscreen window
2814  
2815 =item C<SDL_WINDOW_FULLSCREEN_DESKTOP> - fullscreen window at desktop resolution
2816  
2817 =item C<SDL_WINDOW_OPENGL> - window usable with an OpenGL context
2818  
2819 =item C<SDL_WINDOW_VULKAN> - window usable with a Vulkan instance
2820  
2821 =item C<SDL_WINDOW_METAL> - window usable with a Metal instance
2822  
2823 =item C<SDL_WINDOW_HIDDEN> - window is not visible
2824  
2825 =item C<SDL_WINDOW_BORDERLESS> - no window decoration
2826  
2827 =item C<SDL_WINDOW_RESIZABLE> - window can be resized
2828  
2829 =item C<SDL_WINDOW_MINIMIZED> - window is minimized
2830  
2831 =item C<SDL_WINDOW_MAXIMIZED> - window is maximized
2832  
2833 =item C<SDL_WINDOW_INPUT_GRABBED> - window has grabbed input focus
2834  
2835 =item C<SDL_WINDOW_ALLOW_HIGHDPI> - window should be created in high-DPI mode if supported (>= SDL 2.0.1)
2836  
2837 =back
2838  
2839 C<SDL_WINDOW_SHOWN> is ignored by C<SDL_CreateWindow( ... )>. The SDL_Window is
2840 implicitly shown if C<SDL_WINDOW_HIDDEN> is not set. C<SDL_WINDOW_SHOWN> may be
2841 queried later using L<< C<SDL_GetWindowFlags( ... )>|/C<SDL_GetWindowFlags( ...
2842 )> >>.
2843  
2844 On Apple's macOS, you B<must> set the NSHighResolutionCapable Info.plist
2845 property to YES, otherwise you will not receive a High-DPI OpenGL canvas.
2846  
2847 If the window is created with the C<SDL_WINDOW_ALLOW_HIGHDPI> flag, its size in
2848 pixels may differ from its size in screen coordinates on platforms with
2849 high-DPI support (e.g. iOS and macOS). Use L<< C<SDL_GetWindowSize( ...
2850 )>|/C<SDL_GetWindowSize( ... )> >> to query the client area's size in screen
2851 coordinates, and L<< C<SDL_GL_GetDrawableSize( )>|/C<SDL_GL_GetDrawableSize( )>
2852 >> or L<< C<SDL_GetRendererOutputSize( )>|/C<SDL_GetRendererOutputSize( )> >>
2853 to query the drawable size in pixels.
2854  
2855 If the window is set fullscreen, the width and height parameters C<w> and C<h>
2856 will not be used. However, invalid size parameters (e.g. too large) may still
2857 fail. Window size is actually limited to 16384 x 16384 for all platforms at
2858 window creation.
2859  
2860 If the window is created with any of the C<SDL_WINDOW_OPENGL> or
2861 C<SDL_WINDOW_VULKAN> flags, then the corresponding LoadLibrary function
2862 (SDL_GL_LoadLibrary or SDL_Vulkan_LoadLibrary) is called and the corresponding
2863 UnloadLibrary function is called by L<< C<SDL_DestroyWindow( ...
2864 )>|/C<SDL_DestroyWindow( ... )> >>.
2865  
2866 If C<SDL_WINDOW_VULKAN> is specified and there isn't a working Vulkan driver,
2867 C<SDL_CreateWindow( ... )> will fail because L<< C<SDL_Vulkan_LoadLibrary(
2868 )>|/C<SDL_Vulkan_LoadLibrary( )> >> will fail.
2869  
2870 If C<SDL_WINDOW_METAL> is specified on an OS that does not support Metal,
2871 C<SDL_CreateWindow( ... )> will fail.
2872  
2873 On non-Apple devices, SDL requires you to either not link to the Vulkan loader
2874 or link to a dynamic library version. This limitation may be removed in a
2875 future version of SDL.
2876  
2877 Expected parameters include:
2878  
2879 =over
2880  
2881 =item C<title> - the title of the window, in UTF-8 encoding
2882  
2883 =item C<x> - the x position of the window, C<SDL_WINDOWPOS_CENTERED>, or C<SDL_WINDOWPOS_UNDEFINED>
2884  
2885 =item C<y> - the y position of the window, C<SDL_WINDOWPOS_CENTERED>, or C<SDL_WINDOWPOS_UNDEFINED>
2886  
2887 =item C<w> - the width of the window, in screen coordinates
2888  
2889 =item C<h> - the height of the window, in screen coordinates
2890  
2891 =item C<flags> - 0, or one or more L<< C<:windowFlags>|SDL2::Enum/C<:windowFlags> >> OR'd together
2892  
2893 =back
2894  
2895 Returns the window that was created or an undefined value on failure; call L<<
2896 C<SDL_GetError( )>|/C<SDL_GetError( )> >> for more information.
2897  
2898  
2899 =head2 C<SDL_CreateWindowFrom( ... )>
2900  
2901 Create an SDL window from an existing native window.
2902  
2903 my $window = SDL_CreateWindowFrom( $data );
2904  
2905 In some cases (e.g. OpenGL) and on some platforms (e.g. Microsoft Windows) the
2906 hint C<SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT> needs to be configured before
2907 using C<SDL_CreateWindowFrom( ... )>.
2908  
2909 Expected parameters include:
2910  
2911 =over
2912  
2913 =item C<data> - driver-dependant window creation data, typically your native window
2914  
2915 =back
2916  
2917 Returns the window that was created or an undefined value on failure; call L<<
2918 C<SDL_GetError( )>|/C<SDL_GetError( )> >> for more information.
2919  
2920 =head2 C<SDL_GetWindowID( ... )>
2921  
2922 Get the numeric ID of a window.
2923  
2924 my $id = SDL_GetWindowID( $window );
2925  
2926 The numeric ID is what L<SDL2::WindowEvent> references, and is necessary to map
2927 these events to specific L<SDL2::Window> objects.
2928  
2929 Expected parameters include:
2930  
2931 =over
2932  
2933 =item C<window> - the window to query
2934  
2935 =back
2936  
2937 Returns the ID of the window on success or C<0> on failure; call L<<
2938 C<SDL_GetError( )>|/C<SDL_GetError( )> >> for more information.
2939  
2940 =head2 C<SDL_GetWindowFromID( ... )>
2941  
2942 Get a window from a stored ID.
2943  
2944 my $window = SDL_GetWindowFromID( 2 );
2945  
2946 The numeric ID is what L<SDL2::WindowEvent> references, and is necessary to map
2947 these events to specific L<SDL2::Window> objects.
2948  
2949 Expected parameters include:
2950  
2951 =over
2952  
2953 =item C<id> - the ID of the window
2954  
2955 =back
2956  
2957 Returns the window associated with C<id> or an undefined value if it doesn't
2958 exist; call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >> for more information.
2959  
2960 =head2 C<SDL_GetWindowFlags( ... )>
2961  
2962 Get the window flags.
2963  
2964 my $id = SDL_GetWindowFlags( $window );
2965  
2966 The numeric ID is what L<SDL2::WindowEvent> references, and is necessary to map
2967 these events to specific L<SDL2::Window> objects.
2968  
2969 Expected parameters include:
2970  
2971 =over
2972  
2973 =item C<window> - the window to query
2974  
2975 =back
2976  
2977 Returns a mask of the L<< C<:windowFlags>|SDL2::Enum/C<:windowFlags> >>
2978 associated with C<window>.
2979  
2980 =head2 C<SDL_SetWindowTitle( ... )>
2981  
2982 Set the title of a window.
2983  
2984 SDL_SetWindowTitle( $window, 'Untitle file *' );
2985  
2986 This string is expected to be in UTF-8 encoding.
2987  
2988 Expected parameters include:
2989  
2990 =over
2991  
2992 =item C<window> - the window to change
2993  
2994 =item C<title> - the desired window title in UTF-8 format
2995  
2996 =back
2997  
2998 =head2 C<SDL_GetWindowTitle( ... )>
2999  
3000 Get the title of a window.
3001  
3002 my $title = SDL_GetWindowTitle( $window );
3003  
3004 Expected parameters include:
3005  
3006 =over
3007  
3008 =item C<window> - the window to query
3009  
3010 =back
3011  
3012 Returns the title of the window in UTF-8 format or C<""> (an empty string) if
3013 there is no title.
3014  
3015 =head2 C<SDL_SetWindowIcon( ... )>
3016  
3017 Set the icon for a window.
3018  
3019 SDL_SetWindowIcon( $window, $icon );
3020  
3021 Expected parameters include:
3022  
3023 =over
3024  
3025 =item C<window> - the window to change
3026  
3027 =item C<icon> - an L<SDL2::Surface> structure containing the icon for the window
3028  
3029 =back
3030  
3031 =head2 C<SDL_SetWindowData( ... )>
3032  
3033 Associate an arbitrary named pointer with a window.
3034  
3035 my $prev = SDL_SetWindowData( $window, 'test', $data );
3036  
3037 Expected parameters include:
3038  
3039 =over
3040  
3041 =item C<window> - the window to change
3042  
3043 =item C<name> - the name of the pointer
3044  
3045 =item C<userdata> - the associated pointer
3046  
3047 =back
3048  
3049 Returns the previous value associated with C<name>.
3050  
3051  
3052 =head2 C<SDL_GetWindowData( ... )>
3053  
3054 Retrieve the data pointer associated with a window.
3055  
3056 my $data = SDL_SetWindowData( $window, 'test' );
3057  
3058 Expected parameters include:
3059  
3060 =over
3061  
3062 =item C<window> - the window to query
3063  
3064 =item C<name> - the name of the pointer
3065  
3066 =back
3067  
3068 Returns the value associated with C<name>.
3069  
3070 =head2 C<SDL_SetWindowPosition( ... )>
3071  
3072 Set the position of a window.
3073  
3074 SDL_SetWindowPosition( $window, 100, 100 );
3075  
3076 The window coordinate origin is the upper left of the display.
3077  
3078 Expected parameters include:
3079  
3080 =over
3081  
3082 =item C<window> - the window to reposition
3083  
3084 =item C<x> - the x coordinate of the window in screen coordinates, or C<SDL_WINDOWPOS_CENTERED> or C<SDL_WINDOWPOS_UNDEFINED>
3085  
3086 =item C<y> - the y coordinate of the window in screen coordinates, or C<SDL_WINDOWPOS_CENTERED> or C<SDL_WINDOWPOS_UNDEFINED>
3087  
3088 =back
3089  
3090 =head2 C<SDL_GetWindowPosition( ... )>
3091  
3092 Get the position of a window.
3093  
3094 my ($x, $y) = SDL_GetWindowPosition( $window );
3095  
3096 Expected parameters include:
3097  
3098 =over
3099  
3100 =item C<window> - the window to query
3101  
3102 =back
3103  
3104 Returns the C<x> and C<y> positions of the window, in screen coordinates,
3105 either of which may be undefined.
3106  
3107 =head2 C<SDL_SetWindowSize( ... )>
3108  
3109 Set the size of a window's client area.
3110  
3111 SDL_SetWindowSize( $window, 100, 100 );
3112  
3113 The window size in screen coordinates may differ from the size in pixels, if
3114 the window was created with C<SDL_WINDOW_ALLOW_HIGHDPI> on a platform with
3115 high-dpi support (e.g. iOS or macOS). Use L<< C<SDL_GL_GetDrawableSize( ...
3116 )>|C<SDL_GL_GetDrawableSize( ... )> >> or L<< C<SDL_GetRendererOutputSize( ...
3117 )>|/C<SDL_GetRendererOutputSize( ... )> >> to get the real client area size in
3118 pixels.
3119  
3120 Fullscreen windows automatically match the size of the display mode, and you
3121 should use L<< C<SDL_SetWindowDisplayMode( ... )>|/C<SDL_SetWindowDisplayMode(
3122 ... )> >> to change their size.
3123  
3124 Expected parameters include:
3125  
3126 =over
3127  
3128 =item C<window> - the window to change
3129  
3130 =item C<w> - the width of the window in pixels, in screen coordinates, must be > 0
3131  
3132 =item C<h> - the height of the window in pixels, in screen coordinates, must be > 0
3133  
3134 =back
3135  
3136 =head2 C<SDL_GetWindowSize( ... )>
3137  
3138 Get the position of a window.
3139  
3140 my ($w, $h) = SDL_GetWindowSize( $window );
3141  
3142 The window size in screen coordinates may differ from the size in pixels, if
3143 the window was created with C<SDL_WINDOW_ALLOW_HIGHDPI> on a platform with
3144 high-dpi support (e.g. iOS or macOS). Use L<< C<SDL_GL_GetDrawableSize( ...
3145 )>|C<SDL_GL_GetDrawableSize( ... )> >>, L<< C<SDL_Vulkan_GetDrawableSize( ...
3146 )>|/C<SDL_Vulkan_GetDrawableSize( ... )> >>, or L<<
3147 C<SDL_GetRendererOutputSize( ... )>|/C<SDL_GetRendererOutputSize( ... )> >> to
3148 get the real client area size in pixels.
3149  
3150 Expected parameters include:
3151  
3152 =over
3153  
3154 =item C<window> - the window to query the width and height from
3155  
3156 =back
3157  
3158 Returns the C<width> and C<height> of the window, in screen coordinates, either
3159 of which may be undefined.
3160  
3161 =head2 C<SDL_GetWindowBordersSize( ... )>
3162  
3163 Get the size of a window's borders (decorations) around the client area.
3164  
3165 my ($top, $left, $bottom, $right) = SDL_GetWindowBorderSize( $window );
3166  
3167 Expected parameters include:
3168  
3169 =over
3170  
3171 =item C<window> - the window to query the size values of the border (decorations) from
3172  
3173 =back
3174  
3175 Returns the C<top>, C<left>, C<bottom>, and C<right> size values, any of which
3176 may be undefined.
3177  
3178 Note: If this function fails (returns -1), the size values will be initialized
3179 to C<0, 0, 0, 0>, as if the window in question was borderless.
3180  
3181 Note: This function may fail on systems where the window has not yet been
3182 decorated by the display server (for example, immediately after calling L<<
3183 C<SDL_CreateWindow( ... )>|/C<SDL_CreateWindow( ... )> >> ). It is
3184 recommended that you wait at least until the window has been presented and
3185 composited, so that the window system has a chance to decorate the window and
3186 provide the border dimensions to SDL.
3187  
3188 This function also returns C<-1> if getting the information is not supported.
3189  
3190 =head2 C<SDL_SetWindowMinimumSize( ... )>
3191  
3192 Set the minimum size of a window's client area.
3193  
3194 SDL_SetWindowMinimumSize( $window, 100, 100 );
3195  
3196 Expected parameters include:
3197  
3198 =over
3199  
3200 =item C<window> - the window to change
3201  
3202 =item C<w> - the minimum width of the window in pixels
3203  
3204 =item C<h> - the minimum height of the window in pixels
3205  
3206 =back
3207  
3208 =head2 C<SDL_GetWindowMinimumSize( ... )>
3209  
3210 Get the minimum size of a window's client area.
3211  
3212 my ($w, $h) = SDL_GetWindowMinimumSize( $window );
3213  
3214 Expected parameters include:
3215  
3216 =over
3217  
3218 =item C<window> - the window to query the minimum width and minimum height from
3219  
3220 =back
3221  
3222 Returns the minimum C<width> and minimum C<height> of the window, either of
3223 which may be undefined.
3224  
3225 =head2 C<SDL_SetWindowMaximumSize( ... )>
3226  
3227 Set the maximum size of a window's client area.
3228  
3229 SDL_SetWindowMaximumSize( $window, 100, 100 );
3230  
3231 Expected parameters include:
3232  
3233 =over
3234  
3235 =item C<window> - the window to change
3236  
3237 =item C<w> - the maximum width of the window in pixels
3238  
3239 =item C<h> - the maximum height of the window in pixels
3240  
3241 =back
3242  
3243 =head2 C<SDL_GetWindowMaximumSize( ... )>
3244  
3245 Get the maximum size of a window's client area.
3246  
3247 my ($w, $h) = SDL_GetWindowMaximumSize( $window );
3248  
3249 Expected parameters include:
3250  
3251 =over
3252  
3253 =item C<window> - the window to query the maximum width and maximum height from
3254  
3255 =back
3256  
3257 Returns the maximum C<width> and maximum C<height> of the window, either of
3258 which may be undefined.
3259  
3260 =head2 C<SDL_SetWindowBordered( ... )>
3261  
3262 Set the border state of a window.
3263  
3264 SDL_SetWindowBordered( $window, 1 );
3265  
3266 This will add or remove the window's C<SDL_WINDOW_BORDERLESS> flag and add or
3267 remove the border from the actual window. This is a no-op if the window's
3268 border already matches the requested state.
3269  
3270 You can't change the border state of a fullscreen window.
3271  
3272 Expected parameters include:
3273  
3274 =over
3275  
3276 =item C<window> - the window of which to change the border state
3277  
3278 =item C<bordered> - false value to remove border, true value to add border
3279  
3280 =back
3281  
3282 =head2 C<SDL_SetWindowResizable( ... )>
3283  
3284 Set the user-resizable state of a window.
3285  
3286 SDL_SetWindowResizable( $window, 1 );
3287  
3288 This will add or remove the window's C<SDL_WINDOW_RESIZABLE> flag and
3289 allow/disallow user resizing of the window. This is a no-op if the window's
3290 resizable state already matches the requested state.
3291  
3292 You can't change the resizable state of a fullscreen window.
3293  
3294 Expected parameters include:
3295  
3296 =over
3297  
3298 =item C<window> - the window of which to change the border state
3299  
3300 =item C<bordered> - true value to allow resizing, false value to disallow
3301  
3302 =back
3303  
3304 =head2 C<SDL_ShowWindow( ... )>
3305  
3306 Show a window.
3307  
3308 SDL_ShowWindow( $window );
3309  
3310 Expected parameters include:
3311  
3312 =over
3313  
3314 =item C<window> - the window to show
3315  
3316 =back
3317  
3318 =head2 C<SDL_HideWindow( ... )>
3319  
3320 Hide a window.
3321  
3322 SDL_HideWindow( $window );
3323  
3324 Expected parameters include:
3325  
3326 =over
3327  
3328 =item C<window> - the window to hide
3329  
3330 =back
3331  
3332 =head2 C<SDL_RaiseWindow( ... )>
3333  
3334 Raise a window above other windows and set the input focus.
3335  
3336 SDL_RaiseWindow( $window );
3337  
3338 Expected parameters include:
3339  
3340 =over
3341  
3342 =item C<window> - the window to raise
3343  
3344 =back
3345  
3346 =head2 C<SDL_MaximizeWindow( ... )>
3347  
3348 Make a window as large as possible.
3349  
3350 SDL_MaximizeWindow( $window );
3351  
3352 Expected parameters include:
3353  
3354 =over
3355  
3356 =item C<window> - the window to maximize
3357  
3358 =back
3359  
3360 =head2 C<SDL_MinimizeWindow( ... )>
3361  
3362 Minimize a window to an iconic representation.
3363  
3364 SDL_MinimizeWindow( $window );
3365  
3366 Expected parameters include:
3367  
3368 =over
3369  
3370 =item C<window> - the window to minimize
3371  
3372 =back
3373  
3374 =head2 C<SDL_RestoreWindow( ... )>
3375  
3376 Restore the size and position of a minimized or maximized window.
3377  
3378 SDL_RestoreWindow( $window );
3379  
3380 Expected parameters include:
3381  
3382 =over
3383  
3384 =item C<window> - the window to restore
3385  
3386 =back
3387  
3388 =head2 C<SDL_SetWindowFullscreen( ... )>
3389  
3390 Set a window's fullscreen state.
3391  
3392 SDL_SetWindowFullscreen( $window, SDL_WINDOW_FULLSCREEN );
3393  
3394 Expected parameters include:
3395  
3396 =over
3397  
3398 =item C<window> - the window to change
3399  
3400 =item C<flags> - C<SDL_WINDOW_FULLSCREEN>, C<SDL_WINDOW_FULLSCREEN_DESKTOP> or 0
3401  
3402 =back
3403  
3404 Returns 0 on success or a negative error code on failure; call L<<
3405 C<SDL_GetError( )>|/C<SDL_GetError( )> >> for more information.
3406  
3407 =head2 C<SDL_GetWindowSurface( ... )>
3408  
3409 Get the SDL surface associated with the window.
3410  
3411 my $surface = SDL_GetWindowSurface( $window );
3412  
3413 A new surface will be created with the optimal format for the window, if
3414 necessary. This surface will be freed when the window is destroyed. Do not free
3415 this surface.
3416  
3417 This surface will be invalidated if the window is resized. After resizing a
3418 window this function must be called again to return a valid surface.
3419  
3420 You may not combine this with 3D or the rendering API on this window.
3421  
3422 This function is affected by C<SDL_HINT_FRAMEBUFFER_ACCELERATION>.
3423  
3424 Expected parameters include:
3425  
3426 =over
3427  
3428 =item C<window> - the window to query
3429  
3430 =back
3431  
3432 Returns the surface associated with the window, or an undefined on failure;
3433 call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >> for more information.
3434  
3435 =head2 C<SDL_UpdateWindowSurface( ... )>
3436  
3437 Copy the window surface to the screen.
3438  
3439 my $ok = !SDL_UpdateWindowSurface( $window );
3440  
3441 This is the function you use to reflect any changes to the surface on the
3442 screen.
3443  
3444 Expected parameters include:
3445  
3446 =over
3447  
3448 =item C<window> - the window to query
3449  
3450 =back
3451  
3452 Returns C<0> on success or a negative error code on failure; call L<<
3453 C<SDL_GetError( )>|/C<SDL_GetError( )> >> for more information.
3454  
3455 =head2 C<SDL_UpdateWindowSurfaceRects( ... )>
3456  
3457 Copy areas of the window surface to the screen.
3458  
3459 SDL_UpdateWindowSurfaceRects( $window, @recs );
3460  
3461 This is the function you use to reflect changes to portions of the surface on
3462 the screen.
3463  
3464 Expected parameters include:
3465  
3466 =over
3467  
3468 =item C<window> - the window to update
3469  
3470 =item C<rects> - an array of L<SDL2::Rect> structures representing areas of the surface to copy
3471  
3472 =back
3473  
3474 Returns C<0> on success or a negative error code on failure; call L<<
3475 C<SDL_GetError( )>|/C<SDL_GetError( )> >> for more information.
3476  
3477 =head2 C<SDL_SetWindowGrab( ... )>
3478  
3479 Set a window's input grab mode.
3480  
3481 SDL_SetWindowGrab( $window, 1 );
3482  
3483 When input is grabbed the mouse is confined to the window.
3484  
3485 If the caller enables a grab while another window is currently grabbed, the
3486 other window loses its grab in favor of the caller's window.
3487  
3488 Expected parameters include:
3489  
3490 =over
3491  
3492 =item C<window> - the window for which the input grab mode should be set
3493  
3494 =item C<grabbed> - a true value to grab input or a false value to release input
3495  
3496 =back
3497  
3498 =head2 C<SDL_SetWindowKeyboardGrab( ... )>
3499  
3500 Set a window's keyboard grab mode.
3501  
3502 SDL_SetWindowKeyboardGrab( $window, 1 );
3503  
3504 If the caller enables a grab while another window is currently grabbed, the
3505 other window loses its grab in favor of the caller's window.
3506  
3507 Expected parameters include:
3508  
3509 =over
3510  
3511 =item C<window> - The window for which the keyboard grab mode should be set.
3512  
3513 =item C<grabbed> - This is true to grab keyboard, and false to release.
3514  
3515 =back
3516  
3517 =head2 C<SDL_SetWindowMouseGrab( ... )>
3518  
3519 Set a window's mouse grab mode.
3520  
3521 SDL_SetWindowMouseGrab( $window, 1 );
3522  
3523 Expected parameters include:
3524  
3525 =over
3526  
3527 =item C<window> - The window for which the mouse grab mode should be set.
3528  
3529 =item C<grabbed> - This is true to grab mouse, and false to release.
3530  
3531 =back
3532  
3533 If the caller enables a grab while another window is currently grabbed, the
3534 other window loses its grab in favor of the caller's window.
3535  
3536 =head2 C<SDL_GetWindowGrab( ... )>
3537  
3538 Get a window's input grab mode.
3539  
3540 my $grabbing = SDL_GetWindowGrab( $window );
3541  
3542 Expected parameters include:
3543  
3544 =over
3545  
3546 =item C<window> - the window to query
3547  
3548 =back
3549  
3550 Returns true if input is grabbed, false otherwise.
3551  
3552 =head2 C<SDL_GetWindowKeyboardGrab( ... )>
3553  
3554 Get a window's keyboard grab mode.
3555  
3556 my $keyboard = SDL_GetWindowKeyboardGrab( $window );
3557  
3558 Expected parameters include:
3559  
3560 =over
3561  
3562 =item C<window> - the window to query
3563  
3564 =back
3565  
3566 Returns true if keyboard is grabbed, and false otherwise.
3567  
3568 =head2 C<SDL_GetWindowMouseGrab( ... )>
3569  
3570 Get a window's mouse grab mode.
3571  
3572 my $mouse = SDL_GetWindowMouseGrab( $window );
3573  
3574 Expected parameters include:
3575  
3576 =over
3577  
3578 =item C<window> - the window to query
3579  
3580 =back
3581  
3582 This returns true if mouse is grabbed, and false otherwise.
3583  
3584 =head2 C<SDL_GetGrabbedWindow( )>
3585  
3586 Get the window that currently has an input grab enabled.
3587  
3588 my $window = SDL_GetGrabbedWindow( );
3589  
3590 Returns the window if input is grabbed or undefined otherwise.
3591  
3592 =head2 C<SDL_SetWindowBrightness( ... )>
3593  
3594 Set the brightness (gamma multiplier) for a given window's display.
3595  
3596 my $ok = !SDL_SetWindowBrightness( $window, 2 );
3597  
3598 Despite the name and signature, this method sets the brightness of the entire
3599 display, not an individual window. A window is considered to be owned by the
3600 display that contains the window's center pixel. (The index of this display can
3601 be retrieved using L<< C<SDL_GetWindowDisplayIndex( ...
3602 )>|/C<SDL_GetWindowDisplayIndex( ... )> >>.) The brightness set will not follow
3603 the window if it is moved to another display.
3604  
3605 Many platforms will refuse to set the display brightness in modern times. You
3606 are better off using a shader to adjust gamma during rendering, or something
3607 similar.
3608  
3609 Expected parameters includes:
3610  
3611 =over
3612  
3613 =item C<window> - the window used to select the display whose brightness will be changed
3614  
3615 =item C<brightness> - the brightness (gamma multiplier) value to set where 0.0 is completely dark and 1.0 is normal brightness
3616  
3617 =back
3618  
3619 Returns C<0> on success or a negative error code on failure; call L<<
3620 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
3621  
3622 =head2 C<SDL_GetWindowBrightness( ... )>
3623  
3624 Get the brightness (gamma multiplier) for a given window's display.
3625  
3626 my $gamma = SDL_GetWindowBrightness( $window );
3627  
3628 Despite the name and signature, this method retrieves the brightness of the
3629 entire display, not an individual window. A window is considered to be owned by
3630 the display that contains the window's center pixel. (The index of this display
3631 can be retrieved using L<< C<SDL_GetWindowDisplayIndex( ...
3632 )>|/C<SDL_GetWindowDisplayIndex( ... )> >>.)
3633  
3634 Expected parameters include:
3635  
3636 =over
3637  
3638 =item C<window> - the window used to select the display whose brightness will be queried
3639  
3640 =back
3641  
3642 Returns the brightness for the display where 0.0 is completely dark and C<1.0>
3643 is normal brightness.
3644  
3645 =head2 C<SDL_SetWindowOpacity( ... )>
3646  
3647 Set the opacity for a window.
3648  
3649 SDL_SetWindowOpacity( $window, .5 );
3650  
3651 The parameter C<opacity> will be clamped internally between C<0.0>
3652 (transparent) and C<1.0> (opaque).
3653  
3654 This function also returns C<-1> if setting the opacity isn't supported.
3655  
3656 Expected parameters include:
3657  
3658 =over
3659  
3660 =item C<window> - the window which will be made transparent or opaque
3661  
3662 =item C<opacity> - the opacity value (0.0 - transparent, 1.0 - opaque)
3663  
3664 =back
3665  
3666 Returns C<0> on success or a negative error code on failure; call L<<
3667 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
3668  
3669 =head2 C<SDL_GetWindowOpacity( ... )>
3670  
3671 Get the opacity of a window.
3672  
3673 my $opacity = SDL_GetWindowOpacity( $window );
3674  
3675 If transparency isn't supported on this platform, opacity will be reported as
3676 1.0 without error.
3677  
3678 The parameter C<opacity> is ignored if it is undefined.
3679  
3680 This function also returns C<-1> if an invalid window was provided.
3681  
3682 Expected parameters include:
3683  
3684 =over
3685  
3686 =item C<window> - the window to get the current opacity value from
3687  
3688 =back
3689  
3690 Returns the current opacity on success or a negative error code on failure;
3691 call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
3692  
3693 =head2 C<SDL_SetWindowModalFor( ... )>
3694  
3695 Set the window as a modal for another window.
3696  
3697 my $ok = !SDL_SetWindowModalFor( $winodw, $parent );
3698  
3699 Expected parameters include:
3700  
3701 =over
3702  
3703 =item C<modal_window> - the window that should be set modal
3704  
3705 =item C<parent_window> - the parent window for the modal window
3706  
3707 =back
3708  
3709 Returns C<0> on success or a negative error code on failure; call L<<
3710 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
3711  
3712  
3713 =head2 C<SDL_SetWindowInputFocus( ... )>
3714  
3715 Explicitly set input focus to the window.
3716  
3717 SDL_SetWindowInputFocus( $window );
3718  
3719 You almost certainly want L<< C<SDL_RaiseWindow( ... )>|/C<SDL_RaiseWindow( ...
3720 )> >> instead of this function. Use this with caution, as you might give focus
3721 to a window that is completely obscured by other windows.
3722  
3723 Expected parameters include:
3724  
3725 =over
3726  
3727 =item C<window> - the window that should get the input focus
3728  
3729 =back
3730  
3731 Returns C<0> on success or a negative error code on failure; call L<<
3732 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
3733  
3734 =head2 C<SDL_SetWindowGammaRamp( ... )>
3735  
3736 Set the gamma ramp for the display that owns a given window.
3737  
3738 my $ok = !SDL_SetWindowGammaRamp( $window, \@red, \@green, \@blue );
3739  
3740 Set the gamma translation table for the red, green, and blue channels of the
3741 video hardware. Each table is an array of 256 16-bit quantities, representing a
3742 mapping between the input and output for that channel. The input is the index
3743 into the array, and the output is the 16-bit gamma value at that index, scaled
3744 to the output color precision. Despite the name and signature, this method sets
3745 the gamma ramp of the entire display, not an individual window. A window is
3746 considered to be owned by the display that contains the window's center pixel.
3747 (The index of this display can be retrieved using L<<
3748 C<SDL_GetWindowDisplayIndex( ... )>|/C<SDL_GetWindowDisplayIndex( ... )> >>.)
3749 The gamma ramp set will not follow the window if it is moved to another
3750 display.
3751  
3752 Expected parameters include:
3753  
3754 =over
3755  
3756 =item C<window> - the window used to select the display whose gamma ramp will be changed
3757  
3758 =item C<red> - a 256 element array of 16-bit quantities representing the translation table for the red channel, or NULL
3759  
3760 =item C<green> - a 256 element array of 16-bit quantities representing the translation table for the green channel, or NULL
3761  
3762 =item C<blue> - a 256 element array of 16-bit quantities representing the translation table for the blue channel, or NULL
3763  
3764 =back
3765  
3766 Returns C<0> on success or a negative error code on failure; call L<<
3767 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
3768  
3769 =head2 C<SDL_GetWindowGammaRamp( ... )>
3770  
3771 Get the gamma ramp for a given window's display.
3772  
3773 my ($red, $green, $blue) = SDL_GetWindowGammaRamp( $window );
3774  
3775 Despite the name and signature, this method retrieves the gamma ramp of the
3776 entire display, not an individual window. A window is considered to be owned by
3777 the display that contains the window's center pixel. (The index of this display
3778 can be retrieved using L<< C<SDL_GetWindowDisplayIndex( ...
3779 )>|/C<SDL_GetWindowDisplayIndex( ... )> >>.)
3780  
3781 Expected parameters include:
3782  
3783 =over
3784  
3785 =item C<window> - the window used to select the display whose gamma ramp will be queried
3786  
3787 =back
3788  
3789 Returns three 256 element arrays of 16-bit quantities filled in with the
3790 translation table for the red, gree, and blue channels on success or a negative
3791 error code on failure; call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >>( )
3792 for more information.
3793  
3794 =head2 C<SDL_SetWindowHitTest( ... )>
3795  
3796 Provide a callback that decides if a window region has special properties.
3797  
3798 SDL_SetWindowHitTest( $window, sub ($win, $point, $data) {
3799 warn sprintf 'Click at x:%d y:%d', $point->x, $point->y;
3800 ...;
3801 });
3802  
3803 Normally, windows are dragged and resized by decorations provided by the system
3804 window manager (a title bar, borders, etc), but for some apps, it makes sense
3805 to drag them from somewhere else inside the window itself; for example, one
3806 might have a borderless window that wants to be draggable from any part, or
3807 simulate its own title bar, etc.
3808  
3809 This function lets the app provide a callback that designates pieces of a given
3810 window as special. This callback is run during event processing if we need to
3811 tell the OS to treat a region of the window specially; the use of this callback
3812 is known as "hit testing."
3813  
3814 Mouse input may not be delivered to your application if it is within a special
3815 area; the OS will often apply that input to moving the window or resizing the
3816 window and not deliver it to the application.
3817  
3818 Specifying undef for a callback disables hit-testing. Hit-testing is disabled
3819 by default.
3820  
3821 Platforms that don't support this functionality will return C<-1>
3822 unconditionally, even if you're attempting to disable hit-testing.
3823  
3824 Your callback may fire at any time, and its firing does not indicate any
3825 specific behavior (for example, on Windows, this certainly might fire when the
3826 OS is deciding whether to drag your window, but it fires for lots of other
3827 reasons, too, some unrelated to anything you probably care about B<and when the
3828 mouse isn't actually at the location it is testing>). Since this can fire at
3829 any time, you should try to keep your callback efficient, devoid of
3830 allocations, etc.
3831  
3832 Expected parameters include:
3833  
3834 =over
3835  
3836 =item C<window> - the window to set hit-testing on
3837  
3838 =item C<callback> - the function to call when doing a hit-test
3839  
3840 =item C<callback_data> - an app-defined void pointer passed to C<callback>
3841  
3842 =back
3843  
3844 Returns C<0> on success or C<-1> on error (including unsupported); call L<<
3845 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
3846  
3847 =head2 C<SDL_FlashWindow( ... )>
3848  
3849 Request a window to give a signal, e.g. a visual signal, to demand attention
3850 from the user.
3851  
3852 SDL_FlashWindow( $window, 10 );
3853  
3854 Expected parameters include:
3855  
3856 =over
3857  
3858 =item C<window> - the window to request the flashing for
3859  
3860 =item C<flash_count> - number of times the window gets flashed on systems that support flashing the window multiple times, like Windows, else it is ignored
3861  
3862 =back
3863  
3864 Returns C<0> on success or a negative error code on failure; call L<<
3865 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
3866  
3867 =head2 C<SDL_DestroyWindow( ... )>
3868  
3869 Destroy a window.
3870  
3871 SDL_DestoryWindow( $window );
3872  
3873 If C<window> is undefined, this function will return immediately after setting
3874 the SDL error message to "Invalid window". See L<< C<SDL_GetError(
3875 )>|/C<SDL_GetError( )> >>( ).
3876  
3877 Expected parameters include:
3878  
3879 =over
3880  
3881 =item C<window> - the window to destroy
3882  
3883 =back
3884  
3885 =head2 C<SDL_IsScreenSaverEnabled( ... )>
3886  
3887 Check whether the screensaver is currently enabled.
3888  
3889 my $enabled = SDL_IsScreenSaverEnabled( );
3890  
3891 The screensaver is disabled by default since SDL 2.0.2. Before SDL 2.0.2 the
3892 screensaver was enabled by default.
3893  
3894 The default can also be changed using C<SDL_HINT_VIDEO_ALLOW_SCREENSAVER>.
3895  
3896 Returns true if the screensaver is enabled, false if it is disabled.
3897  
3898 =head2 C<SDL_EnableScreenSaver( ... )>
3899  
3900 Allow the screen to be blanked by a screen saver.
3901  
3902 SDL_EnableScreenSaver( );
3903  
3904  
3905 =head2 C<SDL_DisableScreenSaver( ... )>
3906  
3907 Prevent the screen from being blanked by a screen saver.
3908  
3909 SDL_DisableScreenSaver( );
3910  
3911 If you disable the screensaver, it is automatically re-enabled when SDL quits.
3912  
3913 =head1 OpenGL Support Functions
3914  
3915 These may be imported with the C<:opengl> tag.
3916  
3917 =head2 C<SDL_GL_LoadLibrary( ... )>
3918  
3919 Dynamically load an OpenGL library.
3920  
3921 my $ok = SDL_GL_LoadLibrary( );
3922  
3923 This should be done after initializing the video driver, but before creating
3924 any OpenGL windows. If no OpenGL library is loaded, the default library will be
3925 loaded upon creation of the first OpenGL window.
3926  
3927 If you do this, you need to retrieve all of the GL functions used in your
3928 program from the dynamic library using L<< C<SDL_GL_GetProcAddress(
3929 )>|/C<SDL_GL_GetProcAddress( )> >>.
3930  
3931 Expected parameters include:
3932  
3933 =over
3934  
3935 =item C<path> - the platform dependent OpenGL library name, or undef to open the default OpenGL library
3936  
3937 =back
3938  
3939 Returns C<0> on success or a negative error code on failure; call L<<
3940 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
3941  
3942 =head2 C<SDL_GL_GetProcAddress( ... )>
3943  
3944 Get an OpenGL function by name.
3945  
3946 my $ptr = SDL_GL_GetProcAddress( 'glGenBuffers' );
3947 ...; # TODO
3948 # TODO: In the future, this should return an XSUB loaded with FFI.
3949  
3950 If the GL library is loaded at runtime with L<< C<SDL_GL_LoadLibrary( ...
3951 )>|/C<SDL_GL_LoadLibrary( ... )> >>, then all GL functions must be retrieved
3952 this way. Usually this is used to retrieve function pointers to OpenGL
3953 extensions.
3954  
3955 There are some quirks to looking up OpenGL functions that require some extra
3956 care from the application. If you code carefully, you can handle these quirks
3957 without any platform-specific code, though:
3958  
3959 =over
3960  
3961 =item * On Windows, function pointers are specific to the current GL context;
3962 this means you need to have created a GL context and made it current before
3963 calling SDL_GL_GetProcAddress( ). If you recreate your context or create a
3964 second context, you should assume that any existing function pointers
3965 aren't valid to use with it. This is (currently) a Windows-specific
3966 limitation, and in practice lots of drivers don't suffer this limitation,
3967 but it is still the way the wgl API is documented to work and you should
3968 expect crashes if you don't respect it. Store a copy of the function
3969 pointers that comes and goes with context lifespan.
3970  
3971 =item * On X11, function pointers returned by this function are valid for any
3972 context, and can even be looked up before a context is created at all. This
3973 means that, for at least some common OpenGL implementations, if you look up
3974 a function that doesn't exist, you'll get a non-NULL result that is _NOT_
3975 safe to call. You must always make sure the function is actually available
3976 for a given GL context before calling it, by checking for the existence of
3977 the appropriate extension with L<< C<SDL_GL_ExtensionSupported( ... )>|C<SDL_GL_ExtensionSupported( ... )> >>, or verifying
3978 that the version of OpenGL you're using offers the function as core
3979 functionality.
3980  
3981 =item * Some OpenGL drivers, on all platforms, B<will> return undef if a function
3982 isn't supported, but you can't count on this behavior. Check for extensions
3983 you use, and if you get an undef anyway, act as if that extension wasn't
3984 available. This is probably a bug in the driver, but you can code
3985 defensively for this scenario anyhow.
3986  
3987 =item * Just because you're on Linux/Unix, don't assume you'll be using X11.
3988 Next-gen display servers are waiting to replace it, and may or may not make
3989 the same promises about function pointers.
3990  
3991 =item * OpenGL function pointers must be declared C<APIENTRY> as in the example
3992 code. This will ensure the proper calling convention is followed on
3993 platforms where this matters (Win32) thereby avoiding stack corruption.
3994  
3995 =back
3996  
3997 Expected parameters include:
3998  
3999 =over
4000  
4001 =item C<proc> - the name of an OpenGL function
4002  
4003 =back
4004  
4005 Returns a pointer to the named OpenGL function. The returned pointer should be
4006 cast to the appropriate function signature.
4007  
4008 =head2 C<SDL_GL_UnloadLibrary( )>
4009  
4010 Unload the OpenGL library previously loaded by L<< C<SDL_GL_LoadLibrary( ...
4011 )>|/C<SDL_GL_LoadLibrary( ... )> >>.
4012  
4013 =head2 C<SDL_GL_ExtensionSupported( ... )>
4014  
4015 Check if an OpenGL extension is supported for the current context.
4016  
4017 my $ok = SDL_GL_ExtensionSupported( 'GL_ARB_texture_rectangle' );
4018  
4019 This function operates on the current GL context; you must have created a
4020 context and it must be current before calling this function. Do not assume that
4021 all contexts you create will have the same set of extensions available, or that
4022 recreating an existing context will offer the same extensions again.
4023  
4024 While it's probably not a massive overhead, this function is not an O(1)
4025 operation. Check the extensions you care about after creating the GL context
4026 and save that information somewhere instead of calling the function every time
4027 you need to know.
4028  
4029 Expected parameters include:
4030  
4031 =over
4032  
4033 =item C<extension> - the name of the extension to check
4034  
4035 =back
4036  
4037 Returns true if the extension is supported, false otherwise.
4038  
4039 =head2 C<SDL_GL_ResetAttributes( )>
4040  
4041 Reset all previously set OpenGL context attributes to their default values.
4042  
4043 SDL_GL_ResetAttributes( );
4044  
4045 =head2 C<SDL_GL_SetAttribute( ... )>
4046  
4047 Set an OpenGL window attribute before window creation.
4048  
4049 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
4050 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
4051 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
4052 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
4053 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
4054  
4055 This function sets the OpenGL attribute C<attr> to C<value>. The requested
4056 attributes should be set before creating an OpenGL window. You should use L<<
4057 C<SDL_GL_GetAttribute( ... )>|/C<SDL_GL_GetAttribute( ... )> >> to check the
4058 values after creating the OpenGL context, since the values obtained can differ
4059 from the requested ones.
4060  
4061 Expected parameters include:
4062  
4063 =over
4064  
4065 =item C<attr> - an SDL_GLattr enum value specifying the OpenGL attribute to set
4066  
4067 =item C<value> - the desired value for the attribute
4068  
4069 =back
4070  
4071 Returns C<0> on success or a negative error code on failure; call L<<
4072 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
4073  
4074 =head2 C<SDL_GL_GetAttribute( ... )>
4075  
4076 Get the actual value for an attribute from the current context.
4077  
4078 my $value = SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER);
4079  
4080 Expected parameters include:
4081  
4082 =over
4083  
4084 =item C<attr> - an SDL_GLattr enum value specifying the OpenGL attribute to get
4085  
4086 =back
4087  
4088 Returns the value on success or a negative error code on failure; call L<<
4089 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
4090  
4091 =head2 C<SDL_GL_CreateContext( ... )>
4092  
4093 Create an OpenGL context for an OpenGL window, and make it current.
4094  
4095 # Window mode MUST include SDL_WINDOW_OPENGL for use with OpenGL.
4096 my $window = SDL_CreateWindow(
4097 'SDL2/OpenGL Demo', 0, 0, 640, 480,
4098 SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);
4099  
4100 # Create an OpenGL context associated with the window
4101 my $glcontext = SDL_GL_CreateContext( $window );
4102  
4103 # now you can make GL calls.
4104 glClearColor( 0, 0, 0 ,1 );
4105 glClear( GL_COLOR_BUFFER_BIT );
4106 SDL_GL_SwapWindow( $window );
4107  
4108 # Once finished with OpenGL functions, the SDL_GLContext can be deleted.
4109 SDL_GL_DeleteContext( $glcontext );
4110  
4111 Windows users new to OpenGL should note that, for historical reasons, GL
4112 functions added after OpenGL version 1.1 are not available by default. Those
4113 functions must be loaded at run-time, either with an OpenGL extension-handling
4114 library or with L<< C<SDL_GL_GetProcAddress( ... )>|/C<SDL_GL_GetProcAddress(
4115 ... )> >> and its related functions.
4116  
4117 SDL2::GLContext is opaque to the application.
4118  
4119 Expected parameters include:
4120  
4121 =over
4122  
4123 =item C<window> - the window to associate with the context
4124  
4125 =back
4126  
4127 Returns the OpenGL context associated with C<window> or undef on error; call
4128 L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more details.
4129  
4130 =head2 C<SDL_GL_MakeCurrent( ... )>
4131  
4132 Set up an OpenGL context for rendering into an OpenGL window.
4133  
4134 SDL_GL_MakeCurrent( $window, $gl );
4135  
4136 The context must have been created with a compatible window.
4137  
4138 Expected parameters include:
4139  
4140 =over
4141  
4142 =item C<window> - the window to associate with the context
4143  
4144 =item C<context> - the OpenGL context to associate with the window
4145  
4146 =back
4147  
4148 Returns C<0> on success or a negative error code on failure; call L<<
4149 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
4150  
4151 =head2 C<SDL_GL_GetCurrentWindow( )>
4152  
4153 Get the currently active OpenGL window.
4154  
4155 my $window = SDL_GL_GetCurrentWindow( );
4156  
4157 Returns the currently active OpenGL window on success or undef on failure; call
4158 L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
4159  
4160 =head2 C<SDL_GL_GetCurrentContext( )>
4161  
4162 Get the currently active OpenGL context.
4163  
4164 my $gl = SDL_GL_GetCurrentContext( );
4165  
4166 Returns the currently active OpenGL context or NULL on failure; call L<<
4167 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
4168  
4169 =head2 C<SDL_GL_GetDrawableSize( ... )>
4170  
4171 Get the size of a window's underlying drawable in pixels.
4172  
4173 my ($w, $h) = SDL_GL_GetDrawableSize( $window );
4174  
4175 This returns info useful for calling C<glViewport( ... )>.
4176  
4177 This may differ from L<< C<SDL_GetWindowSize( ... )>|/C<SDL_GetWindowSize( ...
4178 )> >> if we're rendering to a high-DPI drawable, i.e. the window was created
4179 with C<SDL_WINDOW_ALLOW_HIGHDPI> on a platform with high-DPI support (Apple
4180 calls this "Retina"), and not disabled by the
4181 C<SDL_HINT_VIDEO_HIGHDPI_DISABLED> hint.
4182  
4183 Expected parameters include:
4184  
4185 =over
4186  
4187 =item C<window> - the window from which the drawable size should be queried
4188  
4189 =back
4190  
4191 Returns the width and height in pixels, either of which may be undefined.
4192  
4193 =head2 C<SDL_GL_SetSwapInterval( ... )>
4194  
4195 Set the swap interval for the current OpenGL context.
4196  
4197 my $ok = !SDL_GL_SetSwapInterval( 1 );
4198  
4199 Some systems allow specifying C<-1> for the interval, to enable adaptive vsync.
4200 Adaptive vsync works the same as vsync, but if you've already missed the
4201 vertical retrace for a given frame, it swaps buffers immediately, which might
4202 be less jarring for the user during occasional framerate drops. If application
4203 requests adaptive vsync and the system does not support it, this function will
4204 fail and return C<-1>. In such a case, you should probably retry the call with
4205 C<1> for the interval.
4206  
4207 Adaptive vsync is implemented for some glX drivers with
4208 C<GLX_EXT_swap_control_tear>:
4209 L<https://www.opengl.org/registry/specs/EXT/glx_swap_control_tear.txt> and for
4210 some Windows drivers with C<WGL_EXT_swap_control_tear>:
4211 L<https://www.opengl.org/registry/specs/EXT/wgl_swap_control_tear.txt>
4212  
4213 Read more on the Khronos wiki:
4214 L<https://www.khronos.org/opengl/wiki/Swap_Interval#Adaptive_Vsync>
4215  
4216 Expected parameters include:
4217  
4218 =over
4219  
4220 =item C<interval> - 0 for immediate updates, 1 for updates synchronized with the vertical retrace, -1 for adaptive vsync
4221  
4222 =back
4223  
4224 Returns C<0> on success or C<-1> if setting the swap interval is not supported;
4225 call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
4226  
4227 =head2 C<SDL_GL_GetSwapInterval( )>
4228  
4229 Get the swap interval for the current OpenGL context.
4230  
4231 my $interval = SDL_GL_GetSwapInterval( );
4232  
4233 If the system can't determine the swap interval, or there isn't a valid current
4234 context, this function will return 0 as a safe default.
4235  
4236 Returns C<0> if there is no vertical retrace synchronization, C<1> if the
4237 buffer swap is synchronized with the vertical retrace, and C<-1> if late swaps
4238 happen immediately instead of waiting for the next retrace; call L<<
4239 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
4240  
4241 =head2 C<SDL_GL_SwapWindow( ... )>
4242  
4243 Update a window with OpenGL rendering.
4244  
4245 SDL_GL_SwapWindow( $window );
4246  
4247 This is used with double-buffered OpenGL contexts, which are the default.
4248  
4249 On macOS, make sure you bind 0 to the draw framebuffer before swapping the
4250 window, otherwise nothing will happen. If you aren't using C<glBindFramebuffer(
4251 )>, this is the default and you won't have to do anything extra.
4252  
4253 Expected parameters include:
4254  
4255 =over
4256  
4257 =item C<window> - the window to change
4258  
4259 =back
4260  
4261 =head2 C<SDL_GL_DeleteContext( ... )>
4262  
4263 Delete an OpenGL context.
4264  
4265 SDL_GL_DeleteContext( $context );
4266  
4267 Expected parameters include:
4268  
4269 =over
4270  
4271 =item C<context> - the OpenGL context to be deleted
4272  
4273 =back
4274  
4275 =head2 2D Accelerated Rendering
4276  
4277 This category contains functions for 2D accelerated rendering. You may import
4278 these functions with the C<:render> tag.
4279  
4280 This API supports the following features:
4281  
4282 =over
4283  
4284 =item single pixel points
4285  
4286 =item single pixel lines
4287  
4288 =item filled rectangles
4289  
4290 =item texture images
4291  
4292 =back
4293  
4294 All of these may be drawn in opaque, blended, or additive modes.
4295  
4296 The texture images can have an additional color tint or alpha modulation
4297 applied to them, and may also be stretched with linear interpolation, rotated
4298 or flipped/mirrored.
4299  
4300 For advanced functionality like particle effects or actual 3D you should use
4301 SDL's OpenGL/Direct3D support or one of the many available 3D engines.
4302  
4303 This API is not designed to be used from multiple threads, see L<SDL issue
4304 #986|https://github.com/libsdl-org/SDL/issues/986> for details.
4305  
4306 =head2 C<SDL_GetNumRenderDrivers( )>
4307  
4308 Get the number of 2D rendering drivers available for the current display.
4309  
4310 my $drivers = SDL_GetNumRenderDrivers( );
4311  
4312 A render driver is a set of code that handles rendering and texture management
4313 on a particular display. Normally there is only one, but some drivers may have
4314 several available with different capabilities.
4315  
4316 There may be none if SDL was compiled without render support.
4317  
4318 Returns a number >= 0 on success or a negative error code on failure; call L<<
4319 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
4320  
4321 =head2 C<SDL_GetRenderDriverInfo( ... )>
4322  
4323 Get info about a specific 2D rendering driver for the current display.
4324  
4325 my $info = !SDL_GetRendererDriverInfo( );
4326  
4327 Expected parameters include:
4328  
4329 =over
4330  
4331 =item C<index> - the index of the driver to query information about
4332  
4333 =back
4334  
4335 Returns an L<SDL2::RendererInfo> structure on success or a negative error code
4336 on failure; call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more
4337 information.
4338  
4339 =head2 C<SDL_CreateWindowAndRenderer( ... )>
4340  
4341 Create a window and default renderer.
4342  
4343 my ($window, $renderer) = SDL_CreateWindowAndRenderer(640, 480, 0);
4344  
4345 Expected parameters include:
4346  
4347 =over
4348  
4349 =item C<width> - the width of the window
4350  
4351 =item C<height> - the height of the window
4352  
4353 =item C<window_flags> - the flags used to create the window (see L<< C<SDL_CreateWindow( ... )>|/C<SDL_CreateWindow( ... )> >>)
4354  
4355 =back
4356  
4357 Returns a L<SDL2::Window> and L<SDL2::Renderer> objects on success, or -1 on
4358 error; call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more
4359 information.
4360  
4361 =head2 C<SDL_CreateRenderer( ... )>
4362  
4363 Create a 2D rendering context for a window.
4364  
4365 my $renderer = SDL_CreateRenderer( $window, -1, 0);
4366  
4367 Expected parameters include:
4368  
4369 =over
4370  
4371 =item C<window> - the window where rendering is displayed
4372  
4373 =item C<index> - the index of the rendering driver to initialize, or C<-1> to initialize the first one supporting the requested flags
4374  
4375 =item C<flags> - C<0>, or one or more C<SDL_RendererFlags> OR'd together
4376  
4377 =back
4378  
4379 Returns a valid rendering context or undefined if there was an error; call L<<
4380 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
4381  
4382 =head2 C<SDL_CreateSoftwareRenderer( ... )>
4383  
4384 Create a 2D software rendering context for a surface.
4385  
4386 my $renderer = SDL_CreateSoftwareRenderer( $surface );
4387  
4388 Two other API which can be used to create SDL_Renderer:
4389  
4390 L<< C<SDL_CreateRenderer( ... )>|/C<SDL_CreateRenderer( ... )> >> and L<<
4391 C<SDL_CreateWindowAndRenderer( ... )>|/C<SDL_CreateWindowAndRenderer( ... )>
4392 >>. These can B<also> create a software renderer, but they are intended to be
4393 used with an L<SDL2::Window> as the final destination and not an
4394 L<SDL2::Surface>.
4395  
4396 Expected parameters include:
4397  
4398 =over
4399  
4400 =item C<surface> - the L<SDL2::Surface> structure representing the surface where rendering is done
4401  
4402 =back
4403  
4404 Returns a valid rendering context or undef if there was an error; call L<<
4405 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
4406  
4407 =head2 C<SDL_GetRenderer( ... )>
4408  
4409 Get the renderer associated with a window.
4410  
4411 my $renderer = SDL_GetRenderer( $window );
4412  
4413 Expected parameters include:
4414  
4415 =over
4416  
4417 =item C<window> - the window to query
4418  
4419 =back
4420  
4421 Returns the rendering context on success or undef on failure; call L<<
4422 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
4423  
4424 =head2 C<SDL_GetRendererInfo( ... )>
4425  
4426 Get information about a rendering context.
4427  
4428 my $info = !SDL_GetRendererInfo( $renderer );
4429  
4430 Expected parameters include:
4431  
4432 =over
4433  
4434 =item C<renderer> - the rendering context
4435  
4436 =back
4437  
4438 Returns an L<SDL2::RendererInfo> structure on success or a negative error code
4439 on failure; call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more
4440 information.
4441  
4442 =head2 C<SDL_GetRendererOutputSize( ... )>
4443  
4444 Get the output size in pixels of a rendering context.
4445  
4446 my ($w, $h) = SDL_GetRendererOutputSize( $renderer );
4447  
4448 Due to high-dpi displays, you might end up with a rendering context that has
4449 more pixels than the window that contains it, so use this instead of L<<
4450 C<SDL_GetWindowSize( ... )>|/C<SDL_GetWindowSize( ... )> >> to decide how much
4451 drawing area you have.
4452  
4453 Expected parameters include:
4454  
4455 =over
4456  
4457 =item C<renderer> - the rendering context
4458  
4459 =back
4460  
4461 Returns the width and height on success or a negative error code on failure;
4462 call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
4463  
4464 =head2 C<SDL_CreateTexture( ... )>
4465  
4466 Create a texture for a rendering context.
4467  
4468 my $texture = SDL_CreateTexture( $renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 1024, 768);
4469  
4470 =for TODO: https://gist.github.com/malja/2193bd656fe50c203f264ce554919976
4471  
4472 You can set the texture scaling method by setting
4473 C<SDL_HINT_RENDER_SCALE_QUALITY> before creating the texture.
4474  
4475 Expected parameters include:
4476  
4477 =over
4478  
4479 =item C<renderer> - the rendering context
4480  
4481 =item C<format> - one of the enumerated values in C<:pixelFormatEnum>
4482  
4483 =item C<access> - one of the enumerated values in C<:textureAccess>
4484  
4485 =item C<w> - the width of the texture in pixels
4486  
4487 =item C<h> - the height of the texture in pixels
4488  
4489 =back
4490  
4491 Returns a pointer to the created texture or undefined if no rendering context
4492 was active, the format was unsupported, or the width or height were out of
4493 range; call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more
4494 information.
4495  
4496 =head2 C<SDL_CreateTextureFromSurface( ... )>
4497  
4498 Create a texture from an existing surface.
4499  
4500 use Config;
4501 my ($rmask, $gmask, $bmask, $amask) =
4502 $Config{byteorder} == 4321 ? (0xff000000,0x00ff0000,0x0000ff00,0x000000ff) :
4503 (0x000000ff,0x0000ff00,0x00ff0000,0xff000000);
4504 my $surface = SDL_CreateRGBSurface( 0, 640, 480, 32, $rmask, $gmask, $bmask, $amask );
4505 my $texture = SDL_CreateTextureFromSurface( $renderer, $surface );
4506  
4507 The surface is not modified or freed by this function.
4508  
4509 The SDL_TextureAccess hint for the created texture is
4510 C<SDL_TEXTUREACCESS_STATIC>.
4511  
4512 The pixel format of the created texture may be different from the pixel format
4513 of the surface. Use L<< C<SDL_QueryTexture( ... )>|/C<SDL_QueryTexture( ... )>
4514 >> to query the pixel format of the texture.
4515  
4516 Expected parameters include:
4517  
4518 =over
4519  
4520 =item C<renderer> - the rendering context
4521  
4522 =item C<surface> - the L<SDL2::Surface> structure containing pixel data used to fill the texture
4523  
4524 =back
4525  
4526 Returns the created texture or undef on failure; call L<< C<SDL_GetError(
4527 )>|/C<SDL_GetError( )> >>( ) for more information.
4528  
4529 =head2 C<SDL_QueryTexture( ... )>
4530  
4531 Query the attributes of a texture.
4532  
4533 my ( $format, $access, $w, $h ) = SDL_QueryTexture( $texture );
4534  
4535 Expected parameters include:
4536  
4537 =over
4538  
4539 =item C<texture> - the texture to query
4540  
4541 =back
4542  
4543 Returns the following on success...
4544  
4545 =over
4546  
4547 =item C<format> - a pointer filled in with the raw format of the texture; the
4548 actual format may differ, but pixel transfers will use this
4549 format (one of the L<< C<:pixelFormatEnum>|/C<:pixelFormatEnum> >> values)
4550  
4551 =item C<access> - a pointer filled in with the actual access to the texture (one of the L<< C<:textureAccess>|/C<:textureAccess> >> values)
4552  
4553 =item C<w> - a pointer filled in with the width of the texture in pixels
4554  
4555 =item C<h> - a pointer filled in with the height of the texture in pixels
4556  
4557 =back
4558  
4559 ...or a negative error code on failure; call L<< C<SDL_GetError(
4560 )>|/C<SDL_GetError( )> >>( ) for more information.
4561  
4562 =head2 C<SDL_SetTextureColorMod( ... )>
4563  
4564 Set an additional color value multiplied into render copy operations.
4565  
4566 my $ok = !SDL_SetTextureColorMod( $texture, 64, 64, 64 );
4567  
4568 When this texture is rendered, during the copy operation each source color
4569 channel is modulated by the appropriate color value according to the following
4570 formula:
4571  
4572 srcC = srcC * (color / 255)
4573  
4574 Color modulation is not always supported by the renderer; it will return C<-1>
4575 if color modulation is not supported.
4576  
4577 Expected parameters include:
4578  
4579 =over
4580  
4581 =item C<texture> - the texture to update
4582  
4583 =item C<r> - the red color value multiplied into copy operations
4584  
4585 =item C<g> - the green color value multiplied into copy operations
4586  
4587 =item C<b> - the blue color value multiplied into copy operations
4588  
4589 =back
4590  
4591 Returns C<0> on success or a negative error code on failure; call L<<
4592 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
4593  
4594 =head2 C<SDL_GetTextureColorMod( ... )>
4595  
4596 Get the additional color value multiplied into render copy operations.
4597  
4598 my ( $r, $g, $b ) = SDL_GetTextureColorMod( $texture );
4599  
4600 Expected parameters include:
4601  
4602 =over
4603  
4604 =item C<texture> - the texture to query
4605  
4606 =back
4607  
4608 Returns the current red, green, and blue color values on success or a negative
4609 error code on failure; call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >>( )
4610 for more information.
4611  
4612 =head2 C<SDL_SetTextureAlphaMod( ... )>
4613  
4614 Set an additional alpha value multiplied into render copy operations.
4615  
4616 SDL_SetTextureAlphaMod( $texture, 100 );
4617  
4618 When this texture is rendered, during the copy operation the source alpha
4619  
4620 value is modulated by this alpha value according to the following formula:
4621  
4622 srcA = srcA * (alpha / 255)
4623  
4624 Alpha modulation is not always supported by the renderer; it will return C<-1>
4625 if alpha modulation is not supported.
4626  
4627 Expected parameters include:
4628  
4629 =over
4630  
4631 =item C<texture> - the texture to update
4632  
4633 =item C<alpha> - the source alpha value multiplied into copy operations
4634  
4635 =back
4636  
4637 Returns C<0> on success or a negative error code on failure; call L<<
4638 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
4639  
4640 =head2 C<SDL_GetTextureAlphaMod( ... )>
4641  
4642 Get the additional alpha value multiplied into render copy operations.
4643  
4644 my $alpha = SDL_GetTextureAlphaMod( $texture );
4645  
4646 Expected parameters include:
4647  
4648 =over
4649  
4650 =item C<texture> - the texture to query
4651  
4652 =back
4653  
4654 Returns the current alpha value on success or a negative error code on failure;
4655 call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
4656  
4657 =head2 C<SDL_SetTextureBlendMode( ... )>
4658  
4659 Set the blend mode for a texture, used by L<< C<SDL_RenderCopy( ...
4660 )>|/C<SDL_RenderCopy( ... )> >>.
4661  
4662 If the blend mode is not supported, the closest supported mode is chosen and
4663 this function returns C<-1>.
4664  
4665 Expected parameters include:
4666  
4667 =over
4668  
4669 =item C<texture> - the texture to update
4670  
4671 =item C<blendMode> - the L<< C<:blendMode>|/C<:blendMode> >> to use for texture blending
4672  
4673 =back
4674  
4675 Returns 0 on success or a negative error code on failure; call L<<
4676 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
4677  
4678 =head2 C<SDL_GetTextureBlendMode( ... )>
4679  
4680 Get the blend mode used for texture copy operations.
4681  
4682 SDL_GetTextureBlendMode( $texture, SDL_BLENDMODE_ADD );
4683  
4684 Expected parameters include:
4685  
4686 =over
4687  
4688 =item C<texture> - the texture to query
4689  
4690 =back
4691  
4692 Returns the current C<:blendMode> on success or a negative error code on
4693 failure; call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more
4694 information.
4695  
4696 =head2 C<SDL_SetTextureScaleMode( ... )>
4697  
4698 Set the scale mode used for texture scale operations.
4699  
4700 SDL_SetTextureScaleMode( $texture, $scaleMode );
4701  
4702 If the scale mode is not supported, the closest supported mode is chosen.
4703  
4704 Expected parameters include:
4705  
4706 =over
4707  
4708 =item C<texture> - The texture to update.
4709  
4710 =item C<scaleMode> - the SDL_ScaleMode to use for texture scaling.
4711  
4712 =back
4713  
4714 Returns C<0> on success, or C<-1> if the texture is not valid.
4715  
4716 =head2 C<SDL_GetTextureScaleMode( ... )>
4717  
4718 Get the scale mode used for texture scale operations.
4719  
4720 my $ok = SDL_GetTextureScaleMode( $texture );
4721  
4722 Expected parameters include:
4723  
4724 =over
4725  
4726 =item C<texture> - the texture to query.
4727  
4728 =back
4729  
4730 Returns the current scale mode on success, or C<-1> if the texture is not
4731 valid.
4732  
4733 =head2 C<SDL_UpdateTexture( ... )>
4734  
4735 Update the given texture rectangle with new pixel data.
4736  
4737 my $rect = SDL2::Rect->new( { x => 0, y => ..., w => $surface->w, h => $surface->h } );
4738 SDL_UpdateTexture( $texture, $rect, $surface->pixels, $surface->pitch );
4739  
4740 The pixel data must be in the pixel format of the texture. Use L<<
4741 C<SDL_QueryTexture( ... )>|/C<SDL_QueryTexture( ... )> >> to query the pixel
4742 format of the texture.
4743  
4744 This is a fairly slow function, intended for use with static textures that do
4745 not change often.
4746  
4747 If the texture is intended to be updated often, it is preferred to create the
4748 texture as streaming and use the locking functions referenced below. While this
4749 function will work with streaming textures, for optimization reasons you may
4750 not get the pixels back if you lock the texture afterward.
4751  
4752 Expected parameters include:
4753  
4754 =over
4755  
4756 =item C<texture> - the texture to update
4757  
4758 =item C<rect> - an L<SDL2::Rect> structure representing the area to update, or undef to update the entire texture
4759  
4760 =item C<pixels> - the raw pixel data in the format of the texture
4761  
4762 =item C<pitch> - the number of bytes in a row of pixel data, including padding between lines
4763  
4764 =back
4765  
4766 Returns C<0> on success or a negative error code on failure; call L<<
4767 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
4768  
4769 =head2 C<SDL_UpdateYUVTexture( ... )>
4770  
4771 Update a rectangle within a planar YV12 or IYUV texture with new pixel data.
4772  
4773 SDL_UpdateYUVTexture( $texture, $rect, $yPlane, $yPitch, $uPlane, $uPitch, $vPlane, $vPitch );
4774  
4775 You can use L<< C<SDL_UpdateTexture( ... )>|/C<SDL_UpdateTexture( ... )> >> as
4776 long as your pixel data is a contiguous block of Y and U/V planes in the proper
4777 order, but this function is available if your pixel data is not contiguous.
4778  
4779 Expected parameters include:
4780  
4781 =over
4782  
4783 =item C<texture> - the texture to update
4784  
4785 =item C<rect> - a pointer to the rectangle of pixels to update, or undef to update the entire texture
4786  
4787 =item C<Yplane> - the raw pixel data for the Y plane
4788  
4789 =item C<Ypitch> - the number of bytes between rows of pixel data for the Y plane
4790  
4791 =item C<Uplane> - the raw pixel data for the U plane
4792  
4793 =item C<Upitch> - the number of bytes between rows of pixel data for the U plane
4794  
4795 =item C<Vplane> - the raw pixel data for the V plane
4796  
4797 =item C<Vpitch> - the number of bytes between rows of pixel data for the V plane
4798  
4799 =back
4800  
4801 Returns C<0> on success or -1 if the texture is not valid; call L<<
4802 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
4803  
4804 =head2 C<SDL_UpdateNVTexture( ... )>
4805  
4806 Update a rectangle within a planar NV12 or NV21 texture with new pixels.
4807  
4808 SDL_UpdateNVTexture( $texture, $rect, $yPlane, $yPitch, $uPlane, $uPitch );
4809  
4810 You can use L<< C<SDL_UpdateTexture( ... )>|/C<SDL_UpdateTexture( ... )> >> as
4811 long as your pixel data is a contiguous block of NV12/21 planes in the proper
4812 order, but this function is available if your pixel data is not contiguous.
4813  
4814 Expected parameters include:
4815  
4816 =over
4817  
4818 =item C<texture> - the texture to update
4819  
4820 =item C<rect> - a pointer to the rectangle of pixels to update, or undef to update the entire texture.
4821  
4822 =item C<Yplane> - the raw pixel data for the Y plane.
4823  
4824 =item C<Ypitch> - the number of bytes between rows of pixel data for the Y plane.
4825  
4826 =item C<UVplane> - the raw pixel data for the UV plane.
4827  
4828 =item C<UVpitch> - the number of bytes between rows of pixel data for the UV plane.
4829  
4830 =back
4831  
4832 Returns C<0> on success, or C<-1> if the texture is not valid.
4833  
4834 =head2 C<SDL_LockTexture( ... )>
4835  
4836 Lock a portion of the texture for B<write-only> pixel access.
4837  
4838 SDL_LockTexture( $texture, $rect, $pixels, $pitch );
4839  
4840 As an optimization, the pixels made available for editing don't necessarily
4841 contain the old texture data. This is a write-only operation, and if you need
4842 to keep a copy of the texture data you should do that at the application level.
4843  
4844 You must use L<< C<SDL_UpdateTexture( ... )>|/C<SDL_UpdateTexture( ... )> >> to
4845 unlock the pixels and apply any changes.
4846  
4847 Expected parameters include:
4848  
4849 =over
4850  
4851 =item C<texture> - the texture to lock for access, which was created with C<SDL_TEXTUREACCESS_STREAMING>
4852  
4853 =item C<rect> - an L<SDL2::Rect> structure representing the area to lock for access; undef to lock the entire texture
4854  
4855 =item C<pixels> - this is filled in with a pointer to the locked pixels, appropriately offset by the locked area
4856  
4857 =item C<pitch> - this is filled in with the pitch of the locked pixels; the pitch is the length of one row in bytes
4858  
4859 =back
4860  
4861 Returns 0 on success or a negative error code if the texture is not valid or
4862 was not created with `SDL_TEXTUREACCESS_STREAMING`; call L<< C<SDL_GetError(
4863 )>|/C<SDL_GetError( )> >>( ) for more information.
4864  
4865 =head2 C<SDL_LockTextureToSurface( ... )>
4866  
4867 Lock a portion of the texture for B<write-only> pixel access, and expose it as
4868 a SDL surface.
4869  
4870 my $surface = SDL_LockTextureSurface( $texture, $rect );
4871  
4872 Besides providing an L<SDL2::Surface> instead of raw pixel data, this function
4873 operates like L<SDL2::LockTexture>.
4874  
4875 As an optimization, the pixels made available for editing don't necessarily
4876 contain the old texture data. This is a write-only operation, and if you need
4877 to keep a copy of the texture data you should do that at the application level.
4878  
4879 You must use L<< C<SDL_UnlockTexture( ... )>|/C<SDL_UnlockTexture( ... )> >> to
4880 unlock the pixels and apply any changes.
4881  
4882 The returned surface is freed internally after calling L<< C<SDL_UnlockTexture(
4883 ... )>|/C<SDL_UnlockTexture( ... )> >> or L<< C<SDL_DestroyTexture( ...
4884 )>|/C<SDL_DestroyTexture( ... )> >>. The caller should not free it.
4885  
4886 Expected parameters include:
4887  
4888 =over
4889  
4890 =item C<texture> - the texture to lock for access, which was created with C<SDL_TEXTUREACCESS_STREAMING>
4891  
4892 =item C<rect> - a pointer to the rectangle to lock for access. If the rect is undef, the entire texture will be locked
4893  
4894 =back
4895  
4896 Returns the L<SDL2::Surface> structure on success, or C<-1> if the texture is
4897 not valid or was not created with C<SDL_TEXTUREACCESS_STREAMING>.
4898  
4899 =head2 C<SDL_UnlockTexture( ... )>
4900  
4901 Unlock a texture, uploading the changes to video memory, if needed.
4902  
4903 SDL_UnlockTexture( $texture );
4904  
4905 B<Warning>: Please note that L<< C<SDL_LockTexture( ... )>|/C<SDL_LockTexture(
4906 ... )> >> is intended to be write-only; it will not guarantee the previous
4907 contents of the texture will be provided. You must fully initialize any area of
4908 a texture that you lock before unlocking it, as the pixels might otherwise be
4909 uninitialized memory.
4910  
4911 Which is to say: locking and immediately unlocking a texture can result in
4912 corrupted textures, depending on the renderer in use.
4913  
4914 Expected parameters include:
4915  
4916 =over
4917  
4918 =item C<texture> - a texture locked by L<< C<SDL_LockTexture( ... )>|/C<SDL_LockTexture( ... )> >>
4919  
4920 =back
4921  
4922 =head2 C<SDL_RenderTargetSupported( ... )>
4923  
4924 Determine whether a renderer supports the use of render targets.
4925  
4926 my $bool = SDL_RenderTargetSupported( $renderer );
4927  
4928 Expected parameters include:
4929  
4930 =over
4931  
4932 =item C<renderer> - the renderer that will be checked
4933  
4934 =back
4935  
4936 Returns true if supported or false if not.
4937  
4938 =head2 C<SDL_SetRenderTarget( ... )>
4939  
4940 Set a texture as the current rendering target.
4941  
4942 SDL_SetRenderTarget( $renderer, $texture );
4943  
4944 Before using this function, you should check the C<SDL_RENDERER_TARGETTEXTURE>
4945 bit in the flags of L<SDL2::RendererInfo> to see if render targets are
4946 supported.
4947  
4948 The default render target is the window for which the renderer was created. To
4949 stop rendering to a texture and render to the window again, call this function
4950 with a undefined C<texture>.
4951  
4952 Expected parameters include:
4953  
4954 =over
4955  
4956 =item C<renderer> - the rendering context
4957  
4958 =item C<texture> - the targeted texture, which must be created with the C<SDL_TEXTUREACCESS_TARGET> flag, or undef to render to the window instead of a texture.
4959  
4960 =back
4961  
4962 Returns C<0> on success or a negative error code on failure; call L<<
4963 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
4964  
4965 =head2 C<SDL_GetRenderTarget( ... )>
4966  
4967 Get the current render target.
4968  
4969 my $texture = SDL_GetRenderTarget( $renderer );
4970  
4971 The default render target is the window for which the renderer was created, and
4972 is reported an undefined value here.
4973  
4974 Expected parameters include:
4975  
4976 =over
4977  
4978 =item C<renderer> - the rendering context
4979  
4980 =back
4981  
4982 Returns the current render target or undef for the default render target.
4983  
4984 =head2 C<SDL_RenderSetLogicalSize( ... )>
4985  
4986 Set a device independent resolution for rendering.
4987  
4988 SDL_RenderSetLogicalSize( $renderer, 100, 100 );
4989  
4990 This function uses the viewport and scaling functionality to allow a fixed
4991 logical resolution for rendering, regardless of the actual output resolution.
4992 If the actual output resolution doesn't have the same aspect ratio the output
4993 rendering will be centered within the output display.
4994  
4995 If the output display is a window, mouse and touch events in the window will be
4996 filtered and scaled so they seem to arrive within the logical resolution.
4997  
4998 If this function results in scaling or subpixel drawing by the rendering
4999 backend, it will be handled using the appropriate quality hints.
5000  
5001 Expected parameters include:
5002  
5003 =over
5004  
5005 =item C<renderer> - the renderer for which resolution should be set
5006  
5007 =item C<w> - the width of the logical resolution
5008  
5009 =item C<h> - the height of the logical resolution
5010  
5011 =back
5012  
5013 Returns C<0> on success or a negative error code on failure; call L<<
5014 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5015  
5016 =head2 C<SDL_RenderGetLogicalSize( ... )>
5017  
5018 Get device independent resolution for rendering.
5019  
5020 my ($w, $h) = SDL_RenderGetLogicalSize( $renderer );
5021  
5022 This may return C<0> for C<w> and C<h> if the L<SDL2::Renderer> has never had
5023 its logical size set by L<< C<SDL_RenderSetLogicalSize( ...
5024 )>|/C<SDL_RenderSetLogicalSize( ... )> >> and never had a render target set.
5025  
5026 Expected parameters include:
5027  
5028 =over
5029  
5030 =item C<renderer> - a rendering context
5031  
5032 =back
5033  
5034 Returns the width and height.
5035  
5036 =head2 C<SDL_RenderSetIntegerScale( ... )>
5037  
5038 Set whether to force integer scales for resolution-independent rendering.
5039  
5040 SDL_RenderSetIntegerScale( $renderer, 1 );
5041  
5042 This function restricts the logical viewport to integer values - that is, when
5043 a resolution is between two multiples of a logical size, the viewport size is
5044 rounded down to the lower multiple.
5045  
5046 Expected parameters include:
5047  
5048 =over
5049  
5050 =item C<renderer> - the renderer for which integer scaling should be set
5051  
5052 =item C<enable> - enable or disable the integer scaling for rendering
5053  
5054 =back
5055  
5056 Returns C<0> on success or a negative error code on failure; call L<<
5057 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5058  
5059 =head2 C<SDL_RenderGetIntegerScale( ... )>
5060  
5061 Get whether integer scales are forced for resolution-independent rendering.
5062  
5063 SDL_RenderGetIntegerScale( $renderer );
5064  
5065 Expected parameters include:
5066  
5067 =over
5068  
5069 =item C<renderer> - the renderer from which integer scaling should be queried
5070  
5071 =back
5072  
5073 Returns true if integer scales are forced or false if not and on failure; call
5074 L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5075  
5076 =head2 C<SDL_RenderSetViewport( ... )>
5077  
5078 Set the drawing area for rendering on the current target.
5079  
5080 SDL_RenderSetViewport( $renderer, $rect );
5081  
5082 When the window is resized, the viewport is reset to fill the entire new window
5083 size.
5084  
5085 Expected parameters include:
5086  
5087 =over
5088  
5089 =item C<renderer> - the rendering context
5090  
5091 =item C<rect> - the L<SDL2::Rect> structure representing the drawing area, or undef to set the viewport to the entire target
5092  
5093 =back
5094  
5095 Returns C<0> on success or a negative error code on failure; call L<<
5096 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5097  
5098 =head2 C<SDL_RenderGetViewport( ... )>
5099  
5100 Get the drawing area for the current target.
5101  
5102 my $rect = SDL_RenderGetViewport( $renderer );
5103  
5104 Expected parameters include:
5105  
5106 =over
5107  
5108 =item C<renderer> - the rendering context
5109  
5110 =back
5111  
5112 Returns an L<SDL2::Rect> structure filled in with the current drawing area.
5113  
5114 =head2 C<SDL_RenderSetClipRect( ... )>
5115  
5116 Set the clip rectangle for rendering on the specified target.
5117  
5118 SDL_RenderSetClipRect( $renderer, $rect );
5119  
5120 Expected parameters include:
5121  
5122 =over
5123  
5124 =item C<renderer> - the rendering context for which clip rectangle should be set
5125  
5126 =item C<rect> - an L<SDL2::Rect> structure representing the clip area, relative to the viewport, or undef to disable clipping
5127  
5128 =back
5129  
5130 Returns C<0> on success or a negative error code on failure; call L<<
5131 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5132  
5133 =head2 C<SDL_RenderGetClipRect( ... )>
5134  
5135 Get the clip rectangle for the current target.
5136  
5137 my $rect = SDL_RenderGetClipRect( $renderer );
5138  
5139 Expected parameters include:
5140  
5141 =over
5142  
5143 =item C<renderer> - the rendering context from which clip rectangle should be queried
5144  
5145 =back
5146  
5147 Returns an L<SDL2::Rect> structure filled in with the current clipping area or
5148 an empty rectangle if clipping is disabled.
5149  
5150 =head2 C<SDL_RenderIsClipEnabled( ... )>
5151  
5152 Get whether clipping is enabled on the given renderer.
5153  
5154 my $tf = SDL_RenderIsClipEnabled( $renderer );
5155  
5156 Expected parameters include:
5157  
5158 =over
5159  
5160 =item C<renderer> - the renderer from which clip state should be queried
5161  
5162 =back
5163  
5164 Returns true if clipping is enabled or false if not; call L<< C<SDL_GetError(
5165 )>|/C<SDL_GetError( )> >>( ) for more information.
5166  
5167 =head2 C<SDL_RenderSetScale( ... )>
5168  
5169 Set the drawing scale for rendering on the current target.
5170  
5171 SDL_RenderSetScale( $renderer, .5, 1 );
5172  
5173 The drawing coordinates are scaled by the x/y scaling factors before they are
5174 used by the renderer. This allows resolution independent drawing with a single
5175 coordinate system.
5176  
5177 If this results in scaling or subpixel drawing by the rendering backend, it
5178 will be handled using the appropriate quality hints. For best results use
5179 integer scaling factors.
5180  
5181 Expected parameters include:
5182  
5183 =over
5184  
5185 =item C<renderer> - a rendering context
5186  
5187 =item C<scaleX> - the horizontal scaling factor
5188  
5189 =item C<scaleY> - the vertical scaling factor
5190  
5191 =back
5192  
5193 Returns C<0> on success or a negative error code on failure; call L<<
5194 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5195  
5196 =head2 C<SDL_RenderGetScale( ... )>
5197  
5198 Get the drawing scale for the current target.
5199  
5200 my ($scaleX, $scaleY) = SDL_RenderGetScale( $renderer );
5201  
5202 Expected parameters include:
5203  
5204 =over
5205  
5206 =item C<renderer> - the renderer from which drawing scale should be queried
5207  
5208 =back
5209  
5210 Returns the horizonal and vertical scaling factors.
5211  
5212 =head2 C<SDL_SetRenderDrawColor( ... )>
5213  
5214 Set the color used for drawing operations (Rect, Line and Clear).
5215  
5216 SDL_SetRenderDrawColor( $renderer, 0, 0, 128, SDL_ALPHA_OPAQUE );
5217  
5218 Set the color for drawing or filling rectangles, lines, and points, and for L<<
5219 C<SDL_RenderClear( ... )>|/C<SDL_RenderClear( ... )> >>.
5220  
5221 Expected parameters include:
5222  
5223 =over
5224  
5225 =item C<renderer> - the rendering context
5226  
5227 =item C<r> - the red value used to draw on the rendering target
5228  
5229 =item C<g> - the green value used to draw on the rendering target
5230  
5231 =item C<b> - the blue value used to draw on the rendering target
5232  
5233 =item C<a> - the alpha value used to draw on the rendering target; usually C<SDL_ALPHA_OPAQUE> (255). Use C<SDL_SetRenderDrawBlendMode> to specify how the alpha channel is used
5234  
5235 =back
5236  
5237 Returns C<0> on success or a negative error code on failure; call L<<
5238 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5239  
5240 =head2 C<SDL_GetRenderDrawColor( ... )>
5241  
5242 Get the color used for drawing operations (Rect, Line and Clear).
5243  
5244 my ($r, $g, $b, $a) = SDL_GetRenderDrawColor( $renderer );
5245  
5246 Expected parameters include:
5247  
5248 =over
5249  
5250 =item C<renderer> - the rendering context
5251  
5252 =back
5253  
5254 Returns red, green, blue, and alpha values on success or a negative error code
5255 on failure; call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more
5256 information.
5257  
5258 =head2 C<SDL_SetRenderDrawBlendMode( ... )>
5259  
5260 Set the blend mode used for drawing operations (Fill and Line).
5261  
5262 SDL_SetRenderDrawBlendMode( $renderer, SDL_BLENDMODE_BLEND );
5263  
5264 If the blend mode is not supported, the closest supported mode is chosen.
5265  
5266 Expected parameters include:
5267  
5268 =over
5269  
5270 =item C<renderer> - the rendering context
5271  
5272 =item C<blendMode> - the L<< C<:blendMode>|/C<:blendMode> >> to use for blending
5273  
5274 =back
5275  
5276 Returns C<0> on success or a negative error code on failure; call L<<
5277 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5278  
5279 =head2 C<SDL_GetRenderDrawBlendMode( ... )>
5280  
5281 Get the blend mode used for drawing operations.
5282  
5283 my $blendMode = SDL_GetRenderDrawBlendMode( $rendering );
5284  
5285 Expected parameters include:
5286  
5287 =over
5288  
5289 =item C<renderer> - the rendering context
5290  
5291 =back
5292  
5293 Returns the current C<:blendMode> on success or a negative error code on
5294 failure; call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more
5295 information.
5296  
5297 =head2 C<SDL_RenderClear( ... )>
5298  
5299 Clear the current rendering target with the drawing color.
5300  
5301 SDL_RenderClear( $renderer );
5302  
5303 This function clears the entire rendering target, ignoring the viewport and the
5304 clip rectangle.
5305  
5306 =over
5307  
5308 =item C<renderer> - the rendering context
5309  
5310 =back
5311  
5312 Returns C<0> on success or a negative error code on failure; call L<<
5313 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5314  
5315 =head2 C<SDL_RenderDrawPoint( ... )>
5316  
5317 Draw a point on the current rendering target.
5318  
5319 SDL_RenderDrawPoint( $renderer, 100, 100 );
5320  
5321 C<SDL_RenderDrawPoint( ... )> draws a single point. If you want to draw
5322 multiple, use L<< C<SDL_RenderDrawPoints( ... )>|/C<SDL_RenderDrawPoints( ...
5323 )> >> instead.
5324  
5325 Expected parameters include:
5326  
5327 =over
5328  
5329 =item C<renderer> - the rendering context
5330  
5331 =item C<x> - the x coordinate of the point
5332  
5333 =item C<y> - the y coordinate of the point
5334  
5335 =back
5336  
5337 Returns C<0> on success or a negative error code on failure; call L<<
5338 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5339  
5340 =head2 C<SDL_RenderDrawPoints( ... )>
5341  
5342 Draw multiple points on the current rendering target.
5343  
5344 my @points = map { SDL2::Point->new( {x => int rand, y => int rand } ) } 1..1024;
5345 SDL_RenderDrawPoints( $renderer, @points );
5346  
5347 =over
5348  
5349 =item C<renderer> - the rendering context
5350  
5351 =item C<points> - an array of L<SDL2::Point> structures that represent the points to draw
5352  
5353 =back
5354  
5355 Returns C<0> on success or a negative error code on failure; call L<<
5356 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5357  
5358 =head2 C<SDL_RenderDrawLine( ... )>
5359  
5360 Draw a line on the current rendering target.
5361  
5362 SDL_RenderDrawLine( $renderer, 300, 240, 340, 240 );
5363  
5364 C<SDL_RenderDrawLine( ... )> draws the line to include both end points. If you
5365 want to draw multiple, connecting lines use L<< C<SDL_RenderDrawLines( ...
5366 )>|/C<SDL_RenderDrawLines( ... )> >> instead.
5367  
5368 Expected parameters include:
5369  
5370 =over
5371  
5372 =item C<renderer> - the rendering context
5373  
5374 =item C<x1> - the x coordinate of the start point
5375  
5376 =item C<y1> - the y coordinate of the start point
5377  
5378 =item C<x2> - the x coordinate of the end point
5379  
5380 =item C<y2> - the y coordinate of the end point
5381  
5382 =back
5383  
5384 Returns C<0> on success or a negative error code on failure; call L<<
5385 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5386  
5387 =head2 C<SDL_RenderDrawLines( ... )>
5388  
5389 Draw a series of connected lines on the current rendering target.
5390  
5391 SDL_RenderDrawLines( $renderer, @points);
5392  
5393 Expected parameters include:
5394  
5395 =over
5396  
5397 =item C<renderer> - the rendering context
5398  
5399 =item C<points> - an array of L<SDL2::Point> structures representing points along the lines
5400  
5401 =back
5402  
5403 Returns C<0> on success or a negative error code on failure; call L<<
5404 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5405  
5406 =head2 C<SDL_RenderDrawRect( ... )>
5407  
5408 Draw a rectangle on the current rendering target.
5409  
5410 SDL_RenderDrawRect( $renderer, SDL2::Rect->new( { x => 100, y => 100, w => 100, h => 100 } ) );
5411  
5412 Expected parameters include:
5413  
5414 =over
5415  
5416 =item C<renderer> - the rendering context
5417  
5418 =item C<rect> - an L<SDL2::Rect> structure representing the rectangle to draw
5419  
5420 =for TODO - or undef to outline the entire rendering target
5421  
5422 =back
5423  
5424 Returns C<0> on success or a negative error code on failure; call L<<
5425 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5426  
5427 =head2 C<SDL_RenderDrawRects( ... )>
5428  
5429 Draw some number of rectangles on the current rendering target.
5430  
5431 SDL_RenderDrawRects( $renderer,
5432 SDL2::Rect->new( { x => 100, y => 100, w => 100, h => 100 } ),
5433 SDL2::Rect->new( { x => 75, y => 75, w => 50, h => 50 } )
5434 );
5435  
5436 Expected parameters include:
5437  
5438 =over
5439  
5440 =item C<renderer> - the rendering context
5441  
5442 =item C<rects> - an array of SDL2::Rect structures representing the rectangles to be drawn
5443  
5444 =back
5445  
5446 Returns C<0> on success or a negative error code on failure; call L<<
5447 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5448  
5449 =head2 C<SDL_RenderFillRect( ... )>
5450  
5451 Fill a rectangle on the current rendering target with the drawing color.
5452  
5453 SDL_RenderFillRect( $renderer, SDL2::Rect->new( { x => 100, y => 100, w => 100, h => 100 } ) );
5454  
5455 The current drawing color is set by L<< C<SDL_SetRenderDrawColor( ...
5456 )>|/C<SDL_SetRenderDrawColor( ... )> >>, and the color's alpha value is ignored
5457 unless blending is enabled with the appropriate call to L<<
5458 C<SDL_SetRenderDrawBlendMode( ... )>|/C<SDL_SetRenderDrawBlendMode( ... )> >>.
5459  
5460 Expected parameters include:
5461  
5462 =over
5463  
5464 =item C<renderer> - the rendering context
5465  
5466 =item C<rect> - the L<SDL2::Rect> structure representing the rectangle to fill
5467  
5468 =for TODO - or undef for the entire rendering target
5469  
5470 =back
5471  
5472 Returns C<0> on success or a negative error code on failure; call L<<
5473 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5474  
5475 =head2 C<SDL_RenderFillRects( ... )>
5476  
5477 Fill some number of rectangles on the current rendering target with the drawing
5478 color.
5479  
5480 SDL_RenderFillRects( $renderer,
5481 SDL2::Rect->new( { x => 100, y => 100, w => 100, h => 100 } ),
5482 SDL2::Rect->new( { x => 75, y => 75, w => 50, h => 50 } )
5483 );
5484  
5485 Expected parameters include:
5486  
5487 =over
5488  
5489 =item C<renderer> - the rendering context
5490  
5491 =item C<rects> - an array of L<SDL2::Rect> structures representing the rectangles to be filled
5492  
5493 =back
5494  
5495 Returns C<0> on success or a negative error code on failure; call L<<
5496 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5497  
5498 =head2 C<SDL_RenderCopy( ... )>
5499  
5500 Copy a portion of the texture to the current rendering target.
5501  
5502 SDL_RenderCopy( $renderer, $blueShapes, $srcR, $destR );
5503  
5504 The texture is blended with the destination based on its blend mode set with
5505 L<< C<SDL_SetTextureBlendMode( ... )>|/C<SDL_SetTextureBlendMode( ... )> >>.
5506  
5507 The texture color is affected based on its color modulation set by L<<
5508 C<SDL_SetTextureColorMod( ... )>|/C<SDL_SetTextureColorMod( ... )> >>.
5509  
5510 The texture alpha is affected based on its alpha modulation set by L<<
5511 C<SDL_SetTextureAlphaMod( ... )>|/C<SDL_SetTextureAlphaMod( ... )> >>.
5512  
5513 Expected parameters include:
5514  
5515 =over
5516  
5517 =item C<renderer> - the rendering context
5518  
5519 =item C<texture> - the source texture
5520  
5521 =item C<srcrect> - the source L<SDL2::Rect> structure
5522  
5523 =for TODO: or NULL for the entire texture
5524  
5525 =item C<dstrect> - the destination L<SDL2::Rect> structure; the texture will be stretched to fill the given rectangle
5526  
5527 =for TODO or NULL for the entire rendering target;
5528  
5529 =back
5530  
5531 Returns C<0> on success or a negative error code on failure; call L<<
5532 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5533  
5534 =head2 C<SDL_RenderCopyEx( ... )>
5535  
5536 Copy a portion of the texture to the current rendering, with optional rotation
5537 and flipping.
5538  
5539 =for TODO: I need an example for this... it's complex
5540  
5541 Copy a portion of the texture to the current rendering target, optionally
5542 rotating it by angle around the given center and also flipping it top-bottom
5543 and/or left-right.
5544  
5545 The texture is blended with the destination based on its blend mode set with
5546 L<< C<SDL_SetTextureBlendMode( ... )>|/C<SDL_SetTextureBlendMode( ... )> >>.
5547  
5548 The texture color is affected based on its color modulation set by L<<
5549 C<SDL_SetTextureColorMod( ... )>|/C<SDL_SetTextureColorMod( ... )> >>.
5550  
5551 The texture alpha is affected based on its alpha modulation set by L<<
5552 C<SDL_SetTextureAlphaMod( ... )>|/C<SDL_SetTextureAlphaMod( ... )> >>.
5553  
5554 Expected parameters include:
5555  
5556 =over
5557  
5558 =item C<renderer> - the rendering context
5559  
5560 =item C<texture> - the source texture
5561  
5562 =item C<srcrect> - the source L<SDL2::Rect> structure
5563  
5564 =for TODO: or NULL for the entire texture
5565  
5566 =item C<dstrect> - the destination SDL_Rect structure
5567  
5568 =for TODO: or NULL for the entire rendering target
5569  
5570 =item C<angle> - an angle in degrees that indicates the rotation that will be applied to dstrect, rotating it in a clockwise direction
5571  
5572 =item C<center> - a pointer to a point indicating the point around which dstrect will be rotated (if NULL, rotation will be done around C<dstrect.w / 2>, C<dstrect.h / 2>)
5573  
5574 =item C<flip> - a L<:rendererFlip> value stating which flipping actions should be performed on the texture
5575  
5576 =back
5577  
5578 Returns C<0> on success or a negative error code on failure; call L<<
5579 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5580  
5581 =head2 C<SDL_RenderDrawPointF( ... )>
5582  
5583 Draw a point on the current rendering target at subpixel precision.
5584  
5585 SDL_RenderDrawPointF( $renderer, 25.5, 100.25 );
5586  
5587 Expected parameters include:
5588  
5589 =over
5590  
5591 =item C<renderer> - The renderer which should draw a point.
5592  
5593 =item C<x> - The x coordinate of the point.
5594  
5595 =item C<y> - The y coordinate of the point.
5596  
5597 =back
5598  
5599 Returns C<0> on success, or C<-1> on error
5600  
5601 =head2 C<SDL_RenderDrawPointsF( ... )>
5602  
5603 Draw multiple points on the current rendering target at subpixel precision.
5604  
5605 my @points = map { SDL2::Point->new( {x => int rand, y => int rand } ) } 1..1024;
5606 SDL_RenderDrawPointsF( $renderer, @points );
5607  
5608 Expected parameters include:
5609  
5610 =over
5611  
5612 =item C<renderer> - The renderer which should draw multiple points
5613  
5614 =item C<points> - The points to draw
5615  
5616 =back
5617  
5618 Returns C<0> on success, or C<-1> on error; call L<< C<SDL_GetError(
5619 )>|/C<SDL_GetError( )> >>( ) for more information.
5620  
5621 =head2 C<SDL_RenderDrawLineF( ... )>
5622  
5623 Draw a line on the current rendering target at subpixel precision.
5624  
5625 SDL_RenderDrawLineF( $renderer, 100, 100, 250, 100);
5626  
5627 Expected parameters include:
5628  
5629 =over
5630  
5631 =item C<renderer> - The renderer which should draw a line.
5632  
5633 =item C<x1> - The x coordinate of the start point.
5634  
5635 =item C<y1> - The y coordinate of the start point.
5636  
5637 =item C<x2> - The x coordinate of the end point.
5638  
5639 =item C<y2> - The y coordinate of the end point.
5640  
5641 =back
5642  
5643 Returns C<0> on success, or C<-1> on error.
5644  
5645 =head2 C<SDL_RenderDrawLinesF( ... )>
5646  
5647 Draw a series of connected lines on the current rendering target at subpixel
5648 precision.
5649  
5650 SDL_RenderDrawLines( $renderer, @points);
5651  
5652 Expected parameters include:
5653  
5654 =over
5655  
5656 =item C<renderer> - The renderer which should draw multiple lines.
5657  
5658 =item C<points> - The points along the lines
5659  
5660 =back
5661  
5662 Return C<0> on success, or C<-1> on error.
5663  
5664 =head2 C<SDL_RenderDrawRectF( ... )>
5665  
5666 Draw a rectangle on the current rendering target at subpixel precision.
5667  
5668 SDL_RenderDrawRectF( $renderer, $point);
5669  
5670 Expected parameters include:
5671  
5672 =over
5673  
5674 =item C<renderer> - The renderer which should draw a rectangle.
5675  
5676 =item C<rect> - A pointer to the destination rectangle
5677  
5678 =for TODO: or NULL to outline the entire rendering target.
5679  
5680 =back
5681  
5682 Returns C<0> on success, or C<-1> on error
5683  
5684 =head2 C<SDL_RenderDrawRectsF( ... )>
5685  
5686 Draw some number of rectangles on the current rendering target at subpixel
5687 precision.
5688  
5689 SDL_RenderDrawRectsF( $renderer,
5690 SDL2::Rect->new( { x => 100, y => 100, w => 100, h => 100 } ),
5691 SDL2::Rect->new( { x => 75, y => 75, w => 50, h => 50 } )
5692 );
5693  
5694 Expected parameters include:
5695  
5696 =over
5697  
5698 =item C<renderer> - The renderer which should draw multiple rectangles.
5699  
5700 =item C<rects> - A pointer to an array of destination rectangles.
5701  
5702 =back
5703  
5704 Returns C<0> on success, or C<-1> on error.
5705  
5706 =head2 C<SDL_RenderFillRectF( ... )>
5707  
5708 Fill a rectangle on the current rendering target with the drawing color at
5709 subpixel precision.
5710  
5711 SDL_RenderFillRectF( $renderer,
5712 SDL2::Rect->new( { x => 75, y => 75, w => 50, h => 50 } )
5713 );
5714  
5715 Expected parameters include:
5716  
5717 =over
5718  
5719 =item C<renderer> - The renderer which should fill a rectangle.
5720  
5721 =item C<rect> - A pointer to the destination rectangle
5722  
5723 =for TODO: or NULL for the entire rendering target.
5724  
5725 =back
5726  
5727 Returns C<0> on success, or C<-1> on error.
5728  
5729 =head2 C<SDL_RenderFillRectsF( ... )>
5730  
5731 Fill some number of rectangles on the current rendering target with the drawing
5732 color at subpixel precision.
5733  
5734 SDL_RenderFillRectsF( $renderer,
5735 SDL2::Rect->new( { x => 100, y => 100, w => 100, h => 100 } ),
5736 SDL2::Rect->new( { x => 75, y => 75, w => 50, h => 50 } )
5737 );
5738  
5739 Expected parameters include:
5740  
5741 =over
5742  
5743 =item C<renderer> - The renderer which should fill multiple rectangles.
5744  
5745 =item C<rects> - A pointer to an array of destination rectangles.
5746  
5747 =back
5748  
5749 Returns C<0> on success, or C<-1> on error.
5750  
5751 =head2 C<SDL_RenderCopyF( ... )>
5752  
5753 Copy a portion of the texture to the current rendering target at subpixel
5754 precision.
5755  
5756 =for TODO: I need to come up with an example for this as well
5757  
5758 Expected parameters include:
5759  
5760 =over
5761  
5762 =item C<renderer> - The renderer which should copy parts of a texture
5763  
5764 =item C<texture> - The source texture
5765  
5766 =item C<srcrect> - A pointer to the source rectangle
5767  
5768 =for TODO: or NULL for the entiretexture.
5769  
5770 =item C<dstrect> - A pointer to the destination rectangle
5771  
5772 =for TODO: or NULL for the entire rendering target
5773  
5774 =back
5775  
5776 Returns C<0> on success, or C<-1> on error.
5777  
5778 =head2 C<SDL_RenderCopyExF( ... )>
5779  
5780 Copy a portion of the source texture to the current rendering target, with
5781 rotation and flipping, at subpixel precision.
5782  
5783 =for TODO: I need to come up with an example for this as well
5784  
5785 =over
5786  
5787 =item C<renderer> - The renderer which should copy parts of a texture
5788  
5789 =item C<texture> - The source texture
5790  
5791 =item C<srcrect> - A pointer to the source rectangle
5792  
5793 =for TODO: or NULL for the entire texture
5794  
5795 =item C<dstrect> - A pointer to the destination rectangle
5796  
5797 =for TODO: or NULL for the entire rendering target.
5798  
5799 =item C<angle> - An angle in degrees that indicates the rotation that will be applied to dstrect, rotating it in a clockwise direction
5800  
5801 =item C<center> - A pointer to a point indicating the point around which dstrect will be rotated (if NULL, rotation will be done around C<dstrect.w/2>, C<dstrect.h/2>)
5802  
5803 =item C<flip> - A C<:rendererFlip> value stating which flipping actions should be performed on the texture
5804  
5805 =back
5806  
5807 Returns C<0> on success, or C<-1> on error
5808  
5809 =head2 C<SDL_RenderReadPixels( ... )>
5810  
5811 Read pixels from the current rendering target to an array of pixels.
5812  
5813 SDL_RenderReadPixels(
5814 $renderer,
5815 SDL2::Rect->new( { x => 0, y => 0, w => 640, h => 480 } ),
5816 SDL_PIXELFORMAT_RGB888,
5817 $surface->pixels, $surface->pitch
5818 );
5819  
5820 B<WARNING>: This is a very slow operation, and should not be used frequently.
5821  
5822 C<pitch> specifies the number of bytes between rows in the destination
5823 C<pixels> data. This allows you to write to a subrectangle or have padded rows
5824 in the destination. Generally, C<pitch> should equal the number of pixels per
5825 row in the `pixels` data times the number of bytes per pixel, but it might
5826 contain additional padding (for example, 24bit RGB Windows Bitmap data pads all
5827 rows to multiples of 4 bytes).
5828  
5829 Expected parameters include:
5830  
5831 =over
5832  
5833 =item C<renderer> - the rendering context
5834  
5835 =item C<rect> - an L<SDL2::Rect> structure representing the area to read
5836  
5837 =for TODO: or NULL for the entire render target
5838  
5839 =item C<format> - an C<:pixelFormatEnum> value of the desired format of the pixel data, or C<0> to use the format of the rendering target
5840  
5841 =item C<pixels> - pointer to the pixel data to copy into
5842  
5843 =item C<pitch> - the pitch of the C<pixels> parameter
5844  
5845 =back
5846  
5847 Returns C<0> on success or a negative error code on failure; call L<<
5848 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5849  
5850 =head2 C<SDL_RenderPresent( ... )>
5851  
5852 Update the screen with any rendering performed since the previous call.
5853  
5854 SDL_RenderPresent( $renderer );
5855  
5856 SDL's rendering functions operate on a backbuffer; that is, calling a rendering
5857 function such as L<< C<SDL_RenderDrawLine( ... )>|/C<SDL_RenderDrawLine( ... )>
5858 >> does not directly put a line on the screen, but rather updates the
5859 backbuffer. As such, you compose your entire scene and *present* the composed
5860 backbuffer to the screen as a complete picture.
5861  
5862 Therefore, when using SDL's rendering API, one does all drawing intended for
5863 the frame, and then calls this function once per frame to present the final
5864 drawing to the user.
5865  
5866 The backbuffer should be considered invalidated after each present; do not
5867 assume that previous contents will exist between frames. You are strongly
5868 encouraged to call L<< C<SDL_RenderClear( ... )>|/C<SDL_RenderClear( ... )> >>
5869 to initialize the backbuffer before starting each new frame's drawing, even if
5870 you plan to overwrite every pixel.
5871  
5872 Expected parameters include:
5873  
5874 =over
5875  
5876 =item C<renderer> - the rendering context
5877  
5878 =back
5879  
5880 =head2 C<SDL_DestroyTexture( ... )>
5881  
5882 Destroy the specified texture.
5883  
5884 SDL_DestroyTexture( $texture );
5885  
5886 Passing undef or an otherwise invalid texture will set the SDL error message to
5887 "Invalid texture".
5888  
5889 Expected parameters include:
5890  
5891 =over
5892  
5893 =item C<texture> - the texture to destroy
5894  
5895 =back
5896  
5897  
5898 =head2 C<SDL_DestroyRenderer( ... )>
5899  
5900 Destroy the rendering context for a window and free associated textures.
5901  
5902 SDL_DestroyRenderer( $renderer );
5903  
5904 Expected parameters include:
5905  
5906 =over
5907  
5908 =item C<renderer> - the rendering context
5909  
5910 =back
5911  
5912 =head2 C<SDL_RenderFlush( ... )>
5913  
5914 Force the rendering context to flush any pending commands to the underlying
5915 rendering API.
5916  
5917 SDL_RenderFlush( $renderer );
5918  
5919 You do not need to (and in fact, shouldn't) call this function unless you are
5920 planning to call into OpenGL/Direct3D/Metal/whatever directly in addition to
5921 using an SDL_Renderer.
5922  
5923 This is for a very-specific case: if you are using SDL's render API, you asked
5924 for a specific renderer backend (OpenGL, Direct3D, etc), you set
5925 C<SDL_HINT_RENDER_BATCHING> to "C<1>", and you plan to make OpenGL/D3D/whatever
5926 calls in addition to SDL render API calls. If all of this applies, you should
5927 call L<< C<SDL_RenderFlush( ... )>|/C<SDL_RenderFlush( ... )> >> between calls
5928 to SDL's render API and the low-level API you're using in cooperation.
5929  
5930 In all other cases, you can ignore this function. This is only here to get
5931 maximum performance out of a specific situation. In all other cases, SDL will
5932 do the right thing, perhaps at a performance loss.
5933  
5934 This function is first available in SDL 2.0.10, and is not needed in 2.0.9 and
5935 earlier, as earlier versions did not queue rendering commands at all, instead
5936 flushing them to the OS immediately.
5937  
5938 Expected parameters include:
5939  
5940 =over
5941  
5942 =item C<renderer> - the rendering context
5943  
5944 =back
5945  
5946 Returns C<0> on success or a negative error code on failure; call L<<
5947 C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more information.
5948  
5949  
5950 =head2 C<SDL_GL_BindTexture( ... )>
5951  
5952 Bind an OpenGL/ES/ES2 texture to the current context.
5953  
5954 my ($texw, $texh) = SDL_GL_BindTexture( $texture );
5955  
5956 This is for use with OpenGL instructions when rendering OpenGL primitives
5957 directly.
5958  
5959 If not NULL, the returned width and height values suitable for the provided
5960 texture. In most cases, both will be C<1.0>, however, on systems that support
5961 the GL_ARB_texture_rectangle extension, these values will actually be the pixel
5962 width and height used to create the texture, so this factor needs to be taken
5963 into account when providing texture coordinates to OpenGL.
5964  
5965 You need a renderer to create an L<SDL2::Texture>, therefore you can only use
5966 this function with an implicit OpenGL context from L<< C<SDL_CreateRenderer(
5967 ... )>|/C<SDL_CreateRenderer( ... )> >>, not with your own OpenGL context. If
5968 you need control over your OpenGL context, you need to write your own
5969 texture-loading methods.
5970  
5971 Also note that SDL may upload RGB textures as BGR (or vice-versa), and re-order
5972 the color channels in the shaders phase, so the uploaded texture may have
5973 swapped color channels.
5974  
5975 Expected parameters include:
5976  
5977 =over
5978  
5979 =item C<texture> - the texture to bind to the current OpenGL/ES/ES2 context
5980  
5981 =back
5982  
5983 Returns the texture's with and height on success, or -1 if the operation is not
5984 supported; call L<< C<SDL_GetError( )>|/C<SDL_GetError( )> >>( ) for more
5985 information.
5986  
5987 =head2 C<SDL_GL_UnbindTexture( ... )>
5988  
5989 Unbind an OpenGL/ES/ES2 texture from the current context.
5990  
5991 SDL_GL_UnbindTexture( $texture );
5992  
5993 See L<< C<SDL_GL_BindTexture( ... )>|/C<SDL_GL_BindTexture( ... )> >> for
5994 examples on how to use these functions.
5995  
5996 Expected parameters include:
5997  
5998 =over
5999  
6000 =item C<texture> - the texture to unbind from the current OpenGL/ES/ES2 context
6001  
6002 =back
6003  
6004 Returns C<0> on success, or C<-1> if the operation is not supported.
6005  
6006 =head2 C<SDL_RenderGetMetalLayer( ... )>
6007  
6008 Get the CAMetalLayer associated with the given Metal renderer.
6009  
6010 my $opaque = SDL_RenderGetMetalLayer( $renderer );
6011  
6012 This function returns C<void *>, so SDL doesn't have to include Metal's
6013 headers, but it can be safely cast to a C<CAMetalLayer *>.
6014  
6015 Expected parameters include:
6016  
6017 =over
6018  
6019 =item C<renderer> - the renderer to query
6020  
6021 =back
6022  
6023 Returns C<CAMetalLayer*> on success, or undef if the renderer isn't a Metal
6024 renderer.
6025  
6026 =head2 C<SDL_RenderGetMetalCommandEncoder( ... )>
6027  
6028 Get the Metal command encoder for the current frame
6029  
6030 $opaque = SDL_RenderGetMetalCommandEncoder( $renderer );
6031  
6032 This function returns C<void *>, so SDL doesn't have to include Metal's
6033 headers, but it can be safely cast to an
6034 C<idE<lt>MTLRenderCommandEncoderE<gt>>.
6035  
6036 Expected parameters include:
6037  
6038 =over
6039  
6040 =item C<renderer> - the renderer to query
6041  
6042 =back
6043  
6044 Returns C<idE<lt>MTLRenderCommandEncoderE<gt>> on success, or undef if the
6045 renderer isn't a Metal renderer.
6046  
6047  
6048  
6049  
6050  
6051  
6052  
6053  
6054  
6055  
6056  
6057  
6058  
6059  
6060  
6061  
6062  
6063  
6064  
6065  
6066  
6067  
6068  
6069  
6070  
6071  
6072  
6073  
6074  
6075  
6076  
6077  
6078  
6079  
6080  
6081  
6082  
6083  
6084  
6085  
6086  
6087  
6088  
6089  
6090  
6091  
6092  
6093  
6094  
6095  
6096  
6097  
6098  
6099 =head2 C<SDL_ComposeCustomBlendMode( ... )>
6100  
6101 Compose a custom blend mode for renderers.
6102  
6103  
6104  
6105 The functions SDL_SetRenderDrawBlendMode and SDL_SetTextureBlendMode accept the
6106 SDL_BlendMode returned by this function if the renderer supports it.
6107  
6108 A blend mode controls how the pixels from a drawing operation (source) get
6109 combined with the pixels from the render target (destination). First, the
6110 components of the source and destination pixels get multiplied with their blend
6111 factors. Then, the blend operation takes the two products and calculates the
6112 result that will get stored in the render target.
6113  
6114 Expressed in pseudocode, it would look like this:
6115  
6116 my $dstRGB = colorOperation( $srcRGB * $srcColorFactor, $dstRGB * $dstColorFactor );
6117 my $dstA = alphaOperation( $srcA * $srcAlphaFactor, $dstA * $dstAlphaFactor );
6118  
6119 Where the functions C<colorOperation(src, dst)> and C<alphaOperation(src, dst)>
6120 can return one of the following:
6121  
6122 =over
6123  
6124 =item C<src + dst>
6125  
6126 =item C<src - dst>
6127  
6128 =item C<dst - src>
6129  
6130 =item C<min(src, dst)>
6131  
6132 =item C<max(src, dst)>
6133  
6134 =back
6135  
6136 The red, green, and blue components are always multiplied with the first,
6137 second, and third components of the SDL_BlendFactor, respectively. The fourth
6138 component is not used.
6139  
6140 The alpha component is always multiplied with the fourth component of the L<<
6141 C<:blendFactor>|/C<:blendFactor> >>. The other components are not used in the
6142 alpha calculation.
6143  
6144 Support for these blend modes varies for each renderer. To check if a specific
6145 L<< C<:blendMode>|/C<:blendMode> >> is supported, create a renderer and pass it
6146 to either C<SDL_SetRenderDrawBlendMode> or C<SDL_SetTextureBlendMode>. They
6147 will return with an error if the blend mode is not supported.
6148  
6149 This list describes the support of custom blend modes for each renderer in SDL
6150 2.0.6. All renderers support the four blend modes listed in the L<<
6151 C<:blendMode>|/C<:blendMode> >> enumeration.
6152  
6153 =over
6154  
6155 =item B<direct3d> - Supports C<SDL_BLENDOPERATION_ADD> with all factors.
6156  
6157 =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>.
6158  
6159 =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.
6160  
6161 =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.
6162  
6163 =item B<opengles2> - Supports the C<SDL_BLENDOPERATION_ADD>, C<SDL_BLENDOPERATION_SUBTRACT>, C<SDL_BLENDOPERATION_REV_SUBTRACT> operations with all factors.
6164  
6165 =item B<psp> - No custom blend mode support.
6166  
6167 =item B<software> - No custom blend mode support.
6168  
6169 =back
6170  
6171 Some renderers do not provide an alpha component for the default render target.
6172 The C<SDL_BLENDFACTOR_DST_ALPHA> and C<SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA>
6173 factors do not have an effect in this case.
6174  
6175 Expected parameters include:
6176  
6177 =over
6178  
6179 =item C<srcColorFactor> -the C<:blendFactor> applied to the red, green, and blue components of the source pixels
6180  
6181 =item C<dstColorFactor> - the C<:blendFactor> applied to the red, green, and blue components of the destination pixels
6182  
6183 =item C<colorOperation> - the C<:blendOperation> used to combine the red, green, and blue components of the source and destination pixels
6184  
6185 =item C<srcAlphaFactor> - the C<:blendFactor> applied to the alpha component of the source pixels
6186  
6187 =item C<dstAlphaFactor> - the C<:blendFactor> applied to the alpha component of the destination pixels
6188  
6189 =item C<alphaOperation> - the C<:blendOperation> used to combine the alpha component of the source and destination pixels
6190  
6191 =back
6192  
6193 Returns a C<:blendMode> that represents the chosen factors and operations.
6194  
6195 =head1 Time Management Routines
6196  
6197 This section contains functions for handling the SDL time management routines.
6198 They may be imported with the C<:timer> tag.
6199  
6200 =head2 C<SDL_GetTicks( )>
6201  
6202 Get the number of milliseconds since SDL library initialization.
6203  
6204 my $time = SDL_GetTicks( );
6205  
6206 This value wraps if the program runs for more than C<~49> days.
6207  
6208 Returns an unsigned 32-bit value representing the number of milliseconds since
6209 the SDL library initialized.
6210  
6211 =head2 C<SDL_GetPerformanceCounter( )>
6212  
6213 Get the current value of the high resolution counter.
6214  
6215 my $high_timer = SDL_GetPerformanceCounter( );
6216  
6217 This function is typically used for profiling.
6218  
6219 The counter values are only meaningful relative to each other. Differences
6220 between values can be converted to times by using L<<
6221 C<SDL_GetPerformanceFrequency( )>|/C<SDL_GetPerformanceFrequency( )> >>.
6222  
6223 Returns the current counter value.
6224  
6225 =head2 C<SDL_GetPerformanceFrequency( ... )>
6226  
6227 Get the count per second of the high resolution counter.
6228  
6229 my $hz = SDL_GetPerformanceFrequency( );
6230  
6231 Returns a platform-specific count per second.
6232  
6233 =head2 C<SDL_Delay( ... )>
6234  
6235 Wait a specified number of milliseconds before returning.
6236  
6237 SDL_Delay( 1000 );
6238  
6239 This function waits a specified number of milliseconds before returning. It
6240 waits at least the specified time, but possibly longer due to OS scheduling.
6241  
6242 Expected parameters include:
6243  
6244 =over
6245  
6246 =item C<ms> - the number of milliseconds to delay
6247  
6248 =back
6249  
6250 =head2 C<SDL_AddTimer( ... )>
6251  
6252 Call a callback function at a future time.
6253  
6254 my $id = SDL_AddTimer( 1000, sub ( $interval, $data ) { warn 'ping!'; $interval; } );
6255  
6256 If you use this function, you must pass C<SDL_INIT_TIMER> to L<< C<SDL_Init(
6257 ... )>|/C<SDL_Init( ... )> >>.
6258  
6259 The callback function is passed the current timer interval and returns the next
6260 timer interval. If the returned value is the same as the one passed in, the
6261 periodic alarm continues, otherwise a new alarm is scheduled. If the callback
6262 returns C<0>, the periodic alarm is cancelled.
6263  
6264 The callback is run on a separate thread.
6265  
6266 Timers take into account the amount of time it took to execute the callback.
6267 For example, if the callback took 250 ms to execute and returned 1000 (ms), the
6268 timer would only wait another 750 ms before its next iteration.
6269  
6270 Timing may be inexact due to OS scheduling. Be sure to note the current time
6271 with L<< C<SDL_GetTicks( )>|/C<SDL_GetTicks( )> >> or L<<
6272 C<SDL_GetPerformanceCounter( )>|/C<SDL_GetPerformanceCounter( )> >> in case
6273 your callback needs to adjust for variances.
6274  
6275 Expected parameters include:
6276  
6277 =over
6278  
6279 =item C<interval> - the timer delay, in milliseconds, passed to C<callback>
6280  
6281 =item C<callback> - the C<CODE> reference to call when the specified C<interval> elapses
6282  
6283 =item C<param> - a pointer that is passed to C<callback>
6284  
6285 =back
6286  
6287 Returns a timer ID or C<0> if an error occurs; call L<< C<SDL_GetError(
6288 )>|/C<SDL_GetError( )> >>( ) for more information.
6289  
6290 =head2 C<SDL_RemoveTimer( ... )>
6291  
6292 SDL_RemoveTimer( $id );
6293  
6294 Remove a timer created with L<< C<SDL_AddTimer( ... )>|/C<SDL_AddTimer( ... )>
6295 >>.
6296  
6297 Expected parameters include:
6298  
6299 =over
6300  
6301 =item C<id> - the ID of the timer to remove
6302  
6303 =back
6304  
6305 Returns true if the timer is removed or false if the timer wasn't found.
6306  
6307 =head1 Raw Audio Mixing
6308  
6309 These methods provide access to the raw audio mixing buffer for the SDL
6310 library. They may be imported with the C<:audio> tag.
6311  
6312 =head2 C<SDL_GetNumAudioDrivers( )>
6313  
6314 Returns a list of built in audio drivers, in the order that they were normally
6315 initialized by default.
6316  
6317 =head2 C<SDL_GetAudioDriver( ... )>
6318  
6319 Returns an audio driver by name.
6320  
6321 my $driver = SDL_GetAudioDriver( 1 );
6322  
6323 Expected parameters include:
6324  
6325 =over
6326  
6327 =item C<index> - The zero-based index of the desired audio driver
6328  
6329 =back
6330  
6331 =head2 C<SDL_AudioInit( ... )>
6332  
6333 Audio system initialization.
6334  
6335 SDL_AudioInit( 'pulseaudio' );
6336  
6337 This method is used internally, and should not be used unless you have a
6338 specific need to specify the audio driver you want to use. You should normally
6339 use L<< C<SDL_Init( ... )>|/C<SDL_Init( ... )> >>.
6340  
6341 Returns C<0> on success.
6342  
6343 =head2 C<SDL_AudioQuit( )>
6344  
6345 Cleaning up initialized audio system.
6346  
6347 SDL_AudioQuit( );
6348  
6349 This method is used internally, and should not be used unless you have a
6350 specific need to close the selected audio driver. You should normally use L<<
6351 C<SDL_Quit( )>|/C<SDL_Quit( )> >>.
6352  
6353 =head2 C<SDL_GetCurrentAudioDriver( )>
6354  
6355 Get the name of the current audio driver.
6356  
6357 my $driver = SDL_GetCurrentAudioDriver( );
6358  
6359 The returned string points to internal static memory and thus never becomes
6360 invalid, even if you quit the audio subsystem and initialize a new driver
6361 (although such a case would return a different static string from another call
6362 to this function, of course). As such, you should not modify or free the
6363 returned string.
6364  
6365 Returns the name of the current audio driver or undef if no driver has been
6366 initialized.
6367  
6368 =head2 C<SDL_OpenAudio( ... )>
6369  
6370 This function is a legacy means of opening the audio device.
6371  
6372 my $obtained = SDL_OpenAudio(
6373 SDL2::AudioSpec->new( { freq => 48000, channels => 2, format => AUDIO_F32 } ) );
6374  
6375 This function remains for compatibility with SDL 1.2, but also because it's
6376 slightly easier to use than the new functions in SDL 2.0. The new, more
6377 powerful, and preferred way to do this is L<< C<SDL_OpenAudioDevice( ...
6378 )>|/C<SDL_OpenAudioDevice( ... )> >> .
6379  
6380 This function is roughly equivalent to:
6381  
6382 SDL_OpenAudioDevice( (), 0, $desired, SDL_AUDIO_ALLOW_ANY_CHANGE );
6383  
6384 With two notable exceptions:
6385  
6386 =over
6387  
6388 =item - If C<obtained> is undefined, we use C<desired> (and allow no changes), which
6389 means desired will be modified to have the correct values for silence,
6390 etc, and SDL will convert any differences between your app's specific
6391 request and the hardware behind the scenes.
6392  
6393 =item - The return value is always success or failure, and not a device ID, which
6394 means you can only have one device open at a time with this function.
6395  
6396 =back
6397  
6398 * \param desired an SDL_AudioSpec structure representing the desired output
6399 * format. Please refer to the SDL_OpenAudioDevice documentation
6400 * for details on how to prepare this structure.
6401 * \param obtained an SDL_AudioSpec structure filled in with the actual
6402 * parameters, or NULL.
6403 * \returns This function opens the audio device with the desired parameters,
6404 * and returns 0 if successful, placing the actual hardware
6405 * parameters in the structure pointed to by `obtained`.
6406 *
6407 * If `obtained` is NULL, the audio data passed to the callback
6408 * function will be guaranteed to be in the requested format, and
6409 * will be automatically converted to the actual hardware audio
6410 * format if necessary. If `obtained` is NULL, `desired` will
6411 * have fields modified.
6412 *
6413 * This function returns a negative error code on failure to open the
6414 * audio device or failure to set up the audio thread; call
6415 * SDL_GetError() for more information.
6416  
6417  
6418
6419 =head1 LICENSE
6420  
6421 Copyright (C) Sanko Robinson.
6422  
6423 This library is free software; you can redistribute it and/or modify it under
6424 the terms found in the Artistic License 2. Other copyrights, terms, and
6425 conditions may apply to data transmitted through this module.
6426  
6427 =head1 AUTHOR
6428  
6429 Sanko Robinson E<lt>sanko@cpan.orgE<gt>
6430  
6431 =begin stopwords
6432  
6433 libSDL enum iOS iPhone tvOS gamepad gamepads bitmap colorkey asyncify keycode
6434 ctrl+click OpenGL glibc pthread screensaver fullscreen SDL_gamecontroller.h
6435 XBox XInput pthread pthreads realtime rtkit Keycode mutexes resources imple
6436 irectMedia ayer errstr coderef patchlevel distro WinRT raspberrypi psp macOS
6437 NSHighResolutionCapable lowlevel vsync gamecontroller framebuffer XRandR
6438 XVidMode libc musl non letterbox libsamplerate AVAudioSessionCategoryAmbient
6439 AVAudioSessionCategoryPlayback VoIP OpenGLES opengl opengles opengles2 spammy
6440 popup tooltip taskbar subwindow high-dpi subpixel borderless draggable viewport
6441 user-resizable resizable srcA srcC GiB dstrect rect subrectangle pseudocode ms
6442 verystrict resampler eglSwapBuffers backbuffer scancode unhandled lifespan wgl
6443 glX framerate deadzones vice-versa kmsdrm jp CAMetalLayer
6444  
6445 =end stopwords
6446  
6447 =cut
6448  
6449 # Examples:
6450 # - https://github.com/crust/sdl2-examples
6451 #