initial work to re-implement FFI with background thread render loop
This commit is contained in:
@@ -81,6 +81,8 @@ namespace polyvox {
|
||||
void setBackgroundImage(const char* resourcePath, bool fillHeight);
|
||||
void clearBackgroundImage();
|
||||
void setBackgroundImagePosition(float x, float y, bool clamp);
|
||||
|
||||
void setViewFrustumCulling(bool enabled);
|
||||
void moveCameraToAsset(EntityId entityId);
|
||||
|
||||
void setCameraExposure(float aperture, float shutterSpeed, float sensitivity);
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
typedef int32_t EntityId;
|
||||
|
||||
const void* create_filament_viewer(const void* const context, const ResourceLoaderWrapper* const loader);
|
||||
ResourceLoaderWrapper* make_resource_loader(LoadResourceFromOwner loadFn, FreeResourceFromOwner freeFn, void* owner);
|
||||
void delete_filament_viewer(const void* const viewer);
|
||||
ResourceLoaderWrapper* make_resource_loader(LoadFilamentResourceFromOwner loadFn, FreeFilamentResourceFromOwner freeFn, void* owner);
|
||||
void destroy_filament_viewer(const void* const viewer);
|
||||
void* get_asset_manager(const void* const viewer);
|
||||
void create_render_target(const void* const viewer, uint32_t textureId, uint32_t width, uint32_t height);
|
||||
void clear_background_image(const void* const viewer);
|
||||
@@ -26,6 +26,7 @@ void clear_lights(const void* const viewer);
|
||||
EntityId load_glb(void *assetManager, const char *assetPath, bool unlit);
|
||||
EntityId load_gltf(void *assetManager, const char *assetPath, const char *relativePath);
|
||||
bool set_camera(const void* const viewer, EntityId asset, const char *nodeName);
|
||||
void set_view_frustum_culling(const void* const viewer, bool enabled);
|
||||
void render(const void* const viewer, uint64_t frameTimeInNanos);
|
||||
void create_swap_chain(const void* const viewer, const void* const window, uint32_t width, uint32_t height);
|
||||
void destroy_swap_chain(const void* const viewer);
|
||||
@@ -82,8 +83,6 @@ void get_morph_target_name(void* assetManager, EntityId asset, const char *meshN
|
||||
int get_morph_target_name_count(void* assetManager, EntityId asset, const char *meshName);
|
||||
void remove_asset(const void* const viewer, EntityId asset);
|
||||
void clear_assets(const void* const viewer);
|
||||
void load_texture(void* assetManager, EntityId asset, const char *assetPath, int renderableIndex);
|
||||
void set_texture(void* assetManager, EntityId asset);
|
||||
bool set_material_color(void* assetManager, EntityId asset, const char* meshName, int materialIndex, const float r, const float g, const float b, const float a);
|
||||
void transform_to_unit_cube(void* assetManager, EntityId asset);
|
||||
void set_position(void* assetManager, EntityId asset, float x, float y, float z);
|
||||
|
||||
83
ios/include/PolyvoxFilamentFFIApi.h
Normal file
83
ios/include/PolyvoxFilamentFFIApi.h
Normal file
@@ -0,0 +1,83 @@
|
||||
#ifndef _POLYVOX_FILAMENT_FFI_API_H
|
||||
#define _POLYVOX_FILAMENT_FFI_API_H
|
||||
|
||||
#include "PolyvoxFilamentApi.h"
|
||||
|
||||
///
|
||||
/// This header replicates most of the methods in PolyvoxFilamentApi.h, and is only intended to be used to generate client FFI bindings.
|
||||
/// The intention is that calling one of these methods will call its respective method in PolyvoxFilamentApi.h, but wrapped in some kind of thread runner to ensure thread safety.
|
||||
///
|
||||
|
||||
typedef int32_t EntityId;
|
||||
|
||||
const void* create_filament_viewer_ffi(void* const context, const ResourceLoaderWrapper* const loader);
|
||||
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);
|
||||
void load_ibl_ffi(void* const viewer, const char *iblPath, float intensity);
|
||||
void remove_skybox_ffi(void* const viewer);
|
||||
void remove_ibl_ffi(void* const viewer);
|
||||
EntityId add_light_ffi(void* const viewer, uint8_t type, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows);
|
||||
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);
|
||||
bool set_camera_ffi(void* const viewer, EntityId asset, const char *nodeName);
|
||||
void apply_weights_ffi(
|
||||
void* assetManager,
|
||||
EntityId asset,
|
||||
const char *const entityName,
|
||||
float *const weights,
|
||||
int count
|
||||
);
|
||||
void set_morph_target_weights_ffi(
|
||||
void* assetManager,
|
||||
EntityId asset,
|
||||
const char *const entityName,
|
||||
const float *const morphData,
|
||||
int numWeights
|
||||
);
|
||||
bool set_morph_animation_ffi(
|
||||
void* assetManager,
|
||||
EntityId asset,
|
||||
const char *const entityName,
|
||||
const float *const morphData,
|
||||
const int* const morphIndices,
|
||||
int numMorphTargets,
|
||||
int numFrames,
|
||||
float frameLengthInMs);
|
||||
|
||||
void set_bone_animation_ffi(
|
||||
void* assetManager,
|
||||
EntityId asset,
|
||||
const float* const frameData,
|
||||
int numFrames,
|
||||
int numBones,
|
||||
const char** const boneNames,
|
||||
const char** const meshName,
|
||||
int numMeshTargets,
|
||||
float frameLengthInMs);
|
||||
|
||||
void play_animation_ffi(void* assetManager, EntityId asset, int index, bool loop, bool reverse, bool replaceActive, float crossfade);
|
||||
void set_animation_frame_ffi(void* assetManager, EntityId asset, int animationIndex, int animationFrame);
|
||||
void stop_animation_ffi(void* assetManager, EntityId asset, int index);
|
||||
int get_animation_count_ffi(void* assetManager, EntityId asset);
|
||||
void get_animation_name_ffi(void* assetManager, EntityId asset, char *const outPtr, int index);
|
||||
float get_animation_duration_ffi(void* assetManager, EntityId asset, int index);
|
||||
void get_morph_target_name_ffi(void* assetManager, EntityId asset, const char *meshName, char *const outPtr, int index);
|
||||
int get_morph_target_name_count_ffi(void* assetManager, EntityId asset, const char *meshName);
|
||||
|
||||
#endif // _POLYVOX_FILAMENT_FFI_API_H
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#if defined(__cplusplus)
|
||||
#include "Log.hpp"
|
||||
extern "C" {
|
||||
#endif
|
||||
//
|
||||
@@ -28,6 +27,10 @@ extern "C" {
|
||||
struct ResourceBuffer {
|
||||
#if defined(__cplusplus)
|
||||
ResourceBuffer(const void* const data, const uint32_t size, const uint32_t id) : data(data), size(size), id(id) {};
|
||||
ResourceBuffer(const ResourceBuffer& rb) : data(rb.data), size(rb.size), id(rb.id) { };
|
||||
ResourceBuffer(const ResourceBuffer&& rb) : data(rb.data), size(rb.size), id(rb.id) { };
|
||||
ResourceBuffer& operator=(const ResourceBuffer& other) = delete;
|
||||
|
||||
#endif
|
||||
const void * const data;
|
||||
const uint32_t size;
|
||||
@@ -35,41 +38,41 @@ extern "C" {
|
||||
};
|
||||
|
||||
typedef struct ResourceBuffer ResourceBuffer;
|
||||
typedef ResourceBuffer (*LoadResource)(const char* uri);
|
||||
typedef ResourceBuffer (*LoadResourceFromOwner)(const char* const, void* const owner);
|
||||
typedef void (*FreeResource)(ResourceBuffer);
|
||||
typedef void (*FreeResourceFromOwner)(ResourceBuffer, void* const owner);
|
||||
typedef ResourceBuffer (*LoadFilamentResource)(const char* uri);
|
||||
typedef ResourceBuffer (*LoadFilamentResourceFromOwner)(const char* const, void* const owner);
|
||||
typedef void (*FreeFilamentResource)(ResourceBuffer);
|
||||
typedef void (*FreeFilamentResourceFromOwner)(ResourceBuffer, void* const owner);
|
||||
|
||||
// this may be compiled as either C or C++, depending on which compiler is being invoked (e.g. binding to Swift will compile as C).
|
||||
// the former does not allow default initialization to be specified inline), so we need to explicitly set the unused members to nullptr
|
||||
struct ResourceLoaderWrapper {
|
||||
#if defined(__cplusplus)
|
||||
ResourceLoaderWrapper(LoadResource loader, FreeResource freeResource) : mLoadResource(loader), mFreeResource(freeResource), mLoadResourceFromOwner(nullptr), mFreeResourceFromOwner(nullptr),
|
||||
ResourceLoaderWrapper(LoadFilamentResource loader, FreeFilamentResource freeResource) : mLoadFilamentResource(loader), mFreeFilamentResource(freeResource), mLoadFilamentResourceFromOwner(nullptr), mFreeFilamentResourceFromOwner(nullptr),
|
||||
mOwner(nullptr) {}
|
||||
|
||||
ResourceLoaderWrapper(LoadResourceFromOwner loader, FreeResourceFromOwner freeResource, void* const owner) : mLoadResource(nullptr), mFreeResource(nullptr), mLoadResourceFromOwner(loader), mFreeResourceFromOwner(freeResource), mOwner(owner) {
|
||||
ResourceLoaderWrapper(LoadFilamentResourceFromOwner loader, FreeFilamentResourceFromOwner freeResource, void* const owner) : mLoadFilamentResource(nullptr), mFreeFilamentResource(nullptr), mLoadFilamentResourceFromOwner(loader), mFreeFilamentResourceFromOwner(freeResource), mOwner(owner) {
|
||||
|
||||
};
|
||||
|
||||
ResourceBuffer load(const char* uri) const {
|
||||
if(mLoadResourceFromOwner) {
|
||||
return mLoadResourceFromOwner(uri, mOwner);
|
||||
if(mLoadFilamentResourceFromOwner) {
|
||||
return mLoadFilamentResourceFromOwner(uri, mOwner);
|
||||
}
|
||||
return mLoadResource(uri);
|
||||
return mLoadFilamentResource(uri);
|
||||
}
|
||||
|
||||
void free(ResourceBuffer rb) const {
|
||||
if(mFreeResourceFromOwner) {
|
||||
mFreeResourceFromOwner(rb, mOwner);
|
||||
if(mFreeFilamentResourceFromOwner) {
|
||||
mFreeFilamentResourceFromOwner(rb, mOwner);
|
||||
} else {
|
||||
mFreeResource(rb);
|
||||
mFreeFilamentResource(rb);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
LoadResource mLoadResource;
|
||||
FreeResource mFreeResource;
|
||||
LoadResourceFromOwner mLoadResourceFromOwner;
|
||||
FreeResourceFromOwner mFreeResourceFromOwner;
|
||||
LoadFilamentResource mLoadFilamentResource;
|
||||
FreeFilamentResource mFreeFilamentResource;
|
||||
LoadFilamentResourceFromOwner mLoadFilamentResourceFromOwner;
|
||||
FreeFilamentResourceFromOwner mFreeFilamentResourceFromOwner;
|
||||
void* mOwner;
|
||||
};
|
||||
typedef struct ResourceLoaderWrapper ResourceLoaderWrapper;
|
||||
|
||||
Reference in New Issue
Block a user