refactoring
This commit is contained in:
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* This file is licensed under the zlib/libpng license, included in this
|
||||
* distribution in the file COPYING.
|
||||
*/
|
||||
|
||||
#include <future>
|
||||
#include <thread>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
#ifndef _THREADPOOL_HPP
|
||||
#define _THREADPOOL_HPP
|
||||
|
||||
namespace thermion {
|
||||
|
||||
class ThreadPool {
|
||||
std::vector<std::thread> pool;
|
||||
bool stop;
|
||||
|
||||
std::mutex access;
|
||||
std::condition_variable cond;
|
||||
std::deque<std::function<void()>> tasks;
|
||||
|
||||
public:
|
||||
explicit ThreadPool(int nr = 1) : stop(false) {
|
||||
while(nr-->0) {
|
||||
add_worker();
|
||||
}
|
||||
}
|
||||
~ThreadPool() {
|
||||
stop = true;
|
||||
for(std::thread &t : pool) {
|
||||
t.join();
|
||||
}
|
||||
pool.clear();
|
||||
}
|
||||
|
||||
template<class Rt>
|
||||
auto add_task(std::packaged_task<Rt()>& pt) -> std::future<Rt> {
|
||||
std::unique_lock<std::mutex> lock(access);
|
||||
|
||||
auto ret = pt.get_future();
|
||||
tasks.push_back([pt=std::make_shared<std::packaged_task<Rt()>>(std::move(pt))]{ (*pt)();});
|
||||
|
||||
cond.notify_one();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private:
|
||||
void add_worker() {
|
||||
std::thread t([this]() {
|
||||
while(!stop || tasks.size() > 0) {
|
||||
std::function<void()> task;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(access);
|
||||
if(tasks.empty()) {
|
||||
cond.wait_for(lock, std::chrono::duration<int, std::milli>(5));
|
||||
continue;
|
||||
}
|
||||
task = std::move(tasks.front());
|
||||
tasks.pop_front();
|
||||
}
|
||||
task();
|
||||
}
|
||||
});
|
||||
pool.push_back(std::move(t));
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif//_THREADPOOL_HPP
|
||||
|
||||
// vim: syntax=cpp11
|
||||
@@ -1,10 +1,7 @@
|
||||
#ifndef _T_GLTF_ASSET_LOADER_H
|
||||
#define _T_GLTF_ASSET_LOADER_H
|
||||
#pragma once
|
||||
|
||||
#include "APIExport.h"
|
||||
#include "APIBoundaryTypes.h"
|
||||
#include "TMaterialInstance.h"
|
||||
#include "TTexture.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
@@ -12,10 +9,10 @@ extern "C"
|
||||
#endif
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TGltfAssetLoader *GltfAssetLoader_create(TEngine *tEngine, TMaterialProvider *tMaterialProvider);
|
||||
EMSCRIPTEN_KEEPALIVE TGltfResourceLoader *GltfResourceLoader_create(TEngine *tEngine);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TFilamentAsset *GltfAssetLoader_load(
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TGltfResourceLoader *tResourceLoader,
|
||||
uint8_t *data,
|
||||
size_t length,
|
||||
uint8_t numInstances
|
||||
@@ -27,4 +24,3 @@ EMSCRIPTEN_KEEPALIVE TMaterialProvider *GltfAssetLoader_getMaterialProvider(TGlt
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
21
thermion_dart/native/include/c_api/TGltfResourceLoader.h
Normal file
21
thermion_dart/native/include/c_api/TGltfResourceLoader.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "APIExport.h"
|
||||
#include "APIBoundaryTypes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TGltfResourceLoader *GltfResourceLoader_create(TEngine *tEngine, const char *relativeResourcePath);
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_destroy(TEngine *tEngine, TGltfResourceLoader *tGltfResourceLoader);
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_asyncBeginLoad(TGltfResourceLoader *tGltfResourceLoader, TFilamentAsset *tFilamentAsset);
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_addResourceData(TGltfResourceLoader *tGltfResourceLoader, const char *uri, uint8_t *data, size_t length);
|
||||
EMSCRIPTEN_KEEPALIVE bool GltfResourceLoader_loadResources(TGltfResourceLoader *tGltfResourceLoader, TFilamentAsset *tFilamentAsset);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -24,9 +24,8 @@ extern "C"
|
||||
);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TSceneAsset *SceneAsset_loadGlb(
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TGltfResourceLoader *tResourceLoader,
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TNameComponentManager *tNameComponentManager,
|
||||
uint8_t *data,
|
||||
size_t length,
|
||||
@@ -43,6 +42,16 @@ extern "C"
|
||||
size_t numInstances
|
||||
);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE int32_t SceneAsset_getResourceUriCount(
|
||||
TSceneAsset *tSceneAsset
|
||||
);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE const char* const* SceneAsset_getResourceUris(
|
||||
TSceneAsset *tSceneAsset
|
||||
);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TFilamentAsset *SceneAsset_getFilamentAsset(TSceneAsset *tSceneAsset);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TSceneAsset *SceneAsset_createGrid(TEngine *tEngine, TMaterial * tMaterial);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void SceneAsset_destroy(TSceneAsset *tSceneAsset);
|
||||
|
||||
@@ -85,9 +85,8 @@ namespace thermion
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void SceneAsset_destroyRenderThread(TSceneAsset *tSceneAsset, void (*onComplete)());
|
||||
EMSCRIPTEN_KEEPALIVE void SceneAsset_loadGlbRenderThread(
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TGltfResourceLoader *tResourceLoader,
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TNameComponentManager *tNameComponentManager,
|
||||
uint8_t *data,
|
||||
size_t length,
|
||||
@@ -250,10 +249,14 @@ namespace thermion
|
||||
EMSCRIPTEN_KEEPALIVE void AnimationManager_resetToRestPoseRenderThread(TAnimationManager *tAnimationManager, 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 GltfResourceLoader_createRenderThread(TEngine *tEngine, const char* relativeResourcePath, void (*callback)(TGltfResourceLoader *));
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_destroyRenderThread(TEngine *tEngine, TGltfResourceLoader *tResourceLoader, void (*callback)());
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_loadResourcesRenderThread(TGltfResourceLoader *tGltfResourceLoader, TFilamentAsset *tFilamentAsset, void (*callback)(bool));
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_addResourceDataRenderThread(TGltfResourceLoader *tGltfResourceLoader, const char *uri, uint8_t *data, size_t length, void (*callback)());
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void GltfAssetLoader_loadRenderThread(
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TGltfResourceLoader *tResourceLoader,
|
||||
uint8_t *data,
|
||||
size_t length,
|
||||
uint8_t numInstances,
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace thermion
|
||||
_materialInstances(materialInstances),
|
||||
_materialInstanceCount(materialInstanceCount)
|
||||
{
|
||||
TRACE("Created GltfSceneAsset with %d reserved instances", asset->getAssetInstanceCount());
|
||||
TRACE("Created GltfSceneAsset from FilamentAsset %d with %d reserved instances", asset, asset->getAssetInstanceCount());
|
||||
}
|
||||
|
||||
~GltfSceneAsset();
|
||||
|
||||
@@ -33,18 +33,6 @@ namespace thermion
|
||||
|
||||
#endif
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TGltfResourceLoader *GltfResourceLoader_create(TEngine *tEngine) {
|
||||
auto *engine = reinterpret_cast<Engine *>(tEngine);
|
||||
auto *gltfResourceLoader = new gltfio::ResourceLoader({.engine = engine,
|
||||
.normalizeSkinningWeights = true});
|
||||
auto stbDecoder = gltfio::createStbProvider(engine);
|
||||
auto ktxDecoder = gltfio::createKtx2Provider(engine);
|
||||
gltfResourceLoader->addTextureProvider("image/ktx2", ktxDecoder);
|
||||
gltfResourceLoader->addTextureProvider("image/png", stbDecoder);
|
||||
gltfResourceLoader->addTextureProvider("image/jpeg", stbDecoder);
|
||||
|
||||
return reinterpret_cast<TGltfResourceLoader *>(gltfResourceLoader);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TGltfAssetLoader *GltfAssetLoader_create(TEngine *tEngine, TMaterialProvider *tMaterialProvider) {
|
||||
auto *engine = reinterpret_cast<filament::Engine *>(tEngine);
|
||||
@@ -66,18 +54,23 @@ EMSCRIPTEN_KEEPALIVE TGltfAssetLoader *GltfAssetLoader_create(TEngine *tEngine,
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TFilamentAsset *GltfAssetLoader_load(
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TGltfResourceLoader *tGltfResourceLoader,
|
||||
uint8_t *data,
|
||||
size_t length,
|
||||
uint8_t numInstances)
|
||||
{
|
||||
auto *engine = reinterpret_cast<filament::Engine *>(tEngine);
|
||||
auto *assetLoader = reinterpret_cast<gltfio::AssetLoader *>(tAssetLoader);
|
||||
auto *resourceLoader = reinterpret_cast<gltfio::ResourceLoader *>(tGltfResourceLoader);
|
||||
|
||||
std::vector<gltfio::FilamentInstance *> instances(numInstances);
|
||||
gltfio::FilamentAsset *asset;
|
||||
|
||||
gltfio::FilamentAsset *asset = assetLoader->createInstancedAsset((const uint8_t *)data, length, instances.data(), numInstances);
|
||||
if(numInstances > 1) {
|
||||
std::vector<gltfio::FilamentInstance *> instances(numInstances);
|
||||
asset = assetLoader->createInstancedAsset((const uint8_t *)data, length, instances.data(), numInstances);
|
||||
} else {
|
||||
asset = assetLoader->createAsset((const uint8_t *)data, length);
|
||||
}
|
||||
|
||||
if (!asset)
|
||||
{
|
||||
@@ -85,11 +78,15 @@ EMSCRIPTEN_KEEPALIVE TFilamentAsset *GltfAssetLoader_load(
|
||||
return std::nullptr_t();
|
||||
}
|
||||
|
||||
if (!resourceLoader->loadResources(asset))
|
||||
{
|
||||
Log("Unknown error loading glb asset");
|
||||
return std::nullptr_t();
|
||||
const char *const *const resourceUris = asset->getResourceUris();
|
||||
const size_t resourceUriCount = asset->getResourceUriCount();
|
||||
|
||||
Log("glTF asset : %d resource URIs, %d instances", resourceUriCount, numInstances);
|
||||
|
||||
for(int i = 0; i < resourceUriCount; i++) {
|
||||
Log("%s", resourceUris[i]);
|
||||
}
|
||||
|
||||
return reinterpret_cast<TFilamentAsset *>(asset);
|
||||
}
|
||||
|
||||
|
||||
75
thermion_dart/native/src/c_api/TGltfResourceLoader.cpp
Normal file
75
thermion_dart/native/src/c_api/TGltfResourceLoader.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "c_api/TGltfResourceLoader.h"
|
||||
|
||||
#include <filament/Engine.h>
|
||||
#include <filament/Fence.h>
|
||||
#include <filament/Material.h>
|
||||
#include <filament/RenderableManager.h>
|
||||
#include <filament/Scene.h>
|
||||
#include <filament/Skybox.h>
|
||||
#include <filament/Texture.h>
|
||||
#include <filament/TextureSampler.h>
|
||||
#include <filament/TransformManager.h>
|
||||
#include <filament/View.h>
|
||||
|
||||
#include <gltfio/Animator.h>
|
||||
#include <gltfio/AssetLoader.h>
|
||||
#include <gltfio/FilamentAsset.h>
|
||||
#include <gltfio/ResourceLoader.h>
|
||||
#include <gltfio/TextureProvider.h>
|
||||
#include <gltfio/math.h>
|
||||
#include <gltfio/materials/uberarchive.h>
|
||||
|
||||
#include <utils/EntityManager.h>
|
||||
#include <utils/NameComponentManager.h>
|
||||
|
||||
#include "Log.hpp"
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace thermion
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
using namespace filament;
|
||||
|
||||
#endif
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TGltfResourceLoader *GltfResourceLoader_create(TEngine *tEngine, const char *relativeResourcePath) {
|
||||
auto *engine = reinterpret_cast<Engine *>(tEngine);
|
||||
auto *gltfResourceLoader = new gltfio::ResourceLoader({
|
||||
.engine = engine,
|
||||
.gltfPath = relativeResourcePath
|
||||
});
|
||||
auto stbDecoder = gltfio::createStbProvider(engine);
|
||||
auto ktxDecoder = gltfio::createKtx2Provider(engine);
|
||||
gltfResourceLoader->addTextureProvider("image/ktx2", ktxDecoder);
|
||||
gltfResourceLoader->addTextureProvider("image/png", stbDecoder);
|
||||
gltfResourceLoader->addTextureProvider("image/jpeg", stbDecoder);
|
||||
|
||||
return reinterpret_cast<TGltfResourceLoader *>(gltfResourceLoader);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_destroy(TEngine *tEngine, TGltfResourceLoader *tGltfResourceLoader) {
|
||||
auto *gltfResourceLoader = reinterpret_cast<gltfio::ResourceLoader *>(tGltfResourceLoader);
|
||||
delete gltfResourceLoader;
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_addResourceData(TGltfResourceLoader *tGltfResourceLoader, const char *uri, uint8_t *data, size_t length) {
|
||||
TRACE("Adding data (length %d) for glTF resource URI %s", length, uri);
|
||||
auto *gltfResourceLoader = reinterpret_cast<gltfio::ResourceLoader *>(tGltfResourceLoader);
|
||||
for(int i = 0; i < 8; i++) {
|
||||
std::cout << static_cast<uint32_t>(data[i]) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
gltfResourceLoader->addResourceData(uri, { data, length});
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE bool GltfResourceLoader_loadResources(TGltfResourceLoader *tGltfResourceLoader, TFilamentAsset *tFilamentAsset) {
|
||||
auto *gltfResourceLoader = reinterpret_cast<gltfio::ResourceLoader *>(tGltfResourceLoader);
|
||||
auto *filamentAsset = reinterpret_cast<gltfio::FilamentAsset *>(tFilamentAsset);
|
||||
return gltfResourceLoader->loadResources(filamentAsset);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -67,9 +67,8 @@ extern "C"
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TSceneAsset *SceneAsset_loadGlb(
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TGltfResourceLoader *tResourceLoader,
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TNameComponentManager *tNameComponentManager,
|
||||
uint8_t *data,
|
||||
size_t length,
|
||||
@@ -77,20 +76,61 @@ extern "C"
|
||||
) {
|
||||
auto *engine = reinterpret_cast<filament::Engine *>(tEngine);
|
||||
auto *nameComponentManager = reinterpret_cast<utils::NameComponentManager *>(tNameComponentManager);
|
||||
auto *tFilamentAsset = GltfAssetLoader_load(tAssetLoader, tResourceLoader, data, length, numInstances);
|
||||
auto *tFilamentAsset = GltfAssetLoader_load(tEngine, tAssetLoader, data, length, numInstances);
|
||||
auto *filamentAsset = reinterpret_cast<filament::gltfio::FilamentAsset *>(tFilamentAsset);
|
||||
|
||||
auto *assetLoader = reinterpret_cast<filament::gltfio::AssetLoader *>(tAssetLoader);
|
||||
auto *resourceLoader = reinterpret_cast<filament::gltfio::ResourceLoader *>(tResourceLoader);
|
||||
auto *sceneAsset = new GltfSceneAsset(
|
||||
filamentAsset,
|
||||
assetLoader,
|
||||
engine,
|
||||
nameComponentManager
|
||||
);
|
||||
return reinterpret_cast<TSceneAsset *>(sceneAsset);
|
||||
|
||||
|
||||
return reinterpret_cast<TSceneAsset *>(sceneAsset);
|
||||
}
|
||||
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE int32_t SceneAsset_getResourceUriCount(
|
||||
TSceneAsset *tSceneAsset
|
||||
) {
|
||||
auto sceneAsset = reinterpret_cast<SceneAsset *>(tSceneAsset);
|
||||
if(sceneAsset->getType() != SceneAsset::SceneAssetType::Gltf) {
|
||||
Log("Error - not a gltf asset");
|
||||
return -1;
|
||||
}
|
||||
auto gltfAsset = reinterpret_cast<GltfSceneAsset *>(tSceneAsset);
|
||||
auto *filamentAsset = gltfAsset->getAsset();
|
||||
return filamentAsset->getResourceUriCount();
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE const char* const* SceneAsset_getResourceUris(
|
||||
TSceneAsset *tSceneAsset
|
||||
) {
|
||||
auto sceneAsset = reinterpret_cast<SceneAsset *>(tSceneAsset);
|
||||
if(sceneAsset->getType() != SceneAsset::SceneAssetType::Gltf) {
|
||||
Log("Error - not a gltf asset");
|
||||
return nullptr;
|
||||
}
|
||||
auto gltfAsset = reinterpret_cast<GltfSceneAsset *>(tSceneAsset);
|
||||
auto *filamentAsset = gltfAsset->getAsset();
|
||||
return filamentAsset->getResourceUris();
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TFilamentAsset *SceneAsset_getFilamentAsset(TSceneAsset *tSceneAsset) {
|
||||
auto sceneAsset = reinterpret_cast<SceneAsset *>(tSceneAsset);
|
||||
if(sceneAsset->getType() != SceneAsset::SceneAssetType::Gltf) {
|
||||
Log("Error - not a gltf asset");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto gltfAsset = reinterpret_cast<GltfSceneAsset *>(tSceneAsset);
|
||||
auto *filamentAsset = gltfAsset->getAsset();
|
||||
TRACE("SceneAsset %d FilamentAsset %d", sceneAsset, filamentAsset);
|
||||
return reinterpret_cast<TFilamentAsset *>(filamentAsset);
|
||||
}
|
||||
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TSceneAsset *SceneAsset_createGrid(TEngine *tEngine, TMaterial* tMaterial) {
|
||||
auto *engine = reinterpret_cast<filament::Engine *>(tEngine);
|
||||
auto *material = reinterpret_cast<filament::Material *>(tMaterial);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "c_api/TAnimationManager.h"
|
||||
#include "c_api/TEngine.h"
|
||||
#include "c_api/TGltfAssetLoader.h"
|
||||
#include "c_api/TGltfResourceLoader.h"
|
||||
#include "c_api/TRenderer.h"
|
||||
#include "c_api/TRenderTicker.h"
|
||||
#include "c_api/TRenderTarget.h"
|
||||
@@ -18,12 +19,9 @@
|
||||
#include "c_api/TView.h"
|
||||
#include "c_api/ThermionDartRenderThreadApi.h"
|
||||
|
||||
|
||||
#include "rendering/RenderLoop.hpp"
|
||||
#include "Log.hpp"
|
||||
|
||||
#include "ThreadPool.hpp"
|
||||
|
||||
using namespace thermion;
|
||||
using namespace std::chrono_literals;
|
||||
#include <time.h>
|
||||
@@ -360,9 +358,8 @@ extern "C"
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void SceneAsset_loadGlbRenderThread(
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TGltfResourceLoader *tResourceLoader,
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TNameComponentManager *tNameComponentManager,
|
||||
uint8_t *data,
|
||||
size_t length,
|
||||
@@ -372,7 +369,7 @@ extern "C"
|
||||
std::packaged_task<void()> lambda(
|
||||
[=]
|
||||
{
|
||||
auto sceneAsset = SceneAsset_loadGlb(tAssetLoader, tResourceLoader, tEngine, tNameComponentManager, data, length, numInstances);
|
||||
auto sceneAsset = SceneAsset_loadGlb(tEngine, tAssetLoader, tNameComponentManager, data, length, numInstances);
|
||||
callback(sceneAsset);
|
||||
});
|
||||
auto fut = _rl->add_task(lambda);
|
||||
@@ -875,19 +872,54 @@ extern "C"
|
||||
auto fut = _rl->add_task(lambda);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_createRenderThread(TEngine *tEngine, void (*callback)(TGltfResourceLoader *)) {
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_createRenderThread(TEngine *tEngine, const char* relativeResourcePath, void (*callback)(TGltfResourceLoader *)) {
|
||||
std::packaged_task<void()> lambda(
|
||||
[=]() mutable
|
||||
{
|
||||
auto loader = GltfResourceLoader_create(tEngine);
|
||||
auto loader = GltfResourceLoader_create(tEngine, relativeResourcePath);
|
||||
callback(loader);
|
||||
});
|
||||
auto fut = _rl->add_task(lambda);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_destroyRenderThread(TEngine *tEngine, TGltfResourceLoader *tResourceLoader, void (*callback)()) {
|
||||
std::packaged_task<void()> lambda(
|
||||
[=]() mutable
|
||||
{
|
||||
GltfResourceLoader_destroy(tEngine, tResourceLoader);
|
||||
callback();
|
||||
});
|
||||
auto fut = _rl->add_task(lambda);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_loadResourcesRenderThread(TGltfResourceLoader *tGltfResourceLoader, TFilamentAsset *tFilamentAsset, void (*callback)(bool)) {
|
||||
std::packaged_task<void()> lambda(
|
||||
[=]() mutable
|
||||
{
|
||||
auto result = GltfResourceLoader_loadResources(tGltfResourceLoader, tFilamentAsset);
|
||||
callback(result);
|
||||
});
|
||||
auto fut = _rl->add_task(lambda);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void GltfResourceLoader_addResourceDataRenderThread(
|
||||
TGltfResourceLoader *tGltfResourceLoader,
|
||||
const char *uri,
|
||||
uint8_t *data,
|
||||
size_t length,
|
||||
void (*callback)()) {
|
||||
std::packaged_task<void()> lambda(
|
||||
[=]() mutable
|
||||
{
|
||||
GltfResourceLoader_addResourceData(tGltfResourceLoader, uri, data, length);
|
||||
callback();
|
||||
});
|
||||
auto fut = _rl->add_task(lambda);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void GltfAssetLoader_loadRenderThread(
|
||||
TEngine *tEngine,
|
||||
TGltfAssetLoader *tAssetLoader,
|
||||
TGltfResourceLoader *tResourceLoader,
|
||||
uint8_t *data,
|
||||
size_t length,
|
||||
uint8_t numInstances,
|
||||
@@ -896,7 +928,7 @@ extern "C"
|
||||
std::packaged_task<void()> lambda(
|
||||
[=]() mutable
|
||||
{
|
||||
auto loader = GltfAssetLoader_load(tAssetLoader, tResourceLoader, data, length, numInstances);
|
||||
auto loader = GltfAssetLoader_load(tEngine, tAssetLoader, data, length, numInstances);
|
||||
callback(loader);
|
||||
});
|
||||
auto fut = _rl->add_task(lambda);
|
||||
|
||||
Reference in New Issue
Block a user