add gltfio FFI methods and expose texture/render target creation directly

This commit is contained in:
Nick Fisher
2025-03-17 18:53:36 +08:00
parent 2244359edd
commit bff76f184e
15 changed files with 622 additions and 202 deletions

View File

@@ -37,6 +37,9 @@ extern "C"
typedef struct TTexture TTexture;
typedef struct TTextureSampler TTextureSampler;
typedef struct TLinearImage TLinearImage;
typedef struct TGltfAssetLoader TGltfAssetLoader;
typedef struct TGltfResourceLoader TGltfResourceLoader;
typedef struct TFilamentAsset TFilamentAsset;
struct TMaterialKey {
bool doubleSided;
@@ -160,6 +163,13 @@ extern "C"
extern uint64_t TSWAP_CHAIN_CONFIG_APPLE_CVPIXELBUFFER;
extern uint64_t TSWAP_CHAIN_CONFIG_HAS_STENCIL_BUFFER;
extern uint64_t TSWAP_CHAIN_CONFIG_TRANSPARENT;
extern uint64_t TSWAP_CHAIN_CONFIG_READABLE;
extern uint64_t TSWAP_CHAIN_CONFIG_APPLE_CVPIXELBUFFER;
extern uint64_t TSWAP_CHAIN_CONFIG_HAS_STENCIL_BUFFER;
#ifdef __cplusplus
}

View File

@@ -25,6 +25,7 @@ EMSCRIPTEN_KEEPALIVE TEngine *Engine_create(TBackend backend);
EMSCRIPTEN_KEEPALIVE TRenderer *Engine_createRenderer(TEngine *tEngine);
EMSCRIPTEN_KEEPALIVE TSwapChain *Engine_createSwapChain(TEngine *tEngine, void *window, uint64_t flags);
EMSCRIPTEN_KEEPALIVE TSwapChain *Engine_createHeadlessSwapChain(TEngine *tEngine, uint32_t width, uint32_t height, uint64_t flags);
EMSCRIPTEN_KEEPALIVE TCamera *Engine_createCamera(TEngine* tEngine);
EMSCRIPTEN_KEEPALIVE TView *Engine_createView(TEngine *tEngine);
EMSCRIPTEN_KEEPALIVE TCamera *Engine_getCameraComponent(TEngine* tEngine, EntityId entityId);
@@ -32,13 +33,7 @@ EMSCRIPTEN_KEEPALIVE TTransformManager *Engine_getTransformManager(TEngine *engi
EMSCRIPTEN_KEEPALIVE TRenderableManager *Engine_getRenderableManager(TEngine *engine);
EMSCRIPTEN_KEEPALIVE TLightManager *Engine_getLightManager(TEngine *engine);
EMSCRIPTEN_KEEPALIVE TEntityManager *Engine_getEntityManager(TEngine *engine);
EMSCRIPTEN_KEEPALIVE TTexture *Engine_buildTexture(TEngine *engine,
uint32_t width,
uint32_t height,
uint32_t depth,
uint8_t levels,
TTextureSamplerType sampler,
TTextureFormat format);
EMSCRIPTEN_KEEPALIVE void Engine_destroyTexture(TEngine *tEngine, TTexture *tTexture);
EMSCRIPTEN_KEEPALIVE TFence *Engine_createFence(TEngine *tEngine);

View File

@@ -0,0 +1,30 @@
#ifndef _T_GLTF_ASSET_LOADER_H
#define _T_GLTF_ASSET_LOADER_H
#include "APIExport.h"
#include "APIBoundaryTypes.h"
#include "TMaterialInstance.h"
#include "TTexture.h"
#include "ResourceBuffer.hpp"
#include "MathUtils.hpp"
#ifdef __cplusplus
extern "C"
{
#endif
EMSCRIPTEN_KEEPALIVE TGltfAssetLoader *GltfAssetLoader_create(TEngine *tEngine, TMaterialProvider *tMaterialProvider);
EMSCRIPTEN_KEEPALIVE TGltfResourceLoader *GltfResourceLoader_create(TEngine *tEngine);
EMSCRIPTEN_KEEPALIVE TFilamentAsset *GltfAssetLoader_load(
TGltfAssetLoader *tAssetLoader,
TGltfResourceLoader *tResourceLoader,
uint8_t *data,
size_t length,
uint8_t numInstances
);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,28 @@
#ifndef _T_RENDERTARGET_H
#define _T_RENDERTARGET_H
#include "APIExport.h"
#include "APIBoundaryTypes.h"
#include "TMaterialInstance.h"
#include "TTexture.h"
#include "ResourceBuffer.hpp"
#include "MathUtils.hpp"
#ifdef __cplusplus
extern "C"
{
#endif
EMSCRIPTEN_KEEPALIVE TRenderTarget *RenderTarget_create(
TEngine *tEngine,
uint32_t width,
uint32_t height,
TTexture *color,
TTexture *depth
);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -17,6 +17,8 @@ extern "C"
EMSCRIPTEN_KEEPALIVE void Scene_addEntity(TScene* tScene, EntityId entityId);
EMSCRIPTEN_KEEPALIVE void Scene_setSkybox(TScene* tScene, TSkybox *skybox);
EMSCRIPTEN_KEEPALIVE void Scene_addFilamentAsset(TScene* tScene, TFilamentAsset *asset);
#ifdef __cplusplus

View File

@@ -192,6 +192,29 @@ enum TPixelDataType {
PIXELDATATYPE_UINT_2_10_10_10_REV, //!< unsigned normalized 10 bits RGB, 2 bits alpha
};
enum TTextureUsage {
TEXTURE_USAGE_NONE = 0x0000,
TEXTURE_USAGE_COLOR_ATTACHMENT = 0x0001, //!< Texture can be used as a color attachment
TEXTURE_USAGE_DEPTH_ATTACHMENT = 0x0002, //!< Texture can be used as a depth attachment
TEXTURE_USAGE_STENCIL_ATTACHMENT = 0x0004, //!< Texture can be used as a stencil attachment
TEXTURE_USAGE_UPLOADABLE = 0x0008, //!< Data can be uploaded into this texture (default)
TEXTURE_USAGE_SAMPLEABLE = 0x0010, //!< Texture can be sampled (default)
TEXTURE_USAGE_SUBPASS_INPUT = 0x0020, //!< Texture can be used as a subpass input
TEXTURE_USAGE_BLIT_SRC = 0x0040, //!< Texture can be used the source of a blit()
TEXTURE_USAGE_BLIT_DST = 0x0080, //!< Texture can be used the destination of a blit()
TEXTURE_USAGE_PROTECTED = 0x0100, //!< Texture can be used the destination of a blit()
TEXTURE_USAGE_DEFAULT = TEXTURE_USAGE_UPLOADABLE | TEXTURE_USAGE_SAMPLEABLE //!< Default texture usage
};
EMSCRIPTEN_KEEPALIVE TTexture *Texture_build(TEngine *engine,
uint32_t width,
uint32_t height,
uint32_t depth,
uint8_t levels,
uint16_t tUsage,
intptr_t import,
TTextureSamplerType sampler,
TTextureFormat format);
EMSCRIPTEN_KEEPALIVE bool Texture_loadImage(TEngine *tEngine, TTexture *tTexture, TLinearImage *tImage, TPixelDataFormat bufferFormat, TPixelDataType pixelDataType);
EMSCRIPTEN_KEEPALIVE bool Texture_setImage(
TEngine *tEngine,
@@ -224,6 +247,7 @@ EMSCRIPTEN_KEEPALIVE bool Texture_setImageWithDepth(
EMSCRIPTEN_KEEPALIVE uint32_t Texture_getWidth(TTexture *tTexture, uint32_t level);
EMSCRIPTEN_KEEPALIVE uint32_t Texture_getHeight(TTexture *tTexture, uint32_t level);
EMSCRIPTEN_KEEPALIVE uint32_t Texture_getDepth(TTexture *tTexture, uint32_t level);
EMSCRIPTEN_KEEPALIVE TTextureUsage Texture_getUsage(TTexture *tTexture, uint32_t level);
EMSCRIPTEN_KEEPALIVE TLinearImage *Image_createEmpty(uint32_t width,uint32_t height,uint32_t channel);
EMSCRIPTEN_KEEPALIVE TLinearImage *Image_decode(uint8_t* data, size_t length, const char* name = "image");

View File

@@ -14,9 +14,11 @@ extern "C"
#endif
EMSCRIPTEN_KEEPALIVE TViewer *Viewer_create(const void *const context, const void *const loader, void *const platform, const char *uberArchivePath);
EMSCRIPTEN_KEEPALIVE TRenderer *Viewer_getRenderer(TViewer *tViewer);
EMSCRIPTEN_KEEPALIVE void Viewer_destroy(TViewer *viewer);
EMSCRIPTEN_KEEPALIVE TSceneManager *Viewer_getSceneManager(TViewer *viewer);
EMSCRIPTEN_KEEPALIVE TRenderTarget* Viewer_createRenderTarget(TViewer *viewer, intptr_t texture, uint32_t width, uint32_t height);
EMSCRIPTEN_KEEPALIVE TRenderTarget* Viewer_createRenderTarget(TViewer *viewer, intptr_t colorTextureId, intptr_t depthTextureId, uint32_t width, uint32_t height);
EMSCRIPTEN_KEEPALIVE void Viewer_destroyRenderTarget(TViewer *viewer, TRenderTarget* tRenderTarget);
EMSCRIPTEN_KEEPALIVE TSwapChain *Viewer_createSwapChain(TViewer *viewer, const void *const window);
EMSCRIPTEN_KEEPALIVE TSwapChain *Viewer_createHeadlessSwapChain(TViewer *viewer, uint32_t width, uint32_t height);
@@ -28,6 +30,7 @@ extern "C"
TView *view,
TSwapChain *swapChain,
uint8_t *pixelBuffer,
bool useFence,
void (*callback)(void));
EMSCRIPTEN_KEEPALIVE void Viewer_captureRenderTarget(
TViewer *viewer,
@@ -35,6 +38,7 @@ extern "C"
TSwapChain *swapChain,
TRenderTarget *renderTarget,
uint8_t *pixelBuffer,
bool useFence,
void (*callback)(void));
EMSCRIPTEN_KEEPALIVE TView* Viewer_createView(TViewer *viewer);
EMSCRIPTEN_KEEPALIVE TView* Viewer_getViewAt(TViewer *viewer, int index);

View File

@@ -57,11 +57,13 @@ namespace thermion
EMSCRIPTEN_KEEPALIVE void Engine_createViewRenderThread(TEngine *tEngine, void (*onComplete)(TView *));
EMSCRIPTEN_KEEPALIVE void Engine_buildMaterialRenderThread(TEngine *tEngine, const uint8_t *materialData, size_t length, void (*onComplete)(TMaterial *));
EMSCRIPTEN_KEEPALIVE void Engine_destroyMaterialRenderThread(TEngine *tEngine, TMaterial *tMaterial, void (*onComplete)());
EMSCRIPTEN_KEEPALIVE void Engine_buildTextureRenderThread(TEngine *engine,
EMSCRIPTEN_KEEPALIVE void Texture_buildRenderThread(TEngine *engine,
uint32_t width,
uint32_t height,
uint32_t depth,
uint8_t levels,
uint16_t tUsage,
intptr_t import,
TTextureSamplerType sampler,
TTextureFormat format,
void (*onComplete)(TTexture*)
@@ -228,6 +230,14 @@ namespace thermion
void (*onComplete)(bool)
);
EMSCRIPTEN_KEEPALIVE void RenderTarget_getColorTextureRenderThread(TRenderTarget *tRenderTarget, void (*onComplete)(TTexture *));
EMSCRIPTEN_KEEPALIVE void RenderTarget_createRenderThread(
TEngine *tEngine,
uint32_t width,
uint32_t height,
TTexture *color,
TTexture *depth,
void (*onComplete)(TRenderTarget *)
);
// TextureSampler methods
EMSCRIPTEN_KEEPALIVE void TextureSampler_createRenderThread(void (*onComplete)(TTextureSampler*));
@@ -297,6 +307,19 @@ namespace thermion
EMSCRIPTEN_KEEPALIVE void set_post_processing_render_thread(TViewer *viewer, bool enabled);
EMSCRIPTEN_KEEPALIVE void reset_to_rest_pose_render_thread(TSceneManager *sceneManager, EntityId entityId, void (*callback)());
EMSCRIPTEN_KEEPALIVE void GltfAssetLoader_createRenderThread(TEngine *tEngine, TMaterialProvider *tMaterialProvider, void (*callback)(TGltfAssetLoader *));
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_createRenderThread(TEngine *tEngine, void (*callback)(TGltfResourceLoader *));
EMSCRIPTEN_KEEPALIVE void GltfAssetLoader_loadRenderThread(
TGltfAssetLoader *tAssetLoader,
TGltfResourceLoader *tResourceLoader,
uint8_t *data,
size_t length,
uint8_t numInstances,
void (*callback)(TFilamentAsset *)
);
EMSCRIPTEN_KEEPALIVE void Scene_addFilamentAssetRenderThread(TScene* tScene, TFilamentAsset *tAsset, void (*callback)());
#ifdef __cplusplus
}