Skip to content

Commit

Permalink
Fixes for Android (#1145)
Browse files Browse the repository at this point in the history
  • Loading branch information
Meakk authored Jan 8, 2024
1 parent 519edac commit 2f95ee3
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 2 additions & 0 deletions java/Camera.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ public Camera(long nativeAddress) {
public native double[] getPosition();
public native void setPosition(double[] pt);

public native void resetToBounds();

private long mNativeAddress;
}
6 changes: 3 additions & 3 deletions java/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public class Engine implements AutoCloseable {
System.loadLibrary("f3d-java");
}

public Engine(Window.Type type) {
mNativeAddress = construct(type); // instantiate the native engine
public Engine() {
mNativeAddress = construct(); // instantiate the native engine
mLoader = new Loader(mNativeAddress);
mOptions = new Options(mNativeAddress);
mWindow = new Window(mNativeAddress);
Expand All @@ -30,7 +30,7 @@ public void close() {
public Options getOptions() { return mOptions; }
public Window getWindow() { return mWindow; }

private native long construct(Window.Type type);
private native long construct();
private native void destroy(long nativeAddress);

private Loader mLoader;
Expand Down
15 changes: 8 additions & 7 deletions java/F3DJavaBindings.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,10 @@ extern "C"
env->ReleaseStringUTFChars(path, str);
}

JNIEXPORT jlong JAVA_BIND(Engine, construct)(JNIEnv* env, jobject self, jobject windowType)
JNIEXPORT jlong JAVA_BIND(Engine, construct)(JNIEnv*, jobject)
{
// read cursor
jmethodID method =
env->GetMethodID(env->FindClass("app/f3d/F3D/Window$Type"), "ordinal", "()I");
jint itype = env->CallIntMethod(windowType, method);

return reinterpret_cast<jlong>(new f3d::engine(static_cast<f3d::window::Type>(itype)));
f3d::log::setVerboseLevel(f3d::log::VerboseLevel::DEBUG);
return reinterpret_cast<jlong>(new f3d::engine());
}

JNIEXPORT void JAVA_BIND(Engine, destroy)(JNIEnv*, jobject, jlong ptr)
Expand Down Expand Up @@ -197,4 +193,9 @@ extern "C"
GetEngine(env, self)->getWindow().getCamera().setPosition({ arr[0], arr[1], arr[2] });
env->ReleaseDoubleArrayElements(pt, arr, 0);
}

JNIEXPORT void JAVA_BIND(Camera, resetToBounds)(JNIEnv* env, jobject self)
{
GetEngine(env, self)->getWindow().getCamera().resetToBounds();
}
}
2 changes: 0 additions & 2 deletions java/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

public class Window {

public enum Type { NONE, NATIVE, NATIVE_OFFSCREEN, EXTERNAL }

public Window(long nativeAddress) {
mNativeAddress = nativeAddress;
mCamera = new Camera(nativeAddress);
Expand Down
2 changes: 1 addition & 1 deletion java/testing/TestJavaBindings.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void main(String[] args) {
Engine.autoloadPlugins();

// Always use try-with-resources idiom to ensure the native engine is released
try (Engine engine = new Engine(Window.Type.NATIVE_OFFSCREEN)) {
try (Engine engine = new Engine()) {

Camera camera = engine.getWindow().getCamera();

Expand Down
3 changes: 1 addition & 2 deletions library/src/camera_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ camera& camera_impl::resetToDefault()
//----------------------------------------------------------------------------
camera& camera_impl::resetToBounds([[maybe_unused]] double zoomFactor)
{

#if VTK_VERSION_NUMBER < VTK_VERSION_CHECK(9, 0, 20210331)
#if __ANDROID__ || VTK_VERSION_NUMBER < VTK_VERSION_CHECK(9, 0, 20210331)
this->Internals->VTKRenderer->ResetCamera();
#else
if (this->Internals->VTKRenderer->GetRenderWindow()->IsA("vtkExternalOpenGLRenderWindow"))
Expand Down

0 comments on commit 2f95ee3

Please sign in to comment.