feat(gui): draw windowed apps through a batched SDL2 surface
Compiled programs could only write to the terminal, so the demo editor had no real window. When CMake finds SDL2 the runtime now exposes a `gui` table and Demo/guipaint.lua builds a 960x640 editor on top of it. Frames are collected in Lua, merged into horizontal runs and sent with a single `gui.rects` call: a full scene goes from 15071 draw calls and 42.9 ms per frame to 1522 calls and 2.1 ms, and the rendered screenshot stays pixel-identical.
This commit is contained in:
11 files changed
+1840
-9
No files matched your search
@@ -43,6 +43,22 @@ endif()
|
||||
set(LUACPP_RUNTIME_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
set(LUACPP_LUA_CFLAGS "${_lua_cflags}")
|
||||
set(LUACPP_LUA_LIBS "${_lua_libs}")
|
||||
|
||||
# --- optional GUI backend -----------------------------------------------------
|
||||
# Programs compiled with `luacpp run` get a global `gui` table (window, drawing
|
||||
# primitives, events) when SDL2 is available. Without SDL2 nothing changes.
|
||||
pkg_check_modules(SDL2 QUIET sdl2)
|
||||
if(SDL2_FOUND)
|
||||
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --cflags sdl2
|
||||
OUTPUT_VARIABLE _sdl_cflags OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --libs sdl2
|
||||
OUTPUT_VARIABLE _sdl_libs OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
set(LUACPP_GUI_FLAGS "-DLUACPP_HAS_GUI=1 ${_sdl_cflags} ${_sdl_libs}")
|
||||
message(STATUS "luacpp: SDL2 found, compiled programs get the 'gui' API")
|
||||
else()
|
||||
set(LUACPP_GUI_FLAGS "")
|
||||
message(STATUS "luacpp: SDL2 not found, the 'gui' API is disabled")
|
||||
endif()
|
||||
configure_file(cmake/luacpp-config.hpp.in
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/generated/luacpp-config.hpp" @ONLY)
|
||||
|
||||
|
||||
Reference in new issue
Block a user