separate skybox/ibl creation from KTX decoding
This commit is contained in:
@@ -729,6 +729,23 @@ external void Texture_generateMipMaps(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Pointer<TTexture> Function(
|
||||
ffi.Pointer<TEngine>,
|
||||
ffi.Pointer<ffi.Uint8>,
|
||||
ffi.Size,
|
||||
ffi.Pointer<ffi.Float>,
|
||||
ffi.Uint32,
|
||||
VoidCallback)>(isLeaf: true)
|
||||
external ffi.Pointer<TTexture> Texture_decodeKtx(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
ffi.Pointer<ffi.Uint8> ktxData,
|
||||
int length,
|
||||
ffi.Pointer<ffi.Float> sphericalHarmonics,
|
||||
int requestId,
|
||||
VoidCallback onTextureUploadComplete,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Pointer<TLinearImage> Function(
|
||||
ffi.Uint32, ffi.Uint32, ffi.Uint32)>(isLeaf: true)
|
||||
@@ -1558,30 +1575,20 @@ external ffi.Pointer<TScene> Engine_createScene(
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Pointer<TSkybox> Function(
|
||||
ffi.Pointer<TEngine>,
|
||||
ffi.Pointer<ffi.Uint8>,
|
||||
ffi.Size,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
|
||||
ffi.Pointer<TEngine>, ffi.Pointer<TTexture>)>(isLeaf: true)
|
||||
external ffi.Pointer<TSkybox> Engine_buildSkybox(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
ffi.Pointer<ffi.Uint8> ktxData,
|
||||
int length,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onTextureUploadComplete,
|
||||
ffi.Pointer<TTexture> tTexture,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Pointer<TIndirectLight> Function(
|
||||
ffi.Pointer<TEngine>,
|
||||
ffi.Pointer<ffi.Uint8>,
|
||||
ffi.Size,
|
||||
ffi.Float,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
|
||||
ffi.Pointer<TIndirectLight> Function(ffi.Pointer<TEngine>,
|
||||
ffi.Pointer<TTexture>, ffi.Float, ffi.Pointer<ffi.Float>)>(isLeaf: true)
|
||||
external ffi.Pointer<TIndirectLight> Engine_buildIndirectLight(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
ffi.Pointer<ffi.Uint8> ktxData,
|
||||
int length,
|
||||
ffi.Pointer<TTexture> tTexture,
|
||||
double intensity,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onTextureUploadComplete,
|
||||
ffi.Pointer<ffi.Float> harmonics,
|
||||
);
|
||||
|
||||
@ffi.Native<ffi.Void Function(ffi.Pointer<TEngine>, ffi.Pointer<TSkybox>)>(
|
||||
@@ -1887,6 +1894,28 @@ external void Texture_generateMipMapsRenderThread(
|
||||
VoidCallback onComplete,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(
|
||||
ffi.Pointer<TEngine>,
|
||||
ffi.Pointer<ffi.Uint8>,
|
||||
ffi.Size,
|
||||
ffi.Pointer<ffi.Float>,
|
||||
ffi.Uint32,
|
||||
VoidCallback,
|
||||
ffi.Pointer<
|
||||
ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TTexture>)>>)>(
|
||||
isLeaf: true)
|
||||
external void Texture_decodeKtxRenderThread(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
ffi.Pointer<ffi.Uint8> ktxData,
|
||||
int length,
|
||||
ffi.Pointer<ffi.Float> sphericalHarmonics,
|
||||
int requestId,
|
||||
VoidCallback onTextureUploadComplete,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TTexture>)>>
|
||||
onComplete,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(ffi.Pointer<TEngine>, ffi.Pointer<TTexture>, ffi.Uint32,
|
||||
VoidCallback)>(isLeaf: true)
|
||||
@@ -1936,40 +1965,36 @@ external void Engine_executeRenderThread(
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(
|
||||
ffi.Pointer<TEngine>,
|
||||
ffi.Pointer<ffi.Uint8>,
|
||||
ffi.Size,
|
||||
ffi.Pointer<
|
||||
ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TSkybox>)>>,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
|
||||
ffi.Void Function(
|
||||
ffi.Pointer<TEngine>,
|
||||
ffi.Pointer<TTexture>,
|
||||
ffi.Pointer<
|
||||
ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TSkybox>)>>)>(
|
||||
isLeaf: true)
|
||||
external void Engine_buildSkyboxRenderThread(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
ffi.Pointer<ffi.Uint8> skyboxData,
|
||||
int length,
|
||||
ffi.Pointer<TTexture> tTexture,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TSkybox>)>>
|
||||
onComplete,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onTextureUploadComplete,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(
|
||||
ffi.Pointer<TEngine>,
|
||||
ffi.Pointer<ffi.Uint8>,
|
||||
ffi.Size,
|
||||
ffi.Pointer<TTexture>,
|
||||
ffi.Float,
|
||||
ffi.Pointer<ffi.Float>,
|
||||
ffi.Pointer<
|
||||
ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TIndirectLight>)>>,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(ffi.Pointer<TIndirectLight>)>>)>(isLeaf: true)
|
||||
external void Engine_buildIndirectLightRenderThread(
|
||||
ffi.Pointer<TEngine> tEngine,
|
||||
ffi.Pointer<ffi.Uint8> iblData,
|
||||
int length,
|
||||
ffi.Pointer<TTexture> tTexture,
|
||||
double intensity,
|
||||
ffi.Pointer<ffi.Float> harmonics,
|
||||
ffi.Pointer<
|
||||
ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TIndirectLight>)>>
|
||||
onComplete,
|
||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onTextureUploadComplete,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
@@ -3045,6 +3070,13 @@ external void RenderableManager_setPriority(
|
||||
int priority,
|
||||
);
|
||||
|
||||
@ffi.Native<Aabb3 Function(ffi.Pointer<TRenderableManager>, EntityId)>(
|
||||
isLeaf: true)
|
||||
external Aabb3 RenderableManager_getBoundingBox(
|
||||
ffi.Pointer<TRenderableManager> tRenderableManager,
|
||||
int entityId,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Pointer<TSceneAsset> Function(
|
||||
ffi.Pointer<TEngine>,
|
||||
@@ -3462,6 +3494,9 @@ external bool AnimationManager_setGltfAnimationFrame(
|
||||
int frame,
|
||||
);
|
||||
|
||||
typedef VoidCallbackFunction = ffi.Void Function(ffi.Int32 requestId);
|
||||
typedef DartVoidCallbackFunction = void Function(int requestId);
|
||||
typedef VoidCallback = ffi.Pointer<ffi.NativeFunction<VoidCallbackFunction>>;
|
||||
typedef EntityId = ffi.Int32;
|
||||
typedef DartEntityId = int;
|
||||
|
||||
@@ -4094,9 +4129,6 @@ sealed class TBackend {
|
||||
static const BACKEND_NOOP = 4;
|
||||
}
|
||||
|
||||
typedef VoidCallbackFunction = ffi.Void Function(ffi.Int32 requestId);
|
||||
typedef DartVoidCallbackFunction = void Function(int requestId);
|
||||
typedef VoidCallback = ffi.Pointer<ffi.NativeFunction<VoidCallbackFunction>>;
|
||||
typedef FilamentRenderCallbackFunction = ffi.Void Function(
|
||||
ffi.Pointer<ffi.Void> owner);
|
||||
typedef DartFilamentRenderCallbackFunction = void Function(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'package:thermion_dart/src/filament/src/implementation/background_image.dart';
|
||||
import 'package:thermion_dart/src/filament/src/implementation/ffi_texture.dart';
|
||||
import '../../../../filament/src/implementation/ffi_asset.dart';
|
||||
import 'package:thermion_dart/src/filament/src/implementation/ffi_filament_app.dart';
|
||||
import '../../../../filament/src/implementation/ffi_scene.dart';
|
||||
@@ -232,56 +233,83 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
Future? _skyboxTextureUploadComplete;
|
||||
FFITexture? _skyboxTexture;
|
||||
Pointer<TSkybox>? _skybox;
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
@override
|
||||
Future loadSkybox(String skyboxPath) async {
|
||||
await removeSkybox();
|
||||
|
||||
var data = await FilamentApp.instance!.loadResource(skyboxPath);
|
||||
|
||||
skybox = await withPointerCallback<TSkybox>((cb) {
|
||||
Engine_buildSkyboxRenderThread(
|
||||
app.engine,
|
||||
data.address,
|
||||
data.length,
|
||||
cb,
|
||||
nullptr,
|
||||
);
|
||||
final completer = Completer();
|
||||
|
||||
_skyboxTextureUploadComplete =
|
||||
withVoidCallback((requestId, onTextureUploadComplete) async {
|
||||
var skyboxTexturePointer = await withPointerCallback<TTexture>((cb) {
|
||||
Texture_decodeKtxRenderThread(app.engine, data.address, data.length,
|
||||
nullptr, requestId, onTextureUploadComplete, cb);
|
||||
});
|
||||
_skyboxTexture = FFITexture(app.engine, skyboxTexturePointer);
|
||||
|
||||
_skybox = await withPointerCallback<TSkybox>((cb) {
|
||||
Engine_buildSkyboxRenderThread(app.engine, _skyboxTexture!.pointer, cb);
|
||||
});
|
||||
Scene_setSkybox(scene.scene, _skybox!);
|
||||
completer.complete();
|
||||
}).then((_) async {
|
||||
_skyboxTextureUploadComplete = null;
|
||||
});
|
||||
Scene_setSkybox(scene.scene, skybox!);
|
||||
await completer.future;
|
||||
}
|
||||
|
||||
Pointer<TIndirectLight>? indirectLight;
|
||||
|
||||
Pointer<TSkybox>? skybox;
|
||||
Pointer<TTexture>? _iblTexture;
|
||||
Pointer<TIndirectLight>? _indirectLight;
|
||||
Future? _iblTextureUploadComplete;
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
@override
|
||||
Future loadIbl(String lightingPath, {double intensity = 30000}) async {
|
||||
late Pointer stackPtr;
|
||||
if (FILAMENT_WASM) {
|
||||
//stackPtr = stackSave();
|
||||
}
|
||||
var data = await FilamentApp.instance!.loadResource(lightingPath);
|
||||
await removeIbl();
|
||||
|
||||
indirectLight = await withPointerCallback<TIndirectLight>((cb) {
|
||||
Engine_buildIndirectLightRenderThread(
|
||||
app.engine,
|
||||
data.address,
|
||||
data.length,
|
||||
intensity,
|
||||
cb,
|
||||
nullptr,
|
||||
);
|
||||
});
|
||||
if (FILAMENT_WASM) {
|
||||
//stackRestore(stackPtr);
|
||||
final completer = Completer();
|
||||
_iblTextureUploadComplete =
|
||||
withVoidCallback((requestId, onTextureUploadComplete) async {
|
||||
late Pointer stackPtr;
|
||||
if (FILAMENT_WASM) {
|
||||
//stackPtr = stackSave();
|
||||
}
|
||||
|
||||
var data = await FilamentApp.instance!.loadResource(lightingPath);
|
||||
|
||||
var harmonics = Float32List(27);
|
||||
|
||||
_iblTexture = await withPointerCallback<TTexture>((cb) {
|
||||
Texture_decodeKtxRenderThread(app.engine, data.address, data.length,
|
||||
harmonics.address, requestId, onTextureUploadComplete, cb);
|
||||
});
|
||||
|
||||
_indirectLight = await withPointerCallback<TIndirectLight>((cb) {
|
||||
Engine_buildIndirectLightRenderThread(
|
||||
app.engine, _iblTexture!, intensity, harmonics.address, cb);
|
||||
});
|
||||
if (FILAMENT_WASM) {
|
||||
//stackRestore(stackPtr);
|
||||
data.free();
|
||||
}
|
||||
data.free();
|
||||
}
|
||||
data.free();
|
||||
Scene_setIndirectLight(scene.scene, indirectLight!);
|
||||
Scene_setIndirectLight(scene.scene, _indirectLight!);
|
||||
completer.complete();
|
||||
}).then((_) {
|
||||
_iblTextureUploadComplete = null;
|
||||
});
|
||||
await completer.future;
|
||||
}
|
||||
|
||||
///
|
||||
@@ -289,7 +317,7 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
///
|
||||
@override
|
||||
Future rotateIbl(Matrix3 rotationMatrix) async {
|
||||
if (indirectLight == null) {
|
||||
if (_indirectLight == null) {
|
||||
throw Exception("No IBL loaded");
|
||||
}
|
||||
|
||||
@@ -298,7 +326,7 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
//stackPtr = stackSave();
|
||||
}
|
||||
|
||||
IndirectLight_setRotation(indirectLight!, rotationMatrix.storage.address);
|
||||
IndirectLight_setRotation(_indirectLight!, rotationMatrix.storage.address);
|
||||
|
||||
if (FILAMENT_WASM) {
|
||||
//stackRestore(stackPtr);
|
||||
@@ -315,17 +343,23 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
throw ViewerDisposedException();
|
||||
}
|
||||
|
||||
if (skybox != null) {
|
||||
if (_skyboxTextureUploadComplete != null) {
|
||||
await _skyboxTextureUploadComplete;
|
||||
_skyboxTextureUploadComplete = null;
|
||||
}
|
||||
|
||||
if (_skybox != null) {
|
||||
await withVoidCallback(
|
||||
(requestId, cb) => Engine_destroySkyboxRenderThread(
|
||||
app.engine,
|
||||
skybox!,
|
||||
_skybox!,
|
||||
requestId,
|
||||
cb,
|
||||
),
|
||||
);
|
||||
skybox = null;
|
||||
}
|
||||
_skybox = null;
|
||||
_skyboxTexture = null;
|
||||
}
|
||||
|
||||
///
|
||||
@@ -333,17 +367,22 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
///
|
||||
@override
|
||||
Future removeIbl() async {
|
||||
if (indirectLight != null) {
|
||||
if (_iblTextureUploadComplete != null) {
|
||||
await _iblTextureUploadComplete!;
|
||||
_iblTextureUploadComplete = null;
|
||||
}
|
||||
if (_indirectLight != null) {
|
||||
Scene_setIndirectLight(scene.scene, nullptr);
|
||||
await withVoidCallback(
|
||||
(requestId, cb) => Engine_destroyIndirectLightRenderThread(
|
||||
app.engine,
|
||||
indirectLight!,
|
||||
_indirectLight!,
|
||||
requestId,
|
||||
cb,
|
||||
),
|
||||
);
|
||||
indirectLight = null;
|
||||
_indirectLight = null;
|
||||
_iblTexture = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user