23#ifdef ES_ENABLE_BITMAP_TEXT
32#ifdef ES_ENABLE_PARTICLES
39#ifdef ES_ENABLE_TILEMAP
49#include <emscripten/html5.h>
60 registerLogicSystems();
63void EstellaContext::registerLogicSystems() {
74#ifdef ES_ENABLE_PARTICLES
85#ifdef ES_ENABLE_TILEMAP
94 render_thread_.stop();
102 return init(webglContextHandle,
false);
111 EMSCRIPTEN_RESULT result = emscripten_webgl_make_context_current(
112 static_cast<EMSCRIPTEN_WEBGL_CONTEXT_HANDLE
>(webglContextHandle));
113 if (result != EMSCRIPTEN_RESULT_SUCCESS) {
114 ES_LOG_ERROR(
"Failed to make WebGL context current: {}", result);
118 state_.webgl_context = webglContextHandle;
119 state_.owns_webgl_context = ownsContext;
127 if (state_.initialized) {
135 initSubsystems(std::move(device));
143 auto* gfxDevicePtr = gfxDevice.get();
155 resourceManager->init(*gfxDevicePtr);
156 services_.
registerOwned<resource::ResourceManager>(std::move(resourceManager));
159 renderContext->init();
162 renderContext->materials().setResourceManager(services_.
getService<resource::ResourceManager>());
163 services_.
registerOwned<RenderContext>(std::move(renderContext));
172 registerLogicSystems();
174 auto* rm = services_.
getService<resource::ResourceManager>();
175 auto* rc = services_.
getService<RenderContext>();
177 immediateDraw->init();
178 auto* immediateDrawPtr = immediateDraw.get();
179 services_.
registerOwned<ImmediateDraw>(std::move(immediateDraw));
184 renderFrame->setPresentedOverlayDraw(immediateDrawPtr);
185 renderFrame->addPlugin(std::make_unique<SpritePlugin>());
186 renderFrame->addPlugin(std::make_unique<UIElementPlugin>());
187#ifdef ES_ENABLE_BITMAP_TEXT
188 renderFrame->addPlugin(std::make_unique<TextPlugin>());
190 renderFrame->addPlugin(std::make_unique<ShapePlugin>());
191 renderFrame->addPlugin(std::make_unique<MeshPlugin>());
193 auto trailPlugin = std::make_unique<TrailPlugin>();
194 trailPlugin->setTrailSystem(services_.
getService<trail::TrailSystem>());
195 renderFrame->addPlugin(std::move(trailPlugin));
198#ifdef ES_ENABLE_TILEMAP
200 auto tilemapPlugin = std::make_unique<TilemapRenderPlugin>();
201 tilemapPlugin->setTilemapSystem(services_.getService<tilemap::TilemapSystem>());
202 renderFrame->addPlugin(std::move(tilemapPlugin));
205#ifdef ES_ENABLE_PARTICLES
207 auto particlePlugin = std::make_unique<ParticlePlugin>();
208 particlePlugin->setParticleSystem(services_.getService<particle::ParticleSystem>());
209 renderFrame->addPlugin(std::move(particlePlugin));
213 renderFrame->init(state_.viewport_width, state_.viewport_height);
214 services_.registerOwned<RenderFrame>(std::move(renderFrame));
216#ifdef ES_ENABLE_POSTPROCESS
221 if (
auto* pp = services_.getService<RenderFrame>()->postProcess()) {
222 services_.registerService<PostProcessPipeline>(pp);
226 state_.initialized =
true;
229 RenderPassDesc initPass{};
230 initPass.clearColor =
true;
231 initPass.clearDepth =
true;
232 initPass.clearColorValue[0] = state_.clear_color.r;
233 initPass.clearColorValue[1] = state_.clear_color.g;
234 initPass.clearColorValue[2] = state_.clear_color.b;
235 initPass.clearColorValue[3] = state_.clear_color.a;
236 gfxDevicePtr->beginRenderPass(initPass);
237 gfxDevicePtr->endRenderPass();
241 gfxDevicePtr->endFrame();
247 if (render_thread_.enabled() && !render_thread_.isOwner()) {
248 render_thread_.invoke([
this] {
shutdown(); });
249 render_thread_.stop();
252 if (!state_.initialized)
return;
254#ifdef ES_PLATFORM_WEB
255 const auto webglCtx =
static_cast<EMSCRIPTEN_WEBGL_CONTEXT_HANDLE
>(state_.webgl_context);
256 const bool ownsWebglContext = state_.owns_webgl_context;
257 const auto previousContext = emscripten_webgl_get_current_context();
260 if (webglCtx > 0 && previousContext != webglCtx) {
261 emscripten_webgl_make_context_current(webglCtx);
273#ifdef ES_PLATFORM_WEB
274 if (webglCtx > 0 && ownsWebglContext) {
275 emscripten_webgl_destroy_context(webglCtx);
277 if (webglCtx > 0 && previousContext != webglCtx) {
278 emscripten_webgl_make_context_current(previousContext);
Custom geometry for user-defined mesh rendering.
Instance-based engine context for estella renderer.
OpenGL ES / WebGL implementation of GfxDevice.
Logging utilities for ESEngine.
#define ES_LOG_WARN(...)
Logs a warning message.
#define ES_LOG_ERROR(...)
Logs an error message.
#define ES_LOG_INFO(...)
Logs an info message.
The engine's randomness, and the only place its seed lives.
Rendering context containing all renderer state.
Frame resources and the shared scene rendering contract.
Central resource management system.
Per-App secondary motion: runs every SpringBone chain after the animation has posed the skeleton and ...
Per-App motion-trail simulation: records each TrailRenderer entity's world position over time into a ...
UI subsystem owning layout tree and hit-test state.
bool init(int webglContextHandle)
Initialize with an existing WebGL context handle.
void shutdown()
Shut down all subsystems and release resources.
T * getService()
Gets a service by type.
void registerOwned(Unique< T > service)
Registers an owned service.
UI subsystem: owns layout tree + hit-test state.
constexpr Unique< T > makeUnique(Args &&... args)
Creates a Unique pointer with the given arguments.
bool takePendingRandomSeed(u32 &out)
std::unique_ptr< T > Unique
Unique ownership smart pointer.
std::uint32_t u32
Unsigned 32-bit integer.
std::string gfxFormatDeviceLost(const GfxDeviceLostInfo &info)
The whole report as one line, for a log or a crash report.