refactoring

This commit is contained in:
Nick Fisher
2025-03-21 17:18:16 +08:00
parent 4ef74c4c70
commit a67f42f0de
12 changed files with 262 additions and 52 deletions

View File

@@ -121,6 +121,24 @@ namespace thermion
engine->destroy(swapChain);
}
EMSCRIPTEN_KEEPALIVE void Engine_destroyView(TEngine *tEngine, TView *tView) {
auto *engine = reinterpret_cast<Engine *>(tEngine);
auto *view = reinterpret_cast<View *>(tView);
engine->destroy(view);
}
EMSCRIPTEN_KEEPALIVE void Engine_destroyScene(TEngine *tEngine, TScene *tScene) {
auto *engine = reinterpret_cast<Engine *>(tEngine);
auto *scene = reinterpret_cast<Scene *>(tScene);
engine->destroy(scene);
}
EMSCRIPTEN_KEEPALIVE void Engine_destroyColorGrading(TEngine *tEngine, TColorGrading *tColorGrading) {
auto *engine = reinterpret_cast<Engine *>(tEngine);
auto *colorGrading = reinterpret_cast<ColorGrading *>(tColorGrading);
engine->destroy(colorGrading);
}
EMSCRIPTEN_KEEPALIVE TView *Engine_createView(TEngine *tEngine)
{
auto *engine = reinterpret_cast<Engine *>(tEngine);

View File

@@ -100,9 +100,13 @@ using namespace filament;
#endif
}
EMSCRIPTEN_KEEPALIVE void View_setToneMapping(TView *tView, TEngine *tEngine, TToneMapping tToneMapping)
{
auto view = reinterpret_cast<View *>(tView);
EMSCRIPTEN_KEEPALIVE void View_setColorGrading(TView *tView, TColorGrading *tColorGrading) {
auto *view = reinterpret_cast<View*>(tView);
auto *colorGrading = reinterpret_cast<ColorGrading *>(tColorGrading);
view->setColorGrading(colorGrading);
}
EMSCRIPTEN_KEEPALIVE TColorGrading *ColorGrading_create(TEngine* tEngine, TToneMapping tToneMapping) {
auto engine = reinterpret_cast<Engine *>(tEngine);
ToneMapper *tm;
@@ -122,17 +126,12 @@ using namespace filament;
break;
default:
TRACE("ERROR: Unsupported tone mapping");
return;
}
auto newColorGrading = ColorGrading::Builder().toneMapper(tm).build(*engine);
auto oldColorGrading = view->getColorGrading();
view->setColorGrading(newColorGrading);
if (oldColorGrading)
{
engine->destroy(oldColorGrading);
return nullptr;
}
auto colorGrading = ColorGrading::Builder().toneMapper(tm).build(*engine);
delete tm;
return reinterpret_cast<TColorGrading *>(colorGrading);
}
void View_setAntiAliasing(TView *tView, bool msaa, bool fxaa, bool taa)

View File

@@ -133,6 +133,26 @@ extern "C"
auto fut = _renderThread->add_task(lambda);
}
EMSCRIPTEN_KEEPALIVE void Engine_destroyViewRenderThread(TEngine *tEngine, TView *tView, void (*onComplete)()) {
std::packaged_task<void()> lambda(
[=]() mutable
{
Engine_destroyView(tEngine, tView);
onComplete();
});
auto fut = _renderThread->add_task(lambda);
}
EMSCRIPTEN_KEEPALIVE void Engine_destroySceneRenderThread(TEngine *tEngine, TScene *tScene, void (*onComplete)()) {
std::packaged_task<void()> lambda(
[=]() mutable
{
Engine_destroyScene(tEngine, tScene);
onComplete();
});
auto fut = _renderThread->add_task(lambda);
}
EMSCRIPTEN_KEEPALIVE void Engine_createCameraRenderThread(TEngine* tEngine, void (*onComplete)(TCamera *)) {
std::packaged_task<void()> lambda(
[=]() mutable
@@ -153,6 +173,16 @@ extern "C"
auto fut = _renderThread->add_task(lambda);
}
EMSCRIPTEN_KEEPALIVE void Engine_destroyRenderThread(TEngine *tEngine, void (*onComplete)()) {
std::packaged_task<void()> lambda(
[=]() mutable
{
Engine_destroy(tEngine);
onComplete();
});
auto fut = _renderThread->add_task(lambda);
}
EMSCRIPTEN_KEEPALIVE void Engine_destroyTextureRenderThread(TEngine *engine, TTexture *tTexture, void (*onComplete)())
{
std::packaged_task<void()> lambda(
@@ -438,13 +468,35 @@ extern "C"
});
auto fut = _renderThread->add_task(lambda);
}
EMSCRIPTEN_KEEPALIVE void View_setToneMappingRenderThread(TView *tView, TEngine *tEngine, TToneMapping toneMapping, void (*callback)())
EMSCRIPTEN_KEEPALIVE void ColorGrading_createRenderThread(TEngine *tEngine, TToneMapping toneMapping, void (*callback)(TColorGrading *))
{
std::packaged_task<void()> lambda(
[=]
{
View_setToneMapping(tView, tEngine, toneMapping);
auto cg = ColorGrading_create(tEngine, toneMapping);
callback(cg);
});
auto fut = _renderThread->add_task(lambda);
}
EMSCRIPTEN_KEEPALIVE void Engine_destroyColorGradingRenderThread(TEngine *tEngine, TColorGrading *tColorGrading, void (*callback)())
{
std::packaged_task<void()> lambda(
[=]
{
Engine_destroyColorGrading(tEngine, tColorGrading);
callback();
});
auto fut = _renderThread->add_task(lambda);
}
EMSCRIPTEN_KEEPALIVE void View_setColorGradingRenderThread(TView *tView, TColorGrading *tColorGrading, void (*callback)())
{
std::packaged_task<void()> lambda(
[=]
{
View_setColorGrading(tView, tColorGrading);
callback();
});
auto fut = _renderThread->add_task(lambda);