~ WIP port emscripen (WebGL)
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
#define NAZARA_DYNLIB_EXTENSION ".dll"
|
||||
#elif defined(NAZARA_PLATFORM_LINUX)
|
||||
#define NAZARA_DYNLIB_EXTENSION ".so"
|
||||
#elif defined(NAZARA_PLATFORM_WEB)
|
||||
#define NAZARA_DYNLIB_EXTENSION ".wasm"
|
||||
#elif defined(NAZARA_PLATFORM_MACOS)
|
||||
#define NAZARA_DYNLIB_EXTENSION ".dylib"
|
||||
#else
|
||||
|
||||
76
include/Nazara/OpenGLRenderer/Wrapper/Web/WebContext.hpp
Normal file
76
include/Nazara/OpenGLRenderer/Wrapper/Web/WebContext.hpp
Normal file
@@ -0,0 +1,76 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - OpenGL renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_OPENGLRENDERER_WRAPPER_WEB_WEBCONTEXT_HPP
|
||||
#define NAZARA_OPENGLRENDERER_WRAPPER_WEB_WEBCONTEXT_HPP
|
||||
|
||||
#include <emscripten/html5.h>
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/DynLib.hpp>
|
||||
#include <Nazara/OpenGLRenderer/Config.hpp>
|
||||
#include <Nazara/OpenGLRenderer/Wrapper/Context.hpp>
|
||||
#include <Nazara/Platform/WindowHandle.hpp>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace Nz::GL
|
||||
{
|
||||
class WebLoader;
|
||||
|
||||
class NAZARA_OPENGLRENDERER_API WebContext : public Context
|
||||
{
|
||||
public:
|
||||
inline WebContext(const OpenGLDevice* device, const WebLoader& loader);
|
||||
WebContext(const WebContext&) = delete;
|
||||
WebContext(WebContext&&) = delete;
|
||||
~WebContext();
|
||||
|
||||
virtual bool Create(const ContextParams& params, const WebContext* shareContext = nullptr);
|
||||
virtual bool Create(const ContextParams& params, WindowHandle window, const WebContext* shareContext = nullptr);
|
||||
virtual void Destroy();
|
||||
|
||||
void EnableVerticalSync(bool enabled) override;
|
||||
|
||||
inline bool HasPlatformExtension(const std::string& str) const;
|
||||
|
||||
void SwapBuffers() override;
|
||||
|
||||
WebContext& operator=(const WebContext&) = delete;
|
||||
WebContext& operator=(WebContext&&) = delete;
|
||||
|
||||
protected:
|
||||
bool ChooseConfig(EmscriptenWebGLContextAttributes* configs, std::size_t maxConfigCount, std::size_t* configCount);
|
||||
bool CreateInternal(EmscriptenWebGLContextAttributes config, const WebContext* shareContext = nullptr);
|
||||
|
||||
const WebLoader& m_loader;
|
||||
|
||||
private:
|
||||
bool ImplementFallback(const std::string_view& function) override;
|
||||
|
||||
bool Activate() const override;
|
||||
void Desactivate() const override;
|
||||
const Loader& GetLoader() override;
|
||||
bool LoadExt();
|
||||
|
||||
struct Fallback
|
||||
{
|
||||
using glClearDepthProc = void(*)(double depth);
|
||||
|
||||
glClearDepthProc glClearDepth;
|
||||
};
|
||||
Fallback fallbacks; //< m_ omitted
|
||||
|
||||
std::unordered_set<std::string> m_supportedPlatformExtensions;
|
||||
static EMSCRIPTEN_WEBGL_CONTEXT_HANDLE s_handle;
|
||||
static size_t s_handleCounter;
|
||||
bool m_ownsDisplay;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/OpenGLRenderer/Wrapper/Web/WebContext.inl>
|
||||
|
||||
#endif // NAZARA_OPENGLRENDERER_WRAPPER_WEB_WEBCONTEXT_HPP
|
||||
24
include/Nazara/OpenGLRenderer/Wrapper/Web/WebContext.inl
Normal file
24
include/Nazara/OpenGLRenderer/Wrapper/Web/WebContext.inl
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - OpenGL renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/OpenGLRenderer/Wrapper/Web/WebContext.hpp>
|
||||
#include <Nazara/OpenGLRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz::GL
|
||||
{
|
||||
inline WebContext::WebContext(const OpenGLDevice* device, const WebLoader& loader) :
|
||||
Context(device),
|
||||
m_loader(loader),
|
||||
//m_handle(0),
|
||||
m_ownsDisplay(false)
|
||||
{
|
||||
}
|
||||
|
||||
inline bool WebContext::HasPlatformExtension(const std::string& str) const
|
||||
{
|
||||
return m_supportedPlatformExtensions.find(str) != m_supportedPlatformExtensions.end();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/OpenGLRenderer/DebugOff.hpp>
|
||||
40
include/Nazara/OpenGLRenderer/Wrapper/Web/WebLoader.hpp
Normal file
40
include/Nazara/OpenGLRenderer/Wrapper/Web/WebLoader.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - OpenGL renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_OPENGLRENDERER_WRAPPER_WEB_WEBLOADER_HPP
|
||||
#define NAZARA_OPENGLRENDERER_WRAPPER_WEB_WEBLOADER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/OpenGLRenderer/Config.hpp>
|
||||
#include <Nazara/OpenGLRenderer/Wrapper/Loader.hpp>
|
||||
#include <Nazara/OpenGLRenderer/Wrapper/Web/WebContext.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz::GL
|
||||
{
|
||||
class NAZARA_OPENGLRENDERER_API WebLoader : public Loader
|
||||
{
|
||||
struct SymbolLoader;
|
||||
friend SymbolLoader;
|
||||
|
||||
public:
|
||||
std::unique_ptr<Context> CreateContext(const OpenGLDevice* device, const ContextParams& params, Context* shareContext) const override;
|
||||
std::unique_ptr<Context> CreateContext(const OpenGLDevice* device, const ContextParams& params, WindowHandle handle, Context* shareContext) const override;
|
||||
|
||||
ContextType GetPreferredContextType() const override;
|
||||
|
||||
GLFunction LoadFunction(const char* name) const override;
|
||||
|
||||
static const char* TranslateError(EMSCRIPTEN_RESULT errorId);
|
||||
|
||||
private:
|
||||
bool ImplementFallback(const std::string_view& function);
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/OpenGLRenderer/Wrapper/Web/WebLoader.inl>
|
||||
|
||||
#endif // NAZARA_OPENGLRENDERER_WRAPPER_WEB_WEBLOADER_HPP
|
||||
12
include/Nazara/OpenGLRenderer/Wrapper/Web/WebLoader.inl
Normal file
12
include/Nazara/OpenGLRenderer/Wrapper/Web/WebLoader.inl
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - OpenGL renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/OpenGLRenderer/Wrapper/Web/WebLoader.hpp>
|
||||
#include <Nazara/OpenGLRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz::GL
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/OpenGLRenderer/DebugOff.hpp>
|
||||
@@ -19,7 +19,8 @@ namespace Nz
|
||||
Cocoa,
|
||||
X11,
|
||||
Wayland,
|
||||
Windows
|
||||
Windows,
|
||||
Web
|
||||
};
|
||||
|
||||
struct WindowHandle
|
||||
@@ -39,7 +40,7 @@ namespace Nz
|
||||
unsigned long window; //< Window
|
||||
} x11;
|
||||
|
||||
struct
|
||||
struct
|
||||
{
|
||||
void* display; //< wl_display*
|
||||
void* surface; //< wl_surface*
|
||||
@@ -50,6 +51,7 @@ namespace Nz
|
||||
{
|
||||
void* window; //< HWND
|
||||
} windows;
|
||||
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
43
include/Nazara/Utility/BasicMainloop.hpp
Normal file
43
include/Nazara/Utility/BasicMainloop.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
// 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_BASIC_MAINLOOP_HPP
|
||||
#define NAZARA_BASIC_MAINLOOP_HPP
|
||||
|
||||
#include <Nazara/Renderer.hpp>
|
||||
|
||||
#ifdef NAZARA_PLATFORM_WEB
|
||||
#include <emscripten/html5.h>
|
||||
#endif
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
template <typename CallbackT>
|
||||
void BasicMainloop(RenderWindow& 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_BASIC_MAINLOOP_HPP
|
||||
Reference in New Issue
Block a user