From 5a57aca66ae546f1dffe2894bd79b0298e450b97 Mon Sep 17 00:00:00 2001 From: SirLynix Date: Thu, 2 Feb 2023 20:33:53 +0100 Subject: [PATCH] Last changes --- examples/DeferredShading/main.cpp | 9 +- examples/DopplerEffect/main.cpp | 22 +- examples/PhysicallyBasedRendering/main.cpp | 9 +- examples/Physics2DDemo/main.cpp | 11 +- examples/PhysicsDemo/main.cpp | 11 +- examples/PhysicsDemo/xmake.lua | 4 + examples/PlayMusic/main.cpp | 62 +++--- examples/PlayMusic/xmake.lua | 6 +- examples/Showcase/main.cpp | 9 +- examples/Showcase/xmake.lua | 4 + examples/Tut00/xmake.lua | 4 + examples/WidgetDemo/main.cpp | 13 +- .../OpenGLRenderer/Wrapper/CoreFunctions.hpp | 4 +- include/Nazara/Platform/WindowHandle.hpp | 4 +- include/Nazara/Utility.hpp | 1 - include/Nazara/Utility/BasicMainloop.hpp | 43 ---- src/Nazara/Core/ApplicationBase.cpp | 4 + src/Nazara/Network/Posix/IpAddressImpl.cpp | 2 +- .../OpenGLRenderer/OpenGLCommandBuffer.cpp | 4 +- src/Nazara/OpenGLRenderer/Wrapper/Context.cpp | 2 +- .../OpenGLRenderer/Wrapper/EGL/EGLLoader.cpp | 1 + tests/ComputeTest/xmake.lua | 4 + tests/GraphicsTest/main.cpp | 27 +-- tests/RenderTest/main.cpp | 21 +- xmake-repo/packages/l/libsdl/xmake.lua | 194 ++++++++++++++++++ xmake.lua | 18 +- 26 files changed, 310 insertions(+), 183 deletions(-) delete mode 100644 include/Nazara/Utility/BasicMainloop.hpp create mode 100644 xmake-repo/packages/l/libsdl/xmake.lua diff --git a/examples/DeferredShading/main.cpp b/examples/DeferredShading/main.cpp index a0a501d4d..bbd617311 100644 --- a/examples/DeferredShading/main.cpp +++ b/examples/DeferredShading/main.cpp @@ -75,14 +75,7 @@ int main() if (!std::filesystem::is_directory(shaderDir) && std::filesystem::is_directory("../.." / shaderDir)) shaderDir = "../.." / shaderDir; - Nz::Renderer::Config rendererConfig; - std::cout << "Run using Vulkan? (y/n)" << std::endl; - if (std::getchar() == 'y') - rendererConfig.preferredAPI = Nz::RenderAPI::Vulkan; - else - rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL; - - Nz::Application app(rendererConfig); + Nz::Application app; nzsl::ShaderWriter::States states; states.shaderModuleResolver = Nz::Graphics::Instance()->GetShaderModuleResolver(); diff --git a/examples/DopplerEffect/main.cpp b/examples/DopplerEffect/main.cpp index b4f5fc2e9..44e769335 100644 --- a/examples/DopplerEffect/main.cpp +++ b/examples/DopplerEffect/main.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -47,10 +46,10 @@ int main() sound.EnableLooping(true); // La source du son se situe vers la gauche (Et un peu en avant) - sound.SetPosition(Nz::Vector3f::Left()*50.f + Nz::Vector3f::Forward()*5.f); + sound.SetPosition(Nz::Vector3f::Left() * 50.f + Nz::Vector3f::Forward() * 5.f); // Et possède une vitesse de 10 par seconde vers la droite - sound.SetVelocity(Nz::Vector3f::Left()*-10.f); + sound.SetVelocity(Nz::Vector3f::Right() * 10.f); // On joue le son sound.Play(); @@ -58,16 +57,27 @@ int main() Nz::MillisecondClock clock; app.AddUpdater([&](Nz::Time elapsedTime) { + std::this_thread::sleep_for(std::chrono::milliseconds(1000 / 30)); + if (sound.GetStatus() != Nz::SoundStatus::Playing) + { + // On arrête le son et l'application + sound.Stop(); app.Quit(); + } // On bouge la source du son en fonction du temps depuis chaque mise à jour - Nz::Vector3f pos = sound.GetPosition() + sound.GetVelocity() * clock.GetElapsedTime().AsSeconds(); + Nz::Vector3f pos = sound.GetPosition() + sound.GetVelocity() * clock.Restart().AsSeconds(); sound.SetPosition(pos); + std::cout << "Position: " << pos.x << std::endl; + // Si la position de la source atteint une certaine position, ou si l'utilisateur appuie sur echap - if (pos.x > Nz::Vector3f::Left().x * -50.f || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Escape)) - sound.Stop(); // On arrête le son (Stoppant également la boucle) + if (pos.x > Nz::Vector3f::Right().x * 50.f || Nz::Keyboard::IsKeyPressed(Nz::Keyboard::VKey::Escape)) + { + sound.Stop(); + app.Quit(); + } }); return app.Run(); diff --git a/examples/PhysicallyBasedRendering/main.cpp b/examples/PhysicallyBasedRendering/main.cpp index 9e607a133..4f1cc9b69 100644 --- a/examples/PhysicallyBasedRendering/main.cpp +++ b/examples/PhysicallyBasedRendering/main.cpp @@ -13,14 +13,7 @@ int main() if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir)) resourceDir = "../.." / resourceDir; - Nz::Renderer::Config rendererConfig; - std::cout << "Run using Vulkan? (y/n)" << std::endl; - if (std::getchar() == 'y') - rendererConfig.preferredAPI = Nz::RenderAPI::Vulkan; - else - rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL; - - Nz::Application app(rendererConfig); + Nz::Application app; std::shared_ptr device = Nz::Graphics::Instance()->GetRenderDevice(); diff --git a/examples/Physics2DDemo/main.cpp b/examples/Physics2DDemo/main.cpp index 230b681cb..b01ac7c31 100644 --- a/examples/Physics2DDemo/main.cpp +++ b/examples/Physics2DDemo/main.cpp @@ -21,16 +21,7 @@ int main() if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir)) resourceDir = "../.." / resourceDir; - Nz::Renderer::Config rendererConfig; - std::cout << "Run using Vulkan? (y/n)" << std::endl; - if (std::getchar() != 'n') - rendererConfig.preferredAPI = Nz::RenderAPI::Vulkan; - else - rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL; - - std::cin.ignore(std::numeric_limits::max(), '\n'); - - Nz::Application app(rendererConfig); + Nz::Application app; auto& windowing = app.AddComponent(); diff --git a/examples/PhysicsDemo/main.cpp b/examples/PhysicsDemo/main.cpp index 75a25e7e4..8bf45bd42 100644 --- a/examples/PhysicsDemo/main.cpp +++ b/examples/PhysicsDemo/main.cpp @@ -20,16 +20,7 @@ int main() if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir)) resourceDir = "../.." / resourceDir; - Nz::Renderer::Config rendererConfig; - std::cout << "Run using Vulkan? (y/n)" << std::endl; - if (std::getchar() != 'n') - rendererConfig.preferredAPI = Nz::RenderAPI::Vulkan; - else - rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL; - - std::cin.ignore(std::numeric_limits::max(), '\n'); - - Nz::Application app(rendererConfig); + Nz::Application app; auto& windowing = app.AddComponent(); diff --git a/examples/PhysicsDemo/xmake.lua b/examples/PhysicsDemo/xmake.lua index ed19da755..375312464 100644 --- a/examples/PhysicsDemo/xmake.lua +++ b/examples/PhysicsDemo/xmake.lua @@ -1,3 +1,7 @@ +if is_plat("wasm") then + return -- Physics3D is not yet supported on wasm because of Newton +end + target("PhysicsDemo") add_deps("NazaraGraphics", "NazaraPhysics3D") add_packages("entt") diff --git a/examples/PlayMusic/main.cpp b/examples/PlayMusic/main.cpp index 2203afa2e..4cef04759 100644 --- a/examples/PlayMusic/main.cpp +++ b/examples/PlayMusic/main.cpp @@ -9,49 +9,39 @@ #include #include #include -#include #include #include #include int main() { - try + std::filesystem::path resourceDir = "assets/examples"; + if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir)) + resourceDir = "../.." / resourceDir; + + Nz::Application app; + + Nz::SoundStreamParams streamParams; + streamParams.forceMono = false; + + Nz::Music music; + if (!music.OpenFromFile(resourceDir / "Audio/file_example_MP3_700KB.mp3", streamParams)) { - - std::filesystem::path resourceDir = "assets/examples"; - if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir)) - resourceDir = "../.." / resourceDir; - - Nz::Application app; - - Nz::SoundStreamParams streamParams; - streamParams.forceMono = false; - - Nz::Music music; - if (!music.OpenFromFile(resourceDir / "Audio/file_example_MP3_700KB.mp3", streamParams)) - { - std::cout << "Failed to load sound" << std::endl; - std::getchar(); - return EXIT_FAILURE; - } - - std::getchar(); - - music.Play(); - - std::cout << "Playing sound..." << std::endl; - - app.AddUpdater([&](Nz::Time /*elapsedTime*/) - { - if (!music.IsPlaying()) - app.Quit(); - }); - - return app.Run(); + std::cout << "Failed to load sound" << std::endl; + return EXIT_FAILURE; } - catch (const std::exception& e) + + music.Play(); + + std::cout << "Playing sound..." << std::endl; + + app.AddUpdater([&](Nz::Time /*elapsedTime*/) { - std::cerr << e.what() << std::endl; - } + if (!music.IsPlaying()) + app.Quit(); + + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + }); + + return app.Run(); } diff --git a/examples/PlayMusic/xmake.lua b/examples/PlayMusic/xmake.lua index 56595b33e..3939ffe3c 100644 --- a/examples/PlayMusic/xmake.lua +++ b/examples/PlayMusic/xmake.lua @@ -1,3 +1,7 @@ +if is_plat("wasm") then + return -- Threads are broken for now +end + target("PlayMusic") - add_deps("NazaraAudio", "NazaraUtility", "NazaraPlatform") + add_deps("NazaraAudio") add_files("main.cpp") diff --git a/examples/Showcase/main.cpp b/examples/Showcase/main.cpp index 5f3a9183b..c8bc2cd69 100644 --- a/examples/Showcase/main.cpp +++ b/examples/Showcase/main.cpp @@ -22,14 +22,7 @@ int main() if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir)) resourceDir = "../.." / resourceDir; - Nz::Renderer::Config rendererConfig; - std::cout << "Run using Vulkan? (y/n)" << std::endl; - if (std::getchar() == 'y') - rendererConfig.preferredAPI = Nz::RenderAPI::Vulkan; - else - rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL; - - Nz::Application app(rendererConfig); + Nz::Application app; Nz::PluginLoader loader; Nz::Plugin assimp = loader.Load(); diff --git a/examples/Showcase/xmake.lua b/examples/Showcase/xmake.lua index 294193c68..061bdab4d 100644 --- a/examples/Showcase/xmake.lua +++ b/examples/Showcase/xmake.lua @@ -2,6 +2,10 @@ if not has_config("assimp") then return end +if is_plat("wasm") then + return -- Physics3D is not yet supported on wasm because of Newton +end + target("Showcase") set_group("Examples") set_kind("binary") diff --git a/examples/Tut00/xmake.lua b/examples/Tut00/xmake.lua index 0a5322b56..c12fcf1d1 100644 --- a/examples/Tut00/xmake.lua +++ b/examples/Tut00/xmake.lua @@ -1,3 +1,7 @@ +if is_plat("wasm") then + return -- Physics3D is not yet supported on wasm because of Newton +end + target("Tut00_EmptyProject") add_deps("NazaraAudio", "NazaraGraphics", "NazaraNetwork", "NazaraPhysics2D", "NazaraPhysics3D", "NazaraRenderer", "NazaraUtility") add_files("main.cpp") diff --git a/examples/WidgetDemo/main.cpp b/examples/WidgetDemo/main.cpp index 58e8aadf1..7baf44321 100644 --- a/examples/WidgetDemo/main.cpp +++ b/examples/WidgetDemo/main.cpp @@ -14,16 +14,7 @@ NAZARA_REQUEST_DEDICATED_GPU() int main() { - Nz::Renderer::Config rendererConfig; - std::cout << "Run using Vulkan? (y/n)" << std::endl; - if (std::getchar() != 'n') - rendererConfig.preferredAPI = Nz::RenderAPI::Vulkan; - else - rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL; - - std::cin.ignore(std::numeric_limits::max(), '\n'); - - Nz::Application app(rendererConfig); + Nz::Application app; auto& windowing = app.AddComponent(); Nz::Window& mainWindow = windowing.CreateWindow(Nz::VideoMode(1920, 1080), "Widget demo"); @@ -67,7 +58,7 @@ int main() samplerInfo.anisotropyLevel = 8; std::shared_ptr materialInstance = material->Instantiate(); - materialInstance->SetTextureProperty("BaseColorMap", fs.GetOrLoad("assets/lynix.jpg")); + materialInstance->SetTextureProperty("BaseColorMap", fs.Load("assets/lynix.jpg")); Nz::ImageWidget* imageWidget = canvas2D.Add(materialInstance); imageWidget->SetPosition(1200.f, 200.f); diff --git a/include/Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp b/include/Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp index 8926a2c6b..d10560f3a 100644 --- a/include/Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp +++ b/include/Nazara/OpenGLRenderer/Wrapper/CoreFunctions.hpp @@ -78,7 +78,6 @@ typedef void (GL_APIENTRYP PFNGLSPECIALIZESHADERPROC) (GLuint shader, const GLch cb(glCreateProgram, PFNGLCREATEPROGRAMPROC) \ cb(glCreateShader, PFNGLCREATESHADERPROC) \ cb(glCullFace, PFNGLCULLFACEPROC) \ - cb(glDebugMessageControl, PFNGLDEBUGMESSAGECONTROLPROC) \ cb(glDeleteBuffers, PFNGLDELETEBUFFERSPROC) \ cb(glDeleteFramebuffers, PFNGLDELETEFRAMEBUFFERSPROC) \ cb(glDeleteProgram, PFNGLDELETEPROGRAMPROC) \ @@ -118,7 +117,6 @@ typedef void (GL_APIENTRYP PFNGLSPECIALIZESHADERPROC) (GLuint shader, const GLch cb(glGetActiveUniformBlockiv, PFNGLGETACTIVEUNIFORMBLOCKIVPROC) \ cb(glGetActiveUniformBlockName, PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC) \ cb(glGetBooleanv, PFNGLGETBOOLEANVPROC) \ - cb(glGetBooleani_v, PFNGLGETBOOLEANI_VPROC) \ cb(glGetBufferParameteriv, PFNGLGETBUFFERPARAMETERIVPROC) \ cb(glGetError, PFNGLGETERRORPROC) \ cb(glGetFloatv, PFNGLGETFLOATVPROC) \ @@ -196,10 +194,12 @@ typedef void (GL_APIENTRYP PFNGLSPECIALIZESHADERPROC) (GLuint shader, const GLch cb(glVertexAttribPointer, PFNGLVERTEXATTRIBPOINTERPROC) \ cb(glViewport, PFNGLVIEWPORTPROC) \ /* Core OpenGL (extension in OpenGL ES) */ \ + extCb(glDebugMessageControl, PFNGLDEBUGMESSAGECONTROLPROC) \ extCb(glDrawBuffer, PFNGLDRAWBUFFERPROC) \ extCb(glPolygonMode, PFNGLPOLYGONMODEPROC) \ /* OpenGL 4.2 - OpenGL ES 3.1 */\ extCb(glBindImageTexture, PFNGLBINDIMAGETEXTUREPROC) \ + extCb(glGetBooleani_v, PFNGLGETBOOLEANI_VPROC) \ extCb(glMemoryBarrier, PFNGLMEMORYBARRIERPROC) \ extCb(glMemoryBarrierByRegion, PFNGLMEMORYBARRIERBYREGIONPROC) \ /* OpenGL 4.3 - OpenGL ES 3.1 */\ diff --git a/include/Nazara/Platform/WindowHandle.hpp b/include/Nazara/Platform/WindowHandle.hpp index 7e9d93c1a..0e2cba553 100644 --- a/include/Nazara/Platform/WindowHandle.hpp +++ b/include/Nazara/Platform/WindowHandle.hpp @@ -19,8 +19,8 @@ namespace Nz Cocoa, X11, Wayland, - Windows, - Web + Web, + Windows }; struct WindowHandle diff --git a/include/Nazara/Utility.hpp b/include/Nazara/Utility.hpp index 8d4750284..4837a6618 100644 --- a/include/Nazara/Utility.hpp +++ b/include/Nazara/Utility.hpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include diff --git a/include/Nazara/Utility/BasicMainloop.hpp b/include/Nazara/Utility/BasicMainloop.hpp deleted file mode 100644 index b47a3900d..000000000 --- a/include/Nazara/Utility/BasicMainloop.hpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com) -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#pragma once - -#ifndef NAZARA_UTILITY_BASICMAINLOOP_HPP -#define NAZARA_UTILITY_BASICMAINLOOP_HPP - -#include - -#ifdef NAZARA_PLATFORM_WEB -#include -#endif - -namespace Nz -{ - template - void BasicMainloop(Window& window, CallbackT&& callback) - { -#ifndef NAZARA_PLATFORM_WEB - while (window.IsOpen()) - { - callback(); - } -#else - emscripten_set_main_loop_arg([] (void* callbackInstance) - { - try - { - (*static_cast(callbackInstance))(); - } - catch(std::exception e) - { - NazaraDebug(e.what()); - } - }, &callback, 0, 1); -#endif - } -} - - -#endif // NAZARA_UTILITY_BASICMAINLOOP_HPP diff --git a/src/Nazara/Core/ApplicationBase.cpp b/src/Nazara/Core/ApplicationBase.cpp index 9a56c25e3..cd9d2d555 100644 --- a/src/Nazara/Core/ApplicationBase.cpp +++ b/src/Nazara/Core/ApplicationBase.cpp @@ -32,7 +32,10 @@ namespace Nz { ApplicationBase* app = static_cast(application); if (!app->m_running) + { + emscripten_cancel_main_loop(); return; + } try { @@ -44,6 +47,7 @@ namespace Nz NazaraError(e.what()); } }, this, 0, 1); + emscripten_set_main_loop_timing(EM_TIMING_RAF, 1); #endif return 0; diff --git a/src/Nazara/Network/Posix/IpAddressImpl.cpp b/src/Nazara/Network/Posix/IpAddressImpl.cpp index 096161a79..b330a2587 100644 --- a/src/Nazara/Network/Posix/IpAddressImpl.cpp +++ b/src/Nazara/Network/Posix/IpAddressImpl.cpp @@ -169,7 +169,7 @@ namespace Nz IpAddress::IPv6 address = ipAddress.ToIPv6(); for (unsigned int i = 0; i < 8; ++i) { - u_short addressPart = htons(address[i]); + UInt16 addressPart = htons(address[i]); socketAddress->sin6_addr.s6_addr[i * 2 + 0] = addressPart >> 0; socketAddress->sin6_addr.s6_addr[i * 2 + 1] = addressPart >> 8; } diff --git a/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp b/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp index 24830e1ea..fdbc6dfe0 100644 --- a/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp +++ b/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp @@ -322,8 +322,8 @@ namespace Nz } } - /*if (!invalidateAttachments.empty()) - context->glInvalidateFramebuffer(GL_FRAMEBUFFER, GLsizei(invalidateAttachments.size()), invalidateAttachments.data());*/ + if (!invalidateAttachments.empty()) + context->glInvalidateFramebuffer(GL_FRAMEBUFFER, GLsizei(invalidateAttachments.size()), invalidateAttachments.data()); } else static_assert(AlwaysFalse::value, "non-exhaustive visitor"); diff --git a/src/Nazara/OpenGLRenderer/Wrapper/Context.cpp b/src/Nazara/OpenGLRenderer/Wrapper/Context.cpp index 321cc8c1e..5bd0f5728 100644 --- a/src/Nazara/OpenGLRenderer/Wrapper/Context.cpp +++ b/src/Nazara/OpenGLRenderer/Wrapper/Context.cpp @@ -431,7 +431,7 @@ namespace Nz::GL try { -#define NAZARA_OPENGLRENDERER_FUNC(name, sig) loader.Load(name, #name, false, true); +#define NAZARA_OPENGLRENDERER_FUNC(name, sig) loader.Load(name, #name, true, true); #define NAZARA_OPENGLRENDERER_EXT_FUNC(name, sig) //< Do nothing NAZARA_OPENGLRENDERER_FOREACH_GLES_FUNC(NAZARA_OPENGLRENDERER_FUNC, NAZARA_OPENGLRENDERER_EXT_FUNC) #undef NAZARA_OPENGLRENDERER_EXT_FUNC diff --git a/src/Nazara/OpenGLRenderer/Wrapper/EGL/EGLLoader.cpp b/src/Nazara/OpenGLRenderer/Wrapper/EGL/EGLLoader.cpp index 509ca943e..b5f897255 100644 --- a/src/Nazara/OpenGLRenderer/Wrapper/EGL/EGLLoader.cpp +++ b/src/Nazara/OpenGLRenderer/Wrapper/EGL/EGLLoader.cpp @@ -165,6 +165,7 @@ namespace Nz::GL { case WindowBackend::Invalid: case WindowBackend::Cocoa: //< TODO? + case WindowBackend::Web: //< TODO? break; case WindowBackend::X11: diff --git a/tests/ComputeTest/xmake.lua b/tests/ComputeTest/xmake.lua index 2158a8e9d..e130b4d2f 100644 --- a/tests/ComputeTest/xmake.lua +++ b/tests/ComputeTest/xmake.lua @@ -1,3 +1,7 @@ +if is_plat("wasm") then + return -- Compute shaders are not supported with WebGL (but are with WebGPU) +end + target("ComputeTest") add_deps("NazaraRenderer") add_files("main.cpp") diff --git a/tests/GraphicsTest/main.cpp b/tests/GraphicsTest/main.cpp index 9dea79588..aa45695d2 100644 --- a/tests/GraphicsTest/main.cpp +++ b/tests/GraphicsTest/main.cpp @@ -17,14 +17,16 @@ int main() resourceDir = "../.." / resourceDir; Nz::Renderer::Config rendererConfig; - rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL; - /*std::cout << "Run using Vulkan? (y/n)" << std::endl; +#ifndef NAZARA_PLATFORM_WEB + std::cout << "Run using Vulkan? (y/n)" << std::endl; if (std::getchar() == 'y') rendererConfig.preferredAPI = Nz::RenderAPI::Vulkan; else - rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL;*/ + rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL; +#endif - Nz::Modules nazara(rendererConfig); + Nz::Application app(rendererConfig); + auto& windowingApp = app.AddComponent(); Nz::MeshParams meshParams; meshParams.center = true; @@ -35,12 +37,7 @@ int main() std::shared_ptr device = Nz::Graphics::Instance()->GetRenderDevice(); std::string windowTitle = "Graphics Test"; - Nz::Window window; - if (!window.Create(Nz::VideoMode(1280, 720), windowTitle)) - { - std::cout << "Failed to create Window" << std::endl; - std::abort(); - } + Nz::Window& window = windowingApp.CreateWindow(Nz::VideoMode(1280, 720), windowTitle); Nz::WindowSwapchain windowSwapchain(device, window); std::shared_ptr spaceshipMesh = Nz::Mesh::LoadFromFile(resourceDir / "Spaceship/spaceship.obj", meshParams); @@ -177,10 +174,8 @@ int main() } }); - while (window.IsOpen()) + app.AddUpdater([&](Nz::Time /*elapsedTime*/) { - Nz::Window::ProcessEvents(); - if (std::optional deltaTime = updateClock.RestartIfOver(Nz::Time::TickDuration(60))) { float cameraSpeed = 2.f * deltaTime->AsSeconds(); @@ -215,7 +210,7 @@ int main() if (!frame) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); - continue; + return; } framePipeline.GetDebugDrawer().DrawLine(Nz::Vector3f::Zero(), Nz::Vector3f::Forward(), Nz::Color::Blue()); @@ -243,7 +238,7 @@ int main() window.SetTitle(windowTitle + " - " + Nz::NumberToString(fps) + " FPS"); fps = 0; } - } + }); - return EXIT_SUCCESS; + return app.Run(); } diff --git a/tests/RenderTest/main.cpp b/tests/RenderTest/main.cpp index afc7031cf..9bbc16bbd 100644 --- a/tests/RenderTest/main.cpp +++ b/tests/RenderTest/main.cpp @@ -88,25 +88,22 @@ int main() resourceDir = "../.." / resourceDir; Nz::Renderer::Config rendererConfig; +#ifndef NAZARA_PLATFORM_WEB std::cout << "Run using Vulkan? (y/n)" << std::endl; if (std::getchar() == 'y') rendererConfig.preferredAPI = Nz::RenderAPI::Vulkan; else rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL; +#endif - Nz::Modules nazara(rendererConfig); + Nz::Application app(rendererConfig); + auto& windowingApp = app.AddComponent(); std::shared_ptr device = Nz::Renderer::Instance()->InstanciateRenderDevice(0); - Nz::Window window; - Nz::WindowSwapchain windowSwapchain(device, window); - std::string windowTitle = "Render Test"; - if (!window.Create(Nz::VideoMode(1280, 720), windowTitle)) - { - std::cout << "Failed to create Window" << std::endl; - return __LINE__; - } + Nz::Window& window = windowingApp.CreateWindow(Nz::VideoMode(1280, 720), windowTitle); + Nz::WindowSwapchain windowSwapchain(device, window); nzsl::Ast::ModulePtr shaderModule = nzsl::Parse(std::string_view(shaderSource, sizeof(shaderSource))); if (!shaderModule) @@ -287,10 +284,8 @@ int main() uboUpdate = true; }); - Nz::BasicMainloop(window, [&] + app.AddUpdater([&](Nz::Time /*elapsedTime*/) { - Nz::Window::ProcessEvents(); - if (std::optional deltaTime = updateClock.RestartIfOver(Nz::Time::TickDuration(60))) { float cameraSpeed = 2.f * deltaTime->AsSeconds(); @@ -416,5 +411,5 @@ int main() } }); - return EXIT_SUCCESS; + return app.Run(); } diff --git a/xmake-repo/packages/l/libsdl/xmake.lua b/xmake-repo/packages/l/libsdl/xmake.lua new file mode 100644 index 000000000..dc329dcc9 --- /dev/null +++ b/xmake-repo/packages/l/libsdl/xmake.lua @@ -0,0 +1,194 @@ +package("libsdl") + set_homepage("https://www.libsdl.org/") + set_description("Simple DirectMedia Layer") + + if is_plat("mingw") and is_subhost("msys") then + add_extsources("pacman::SDL2") + elseif is_plat("linux") then + add_extsources("pacman::sdl2", "apt::libsdl2-dev") + elseif is_plat("macosx") then + add_extsources("brew::sdl2") + end + + set_license("zlib") + + add_urls("https://www.libsdl.org/release/SDL2-$(version).zip", + "https://github.com/libsdl-org/SDL/releases/download/release-$(version)/SDL2-$(version).zip", { alias = "archive" }) + add_urls("https://github.com/libsdl-org/SDL.git", { alias = "github" }) + add_versions("archive:2.0.8", "e6a7c71154c3001e318ba7ed4b98582de72ff970aca05abc9f45f7cbdc9088cb") + add_versions("archive:2.0.12", "476e84d6fcbc499cd1f4a2d3fd05a924abc165b5d0e0d53522c9604fe5a021aa") + add_versions("archive:2.0.14", "2c1e870d74e13dfdae870600bfcb6862a5eab4ea5b915144aff8d75a0f9bf046") + add_versions("archive:2.0.16", "010148866e2226e5469f2879425d28ff7c572c736cb3fb65a0604c3cde6bfab9") + add_versions("archive:2.0.18", "2d96cc82020341f7f5957c42001ad526e15fbb7056be8a74dab302483e97aa24") + add_versions("archive:2.0.20", "cc8b16a326eb082c1f48ca30fdf471acfd2334b69bd7527e65ac58369013a1ba") + add_versions("archive:2.0.22", "9a81ab724e6dcef96c61a4a2ebe7758e5b8bb191794650d276a20d5148fbd50c") + add_versions("archive:2.24.0", "4b065503d45652d5f65d807fe98c757c73af2968727945b596861995bc3b69c2") + add_versions("archive:2.24.2", "7fae98ac4e7b39eb2511fc27c2e84b220ac69b5296ff41f833b967c891f9d2ac") + add_versions("archive:2.26.0", "4a181f158f88676816e4993d7e97e7b48ef273aa6f4e2909c6a85497e9af3e9f") + add_versions("archive:2.26.1", "c038222fcac6ccc448daaa3febcae93fdac401aed12fd60da3b7939529276b1b") + add_versions("archive:2.26.2", "31510e53266c9e4730070ec20543c25642a85db7f678445cd9cfc61c7b6eb94b") + add_versions("github:2.0.8", "release-2.0.8") + add_versions("github:2.0.12", "release-2.0.12") + add_versions("github:2.0.14", "release-2.0.14") + add_versions("github:2.0.16", "release-2.0.16") + add_versions("github:2.0.18", "release-2.0.18") + add_versions("github:2.0.20", "release-2.0.20") + add_versions("github:2.0.22", "release-2.0.22") + add_versions("github:2.24.0", "release-2.24.0") + add_versions("github:2.24.2", "release-2.24.2") + add_versions("github:2.26.0", "release-2.26.0") + add_versions("github:2.26.1", "release-2.26.1") + add_versions("github:2.26.2", "release-2.26.2") + + add_deps("cmake") + + add_includedirs("include", "include/SDL2") + + add_configs("use_sdlmain", {description = "Use SDL_main entry point", default = true, type = "boolean"}) + if is_plat("linux") then + add_configs("with_x", {description = "Enables X support (requires it on the system)", default = true, type = "boolean"}) + elseif is_plat("wasm") then + add_configs("pthread", {description = "Compiles libsdl with pthread support", default = true, type = "boolean"}) + end + + on_load(function (package) + if package:config("use_sdlmain") then + package:add("components", "main") + end + package:add("components", "lib") + if package:is_plat("linux") and package:config("with_x") then + package:add("deps", "libxext", {private = true}) + elseif package:is_plat("wasm") and package:config("pthread") then + package:add("cxflags", "-pthread") + package:add("syslinks", "pthread") + end + end) + + on_component("main", function (package, component) + component:add("links", "SDL2main") + component:add("defines", "SDL_MAIN_HANDLED") + component:add("deps", "lib") + end) + + on_component("lib", function (package, component) + if package:config("shared") then + component:add("links", "SDL2") + else + component:add("links", package:is_plat("windows") and "SDL2-static" or "SDL2") + if package:is_plat("windows", "mingw") then + component:add("syslinks", "user32", "gdi32", "winmm", "imm32", "ole32", "oleaut32", "version", "uuid", "advapi32", "setupapi", "shell32") + elseif package:is_plat("linux", "bsd") then + component:add("syslinks", "pthread", "dl") + if package:is_plat("bsd") then + component:add("syslinks", "usbhid") + end + elseif package:is_plat("android") then + component:add("syslinks", "dl", "log", "android", "GLESv1_CM", "GLESv2", "OpenSLES") + elseif package:is_plat("iphoneos", "macosx") then + component:add("frameworks", "AudioToolbox", "AVFoundation", "CoreAudio", "CoreVideo", "Foundation", "Metal", "QuartzCore", "CoreFoundation") + component:add("syslinks", "iconv") + if package:is_plat("macosx") then + component:add("frameworks", "Cocoa", "Carbon", "ForceFeedback", "IOKit") + else + component:add("frameworks", "CoreBluetooth", "CoreGraphics", "CoreMotion", "OpenGLES", "UIKit") + end + if package:version():ge("2.0.14") then + package:add("frameworks", "CoreHaptics", "GameController") + end + end + end + end) + + on_fetch("linux", "macosx", "bsd", function (package, opt) + if opt.system then + -- use sdl2-config + local sdl2conf = try {function() return os.iorunv("sdl2-config", {"--version", "--cflags", "--libs"}) end} + if sdl2conf then + sdl2conf = os.argv(sdl2conf) + local sdl2ver = table.remove(sdl2conf, 1) + local result = {version = sdl2ver} + for _, flag in ipairs(sdl2conf) do + if flag:startswith("-L") and #flag > 2 then + -- get linkdirs + local linkdir = flag:sub(3) + if linkdir and os.isdir(linkdir) then + result.linkdirs = result.linkdirs or {} + table.insert(result.linkdirs, linkdir) + end + elseif flag:startswith("-I") and #flag > 2 then + -- get includedirs + local includedir = flag:sub(3) + if includedir and os.isdir(includedir) then + result.includedirs = result.includedirs or {} + table.insert(result.includedirs, includedir) + end + elseif flag:startswith("-l") and #flag > 2 then + -- get links + local link = flag:sub(3) + result.links = result.links or {} + table.insert(result.links, link) + elseif flag:startswith("-D") and #flag > 2 then + -- get defines + local define = flag:sub(3) + result.defines = result.defines or {} + table.insert(result.defines, define) + end + end + + return result + end + + -- finding using sdl2-config didn't work, fallback on pkgconfig + if package.find_package then + return package:find_package("pkgconfig::sdl2", opt) + else + return find_package("pkgconfig::sdl2", opt) + end + end + end) + + on_install(function (package) + local configs = {} + table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release")) + table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) + table.insert(configs, "-DSDL_TEST=OFF") + local opt + if package:is_plat("linux", "cross") then + local includedirs = {} + for _, depname in ipairs({"libxext", "libx11", "xorgproto"}) do + local dep = package:dep(depname) + if dep then + local depfetch = dep:fetch() + if depfetch then + for _, includedir in ipairs(depfetch.includedirs or depfetch.sysincludedirs) do + table.insert(includedirs, includedir) + end + end + end + end + if #includedirs > 0 then + includedirs = table.unique(includedirs) + + local cflags = {} + opt = opt or {} + opt.cflags = cflags + for _, includedir in ipairs(includedirs) do + table.insert(cflags, "-I" .. includedir) + end + table.insert(configs, "-DCMAKE_INCLUDE_PATH=" .. table.concat(includedirs, ";")) + end + elseif package:is_plat("bsd") then + opt = opt or {} + opt.packagedeps = "libusb" + elseif package:is_plat("wasm") then + -- emscripten enables USE_SDL by default which will conflict with the sdl headers + opt = opt or {} + opt.cflags = {"-sUSE_SDL=0"} + table.insert(configs, "-DSDL_PTHREADS=" .. (package:config("pthread") and "ON" or "OFF")) + end + import("package.tools.cmake").install(package, configs, opt) + end) + + on_test(function (package) + assert(package:has_cfuncs("SDL_Init", {includes = "SDL2/SDL.h", configs = {defines = "SDL_MAIN_HANDLED"}})) + end) diff --git a/xmake.lua b/xmake.lua index e2cd84314..22f1404d1 100644 --- a/xmake.lua +++ b/xmake.lua @@ -45,10 +45,6 @@ local rendererBackends = { } NazaraRendererBackends = rendererBackends -if is_plat("wasm") then - rendererBackends.VulkanRenderer = nil -end - local modules = { Audio = { Deps = {"NazaraCore"}, @@ -83,6 +79,13 @@ local modules = { elseif is_plat("linux") then add_packages("libuuid") add_syslinks("dl", "pthread") + elseif is_plat("wasm") then + --[[ + Have to fix issues with libsdl first + add_ldflags("-sPTHREAD_POOL_SIZE=4", { public = true }) + add_cxflags("-pthread", { public = true }) + add_ldflags("-pthread", { public = true }) + ]] end if is_plat("macosx", "iphoneos") then @@ -164,6 +167,12 @@ local modules = { } } +-- Vulkan doesn't run on web and Newton does not (yet) compile using emscripten +if is_plat("wasm") then + rendererBackends.VulkanRenderer = nil + modules.Physics3D = nil +end + if not has_config("embed_rendererbackends") then -- Register backends as separate modules for name, module in pairs(rendererBackends) do @@ -217,6 +226,7 @@ else end add_repositories("nazara-engine-repo https://github.com/NazaraEngine/xmake-repo") +--add_repositories("local-repo xmake-repo") add_requires("nazarautils") add_requires("nzsl", { debug = is_mode("debug"), configs = { with_symbols = not is_mode("release"), shared = not is_plat("wasm") } })