diff --git a/CMakeOptions.txt b/CMakeOptions.txt index d65ba52a3..8bd89514a 100644 --- a/CMakeOptions.txt +++ b/CMakeOptions.txt @@ -2,7 +2,7 @@ include(CMakeDependentOption) include(EnumOption) -enum_option(PLATFORM "Desktop;Web;Android;Raspberry Pi;DRM;SDL;Offscreen;None" "Platform to build for.") +enum_option(PLATFORM "Desktop;Web;Android;Raspberry Pi;DRM;SDL;Embeddable;None" "Platform to build for.") enum_option(OPENGL_VERSION "OFF;4.3;3.3;2.1;1.1;ES 2.0;ES 3.0" "Force a specific OpenGL Version?") diff --git a/cmake/LibraryConfigurations.cmake b/cmake/LibraryConfigurations.cmake index 4dee74b07..7d8f435ec 100644 --- a/cmake/LibraryConfigurations.cmake +++ b/cmake/LibraryConfigurations.cmake @@ -105,9 +105,9 @@ elseif ("${PLATFORM}" MATCHES "None") find_package(OpenGL) set(LIBS_PRIVATE m atomic pthread ${OPENGL_LIBRARIES}) -elseif ("${PLATFORM}" MATCHES "Offscreen") +elseif ("${PLATFORM}" MATCHES "Embeddable") set(GRAPHICS "GRAPHICS_API_OPENGL_33") - set(PLATFORM_CPP "PLATFORM_OFFSCREEN") + set(PLATFORM_CPP "PLATFORM_EMBEDDABLE") find_library(pthread NAMES pthread) find_package(OpenGL) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index d36ccc2ee..043036c6e 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -118,15 +118,16 @@ elseif (NOT SUPPORT_GESTURES_SYSTEM) list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_basic_screen_manager.c) list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_input_gestures_web.c) list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_input_gestures.c) -elseif ("${PLATFORM}" STREQUAL "None" OR "${PLATFORM}" STREQUAL "Offscreen") - # for some reason i get an error when trying to compile this one from any platform? oh well we'll just stick it here - list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/raylib_opengl_interop.c) endif () +# The core_override one is only for Embeddable/Blank platforms +if (NOT ${PLATFORM} MATCHES "None" AND NOT ${PLATFORM} MATCHES "Embeddable") + list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/core/core_override.c) +endif() + # The rlgl_standalone example only targets desktop, without shared libraries. if (BUILD_SHARED_LIBS OR NOT ${PLATFORM} MATCHES "Desktop") list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/others/rlgl_standalone.c) - endif() include_directories(BEFORE SYSTEM others/external/include) diff --git a/examples/core/core_ascii_rendering.c b/examples/core/core_override.c similarity index 75% rename from examples/core/core_ascii_rendering.c rename to examples/core/core_override.c index 72b6b3090..ee897ab9b 100644 --- a/examples/core/core_ascii_rendering.c +++ b/examples/core/core_override.c @@ -14,7 +14,6 @@ ********************************************************************************************/ #include "raylib.h" -#include "rmod.h" #include "rcore.h" #include "GLFW/glfw3.h" // Windows/Context and inputs management @@ -28,6 +27,15 @@ const int screenHeight = 450; GLFWwindow *window; +void CustomSetWindowTitle(const char *title) +{ + GetCore()->Window.title = title; + glfwSetWindowTitle(window, title); +} + +double CustomGetTime(void) { + return glfwGetTime(); +} bool CustomWindowShouldClose(void) { if (GetCore()->Window.ready) return GetCore()->Window.shouldClose; @@ -35,7 +43,6 @@ bool CustomWindowShouldClose(void) { } int CustomInitPlatform(void) { - printf("Initing\n"); if (!glfwInit()) { printf("GLFW3: Can not initialize GLFW\n"); @@ -65,6 +72,7 @@ int CustomInitPlatform(void) { else printf("GLFW3: Window created successfully\n"); //glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); + glfwSetWindowSize(window, GetCore()->Window.screen.width, GetCore()->Window.screen.height); glfwSetWindowPos(window, 200, 200); glfwMakeContextCurrent(window); @@ -94,40 +102,51 @@ void CustomClosePlatform(void) { glfwTerminate(); // Free GLFW3 resources } + + //------------------------------------------------------------------------------------ // Program main entry point //------------------------------------------------------------------------------------ int main(void) { - union OverridableFunctionPointer funcs; - funcs.InitPlatform = CustomInitPlatform; - funcs.ClosePlatform = CustomClosePlatform; - funcs.WindowShouldClose = CustomWindowShouldClose; - //CustomInitPlatform(); - - OverrideInternalFunction("InitPlatform",&funcs); - OverrideInternalFunction("ClosePlatform",&funcs); - OverrideInternalFunction("WindowShouldClose",&funcs); - RenderTexture2D fb = LoadRenderTexture(80,24); + union OverridableFunctionPointer funcs[4]; - InitWindow(1,1,"r"); + funcs[0].InitPlatform = CustomInitPlatform; + OverrideInternalFunction("InitPlatform",&funcs[0]); - Color col; + funcs[1].ClosePlatform = CustomClosePlatform; + OverrideInternalFunction("ClosePlatform",&funcs[1]); + + funcs[2].WindowShouldClose = CustomWindowShouldClose; + OverrideInternalFunction("WindowShouldClose",&funcs[2]); + + funcs[3].GetTime = CustomGetTime; + OverrideInternalFunction("GetTime",&funcs[3]); + + funcs[4].SetWindowTitle = CustomSetWindowTitle; + OverrideInternalFunction("SetWindowTitle",&funcs[4]); + + + InitWindow(screenWidth,screenHeight,"Test"); + + Color col = WHITE; + + SetTargetFPS(5); //-------------------------------------------------------------------------------------- - while(!WindowShouldClose()) { - Vector2 pos = GetMousePosition(); - + // Main game loop + while(!WindowShouldClose()) { BeginDrawing(); - ClearBackground(WHITE); - BeginTextureMode(fb); - ClearBackground(RED); - EndTextureMode(); + ClearBackground(col); EndDrawing(); + col.r = GetRandomValue(0,255); + col.g = GetRandomValue(0,255); + col.b = GetRandomValue(0,255); + glfwSwapBuffers(window); glfwPollEvents(); GetCore()->Window.shouldClose = glfwWindowShouldClose(window); diff --git a/src/external/RGFW.h b/src/external/RGFW.h index 35e782d4a..696f1ed4f 100644 --- a/src/external/RGFW.h +++ b/src/external/RGFW.h @@ -8516,9 +8516,9 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) { attrs.preserveDrawingBuffer = EM_FALSE; if (RGFW_DOUBLE_BUFFER == 0) - attrs.renderViaOffscreenBackBuffer = 0; + attrs.renderViaEmbeddableBackBuffer = 0; else - attrs.renderViaOffscreenBackBuffer = RGFW_AUX_BUFFERS; + attrs.renderViaEmbeddableBackBuffer = RGFW_AUX_BUFFERS; attrs.failIfMajorPerformanceCaveat = EM_FALSE; attrs.majorVersion = (RGFW_majorVersion == 0) ? 1 : RGFW_majorVersion; diff --git a/src/platforms/rcore_none.c b/src/platforms/rcore_none.c index a55c61666..d4c640d41 100644 --- a/src/platforms/rcore_none.c +++ b/src/platforms/rcore_none.c @@ -36,20 +36,72 @@ static PlatformData platform = { 0 }; // Platform specific data return; \ } -// For the functions that have default behavior on PLATFORM_OFFSCREEN, check if the function exists +// For the functions that have default behavior on PLATFORM_EMBEDDABLE, check if the function exists // first. #define CHECK_AND_CALL(fn_name, args) \ if(internal##fn_name##Callback != NULL) {\ return (*internal##fn_name##Callback)(LIST args); \ } -// For the functions that have default behavior on PLATFORM_OFFSCREEN, check if the function exists +// For the functions that have default behavior on PLATFORM_EMBEDDABLE, check if the function exists // first (void version). #define CHECK_AND_CALL_VOID(fn_name, args) \ if(internal##fn_name##Callback != NULL) {\ (*internal##fn_name##Callback)(LIST args); \ } +// Generate an internal callback function pointer +#define GEN_FUNCPOINTER(fn_name) \ + static fn_name##Callback * internal##fn_name##Callback = NULL; + +GEN_FUNCPOINTER(InitPlatform) +GEN_FUNCPOINTER(WindowShouldClose) +GEN_FUNCPOINTER(GetMonitorCount) +GEN_FUNCPOINTER(GetCurrentMonitor) +GEN_FUNCPOINTER(ShowCursor) +GEN_FUNCPOINTER(HideCursor) +GEN_FUNCPOINTER(SetWindowState) +GEN_FUNCPOINTER(ClearWindowState) +GEN_FUNCPOINTER(SetWindowMinSize) +GEN_FUNCPOINTER(SetWindowMaxSize) +GEN_FUNCPOINTER(SetWindowSize) +GEN_FUNCPOINTER(ClosePlatform) +GEN_FUNCPOINTER(ToggleFullscreen) +GEN_FUNCPOINTER(ToggleBorderlessWindowed) +GEN_FUNCPOINTER(MaximizeWindow) +GEN_FUNCPOINTER(MinimizeWindow) +GEN_FUNCPOINTER(RestoreWindow) +GEN_FUNCPOINTER(SetWindowIcon) +GEN_FUNCPOINTER(SetWindowIcons) +GEN_FUNCPOINTER(SetWindowTitle) +GEN_FUNCPOINTER(SetWindowPosition) +GEN_FUNCPOINTER(SetWindowMonitor) +GEN_FUNCPOINTER(SetWindowOpacity) +GEN_FUNCPOINTER(SetWindowFocused) +GEN_FUNCPOINTER(EnableCursor) +GEN_FUNCPOINTER(DisableCursor) +GEN_FUNCPOINTER(SwapScreenBuffer) +GEN_FUNCPOINTER(SetGamepadVibration) +GEN_FUNCPOINTER(SetMousePosition) +GEN_FUNCPOINTER(SetMouseCursor) +GEN_FUNCPOINTER(PollInputEvents) +GEN_FUNCPOINTER(SetClipboardText) +GEN_FUNCPOINTER(SetGamepadMappings) +GEN_FUNCPOINTER(GetWindowHandle) +GEN_FUNCPOINTER(GetMonitorPosition) +GEN_FUNCPOINTER(GetMonitorWidth) +GEN_FUNCPOINTER(GetMonitorHeight) +GEN_FUNCPOINTER(GetMonitorPhysicalWidth) +GEN_FUNCPOINTER(GetMonitorPhysicalHeight) +GEN_FUNCPOINTER(GetMonitorRefreshRate) +GEN_FUNCPOINTER(GetMonitorName) +GEN_FUNCPOINTER(GetWindowPosition) +GEN_FUNCPOINTER(GetWindowScaleDPI) +GEN_FUNCPOINTER(GetClipboardText) +GEN_FUNCPOINTER(GetKeyName) +GEN_FUNCPOINTER(GetTime) +GEN_FUNCPOINTER(OpenURL) + GEN_CALLBACK_BODY_VOID(ClosePlatform, (void), ()) GEN_CALLBACK_BODY_VOID(ToggleFullscreen, (void), ()) GEN_CALLBACK_BODY_VOID(ToggleBorderlessWindowed, (void), ()) @@ -87,7 +139,7 @@ GEN_CALLBACK_BODY(const char *, "", GetKeyName, (int key), (key)) GEN_CALLBACK_BODY(double, 0.0, GetTime, (void), ()) GEN_CALLBACK_BODY_VOID(OpenURL, (const char *url), (url)) -// Override an internal platform function with your own (PLATFORM_OFFSCREEN and PLATFORM_NONE only). +// Override an internal platform function with your own (PLATFORM_EMBEDDABLE and PLATFORM_NONE only). // Note that there is no responsibility here for the Raylib maintainers to keep a stable API for core functions void OverrideInternalFunction(const char * funcName, union OverridableFunctionPointer * func) { GEN_CASE(InitPlatform) @@ -136,17 +188,29 @@ void OverrideInternalFunction(const char * funcName, union OverridableFunctionPo GEN_CASE(GetClipboardText) GEN_CASE(GetKeyName) GEN_CASE(GetTime) + GEN_CASE(OpenURL) TraceLog(LOG_ERROR, "Unknown function name \"%s\", did not bind.",funcName); }; -#ifdef PLATFORM_OFFSCREEN -// +#ifndef PLATFORM_EMBEDDABLE +GEN_CALLBACK_BODY(int, 0, InitPlatform, (void), ()) +GEN_CALLBACK_BODY(bool, true, WindowShouldClose, (void), ()) +GEN_CALLBACK_BODY(int, 0, GetMonitorCount, (void), ()) +GEN_CALLBACK_BODY(int, 0, GetCurrentMonitor, (void), ()) +GEN_CALLBACK_BODY_VOID(ShowCursor, (void), ()) +GEN_CALLBACK_BODY_VOID(HideCursor, (void), ()) +GEN_CALLBACK_BODY_VOID(SetWindowState, (unsigned int flags), (flags)) +GEN_CALLBACK_BODY_VOID(ClearWindowState, (unsigned int flags), (flags)) +GEN_CALLBACK_BODY_VOID(SetWindowMinSize, (int width, int height), (width,height)) +GEN_CALLBACK_BODY_VOID(SetWindowMaxSize, (int width, int height), (width,height)) +GEN_CALLBACK_BODY_VOID(SetWindowSize, (int width, int height), (width,height)) + +#else int InitPlatform(void) { - printf("j\n"); CHECK_AND_CALL(InitPlatform, ()); - printf("test\n"); + printf("theJ\n"); CORE.Window.ready = true; return 0; } diff --git a/src/platforms/rcore_none.h b/src/platforms/rcore_none.h index de9c9b5ef..030d6ff32 100644 --- a/src/platforms/rcore_none.h +++ b/src/platforms/rcore_none.h @@ -63,7 +63,7 @@ typedef struct { #define LIST(...) __VA_ARGS__ // The code for warning the user that a function hasn't been overriden. On PLATFORM_NONE, this isn't emitted. -#ifndef PLATFORM_OFFSCREEN +#ifndef PLATFORM_EMBEDDABLE #define FUNCTION_MISSING_WARNING(fn_name) TRACELOG(LOG_WARNING, #fn_name " was called but not overriden by the user"); #else #define FUNCTION_MISSING_WARNING(fn_name) @@ -72,13 +72,11 @@ typedef struct { // Generate a callback #define GEN_CALLBACK_HEAD(fn_ret, ret_value, fn_name, named_args, args) \ typedef fn_ret (*fn_name##Callback)(LIST named_args); \ - static fn_name##Callback * internal##fn_name##Callback = NULL; \ fn_ret fn_name(LIST named_args); // Generate a callback that returns a void. #define GEN_CALLBACK_HEAD_VOID(fn_name, named_args, args) \ typedef void (*fn_name##Callback)(LIST named_args); \ - static fn_name##Callback * internal##fn_name##Callback = NULL; \ void fn_name(LIST named_args); //---------------------------------------------------------------------------------- @@ -141,7 +139,7 @@ GEN_CALLBACK_HEAD_VOID(SetWindowSize, (int width, int height), (width,height)) #define GEN_FIELD(fn_name) fn_name##Callback fn_name; // The avaliable functions you can pass to OverrideInternalFunction. -// The fields are only accessible when compiling with PLATFORM_NONE or PLATFORM_OFFSCREEN +// The fields are only accessible when compiling with PLATFORM_NONE or PLATFORM_EMBEDDABLE union OverridableFunctionPointer { GEN_FIELD(InitPlatform) GEN_FIELD(WindowShouldClose) @@ -189,6 +187,7 @@ union OverridableFunctionPointer { GEN_FIELD(GetClipboardText) GEN_FIELD(GetKeyName) GEN_FIELD(GetTime) + GEN_FIELD(OpenURL) }; void OverrideInternalFunction(const char * funcName, union OverridableFunctionPointer * func); diff --git a/src/rcore.c b/src/rcore.c index cb90e15da..c97d9e63f 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -361,7 +361,7 @@ const char *TextFormat(const char *text, ...); // Formatting of tex #include "platforms/rcore_android.c" #elif defined(PLATFORM_NONE) #include "platforms/rcore_none.c" -#elif defined(PLATFORM_OFFSCREEN) +#elif defined(PLATFORM_EMBEDDABLE) #include "platforms/rcore_none.c" #else // TODO: Include your custom platform backend! diff --git a/src/rcore.h b/src/rcore.h index 82927deb2..d5ed50143 100644 --- a/src/rcore.h +++ b/src/rcore.h @@ -88,6 +88,13 @@ #include #include +#ifdef PLATFORM_NONE +#include "platforms/rcore_none.h" +#endif +#ifdef PLATFORM_EMBEDDABLE +#include "platforms/rcore_none.h" +#endif + //---------------------------------------------------------------------------------- // Defines and Macros //---------------------------------------------------------------------------------- diff --git a/src/rmod.h b/src/rmod.h deleted file mode 100644 index 211d8ae3e..000000000 --- a/src/rmod.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef RMOD_H -#define RMOD_H - -#ifdef PLATFORM_NONE -#include "platforms/rcore_none.h" -#endif -#ifdef PLATFORM_OFFSCREEN -#include "platforms/rcore_none.h" -#endif - -#endif // RMOD_H \ No newline at end of file