Basic sdl3 support.

This commit is contained in:
jussi
2025-03-12 23:26:01 +02:00
parent bfa73944f7
commit 63f3c1781c
10 changed files with 58 additions and 16 deletions

View File

@@ -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( 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 ) 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 ) if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE ) 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" ) if( PLATFORM STREQUAL "Desktop" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_DESKTOP" ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_DESKTOP" )
elseif( PLATFORM STREQUAL "Desktop_SDL" ) elseif( PLATFORM STREQUAL "Desktop_SDL2" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_DESKTOP_SDL" ) 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" ) elseif( PLATFORM STREQUAL "Web" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_WEB" ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPLATFORM_WEB" )
endif() endif()
@@ -86,11 +88,16 @@ else() # Desktop
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEXPOSE_LUA_API_SYMBOLS -rdynamic -fvisibility=hidden" ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEXPOSE_LUA_API_SYMBOLS -rdynamic -fvisibility=hidden" )
endif() endif()
if ( PLATFORM MATCHES "Desktop_SDL" ) if ( PLATFORM MATCHES "Desktop_SDL2" )
include( FindPkgConfig ) include( FindPkgConfig )
pkg_search_module( SDL2 REQUIRED sdl2 ) pkg_search_module( SDL2 REQUIRED sdl2 )
include_directories( ${SDL2_INCLUDE_DIRS} ) include_directories( ${SDL2_INCLUDE_DIRS} )
target_link_libraries( ${PROJECT_NAME} ${SDL2_LIBRARIES} ) 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() endif()
if( DRM ) # For Raspberry Pi. if( DRM ) # For Raspberry Pi.
@@ -104,7 +111,7 @@ else() # Desktop
elseif( APPLE ) elseif( APPLE )
set( CMAKE_C_COMPILER "clang" ) 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 IOKit" )
target_link_libraries( ${PROJECT_NAME} "-framework Cocoa" ) target_link_libraries( ${PROJECT_NAME} "-framework Cocoa" )
@@ -114,11 +121,16 @@ else() # Desktop
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEXPOSE_LUA_API_SYMBOLS" ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEXPOSE_LUA_API_SYMBOLS" )
endif() endif()
if ( PLATFORM MATCHES "Desktop_SDL" ) if ( PLATFORM MATCHES "Desktop_SDL2" )
find_package( SDL2 REQUIRED ) find_package( SDL2 REQUIRED )
include_directories( ${SDL2_INCLUDE_DIRS} ) include_directories( ${SDL2_INCLUDE_DIRS} )
target_link_libraries( ${PROJECT_NAME} ${SDL2MAIN_LIBRARIES} ) target_link_libraries( ${PROJECT_NAME} ${SDL2MAIN_LIBRARIES} )
target_link_libraries( ${PROJECT_NAME} ${SDL2_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() endif()
# Remove this to get console. //TODO Could be build option. # Remove this to get console. //TODO Could be build option.
set( CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-mwindows" ) set( CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-mwindows" )

View File

@@ -17,8 +17,10 @@
#ifdef PLATFORM_DESKTOP #ifdef PLATFORM_DESKTOP
#include "GLFW/glfw3.h" #include "GLFW/glfw3.h"
#include "GLFW/glfw3native.h" #include "GLFW/glfw3native.h"
#elif PLATFORM_DESKTOP_SDL #elif PLATFORM_DESKTOP_SDL2
#include <SDL.h> #include <SDL2/SDL.h>
#elif PLATFORM_DESKTOP_SDL3
#include <SDL3/SDL.h>
#endif #endif
#ifdef SHARED #ifdef SHARED

View File

@@ -0,0 +1,3 @@
#pragma once
#include "SDL3/SDL.h"

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#ifdef PLATFORM_DESKTOP_SDL #ifdef PLATFORM_DESKTOP_SDL2
#define PLATFORM_SDL_EVENT_QUEUE_LEN 128 #define PLATFORM_SDL_EVENT_QUEUE_LEN 128
#endif #endif
@@ -39,7 +39,7 @@ typedef struct {
GLFWpentabletdatafun glfwTabletDataCallback; GLFWpentabletdatafun glfwTabletDataCallback;
GLFWpentabletcursorfun glfwTabletCursorCallback; GLFWpentabletcursorfun glfwTabletCursorCallback;
GLFWpentabletproximityfun glfwTabletProximityCallback; GLFWpentabletproximityfun glfwTabletProximityCallback;
#elif PLATFORM_DESKTOP_SDL #elif PLATFORM_DESKTOP_SDL2
int SDL_eventQueueLen; int SDL_eventQueueLen;
SDL_Event* SDL_eventQueue; SDL_Event* SDL_eventQueue;
#endif #endif

View File

@@ -32,7 +32,7 @@ Copy a block of pixels from one framebuffer object to another.
Use nil RenderTexture for window framebuffer Use nil RenderTexture for window framebuffer
*/ */
int lglBlitFramebuffer( lua_State* L ) { 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 ) ) ) { 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" ); TraceLog( state->logLevelInvalid, "%s", "Argument needs to be RenderTexture or nil" );
lua_pushnil( L ); lua_pushnil( L );

View File

@@ -17,8 +17,10 @@
#ifdef PLATFORM_DESKTOP #ifdef PLATFORM_DESKTOP
#include "platforms/core_desktop_glfw.c" #include "platforms/core_desktop_glfw.c"
#elif PLATFORM_DESKTOP_SDL #elif PLATFORM_DESKTOP_SDL2
#include "platforms/core_desktop_sdl.c" #include "platforms/core_desktop_sdl2.c"
#elif PLATFORM_DESKTOP_SDL3
#include "platforms/core_desktop_sdl3.c"
#elif PLATFORM_WEB #elif PLATFORM_WEB
#include "platforms/core_web.c" #include "platforms/core_web.c"
#endif #endif
@@ -1451,7 +1453,7 @@ void luaCallInit() {
void luaCallUpdate() { void luaCallUpdate() {
#if defined PLATFORM_DESKTOP_SDL && defined LUA_EVENTS #if defined PLATFORM_DESKTOP_SDL2 && defined LUA_EVENTS
platformSendEvents(); platformSendEvents();
#endif #endif
lua_State* L = state->luaState; lua_State* L = state->luaState;

View File

@@ -1,7 +1,7 @@
#include "main.h" #include "main.h"
#include "lua_core.h" #include "lua_core.h"
#include "core.h" #include "core.h"
#include "platforms/core_desktop_sdl.h" #include "platforms/core_desktop_sdl2.h"
void platformDefineGlobals() { void platformDefineGlobals() {
lua_State* L = state->luaState; lua_State* L = state->luaState;

View File

@@ -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
}

View File

@@ -29,7 +29,7 @@ void stateContextInit() {
state->defaultTexture = (Texture){ 1, 1, 1, 1, 7 }; state->defaultTexture = (Texture){ 1, 1, 1, 1, 7 };
state->shapesTexture = (Texture){ 1, 1, 1, 1, 7 }; state->shapesTexture = (Texture){ 1, 1, 1, 1, 7 };
state->RLGLcurrentShaderLocs = malloc( RL_MAX_SHADER_LOCATIONS * sizeof( int ) ); 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_eventQueue = malloc( PLATFORM_SDL_EVENT_QUEUE_LEN * sizeof( SDL_Event ) );
state->SDL_eventQueueLen = 0; state->SDL_eventQueueLen = 0;
#endif #endif