more FFI work
This commit is contained in:
@@ -128,6 +128,11 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
||||
let instance:SwiftPolyvoxFilamentPlugin = Unmanaged<SwiftPolyvoxFilamentPlugin>.fromOpaque(resourcesPtr!).takeUnretainedValue()
|
||||
instance.resources.removeObject(forKey:rbuf.id)
|
||||
}
|
||||
|
||||
var markTextureFrameAvailable : @convention(c) (UnsafeMutableRawPointer?) -> () = { rbuf, resourcesPtr in
|
||||
let instance:SwiftPolyvoxFilamentPlugin = Unmanaged<SwiftPolyvoxFilamentPlugin>.fromOpaque(resourcesPtr!).takeUnretainedValue()
|
||||
instance.registry.textureFrameAvailable(instance.flutterTextureId)
|
||||
}
|
||||
|
||||
@objc func doRender() {
|
||||
if(viewer != nil && rendering) {
|
||||
@@ -241,6 +246,9 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
||||
update_viewport_and_camera_projection(viewer, UInt32(args[0] as! Int64), UInt32(args[1] as! Int64), 1.0)
|
||||
set_frame_interval(viewer, Float(frameInterval))
|
||||
result(unsafeBitCast(viewer, to:Int64.self))
|
||||
case "textureFrameAvailable":
|
||||
self.registry.textureFrameAvailable(flutterTextureId)
|
||||
result(nil)
|
||||
case "getAssetManager":
|
||||
let assetManager = get_asset_manager(viewer)
|
||||
result(unsafeBitCast(assetManager, to:Int64.self))
|
||||
|
||||
@@ -10,18 +10,18 @@
|
||||
|
||||
typedef int32_t EntityId;
|
||||
|
||||
const void* create_filament_viewer_ffi(void* const context, const ResourceLoaderWrapper* const loader);
|
||||
void* const create_filament_viewer_ffi(void* const context, const ResourceLoaderWrapper* const loader, void (*renderCallback)(void* const renderCallbackOwner), void* const renderCallbackOwner);
|
||||
void create_swap_chain_ffi(void* const viewer, void* const surface, uint32_t width, uint32_t height);
|
||||
void create_render_target_ffi(void* const viewer, uint32_t nativeTextureId, uint32_t width, uint32_t height);
|
||||
void destroy_filament_viewer_ffi(void* const viewer);
|
||||
void render_ffi(void* const viewer);
|
||||
void set_rendering_ffi(void* const viewer, bool rendering);
|
||||
void set_frame_interval_ffi(float frameInterval);
|
||||
void update_viewport_and_camera_projection_ffi(void* const viewer, const uint32_t width, const uint32_t height, const float scaleFactor);
|
||||
void create_render_target_ffi(void* const viewer, uint32_t textureId, uint32_t width, uint32_t height);
|
||||
void set_background_color_ffi(void* const viewer, const float r, const float g, const float b, const float a);
|
||||
void clear_background_image_ffi(void* const viewer);
|
||||
void set_background_image_ffi(void* const viewer, const char *path, bool fillHeight);
|
||||
void set_background_image_position_ffi(void* const viewer, float x, float y, bool clamp);
|
||||
void set_background_color_ffi(void* const viewer, const float r, const float g, const float b, const float a);
|
||||
void set_tone_mapping_ffi(void* const viewer, int toneMapping);
|
||||
void set_bloom_ffi(void* const viewer, float strength);
|
||||
void load_skybox_ffi(void* const viewer, const char *skyboxPath);
|
||||
@@ -33,8 +33,8 @@ void remove_light_ffi(void* const viewer, EntityId entityId);
|
||||
void clear_lights_ffi(void* const viewer);
|
||||
EntityId load_glb_ffi(void* const assetManager, const char *assetPath, bool unlit);
|
||||
EntityId load_gltf_ffi(void* const assetManager, const char *assetPath, const char *relativePath);
|
||||
void remove_asset_ffi(const void* const viewer, EntityId asset);
|
||||
void clear_assets_ffi(const void* const viewer);
|
||||
void remove_asset_ffi(void* const const viewer, EntityId asset);
|
||||
void clear_assets_ffi(void* const const viewer);
|
||||
bool set_camera_ffi(void* const viewer, EntityId asset, const char *nodeName);
|
||||
void apply_weights_ffi(
|
||||
void* assetManager,
|
||||
|
||||
@@ -311,7 +311,7 @@ extern "C" {
|
||||
void* assetManager,
|
||||
EntityId asset) {
|
||||
auto names = ((AssetManager*)assetManager)->getAnimationNames(asset);
|
||||
return names->size();
|
||||
return (int)names->size();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void get_animation_name(
|
||||
@@ -326,12 +326,8 @@ extern "C" {
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT int get_morph_target_name_count(void* assetManager, EntityId asset, const char* meshName) {
|
||||
//std::packaged_task<int()> lambda([=]() mutable {
|
||||
unique_ptr<vector<string>> names = ((AssetManager*)assetManager)->getMorphTargetNames(asset, meshName);
|
||||
return names->size();
|
||||
|
||||
|
||||
//return fut.get();
|
||||
return (int)names->size();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void get_morph_target_name(void* assetManager, EntityId asset, const char* meshName, char* const outPtr, int index ) {
|
||||
|
||||
@@ -28,6 +28,10 @@ public:
|
||||
_tasks.pop_front();
|
||||
std::this_thread::sleep_for(
|
||||
std::chrono::milliseconds(_frameIntervalInMilliseconds));
|
||||
if(_rendering) {
|
||||
doRender();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
task();
|
||||
@@ -39,10 +43,27 @@ public:
|
||||
_t->join();
|
||||
}
|
||||
|
||||
void* const createViewer(void* const context, const ResourceLoaderWrapper* const loader, void (*renderCallback)(void*), void* const owner) {
|
||||
_renderCallback = renderCallback;
|
||||
_renderCallbackOwner = owner;
|
||||
std::packaged_task<FilamentViewer* const()> lambda([&]() mutable {
|
||||
return new FilamentViewer(context, loader);
|
||||
});
|
||||
auto fut = add_task(lambda);
|
||||
fut.wait();
|
||||
_viewer = fut.get();
|
||||
return (void* const)_viewer;
|
||||
}
|
||||
|
||||
void setRendering(bool rendering) {
|
||||
_rendering = rendering;
|
||||
}
|
||||
|
||||
void doRender() {
|
||||
render(_viewer, 0);
|
||||
_renderCallback(_renderCallbackOwner);
|
||||
}
|
||||
|
||||
template<class Rt>
|
||||
auto add_task(std::packaged_task<Rt()>& pt) -> std::future<Rt> {
|
||||
std::unique_lock<std::mutex> lock(_access);
|
||||
@@ -57,6 +78,8 @@ private:
|
||||
int _frameIntervalInMilliseconds = 1000 / 60;
|
||||
std::mutex _access;
|
||||
FilamentViewer* _viewer = nullptr;
|
||||
void (*_renderCallback)(void* const) = nullptr;
|
||||
void* _renderCallbackOwner = nullptr;
|
||||
std::thread* _t = nullptr;
|
||||
std::condition_variable _cond;
|
||||
std::deque<std::function<void()>> _tasks;
|
||||
@@ -71,19 +94,32 @@ extern "C" {
|
||||
|
||||
static RenderLoop* _rl;
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT const void* create_filament_viewer_ffi(const void* context, const ResourceLoaderWrapper* const loader) {
|
||||
FLUTTER_PLUGIN_EXPORT void* const create_filament_viewer_ffi(void* const context, const ResourceLoaderWrapper* const loader, void (*renderCallback)(void* const renderCallbackOwner), void* const renderCallbackOwner) {
|
||||
if(!_rl) {
|
||||
_rl = new RenderLoop();
|
||||
}
|
||||
std::packaged_task<const void*()> lambda([&]() mutable {
|
||||
return (const void*) new FilamentViewer(context, loader);
|
||||
return _rl->createViewer(context, loader, renderCallback, renderCallbackOwner);
|
||||
}
|
||||
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void create_swap_chain_ffi(void* const viewer, void* const surface, uint32_t width, uint32_t height) {
|
||||
std::packaged_task<void()> lambda([&]() mutable {
|
||||
create_swap_chain(viewer, surface, width, height);
|
||||
});
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
return fut.get();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void update_viewport_and_camera_projection_ffi(void* const viewer, const uint32_t width, const uint32_t height, const float scaleFactor);
|
||||
FLUTTER_PLUGIN_EXPORT void create_render_target_ffi(void* const viewer, uint32_t nativeTextureId, uint32_t width, uint32_t height) {
|
||||
std::packaged_task<void()> lambda([&]() mutable {
|
||||
create_render_target(viewer, nativeTextureId, width, height);
|
||||
});
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void update_viewport_and_camera_projection_ffi(void* const viewer, const uint32_t width, const uint32_t height, const float scaleFactor) {
|
||||
std::packaged_task<void()> lambda([&]() mutable {
|
||||
update_viewport_and_camera_projection(viewer, width, height, scaleFactor);
|
||||
});
|
||||
@@ -92,7 +128,7 @@ extern "C" {
|
||||
}
|
||||
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT bool set_rendering(bool rendering) {
|
||||
FLUTTER_PLUGIN_EXPORT bool set_rendering_ffi(bool rendering) {
|
||||
if(!_rl) {
|
||||
return false;
|
||||
}
|
||||
@@ -102,13 +138,13 @@ extern "C" {
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void render_ffi(void* const viewer) {
|
||||
std::packaged_task<void()> lambda([&]() mutable {
|
||||
render(viewer, 0);
|
||||
_rl->doRender();
|
||||
});
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_background_color_ffi(const void* const viewer, const float r, const float g, const float b, const float a) {
|
||||
FLUTTER_PLUGIN_EXPORT void set_background_color_ffi(void* const viewer, const float r, const float g, const float b, const float a) {
|
||||
std::packaged_task<void()> lambda([&]() mutable {
|
||||
set_background_color(viewer, r, g,b, a);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user