Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion java/F3DJavaBindings.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern "C"
JNIEXPORT jlong JAVA_BIND(Engine, construct)(JNIEnv*, jobject)
{
f3d::log::setVerboseLevel(f3d::log::VerboseLevel::DEBUG);
return reinterpret_cast<jlong>(new f3d::engine(f3d::engine::create()));
return reinterpret_cast<jlong>(new f3d::engine(f3d::engine::createExternalEGL()));
}

JNIEXPORT void JAVA_BIND(Engine, destroy)(JNIEnv*, jobject, jlong ptr)
Expand Down
64 changes: 36 additions & 28 deletions library/src/engine.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,52 +38,60 @@ class engine::internals
}
}

std::unique_ptr<options> Options;
std::unique_ptr<detail::window_impl> Window;
std::unique_ptr<detail::scene_impl> Scene;
std::unique_ptr<detail::interactor_impl> Interactor;
};

//----------------------------------------------------------------------------
engine::engine(
const std::optional<window::Type>& windowType, bool offscreen, const context::function& loader)
: Internals(new engine::internals)
{
// Ensure all lib initialization is done (once)
detail::init::initialize();

fs::path GetDefaultCachePath()
{
#if defined(_WIN32)
static constexpr const char* CACHE_ENV_VAR = "LOCALAPPDATA";
static constexpr const char* CACHE_ENV_VAR = "LOCALAPPDATA";
#else
static constexpr const char* CACHE_ENV_VAR = "HOME";
static constexpr const char* CACHE_ENV_VAR = "HOME";
#endif

char* env = std::getenv(CACHE_ENV_VAR);
if (!env)
{
throw engine::cache_exception(
std::string("Could not setup cache, please set ") + CACHE_ENV_VAR + " environment variable");
}
char* env = std::getenv(CACHE_ENV_VAR);
if (!env)
{
throw engine::cache_exception(
std::string("Could not setup cache, please set ") + CACHE_ENV_VAR + " environment variable");
}

fs::path cachePath(env);
fs::path cachePath(env);

#if defined(_WIN32)
cachePath /= "f3d";
cachePath /= "f3d";
#elif defined(__APPLE__)
cachePath = cachePath / "Library" / "Caches" / "f3d";
cachePath = cachePath / "Library" / "Caches" / "f3d";
#elif defined(__ANDROID__)
// XXX: Android does not have a default cache location for now
// XXX: Android does not have a default cache location for now
#elif defined(__unix__)
cachePath = cachePath / ".cache" / "f3d";
cachePath = cachePath / ".cache" / "f3d";
#else
#error "Unsupported platform"
#endif

return cachePath;
}

std::unique_ptr<options> Options;
std::unique_ptr<detail::window_impl> Window;
std::unique_ptr<detail::scene_impl> Scene;
std::unique_ptr<detail::interactor_impl> Interactor;
};

//----------------------------------------------------------------------------
engine::engine(
const std::optional<window::Type>& windowType, bool offscreen, const context::function& loader)
: Internals(new engine::internals)
{
// Ensure all lib initialization is done (once)
detail::init::initialize();

this->Internals->Options = std::make_unique<options>();

this->Internals->Window =
std::make_unique<detail::window_impl>(*this->Internals->Options, windowType, offscreen, loader);
this->Internals->Window->SetCachePath(cachePath);

#if !defined(__ANDROID__)
this->Internals->Window->SetCachePath(this->Internals->GetDefaultCachePath());
#endif

this->Internals->Scene =
std::make_unique<detail::scene_impl>(*this->Internals->Options, *this->Internals->Window);
Expand Down
Loading