Last changes
This commit is contained in:
parent
cee75dcc11
commit
5a57aca66a
|
|
@ -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<Nz::Graphics> app(rendererConfig);
|
||||
Nz::Application<Nz::Graphics> app;
|
||||
|
||||
nzsl::ShaderWriter::States states;
|
||||
states.shaderModuleResolver = Nz::Graphics::Instance()->GetShaderModuleResolver();
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
#include <Nazara/Platform/Keyboard.hpp>
|
||||
#include <Nazara/Platform/Platform.hpp>
|
||||
#include <Nazara/Platform/Window.hpp>
|
||||
#include <Nazara/Utility/BasicMainloop.hpp>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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<Nz::Graphics> app(rendererConfig);
|
||||
Nz::Application<Nz::Graphics> app;
|
||||
|
||||
std::shared_ptr<Nz::RenderDevice> device = Nz::Graphics::Instance()->GetRenderDevice();
|
||||
|
||||
|
|
|
|||
|
|
@ -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<std::streamsize>::max(), '\n');
|
||||
|
||||
Nz::Application<Nz::Graphics, Nz::Physics2D> app(rendererConfig);
|
||||
Nz::Application<Nz::Graphics, Nz::Physics2D> app;
|
||||
|
||||
auto& windowing = app.AddComponent<Nz::AppWindowingComponent>();
|
||||
|
||||
|
|
|
|||
|
|
@ -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<std::streamsize>::max(), '\n');
|
||||
|
||||
Nz::Application<Nz::Graphics, Nz::Physics3D> app(rendererConfig);
|
||||
Nz::Application<Nz::Graphics, Nz::Physics3D> app;
|
||||
|
||||
auto& windowing = app.AddComponent<Nz::AppWindowingComponent>();
|
||||
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -9,49 +9,39 @@
|
|||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Platform/Keyboard.hpp>
|
||||
#include <Nazara/Platform/Platform.hpp>
|
||||
#include <Nazara/Utility/BasicMainloop.hpp>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
int main()
|
||||
{
|
||||
try
|
||||
std::filesystem::path resourceDir = "assets/examples";
|
||||
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir))
|
||||
resourceDir = "../.." / resourceDir;
|
||||
|
||||
Nz::Application<Nz::Audio> 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<Nz::Audio> 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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<Nz::Graphics> app(rendererConfig);
|
||||
Nz::Application<Nz::Graphics> app;
|
||||
|
||||
Nz::PluginLoader loader;
|
||||
Nz::Plugin<Nz::AssimpPlugin> assimp = loader.Load<Nz::AssimpPlugin>();
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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<std::streamsize>::max(), '\n');
|
||||
|
||||
Nz::Application<Nz::Graphics, Nz::Widgets> app(rendererConfig);
|
||||
Nz::Application<Nz::Graphics, Nz::Widgets> app;
|
||||
|
||||
auto& windowing = app.AddComponent<Nz::AppWindowingComponent>();
|
||||
Nz::Window& mainWindow = windowing.CreateWindow(Nz::VideoMode(1920, 1080), "Widget demo");
|
||||
|
|
@ -67,7 +58,7 @@ int main()
|
|||
samplerInfo.anisotropyLevel = 8;
|
||||
|
||||
std::shared_ptr<Nz::MaterialInstance> materialInstance = material->Instantiate();
|
||||
materialInstance->SetTextureProperty("BaseColorMap", fs.GetOrLoad<Nz::Texture>("assets/lynix.jpg"));
|
||||
materialInstance->SetTextureProperty("BaseColorMap", fs.Load<Nz::Texture>("assets/lynix.jpg"));
|
||||
|
||||
Nz::ImageWidget* imageWidget = canvas2D.Add<Nz::ImageWidget>(materialInstance);
|
||||
imageWidget->SetPosition(1200.f, 200.f);
|
||||
|
|
|
|||
|
|
@ -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 */\
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ namespace Nz
|
|||
Cocoa,
|
||||
X11,
|
||||
Wayland,
|
||||
Windows,
|
||||
Web
|
||||
Web,
|
||||
Windows
|
||||
};
|
||||
|
||||
struct WindowHandle
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@
|
|||
#include <Nazara/Utility/AbstractTextDrawer.hpp>
|
||||
#include <Nazara/Utility/Algorithm.hpp>
|
||||
#include <Nazara/Utility/Animation.hpp>
|
||||
#include <Nazara/Utility/BasicMainloop.hpp>
|
||||
#include <Nazara/Utility/Buffer.hpp>
|
||||
#include <Nazara/Utility/BufferMapper.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
|
|
|
|||
|
|
@ -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 <Nazara/Platform/Window.hpp>
|
||||
|
||||
#ifdef NAZARA_PLATFORM_WEB
|
||||
#include <emscripten/html5.h>
|
||||
#endif
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template <typename CallbackT>
|
||||
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<decltype(&callback)>(callbackInstance))();
|
||||
}
|
||||
catch(std::exception e)
|
||||
{
|
||||
NazaraDebug(e.what());
|
||||
}
|
||||
}, &callback, 0, 1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // NAZARA_UTILITY_BASICMAINLOOP_HPP
|
||||
|
|
@ -32,7 +32,10 @@ namespace Nz
|
|||
{
|
||||
ApplicationBase* app = static_cast<ApplicationBase*>(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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<T>::value, "non-exhaustive visitor");
|
||||
|
|
|
|||
|
|
@ -431,7 +431,7 @@ namespace Nz::GL
|
|||
|
||||
try
|
||||
{
|
||||
#define NAZARA_OPENGLRENDERER_FUNC(name, sig) loader.Load<sig, UnderlyingCast(FunctionIndex:: name)>(name, #name, false, true);
|
||||
#define NAZARA_OPENGLRENDERER_FUNC(name, sig) loader.Load<sig, UnderlyingCast(FunctionIndex:: name)>(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
|
||||
|
|
|
|||
|
|
@ -165,6 +165,7 @@ namespace Nz::GL
|
|||
{
|
||||
case WindowBackend::Invalid:
|
||||
case WindowBackend::Cocoa: //< TODO?
|
||||
case WindowBackend::Web: //< TODO?
|
||||
break;
|
||||
|
||||
case WindowBackend::X11:
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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<Nz::Graphics> nazara(rendererConfig);
|
||||
Nz::Application<Nz::Graphics> app(rendererConfig);
|
||||
auto& windowingApp = app.AddComponent<Nz::AppWindowingComponent>();
|
||||
|
||||
Nz::MeshParams meshParams;
|
||||
meshParams.center = true;
|
||||
|
|
@ -35,12 +37,7 @@ int main()
|
|||
std::shared_ptr<Nz::RenderDevice> 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<Nz::Mesh> 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<Nz::Time> 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Nz::Renderer> nazara(rendererConfig);
|
||||
Nz::Application<Nz::Renderer> app(rendererConfig);
|
||||
auto& windowingApp = app.AddComponent<Nz::AppWindowingComponent>();
|
||||
|
||||
std::shared_ptr<Nz::RenderDevice> 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<Nz::Time> 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
18
xmake.lua
18
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") } })
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue