Skip to content
Draft

SDL 3 #749

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ jobs:
- uses: actions/checkout@v4
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install libsdl2-dev
curl -LO https://github.com/libsdl-org/SDL/releases/download/release-3.2.20/SDL3-3.2.20.tar.gz
tar zxf SDL3-3.2.20.tar.gz
cd SDL3-3.2.20
cmake -S . -B build
cmake --build build
sudo cmake --install build
- name: Compile
run: |
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
Expand Down Expand Up @@ -173,10 +177,18 @@ jobs:
- name: Install emsdk
uses: mymindstorm/setup-emsdk@v13
with:
version: 3.1.58
version: 4.0.11
- name: Install Dependencies
run: |
curl -LO https://github.com/libsdl-org/SDL/releases/download/release-3.2.20/SDL3-3.2.20.tar.gz
tar zxf SDL3-3.2.20.tar.gz
cd SDL3-3.2.20
emcmake cmake -S . -B build -DCMAKE_INSTALL_PREFIX=$HOME/sdl3-emscripten-install
cmake --build build
sudo cmake --install build
- name: Compile
run: |
emcmake cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
emcmake cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DSDL3_DIR="$HOME/sdl3-emscripten-install/lib/cmake/SDL3"
cmake --build build
- name: Upload
uses: actions/upload-artifact@v4
Expand All @@ -189,6 +201,14 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Install SDL
run: |
curl -LO https://github.com/libsdl-org/SDL/releases/download/release-3.2.20/SDL3-3.2.20.tar.gz
tar zxf SDL3-3.2.20.tar.gz
cd SDL3-3.2.20
cmake -S . -B build
cmake --build build
sudo cmake --install build
- name: Install Dependencies
run: |
sudo apt-get update
Expand All @@ -207,7 +227,14 @@ jobs:
uses: vmactions/freebsd-vm@v1
with:
prepare: |
pkg install -y cmake ninja devel/sdl20
pkg install -y cmake ninja
pkg install -y curl xorgproto libX11 libXext libXrandr libXcursor libXinerama libXi
curl -LO https://github.com/libsdl-org/SDL/releases/download/release-3.2.20/SDL3-3.2.20.tar.gz
tar zxf SDL3-3.2.20.tar.gz
cd SDL3-3.2.20
cmake -S . -B build
cmake --build build
cmake --install build
run: |
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build
Expand All @@ -220,7 +247,14 @@ jobs:
uses: vmactions/openbsd-vm@v1
with:
prepare: |
pkg_add cmake ninja sdl2
pkg_add cmake ninja
pkg_add curl
curl -LO https://github.com/libsdl-org/SDL/releases/download/release-3.2.20/SDL3-3.2.20.tar.gz
tar zxf SDL3-3.2.20.tar.gz
cd SDL3-3.2.20
cmake -S . -B build
cmake --build build
cmake --install build
run: |
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build
Expand Down
41 changes: 19 additions & 22 deletions cmake/libraries/sdl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ endif()

if(EMSCRIPTEN)
# Emscripten provides its own self contained SDL setup
list(APPEND CLIENT_COMPILE_OPTIONS -sUSE_SDL=2)
list(APPEND CLIENT_LINK_OPTIONS -sUSE_SDL=2)
list(APPEND CLIENT_COMPILE_OPTIONS -sUSE_SDL=3)
list(APPEND CLIENT_LINK_OPTIONS -sUSE_SDL=3)
return()
endif()

set(INTERNAL_SDL_DIR ${SOURCE_DIR}/thirdparty/SDL2-2.32.8)
set(INTERNAL_SDL_DIR ${SOURCE_DIR}/thirdparty/SDL3-3.2.18)

include(utils/arch)

Expand All @@ -19,7 +19,7 @@ if(WIN32 OR APPLE)
endif()

if(USE_INTERNAL_SDL AND HAVE_INTERNAL_SDL)
set(SDL2_INCLUDE_DIRS ${INTERNAL_SDL_DIR}/include)
set(SDL3_INCLUDE_DIRS ${INTERNAL_SDL_DIR}/include)
list(APPEND CLIENT_DEFINITIONS USE_INTERNAL_SDL_HEADERS)
list(APPEND RENDERER_DEFINITIONS USE_INTERNAL_SDL_HEADERS)

Expand All @@ -33,32 +33,29 @@ if(USE_INTERNAL_SDL AND HAVE_INTERNAL_SDL)
endif()

if(MINGW)
set(SDL2_LIBRARIES
${LIB_DIR}/libSDL2main.a
${LIB_DIR}/libSDL2.dll.a)
set(SDL3_LIBRARIES
${LIB_DIR}/libSDL3.dll.a)
elseif(MSVC)
set(SDL2_LIBRARIES
${LIB_DIR}/SDL2main.lib
${LIB_DIR}/SDL2.lib)
set(SDL3_LIBRARIES
${LIB_DIR}/SDL3.lib)
endif()

list(APPEND CLIENT_DEPLOY_LIBRARIES ${LIB_DIR}/SDL2.dll)
list(APPEND CLIENT_DEPLOY_LIBRARIES ${LIB_DIR}/SDL3.dll)
elseif(APPLE)
set(SDL2_LIBRARIES
${SOURCE_DIR}/thirdparty/libs/macos/libSDL2main.a
${SOURCE_DIR}/thirdparty/libs/macos/libSDL2-2.0.0.dylib)
set(SDL3_LIBRARIES
${SOURCE_DIR}/thirdparty/libs/macos/libSDL3.dylib)
list(APPEND CLIENT_DEPLOY_LIBRARIES
${SOURCE_DIR}/thirdparty/libs/macos/libSDL2-2.0.0.dylib)
${SOURCE_DIR}/thirdparty/libs/macos/libSDL3.dylib)
else()
message(FATAL_ERROR "HAVE_INTERNAL_SDL set incorrectly; file a bug")
endif()
else()
find_package(SDL2 REQUIRED)
find_package(SDL3 REQUIRED)
endif()

list(APPEND CLIENT_LIBRARIES ${SDL2_LIBRARIES})
list(APPEND CLIENT_INCLUDE_DIRS ${SDL2_INCLUDE_DIRS})
list(APPEND CLIENT_COMPILE_OPTIONS ${SDL2_CFLAGS_OTHER})
list(APPEND RENDERER_LIBRARIES ${SDL2_LIBRARIES})
list(APPEND RENDERER_INCLUDE_DIRS ${SDL2_INCLUDE_DIRS})
list(APPEND RENDERER_COMPILE_OPTIONS ${SDL2_CFLAGS_OTHER})
list(APPEND CLIENT_LIBRARIES ${SDL3_LIBRARIES})
list(APPEND CLIENT_INCLUDE_DIRS ${SDL3_INCLUDE_DIRS})
list(APPEND CLIENT_COMPILE_OPTIONS ${SDL3_CFLAGS_OTHER})
list(APPEND RENDERER_LIBRARIES ${SDL3_LIBRARIES})
list(APPEND RENDERER_INCLUDE_DIRS ${SDL3_INCLUDE_DIRS})
list(APPEND RENDERER_COMPILE_OPTIONS ${SDL3_CFLAGS_OTHER})
2 changes: 1 addition & 1 deletion code/client/cl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3273,7 +3273,7 @@ void CL_InitRef( void ) {
Com_Error(ERR_FATAL, "Failed to load renderer");
}

GetRefAPI = Sys_LoadFunction(rendererLib, "GetRefAPI");
GetRefAPI = (GetRefAPI_t)Sys_LoadFunction(rendererLib, "GetRefAPI");
if(!GetRefAPI)
{
Com_Error(ERR_FATAL, "Can't load symbol GetRefAPI: '%s'", Sys_LibraryError());
Expand Down
5 changes: 5 additions & 0 deletions code/client/keycodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ typedef enum {
K_PAD0_PADDLE3, /* Xbox Elite paddle P2 */
K_PAD0_PADDLE4, /* Xbox Elite paddle P4 */
K_PAD0_TOUCHPAD, /* PS4/PS5 touchpad button */
K_PAD0_MISC2, /**< Additional button */
K_PAD0_MISC3, /**< Additional button */
K_PAD0_MISC4, /**< Additional button */
K_PAD0_MISC5, /**< Additional button */
K_PAD0_MISC6, /**< Additional button */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Key codes are passed to the CGame/UI API. If any mods/games added support for K_PAD0_LEFTSTICK_LEFT, etc in the menu, this change would break it. This is purely hypothetical—I don't know of such mods—but that's why these buttons were separate.

K_CONSOLE is never passed to VMs, so it's last.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I OK, I wondered what all that stuff was about. I've made a change on main to make this mapping more robust and a bit more readable, but I will also append the new buttons so they don't cause reordering.

// Pseudo-key that brings the console down
K_CONSOLE,
Expand Down
4 changes: 2 additions & 2 deletions code/renderercommon/qgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define __QGL_H__

#ifdef USE_INTERNAL_SDL_HEADERS
# include "SDL_opengl.h"
# include "SDL3/SDL_opengl.h"
#else
# include <SDL_opengl.h>
# include <SDL3/SDL_opengl.h>
#endif

extern void (APIENTRYP qglActiveTextureARB) (GLenum texture);
Expand Down
4 changes: 2 additions & 2 deletions code/renderergl2/tr_extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// tr_extensions.c - extensions needed by the renderer not in sdl_glimp.c

#ifdef USE_INTERNAL_SDL_HEADERS
# include "SDL.h"
# include "SDL3/SDL.h"
#else
# include <SDL.h>
# include <SDL3/SDL.h>
#endif

#include "tr_local.h"
Expand Down
49 changes: 4 additions & 45 deletions code/sdl/sdl_gamma.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifdef USE_INTERNAL_SDL_HEADERS
# include "SDL.h"
# include "SDL3/SDL.h"
#else
# include <SDL.h>
# include <SDL3/SDL.h>
#endif

#include "../renderercommon/tr_common.h"
Expand All @@ -38,48 +38,7 @@ GLimp_SetGamma
*/
void GLimp_SetGamma( unsigned char red[256], unsigned char green[256], unsigned char blue[256] )
{
Uint16 table[3][256];
int i, j;

if( !glConfig.deviceSupportsGamma || r_ignorehwgamma->integer > 0 )
return;

for (i = 0; i < 256; i++)
{
table[0][i] = ( ( ( Uint16 ) red[i] ) << 8 ) | red[i];
table[1][i] = ( ( ( Uint16 ) green[i] ) << 8 ) | green[i];
table[2][i] = ( ( ( Uint16 ) blue[i] ) << 8 ) | blue[i];
}

#ifdef _WIN32
// Windows puts this odd restriction on gamma ramps...
ri.Printf( PRINT_DEVELOPER, "performing gamma clamp.\n" );
for( j = 0 ; j < 3 ; j++ )
{
for( i = 0 ; i < 128 ; i++ )
{
if( table[ j ][ i ] > ( ( 128 + i ) << 8 ) )
table[ j ][ i ] = ( 128 + i ) << 8;
}

if( table[ j ][ 127 ] > 254 << 8 )
table[ j ][ 127 ] = 254 << 8;
}
#endif

// enforce constantly increasing
for (j = 0; j < 3; j++)
{
for (i = 1; i < 256; i++)
{
if (table[j][i] < table[j][i-1])
table[j][i] = table[j][i-1];
}
}

if (SDL_SetWindowGammaRamp(SDL_window, table[0], table[1], table[2]) < 0)
{
ri.Printf( PRINT_DEVELOPER, "SDL_SetWindowGammaRamp() failed: %s\n", SDL_GetError() );
}
//FIXME Ummmmm... do it with a shader maybe? What about GL1?
ri.Printf( PRINT_DEVELOPER, "Gamma adjustment not supported in SDL3\n" );
}

Loading
Loading