Skip to content

Commit 8dab7b5

Browse files
author
Pier-Olivier Boulianne
committed
Add SDL3 dynamic backend from samgubernick
jarikomppa#385
1 parent e82fd32 commit 8dab7b5

9 files changed

Lines changed: 549 additions & 12 deletions

File tree

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ lexander Yashin https://github.com/yashin-alexander
4040
Nils Duval https://github.com/nlsdvl
4141
JackRedstonia jackredstonia64@gmail.com
4242
David Bullock https://github.com/dwbullock
43+
Sam Gubernick https://github.com/samgubernick

build/genie.lua

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local WITH_SDL = 0
22
local WITH_SDL2 = 0
3+
local WITH_SDL3 = 0
34
local WITH_SDL_STATIC = 0
45
local WITH_SDL2_STATIC = 0
56
local WITH_PORTAUDIO = 0
@@ -30,6 +31,7 @@ end
3031

3132
local sdl_root = "/libraries/sdl"
3233
local sdl2_root = "/libraries/sdl2"
34+
local sdl3_root = "/libraries/sdl3"
3335
local dxsdk_root = os.getenv("DXSDK_DIR") and os.getenv("DXSDK_DIR") or "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)"
3436
local portaudio_root = "/libraries/portaudio"
3537
local openal_root = "/libraries/openal"
@@ -40,6 +42,9 @@ local sdl_include = sdl_root .. "/include"
4042
local sdl2_include = sdl2_root .. "/include"
4143
local sdl2_lib_x86 = sdl2_root .. "/lib/x86"
4244
local sdl2_lib_x64 = sdl2_root .. "/lib/x64"
45+
local sdl3_include = sdl3_root .. "/include"
46+
local sdl3_lib_x86 = sdl3_root .. "/lib/x86"
47+
local sdl3_lib_x64 = sdl3_root .. "/lib/x64"
4348
local dxsdk_include = dxsdk_root .. "/include"
4449
local portaudio_include = portaudio_root .. "/include"
4550
local openal_include = openal_root .. "/include"
@@ -69,6 +74,11 @@ newoption {
6974
description = "Include SDL2 backend in build"
7075
}
7176

77+
newoption {
78+
trigger = "with-sdl3",
79+
description = "Include SDL3 backend in build"
80+
}
81+
7282
newoption {
7383
trigger = "with-portaudio",
7484
description = "Include PortAudio backend in build"
@@ -109,6 +119,11 @@ newoption {
109119
description = "Only include sdl2 that doesn't use dyndll in build"
110120
}
111121

122+
newoption {
123+
trigger = "with-sdl3-only",
124+
description = "Only include sdl3 in build"
125+
}
126+
112127
newoption {
113128
trigger = "with-coreaudio",
114129
description = "Include OS X CoreAudio backend in build"
@@ -157,6 +172,7 @@ newoption {
157172
if _OPTIONS["soloud-devel"] then
158173
WITH_SDL = 0
159174
WITH_SDL2 = 1
175+
WITH_SDL3 = 0
160176
WITH_SDL_STATIC = 0
161177
WITH_SDL2_STATIC = 0
162178
WITH_PORTAUDIO = 1
@@ -178,6 +194,7 @@ end
178194

179195
if _OPTIONS["with-common-backends"] then
180196
WITH_SDL = 1
197+
WITH_SDL3 = 0
181198
WITH_SDL_STATIC = 0
182199
WITH_SDL2_STATIC = 0
183200
WITH_PORTAUDIO = 1
@@ -221,6 +238,10 @@ if _OPTIONS["with-sdl2"] then
221238
WITH_SDL2 = 1
222239
end
223240

241+
if _OPTIONS["with-sdl3"] then
242+
WITH_SDL3 = 1
243+
end
244+
224245
if _OPTIONS["with-wasapi"] then
225246
WITH_WASAPI = 1
226247
end
@@ -232,6 +253,7 @@ end
232253
if _OPTIONS["with-sdl-only"] then
233254
WITH_SDL = 1
234255
WITH_SDL2 = 0
256+
WITH_SDL3 = 0
235257
WITH_SDL_STATIC = 0
236258
WITH_SDL2_STATIC = 0
237259
WITH_PORTAUDIO = 0
@@ -247,6 +269,23 @@ end
247269
if _OPTIONS["with-sdl2-only"] then
248270
WITH_SDL = 0
249271
WITH_SDL2 = 1
272+
WITH_SDL3 = 0
273+
WITH_SDL_STATIC = 0
274+
WITH_SDL2_STATIC = 0
275+
WITH_PORTAUDIO = 0
276+
WITH_OPENAL = 0
277+
WITH_XAUDIO2 = 0
278+
WITH_WINMM = 0
279+
WITH_WASAPI = 0
280+
WITH_OSS = 0
281+
WITH_NOSOUND = 0
282+
WITH_MINIAUDIO = 0
283+
end
284+
285+
if _OPTIONS["with-sdl3-only"] then
286+
WITH_SDL = 0
287+
WITH_SDL2 = 0
288+
WITH_SDL3 = 1
250289
WITH_SDL_STATIC = 0
251290
WITH_SDL2_STATIC = 0
252291
WITH_PORTAUDIO = 0
@@ -262,6 +301,7 @@ end
262301
if _OPTIONS["with-sdlstatic-only"] then
263302
WITH_SDL = 0
264303
WITH_SDL2 = 0
304+
WITH_SDL3 = 0
265305
WITH_SDL_STATIC = 1
266306
WITH_PORTAUDIO = 0
267307
WITH_OPENAL = 0
@@ -276,6 +316,7 @@ end
276316
if _OPTIONS["with-sdl2static-only"] then
277317
WITH_SDL = 0
278318
WITH_SDL2 = 0
319+
WITH_SDL3 = 0
279320
WITH_SDL_STATIC = 0
280321
WITH_SDL2_STATIC = 1
281322
WITH_PORTAUDIO = 0
@@ -291,6 +332,7 @@ end
291332
if _OPTIONS["with-sdl2static-only"] then
292333
WITH_SDL = 0
293334
WITH_SDL2 = 0
335+
WITH_SDL3 = 0
294336
WITH_SDL_STATIC = 0
295337
WITH_SDL2_STATIC = 1
296338
WITH_PORTAUDIO = 0
@@ -306,6 +348,7 @@ end
306348
if _OPTIONS["with-vita-homebrew-only"] then
307349
WITH_SDL = 0
308350
WITH_SDL2 = 0
351+
WITH_SDL3 = 0
309352
WITH_SDL_STATIC = 0
310353
WITH_SDL2_STATIC = 0
311354
WITH_PORTAUDIO = 0
@@ -331,6 +374,7 @@ end
331374
if _OPTIONS["with-jack-only"] then
332375
WITH_SDL = 0
333376
WITH_SDL2 = 0
377+
WITH_SDL3 = 0
334378
WITH_SDL_STATIC = 0
335379
WITH_SDL2_STATIC = 0
336380
WITH_PORTAUDIO = 0
@@ -354,6 +398,7 @@ end
354398
if _OPTIONS["with-miniaudio-only"] then
355399
WITH_SDL = 0
356400
WITH_SDL2 = 0
401+
WITH_SDL3 = 0
357402
WITH_SDL_STATIC = 0
358403
WITH_SDL2_STATIC = 0
359404
WITH_PORTAUDIO = 0
@@ -373,6 +418,7 @@ end
373418
if _OPTIONS["with-native-only"] then
374419
WITH_SDL = 0
375420
WITH_SDL2 = 0
421+
WITH_SDL3 = 0
376422
WITH_SDL_STATIC = 0
377423
WITH_SDL2_STATIC = 0
378424
WITH_PORTAUDIO = 0
@@ -400,6 +446,7 @@ print ("")
400446
print ("Active options:")
401447
print ("WITH_SDL = ", WITH_SDL)
402448
print ("WITH_SDL2 = ", WITH_SDL2)
449+
print ("WITH_SDL3 = ", WITH_SDL3)
403450
print ("WITH_PORTAUDIO = ", WITH_PORTAUDIO)
404451
print ("WITH_OPENAL = ", WITH_OPENAL)
405452
print ("WITH_XAUDIO2 = ", WITH_XAUDIO2)
@@ -601,6 +648,31 @@ if (WITH_SDL2 == 1 or WITH_SDL2STATIC) then
601648

602649
targetname "solouddemocommon"
603650
end
651+
-- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< --
652+
653+
if (WITH_SDL3 == 1) then
654+
655+
project "SoloudDemoCommon"
656+
kind "StaticLib"
657+
targetdir "../lib"
658+
language "C++"
659+
660+
files {
661+
"../demos/common/**.c*",
662+
"../demos/common/imgui/**.c*",
663+
"../demos/common/glew/GL/**.c*"
664+
}
665+
includedirs {
666+
"../include",
667+
"../demos/common",
668+
"../demos/common/imgui",
669+
"../demos/common/glew",
670+
sdl3_include
671+
}
672+
defines { "GLEW_STATIC" }
673+
674+
targetname "solouddemocommon"
675+
end
604676
-- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< --
605677

606678
project "SoloudStatic"
@@ -715,6 +787,17 @@ if (WITH_SDL2 == 1) then
715787
}
716788
end
717789

790+
if (WITH_SDL3 == 1) then
791+
defines { "WITH_SDL3" }
792+
files {
793+
"../src/backend/sdl/**.c*"
794+
}
795+
includedirs {
796+
"../include",
797+
sdl3_include
798+
}
799+
end
800+
718801
if (WITH_SDL_STATIC == 1) then
719802
defines { "WITH_SDL_STATIC" }
720803
files {

include/soloud.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ freely, subject to the following restrictions:
4848
#endif
4949

5050
#ifdef WITH_SDL
51+
#undef WITH_SDL3
5152
#undef WITH_SDL2
5253
#undef WITH_SDL1
5354
#define WITH_SDL1
5455
#define WITH_SDL2
56+
#define WITH_SDL3
5557
#endif
5658

5759
#ifdef WITH_SDL_STATIC
@@ -194,6 +196,7 @@ namespace SoLoud
194196
MINIAUDIO,
195197
NOSOUND,
196198
NULLDRIVER,
199+
SDL3,
197200
BACKEND_MAX,
198201
};
199202

@@ -227,7 +230,7 @@ namespace SoLoud
227230
};
228231

229232
// Initialize SoLoud. Must be called before SoLoud can be used.
230-
result init(unsigned int aFlags = Soloud::CLIP_ROUNDOFF, unsigned int aBackend = Soloud::AUTO, unsigned int aSamplerate = Soloud::AUTO, unsigned int aBufferSize = Soloud::AUTO, unsigned int aChannels = 2);
233+
result init(unsigned int aFlags = Soloud::CLIP_ROUNDOFF, unsigned int aBackend = Soloud::AUTO, unsigned int aSamplerate = Soloud::AUTO, unsigned int aBufferSize = Soloud::AUTO, unsigned int aChannels = 2, void const * clientData = NULL);
231234

232235
result pause();
233236
result resume();

include/soloud_backend_data_sdl3.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
SoLoud audio engine
3+
Copyright (c) 2013-2015 Jari Komppa
4+
5+
This software is provided 'as-is', without any express or implied
6+
warranty. In no event will the authors be held liable for any damages
7+
arising from the use of this software.
8+
9+
Permission is granted to anyone to use this software for any purpose,
10+
including commercial applications, and to alter it and redistribute it
11+
freely, subject to the following restrictions:
12+
13+
1. The origin of this software must not be misrepresented; you must not
14+
claim that you wrote the original software. If you use this software
15+
in a product, an acknowledgment in the product documentation would be
16+
appreciated but is not required.
17+
18+
2. Altered source versions must be plainly marked as such, and must not be
19+
misrepresented as being the original software.
20+
21+
3. This notice may not be removed or altered from any source
22+
distribution.
23+
*/
24+
25+
#ifndef SOLOUD_BACKEND_DATA_SDL3_H
26+
#define SOLOUD_BACKEND_DATA_SDL3_H
27+
28+
#ifdef WITH_SDL3
29+
#include "SDL3/SDL.h"
30+
31+
namespace SoLoud
32+
{
33+
struct SoLoudBackendDataSdl3
34+
{
35+
SoLoudBackendDataSdl3()
36+
: audioStream{NULL}
37+
, audioDeviceId{0}
38+
, activeAudioSpec{}
39+
{}
40+
SDL_AudioStream * audioStream;
41+
SDL_AudioDeviceID audioDeviceId;
42+
SDL_AudioSpec activeAudioSpec;
43+
};
44+
45+
struct SoLoudClientDataSdl3
46+
{
47+
SoLoudClientDataSdl3(unsigned int deviceId)
48+
: deviceId(deviceId)
49+
{}
50+
unsigned int deviceId;
51+
};
52+
}
53+
#endif
54+
55+
#endif

include/soloud_internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ namespace SoLoud
3535
// SDL2 back-end initialization call
3636
result sdl2_init(SoLoud::Soloud *aSoloud, unsigned int aFlags = Soloud::CLIP_ROUNDOFF, unsigned int aSamplerate = 44100, unsigned int aBuffer = 2048, unsigned int aChannels = 2);
3737

38+
// SDL3 back-end initialization call
39+
result sdl3_init(SoLoud::Soloud *aSoloud, unsigned int aFlags = Soloud::CLIP_ROUNDOFF, unsigned int aSamplerate = 44100, unsigned int aBuffer = 2048, unsigned int aChannels = 2, void const * clientData = NULL);
40+
3841
// SDL1 "non-dynamic" back-end initialization call
3942
result sdl1static_init(SoLoud::Soloud *aSoloud, unsigned int aFlags = Soloud::CLIP_ROUNDOFF, unsigned int aSamplerate = 44100, unsigned int aBuffer = 2048, unsigned int aChannels = 2);
4043

0 commit comments

Comments
 (0)