diff options
| author | jussi | 2025-03-12 23:26:01 +0200 |
|---|---|---|
| committer | jussi | 2025-03-12 23:26:01 +0200 |
| commit | 63f3c1781cec32bd4603cd92a9b788e3000a9594 (patch) | |
| tree | 977b1847a2b7cd4c1dada94597a19a6acaa72c1b | |
| parent | bfa73944f7e8a3a239ed105871a0912e8b22ed15 (diff) | |
| download | reilua-enhanced-63f3c1781cec32bd4603cd92a9b788e3000a9594.tar.gz reilua-enhanced-63f3c1781cec32bd4603cd92a9b788e3000a9594.tar.bz2 reilua-enhanced-63f3c1781cec32bd4603cd92a9b788e3000a9594.zip | |
Basic sdl3 support.
| -rw-r--r-- | CMakeLists.txt | 24 | ||||
| -rw-r--r-- | include/main.h | 6 | ||||
| -rw-r--r-- | include/platforms/core_desktop_sdl2.h (renamed from include/platforms/core_desktop_sdl.h) | 0 | ||||
| -rw-r--r-- | include/platforms/core_desktop_sdl3.h | 3 | ||||
| -rw-r--r-- | include/state.h | 4 | ||||
| -rw-r--r-- | src/gl.c | 2 | ||||
| -rw-r--r-- | src/lua_core.c | 8 | ||||
| -rw-r--r-- | src/platforms/core_desktop_sdl2.c (renamed from src/platforms/core_desktop_sdl.c) | 2 | ||||
| -rw-r--r-- | src/platforms/core_desktop_sdl3.c | 23 | ||||
| -rw-r--r-- | src/state.c | 2 |
10 files changed, 58 insertions, 16 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 09e7b10..4cfba5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ option( LUA_EVENTS "Enable Lua event callbacks (RL.event)." off ) option( DYNAMIC_SYMBOLS "Expose all dynamic symbols with rdynamic." off ) option( EXPOSE_API_SYMBOLS "Expose dynamic symbols only for get and push functions of variable types." off ) -enum_option( PLATFORM "Desktop;Desktop_SDL;Web" "Platform to build for." ) +enum_option( PLATFORM "Desktop;Desktop_SDL2;Desktop_SDL3;Web" "Platform to build for." ) if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE ) @@ -30,8 +30,10 @@ add_executable( ${PROJECT_NAME} ${SOURCES} ) if( PLATFORM STREQUAL "Desktop" ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_DESKTOP" ) -elseif( PLATFORM STREQUAL "Desktop_SDL" ) - set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_DESKTOP_SDL" ) +elseif( PLATFORM STREQUAL "Desktop_SDL2" ) + set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_DESKTOP_SDL2" ) +elseif( PLATFORM STREQUAL "Desktop_SDL3" ) + set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_DESKTOP_SDL3" ) elseif( PLATFORM STREQUAL "Web" ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_WEB" ) endif() @@ -86,11 +88,16 @@ else() # Desktop set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEXPOSE_LUA_API_SYMBOLS -rdynamic -fvisibility=hidden" ) endif() - if ( PLATFORM MATCHES "Desktop_SDL" ) + if ( PLATFORM MATCHES "Desktop_SDL2" ) include( FindPkgConfig ) pkg_search_module( SDL2 REQUIRED sdl2 ) include_directories( ${SDL2_INCLUDE_DIRS} ) target_link_libraries( ${PROJECT_NAME} ${SDL2_LIBRARIES} ) + elseif ( PLATFORM MATCHES "Desktop_SDL3" ) + include( FindPkgConfig ) + pkg_search_module( SDL3 REQUIRED sdl3 ) + include_directories( ${SDL3_INCLUDE_DIRS} ) + target_link_libraries( ${PROJECT_NAME} ${SDL3_LIBRARIES} ) endif() if( DRM ) # For Raspberry Pi. @@ -104,7 +111,7 @@ else() # Desktop elseif( APPLE ) set( CMAKE_C_COMPILER "clang" ) - # //TODO Linking to sdl2. + # //TODO Linking to SDL. target_link_libraries( ${PROJECT_NAME} "-framework IOKit" ) target_link_libraries( ${PROJECT_NAME} "-framework Cocoa" ) @@ -114,11 +121,16 @@ else() # Desktop set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEXPOSE_LUA_API_SYMBOLS" ) endif() - if ( PLATFORM MATCHES "Desktop_SDL" ) + if ( PLATFORM MATCHES "Desktop_SDL2" ) find_package( SDL2 REQUIRED ) include_directories( ${SDL2_INCLUDE_DIRS} ) target_link_libraries( ${PROJECT_NAME} ${SDL2MAIN_LIBRARIES} ) target_link_libraries( ${PROJECT_NAME} ${SDL2_LIBRARIES} ) + elseif ( PLATFORM MATCHES "Desktop_SDL3" ) + find_package( SDL3 REQUIRED ) + include_directories( ${SDL3_INCLUDE_DIRS} ) + target_link_libraries( ${PROJECT_NAME} ${SDL3MAIN_LIBRARIES} ) + target_link_libraries( ${PROJECT_NAME} ${SDL3_LIBRARIES} ) endif() # Remove this to get console. //TODO Could be build option. set( CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-mwindows" ) diff --git a/include/main.h b/include/main.h index 6fcda26..1d4fc74 100644 --- a/include/main.h +++ b/include/main.h @@ -17,8 +17,10 @@ #ifdef PLATFORM_DESKTOP #include "GLFW/glfw3.h" #include "GLFW/glfw3native.h" -#elif PLATFORM_DESKTOP_SDL - #include <SDL.h> +#elif PLATFORM_DESKTOP_SDL2 + #include <SDL2/SDL.h> +#elif PLATFORM_DESKTOP_SDL3 + #include <SDL3/SDL.h> #endif #ifdef SHARED diff --git a/include/platforms/core_desktop_sdl.h b/include/platforms/core_desktop_sdl2.h index e787494..e787494 100644 --- a/include/platforms/core_desktop_sdl.h +++ b/include/platforms/core_desktop_sdl2.h diff --git a/include/platforms/core_desktop_sdl3.h b/include/platforms/core_desktop_sdl3.h new file mode 100644 index 0000000..4331412 --- /dev/null +++ b/include/platforms/core_desktop_sdl3.h @@ -0,0 +1,3 @@ +#pragma once + +#include "SDL3/SDL.h" diff --git a/include/state.h b/include/state.h index 1e84b43..a6b5118 100644 --- a/include/state.h +++ b/include/state.h @@ -1,6 +1,6 @@ #pragma once -#ifdef PLATFORM_DESKTOP_SDL +#ifdef PLATFORM_DESKTOP_SDL2 #define PLATFORM_SDL_EVENT_QUEUE_LEN 128 #endif @@ -39,7 +39,7 @@ typedef struct { GLFWpentabletdatafun glfwTabletDataCallback; GLFWpentabletcursorfun glfwTabletCursorCallback; GLFWpentabletproximityfun glfwTabletProximityCallback; -#elif PLATFORM_DESKTOP_SDL +#elif PLATFORM_DESKTOP_SDL2 int SDL_eventQueueLen; SDL_Event* SDL_eventQueue; #endif @@ -32,7 +32,7 @@ Copy a block of pixels from one framebuffer object to another. Use nil RenderTexture for window framebuffer */ int lglBlitFramebuffer( lua_State* L ) { -#if defined( PLATFORM_DESKTOP ) || defined( PLATFORM_DESKTOP_SDL ) +#if defined( PLATFORM_DESKTOP ) || defined( PLATFORM_DESKTOP_SDL2 ) || defined( PLATFORM_DESKTOP_SDL3 ) if ( !( lua_isuserdata( L, 1 ) || lua_isnil( L, 1 ) ) || !( lua_isuserdata( L, 2 ) || lua_isnil( L, 2 ) ) ) { TraceLog( state->logLevelInvalid, "%s", "Argument needs to be RenderTexture or nil" ); lua_pushnil( L ); diff --git a/src/lua_core.c b/src/lua_core.c index de90e89..0191e98 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -17,8 +17,10 @@ #ifdef PLATFORM_DESKTOP #include "platforms/core_desktop_glfw.c" -#elif PLATFORM_DESKTOP_SDL - #include "platforms/core_desktop_sdl.c" +#elif PLATFORM_DESKTOP_SDL2 + #include "platforms/core_desktop_sdl2.c" +#elif PLATFORM_DESKTOP_SDL3 + #include "platforms/core_desktop_sdl3.c" #elif PLATFORM_WEB #include "platforms/core_web.c" #endif @@ -1451,7 +1453,7 @@ void luaCallInit() { void luaCallUpdate() { -#if defined PLATFORM_DESKTOP_SDL && defined LUA_EVENTS +#if defined PLATFORM_DESKTOP_SDL2 && defined LUA_EVENTS platformSendEvents(); #endif lua_State* L = state->luaState; diff --git a/src/platforms/core_desktop_sdl.c b/src/platforms/core_desktop_sdl2.c index 4105b25..ce105ee 100644 --- a/src/platforms/core_desktop_sdl.c +++ b/src/platforms/core_desktop_sdl2.c @@ -1,7 +1,7 @@ #include "main.h" #include "lua_core.h" #include "core.h" -#include "platforms/core_desktop_sdl.h" +#include "platforms/core_desktop_sdl2.h" void platformDefineGlobals() { lua_State* L = state->luaState; diff --git a/src/platforms/core_desktop_sdl3.c b/src/platforms/core_desktop_sdl3.c new file mode 100644 index 0000000..9314b26 --- /dev/null +++ b/src/platforms/core_desktop_sdl3.c @@ -0,0 +1,23 @@ +#include "main.h" +#include "lua_core.h" +#include "core.h" +#include "platforms/core_desktop_sdl3.h" + +void platformDefineGlobals() { + lua_State* L = state->luaState; + + lua_getglobal( L, "RL" ); +/*DOC_DEFINES_START*/ +/*DOC_DEFINES_END*/ + lua_pop( L, -1 ); +} + +void luaPlatformRegister() { + // lua_State* L = state->luaState; + // lua_getglobal( L, "RL" ); + + // lua_pop( L, -1 ); +#ifdef LUA_EVENTS + // platformRegisterEvents(); +#endif +} diff --git a/src/state.c b/src/state.c index fdfdbd0..8f8c03d 100644 --- a/src/state.c +++ b/src/state.c @@ -29,7 +29,7 @@ void stateContextInit() { state->defaultTexture = (Texture){ 1, 1, 1, 1, 7 }; state->shapesTexture = (Texture){ 1, 1, 1, 1, 7 }; state->RLGLcurrentShaderLocs = malloc( RL_MAX_SHADER_LOCATIONS * sizeof( int ) ); -#ifdef PLATFORM_DESKTOP_SDL +#ifdef PLATFORM_DESKTOP_SDL2 state->SDL_eventQueue = malloc( PLATFORM_SDL_EVENT_QUEUE_LEN * sizeof( SDL_Event ) ); state->SDL_eventQueueLen = 0; #endif |
