#if __APPLE__ #include "TargetConditionals.h" #endif #ifdef _WIN32 #pragma comment(lib, "Ws2_32.lib") #endif #include #include #include #include #ifdef __EMSCRIPTEN__ #include #include #include #include #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "Log.hpp" #include "RenderTicker.hpp" namespace thermion { using namespace filament; using namespace filament::math; using namespace utils; using std::string; void RenderTicker::setRenderable(SwapChain *swapChain, View **views, uint8_t numViews) { std::lock_guard lock(mMutex); auto it = std::find_if(mRenderable.begin(), mRenderable.end(), [swapChain](const auto& pair) { return pair.first == swapChain; }); std::vector swapChainViews; for(int i = 0; i < numViews; i++) { swapChainViews.push_back(views[i]); } if (it != mRenderable.end()) { it->second = swapChainViews; } else { mRenderable.emplace_back(swapChain, swapChainViews); } } void RenderTicker::render(uint64_t frameTimeInNanos) { std::lock_guard lock(mMutex); for (auto animationManager : mAnimationManagers) { animationManager->update(frameTimeInNanos); } for (const auto& [swapChain, views] : mRenderable) { if (!views.empty()) { bool beginFrame = mRenderer->beginFrame(swapChain, frameTimeInNanos); if (beginFrame) { for (auto view : views) { mRenderer->render(view); } } mRenderer->endFrame(); } } #ifdef __EMSCRIPTEN__ _engine->execute(); #endif } void RenderTicker::addAnimationManager(AnimationManager* animationManager) { std::lock_guard lock(mMutex); mAnimationManagers.push_back(animationManager); } void RenderTicker::removeAnimationManager(AnimationManager* animationManager) { std::lock_guard lock(mMutex); auto it = std::find(mAnimationManagers.begin(), mAnimationManagers.end(), animationManager); if (it != mAnimationManagers.end()) { mAnimationManagers.erase(it); } } RenderTicker::~RenderTicker() {} } // namespace thermion