diff --git a/Submodules/UIKit/include/Application.h b/Submodules/UIKit/include/Application.h index 7ccaf07..1150de6 100644 --- a/Submodules/UIKit/include/Application.h +++ b/Submodules/UIKit/include/Application.h @@ -13,8 +13,6 @@ class Application { ~Application(); private: - SDL_Window* window; - sk_sp typeface; float fRotationAngle = 0; diff --git a/Submodules/UIKit/include/SkiaCtx.h b/Submodules/UIKit/include/SkiaCtx.h index 6a3213f..3955cdd 100644 --- a/Submodules/UIKit/include/SkiaCtx.h +++ b/Submodules/UIKit/include/SkiaCtx.h @@ -14,7 +14,7 @@ bool platformRunLoop(std::function loop); class SkiaCtx { public: - virtual ~SkiaCtx() {} + virtual ~SkiaCtx() = default; virtual sk_sp getBackbufferSurface() = 0; virtual sk_sp directContext() = 0; virtual void flushAndSubmit(sk_sp surface); @@ -29,6 +29,6 @@ class SkiaCtx { sk_sp fontMgr; }; -std::unique_ptr MakeSkiaCtx(SDL_Window* window); +std::unique_ptr MakeSkiaCtx(); } diff --git a/Submodules/UIKit/include/platforms/SkiaCtx_sdlBase.h b/Submodules/UIKit/include/platforms/SkiaCtx_sdlBase.h index 548027c..ef5c0b7 100644 --- a/Submodules/UIKit/include/platforms/SkiaCtx_sdlBase.h +++ b/Submodules/UIKit/include/platforms/SkiaCtx_sdlBase.h @@ -7,7 +7,7 @@ namespace NXKit { class SkiaCtx_sdlBase : public SkiaCtx { public: - SkiaCtx_sdlBase(SDL_Window *window); + SkiaCtx_sdlBase(); virtual void swapBuffers() override; diff --git a/Submodules/UIKit/include/platforms/ios/SkiaCtx_ios.h b/Submodules/UIKit/include/platforms/ios/SkiaCtx_ios.h index 22b7487..815f7a3 100644 --- a/Submodules/UIKit/include/platforms/ios/SkiaCtx_ios.h +++ b/Submodules/UIKit/include/platforms/ios/SkiaCtx_ios.h @@ -10,7 +10,7 @@ namespace NXKit { class SkiaCtx_ios : public SkiaCtx_sdlBase { public: - SkiaCtx_ios(SDL_Window *window); + SkiaCtx_ios(); sk_sp getBackbufferSurface() override; diff --git a/Submodules/UIKit/include/platforms/macos/SkiaCtx_macos.h b/Submodules/UIKit/include/platforms/macos/SkiaCtx_macos.h index 09fba14..6b925e1 100644 --- a/Submodules/UIKit/include/platforms/macos/SkiaCtx_macos.h +++ b/Submodules/UIKit/include/platforms/macos/SkiaCtx_macos.h @@ -8,7 +8,7 @@ namespace NXKit { class SkiaCtx_macos: public SkiaCtx_sdlBase { public: - SkiaCtx_macos(SDL_Window* window); + SkiaCtx_macos(); sk_sp getBackbufferSurface() override; // float getScaleFactor() override; diff --git a/Submodules/UIKit/lib/Application.cpp b/Submodules/UIKit/lib/Application.cpp index c9a73d1..0656e06 100644 --- a/Submodules/UIKit/lib/Application.cpp +++ b/Submodules/UIKit/lib/Application.cpp @@ -21,10 +21,7 @@ Application* Application::shared = nullptr; int Application::resizingEventWatcher(void* data, SDL_Event* event) { if (event->type == SDL_WINDOWEVENT && event->window.event == SDL_WINDOWEVENT_RESIZED) { - SDL_Window* win = SDL_GetWindowFromID(event->window.windowID); - if (win == (SDL_Window*)data) { - Application::shared->render(); - } + ((Application*) data)->render(); } return 0; } @@ -32,32 +29,10 @@ int Application::resizingEventWatcher(void* data, SDL_Event* event) { Application::Application() { shared = this; - SDL_Init(SDL_INIT_EVERYTHING); - - Uint32 flags = SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_RESIZABLE; -#ifdef PLATFORM_IOS - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); - SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); - SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0); - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); - - flags |= SDL_WINDOW_OPENGL; -#endif - - window = SDL_CreateWindow("Window", 12, 12, 1280, 720, flags); - auto context = SDL_GL_CreateContext(window); - SDL_GL_MakeCurrent(window, context); - skiaCtx = MakeSkiaCtx(window); + skiaCtx = MakeSkiaCtx(); - SDL_AddEventWatch(resizingEventWatcher, window); + SDL_AddEventWatch(resizingEventWatcher, this); SkFontStyle style; typeface = skiaCtx->getFontMgr()->matchFamilyStyle(nullptr, style); diff --git a/Submodules/UIKit/lib/platforms/SkiaCtx.cpp b/Submodules/UIKit/lib/platforms/SkiaCtx.cpp index d2720da..cac76bb 100644 --- a/Submodules/UIKit/lib/platforms/SkiaCtx.cpp +++ b/Submodules/UIKit/lib/platforms/SkiaCtx.cpp @@ -5,6 +5,6 @@ using namespace NXKit; void SkiaCtx::flushAndSubmit(sk_sp surface) { if (auto dContext = directContext()) { - dContext->flushAndSubmit(surface.get(), GrSyncCpu::kNo); + dContext->flushAndSubmit(surface.get(), GrSyncCpu::kYes); } -} \ No newline at end of file +} diff --git a/Submodules/UIKit/lib/platforms/SkiaCtx_sdlBase.cpp b/Submodules/UIKit/lib/platforms/SkiaCtx_sdlBase.cpp index ae08697..692305d 100644 --- a/Submodules/UIKit/lib/platforms/SkiaCtx_sdlBase.cpp +++ b/Submodules/UIKit/lib/platforms/SkiaCtx_sdlBase.cpp @@ -2,8 +2,31 @@ using namespace NXKit; -SkiaCtx_sdlBase::SkiaCtx_sdlBase(SDL_Window *window): window(window) -{ } +SkiaCtx_sdlBase::SkiaCtx_sdlBase() +{ + SDL_Init(SDL_INIT_EVERYTHING); + Uint32 flags = SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_RESIZABLE; + +#ifdef USE_GLES + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); + SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0); + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); + + flags |= SDL_WINDOW_OPENGL; +#endif + + window = SDL_CreateWindow("Window", 12, 12, 1280, 720, flags); + auto context = SDL_GL_CreateContext(window); + SDL_GL_MakeCurrent(window, context); +} void SkiaCtx_sdlBase::swapBuffers() { SDL_GL_SwapWindow(window); @@ -19,5 +42,5 @@ float SkiaCtx_sdlBase::getScaleFactor() { int w, h, dw, dh; SDL_GetWindowSize(window, &w, &h); SDL_GL_GetDrawableSize(window, &dw, &dh); - return dw / w; -} + return (float)dw / (float)w; +} \ No newline at end of file diff --git a/Submodules/UIKit/lib/platforms/apple/ios/SkiaCtx_ios.mm b/Submodules/UIKit/lib/platforms/apple/ios/SkiaCtx_ios.mm index df310a8..8fed7a5 100644 --- a/Submodules/UIKit/lib/platforms/apple/ios/SkiaCtx_ios.mm +++ b/Submodules/UIKit/lib/platforms/apple/ios/SkiaCtx_ios.mm @@ -21,7 +21,7 @@ using namespace NXKit; -SkiaCtx_ios::SkiaCtx_ios(SDL_Window* window): SkiaCtx_sdlBase(window) { +SkiaCtx_ios::SkiaCtx_ios(): SkiaCtx_sdlBase() { SkGraphics::Init(); initContext(); @@ -66,8 +66,8 @@ nullptr, &props); } -std::unique_ptr NXKit::MakeSkiaCtx(SDL_Window* window) { - return std::make_unique(window); +std::unique_ptr NXKit::MakeSkiaCtx() { + return std::make_unique(); } bool NXKit::platformRunLoop(std::function loop) { diff --git a/Submodules/UIKit/lib/platforms/apple/macos/SkiaCtx_macos.mm b/Submodules/UIKit/lib/platforms/apple/macos/SkiaCtx_macos.mm index bb713e3..6770b17 100644 --- a/Submodules/UIKit/lib/platforms/apple/macos/SkiaCtx_macos.mm +++ b/Submodules/UIKit/lib/platforms/apple/macos/SkiaCtx_macos.mm @@ -21,7 +21,7 @@ using namespace NXKit; -SkiaCtx_macos::SkiaCtx_macos(SDL_Window* window): SkiaCtx_sdlBase(window) { +SkiaCtx_macos::SkiaCtx_macos(): SkiaCtx_sdlBase() { SkGraphics::Init(); initContext(); @@ -66,12 +66,12 @@ nullptr, &props); } -std::unique_ptr NXKit::MakeSkiaCtx(SDL_Window* window) { - return std::make_unique(window); +std::unique_ptr NXKit::MakeSkiaCtx() { + return std::make_unique(); } bool NXKit::platformRunLoop(std::function loop) { @autoreleasepool { return loop(); } -} +} \ No newline at end of file diff --git a/Submodules/cmake/toolchain.cmake b/Submodules/cmake/toolchain.cmake index 5361d7d..06f9dc3 100644 --- a/Submodules/cmake/toolchain.cmake +++ b/Submodules/cmake/toolchain.cmake @@ -72,6 +72,8 @@ elseif (PLATFORM_IOS) message("Building for iOS") add_definitions( -DPLATFORM_IOS ) + set(USE_GLES ON) + set(BUILD_SHARED_LIBS OFF) set(PLATFORM OS64) set(CMAKE_TOOLCHAIN_FILE ${EXTERN_PATH}/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE PATH "vcpkg toolchain file") @@ -79,6 +81,10 @@ elseif (PLATFORM_IOS) set(CMAKE_XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2") # iphone, ipad endif () +if (USE_GLES) + add_definitions( -DUSE_GLES ) +endif () + # Setup LibRomFS check_libromfs_generator()