feat: working implementation of multiple widgets on macos

This commit is contained in:
Nick Fisher
2024-09-30 13:45:57 +08:00
parent 921a994eb6
commit c80c163212
22 changed files with 383 additions and 184 deletions

View File

@@ -39,4 +39,18 @@ class FFIView extends View {
final engine = Viewer_getEngine(viewer);
return FFICamera(View_getCamera(view), engine);
}
@override
Future setAntiAliasing(bool msaa, bool fxaa, bool taa) async {
View_setAntiAliasing(view, msaa, fxaa, taa);
}
@override
Future setPostProcessing(bool enabled) async {
View_setPostProcessing(view, enabled);
}
Future setRenderable(bool renderable) async {
Viewer_markViewRenderable(viewer, view, renderable);
}
}

View File

@@ -65,7 +65,6 @@ external void Viewer_destroySwapChain(
@ffi.Native<
ffi.Bool Function(
ffi.Pointer<TViewer>,
ffi.Pointer<TView>,
ffi.Pointer<TSwapChain>,
ffi.Uint64,
ffi.Pointer<ffi.Void>,
@@ -76,7 +75,6 @@ external void Viewer_destroySwapChain(
ffi.Pointer<ffi.Void>)>(isLeaf: true)
external bool Viewer_render(
ffi.Pointer<TViewer> viewer,
ffi.Pointer<TView> view,
ffi.Pointer<TSwapChain> swapChain,
int frameTimeInNanos,
ffi.Pointer<ffi.Void> pixelBuffer,
@@ -146,6 +144,15 @@ external ffi.Pointer<TSwapChain> Viewer_getSwapChainAt(
int index,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TViewer>, ffi.Pointer<TView>, ffi.Bool)>(isLeaf: true)
external void Viewer_markViewRenderable(
ffi.Pointer<TViewer> viewer,
ffi.Pointer<TView> view,
bool renderable,
);
@ffi.Native<ffi.Pointer<TEngine> Function(ffi.Pointer<TViewer>)>(isLeaf: true)
external ffi.Pointer<TEngine> Viewer_getEngine(
ffi.Pointer<TViewer> viewer,
@@ -1451,6 +1458,15 @@ external void Viewer_captureRenderTargetRenderThread(
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onComplete,
);
@ffi.Native<
ffi.Void Function(ffi.Pointer<TViewer>, ffi.Pointer<TSwapChain>,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
external void Viewer_requestFrameRenderThread(
ffi.Pointer<TViewer> viewer,
ffi.Pointer<TSwapChain> tSwapChain,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onComplete,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TViewer>)>(isLeaf: true)
external void destroy_filament_viewer_render_thread(
ffi.Pointer<TViewer> viewer,
@@ -1471,19 +1487,6 @@ external void set_rendering_render_thread(
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onComplete,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TViewer>,
ffi.Pointer<TView>,
ffi.Pointer<TSwapChain>,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
external void Viewer_requestFrameRenderThread(
ffi.Pointer<TViewer> viewer,
ffi.Pointer<TView> view,
ffi.Pointer<TSwapChain> tSwapChain,
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onComplete,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<TViewer>, ffi.Float)>(isLeaf: true)
external void set_frame_interval_render_thread(
ffi.Pointer<TViewer> viewer,
@@ -1888,14 +1891,25 @@ external void View_setBloom(
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TView>, ffi.Pointer<TEngine>, ffi.Int32)>(isLeaf: true)
external void View_setToneMapping(
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,
ToneMapping toneMapping,
) =>
_View_setToneMapping(
tView,
tEngine,
toneMapping.value,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<TView>, ffi.Bool, ffi.Bool, ffi.Bool)>(isLeaf: true)
@@ -2224,10 +2238,20 @@ final class TViewport extends ffi.Struct {
external int height;
}
abstract class ToneMapping {
static const int ACES = 0;
static const int FILMIC = 1;
static const int LINEAR = 2;
enum ToneMapping {
ACES(0),
FILMIC(1),
LINEAR(2);
final int value;
const ToneMapping(this.value);
static ToneMapping fromValue(int value) => switch (value) {
0 => ACES,
1 => FILMIC,
2 => LINEAR,
_ => throw ArgumentError("Unknown value for ToneMapping: $value"),
};
}
typedef GizmoPickCallback

View File

@@ -2040,10 +2040,8 @@ class ThermionViewerFFI extends ThermionViewer {
});
final swapChain = Viewer_getSwapChainAt(_viewer!, 0);
final view = Viewer_getViewAt(_viewer!, 0);
Viewer_requestFrameRenderThread(
_viewer!, view, swapChain, callback.nativeFunction);
Viewer_requestFrameRenderThread(_viewer!, swapChain, callback.nativeFunction);
await completer.future;
}

View File

@@ -1,6 +1,7 @@
library shared_types;
export 'swap_chain.dart';
export 'view.dart';
export 'render_target.dart';
export 'camera.dart';
export 'material.dart';

View File

@@ -15,4 +15,7 @@ abstract class View {
Future setRenderTarget(covariant RenderTarget? renderTarget);
Future setCamera(covariant Camera camera);
Camera getCamera();
Future setPostProcessing(bool enabled);
Future setAntiAliasing(bool msaa, bool fxaa, bool taa);
Future setRenderable(bool renderable);
}