sdl3 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +7 -0
  3. data/LICENSE +21 -0
  4. data/README.md +188 -0
  5. data/Rakefile +12 -0
  6. data/examples/01_hello_window.rb +24 -0
  7. data/examples/02_basic_rendering.rb +45 -0
  8. data/examples/03_keyboard_input.rb +52 -0
  9. data/examples/04_mouse_input.rb +56 -0
  10. data/examples/05_simple_game.rb +107 -0
  11. data/lib/sdl3/high_level/audio_device.rb +202 -0
  12. data/lib/sdl3/high_level/camera.rb +118 -0
  13. data/lib/sdl3/high_level/clipboard.rb +59 -0
  14. data/lib/sdl3/high_level/event.rb +240 -0
  15. data/lib/sdl3/high_level/gamepad.rb +190 -0
  16. data/lib/sdl3/high_level/gpu.rb +194 -0
  17. data/lib/sdl3/high_level/haptic.rb +213 -0
  18. data/lib/sdl3/high_level/joystick.rb +165 -0
  19. data/lib/sdl3/high_level/renderer.rb +163 -0
  20. data/lib/sdl3/high_level/sensor.rb +105 -0
  21. data/lib/sdl3/high_level/surface.rb +143 -0
  22. data/lib/sdl3/high_level/texture.rb +111 -0
  23. data/lib/sdl3/high_level/timer.rb +88 -0
  24. data/lib/sdl3/high_level/window.rb +151 -0
  25. data/lib/sdl3/library_loader.rb +63 -0
  26. data/lib/sdl3/raw/assert.rb +32 -0
  27. data/lib/sdl3/raw/asyncio.rb +36 -0
  28. data/lib/sdl3/raw/atomic.rb +40 -0
  29. data/lib/sdl3/raw/audio.rb +95 -0
  30. data/lib/sdl3/raw/base.rb +12 -0
  31. data/lib/sdl3/raw/bits.rb +17 -0
  32. data/lib/sdl3/raw/blendmode.rb +36 -0
  33. data/lib/sdl3/raw/camera.rb +38 -0
  34. data/lib/sdl3/raw/clipboard.rb +20 -0
  35. data/lib/sdl3/raw/cpuinfo.rb +29 -0
  36. data/lib/sdl3/raw/dialog.rb +33 -0
  37. data/lib/sdl3/raw/endian.rb +8 -0
  38. data/lib/sdl3/raw/error.rb +15 -0
  39. data/lib/sdl3/raw/events.rb +563 -0
  40. data/lib/sdl3/raw/filesystem.rb +47 -0
  41. data/lib/sdl3/raw/gamepad.rb +135 -0
  42. data/lib/sdl3/raw/gpu.rb +734 -0
  43. data/lib/sdl3/raw/guid.rb +12 -0
  44. data/lib/sdl3/raw/haptic.rb +167 -0
  45. data/lib/sdl3/raw/hidapi.rb +57 -0
  46. data/lib/sdl3/raw/hints.rb +20 -0
  47. data/lib/sdl3/raw/init.rb +27 -0
  48. data/lib/sdl3/raw/iostream.rb +88 -0
  49. data/lib/sdl3/raw/joystick.rb +101 -0
  50. data/lib/sdl3/raw/keyboard.rb +30 -0
  51. data/lib/sdl3/raw/keycode.rb +132 -0
  52. data/lib/sdl3/raw/loadso.rb +9 -0
  53. data/lib/sdl3/raw/locale.rb +12 -0
  54. data/lib/sdl3/raw/log.rb +61 -0
  55. data/lib/sdl3/raw/main.rb +23 -0
  56. data/lib/sdl3/raw/messagebox.rb +50 -0
  57. data/lib/sdl3/raw/metal.rb +9 -0
  58. data/lib/sdl3/raw/misc.rb +7 -0
  59. data/lib/sdl3/raw/mouse.rb +82 -0
  60. data/lib/sdl3/raw/mutex.rb +48 -0
  61. data/lib/sdl3/raw/openxr.rb +21 -0
  62. data/lib/sdl3/raw/pen.rb +38 -0
  63. data/lib/sdl3/raw/pixels.rb +180 -0
  64. data/lib/sdl3/raw/platform.rb +7 -0
  65. data/lib/sdl3/raw/power.rb +14 -0
  66. data/lib/sdl3/raw/process.rb +15 -0
  67. data/lib/sdl3/raw/properties.rb +39 -0
  68. data/lib/sdl3/raw/rect.rb +41 -0
  69. data/lib/sdl3/raw/render.rb +153 -0
  70. data/lib/sdl3/raw/scancode.rb +112 -0
  71. data/lib/sdl3/raw/sensor.rb +31 -0
  72. data/lib/sdl3/raw/stdinc.rb +209 -0
  73. data/lib/sdl3/raw/storage.rb +50 -0
  74. data/lib/sdl3/raw/surface.rb +106 -0
  75. data/lib/sdl3/raw/system.rb +77 -0
  76. data/lib/sdl3/raw/thread.rb +40 -0
  77. data/lib/sdl3/raw/time.rb +36 -0
  78. data/lib/sdl3/raw/timer.rb +19 -0
  79. data/lib/sdl3/raw/touch.rb +22 -0
  80. data/lib/sdl3/raw/tray.rb +42 -0
  81. data/lib/sdl3/raw/types.rb +21 -0
  82. data/lib/sdl3/raw/version.rb +8 -0
  83. data/lib/sdl3/raw/video.rb +208 -0
  84. data/lib/sdl3/raw/vulkan.rb +13 -0
  85. data/lib/sdl3/version.rb +5 -0
  86. data/lib/sdl3.rb +128 -0
  87. data/sdl3.gemspec +30 -0
  88. metadata +143 -0
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SDL3
4
+ class Timer
5
+ attr_reader :id
6
+
7
+ def initialize(interval_ms, &callback)
8
+ raise ArgumentError, "block required" unless callback
9
+
10
+ @callback = callback
11
+ @prevent_gc = proc do |userdata, timer_id, interval|
12
+ @callback.call(timer_id, interval)
13
+ end
14
+ @id = Raw.SDL_AddTimer(interval_ms, @prevent_gc, nil)
15
+ raise Error, Raw.SDL_GetError if @id.zero?
16
+ end
17
+
18
+ def self.create(interval_ms, &callback)
19
+ timer = new(interval_ms, &callback)
20
+ return timer unless block_given?
21
+
22
+ begin
23
+ yield timer
24
+ ensure
25
+ timer.remove
26
+ end
27
+ end
28
+
29
+ def self.create_ns(interval_ns, &callback)
30
+ raise ArgumentError, "block required" unless callback
31
+
32
+ timer = allocate
33
+ timer.instance_variable_set(:@callback, callback)
34
+ prevent_gc = proc do |userdata, timer_id, interval|
35
+ callback.call(timer_id, interval)
36
+ end
37
+ timer.instance_variable_set(:@prevent_gc, prevent_gc)
38
+ timer_id = Raw.SDL_AddTimerNS(interval_ns, prevent_gc, nil)
39
+ raise Error, Raw.SDL_GetError if timer_id.zero?
40
+
41
+ timer.instance_variable_set(:@id, timer_id)
42
+
43
+ return timer unless block_given?
44
+
45
+ begin
46
+ yield timer
47
+ ensure
48
+ timer.remove
49
+ end
50
+ end
51
+
52
+ def remove
53
+ return false if @id.zero?
54
+
55
+ result = Raw.SDL_RemoveTimer(@id)
56
+ @id = 0 if result
57
+ result
58
+ end
59
+
60
+ def self.ticks
61
+ Raw.SDL_GetTicks
62
+ end
63
+
64
+ def self.ticks_ns
65
+ Raw.SDL_GetTicksNS
66
+ end
67
+
68
+ def self.performance_counter
69
+ Raw.SDL_GetPerformanceCounter
70
+ end
71
+
72
+ def self.performance_frequency
73
+ Raw.SDL_GetPerformanceFrequency
74
+ end
75
+
76
+ def self.delay(ms)
77
+ Raw.SDL_Delay(ms)
78
+ end
79
+
80
+ def self.delay_ns(ns)
81
+ Raw.SDL_DelayNS(ns)
82
+ end
83
+
84
+ def self.delay_precise(ns)
85
+ Raw.SDL_DelayPrecise(ns)
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,151 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SDL3
4
+ class Window
5
+ attr_reader :ptr
6
+
7
+ FULLSCREEN = Raw::SDL_WINDOW_FULLSCREEN
8
+ OPENGL = Raw::SDL_WINDOW_OPENGL
9
+ HIDDEN = Raw::SDL_WINDOW_HIDDEN
10
+ BORDERLESS = Raw::SDL_WINDOW_BORDERLESS
11
+ RESIZABLE = Raw::SDL_WINDOW_RESIZABLE
12
+ MINIMIZED = Raw::SDL_WINDOW_MINIMIZED
13
+ MAXIMIZED = Raw::SDL_WINDOW_MAXIMIZED
14
+ VULKAN = Raw::SDL_WINDOW_VULKAN
15
+ METAL = Raw::SDL_WINDOW_METAL
16
+
17
+ def initialize(title, width, height, flags = 0)
18
+ @ptr = Raw.SDL_CreateWindow(title, width, height, flags)
19
+ raise Error, Raw.SDL_GetError if @ptr.null?
20
+
21
+ ObjectSpace.define_finalizer(self, self.class.releasing(@ptr))
22
+ end
23
+
24
+ def self.releasing(ptr)
25
+ prevented_ptr = ptr
26
+ proc { Raw.SDL_DestroyWindow(prevented_ptr) unless prevented_ptr.null? }
27
+ end
28
+
29
+ def self.open(title, width, height, flags = 0)
30
+ window = new(title, width, height, flags)
31
+ return window unless block_given?
32
+
33
+ begin
34
+ yield window
35
+ ensure
36
+ window.destroy
37
+ end
38
+ end
39
+
40
+ def destroy
41
+ return if @ptr.null?
42
+
43
+ ObjectSpace.undefine_finalizer(self)
44
+ Raw.SDL_DestroyWindow(@ptr)
45
+ @ptr = FFI::Pointer::NULL
46
+ end
47
+
48
+ def id
49
+ Raw.SDL_GetWindowID(@ptr)
50
+ end
51
+
52
+ def title
53
+ Raw.SDL_GetWindowTitle(@ptr)
54
+ end
55
+
56
+ def title=(value)
57
+ Raw.SDL_SetWindowTitle(@ptr, value)
58
+ end
59
+
60
+ def size
61
+ w = FFI::MemoryPointer.new(:int)
62
+ h = FFI::MemoryPointer.new(:int)
63
+ Raw.SDL_GetWindowSize(@ptr, w, h)
64
+ [w.read_int, h.read_int]
65
+ end
66
+
67
+ def size=(dimensions)
68
+ Raw.SDL_SetWindowSize(@ptr, dimensions[0], dimensions[1])
69
+ end
70
+
71
+ def width
72
+ size[0]
73
+ end
74
+
75
+ def height
76
+ size[1]
77
+ end
78
+
79
+ def position
80
+ x = FFI::MemoryPointer.new(:int)
81
+ y = FFI::MemoryPointer.new(:int)
82
+ Raw.SDL_GetWindowPosition(@ptr, x, y)
83
+ [x.read_int, y.read_int]
84
+ end
85
+
86
+ def position=(coords)
87
+ Raw.SDL_SetWindowPosition(@ptr, coords[0], coords[1])
88
+ end
89
+
90
+ def show
91
+ Raw.SDL_ShowWindow(@ptr)
92
+ end
93
+
94
+ def hide
95
+ Raw.SDL_HideWindow(@ptr)
96
+ end
97
+
98
+ def raise_window
99
+ Raw.SDL_RaiseWindow(@ptr)
100
+ end
101
+
102
+ def maximize
103
+ Raw.SDL_MaximizeWindow(@ptr)
104
+ end
105
+
106
+ def minimize
107
+ Raw.SDL_MinimizeWindow(@ptr)
108
+ end
109
+
110
+ def restore
111
+ Raw.SDL_RestoreWindow(@ptr)
112
+ end
113
+
114
+ def fullscreen=(enabled)
115
+ Raw.SDL_SetWindowFullscreen(@ptr, enabled)
116
+ end
117
+
118
+ def bordered=(enabled)
119
+ Raw.SDL_SetWindowBordered(@ptr, enabled)
120
+ end
121
+
122
+ def resizable=(enabled)
123
+ Raw.SDL_SetWindowResizable(@ptr, enabled)
124
+ end
125
+
126
+ def opacity
127
+ Raw.SDL_GetWindowOpacity(@ptr)
128
+ end
129
+
130
+ def opacity=(value)
131
+ Raw.SDL_SetWindowOpacity(@ptr, value)
132
+ end
133
+
134
+ def surface
135
+ ptr = Raw.SDL_GetWindowSurface(@ptr)
136
+ raise Error, Raw.SDL_GetError if ptr.null?
137
+
138
+ Surface.from_ptr(ptr, owned: false)
139
+ end
140
+
141
+ def update_surface
142
+ raise Error, Raw.SDL_GetError unless Raw.SDL_UpdateWindowSurface(@ptr)
143
+
144
+ true
145
+ end
146
+
147
+ def to_ptr
148
+ @ptr
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rbconfig"
4
+
5
+ module SDL3
6
+ module LibraryLoader
7
+ LIBRARY_NAMES = {
8
+ "linux" => ["libSDL3.so.0", "libSDL3.so"],
9
+ "darwin" => ["libSDL3.dylib", "SDL3.framework/SDL3"],
10
+ "mingw" => ["SDL3.dll"],
11
+ "mswin" => ["SDL3.dll"]
12
+ }.freeze
13
+
14
+ SEARCH_PATHS = {
15
+ "linux" => ["/usr/lib", "/usr/local/lib", "/usr/lib/x86_64-linux-gnu"],
16
+ "darwin" => ["/opt/homebrew/lib", "/usr/local/lib", "/Library/Frameworks"],
17
+ "mingw" => [],
18
+ "mswin" => []
19
+ }.freeze
20
+
21
+ class << self
22
+ def library_name
23
+ platform = detect_platform
24
+ names = LIBRARY_NAMES[platform]
25
+ raise LoadError, "Unsupported platform: #{platform}" unless names
26
+
27
+ names.each do |name|
28
+ return name if library_available?(name)
29
+ end
30
+
31
+ paths = SEARCH_PATHS[platform] || []
32
+ paths.each do |path|
33
+ names.each do |name|
34
+ full_path = File.join(path, name)
35
+ return full_path if library_available?(full_path)
36
+ end
37
+ end
38
+
39
+ raise LoadError, "Could not find SDL3 library. Tried: #{names.join(", ")}"
40
+ end
41
+
42
+ private
43
+
44
+ def detect_platform
45
+ case RbConfig::CONFIG["host_os"]
46
+ when /linux/i then "linux"
47
+ when /darwin/i then "darwin"
48
+ when /mingw/i then "mingw"
49
+ when /mswin/i then "mswin"
50
+ else "unknown"
51
+ end
52
+ end
53
+
54
+ def library_available?(name)
55
+ require "ffi"
56
+ FFI::DynamicLibrary.open(name, FFI::DynamicLibrary::RTLD_LAZY)
57
+ true
58
+ rescue LoadError
59
+ false
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SDL3
4
+ module Raw
5
+ SDL_AssertState = enum :SDL_AssertState, [
6
+ :SDL_ASSERTION_RETRY, 0,
7
+ :SDL_ASSERTION_BREAK, 1,
8
+ :SDL_ASSERTION_ABORT, 2,
9
+ :SDL_ASSERTION_IGNORE, 3,
10
+ :SDL_ASSERTION_ALWAYS_IGNORE, 4
11
+ ]
12
+
13
+ class SDL_AssertData < FFI::Struct
14
+ layout :always_ignore, :bool,
15
+ :trigger_count, :uint,
16
+ :condition, :string,
17
+ :filename, :string,
18
+ :linenum, :int,
19
+ :function, :string,
20
+ :next, :pointer
21
+ end
22
+
23
+ callback :SDL_AssertionHandler, [:pointer, :pointer], :SDL_AssertState
24
+
25
+ attach_function :SDL_ReportAssertion, [:pointer, :string, :string, :int], :SDL_AssertState
26
+ attach_function :SDL_SetAssertionHandler, [:SDL_AssertionHandler, :pointer], :void
27
+ attach_function :SDL_GetDefaultAssertionHandler, [], :SDL_AssertionHandler
28
+ attach_function :SDL_GetAssertionHandler, [:pointer], :SDL_AssertionHandler
29
+ attach_function :SDL_GetAssertionReport, [], :pointer
30
+ attach_function :SDL_ResetAssertionReport, [], :void
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SDL3
4
+ module Raw
5
+ SDL_AsyncIOTaskType = enum :SDL_ASYNCIO_TASK_READ, 0,
6
+ :SDL_ASYNCIO_TASK_WRITE,
7
+ :SDL_ASYNCIO_TASK_CLOSE
8
+
9
+ SDL_AsyncIOResult = enum :SDL_ASYNCIO_COMPLETE, 0,
10
+ :SDL_ASYNCIO_FAILURE,
11
+ :SDL_ASYNCIO_CANCELED
12
+
13
+ class SDL_AsyncIOOutcome < FFI::Struct
14
+ layout :asyncio, :pointer,
15
+ :type, SDL_AsyncIOTaskType,
16
+ :result, SDL_AsyncIOResult,
17
+ :buffer, :pointer,
18
+ :offset, :uint64,
19
+ :bytes_requested, :uint64,
20
+ :bytes_transferred, :uint64,
21
+ :userdata, :pointer
22
+ end
23
+
24
+ attach_function :SDL_AsyncIOFromFile, %i[string string], :pointer
25
+ attach_function :SDL_GetAsyncIOSize, [:pointer], :int64
26
+ attach_function :SDL_ReadAsyncIO, %i[pointer pointer uint64 uint64 pointer pointer], :bool
27
+ attach_function :SDL_WriteAsyncIO, %i[pointer pointer uint64 uint64 pointer pointer], :bool
28
+ attach_function :SDL_CloseAsyncIO, %i[pointer bool pointer pointer], :bool
29
+ attach_function :SDL_CreateAsyncIOQueue, [], :pointer
30
+ attach_function :SDL_DestroyAsyncIOQueue, [:pointer], :void
31
+ attach_function :SDL_GetAsyncIOResult, [:pointer, SDL_AsyncIOOutcome.ptr], :bool
32
+ attach_function :SDL_WaitAsyncIOResult, [:pointer, SDL_AsyncIOOutcome.ptr, :int32], :bool
33
+ attach_function :SDL_SignalAsyncIOQueue, [:pointer], :void
34
+ attach_function :SDL_LoadFileAsync, %i[string pointer pointer], :bool
35
+ end
36
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SDL3
4
+ module Raw
5
+ typedef :int, :SDL_SpinLock
6
+
7
+ class SDL_AtomicInt < FFI::Struct
8
+ layout :value, :int
9
+ end
10
+
11
+ class SDL_AtomicU32 < FFI::Struct
12
+ layout :value, :uint32
13
+ end
14
+
15
+ attach_function :SDL_TryLockSpinlock, [:pointer], :bool
16
+ attach_function :SDL_LockSpinlock, [:pointer], :void
17
+ attach_function :SDL_UnlockSpinlock, [:pointer], :void
18
+
19
+ attach_function :SDL_MemoryBarrierReleaseFunction, [], :void
20
+ attach_function :SDL_MemoryBarrierAcquireFunction, [], :void
21
+
22
+ attach_function :SDL_CompareAndSwapAtomicInt, [SDL_AtomicInt.ptr, :int, :int], :bool
23
+ attach_function :SDL_SetAtomicInt, [SDL_AtomicInt.ptr, :int], :int
24
+ attach_function :SDL_GetAtomicInt, [SDL_AtomicInt.ptr], :int
25
+ attach_function :SDL_AddAtomicInt, [SDL_AtomicInt.ptr, :int], :int
26
+
27
+ attach_function :SDL_CompareAndSwapAtomicU32, [SDL_AtomicU32.ptr, :uint32, :uint32], :bool
28
+ attach_function :SDL_SetAtomicU32, [SDL_AtomicU32.ptr, :uint32], :uint32
29
+ attach_function :SDL_GetAtomicU32, [SDL_AtomicU32.ptr], :uint32
30
+ begin
31
+ attach_function :SDL_AddAtomicU32, [SDL_AtomicU32.ptr, :int], :uint32
32
+ rescue FFI::NotFoundError
33
+ # Added in newer SDL3 versions.
34
+ end
35
+
36
+ attach_function :SDL_CompareAndSwapAtomicPointer, %i[pointer pointer pointer], :bool
37
+ attach_function :SDL_SetAtomicPointer, %i[pointer pointer], :pointer
38
+ attach_function :SDL_GetAtomicPointer, [:pointer], :pointer
39
+ end
40
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SDL3
4
+ module Raw
5
+ SDL_AUDIO_MASK_BITSIZE = 0xFF
6
+ SDL_AUDIO_MASK_FLOAT = 1 << 8
7
+ SDL_AUDIO_MASK_BIG_ENDIAN = 1 << 12
8
+ SDL_AUDIO_MASK_SIGNED = 1 << 15
9
+
10
+ SDL_AUDIO_U8 = 0x0008
11
+ SDL_AUDIO_S8 = 0x8008
12
+ SDL_AUDIO_S16LE = 0x8010
13
+ SDL_AUDIO_S16BE = 0x9010
14
+ SDL_AUDIO_S32LE = 0x8020
15
+ SDL_AUDIO_S32BE = 0x9020
16
+ SDL_AUDIO_F32LE = 0x8120
17
+ SDL_AUDIO_F32BE = 0x9120
18
+
19
+ SDL_AUDIO_S16 = SDL_AUDIO_S16LE
20
+ SDL_AUDIO_S32 = SDL_AUDIO_S32LE
21
+ SDL_AUDIO_F32 = SDL_AUDIO_F32LE
22
+
23
+ class SDL_AudioSpec < FFI::Struct
24
+ layout :format, :uint16,
25
+ :channels, :int,
26
+ :freq, :int
27
+ end
28
+
29
+ attach_function :SDL_GetNumAudioDrivers, [], :int
30
+ attach_function :SDL_GetAudioDriver, [:int], :string
31
+ attach_function :SDL_GetCurrentAudioDriver, [], :string
32
+ attach_function :SDL_GetAudioPlaybackDevices, [:pointer], :pointer
33
+ attach_function :SDL_GetAudioRecordingDevices, [:pointer], :pointer
34
+ attach_function :SDL_GetAudioDeviceName, [:SDL_AudioDeviceID], :string
35
+ attach_function :SDL_GetAudioDeviceFormat, [:SDL_AudioDeviceID, SDL_AudioSpec.ptr, :pointer], :bool
36
+ attach_function :SDL_GetAudioDeviceChannelMap, [:SDL_AudioDeviceID, :pointer], :pointer
37
+ attach_function :SDL_OpenAudioDevice, [:SDL_AudioDeviceID, SDL_AudioSpec.ptr], :SDL_AudioDeviceID
38
+ attach_function :SDL_IsAudioDevicePhysical, [:SDL_AudioDeviceID], :bool
39
+ attach_function :SDL_IsAudioDevicePlayback, [:SDL_AudioDeviceID], :bool
40
+ attach_function :SDL_PauseAudioDevice, [:SDL_AudioDeviceID], :bool
41
+ attach_function :SDL_ResumeAudioDevice, [:SDL_AudioDeviceID], :bool
42
+ attach_function :SDL_AudioDevicePaused, [:SDL_AudioDeviceID], :bool
43
+ attach_function :SDL_GetAudioDeviceGain, [:SDL_AudioDeviceID], :float
44
+ attach_function :SDL_SetAudioDeviceGain, [:SDL_AudioDeviceID, :float], :bool
45
+ attach_function :SDL_CloseAudioDevice, [:SDL_AudioDeviceID], :void
46
+ attach_function :SDL_BindAudioStreams, [:SDL_AudioDeviceID, :pointer, :int], :bool
47
+ attach_function :SDL_BindAudioStream, [:SDL_AudioDeviceID, :pointer], :bool
48
+ attach_function :SDL_UnbindAudioStreams, %i[pointer int], :void
49
+ attach_function :SDL_UnbindAudioStream, [:pointer], :void
50
+ attach_function :SDL_GetAudioStreamDevice, [:pointer], :SDL_AudioDeviceID
51
+ attach_function :SDL_CreateAudioStream, [SDL_AudioSpec.ptr, SDL_AudioSpec.ptr], :pointer
52
+ attach_function :SDL_GetAudioStreamProperties, [:pointer], :SDL_PropertiesID
53
+ attach_function :SDL_GetAudioStreamFormat, [:pointer, SDL_AudioSpec.ptr, SDL_AudioSpec.ptr], :bool
54
+ attach_function :SDL_SetAudioStreamFormat, [:pointer, SDL_AudioSpec.ptr, SDL_AudioSpec.ptr], :bool
55
+ attach_function :SDL_GetAudioStreamFrequencyRatio, [:pointer], :float
56
+ attach_function :SDL_SetAudioStreamFrequencyRatio, %i[pointer float], :bool
57
+ attach_function :SDL_GetAudioStreamGain, [:pointer], :float
58
+ attach_function :SDL_SetAudioStreamGain, %i[pointer float], :bool
59
+ attach_function :SDL_GetAudioStreamInputChannelMap, %i[pointer pointer], :pointer
60
+ attach_function :SDL_GetAudioStreamOutputChannelMap, %i[pointer pointer], :pointer
61
+ attach_function :SDL_SetAudioStreamInputChannelMap, %i[pointer pointer int], :bool
62
+ attach_function :SDL_SetAudioStreamOutputChannelMap, %i[pointer pointer int], :bool
63
+ attach_function :SDL_PutAudioStreamData, %i[pointer pointer int], :bool
64
+ begin
65
+ callback :SDL_AudioStreamDataCompleteCallback, %i[pointer pointer int], :void
66
+ attach_function :SDL_PutAudioStreamDataNoCopy, %i[pointer pointer int SDL_AudioStreamDataCompleteCallback pointer], :bool
67
+ attach_function :SDL_PutAudioStreamPlanarData, %i[pointer pointer int int], :bool
68
+ rescue FFI::NotFoundError
69
+ # Added in newer SDL3 versions.
70
+ end
71
+ attach_function :SDL_GetAudioStreamData, %i[pointer pointer int], :int
72
+ attach_function :SDL_GetAudioStreamAvailable, [:pointer], :int
73
+ attach_function :SDL_GetAudioStreamQueued, [:pointer], :int
74
+ attach_function :SDL_FlushAudioStream, [:pointer], :bool
75
+ attach_function :SDL_ClearAudioStream, [:pointer], :bool
76
+ attach_function :SDL_PauseAudioStreamDevice, [:pointer], :bool
77
+ attach_function :SDL_ResumeAudioStreamDevice, [:pointer], :bool
78
+ attach_function :SDL_AudioStreamDevicePaused, [:pointer], :bool
79
+ attach_function :SDL_LockAudioStream, [:pointer], :bool
80
+ attach_function :SDL_UnlockAudioStream, [:pointer], :bool
81
+ callback :SDL_AudioStreamCallback, %i[pointer pointer int int], :void
82
+ attach_function :SDL_SetAudioStreamGetCallback, [:pointer, :SDL_AudioStreamCallback, :pointer], :bool
83
+ attach_function :SDL_SetAudioStreamPutCallback, [:pointer, :SDL_AudioStreamCallback, :pointer], :bool
84
+ attach_function :SDL_DestroyAudioStream, [:pointer], :void
85
+ attach_function :SDL_OpenAudioDeviceStream, [:SDL_AudioDeviceID, SDL_AudioSpec.ptr, :SDL_AudioStreamCallback, :pointer], :pointer
86
+ callback :SDL_AudioPostmixCallback, [:pointer, SDL_AudioSpec.ptr, :pointer, :int], :void
87
+ attach_function :SDL_SetAudioPostmixCallback, [:SDL_AudioDeviceID, :SDL_AudioPostmixCallback, :pointer], :bool
88
+ attach_function :SDL_LoadWAV_IO, [:pointer, :bool, SDL_AudioSpec.ptr, :pointer, :pointer], :bool
89
+ attach_function :SDL_LoadWAV, [:string, SDL_AudioSpec.ptr, :pointer, :pointer], :bool
90
+ attach_function :SDL_MixAudio, %i[pointer pointer pointer uint16 int float], :bool
91
+ attach_function :SDL_ConvertAudioSamples, [SDL_AudioSpec.ptr, :pointer, :int, SDL_AudioSpec.ptr, :pointer, :pointer], :bool
92
+ attach_function :SDL_GetAudioFormatName, [:uint16], :string
93
+ attach_function :SDL_GetSilenceValueForFormat, [:uint16], :int
94
+ end
95
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ffi"
4
+ require_relative "../library_loader"
5
+
6
+ module SDL3
7
+ module Raw
8
+ extend FFI::Library
9
+
10
+ ffi_lib LibraryLoader.library_name
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SDL3
4
+ module Raw
5
+ module Bits
6
+ def self.most_significant_bit_index32(x)
7
+ return -1 if x == 0
8
+
9
+ 31 - x.to_s(2).rjust(32, "0").index("1")
10
+ end
11
+
12
+ def self.has_exactly_one_bit_set32(x)
13
+ x != 0 && (x & (x - 1)) == 0
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SDL3
4
+ module Raw
5
+ SDL_BLENDMODE_NONE = 0x00000000
6
+ SDL_BLENDMODE_BLEND = 0x00000001
7
+ SDL_BLENDMODE_BLEND_PREMULTIPLIED = 0x00000010
8
+ SDL_BLENDMODE_ADD = 0x00000002
9
+ SDL_BLENDMODE_ADD_PREMULTIPLIED = 0x00000020
10
+ SDL_BLENDMODE_MOD = 0x00000004
11
+ SDL_BLENDMODE_MUL = 0x00000008
12
+ SDL_BLENDMODE_INVALID = 0x7FFFFFFF
13
+
14
+ SDL_BlendOperation = enum :SDL_BLENDOPERATION_ADD, 0x1,
15
+ :SDL_BLENDOPERATION_SUBTRACT, 0x2,
16
+ :SDL_BLENDOPERATION_REV_SUBTRACT, 0x3,
17
+ :SDL_BLENDOPERATION_MINIMUM, 0x4,
18
+ :SDL_BLENDOPERATION_MAXIMUM, 0x5
19
+
20
+ SDL_BlendFactor = enum :SDL_BLENDFACTOR_ZERO, 0x1,
21
+ :SDL_BLENDFACTOR_ONE, 0x2,
22
+ :SDL_BLENDFACTOR_SRC_COLOR, 0x3,
23
+ :SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR, 0x4,
24
+ :SDL_BLENDFACTOR_SRC_ALPHA, 0x5,
25
+ :SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, 0x6,
26
+ :SDL_BLENDFACTOR_DST_COLOR, 0x7,
27
+ :SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR, 0x8,
28
+ :SDL_BLENDFACTOR_DST_ALPHA, 0x9,
29
+ :SDL_BLENDFACTOR_ONE_MINUS_DST_ALPHA, 0xA
30
+
31
+ attach_function :SDL_ComposeCustomBlendMode,
32
+ [SDL_BlendFactor, SDL_BlendFactor, SDL_BlendOperation,
33
+ SDL_BlendFactor, SDL_BlendFactor, SDL_BlendOperation],
34
+ :uint32
35
+ end
36
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SDL3
4
+ module Raw
5
+ SDL_CameraPosition = enum :SDL_CAMERA_POSITION_UNKNOWN, 0,
6
+ :SDL_CAMERA_POSITION_FRONT_FACING, 1,
7
+ :SDL_CAMERA_POSITION_BACK_FACING, 2
8
+
9
+ class SDL_CameraSpec < FFI::Struct
10
+ layout :format, :uint32,
11
+ :colorspace, :uint32,
12
+ :width, :int,
13
+ :height, :int,
14
+ :framerate_numerator, :int,
15
+ :framerate_denominator, :int
16
+ end
17
+
18
+ begin
19
+ attach_function :SDL_GetNumCameraDrivers, [], :int
20
+ attach_function :SDL_GetCameraDriver, [:int], :string
21
+ attach_function :SDL_GetCurrentCameraDriver, [], :string
22
+ attach_function :SDL_GetCameras, [:pointer], :pointer
23
+ attach_function :SDL_GetCameraSupportedFormats, [:SDL_CameraID, :pointer], :pointer
24
+ attach_function :SDL_GetCameraName, [:SDL_CameraID], :string
25
+ attach_function :SDL_GetCameraPosition, [:SDL_CameraID], SDL_CameraPosition
26
+ attach_function :SDL_OpenCamera, [:SDL_CameraID, SDL_CameraSpec.ptr], :pointer
27
+ attach_function :SDL_GetCameraPermissionState, [:pointer], :int
28
+ attach_function :SDL_GetCameraID, [:pointer], :SDL_CameraID
29
+ attach_function :SDL_GetCameraProperties, [:pointer], :SDL_PropertiesID
30
+ attach_function :SDL_GetCameraFormat, [:pointer, SDL_CameraSpec.ptr], :bool
31
+ attach_function :SDL_AcquireCameraFrame, %i[pointer pointer], :pointer
32
+ attach_function :SDL_ReleaseCameraFrame, [:pointer, :pointer], :void
33
+ attach_function :SDL_CloseCamera, [:pointer], :void
34
+ rescue FFI::NotFoundError
35
+ # Camera API may not be available in all SDL3 versions
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SDL3
4
+ module Raw
5
+ callback :SDL_ClipboardDataCallback, %i[pointer string pointer], :pointer
6
+ callback :SDL_ClipboardCleanupCallback, [:pointer], :void
7
+
8
+ attach_function :SDL_SetClipboardText, [:string], :bool
9
+ attach_function :SDL_GetClipboardText, [], :string
10
+ attach_function :SDL_HasClipboardText, [], :bool
11
+ attach_function :SDL_SetPrimarySelectionText, [:string], :bool
12
+ attach_function :SDL_GetPrimarySelectionText, [], :string
13
+ attach_function :SDL_HasPrimarySelectionText, [], :bool
14
+ attach_function :SDL_SetClipboardData, [:SDL_ClipboardDataCallback, :SDL_ClipboardCleanupCallback, :pointer, :pointer, :size_t], :bool
15
+ attach_function :SDL_ClearClipboardData, [], :bool
16
+ attach_function :SDL_GetClipboardData, %i[string pointer], :pointer
17
+ attach_function :SDL_HasClipboardData, [:string], :bool
18
+ attach_function :SDL_GetClipboardMimeTypes, [:pointer], :pointer
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SDL3
4
+ module Raw
5
+ attach_function :SDL_GetNumLogicalCPUCores, [], :int
6
+ attach_function :SDL_GetCPUCacheLineSize, [], :int
7
+ attach_function :SDL_HasAltiVec, [], :bool
8
+ attach_function :SDL_HasMMX, [], :bool
9
+ attach_function :SDL_HasSSE, [], :bool
10
+ attach_function :SDL_HasSSE2, [], :bool
11
+ attach_function :SDL_HasSSE3, [], :bool
12
+ attach_function :SDL_HasSSE41, [], :bool
13
+ attach_function :SDL_HasSSE42, [], :bool
14
+ attach_function :SDL_HasAVX, [], :bool
15
+ attach_function :SDL_HasAVX2, [], :bool
16
+ attach_function :SDL_HasAVX512F, [], :bool
17
+ attach_function :SDL_HasARMSIMD, [], :bool
18
+ attach_function :SDL_HasNEON, [], :bool
19
+ attach_function :SDL_HasLSX, [], :bool
20
+ attach_function :SDL_HasLASX, [], :bool
21
+ attach_function :SDL_GetSystemRAM, [], :int
22
+ begin
23
+ attach_function :SDL_GetSystemPageSize, [], :int
24
+ rescue FFI::NotFoundError
25
+ # Added in newer SDL3 versions.
26
+ end
27
+ attach_function :SDL_GetSIMDAlignment, [], :size_t
28
+ end
29
+ end