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 {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user