refactoring
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'dart:typed_data';
|
||||
import 'package:thermion_dart/src/filament/src/engine.dart';
|
||||
import 'package:thermion_dart/src/filament/src/scene.dart';
|
||||
import 'package:thermion_dart/thermion_dart.dart';
|
||||
|
||||
class FilamentConfig<T, U> {
|
||||
@@ -63,6 +64,16 @@ abstract class FilamentApp<T> {
|
||||
///
|
||||
Future destroySwapChain(SwapChain swapChain);
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
Future destroyView(View view);
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
Future destroyScene(Scene scene);
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
@@ -248,4 +259,9 @@ abstract class FilamentApp<T> {
|
||||
int layer = 0,
|
||||
bool loadResourcesAsync = false,
|
||||
String? relativeResourcePath});
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
Future<T> createColorGrading(ToneMapper mapper);
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@ import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:path/path.dart';
|
||||
import 'package:thermion_dart/src/filament/src/engine.dart';
|
||||
import 'package:thermion_dart/src/filament/src/scene.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/callbacks.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_asset.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_material.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_render_target.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_scene.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_swapchain.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_texture.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_view.dart';
|
||||
@@ -199,9 +200,13 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
|
||||
for (final swapChain in _swapChains.keys.toList()) {
|
||||
await destroySwapChain(swapChain);
|
||||
}
|
||||
await withVoidCallback((cb) async {
|
||||
Engine_destroyRenderThread(engine, cb);
|
||||
});
|
||||
|
||||
RenderThread_destroy();
|
||||
RenderTicker_destroy(renderTicker);
|
||||
Engine_destroy(engine);
|
||||
|
||||
calloc.free(viewsPtr);
|
||||
}
|
||||
|
||||
@@ -725,6 +730,27 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
|
||||
GltfResourceLoader_destroyRenderThread(engine, gltfResourceLoader, cb));
|
||||
return FFIAsset(asset, this, animationManager.cast<TAnimationManager>());
|
||||
}
|
||||
|
||||
Future destroyView(covariant FFIView view) async {
|
||||
View_setColorGrading(view.view, nullptr);
|
||||
for (final cg in view.colorGrading.entries) {
|
||||
await withVoidCallback(
|
||||
(cb) => Engine_destroyColorGradingRenderThread(engine, cg.value, cb));
|
||||
}
|
||||
await withVoidCallback(
|
||||
(cb) => Engine_destroyViewRenderThread(engine, view.view, cb));
|
||||
}
|
||||
|
||||
Future destroyScene(covariant FFIScene scene) async {
|
||||
await withVoidCallback(
|
||||
(cb) => Engine_destroySceneRenderThread(engine, scene.scene, cb));
|
||||
}
|
||||
|
||||
Future<Pointer<TColorGrading>> createColorGrading(ToneMapper mapper) async {
|
||||
return withPointerCallback<TColorGrading>((cb) =>
|
||||
ColorGrading_createRenderThread(
|
||||
engine, TToneMapping.values[mapper.index], cb));
|
||||
}
|
||||
}
|
||||
|
||||
class FinalizableUint8List implements Finalizable {
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_render_target.dart';
|
||||
import 'package:thermion_dart/src/viewer/src/ffi/src/ffi_scene.dart';
|
||||
import 'package:thermion_dart/src/filament/src/layers.dart';
|
||||
import 'package:thermion_dart/src/filament/src/shared_types.dart';
|
||||
import 'package:thermion_dart/thermion_dart.dart';
|
||||
import 'callbacks.dart';
|
||||
import 'ffi_camera.dart';
|
||||
|
||||
@@ -92,10 +93,19 @@ class FFIView extends View {
|
||||
});
|
||||
}
|
||||
|
||||
final colorGrading = <ToneMapper, Pointer<TColorGrading>>{};
|
||||
|
||||
@override
|
||||
Future setToneMapper(ToneMapper mapper) async {
|
||||
await withVoidCallback((cb) => View_setToneMappingRenderThread(
|
||||
view, app.engine, TToneMapping.values[mapper.index], cb));
|
||||
if (colorGrading[mapper] == null) {
|
||||
colorGrading[mapper] =
|
||||
await FilamentApp.instance!.createColorGrading(mapper);
|
||||
if (colorGrading[mapper] == nullptr) {
|
||||
throw Exception("Failed to create color grading");
|
||||
}
|
||||
}
|
||||
|
||||
View_setColorGrading(view, colorGrading[mapper]!);
|
||||
}
|
||||
|
||||
Future setStencilBufferEnabled(bool enabled) async {
|
||||
|
||||
@@ -473,6 +473,30 @@ external TViewport View_getViewport(
|
||||
ffi.Pointer<TView> view,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Pointer<TColorGrading> Function(ffi.Pointer<TEngine>,
|
||||
ffi.UnsignedInt)>(symbol: "ColorGrading_create", isLeaf: true)
|
||||
external ffi.Pointer<TColorGrading> _ColorGrading_create(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
int toneMapping,
|
||||
);
|
||||
|
||||
ffi.Pointer<TColorGrading> ColorGrading_create(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
TToneMapping toneMapping,
|
||||
) =>
|
||||
_ColorGrading_create(
|
||||
tEngine,
|
||||
toneMapping.value,
|
||||
);
|
||||
|
||||
@ffi.Native<ffi.Void Function(ffi.Pointer<TView>, ffi.Pointer<TColorGrading>)>(
|
||||
isLeaf: true)
|
||||
external void View_setColorGrading(
|
||||
ffi.Pointer<TView> tView,
|
||||
ffi.Pointer<TColorGrading> tColorGrading,
|
||||
);
|
||||
|
||||
@ffi.Native<ffi.Void Function(ffi.Pointer<TView>, ffi.UnsignedInt)>(
|
||||
symbol: "View_setBlendMode", isLeaf: true)
|
||||
external void _View_setBlendMode(
|
||||
@@ -566,26 +590,6 @@ void View_setRenderQuality(
|
||||
qualityLevel.value,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(ffi.Pointer<TView>, ffi.Pointer<TEngine>,
|
||||
ffi.UnsignedInt)>(symbol: "View_setToneMapping", isLeaf: true)
|
||||
external void _View_setToneMapping(
|
||||
ffi.Pointer<TView> tView,
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
int toneMapping,
|
||||
);
|
||||
|
||||
void View_setToneMapping(
|
||||
ffi.Pointer<TView> tView,
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
TToneMapping toneMapping,
|
||||
) =>
|
||||
_View_setToneMapping(
|
||||
tView,
|
||||
tEngine,
|
||||
toneMapping.value,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(
|
||||
ffi.Pointer<TView>, ffi.Bool, ffi.Bool, ffi.Bool)>(isLeaf: true)
|
||||
@@ -1669,6 +1673,14 @@ external void Engine_buildMaterialRenderThread(
|
||||
onComplete,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(ffi.Pointer<TEngine>,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
|
||||
external void Engine_destroyRenderThread(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onComplete,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(ffi.Pointer<TEngine>, ffi.Pointer<TSwapChain>,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
|
||||
@@ -1678,6 +1690,33 @@ external void Engine_destroySwapChainRenderThread(
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onComplete,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(ffi.Pointer<TEngine>, ffi.Pointer<TView>,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
|
||||
external void Engine_destroyViewRenderThread(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
ffi.Pointer<TView> tView,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onComplete,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(ffi.Pointer<TEngine>, ffi.Pointer<TScene>,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
|
||||
external void Engine_destroySceneRenderThread(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
ffi.Pointer<TScene> tScene,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onComplete,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(ffi.Pointer<TEngine>, ffi.Pointer<TColorGrading>,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
|
||||
external void Engine_destroyColorGradingRenderThread(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
ffi.Pointer<TColorGrading> tColorGrading,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onComplete,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(ffi.Pointer<TEngine>, ffi.Pointer<TMaterial>,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
|
||||
@@ -1954,31 +1993,40 @@ external void Material_createImageMaterialRenderThread(
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(
|
||||
ffi.Pointer<TView>,
|
||||
ffi.Pointer<TEngine>,
|
||||
ffi.UnsignedInt,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(
|
||||
symbol: "View_setToneMappingRenderThread", isLeaf: true)
|
||||
external void _View_setToneMappingRenderThread(
|
||||
ffi.Pointer<TView> tView,
|
||||
ffi.Pointer<
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(ffi.Pointer<TColorGrading>)>>)>(
|
||||
symbol: "ColorGrading_createRenderThread", isLeaf: true)
|
||||
external void _ColorGrading_createRenderThread(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
int toneMapping,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> callback,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TColorGrading>)>>
|
||||
callback,
|
||||
);
|
||||
|
||||
void View_setToneMappingRenderThread(
|
||||
ffi.Pointer<TView> tView,
|
||||
void ColorGrading_createRenderThread(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
TToneMapping toneMapping,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> callback,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TColorGrading>)>>
|
||||
callback,
|
||||
) =>
|
||||
_View_setToneMappingRenderThread(
|
||||
tView,
|
||||
_ColorGrading_createRenderThread(
|
||||
tEngine,
|
||||
toneMapping.value,
|
||||
callback,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(ffi.Pointer<TView>, ffi.Pointer<TColorGrading>,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
|
||||
external void View_setColorGradingRenderThread(
|
||||
ffi.Pointer<TView> tView,
|
||||
ffi.Pointer<TColorGrading> tColorGrading,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> callback,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(ffi.Pointer<TView>, ffi.Bool, ffi.Double,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
|
||||
@@ -2912,6 +2960,28 @@ external void Engine_destroySwapChain(
|
||||
ffi.Pointer<TSwapChain> tSwapChain,
|
||||
);
|
||||
|
||||
@ffi.Native<ffi.Void Function(ffi.Pointer<TEngine>, ffi.Pointer<TView>)>(
|
||||
isLeaf: true)
|
||||
external void Engine_destroyView(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
ffi.Pointer<TView> tView,
|
||||
);
|
||||
|
||||
@ffi.Native<ffi.Void Function(ffi.Pointer<TEngine>, ffi.Pointer<TScene>)>(
|
||||
isLeaf: true)
|
||||
external void Engine_destroyScene(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
ffi.Pointer<TScene> tScene,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(
|
||||
ffi.Pointer<TEngine>, ffi.Pointer<TColorGrading>)>(isLeaf: true)
|
||||
external void Engine_destroyColorGrading(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
ffi.Pointer<TColorGrading> tColorGrading,
|
||||
);
|
||||
|
||||
@ffi.Native<ffi.Pointer<TCamera> Function(ffi.Pointer<TEngine>)>(isLeaf: true)
|
||||
external ffi.Pointer<TCamera> Engine_createCamera(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
@@ -3542,6 +3612,8 @@ final class TGltfResourceLoader extends ffi.Opaque {}
|
||||
|
||||
final class TFilamentAsset extends ffi.Opaque {}
|
||||
|
||||
final class TColorGrading extends ffi.Opaque {}
|
||||
|
||||
final class TMaterialKey extends ffi.Struct {
|
||||
@ffi.Bool()
|
||||
external bool doubleSided;
|
||||
|
||||
@@ -90,6 +90,8 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
View_setAntiAliasing(view.view, false, false, false);
|
||||
View_setDitheringEnabled(view.view, false);
|
||||
View_setRenderQuality(view.view, TQualityLevel.MEDIUM);
|
||||
|
||||
|
||||
await FilamentApp.instance!.setClearColor(1.0, 0.0, 0.0, 1.0);
|
||||
scene = FFIScene(Engine_createScene(app.engine));
|
||||
await view.setScene(scene);
|
||||
@@ -167,6 +169,9 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
for (final callback in _onDispose) {
|
||||
await callback.call();
|
||||
}
|
||||
View_setScene(view.view, nullptr);
|
||||
await FilamentApp.instance!.destroyScene(scene);
|
||||
await FilamentApp.instance!.destroyView(view);
|
||||
|
||||
_onDispose.clear();
|
||||
}
|
||||
@@ -426,6 +431,8 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
|
||||
@@ -42,6 +42,7 @@ extern "C"
|
||||
typedef struct TGltfAssetLoader TGltfAssetLoader;
|
||||
typedef struct TGltfResourceLoader TGltfResourceLoader;
|
||||
typedef struct TFilamentAsset TFilamentAsset;
|
||||
typedef struct TColorGrading TColorGrading;
|
||||
|
||||
struct TMaterialKey {
|
||||
bool doubleSided;
|
||||
|
||||
@@ -32,6 +32,9 @@ EMSCRIPTEN_KEEPALIVE TRenderer *Engine_createRenderer(TEngine *tEngine);
|
||||
EMSCRIPTEN_KEEPALIVE TSwapChain *Engine_createSwapChain(TEngine *tEngine, void *window, uint64_t flags);
|
||||
EMSCRIPTEN_KEEPALIVE TSwapChain *Engine_createHeadlessSwapChain(TEngine *tEngine, uint32_t width, uint32_t height, uint64_t flags);
|
||||
EMSCRIPTEN_KEEPALIVE void Engine_destroySwapChain(TEngine *tEngine, TSwapChain *tSwapChain);
|
||||
EMSCRIPTEN_KEEPALIVE void Engine_destroyView(TEngine *tEngine, TView *tView);
|
||||
EMSCRIPTEN_KEEPALIVE void Engine_destroyScene(TEngine *tEngine, TScene *tScene);
|
||||
EMSCRIPTEN_KEEPALIVE void Engine_destroyColorGrading(TEngine *tEngine, TColorGrading *tColorGrading);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TCamera *Engine_createCamera(TEngine* tEngine);
|
||||
EMSCRIPTEN_KEEPALIVE TView *Engine_createView(TEngine *tEngine);
|
||||
|
||||
@@ -39,6 +39,8 @@ enum TBlendMode {
|
||||
|
||||
// View
|
||||
EMSCRIPTEN_KEEPALIVE TViewport View_getViewport(TView *view);
|
||||
EMSCRIPTEN_KEEPALIVE TColorGrading *ColorGrading_create(TEngine* tEngine, TToneMapping toneMapping);
|
||||
EMSCRIPTEN_KEEPALIVE void View_setColorGrading(TView *tView, TColorGrading *tColorGrading);
|
||||
EMSCRIPTEN_KEEPALIVE void View_setBlendMode(TView *view, TBlendMode blendMode);
|
||||
EMSCRIPTEN_KEEPALIVE void View_setViewport(TView *view, uint32_t width, uint32_t height);
|
||||
EMSCRIPTEN_KEEPALIVE void View_setRenderTarget(TView *view, TRenderTarget *renderTarget);
|
||||
@@ -52,7 +54,6 @@ EMSCRIPTEN_KEEPALIVE void View_setShadowType(TView* tView, int shadowType);
|
||||
EMSCRIPTEN_KEEPALIVE void View_setSoftShadowOptions(TView* tView, float penumbraScale, float penumbraRatioScale);
|
||||
EMSCRIPTEN_KEEPALIVE void View_setBloom(TView* tView, bool enabled, float strength);
|
||||
EMSCRIPTEN_KEEPALIVE void View_setRenderQuality(TView* tView, TQualityLevel qualityLevel);
|
||||
EMSCRIPTEN_KEEPALIVE void View_setToneMapping(TView* tView, TEngine* tEngine, TToneMapping toneMapping);
|
||||
EMSCRIPTEN_KEEPALIVE void View_setAntiAliasing(TView *tView, bool msaa, bool fxaa, bool taa);
|
||||
EMSCRIPTEN_KEEPALIVE void View_setLayerEnabled(TView *tView, int layer, bool visible);
|
||||
EMSCRIPTEN_KEEPALIVE void View_setCamera(TView *tView, TCamera *tCamera);
|
||||
|
||||
@@ -37,7 +37,11 @@ namespace thermion
|
||||
EMSCRIPTEN_KEEPALIVE void Engine_createCameraRenderThread(TEngine* tEngine, void (*onComplete)(TCamera *));
|
||||
EMSCRIPTEN_KEEPALIVE void Engine_createViewRenderThread(TEngine *tEngine, void (*onComplete)(TView *));
|
||||
EMSCRIPTEN_KEEPALIVE void Engine_buildMaterialRenderThread(TEngine *tEngine, const uint8_t *materialData, size_t length, void (*onComplete)(TMaterial *));
|
||||
EMSCRIPTEN_KEEPALIVE void Engine_destroyRenderThread(TEngine *tEngine, void (*onComplete)());
|
||||
EMSCRIPTEN_KEEPALIVE void Engine_destroySwapChainRenderThread(TEngine *tEngine, TSwapChain *tSwapChain, void (*onComplete)());
|
||||
EMSCRIPTEN_KEEPALIVE void Engine_destroyViewRenderThread(TEngine *tEngine, TView *tView, void (*onComplete)());
|
||||
EMSCRIPTEN_KEEPALIVE void Engine_destroySceneRenderThread(TEngine *tEngine, TScene *tScene, void (*onComplete)());
|
||||
EMSCRIPTEN_KEEPALIVE void Engine_destroyColorGradingRenderThread(TEngine *tEngine, TColorGrading *tColorGrading, void (*onComplete)());
|
||||
EMSCRIPTEN_KEEPALIVE void Engine_destroyMaterialRenderThread(TEngine *tEngine, TMaterial *tMaterial, void (*onComplete)());
|
||||
EMSCRIPTEN_KEEPALIVE void Engine_destroyMaterialInstanceRenderThread(TEngine *tEngine, TMaterialInstance *tMaterialInstance, void (*onComplete)());
|
||||
EMSCRIPTEN_KEEPALIVE void Engine_destroySkyboxRenderThread(TEngine *tEngine, TSkybox *tSkybox, void (*onComplete)());
|
||||
@@ -78,7 +82,8 @@ namespace thermion
|
||||
EMSCRIPTEN_KEEPALIVE void Material_createInstanceRenderThread(TMaterial *tMaterial, void (*onComplete)(TMaterialInstance *));
|
||||
EMSCRIPTEN_KEEPALIVE void Material_createImageMaterialRenderThread(TEngine *tEngine, void (*onComplete)(TMaterial *));
|
||||
|
||||
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 *));
|
||||
EMSCRIPTEN_KEEPALIVE void View_setColorGradingRenderThread(TView *tView, TColorGrading *tColorGrading, void (*callback)());
|
||||
EMSCRIPTEN_KEEPALIVE void View_setBloomRenderThread(TView *tView, bool enabled, double strength, void (*callback)());
|
||||
EMSCRIPTEN_KEEPALIVE void View_setCameraRenderThread(TView *tView, TCamera *tCamera, void (*callback)());
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user