Skip to content

Commit

Permalink
Create EngineWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Feb 21, 2024
1 parent d8ad127 commit f92dfec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
19 changes: 18 additions & 1 deletion package/cpp/FilamentProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <memory>
#include <string>
#include <vector>
#include "core/EngineWrapper.h"

namespace margelo {

Expand All @@ -17,7 +18,8 @@ using namespace facebook;
std::vector<jsi::PropNameID> FilamentProxy::getPropertyNames(jsi::Runtime& runtime) {
std::vector<jsi::PropNameID> result;
// TODO(hanno): add more methods here?
result.push_back(jsi::PropNameID::forUtf8(runtime, std::string("loadModel")));
result.push_back(jsi::PropNameID::forUtf8(runtime, std::string("loadModel")));
result.push_back(jsi::PropNameID::forUtf8(runtime, std::string("createEngine")));
return result;
}

Expand All @@ -42,6 +44,21 @@ jsi::Value FilamentProxy::get(jsi::Runtime& runtime, const jsi::PropNameID& prop
});
});
}
if (name == "createEngine") {
return jsi::Function::createFromHostFunction(
runtime, jsi::PropNameID::forUtf8(runtime, "createEngine"), 1,
[this](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* arguments, size_t count) -> jsi::Value {
if (count != 1) {
[[unlikely]];
throw jsi::JSError(runtime, "createEngine: Expected 1 argument(s), but received " + std::to_string(count) + "!");
}
std::string backend = arguments[0].asString(runtime).utf8(runtime);
// TODO: Parse backend from string
EngineWrapper engine(filament::Engine::Backend::OPENGL);

return jsi::Value(13);
});
}

return jsi::Value::undefined();
}
Expand Down
4 changes: 2 additions & 2 deletions package/cpp/core/EngineWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

namespace margelo {

EngineWrapper::EngineWrapper() {
_engine = Engine::create(filament::Engine::Backend::OPENGL);
EngineWrapper::EngineWrapper(filament::Engine::Backend backend) {
_engine = Engine::create(backend);
}

EngineWrapper::~EngineWrapper() {
Expand Down
2 changes: 1 addition & 1 deletion package/cpp/core/EngineWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using namespace filament;

class EngineWrapper {
public:
explicit EngineWrapper();
explicit EngineWrapper(filament::Engine::Backend backend);
~EngineWrapper();

void setSurfaceProvider(std::shared_ptr<SurfaceProvider> surfaceProvider);
Expand Down

0 comments on commit f92dfec

Please sign in to comment.