diff --git a/emscripten.patch b/emscripten.patch new file mode 100644 index 000000000..862f11759 --- /dev/null +++ b/emscripten.patch @@ -0,0 +1,1208 @@ +diff --git a/examples/DopplerEffect/main.cpp b/examples/DopplerEffect/main.cpp +index 0498da58a..ba817eadd 100644 +--- a/examples/DopplerEffect/main.cpp ++++ b/examples/DopplerEffect/main.cpp +@@ -14,6 +14,8 @@ + #include + #include + #include ++#include ++#include + #include + #include + #include +@@ -52,28 +54,33 @@ int main() + // On joue le son + sound.Play(); + +- // La boucle du programme (Pour déplacer le son) ++ Nz::Window window; ++ + Nz::Clock clock; +- while (sound.GetStatus() == Nz::SoundStatus::Playing) +- { +- // Comme le son se joue dans un thread séparé, on peut mettre en pause le principal régulièrement +- int sleepTime = int(1000/60 - clock.GetMilliseconds()); // 60 FPS ++ Nz::BasicMainloop(window, [&] { ++ if (sound.GetStatus() == Nz::SoundStatus::Playing) ++ { ++ // Comme le son se joue dans un thread séparé, on peut mettre en pause le principal régulièrement ++ int sleepTime = int(1000 / 60 - clock.GetMilliseconds()); // 60 FPS + +- if (sleepTime > 0) +- std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime)); ++ if (sleepTime > 0) ++ std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime)); + +- // On bouge la source du son en fonction du temps depuis chaque mise à jour +- Nz::Vector3f pos = sound.GetPosition() + sound.GetVelocity()*clock.GetSeconds(); +- sound.SetPosition(pos); ++ // On bouge la source du son en fonction du temps depuis chaque mise à jour ++ Nz::Vector3f pos = sound.GetPosition() + sound.GetVelocity() * clock.GetSeconds(); ++ sound.SetPosition(pos); + +- std::cout << "Sound position: " << pos << std::endl; ++ std::cout << "Sound position: " << pos << 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) ++ // 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) + +- clock.Restart(); +- } ++ clock.Restart(); ++ } ++ }); ++ ++ // La boucle du programme (Pour déplacer le son) + + return 0; + } +diff --git a/examples/GraphicsTest/main.cpp b/examples/GraphicsTest/main.cpp +index 1054bd8bd..f51e917d6 100644 +--- a/examples/GraphicsTest/main.cpp ++++ b/examples/GraphicsTest/main.cpp +@@ -17,11 +17,12 @@ int main() + resourceDir = "../.." / resourceDir; + + Nz::Renderer::Config rendererConfig; +- std::cout << "Run using Vulkan? (y/n)" << std::endl; ++ rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL; ++ /*std::cout << "Run using Vulkan? (y/n)" << std::endl; + if (std::getchar() == 'y') + rendererConfig.preferredAPI = Nz::RenderAPI::Vulkan; + else +- rendererConfig.preferredAPI = Nz::RenderAPI::Vulkan; ++ rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL;*/ + + Nz::Modules nazara(rendererConfig); + +@@ -31,7 +32,7 @@ int main() + meshParams.center = true; + meshParams.vertexRotation = Nz::EulerAnglesf(0.f, -90.f, 0.f); + meshParams.vertexScale = Nz::Vector3f(0.002f); +- meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_Normal_UV_Tangent); ++ meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_Normal_UV); + + std::shared_ptr device = Nz::Graphics::Instance()->GetRenderDevice(); + +@@ -122,6 +123,8 @@ int main() + + Nz::Mouse::SetRelativeMouseMode(true); + ++ Nz::Clock crashClock; ++ + Nz::BasicMainloop(window, [&] + { + Nz::WindowEvent event; +@@ -221,6 +224,14 @@ int main() + + framePipeline.GetDebugDrawer().DrawLine(Nz::Vector3f::Zero(), Nz::Vector3f::Forward(), Nz::Color::Blue); + ++ for (const Nz::WorldInstancePtr& worldInstance : { modelInstance, modelInstance2 }) ++ { ++ Nz::Boxf aabb = model.GetAABB(); ++ aabb.Transform(worldInstance->GetWorldMatrix()); ++ ++ framePipeline.GetDebugDrawer().DrawBox(aabb, Nz::Color::Green); ++ } ++ + viewerInstance.UpdateViewMatrix(Nz::Matrix4f::TransformInverse(viewerPos, camAngles)); + viewerInstance.UpdateEyePosition(viewerPos); + +@@ -249,6 +260,9 @@ int main() + // Et on relance l'horloge pour refaire ça dans une seconde + secondClock.Restart(); + } ++ ++ if (crashClock.GetSeconds() > 3.f) ++ std::abort(); + }); + + return EXIT_SUCCESS; +diff --git a/examples/GraphicsTest/xmake.lua b/examples/GraphicsTest/xmake.lua +index 76c04f596..b439049fd 100644 +--- a/examples/GraphicsTest/xmake.lua ++++ b/examples/GraphicsTest/xmake.lua +@@ -1,7 +1,3 @@ + target("GraphicsTest") + add_deps("NazaraGraphics") +- add_files("main.cpp") +- +- if is_plat("wasm") then +- add_ldflags("--preload-file assets/", {force = true}) +- end ++ add_files("main.cpp") +\ No newline at end of file +diff --git a/examples/PhysicallyBasedRendering/xmake.lua b/examples/PhysicallyBasedRendering/xmake.lua +index 5093554b6..6af2278d6 100644 +--- a/examples/PhysicallyBasedRendering/xmake.lua ++++ b/examples/PhysicallyBasedRendering/xmake.lua +@@ -1,7 +1,3 @@ + target("PBR") + add_deps("NazaraGraphics") + add_files("main.cpp") +- +- if is_plat("wasm") then +- add_ldflags("--preload-file assets/", {force = true}) +- end +diff --git a/examples/PlayMusic/main.cpp b/examples/PlayMusic/main.cpp +index e52b10440..dc5154a2d 100644 +--- a/examples/PlayMusic/main.cpp ++++ b/examples/PlayMusic/main.cpp +@@ -8,6 +8,8 @@ + #include + #include + #include ++#include ++#include + #include + #include + #include +@@ -18,6 +20,8 @@ int main() + if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir)) + resourceDir = "../.." / resourceDir; + ++ std::getchar(); ++ + Nz::Modules audio; + + Nz::SoundStreamParams streamParams; +@@ -35,8 +39,10 @@ int main() + + std::cout << "Playing sound..." << std::endl; + +- while (music.IsPlaying()) +- std::this_thread::sleep_for(std::chrono::milliseconds(100)); ++ Nz::Window window; ++ ++ Nz::BasicMainloop(window, [&] { ++ }); + + return EXIT_SUCCESS; + } +diff --git a/examples/PlayMusic/xmake.lua b/examples/PlayMusic/xmake.lua +index 946c770e3..3825e84bd 100644 +--- a/examples/PlayMusic/xmake.lua ++++ b/examples/PlayMusic/xmake.lua +@@ -1,3 +1,3 @@ + target("PlayMusic") +- add_deps("NazaraAudio") ++ add_deps("NazaraAudio", "NazaraPlatform") + add_files("main.cpp") +diff --git a/examples/RenderTest/main.cpp b/examples/RenderTest/main.cpp +index 7ae60e011..0c17e233e 100644 +--- a/examples/RenderTest/main.cpp ++++ b/examples/RenderTest/main.cpp +@@ -129,7 +129,6 @@ int main() + } + + Nz::MeshParams meshParams; +- meshParams.bufferFactory = Nz::GetRenderBufferFactory(device); + meshParams.center = true; + meshParams.vertexRotation = Nz::EulerAnglesf(0.f, -90.f, 0.f); + meshParams.vertexScale = Nz::Vector3f(0.002f); +@@ -153,6 +152,17 @@ int main() + // Vertex buffer + std::cout << "Vertex count: " << meshVB->GetVertexCount() << std::endl; + ++ // Create renderbuffers (GPU buffers) ++ const std::shared_ptr& renderDevice = window.GetRenderDevice(); ++ ++ assert(meshIB->GetBuffer()->GetStorage() == Nz::DataStorage::Software); ++ assert(meshVB->GetBuffer()->GetStorage() == Nz::DataStorage::Software); ++ const Nz::SoftwareBuffer* indexBufferContent = static_cast(meshIB->GetBuffer().get()); ++ const Nz::SoftwareBuffer* vertexBufferContent = static_cast(meshVB->GetBuffer().get()); ++ ++ std::shared_ptr renderBufferIB = renderDevice->InstantiateBuffer(Nz::BufferType::Index, indexBufferContent->GetSize(), Nz::BufferUsage::DeviceLocal, indexBufferContent->GetData()); ++ std::shared_ptr renderBufferVB = renderDevice->InstantiateBuffer(Nz::BufferType::Vertex, vertexBufferContent->GetSize(), Nz::BufferUsage::DeviceLocal, vertexBufferContent->GetData()); ++ + // Texture + Nz::TextureParams texParams; + texParams.renderDevice = device; +@@ -230,13 +240,8 @@ int main() + + std::shared_ptr pipeline = device->InstantiateRenderPipeline(pipelineInfo); + +- const std::shared_ptr& renderDevice = window.GetRenderDevice(); +- + std::shared_ptr commandPool = renderDevice->InstantiateCommandPool(Nz::QueueType::Graphics); + +- Nz::RenderBuffer& renderBufferIB = static_cast(*meshIB->GetBuffer()); +- Nz::RenderBuffer& renderBufferVB = static_cast(*meshVB->GetBuffer()); +- + Nz::Vector3f viewerPos = Nz::Vector3f::Zero(); + + Nz::EulerAnglesf camAngles(0.f, 0.f, 0.f); +@@ -253,6 +258,8 @@ int main() + + Nz::DebugDrawer debugDrawer(*renderDevice); + ++ Nz::Clock crashClock; ++ + Nz::BasicMainloop(window, [&] + { + Nz::WindowEvent event; +@@ -379,9 +386,9 @@ int main() + { + builder.BeginRenderPass(windowRT->GetFramebuffer(frame.GetFramebufferIndex()), windowRT->GetRenderPass(), renderRect, { clearValues[0], clearValues[1] }); + { +- builder.BindIndexBuffer(renderBufferIB, Nz::IndexType::U16); ++ builder.BindIndexBuffer(*renderBufferIB, Nz::IndexType::U16); + builder.BindPipeline(*pipeline); +- builder.BindVertexBuffer(0, renderBufferVB); ++ builder.BindVertexBuffer(0, *renderBufferVB); + builder.BindShaderBinding(0, *viewerShaderBinding); + builder.BindShaderBinding(1, *textureShaderBinding); + +@@ -421,6 +428,9 @@ int main() + // Et on relance l'horloge pour refaire ça dans une seconde + secondClock.Restart(); + } ++ ++ if (crashClock.GetSeconds() > 2.f) ++ std::abort(); + }); + + return EXIT_SUCCESS; +diff --git a/examples/xmake.lua b/examples/xmake.lua +index 2e114e9dd..c86f78d0b 100644 +--- a/examples/xmake.lua ++++ b/examples/xmake.lua +@@ -5,5 +5,9 @@ if has_config("examples") then + set_group("Examples") + set_kind("binary") + ++ if is_plat("wasm") then ++ add_ldflags("--preload-file assets/", { force = true }) ++ end ++ + includes("*/xmake.lua") + end +diff --git a/include/Nazara/Audio.hpp b/include/Nazara/Audio.hpp +index 5b2ad2252..a72eaca2a 100644 +--- a/include/Nazara/Audio.hpp ++++ b/include/Nazara/Audio.hpp +@@ -40,11 +40,6 @@ + #include + #include + #include +-#include +-#include +-#include +-#include +-#include + #include + #include + #include +diff --git a/include/Nazara/Audio/OpenAL.hpp b/include/Nazara/Audio/OpenAL.hpp +index d23cd08eb..f50c8bd1a 100644 +--- a/include/Nazara/Audio/OpenAL.hpp ++++ b/include/Nazara/Audio/OpenAL.hpp +@@ -2,174 +2,147 @@ + // This file is part of the "Nazara Engine - Audio module" + // For conditions of distribution and use, see copyright notice in Config.hpp + +-#pragma once ++// no header guards + +-#ifndef NAZARA_AUDIO_OPENAL_HPP +-#define NAZARA_AUDIO_OPENAL_HPP ++#if (!defined(NAZARA_AUDIO_AL_FUNCTION) || !defined(NAZARA_AUDIO_ALC_FUNCTION)) && !defined(NAZARA_AUDIO_AL_ALC_FUNCTION) ++#error You must define NAZARA_AUDIO_AL_FUNCTION and NAZARA_AUDIO_ALC_FUNCTION, or NAZARA_AUDIO_AL_ALC_FUNCTION before including this file ++#endif + +-// no include reordering ++#ifndef NAZARA_AUDIO_AL_FUNCTION ++#define NAZARA_AUDIO_AL_FUNCTION(func) NAZARA_AUDIO_AL_ALC_FUNCTION(func) ++#endif + +-#if defined(NAZARA_AUDIO_OPENAL) || defined(NAZARA_AUDIO_BUILD) ++#ifndef NAZARA_AUDIO_ALC_FUNCTION ++#define NAZARA_AUDIO_ALC_FUNCTION(func) NAZARA_AUDIO_AL_ALC_FUNCTION(func) ++#endif + +-#include ++#ifndef NAZARA_AUDIO_AL_EXT_FUNCTION ++#define NAZARA_AUDIO_AL_EXT_FUNCTION(func) NAZARA_AUDIO_AL_FUNCTION(func) ++#endif + +-// Inclusion of OpenAL headers ++#ifndef NAZARA_AUDIO_AL_EXT_BEGIN ++#define NAZARA_AUDIO_AL_EXT_BEGIN(ext) ++#endif + +-// OpenAL headers does not allow us to only get the signatures without the pointers to the functions +-// And I do no want to modify them, I'm obliged to put them in a different namespace +-// to put only interesting things back in the global namespace (specially typedef) +-namespace OpenALDetail +-{ +- #include +- #include +- #include +-} ++#ifndef NAZARA_AUDIO_AL_EXT_END ++#define NAZARA_AUDIO_AL_EXT_END() ++#endif + +-// If someone has a better idea ... +-using OpenALDetail::ALboolean; +-using OpenALDetail::ALbyte; +-using OpenALDetail::ALchar; +-using OpenALDetail::ALdouble; +-using OpenALDetail::ALenum; +-using OpenALDetail::ALfloat; +-using OpenALDetail::ALint; +-using OpenALDetail::ALshort; +-using OpenALDetail::ALsizei; +-using OpenALDetail::ALubyte; +-using OpenALDetail::ALuint; +-using OpenALDetail::ALushort; +-using OpenALDetail::ALvoid; ++NAZARA_AUDIO_AL_FUNCTION(alBuffer3f) ++NAZARA_AUDIO_AL_FUNCTION(alBuffer3i) ++NAZARA_AUDIO_AL_FUNCTION(alBufferData) ++NAZARA_AUDIO_AL_FUNCTION(alBufferf) ++NAZARA_AUDIO_AL_FUNCTION(alBufferfv) ++NAZARA_AUDIO_AL_FUNCTION(alBufferi) ++NAZARA_AUDIO_AL_FUNCTION(alBufferiv) ++NAZARA_AUDIO_AL_FUNCTION(alDeleteBuffers) ++NAZARA_AUDIO_AL_FUNCTION(alDeleteSources) ++NAZARA_AUDIO_AL_FUNCTION(alDisable) ++NAZARA_AUDIO_AL_FUNCTION(alDistanceModel) ++NAZARA_AUDIO_AL_FUNCTION(alDopplerFactor) ++NAZARA_AUDIO_AL_FUNCTION(alDopplerVelocity) ++NAZARA_AUDIO_AL_FUNCTION(alEnable) ++NAZARA_AUDIO_AL_FUNCTION(alGenBuffers) ++NAZARA_AUDIO_AL_FUNCTION(alGenSources) ++NAZARA_AUDIO_AL_FUNCTION(alGetBoolean) ++NAZARA_AUDIO_AL_FUNCTION(alGetBooleanv) ++NAZARA_AUDIO_AL_FUNCTION(alGetBuffer3f) ++NAZARA_AUDIO_AL_FUNCTION(alGetBuffer3i) ++NAZARA_AUDIO_AL_FUNCTION(alGetBufferf) ++NAZARA_AUDIO_AL_FUNCTION(alGetBufferfv) ++NAZARA_AUDIO_AL_FUNCTION(alGetBufferi) ++NAZARA_AUDIO_AL_FUNCTION(alGetBufferiv) ++NAZARA_AUDIO_AL_FUNCTION(alGetDouble) ++NAZARA_AUDIO_AL_FUNCTION(alGetDoublev) ++NAZARA_AUDIO_AL_FUNCTION(alGetEnumValue) ++NAZARA_AUDIO_AL_FUNCTION(alGetError) ++NAZARA_AUDIO_AL_FUNCTION(alGetFloat) ++NAZARA_AUDIO_AL_FUNCTION(alGetFloatv) ++NAZARA_AUDIO_AL_FUNCTION(alGetInteger) ++NAZARA_AUDIO_AL_FUNCTION(alGetIntegerv) ++NAZARA_AUDIO_AL_FUNCTION(alGetListener3f) ++NAZARA_AUDIO_AL_FUNCTION(alGetListener3i) ++NAZARA_AUDIO_AL_FUNCTION(alGetListenerf) ++NAZARA_AUDIO_AL_FUNCTION(alGetListenerfv) ++NAZARA_AUDIO_AL_FUNCTION(alGetListeneri) ++NAZARA_AUDIO_AL_FUNCTION(alGetListeneriv) ++NAZARA_AUDIO_AL_FUNCTION(alGetProcAddress) ++NAZARA_AUDIO_AL_FUNCTION(alGetSource3f) ++NAZARA_AUDIO_AL_FUNCTION(alGetSource3i) ++NAZARA_AUDIO_AL_FUNCTION(alGetSourcef) ++NAZARA_AUDIO_AL_FUNCTION(alGetSourcefv) ++NAZARA_AUDIO_AL_FUNCTION(alGetSourcei) ++NAZARA_AUDIO_AL_FUNCTION(alGetSourceiv) ++NAZARA_AUDIO_AL_FUNCTION(alGetString) ++NAZARA_AUDIO_AL_FUNCTION(alIsBuffer) ++NAZARA_AUDIO_AL_FUNCTION(alIsEnabled) ++NAZARA_AUDIO_AL_FUNCTION(alIsExtensionPresent) ++NAZARA_AUDIO_AL_FUNCTION(alIsSource) ++NAZARA_AUDIO_AL_FUNCTION(alListener3f) ++NAZARA_AUDIO_AL_FUNCTION(alListener3i) ++NAZARA_AUDIO_AL_FUNCTION(alListenerf) ++NAZARA_AUDIO_AL_FUNCTION(alListenerfv) ++NAZARA_AUDIO_AL_FUNCTION(alListeneri) ++NAZARA_AUDIO_AL_FUNCTION(alListeneriv) ++NAZARA_AUDIO_AL_FUNCTION(alSource3f) ++NAZARA_AUDIO_AL_FUNCTION(alSource3i) ++NAZARA_AUDIO_AL_FUNCTION(alSourcef) ++NAZARA_AUDIO_AL_FUNCTION(alSourcefv) ++NAZARA_AUDIO_AL_FUNCTION(alSourcei) ++NAZARA_AUDIO_AL_FUNCTION(alSourceiv) ++NAZARA_AUDIO_AL_FUNCTION(alSourcePause) ++NAZARA_AUDIO_AL_FUNCTION(alSourcePausev) ++NAZARA_AUDIO_AL_FUNCTION(alSourcePlay) ++NAZARA_AUDIO_AL_FUNCTION(alSourcePlayv) ++NAZARA_AUDIO_AL_FUNCTION(alSourceQueueBuffers) ++NAZARA_AUDIO_AL_FUNCTION(alSourceRewind) ++NAZARA_AUDIO_AL_FUNCTION(alSourceRewindv) ++NAZARA_AUDIO_AL_FUNCTION(alSourceStop) ++NAZARA_AUDIO_AL_FUNCTION(alSourceStopv) ++NAZARA_AUDIO_AL_FUNCTION(alSourceUnqueueBuffers) ++NAZARA_AUDIO_AL_FUNCTION(alSpeedOfSound) + +-// SOFT_source_latency +-using OpenALDetail::ALint64SOFT; +-using OpenALDetail::ALuint64SOFT; ++/* ++NAZARA_AUDIO_AL_EXT_BEGIN(AL_SOFT_source_latency) ++NAZARA_AUDIO_AL_FUNCTION_EXT(alGetSource3dSOFT) ++NAZARA_AUDIO_AL_FUNCTION_EXT(alGetSource3i64SOFT) ++NAZARA_AUDIO_AL_FUNCTION_EXT(alGetSourcedSOFT) ++NAZARA_AUDIO_AL_FUNCTION_EXT(alGetSourcedvSOFT) ++NAZARA_AUDIO_AL_FUNCTION_EXT(alGetSourcei64SOFT) ++NAZARA_AUDIO_AL_FUNCTION_EXT(alGetSourcei64vSOFT) ++NAZARA_AUDIO_AL_FUNCTION_EXT(alSource3dSOFT) ++NAZARA_AUDIO_AL_FUNCTION_EXT(alSource3i64SOFT) ++NAZARA_AUDIO_AL_FUNCTION_EXT(alSourcedSOFT) ++NAZARA_AUDIO_AL_FUNCTION_EXT(alSourcedvSOFT) ++NAZARA_AUDIO_AL_FUNCTION_EXT(alSourcei64SOFT) ++NAZARA_AUDIO_AL_FUNCTION_EXT(alSourcei64vSOFT) ++NAZARA_AUDIO_AL_EXT_END() ++*/ + +-using OpenALDetail::ALCboolean; +-using OpenALDetail::ALCbyte; +-using OpenALDetail::ALCchar; +-using OpenALDetail::ALCcontext; +-using OpenALDetail::ALCdevice; +-using OpenALDetail::ALCdouble; +-using OpenALDetail::ALCenum; +-using OpenALDetail::ALCfloat; +-using OpenALDetail::ALCint; +-using OpenALDetail::ALCshort; +-using OpenALDetail::ALCsizei; +-using OpenALDetail::ALCubyte; +-using OpenALDetail::ALCuint; +-using OpenALDetail::ALCushort; +-using OpenALDetail::ALCvoid; ++NAZARA_AUDIO_ALC_FUNCTION(alcCaptureCloseDevice) ++NAZARA_AUDIO_ALC_FUNCTION(alcCaptureOpenDevice) ++NAZARA_AUDIO_ALC_FUNCTION(alcCaptureSamples) ++NAZARA_AUDIO_ALC_FUNCTION(alcCaptureStart) ++NAZARA_AUDIO_ALC_FUNCTION(alcCaptureStop) ++NAZARA_AUDIO_ALC_FUNCTION(alcCloseDevice) ++NAZARA_AUDIO_ALC_FUNCTION(alcCreateContext) ++NAZARA_AUDIO_ALC_FUNCTION(alcDestroyContext) ++NAZARA_AUDIO_ALC_FUNCTION(alcGetContextsDevice) ++NAZARA_AUDIO_ALC_FUNCTION(alcGetCurrentContext) ++NAZARA_AUDIO_ALC_FUNCTION(alcGetEnumValue) ++NAZARA_AUDIO_ALC_FUNCTION(alcGetError) ++NAZARA_AUDIO_ALC_FUNCTION(alcGetIntegerv) ++NAZARA_AUDIO_ALC_FUNCTION(alcGetProcAddress) ++NAZARA_AUDIO_ALC_FUNCTION(alcGetString) ++NAZARA_AUDIO_ALC_FUNCTION(alcIsExtensionPresent) ++NAZARA_AUDIO_ALC_FUNCTION(alcMakeContextCurrent) ++NAZARA_AUDIO_ALC_FUNCTION(alcOpenDevice) ++NAZARA_AUDIO_ALC_FUNCTION(alcProcessContext) ++NAZARA_AUDIO_ALC_FUNCTION(alcSuspendContext) + +-#define NAZARA_AUDIO_FOREACH_AL_FUNC(cb, extCb) \ +- cb(alBuffer3f, OpenALDetail::LPALBUFFER3F) \ +- cb(alBuffer3i, OpenALDetail::LPALBUFFER3I) \ +- cb(alBufferData, OpenALDetail::LPALBUFFERDATA) \ +- cb(alBufferf, OpenALDetail::LPALBUFFERF) \ +- cb(alBufferfv, OpenALDetail::LPALBUFFERFV) \ +- cb(alBufferi, OpenALDetail::LPALBUFFERI) \ +- cb(alBufferiv, OpenALDetail::LPALBUFFERIV) \ +- cb(alDeleteBuffers, OpenALDetail::LPALDELETEBUFFERS) \ +- cb(alDeleteSources, OpenALDetail::LPALDELETESOURCES) \ +- cb(alDisable, OpenALDetail::LPALDISABLE) \ +- cb(alDistanceModel, OpenALDetail::LPALDISTANCEMODEL) \ +- cb(alDopplerFactor, OpenALDetail::LPALDOPPLERFACTOR) \ +- cb(alDopplerVelocity, OpenALDetail::LPALDOPPLERVELOCITY) \ +- cb(alEnable, OpenALDetail::LPALENABLE) \ +- cb(alGenBuffers, OpenALDetail::LPALGENBUFFERS) \ +- cb(alGenSources, OpenALDetail::LPALGENSOURCES) \ +- cb(alGetBoolean, OpenALDetail::LPALGETBOOLEAN) \ +- cb(alGetBooleanv, OpenALDetail::LPALGETBOOLEANV) \ +- cb(alGetBuffer3f, OpenALDetail::LPALGETBUFFER3F) \ +- cb(alGetBuffer3i, OpenALDetail::LPALGETBUFFER3I) \ +- cb(alGetBufferf, OpenALDetail::LPALGETBUFFERF) \ +- cb(alGetBufferfv, OpenALDetail::LPALGETBUFFERFV) \ +- cb(alGetBufferi, OpenALDetail::LPALGETBUFFERI) \ +- cb(alGetBufferiv, OpenALDetail::LPALGETBUFFERIV) \ +- cb(alGetDouble, OpenALDetail::LPALGETDOUBLE) \ +- cb(alGetDoublev, OpenALDetail::LPALGETDOUBLEV) \ +- cb(alGetEnumValue, OpenALDetail::LPALGETENUMVALUE) \ +- cb(alGetError, OpenALDetail::LPALGETERROR) \ +- cb(alGetFloat, OpenALDetail::LPALGETFLOAT) \ +- cb(alGetFloatv, OpenALDetail::LPALGETFLOATV) \ +- cb(alGetInteger, OpenALDetail::LPALGETINTEGER) \ +- cb(alGetIntegerv, OpenALDetail::LPALGETINTEGERV) \ +- cb(alGetListener3f, OpenALDetail::LPALGETLISTENER3F) \ +- cb(alGetListener3i, OpenALDetail::LPALGETLISTENER3I) \ +- cb(alGetListenerf, OpenALDetail::LPALGETLISTENERF) \ +- cb(alGetListenerfv, OpenALDetail::LPALGETLISTENERFV) \ +- cb(alGetListeneri, OpenALDetail::LPALGETLISTENERI) \ +- cb(alGetListeneriv, OpenALDetail::LPALGETLISTENERIV) \ +- cb(alGetProcAddress, OpenALDetail::LPALGETPROCADDRESS) \ +- cb(alGetSource3f, OpenALDetail::LPALGETSOURCE3F) \ +- cb(alGetSource3i, OpenALDetail::LPALGETSOURCE3I) \ +- cb(alGetSourcef, OpenALDetail::LPALGETSOURCEF) \ +- cb(alGetSourcefv, OpenALDetail::LPALGETSOURCEFV) \ +- cb(alGetSourcei, OpenALDetail::LPALGETSOURCEI) \ +- cb(alGetSourceiv, OpenALDetail::LPALGETSOURCEIV) \ +- cb(alGetString, OpenALDetail::LPALGETSTRING) \ +- cb(alIsBuffer, OpenALDetail::LPALISBUFFER) \ +- cb(alIsEnabled, OpenALDetail::LPALISENABLED) \ +- cb(alIsExtensionPresent, OpenALDetail::LPALISEXTENSIONPRESENT) \ +- cb(alIsSource, OpenALDetail::LPALISSOURCE) \ +- cb(alListener3f, OpenALDetail::LPALLISTENER3F) \ +- cb(alListener3i, OpenALDetail::LPALLISTENER3I) \ +- cb(alListenerf, OpenALDetail::LPALLISTENERF) \ +- cb(alListenerfv, OpenALDetail::LPALLISTENERFV) \ +- cb(alListeneri, OpenALDetail::LPALLISTENERI) \ +- cb(alListeneriv, OpenALDetail::LPALLISTENERIV) \ +- cb(alSource3f, OpenALDetail::LPALSOURCE3F) \ +- cb(alSource3i, OpenALDetail::LPALSOURCE3I) \ +- cb(alSourcef, OpenALDetail::LPALSOURCEF) \ +- cb(alSourcefv, OpenALDetail::LPALSOURCEFV) \ +- cb(alSourcei, OpenALDetail::LPALSOURCEI) \ +- cb(alSourceiv, OpenALDetail::LPALSOURCEIV) \ +- cb(alSourcePause, OpenALDetail::LPALSOURCEPAUSE) \ +- cb(alSourcePausev, OpenALDetail::LPALSOURCEPAUSEV) \ +- cb(alSourcePlay, OpenALDetail::LPALSOURCEPLAY) \ +- cb(alSourcePlayv, OpenALDetail::LPALSOURCEPLAYV) \ +- cb(alSourceQueueBuffers, OpenALDetail::LPALSOURCEQUEUEBUFFERS) \ +- cb(alSourceRewind, OpenALDetail::LPALSOURCEREWIND) \ +- cb(alSourceRewindv, OpenALDetail::LPALSOURCEREWINDV) \ +- cb(alSourceStop, OpenALDetail::LPALSOURCESTOP) \ +- cb(alSourceStopv, OpenALDetail::LPALSOURCESTOPV) \ +- cb(alSourceUnqueueBuffers, OpenALDetail::LPALSOURCEUNQUEUEBUFFERS) \ +- cb(alSpeedOfSound, OpenALDetail::LPALSPEEDOFSOUND) \ +- /* AL_SOFT_source_latency */ \ +- extCb(alGetSource3dSOFT, OpenALDetail::LPALGETSOURCE3DSOFT) \ +- extCb(alGetSource3i64SOFT, OpenALDetail::LPALGETSOURCE3I64SOFT) \ +- extCb(alGetSourcedSOFT, OpenALDetail::LPALGETSOURCEDSOFT) \ +- extCb(alGetSourcedvSOFT, OpenALDetail::LPALGETSOURCEDVSOFT) \ +- extCb(alGetSourcei64SOFT, OpenALDetail::LPALGETSOURCEI64SOFT) \ +- extCb(alGetSourcei64vSOFT, OpenALDetail::LPALGETSOURCEI64VSOFT) \ +- extCb(alSource3dSOFT, OpenALDetail::LPALSOURCE3DSOFT) \ +- extCb(alSource3i64SOFT, OpenALDetail::LPALSOURCE3I64SOFT) \ +- extCb(alSourcedSOFT, OpenALDetail::LPALSOURCEDSOFT) \ +- extCb(alSourcedvSOFT, OpenALDetail::LPALSOURCEDVSOFT) \ +- extCb(alSourcei64SOFT, OpenALDetail::LPALSOURCEI64SOFT) \ +- extCb(alSourcei64vSOFT, OpenALDetail::LPALSOURCEI64VSOFT) \ +- +-#define NAZARA_AUDIO_FOREACH_ALC_FUNC(cb, extCb) \ +- cb(alcCaptureCloseDevice, OpenALDetail::LPALCCAPTURECLOSEDEVICE) \ +- cb(alcCaptureOpenDevice, OpenALDetail::LPALCCAPTUREOPENDEVICE) \ +- cb(alcCaptureSamples, OpenALDetail::LPALCCAPTURESAMPLES) \ +- cb(alcCaptureStart, OpenALDetail::LPALCCAPTURESTART) \ +- cb(alcCaptureStop, OpenALDetail::LPALCCAPTURESTOP) \ +- cb(alcCloseDevice, OpenALDetail::LPALCCLOSEDEVICE) \ +- cb(alcCreateContext, OpenALDetail::LPALCCREATECONTEXT) \ +- cb(alcDestroyContext, OpenALDetail::LPALCDESTROYCONTEXT) \ +- cb(alcGetContextsDevice, OpenALDetail::LPALCGETCONTEXTSDEVICE) \ +- cb(alcGetCurrentContext, OpenALDetail::LPALCGETCURRENTCONTEXT) \ +- cb(alcGetEnumValue, OpenALDetail::LPALCGETENUMVALUE) \ +- cb(alcGetError, OpenALDetail::LPALCGETERROR) \ +- cb(alcGetIntegerv, OpenALDetail::LPALCGETINTEGERV) \ +- cb(alcGetProcAddress, OpenALDetail::LPALCGETPROCADDRESS) \ +- cb(alcGetString, OpenALDetail::LPALCGETSTRING) \ +- cb(alcIsExtensionPresent, OpenALDetail::LPALCISEXTENSIONPRESENT) \ +- cb(alcMakeContextCurrent, OpenALDetail::LPALCMAKECONTEXTCURRENT) \ +- cb(alcOpenDevice, OpenALDetail::LPALCOPENDEVICE) \ +- cb(alcProcessContext, OpenALDetail::LPALCPROCESSCONTEXT) \ +- cb(alcSuspendContext, OpenALDetail::LPALCSUSPENDCONTEXT) \ +- +-#endif // NAZARA_AUDIO_OPENAL +- +-#endif // NAZARA_AUDIO_OPENAL_HPP ++#undef NAZARA_AUDIO_AL_FUNCTION ++#undef NAZARA_AUDIO_AL_ALC_FUNCTION ++#undef NAZARA_AUDIO_AL_EXT_FUNCTION ++#undef NAZARA_AUDIO_ALC_FUNCTION ++#undef NAZARA_AUDIO_AL_EXT_BEGIN ++#undef NAZARA_AUDIO_AL_EXT_END +diff --git a/include/Nazara/Audio/OpenALBuffer.hpp b/include/Nazara/Audio/OpenALBuffer.hpp +index 132b2be4b..24e974e4f 100644 +--- a/include/Nazara/Audio/OpenALBuffer.hpp ++++ b/include/Nazara/Audio/OpenALBuffer.hpp +@@ -12,12 +12,11 @@ + #include + #include + #include +-#include ++#include + + namespace Nz + { + class OpenALDevice; +- class OpenALLibrary; + + class NAZARA_AUDIO_API OpenALBuffer final : public AudioBuffer + { +diff --git a/include/Nazara/Audio/OpenALDevice.hpp b/include/Nazara/Audio/OpenALDevice.hpp +index 84572e4d7..30fe1fc94 100644 +--- a/include/Nazara/Audio/OpenALDevice.hpp ++++ b/include/Nazara/Audio/OpenALDevice.hpp +@@ -13,7 +13,7 @@ + #include + #include + #include +-#include ++#include + #include + #include + #include +@@ -21,8 +21,6 @@ + + namespace Nz + { +- class OpenALLibrary; +- + enum class OpenALExtension + { + SourceLatency, +diff --git a/include/Nazara/Audio/OpenALLibrary.hpp b/include/Nazara/Audio/OpenALLibrary.hpp +index c9a1d1c66..07c990067 100644 +--- a/include/Nazara/Audio/OpenALLibrary.hpp ++++ b/include/Nazara/Audio/OpenALLibrary.hpp +@@ -7,23 +7,29 @@ + #ifndef NAZARA_AUDIO_OPENALLIBRARY_HPP + #define NAZARA_AUDIO_OPENALLIBRARY_HPP + +-#if defined(NAZARA_AUDIO_OPENAL) || defined(NAZARA_AUDIO_BUILD) +- + #include + #include + #include +-#include +-#include + #include + #include + #include + ++// Inclusion of OpenAL headers ++#include ++#include ++ ++#ifndef NAZARA_PLATFORM_WEB ++#include ++#endif ++ + namespace Nz + { ++ class OpenALDevice; ++ + class NAZARA_AUDIO_API OpenALLibrary + { + public: +- OpenALLibrary() = default; ++ inline OpenALLibrary(); + OpenALLibrary(const OpenALLibrary&) = delete; + OpenALLibrary(OpenALLibrary&&) = delete; + inline ~OpenALLibrary(); +@@ -42,21 +48,18 @@ namespace Nz + OpenALLibrary& operator=(const OpenALLibrary&) = delete; + OpenALLibrary& operator=(OpenALLibrary&&) = delete; + +-#define NAZARA_AUDIO_FUNC(name, sig) sig name; +- NAZARA_AUDIO_FOREACH_AL_FUNC(NAZARA_AUDIO_FUNC, NAZARA_AUDIO_FUNC) +- NAZARA_AUDIO_FOREACH_ALC_FUNC(NAZARA_AUDIO_FUNC, NAZARA_AUDIO_FUNC) +-#undef NAZARA_AUDIO_FUNC ++#define NAZARA_AUDIO_AL_ALC_FUNCTION(name) decltype(&::name) name; ++#include + + private: + std::vector ParseDevices(const char* deviceString); + + DynLib m_library; ++ bool m_isLoaded; + bool m_hasCaptureSupport; + }; + } + + #include + +-#endif // NAZARA_AUDIO_OPENAL +- + #endif // NAZARA_AUDIO_OPENALLIBRARY_HPP +diff --git a/include/Nazara/Audio/OpenALLibrary.inl b/include/Nazara/Audio/OpenALLibrary.inl +index 05e08e4e0..856fd9a2d 100644 +--- a/include/Nazara/Audio/OpenALLibrary.inl ++++ b/include/Nazara/Audio/OpenALLibrary.inl +@@ -7,6 +7,12 @@ + + namespace Nz + { ++ inline OpenALLibrary::OpenALLibrary() : ++ m_hasCaptureSupport(false), ++ m_isLoaded(false) ++ { ++ } ++ + inline OpenALLibrary::~OpenALLibrary() + { + Unload(); +@@ -14,7 +20,7 @@ namespace Nz + + inline bool OpenALLibrary::IsLoaded() const + { +- return m_library.IsLoaded(); ++ return m_isLoaded; + } + } + +diff --git a/include/Nazara/Audio/OpenALSource.hpp b/include/Nazara/Audio/OpenALSource.hpp +index 73afff99d..3473abdcb 100644 +--- a/include/Nazara/Audio/OpenALSource.hpp ++++ b/include/Nazara/Audio/OpenALSource.hpp +@@ -12,13 +12,12 @@ + #include + #include + #include +-#include ++#include + + namespace Nz + { + class OpenALBuffer; + class OpenALDevice; +- class OpenALLibrary; + + class NAZARA_AUDIO_API OpenALSource final : public AudioSource + { +diff --git a/include/Nazara/OpenGLRenderer/Wrapper/Context.hpp b/include/Nazara/OpenGLRenderer/Wrapper/Context.hpp +index d2cc4248f..e674abd1c 100644 +--- a/include/Nazara/OpenGLRenderer/Wrapper/Context.hpp ++++ b/include/Nazara/OpenGLRenderer/Wrapper/Context.hpp +@@ -164,6 +164,7 @@ namespace Nz::GL + inline void NotifyVertexArrayDestruction(GLuint vao) const; + + bool ProcessErrorStack() const; ++ template bool ProcessErrorStack(std::size_t funcIndex, Args... args) const; + + inline void ResetColorWriteMasks() const; + inline void ResetDepthWriteMasks() const; +diff --git a/include/Nazara/Utility/BasicMainloop.hpp b/include/Nazara/Utility/BasicMainloop.hpp +index 359b5c978..c419651a9 100644 +--- a/include/Nazara/Utility/BasicMainloop.hpp ++++ b/include/Nazara/Utility/BasicMainloop.hpp +@@ -7,7 +7,7 @@ + #ifndef NAZARA_BASIC_MAINLOOP_HPP + #define NAZARA_BASIC_MAINLOOP_HPP + +-#include ++#include + + #ifdef NAZARA_PLATFORM_WEB + #include +@@ -16,7 +16,7 @@ + namespace Nz + { + template +- void BasicMainloop(RenderWindow& window, CallbackT&& callback) ++ void BasicMainloop(Window& window, CallbackT&& callback) + { + #ifndef NAZARA_PLATFORM_WEB + while (window.IsOpen()) +diff --git a/src/Nazara/Audio/Audio.cpp b/src/Nazara/Audio/Audio.cpp +index 153c9f585..02f8a6c86 100644 +--- a/src/Nazara/Audio/Audio.cpp ++++ b/src/Nazara/Audio/Audio.cpp +@@ -8,7 +8,7 @@ + #include + #include + #include +-#include ++#include + #include + #include + #include +diff --git a/src/Nazara/Audio/OpenALLibrary.cpp b/src/Nazara/Audio/OpenALLibrary.cpp +index e9380a68e..4fcfe990f 100644 +--- a/src/Nazara/Audio/OpenALLibrary.cpp ++++ b/src/Nazara/Audio/OpenALLibrary.cpp +@@ -3,6 +3,7 @@ + // For conditions of distribution and use, see copyright notice in Config.hpp + + #include ++#include + #include + #include + #include +@@ -23,6 +24,16 @@ namespace Nz + + CallOnExit unloadOnFailure([this] { Unload(); }); + ++ auto PostLoad = [&] ++ { ++ m_hasCaptureSupport = alcIsExtensionPresent(nullptr, "ALC_EXT_CAPTURE"); ++ m_isLoaded = true; ++ ++ unloadOnFailure.Reset(); ++ }; ++ ++#ifndef NAZARA_AUDIO_OPENAL_LINK ++ // Dynamically load OpenAL + #if defined(NAZARA_PLATFORM_WINDOWS) + std::array libs{ + "soft_oal.dll", +@@ -74,15 +85,32 @@ namespace Nz + continue; + } + +- m_hasCaptureSupport = alcIsExtensionPresent(nullptr, "ALC_EXT_CAPTURE"); +- +- unloadOnFailure.Reset(); ++ PostLoad(); + return true; + } + + NazaraError("failed to load OpenAL library"); + return false; +- } ++ ++#else ++ // OpenAL is linked to the executable ++ ++ // Load core ++#define NAZARA_AUDIO_AL_ALC_FUNCTION(name) name = &::name; ++#define NAZARA_AUDIO_AL_EXT_FUNCTION(name) ++#include ++ ++ // Load ext ++#define NAZARA_AUDIO_AL_ALC_FUNCTION(name) ++#define NAZARA_AUDIO_AL_EXT_BEGIN(ext) if (alIsExtensionPresent(#ext)) { ++#define NAZARA_AUDIO_AL_EXT_END() } ++#define NAZARA_AUDIO_AL_FUNCTION_EXT(name) name = reinterpret_cast(alGetProcAddress(#name)); ++#include ++ ++ PostLoad(); ++ return true; ++#endif ++ } + + std::vector OpenALLibrary::QueryInputDevices() + { +@@ -111,10 +139,8 @@ namespace Nz + if (!m_library.IsLoaded()) + return; + +-#define NAZARA_AUDIO_FUNC(name, sig) name = nullptr; +- NAZARA_AUDIO_FOREACH_AL_FUNC(NAZARA_AUDIO_FUNC, NAZARA_AUDIO_FUNC) +- NAZARA_AUDIO_FOREACH_ALC_FUNC(NAZARA_AUDIO_FUNC, NAZARA_AUDIO_FUNC) +-#undef NAZARA_AUDIO_FUNC ++#define NAZARA_AUDIO_AL_ALC_FUNCTION(name) name = nullptr; ++#include + + m_library.Unload(); + } +diff --git a/src/Nazara/Audio/OpenALSource.cpp b/src/Nazara/Audio/OpenALSource.cpp +index d4bf7a808..98d163b79 100644 +--- a/src/Nazara/Audio/OpenALSource.cpp ++++ b/src/Nazara/Audio/OpenALSource.cpp +@@ -4,6 +4,7 @@ + + #include + #include ++#include + #include + #include + #include +@@ -84,18 +85,20 @@ namespace Nz + auto OpenALSource::GetSampleOffsetAndLatency() const -> OffsetWithLatency + { + OffsetWithLatency offsetWithLatency; +- if (GetDevice().IsExtensionSupported(OpenALExtension::SourceLatency)) ++#ifndef NAZARA_PLATFORM_WEB ++ /*if (GetDevice().IsExtensionSupported(OpenALExtension::SourceLatency)) + { + GetDevice().MakeContextCurrent(); + +- std::array values; ++ std::array values; + m_library.alGetSourcei64vSOFT(m_sourceId, AL_SAMPLE_OFFSET_LATENCY_SOFT, values.data()); + + offsetWithLatency.sampleOffset = ((values[0] & 0xFFFFFFFF00000000) >> 32) * 1'000; + offsetWithLatency.sourceLatency = values[1] / 1'000; + + } +- else ++ else*/ ++#endif + { + offsetWithLatency.sampleOffset = GetSampleOffset() * 1'000; + offsetWithLatency.sourceLatency = 0; +diff --git a/src/Nazara/Graphics/DebugDrawPipelinePass.cpp b/src/Nazara/Graphics/DebugDrawPipelinePass.cpp +index 2eb17dddf..a0876d3e3 100644 +--- a/src/Nazara/Graphics/DebugDrawPipelinePass.cpp ++++ b/src/Nazara/Graphics/DebugDrawPipelinePass.cpp +@@ -44,8 +44,8 @@ namespace Nz + builder.SetScissor(viewport); + builder.SetViewport(viewport); + +- DebugDrawer& debugDrawer = m_pipeline.GetDebugDrawer(); +- debugDrawer.Draw(builder); ++ //DebugDrawer& debugDrawer = m_pipeline.GetDebugDrawer(); ++ //debugDrawer.Draw(builder); + }); + } + } +diff --git a/src/Nazara/Graphics/ForwardFramePipeline.cpp b/src/Nazara/Graphics/ForwardFramePipeline.cpp +index 2f5ffda80..2e4e1337e 100644 +--- a/src/Nazara/Graphics/ForwardFramePipeline.cpp ++++ b/src/Nazara/Graphics/ForwardFramePipeline.cpp +@@ -161,7 +161,7 @@ namespace Nz + auto& viewerData = *m_viewerPool.Allocate(viewerIndex); + viewerData.renderOrder = renderOrder; + viewerData.debugDrawPass = std::make_unique(*this, viewerInstance); +- viewerData.depthPrepass = std::make_unique(*this, m_elementRegistry, viewerInstance); ++ //viewerData.depthPrepass = std::make_unique(*this, m_elementRegistry, viewerInstance); + viewerData.forwardPass = std::make_unique(*this, m_elementRegistry, viewerInstance); + viewerData.viewer = viewerInstance; + viewerData.onTransferRequired.Connect(viewerInstance->GetViewerInstance().OnTransferRequired, [this](TransferInterface* transferInterface) +diff --git a/src/Nazara/Graphics/ForwardPipelinePass.cpp b/src/Nazara/Graphics/ForwardPipelinePass.cpp +index a860a6ddc..bd4f17cb8 100644 +--- a/src/Nazara/Graphics/ForwardPipelinePass.cpp ++++ b/src/Nazara/Graphics/ForwardPipelinePass.cpp +@@ -297,6 +297,11 @@ namespace Nz + elementRenderer.Render(viewerInstance, *m_elementRendererData[elementType], builder, elementCount, elements); + }); + ++ DebugDrawer& debugDrawer = m_pipeline.GetDebugDrawer(); ++ debugDrawer.Draw(builder); ++ ++ NazaraWarning("----"); ++ + m_rebuildCommandBuffer = false; + }); + } +diff --git a/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp b/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp +index 25d9b384e..a656d74d2 100644 +--- a/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp ++++ b/src/Nazara/OpenGLRenderer/OpenGLCommandBuffer.cpp +@@ -175,7 +175,14 @@ namespace Nz + { + const OpenGLFboFramebuffer& fboFramebuffer = static_cast(*command.framebuffer); + +- context->glDrawBuffers(GLsizei(colorBufferCount), fboDrawBuffers.data()); ++ // TODO: glDrawBuffers should be called only at FBO setup ++ if (colorBufferCount > 0) ++ context->glDrawBuffers(GLsizei(colorBufferCount), fboDrawBuffers.data()); ++ else ++ { ++ GLenum buffer = GL_NONE; ++ context->glDrawBuffers(1, &buffer); ++ } + + invalidateAttachments = NazaraStackVector(GLenum, colorBufferCount + 1); + +@@ -246,13 +253,13 @@ namespace Nz + assert(command.framebuffer->GetType() == FramebufferType::Window); + + // glDrawBuffers doesn't accept GL_BACK on OpenGL non-ES, and glDrawBuffer must be used instead +- if (context->glDrawBuffer) ++ /*if (context->GetParams().type != GL::ContextType::OpenGL_ES && context->glDrawBuffer) + context->glDrawBuffer(GL_BACK); + else + { + GLenum buffer = GL_BACK; + context->glDrawBuffers(1, &buffer); +- } ++ }*/ + + invalidateAttachments = NazaraStackVector(GLenum, 3); //< color + depth + stencil + +diff --git a/src/Nazara/OpenGLRenderer/Wrapper/Context.cpp b/src/Nazara/OpenGLRenderer/Wrapper/Context.cpp +index 478a904a1..355cf46ac 100644 +--- a/src/Nazara/OpenGLRenderer/Wrapper/Context.cpp ++++ b/src/Nazara/OpenGLRenderer/Wrapper/Context.cpp +@@ -22,6 +22,12 @@ namespace Nz::GL + + namespace + { ++ constexpr std::array s_functionNames = { ++#define NAZARA_OPENGLRENDERER_FUNC(name, sig) #name, ++ NAZARA_OPENGLRENDERER_FOREACH_GLES_FUNC(NAZARA_OPENGLRENDERER_FUNC, NAZARA_OPENGLRENDERER_FUNC) ++#undef NAZARA_OPENGLRENDERER_FUNC ++ }; ++ + template + struct GLWrapper; + +@@ -41,13 +47,13 @@ namespace Nz::GL + { + funcPtr(std::forward(args)...); + +- context->ProcessErrorStack(); ++ context->ProcessErrorStack(FuncIndex, std::forward(args)...); + } + else + { + Ret r = funcPtr(std::forward(args)...); + +- context->ProcessErrorStack(); ++ context->ProcessErrorStack(FuncIndex, std::forward(args)...); + + return r; + } +@@ -139,9 +145,14 @@ namespace Nz::GL + + GLenum Context::BindFramebuffer(GLuint fbo) const + { +- if (m_state.boundDrawFBO == fbo) ++#ifdef NAZARA_PLATFORM_WEB ++ constexpr bool isWeb = true; ++#else ++ constexpr bool isWeb = false; ++#endif ++ if (m_state.boundDrawFBO == fbo && !isWeb) + return GL_DRAW_FRAMEBUFFER; +- else if (m_state.boundReadFBO == fbo) ++ else if (m_state.boundReadFBO == fbo && !isWeb) + return GL_READ_FRAMEBUFFER; + else + { +@@ -163,7 +174,7 @@ namespace Nz::GL + #else + constexpr bool isWeb = false; + #endif +- if (currentFbo != fbo || isWeb); ++ if (currentFbo != fbo || isWeb) + { + if (!SetCurrentContext(this)) + throw std::runtime_error("failed to activate context"); +@@ -271,6 +282,9 @@ namespace Nz::GL + + void Context::BindVertexArray(GLuint vertexArray, bool force) const + { ++#ifdef NAZARA_PLATFORM_WEB ++ force = true; ++#endif + if (m_state.boundVertexArray != vertexArray || force) + { + if (!SetCurrentContext(this)) +@@ -355,7 +369,7 @@ namespace Nz::GL + } + + SymbolLoader loader(*this); +- loader.wrapErrorHandling = params.wrapErrorHandling; ++ //loader.wrapErrorHandling = params.wrapErrorHandling; + + try + { +@@ -594,6 +608,34 @@ namespace Nz::GL + return hasAnyError; + } + ++ template ++ bool Context::ProcessErrorStack(std::size_t funcIndex, Args... args) const ++ { ++ if (!ProcessErrorStack()) ++ return false; ++ ++ std::stringstream ss; ++ ss << s_functionNames[funcIndex] << "("; ++ if constexpr (sizeof...(args) > 0) ++ { ++ bool first = true; ++ auto PrintParam = [&](auto value) ++ { ++ if (!first) ++ ss << ", "; ++ ++ ss << +value; ++ first = false; ++ }; ++ ++ (PrintParam(args), ...); ++ } ++ ss << ")"; ++ NazaraDebug(ss.str()); ++ ++ return true; ++ } ++ + void Context::SetCurrentTextureUnit(UInt32 textureUnit) const + { + if (m_state.currentTextureUnit != textureUnit) +@@ -616,7 +658,7 @@ namespace Nz::GL + if (!SetCurrentContext(this)) + throw std::runtime_error("failed to activate context"); + +- glScissor(x, y, width, height); ++ //glScissor(x, y, width, height); + + m_state.scissorBox.x = x; + m_state.scissorBox.y = y; +diff --git a/src/Nazara/OpenGLRenderer/Wrapper/WGL/WGLLoader.cpp b/src/Nazara/OpenGLRenderer/Wrapper/WGL/WGLLoader.cpp +index eb0137a4d..d80bdd0a0 100644 +--- a/src/Nazara/OpenGLRenderer/Wrapper/WGL/WGLLoader.cpp ++++ b/src/Nazara/OpenGLRenderer/Wrapper/WGL/WGLLoader.cpp +@@ -52,11 +52,11 @@ namespace Nz::GL + ContextParams params; + // Favor OpenGL on desktop and OpenGL ES on mobile + std::array contextTypes = { +-#if defined(NAZARA_PLATFORM_DESKTOP) ++/*#if defined(NAZARA_PLATFORM_DESKTOP) + GL::ContextType::OpenGL, GL::ContextType::OpenGL_ES +-#else ++#else*/ + GL::ContextType::OpenGL_ES, GL::ContextType::OpenGL +-#endif ++//#endif + }; + + bool created = false; +diff --git a/xmake.lua b/xmake.lua +index ff6b6b31c..8b72ebaf1 100644 +--- a/xmake.lua ++++ b/xmake.lua +@@ -54,7 +54,17 @@ local modules = { + Deps = {"NazaraCore"}, + Packages = {"dr_wav", "frozen", "libflac", "libvorbis", "minimp3"}, + Custom = function () +- add_packages("openal-soft", { links = {} }) -- Don't link OpenAL (it will be loaded dynamically) ++ if is_plat("wasm") or has_config("link_openal") then ++ add_defines("NAZARA_AUDIO_OPENAL_LINK") ++ add_defines("AL_ALEXT_PROTOTYPES") ++ if is_plat("wasm") then ++ add_syslinks("openal") ++ else ++ add_packages("openal-soft") ++ end ++ else ++ add_packages("openal-soft", { links = {} }) ++ end + end + }, + Core = { +@@ -157,8 +167,8 @@ if not has_config("embed_rendererbackends") then + end + end + +-add_ldflags("-g -s NO_DISABLE_EXCEPTION_CATCHING -s ALLOW_MEMORY_GROWTH=1") +-add_cxflags("-g -s NO_DISABLE_EXCEPTION_CATCHING") ++add_ldflags("-g", "-sNO_DISABLE_EXCEPTION_CATCHING", "-sALLOW_MEMORY_GROWTH", "-sWASM_BIGINT") ++add_cxflags("-g", "-sNO_DISABLE_EXCEPTION_CATCHING", "-sERROR_ON_WASM_CHANGES_AFTER_LINK") + + NazaraModules = modules + +@@ -167,6 +177,7 @@ includes("xmake/**.lua") + option("compile_shaders", { description = "Compile nzsl shaders into an includable binary version", default = true }) + option("embed_rendererbackends", { description = "Embed renderer backend code into NazaraRenderer instead of loading them dynamically", default = false }) + option("embed_resources", { description = "Turn builtin resources into includable headers", default = true }) ++option("link_openal", { description = "Link OpenAL in the executable instead of dynamically loading it", default = false }) + option("override_runtime", { description = "Override vs runtime to MD in release and MDd in debug", default = true }) + option("usepch", { description = "Use precompiled headers to speedup compilation", default = false }) + option("unitybuild", { description = "Build the engine using unity build", default = false }) +@@ -174,15 +185,17 @@ option("unitybuild", { description = "Build the engine using unity build", defau + set_project("NazaraEngine") + set_xmakever("2.7.3") + +-add_requires("dr_wav", "entt 3.10.1", "fmt", "frozen", "kiwisolver", "minimp3", "ordered_map", "stb") ++add_requires("dr_wav", "entt 3.10.1", "fmt", "frozen", "libflac", "kiwisolver", "minimp3", "ordered_map", "stb") ++add_requires("libvorbis", { configs = { with_vorbisenc = false } }) + if not is_plat("wasm") then +- add_requires("chipmunk2d", "libsdl", "libflac", "efsw") ++ add_requires("chipmunk2d", "libsdl", "efsw") + add_requires("freetype", { configs = { bzip2 = true, png = true, woff2 = true, zlib = true, debug = is_mode("debug") } }) +- add_requires("libvorbis", { configs = { with_vorbisenc = false } }) + add_requires("openal-soft", { configs = { shared = true }}) + add_requires("newtondynamics3", { debug = is_plat("windows") and is_mode("debug") }) -- Newton doesn't like compiling in Debug on Linux + end + ++add_repositories("local-repo xmake-repo") ++ + add_repositories("nazara-engine-repo https://github.com/NazaraEngine/xmake-repo") + add_requires("nazarautils") + add_requires("nzsl", { debug = is_mode("debug"), configs = { with_symbols = not is_mode("release"), shared = not is_plat("wasm") } }) diff --git a/examples/DopplerEffect/main.cpp b/examples/DopplerEffect/main.cpp index 901521ac5..c7b3db34b 100644 --- a/examples/DopplerEffect/main.cpp +++ b/examples/DopplerEffect/main.cpp @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include #include #include @@ -66,14 +68,17 @@ int main() Nz::Vector3f pos = sound.GetPosition() + sound.GetVelocity() * clock.GetElapsedTime().AsSeconds(); sound.SetPosition(pos); - std::cout << "Sound position: " << pos << std::endl; + std::cout << "Sound position: " << pos << 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) + // 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) - clock.Restart(); - } + clock.Restart(); + } + }); + + // La boucle du programme (Pour déplacer le son) return 0; } diff --git a/examples/PlayMusic/main.cpp b/examples/PlayMusic/main.cpp index e52b10440..d6e0485fd 100644 --- a/examples/PlayMusic/main.cpp +++ b/examples/PlayMusic/main.cpp @@ -8,35 +8,49 @@ #include #include #include +#include #include #include #include int main() { - std::filesystem::path resourceDir = "assets/examples"; - if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir)) - resourceDir = "../.." / resourceDir; - - Nz::Modules audio; - - Nz::SoundStreamParams streamParams; - streamParams.forceMono = false; - - Nz::Music music; - if (!music.OpenFromFile(resourceDir / "Audio/file_example_MP3_700KB.mp3", streamParams)) + try { - std::cout << "Failed to load sound" << std::endl; + + std::filesystem::path resourceDir = "assets/examples"; + if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir)) + resourceDir = "../.." / resourceDir; + + Nz::Modules audio; + + 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(); - return EXIT_FAILURE; + + music.Play(); + + std::cout << "Playing sound..." << std::endl; + + Nz::Window window; + + Nz::Clock clock; + Nz::BasicMainloop(window, [&] { + }); + + return EXIT_SUCCESS; + } + catch (const std::exception& e) + { + std::cerr << e.what() << std::endl; } - - music.Play(); - - std::cout << "Playing sound..." << std::endl; - - while (music.IsPlaying()) - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - - return EXIT_SUCCESS; } diff --git a/examples/PlayMusic/xmake.lua b/examples/PlayMusic/xmake.lua index 946c770e3..56595b33e 100644 --- a/examples/PlayMusic/xmake.lua +++ b/examples/PlayMusic/xmake.lua @@ -1,3 +1,3 @@ target("PlayMusic") - add_deps("NazaraAudio") + add_deps("NazaraAudio", "NazaraUtility", "NazaraPlatform") add_files("main.cpp") diff --git a/examples/Showcase/main.cpp b/examples/Showcase/main.cpp index 0ae3fcebd..5f3a9183b 100644 --- a/examples/Showcase/main.cpp +++ b/examples/Showcase/main.cpp @@ -50,7 +50,7 @@ int main() Nz::Window& mainWindow = windowing.CreateWindow(Nz::VideoMode(1280, 720), windowTitle); auto& windowSwapchain = renderSystem.CreateSwapchain(mainWindow); - physSytem.GetPhysWorld().SetGravity({ 0.f, -9.81f, 0.f }); + //physSytem.GetPhysWorld().SetGravity({ 0.f, -9.81f, 0.f }); Nz::TextureParams texParams; texParams.renderDevice = device; @@ -516,6 +516,4 @@ int main() }); return app.Run(); - - return EXIT_SUCCESS; } diff --git a/examples/Showcase/xmake.lua b/examples/Showcase/xmake.lua index d6bf70e00..7b370308c 100644 --- a/examples/Showcase/xmake.lua +++ b/examples/Showcase/xmake.lua @@ -5,8 +5,12 @@ end target("Showcase") set_group("Examples") set_kind("binary") - add_deps("NazaraAudio", "NazaraGraphics", "NazaraPhysics2D", "NazaraPhysics3D", "NazaraWidgets") - add_deps("PluginAssimp", { links = {} }) + add_deps("NazaraAudio", "NazaraGraphics", "NazaraPhysics2D", "NazaraWidgets") + if has_config("embed_plugins") then + add_deps("PluginAssimp") + else + add_deps("PluginAssimp", { links = {} }) + end add_packages("entt") add_files("main.cpp") add_defines("NAZARA_ENTT") diff --git a/examples/WidgetDemo/main.cpp b/examples/WidgetDemo/main.cpp index 54a917dbd..58e8aadf1 100644 --- a/examples/WidgetDemo/main.cpp +++ b/examples/WidgetDemo/main.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include diff --git a/examples/WidgetDemo/xmake.lua b/examples/WidgetDemo/xmake.lua index 78083420a..4c4d4383a 100644 --- a/examples/WidgetDemo/xmake.lua +++ b/examples/WidgetDemo/xmake.lua @@ -1,5 +1,5 @@ target("WidgetDemo") - add_deps("NazaraGraphics", "NazaraPhysics3D", "NazaraWidgets") + add_deps("NazaraGraphics", "NazaraWidgets") add_packages("entt") add_files("main.cpp") add_defines("NAZARA_ENTT") diff --git a/include/Nazara/Core/PluginInterface.hpp b/include/Nazara/Core/PluginInterface.hpp index 0d4d06ffb..d4cadbf6a 100644 --- a/include/Nazara/Core/PluginInterface.hpp +++ b/include/Nazara/Core/PluginInterface.hpp @@ -9,6 +9,7 @@ #include #include +#include #include #ifdef NAZARA_COMPILER_MSVC @@ -37,6 +38,14 @@ namespace Nz PluginInterface& operator=(const PluginInterface&) = delete; PluginInterface& operator=(PluginInterface&&) = delete; }; + +#ifdef NAZARA_PLUGINS_STATIC + template + struct PluginProvider + { + static_assert(AlwaysFalse(), "unknown plugin"); + }; +#endif } #include diff --git a/include/Nazara/Core/PluginLoader.hpp b/include/Nazara/Core/PluginLoader.hpp index 51c38672e..85f5bac5f 100644 --- a/include/Nazara/Core/PluginLoader.hpp +++ b/include/Nazara/Core/PluginLoader.hpp @@ -29,7 +29,9 @@ namespace Nz void AddSearchDirectory(const std::filesystem::path& directoryPath); template Plugin Load(bool activate = true); +#ifndef NAZARA_PLUGINS_STATIC GenericPlugin Load(const std::filesystem::path& pluginPath, bool activate = true); +#endif void RemoveSearchDirectory(const std::filesystem::path& directoryPath); diff --git a/include/Nazara/Core/PluginLoader.inl b/include/Nazara/Core/PluginLoader.inl index b89ebb5ea..72a17c2d1 100644 --- a/include/Nazara/Core/PluginLoader.inl +++ b/include/Nazara/Core/PluginLoader.inl @@ -11,8 +11,16 @@ namespace Nz template Plugin PluginLoader::Load(bool activate) { +#ifdef NAZARA_PLUGINS_STATIC + std::unique_ptr pluginInterface = PluginProvider::Instantiate(); + if (activate && !pluginInterface->Activate()) + throw std::runtime_error("failed to activate plugin"); + + return Plugin({}, std::move(pluginInterface), activate); +#else GenericPlugin plugin = Load(Utf8Path(T::Filename), activate); return std::move(plugin).Cast(); +#endif } } diff --git a/include/Nazara/Utility.hpp b/include/Nazara/Utility.hpp index 4837a6618..8d4750284 100644 --- a/include/Nazara/Utility.hpp +++ b/include/Nazara/Utility.hpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include diff --git a/include/Nazara/Utility/Plugins/AssimpPlugin.hpp b/include/Nazara/Utility/Plugins/AssimpPlugin.hpp index f35415bbe..5c4f2da9a 100644 --- a/include/Nazara/Utility/Plugins/AssimpPlugin.hpp +++ b/include/Nazara/Utility/Plugins/AssimpPlugin.hpp @@ -31,6 +31,14 @@ namespace Nz AssimpPlugin& operator=(const AssimpPlugin&) = delete; AssimpPlugin& operator=(AssimpPlugin&&) = delete; }; + +#ifdef NAZARA_PLUGINS_STATIC + template<> + struct PluginProvider + { + static std::unique_ptr Instantiate(); + }; +#endif } #include diff --git a/plugins/Assimp/Plugin.cpp b/plugins/Assimp/Plugin.cpp index 81476d2c7..dc1d73414 100644 --- a/plugins/Assimp/Plugin.cpp +++ b/plugins/Assimp/Plugin.cpp @@ -939,6 +939,15 @@ namespace }; } +#ifdef NAZARA_PLUGINS_STATIC +namespace Nz +{ + std::unique_ptr PluginProvider::Instantiate() + { + return std::make_unique(); + } +} +#else extern "C" { NAZARA_EXPORT Nz::PluginInterface* PluginLoad() @@ -954,3 +963,4 @@ extern "C" return plugin.release(); } } +#endif \ No newline at end of file diff --git a/plugins/Assimp/xmake.lua b/plugins/Assimp/xmake.lua index f8829271b..6858d4361 100644 --- a/plugins/Assimp/xmake.lua +++ b/plugins/Assimp/xmake.lua @@ -4,7 +4,6 @@ if has_config("assimp") then add_requires("assimp v5.2.3") target("PluginAssimp") - set_kind("shared") set_group("Plugins") add_rpathdirs("$ORIGIN") diff --git a/plugins/FFmpeg/xmake.lua b/plugins/FFmpeg/xmake.lua index 5c113f1b2..947515d75 100644 --- a/plugins/FFmpeg/xmake.lua +++ b/plugins/FFmpeg/xmake.lua @@ -4,7 +4,6 @@ if has_config("ffmpeg") then add_requires("ffmpeg", { configs = { shared = true } }) target("PluginFFmpeg") - set_kind("shared") set_group("Plugins") add_rpathdirs("$ORIGIN") diff --git a/plugins/xmake.lua b/plugins/xmake.lua new file mode 100644 index 000000000..a8922dcb3 --- /dev/null +++ b/plugins/xmake.lua @@ -0,0 +1,7 @@ +if has_config("embed_plugins") then + set_kind("static") +else + set_kind("shared") +end + +includes("*/xmake.lua") \ No newline at end of file diff --git a/src/Nazara/Core/PluginLoader.cpp b/src/Nazara/Core/PluginLoader.cpp index d97f3ee20..dd3e77a6f 100644 --- a/src/Nazara/Core/PluginLoader.cpp +++ b/src/Nazara/Core/PluginLoader.cpp @@ -24,6 +24,7 @@ namespace Nz m_directories.push_back(std::filesystem::absolute(directoryPath)); } +#ifndef NAZARA_PLUGINS_STATIC GenericPlugin PluginLoader::Load(const std::filesystem::path& pluginPath, bool activate) { std::filesystem::path path = pluginPath; @@ -60,6 +61,7 @@ namespace Nz return GenericPlugin(std::move(library), std::move(pluginInterface), activate); } +#endif void PluginLoader::RemoveSearchDirectory(const std::filesystem::path& directoryPath) { diff --git a/src/Nazara/Graphics/Resources/Shaders/BasicMaterial.nzsl b/src/Nazara/Graphics/Resources/Shaders/BasicMaterial.nzsl index c888af92c..c56ddb797 100644 --- a/src/Nazara/Graphics/Resources/Shaders/BasicMaterial.nzsl +++ b/src/Nazara/Graphics/Resources/Shaders/BasicMaterial.nzsl @@ -80,7 +80,7 @@ fn main(input: FragIn) -> FragOut let color = settings.BaseColor; const if (HasUV) - color *= TextureOverlay.Sample(input.uv); + color *= TextureOverlay.Sample(input.uv).rrra; const if (HasColor) color *= input.color; diff --git a/src/Nazara/Graphics/Resources/Shaders/PhongMaterial.nzsl b/src/Nazara/Graphics/Resources/Shaders/PhongMaterial.nzsl index 37d775b37..968d0d223 100644 --- a/src/Nazara/Graphics/Resources/Shaders/PhongMaterial.nzsl +++ b/src/Nazara/Graphics/Resources/Shaders/PhongMaterial.nzsl @@ -129,7 +129,7 @@ fn main(input: VertToFrag) -> FragOut let color = settings.BaseColor; const if (HasUV) - color *= TextureOverlay.Sample(input.uv); + color *= TextureOverlay.Sample(input.uv).rrra; const if (HasColor) color *= input.color; diff --git a/src/Nazara/Graphics/Resources/Shaders/PhysicallyBasedMaterial.nzsl b/src/Nazara/Graphics/Resources/Shaders/PhysicallyBasedMaterial.nzsl index 1ea78fbf6..d95aef91c 100644 --- a/src/Nazara/Graphics/Resources/Shaders/PhysicallyBasedMaterial.nzsl +++ b/src/Nazara/Graphics/Resources/Shaders/PhysicallyBasedMaterial.nzsl @@ -115,7 +115,7 @@ fn main(input: VertToFrag) -> FragOut let color = settings.BaseColor; const if (HasUV) - color *= TextureOverlay.Sample(input.uv); + color *= TextureOverlay.Sample(input.uv).rrra; const if (HasColor) color *= input.color; diff --git a/src/Nazara/Utility/Formats/STBLoader.cpp b/src/Nazara/Utility/Formats/STBLoader.cpp index b747edacc..54e0e50c8 100644 --- a/src/Nazara/Utility/Formats/STBLoader.cpp +++ b/src/Nazara/Utility/Formats/STBLoader.cpp @@ -10,13 +10,16 @@ #include #include #include + +#define STB_IMAGE_STATIC #define STB_IMAGE_IMPLEMENTATION #include + #include namespace Nz { - namespace + namespace NAZARA_ANONYMOUS_NAMESPACE { int StbiEof(void* userdata) { @@ -98,6 +101,8 @@ namespace Nz { ImageLoader::Entry GetImageLoader_STB() { + NAZARA_USE_ANONYMOUS_NAMESPACE + ImageLoader::Entry loaderEntry; loaderEntry.extensionSupport = IsSTBSupported; loaderEntry.streamLoader = LoadSTB; diff --git a/tests/GraphicsTest/main.cpp b/tests/GraphicsTest/main.cpp index 220ab6691..19592a1d7 100644 --- a/tests/GraphicsTest/main.cpp +++ b/tests/GraphicsTest/main.cpp @@ -17,11 +17,12 @@ int main() resourceDir = "../.." / resourceDir; Nz::Renderer::Config rendererConfig; - std::cout << "Run using Vulkan? (y/n)" << std::endl; + rendererConfig.preferredAPI = Nz::RenderAPI::OpenGL; + /*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;*/ Nz::Modules nazara(rendererConfig); @@ -29,7 +30,7 @@ int main() meshParams.center = true; meshParams.vertexRotation = Nz::EulerAnglesf(0.f, -90.f, 0.f); meshParams.vertexScale = Nz::Vector3f(0.002f); - meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_Normal_UV_Tangent); + meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout::XYZ_Normal_UV); std::shared_ptr device = Nz::Graphics::Instance()->GetRenderDevice(); @@ -219,6 +220,14 @@ int main() framePipeline.GetDebugDrawer().DrawLine(Nz::Vector3f::Zero(), Nz::Vector3f::Forward(), Nz::Color::Blue()); + for (const Nz::WorldInstancePtr& worldInstance : { modelInstance, modelInstance2 }) + { + Nz::Boxf aabb = model.GetAABB(); + aabb.Transform(worldInstance->GetWorldMatrix()); + + framePipeline.GetDebugDrawer().DrawBox(aabb, Nz::Color::Green); + } + viewerInstance.UpdateViewMatrix(Nz::Matrix4f::TransformInverse(viewerPos, camAngles)); viewerInstance.UpdateEyePosition(viewerPos); diff --git a/wasm.config b/wasm.config new file mode 100644 index 000000000..faeff1c3c --- /dev/null +++ b/wasm.config @@ -0,0 +1,29 @@ +{ + arch = "wasm32", + assimp = true, + buildir = "build", + ccache = false, + clean = true, + compile_shaders = true, + embed_plugins = true, + embed_rendererbackends = true, + embed_resources = true, + examples = true, + ffmpeg = false, + host = "windows", + kind = "static", + link_openal = true, + mingw = [[C:\Projets\Perso\Softs\mingw64-11.2]], + mode = "debug", + ndk_stdcxx = true, + network = "public", + override_runtime = true, + plat = "wasm", + proxy_pac = "pac.lua", + qt = "C:/Projets/Perso/Libs/Qt", + shadernodes = false, + tests = false, + theme = "default", + unitybuild = false, + usepch = false +} \ No newline at end of file diff --git a/xmake-repo/packages/a/assimp/patches/5.0.1/fix-mingw.patch b/xmake-repo/packages/a/assimp/patches/5.0.1/fix-mingw.patch new file mode 100644 index 000000000..6ccff6c65 --- /dev/null +++ b/xmake-repo/packages/a/assimp/patches/5.0.1/fix-mingw.patch @@ -0,0 +1,56 @@ +diff --git a/include/assimp/defs.h b/include/assimp/defs.h +index 05a5e3fd4..8b90edfca 100644 +--- a/include/assimp/defs.h ++++ b/include/assimp/defs.h +@@ -126,7 +126,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * GENBOUNDINGBOXES */ + ////////////////////////////////////////////////////////////////////////// + +-#ifdef _MSC_VER ++#ifdef _WIN32 + # undef ASSIMP_API + + ////////////////////////////////////////////////////////////////////////// +@@ -135,7 +135,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + # ifdef ASSIMP_BUILD_DLL_EXPORT + # define ASSIMP_API __declspec(dllexport) + # define ASSIMP_API_WINONLY __declspec(dllexport) +-# pragma warning (disable : 4251) ++# ifdef _MSC_VER ++# pragma warning (disable : 4251) ++# endif + + ////////////////////////////////////////////////////////////////////////// + /* Define 'ASSIMP_DLL' before including Assimp to link to ASSIMP in +@@ -149,6 +151,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + # define ASSIMP_API_WINONLY + # endif + ++# ifdef _MSC_VER ++ + /* Force the compiler to inline a function, if possible + */ + # define AI_FORCE_INLINE __forceinline +@@ -157,6 +161,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * to skip dead paths (e.g. after an assertion evaluated to false). */ + # define AI_WONT_RETURN __declspec(noreturn) + ++# else ++ ++# define AI_FORCE_INLINE inline ++# define AI_WONT_RETURN ++ ++# endif ++ + #elif defined(SWIG) + + /* Do nothing, the relevant defines are all in AssimpSwigPort.i */ +@@ -170,7 +181,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + # define AI_FORCE_INLINE inline + #endif // (defined _MSC_VER) + +-#ifdef __GNUC__ ++#if defined(__GNUC__) || defined(__MINGW32__) + # define AI_WONT_RETURN_SUFFIX __attribute__((noreturn)) + #else + # define AI_WONT_RETURN_SUFFIX diff --git a/xmake-repo/packages/a/assimp/patches/5.2.1/fix_zlib_filefunc_def.patch b/xmake-repo/packages/a/assimp/patches/5.2.1/fix_zlib_filefunc_def.patch new file mode 100644 index 000000000..3584d1930 --- /dev/null +++ b/xmake-repo/packages/a/assimp/patches/5.2.1/fix_zlib_filefunc_def.patch @@ -0,0 +1,14 @@ +diff --git a/code/Common/ZipArchiveIOSystem.cpp b/code/Common/ZipArchiveIOSystem.cpp +index e0c9883d2..c748b3255 100644 +--- a/code/Common/ZipArchiveIOSystem.cpp ++++ b/code/Common/ZipArchiveIOSystem.cpp +@@ -196,7 +196,9 @@ zlib_filefunc_def IOSystem2Unzip::get(IOSystem *pIOHandler) { + zlib_filefunc_def mapping; + + mapping.zopen_file = (open_file_func)open; ++#ifdef ZOPENDISK64 + mapping.zopendisk_file = (opendisk_file_func)opendisk; ++#endif + mapping.zread_file = (read_file_func)read; + mapping.zwrite_file = (write_file_func)write; + mapping.ztell_file = (tell_file_func)tell; diff --git a/xmake-repo/packages/a/assimp/patches/5.2.3/cmake_static_crt.patch b/xmake-repo/packages/a/assimp/patches/5.2.3/cmake_static_crt.patch new file mode 100644 index 000000000..e6abe2640 --- /dev/null +++ b/xmake-repo/packages/a/assimp/patches/5.2.3/cmake_static_crt.patch @@ -0,0 +1,27 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index f48391edf..66f7b726d 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -155,22 +155,6 @@ IF (WIN32) + # "VCRUNTIME140.dll not found. Try reinstalling the app.", but give users + # a choice to opt for the shared runtime if they want. + option(USE_STATIC_CRT "Link against the static runtime libraries." OFF) +- +- # The CMAKE_CXX_FLAGS vars can be overriden by some Visual Studio generators, so we use an alternative +- # global method here: +- if (${USE_STATIC_CRT}) +- add_compile_options( +- $<$:/MT> +- $<$:/MTd> +- $<$:/MT> +- ) +- else() +- add_compile_options( +- $<$:/MD> +- $<$:/MDd> +- $<$:/MD> +- ) +- endif() + ENDIF() + ENDIF() + diff --git a/xmake-repo/packages/a/assimp/patches/5.2.4/fix_x86_windows_build.patch b/xmake-repo/packages/a/assimp/patches/5.2.4/fix_x86_windows_build.patch new file mode 100644 index 000000000..e7ca170e2 --- /dev/null +++ b/xmake-repo/packages/a/assimp/patches/5.2.4/fix_x86_windows_build.patch @@ -0,0 +1,22 @@ +diff --git a/code/Common/DefaultIOStream.cpp b/code/Common/DefaultIOStream.cpp +index e30f26acd3..17fc44f9a2 100644 +--- a/code/Common/DefaultIOStream.cpp ++++ b/code/Common/DefaultIOStream.cpp +@@ -63,7 +63,7 @@ inline int select_fseek(FILE *file, int64_t offset, int origin) { + + + +-#if defined _WIN64 && (!defined __GNUC__ || __MSVCRT_VERSION__ >= 0x0601) ++#if defined _WIN32 && (!defined __GNUC__ || __MSVCRT_VERSION__ >= 0x0601) + template <> + inline size_t select_ftell<8>(FILE *file) { + return (size_t)::_ftelli64(file); +@@ -149,7 +149,7 @@ size_t DefaultIOStream::FileSize() const { + // + // See here for details: + // https://www.securecoding.cert.org/confluence/display/seccode/FIO19-C.+Do+not+use+fseek()+and+ftell()+to+compute+the+size+of+a+regular+file +-#if defined _WIN64 && (!defined __GNUC__ || __MSVCRT_VERSION__ >= 0x0601) ++#if defined _WIN32 && (!defined __GNUC__ || __MSVCRT_VERSION__ >= 0x0601) + struct __stat64 fileStat; + //using fileno + fstat avoids having to handle the filename + int err = _fstat64(_fileno(mFile), &fileStat); diff --git a/xmake-repo/packages/a/assimp/xmake.lua b/xmake-repo/packages/a/assimp/xmake.lua new file mode 100644 index 000000000..138551d31 --- /dev/null +++ b/xmake-repo/packages/a/assimp/xmake.lua @@ -0,0 +1,120 @@ +package("assimp") + + set_homepage("https://assimp.org") + set_description("Portable Open-Source library to import various well-known 3D model formats in a uniform manner") + set_license("BSD-3-Clause") + + set_urls("https://github.com/assimp/assimp/archive/$(version).zip", + "https://github.com/assimp/assimp.git") + add_versions("v5.2.5", "5384877d53be7b5bbf50c26ab3f054bec91b3df8614372dcd7240f44f61c509b") + add_versions("v5.2.4", "713e9aa035ae019e5f3f0de1605de308d63538897249a2ba3a2d7d40036ad2b1") + add_versions("v5.2.3", "9667cfc8ddabd5dd5e83f3aebb99dbf232fce99f17b9fe59540dccbb5e347393") + add_versions("v5.2.2", "7b833182b89917b3c6e8aee6432b74870fb71f432cc34aec5f5411bd6b56c1b5") + add_versions("v5.2.1", "636fe5c2cfe925b559b5d89e53a42412a2d2ab49a0712b7d655d1b84c51ed504") + add_versions("v5.1.4", "59a00cf72fa5ceff960460677e2b37be5cd1041e85bae9c02828c27ade7e4160") + add_versions("v5.0.1", "d10542c95e3e05dece4d97bb273eba2dfeeedb37a78fb3417fd4d5e94d879192") + + add_patches("v5.0.1", path.join(os.scriptdir(), "patches", "5.0.1", "fix-mingw.patch"), "a3375489e2bbb2dd97f59be7dd84e005e7e9c628b4395d7022a6187ca66b5abb") + add_patches("v5.2.1", path.join(os.scriptdir(), "patches", "5.2.1", "fix_zlib_filefunc_def.patch"), "a9f8a9aa1975888ea751b80c8268296dee901288011eeb1addf518eac40b71b1") + add_patches("v5.2.2", path.join(os.scriptdir(), "patches", "5.2.1", "fix_zlib_filefunc_def.patch"), "a9f8a9aa1975888ea751b80c8268296dee901288011eeb1addf518eac40b71b1") + add_patches("v5.2.3", path.join(os.scriptdir(), "patches", "5.2.1", "fix_zlib_filefunc_def.patch"), "a9f8a9aa1975888ea751b80c8268296dee901288011eeb1addf518eac40b71b1") + add_patches("v5.2.3", path.join(os.scriptdir(), "patches", "5.2.3", "cmake_static_crt.patch"), "3872a69976055bed9e40814e89a24a3420692885b50e9f9438036e8d809aafb4") + add_patches("v5.2.4", path.join(os.scriptdir(), "patches", "5.2.4", "fix_x86_windows_build.patch"), "becb4039c220678cf1e888e3479f8e68d1964c49d58f14c5d247c86b4a5c3293") + + if not is_host("windows") then + add_extsources("pkgconfig::assimp") + end + + if is_plat("mingw") and is_subhost("msys") then + add_extsources("pacman::assimp") + elseif is_plat("linux") then + add_extsources("pacman::assimp", "apt::libassimp-dev") + elseif is_plat("macosx") then + add_extsources("brew::assimp") + end + + add_configs("build_tools", {description = "Build the supplementary tools for Assimp.", default = false, type = "boolean"}) + add_configs("double_precision", {description = "Enable double precision processing.", default = false, type = "boolean"}) + add_configs("no_export", {description = "Disable Assimp's export functionality (reduces library size).", default = false, type = "boolean"}) + add_configs("android_jniiosysystem", {description = "Enable Android JNI IOSystem support.", default = false, type = "boolean"}) + add_configs("asan", {description = "Enable AddressSanitizer.", default = false, type = "boolean"}) + add_configs("ubsan", {description = "Enable Undefined Behavior sanitizer.", default = false, type = "boolean"}) + + add_deps("cmake", "zlib") + + if is_plat("windows") then + add_syslinks("advapi32") + end + + on_load(function (package) + if not package:gitref() and package:version():le("5.1.0") then + package:add("deps", "irrxml") + end + if package:is_plat("linux", "macosx") and package:config("shared") then + package:add("links", "assimp") + end + end) + + on_install("windows", "linux", "macosx", "mingw", "wasm", function (package) + local configs = {"-DASSIMP_BUILD_SAMPLES=OFF", + "-DASSIMP_BUILD_TESTS=OFF", + "-DASSIMP_BUILD_DOCS=OFF", + "-DASSIMP_BUILD_FRAMEWORK=OFF", + "-DASSIMP_INSTALL_PDB=ON", + "-DASSIMP_INJECT_DEBUG_POSTFIX=ON", + "-DASSIMP_BUILD_ZLIB=ON", + "-DSYSTEM_IRRXML=ON", + "-DASSIMP_WARNINGS_AS_ERRORS=OFF"} + table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release")) + + local function add_config_arg(config_name, cmake_name) + table.insert(configs, "-D" .. cmake_name .. "=" .. (package:config(config_name) and "ON" or "OFF")) + end + add_config_arg("shared", "BUILD_SHARED_LIBS") + add_config_arg("double_precision", "ASSIMP_DOUBLE_PRECISION") + add_config_arg("no_export", "ASSIMP_NO_EXPORT") + add_config_arg("asan", "ASSIMP_ASAN") + add_config_arg("ubsan", "ASSIMP_UBSAN") + + if package:is_plat("android") then + add_config_arg("android_jniiosysystem", "ASSIMP_ANDROID_JNIIOSYSTEM") + end + if package:is_plat("windows", "linux", "macosx", "mingw") then + add_config_arg("build_tools", "ASSIMP_BUILD_ASSIMP_TOOLS") + else + table.insert(configs, "-DASSIMP_BUILD_ASSIMP_TOOLS=OFF") + end + + if not package:gitref() and package:version():lt("v5.2.4") then + -- ASSIMP_WARNINGS_AS_ERRORS is not supported before v5.2.4 + if package:is_plat("windows") then + io.replace("code/CMakeLists.txt", "TARGET_COMPILE_OPTIONS(assimp PRIVATE /W4 /WX)", "", {plain = true}) + else + io.replace("code/CMakeLists.txt", "TARGET_COMPILE_OPTIONS(assimp PRIVATE -Werror)", "", {plain = true}) + end + end + if package:is_plat("mingw") and package:version():lt("v5.1.5") then + -- CMAKE_COMPILER_IS_MINGW has been removed: https://github.com/assimp/assimp/pull/4311 + io.replace("CMakeLists.txt", "CMAKE_COMPILER_IS_MINGW", "MINGW", {plain = true}) + end + + import("package.tools.cmake").install(package, configs) + + -- copy pdb + if package:is_plat("windows") then + if package:config("shared") then + os.trycp(path.join(package:buildir(), "bin", "**.pdb"), package:installdir("bin")) + else + os.trycp(path.join(package:buildir(), "lib", "**.pdb"), package:installdir("lib")) + end + end + end) + + on_test(function (package) + assert(package:check_cxxsnippets({test = [[ + #include + void test() { + Assimp::Importer importer; + } + ]]}, {configs = {languages = "c++11"}, includes = "assimp/Importer.hpp"})) + end) diff --git a/xmake-repo/packages/b/bzip2/port/xmake.lua b/xmake-repo/packages/b/bzip2/port/xmake.lua new file mode 100644 index 000000000..918275d52 --- /dev/null +++ b/xmake-repo/packages/b/bzip2/port/xmake.lua @@ -0,0 +1,64 @@ +add_rules("mode.debug", "mode.release") + +option("enable_tools") + set_default(false) + set_showmenu(true) + +target("bz2") + set_kind("$(kind)") + set_languages("c89") + add_headerfiles("bzlib.h") + add_files("blocksort.c") + add_files("bzlib.c") + add_files("compress.c") + add_files("crctable.c") + add_files("decompress.c") + add_files("huffman.c") + add_files("randtable.c") + if is_plat("windows") and is_kind("shared") then + set_filename("libbz2.dll") + add_files("libbz2.def") + end + if is_plat("wasm") then + add_defines("BZ_STRICT_ANSI") + end + +if has_config("enable_tools") then + +target("bzip2") + set_kind("binary") + add_deps("bz2") + add_files("bzip2.c") + + after_install(function (target) + -- copy/link additional executables/scripts (behavior is altered by checking the program name) + if target:is_plat("windows", "mingw") then + local binarydir = path.join(target:installdir(), "bin") + os.vcp(path.join(binarydir, "bzip2.exe"), path.join(binarydir, "bzcat.exe")) + os.vcp(path.join(binarydir, "bzip2.exe"), path.join(binarydir, "bunzip2.exe")) + else + local binarydir = path.join(target:installdir(), "bin") + os.ln(path.join(binarydir, "bzip2"), path.join(binarydir, "bzcat")) + os.ln(path.join(binarydir, "bzip2"), path.join(binarydir, "bunzip2")) + + -- copy shell scripts + os.vcp("bzdiff", binarydir) + os.vcp("bzgrep", binarydir) + os.vcp("bzmore", binarydir) + + -- and renamed copies + os.ln(path.join(binarydir, "bzdiff"), path.join(binarydir, "bzcmp")) + + os.ln(path.join(binarydir, "bzgrep"), path.join(binarydir, "bzegrep")) + os.ln(path.join(binarydir, "bzgrep"), path.join(binarydir, "bzfgrep")) + + os.ln(path.join(binarydir, "bzmore"), path.join(binarydir, "bzless")) + end + end) + +target("bzip2recover") + set_kind("binary") + add_deps("bz2") + add_files("bzip2recover.c") + +end diff --git a/xmake-repo/packages/b/bzip2/xmake.lua b/xmake-repo/packages/b/bzip2/xmake.lua new file mode 100644 index 000000000..25b9cecce --- /dev/null +++ b/xmake-repo/packages/b/bzip2/xmake.lua @@ -0,0 +1,36 @@ +package("bzip2") + + set_homepage("https://sourceware.org/bzip2/") + set_description("Freely available, patent free, high-quality data compressor.") + + add_urls("https://sourceware.org/pub/bzip2/bzip2-$(version).tar.gz") + add_versions("1.0.8", "ab5a03176ee106d3f0fa90e381da478ddae405918153cca248e682cd0c4a2269") + + if is_plat("mingw") and is_subhost("msys") then + add_extsources("pacman::bzip2") + elseif is_plat("linux") then + add_extsources("pacman::bzip2", "apt::libbz2-dev") + elseif is_plat("macosx") then + add_extsources("brew::bzip2") + end + + on_install("linux", "macosx", "windows", "android", "iphoneos", "cross", "bsd", "mingw", "wasm", function (package) + local configs = {} + if not package:is_plat("cross", "iphoneos", "android", "wasm") then + configs.enable_tools = true + package:addenv("PATH", "bin") + end + + os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua") + import("package.tools.xmake").install(package, configs) + end) + + on_test(function (package) + if not package:is_plat("cross", "iphoneos", "android", "wasm") then + os.vrun("bunzip2 --help") + os.vrun("bzcat --help") + os.vrun("bzip2 --help") + end + + assert(package:has_cfuncs("BZ2_bzCompressInit", {includes = "bzlib.h"})) + end) diff --git a/xmake-repo/packages/l/libpng/xmake.lua b/xmake-repo/packages/l/libpng/xmake.lua new file mode 100644 index 000000000..953643dd4 --- /dev/null +++ b/xmake-repo/packages/l/libpng/xmake.lua @@ -0,0 +1,100 @@ +package("libpng") + + set_homepage("http://www.libpng.org/pub/png/libpng.html") + set_description("The official PNG reference library") + set_license("libpng-2.0") + + set_urls("https://github.com/glennrp/libpng/archive/$(version).zip", + "https://github.com/glennrp/libpng.git") + add_versions("v1.6.37", "c2c50c13a727af73ecd3fc0167d78592cf5e0bca9611058ca414b6493339c784") + add_versions("v1.6.36", "6274d3f761cc80f7f6e2cde6c07bed10c00bc4ddd24c4f86e25eb51affa1664d") + add_versions("v1.6.35", "3d22d46c566b1761a0e15ea397589b3a5f36ac09b7c785382e6470156c04247f") + add_versions("v1.6.34", "7ffa5eb8f9f3ed23cf107042e5fec28699718916668bbce48b968600475208d3") + + add_deps("zlib") + + if is_plat("linux") then + add_syslinks("m") + end + + if is_plat("mingw") and is_subhost("msys") then + add_extsources("pacman::libpng") + elseif is_plat("linux") then + add_extsources("pacman::libpng", "apt::libpng-dev") + elseif is_plat("macosx") then + add_extsources("brew::libpng") + end + + on_install("windows", "mingw", "android", "iphoneos", "cross", "bsd", "wasm", function (package) + io.writefile("xmake.lua", [[ + add_rules("mode.debug", "mode.release") + add_requires("zlib") + target("png") + set_kind("$(kind)") + add_files("*.c|example.c|pngtest.c") + if is_arch("x86", "x64", "i386", "x86_64") then + add_files("intel/*.c") + add_defines("PNG_INTEL_SSE_OPT=1") + add_vectorexts("sse", "sse2") + elseif is_arch("arm.*") then + add_files("arm/*.c") + if is_plat("windows") then + add_defines("PNG_ARM_NEON_OPT=1") + add_defines("PNG_ARM_NEON_IMPLEMENTATION=1") + else + add_files("arm/*.S") + add_defines("PNG_ARM_NEON_OPT=2") + end + elseif is_arch("mips.*") then + add_files("mips/*.c") + add_defines("PNG_MIPS_MSA_OPT=2") + elseif is_arch("ppc.*") then + add_files("powerpc/*.c") + add_defines("PNG_POWERPC_VSX_OPT=2") + end + add_headerfiles("*.h") + add_packages("zlib") + if is_kind("shared") and is_plat("windows") then + add_defines("PNG_BUILD_DLL") + end + ]]) + local configs = {} + if package:config("shared") then + configs.kind = "shared" + elseif not package:is_plat("windows", "mingw") and package:config("pic") ~= false then + configs.cxflags = "-fPIC" + end + if package:is_plat("android") and package:is_arch("armeabi-v7a") then + io.replace("arm/filter_neon.S", ".func", ".hidden", {plain = true}) + io.replace("arm/filter_neon.S", ".endfunc", "", {plain = true}) + end + os.cp("scripts/pnglibconf.h.prebuilt", "pnglibconf.h") + import("package.tools.xmake").install(package, configs) + end) + + on_install("macosx", "linux", function (package) + local configs = {} + table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no")) + table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes")) + if package:config("pic") ~= false then + table.insert(configs, "--with-pic") + end + local cppflags = {} + local ldflags = {} + for _, dep in ipairs(package:orderdeps()) do + local fetchinfo = dep:fetch() + if fetchinfo then + for _, includedir in ipairs(fetchinfo.includedirs or fetchinfo.sysincludedirs) do + table.insert(cppflags, "-I" .. includedir) + end + for _, linkdir in ipairs(fetchinfo.linkdirs) do + table.insert(ldflags, "-L" .. linkdir) + end + end + end + import("package.tools.autoconf").install(package, configs, {cppflags = cppflags, ldflags = ldflags}) + end) + + on_test(function (package) + assert(package:has_cfuncs("png_create_read_struct", {includes = "png.h"})) + end) diff --git a/xmake-repo/packages/l/libsdl/xmake.lua b/xmake-repo/packages/l/libsdl/xmake.lua new file mode 100644 index 000000000..2518843bd --- /dev/null +++ b/xmake-repo/packages/l/libsdl/xmake.lua @@ -0,0 +1,171 @@ +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("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") + + if is_plat("macosx") then + add_frameworks("OpenGL", "CoreVideo", "CoreAudio", "AudioToolbox", "Carbon", "CoreGraphics", "ForceFeedback", "Metal", "AppKit", "IOKit", "CoreFoundation", "Foundation") + add_syslinks("iconv") + elseif is_plat("linux", "bsd") then + if is_plat("bsd") then + add_deps("libusb") + add_syslinks("usbhid") + end + add_syslinks("pthread", "dl") + elseif is_plat("windows", "mingw") then + add_syslinks("gdi32", "user32", "winmm", "shell32") + end + 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"}) + end + + on_load(function (package) + if package.components then + if package:config("use_sdlmain") then + package:add("components", "main") + end + package:add("components", "lib") + else + if package:config("use_sdlmain") then + package:add("links", "SDL2main", "SDL2") + package:add("defines", "SDL_MAIN_HANDLED") + else + package:add("links", "SDL2") + end + end + if package:is_plat("linux") and package:config("with_x") then + package:add("deps", "libxext", {private = true}) + end + if package:is_plat("macosx") and package:version():ge("2.0.14") then + package:add("frameworks", "CoreHaptics", "GameController") + end + end) + + on_component = on_component or function() end + on_component("main", function (package, component) + component:add("links", "SDL2main") + component:add("defines", "SDL_MAIN_HANDLED") + component:add("deps", "lib") + end) + + on_component("main", function (package, component) + component:add("links", "SDL2") + 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, "-DLIBTYPE=" .. (package:config("shared") and "SHARED" or "STATIC")) + local opt + if package:is_plat("linux") then + local cflags = {} + opt = opt or {} + opt.cflags = cflags + 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.join2(cflags, "-I" .. includedir) + end + end + end + end + elseif package:is_plat("bsd") then + opt = opt or {} + opt.packagedeps = "libusb" + end + import("package.tools.cmake").install(package, configs) + 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 95fd3916f..4822f6497 100644 --- a/xmake.lua +++ b/xmake.lua @@ -74,6 +74,10 @@ local modules = { -- NazaraMath is header-only, make it part of the core project add_headerfiles("include/(Nazara/Math/**.hpp)", "include/(Nazara/Math/**.inl)") + if has_config("embed_plugins") then + add_defines("NAZARA_PLUGINS_STATIC", { public = true }) + end + if is_plat("windows", "mingw") then add_syslinks("ole32") elseif is_plat("linux") then @@ -131,8 +135,8 @@ local modules = { add_defines("SDL_VIDEO_DRIVER_COCOA=1") add_packages("libx11", { links = {} }) -- we only need X11 headers elseif is_plat("wasm") then - add_cxflags("-s USE_SDL=2") - add_ldflags("-s USE_SDL=2", { public = true }) + add_cxflags("-sUSE_SDL=2") + add_ldflags("-sUSE_SDL=2", { public = true }) end end }, @@ -151,13 +155,7 @@ local modules = { }, Utility = { Deps = {"NazaraCore"}, - Packages = {"entt", "freetype", "frozen", "ordered_map", "stb"}, - Custom = function() - if is_plat("wasm") then - add_cxflags("-s USE_FREETYPE=1") - add_ldflags("-s USE_FREETYPE=1", { public = true }) - end - end + Packages = {"entt", "freetype", "frozen", "ordered_map", "stb"} }, Widgets = { Deps = {"NazaraGraphics"}, @@ -183,6 +181,7 @@ includes("xmake/**.lua") option("compile_shaders", { description = "Compile nzsl shaders into an includable binary version", default = true }) option("embed_rendererbackends", { description = "Embed renderer backend code into NazaraRenderer instead of loading them dynamically", default = false }) option("embed_resources", { description = "Turn builtin resources into includable headers", default = true }) +option("embed_plugins", { description = "Embed enabled plugins code as static libraries", default = false }) option("link_openal", { description = "Link OpenAL in the executable instead of dynamically loading it", default = false }) option("override_runtime", { description = "Override vs runtime to MD in release and MDd in debug", default = true }) option("usepch", { description = "Use precompiled headers to speedup compilation", default = false }) @@ -192,13 +191,16 @@ set_project("NazaraEngine") set_xmakever("2.7.3") add_requires("chipmunk2d", "dr_wav", "entt 3.10.1", "fmt", "frozen", "kiwisolver", "libflac", "minimp3", "ordered_map", "stb") +add_requires("freetype", { configs = { bzip2 = true, png = true, woff2 = true, zlib = true, debug = is_mode("debug") } }) add_requires("libvorbis", { configs = { with_vorbisenc = false } }) if is_plat("wasm") then -- Enable some flags for emscripten - add_cxflags("-g", "-sNO_DISABLE_EXCEPTION_CATCHING") - add_ldflags("-g", "-sNO_DISABLE_EXCEPTION_CATCHING", "-sALLOW_MEMORY_GROWTH", "-sWASM_BIGINT") - add_ldflags("-sERROR_ON_WASM_CHANGES_AFTER_LINK", { force = true }) + add_cxflags("-sNO_DISABLE_EXCEPTION_CATCHING") + add_ldflags("-sNO_DISABLE_EXCEPTION_CATCHING", "-sALLOW_MEMORY_GROWTH", "-sWASM_BIGINT") + if is_mode("debug") then + add_ldflags("-sERROR_ON_WASM_CHANGES_AFTER_LINK", { force = true }) + end -- we can't use wasm nzsl to compile shaders if has_config("compile_shaders") then @@ -207,7 +209,6 @@ if is_plat("wasm") then else -- these libraries have ports in emscripten add_requires("libsdl") - add_requires("freetype", { configs = { bzip2 = true, png = true, woff2 = true, zlib = true, debug = is_mode("debug") } }) add_requires("openal-soft", { configs = { shared = true }}) -- these libraries aren't supported on emscripten @@ -215,6 +216,7 @@ else add_requires("newtondynamics3", { debug = is_plat("windows") and is_mode("debug") }) -- Newton doesn't like compiling in Debug on Linux end +add_repositories("local-repo xmake-repo") add_repositories("nazara-engine-repo https://github.com/NazaraEngine/xmake-repo") add_requires("nazarautils") add_requires("nzsl", { debug = is_mode("debug"), configs = { with_symbols = not is_mode("release"), shared = not is_plat("wasm") } }) @@ -254,15 +256,22 @@ elseif is_mode("releasedbg", "release") then add_vectorexts("sse", "sse2", "sse3", "ssse3") end +if is_kind("static") then + add_defines("NAZARA_STATIC") +end + add_includedirs("include") add_sysincludedirs("thirdparty/include") set_languages("c89", "cxx17") set_rundir("./bin/$(plat)_$(arch)_$(mode)") -set_symbols("debug", "hidden") set_targetdir("./bin/$(plat)_$(arch)_$(mode)") set_warnings("allextra") +if not is_mode("release") then + set_symbols("debug", "hidden") +end + if is_mode("debug") then add_defines("NAZARA_DEBUG") end @@ -391,4 +400,4 @@ end includes("tools/*.lua") includes("tests/*.lua") includes("examples/*.lua") -includes("plugins/*/xmake.lua") +includes("plugins/*.lua")