Skip to content
Snippets Groups Projects
Commit 912a2763 authored by Joachim Pouderoux's avatar Joachim Pouderoux
Browse files

Fix Android build

Fix several CMake and cxx issues when building VTK for Android.
parent 694c0611
Branches
No related tags found
No related merge requests found
......@@ -27,7 +27,7 @@ set(ANDROID_NDK ${_ANDROID_NDK_DEFAULT} CACHE PATH
if (NOT EXISTS "${ANDROID_NDK}/platforms")
message(FATAL_ERROR "Please set a valid ANDROID_NDK path")
endif()
set(ANDROID_NATIVE_API_LEVEL "21" CACHE STRING "Android Native API Level")
set(ANDROID_NATIVE_API_LEVEL "27" CACHE STRING "Android Native API Level")
set(ANDROID_ARCH_ABI "armeabi" CACHE STRING "Target Android architecture/abi")
# find android
......
......@@ -21,12 +21,15 @@ if (ANDROID OR APPLE_IOS)
)
elseif (ANDROID)
unset(OPENGL_INCLUDE_DIR CACHE)
unset(OPENGL_gl_LIBRARY CACHE)
unset(OPENGL_gles3_LIBRARY CACHE)
unset(OPENGL_egl_LIBRARY CACHE)
find_path(OPENGL_INCLUDE_DIR GLES3/gl3.h)
find_library(OPENGL_gl_LIBRARY NAMES GLESv3)
find_library(OPENGL_egl_LIBRARY NAMES EGL)
set(_ANDROID_INC_PATH ${CMAKE_ANDROID_NDK}/sysroot/usr/include)
set(_ANDROID_LIB_PATH ${CMAKE_ANDROID_NDK}/platforms/android-${CMAKE_SYSTEM_VERSION}/arch-${CMAKE_ANDROID_ARCH}/usr/lib)
find_path(OPENGL_INCLUDE_DIR GLES3/gl3.h ${_ANDROID_INC_PATH})
find_library(OPENGL_gles3_LIBRARY NAMES GLESv3 PATHS ${_ANDROID_LIB_PATH})
find_library(OPENGL_egl_LIBRARY NAMES EGL PATHS ${_ANDROID_LIB_PATH})
endif()
else()
# Choose static or shared libraries.
......
......@@ -48,12 +48,12 @@ public:
* New lines are converted to carriage return new lines.
*/
void DisplayText(const char*) override;
virtual void DisplayErrorText(const char*);
virtual void DisplayWarningText(const char*);
virtual void DisplayGenericWarningText(const char*);
void DisplayErrorText(const char*) override;
void DisplayWarningText(const char*) override;
void DisplayGenericWarningText(const char*) override;
///@}
virtual void DisplayDebugText(const char*);
void DisplayDebugText(const char*) override;
protected:
vtkAndroidOutputWindow();
......
......@@ -17,7 +17,7 @@
#if defined(_WIN32) && !defined(VTK_USE_X)
#include "vtkWin32OutputWindow.h"
#endif
#if defined(ANDROID)
#if defined(__ANDROID__) || defined(ANDROID)
#include "vtkAndroidOutputWindow.h"
#endif
......
......@@ -31,8 +31,9 @@
#include <cassert>
#include <sstream>
#ifdef ANDROID
#if defined(__ANDROID__) || defined(ANDROID)
#include <android/native_window.h>
#include <vtkAndroidRenderWindowInteractor.h>
#endif
namespace
......@@ -139,7 +140,7 @@ struct vtkEGLRenderWindow::vtkInternals
vtkEGLRenderWindow::vtkEGLRenderWindow()
{
this->Internals = new vtkInternals();
this->OwnWindow = 1;
this->OwnWindow = true;
this->ScreenSize[0] = 1920;
this->ScreenSize[1] = 1080;
......@@ -338,7 +339,7 @@ void vtkEGLRenderWindow::ResizeWindow(int width, int height)
*/
EGLint surfaceType, clientAPI;
const EGLint* contextAttribs;
#ifdef ANDROID
#if defined(__ANDROID__) || defined(ANDROID)
surfaceType = EGL_WINDOW_BIT;
clientAPI = EGL_OPENGL_ES2_BIT;
const EGLint contextES2[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
......@@ -354,7 +355,7 @@ void vtkEGLRenderWindow::ResizeWindow(int width, int height)
EGL_RED_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_DEPTH_SIZE, 8, EGL_RENDERABLE_TYPE, clientAPI,
EGL_NONE };
#if !defined(ANDROID)
#if !defined(__ANDROID__) && !defined(ANDROID)
const EGLint surface_attribs[] = { EGL_WIDTH, width, EGL_HEIGHT, height, EGL_NONE };
#endif
......@@ -375,7 +376,7 @@ void vtkEGLRenderWindow::ResizeWindow(int width, int height)
EGLint major = 0, minor = 0;
vtkEGLDisplayInitializationHelper::Initialize(impl->Display, &major, &minor);
#if !defined(ANDROID)
#if !defined(__ANDROID__) && !defined(ANDROID)
if (major <= 1 && minor < 4)
{
vtkErrorMacro("Only EGL 1.4 and greater allows OpenGL as client API. "
......@@ -396,7 +397,7 @@ void vtkEGLRenderWindow::ResizeWindow(int width, int height)
return;
}
#ifdef ANDROID
#if defined(__ANDROID__) || defined(ANDROID)
EGLint format = 0;
/* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
* guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
......@@ -417,13 +418,22 @@ void vtkEGLRenderWindow::ResizeWindow(int width, int height)
eglDestroySurface(impl->Display, impl->Surface);
}
#ifdef ANDROID
#if defined(__ANDROID__) || defined(ANDROID)
impl->Surface = eglCreateWindowSurface(impl->Display, config, impl->Window, nullptr);
#else
impl->Surface = eglCreatePbufferSurface(impl->Display, config, surface_attribs);
#endif
this->Mapped = this->ShowWindow;
this->OwnWindow = 1;
this->OwnWindow = true;
#if defined(__ANDROID__) || defined(ANDROID)
vtkAndroidRenderWindowInteractor* interactor =
vtkAndroidRenderWindowInteractor::SafeDownCast(this->Interactor);
if (interactor)
{
interactor->SetOwnWindow(this->OwnWindow);
}
#endif
this->MakeCurrent();
......@@ -485,9 +495,18 @@ void vtkEGLRenderWindow::WindowInitialize(void)
this->OpenGLInit();
// for offscreen EGL always turn on point sprites
#if !defined(ANDROID) && defined(GL_POINT_SPRITE)
#if !defined(__ANDROID__) && !defined(ANDROID) && defined(GL_POINT_SPRITE)
glEnable(GL_POINT_SPRITE);
#endif
#if defined(__ANDROID__) || defined(ANDROID)
vtkAndroidRenderWindowInteractor* interactor =
vtkAndroidRenderWindowInteractor::SafeDownCast(this->Interactor);
if (interactor)
{
interactor->SetOwnWindow(this->OwnWindow);
}
#endif
}
// Initialize the rendering window.
......@@ -608,8 +627,17 @@ void vtkEGLRenderWindow::SetPosition(int x, int y)
// Set this RenderWindow to a pre-existing window.
void vtkEGLRenderWindow::SetWindowInfo(const char*)
{
this->OwnWindow = 0;
this->Mapped = 1;
this->OwnWindow = false;
#if defined(__ANDROID__) || defined(ANDROID)
vtkAndroidRenderWindowInteractor* interactor =
vtkAndroidRenderWindowInteractor::SafeDownCast(this->Interactor);
if (interactor)
{
interactor->SetOwnWindow(this->OwnWindow);
}
#endif
}
void vtkEGLRenderWindow::SetWindowName(const char* name)
......
......@@ -537,7 +537,7 @@ void vtkAndroidRenderWindowInteractor::Initialize()
// get the info we need from the RenderingWindow
ren = this->RenderWindow;
if (ren->GetOwnWindow())
if (this->GetOwnWindow())
{
this->AndroidApplication->userData = this;
this->AndroidApplication->onAppCmd = android_handle_cmd;
......
......@@ -44,12 +44,12 @@ public:
static vtkAndroidRenderWindowInteractor* New();
vtkTypeMacro(vtkAndroidRenderWindowInteractor, vtkRenderWindowInteractor);
void PrintSelf(ostream& os, vtkIndent indent);
void PrintSelf(ostream& os, vtkIndent indent) override;
/**
* Initialize the event handler
*/
virtual void Initialize();
void Initialize() override;
///@{
/**
......@@ -61,8 +61,8 @@ public:
* and all other interactors associated with the widget are disabled
* when their data is not displayed.
*/
virtual void Enable();
virtual void Disable();
void Enable() override;
void Disable() override;
///@}
/**
......@@ -70,7 +70,7 @@ public:
* calls PostQuitMessage(0) to terminate the application. An application can Specify
* ExitMethod for alternative behavior (i.e. suppression of keyboard exit)
*/
void TerminateApp(void);
void TerminateApp(void) override;
///@{
/**
......@@ -87,7 +87,7 @@ public:
* These methods correspond to the Exit, User and Pick
* callbacks. They allow for the Style to invoke them.
*/
virtual void ExitCallback();
void ExitCallback() override;
virtual void SetAndroidApplication(struct android_app* app) { this->AndroidApplication = app; }
......@@ -110,6 +110,14 @@ public:
void HandleCommand(int32_t cmd);
int32_t HandleInput(AInputEvent* event);
///@{
/**
* Returns true if the window is owned by VTK.
*/
vtkSetMacro(OwnWindow, bool);
vtkGetMacro(OwnWindow, bool);
///@}
protected:
vtkAndroidRenderWindowInteractor();
~vtkAndroidRenderWindowInteractor() override;
......@@ -138,8 +146,8 @@ protected:
* Win32-specific internal timer methods. See the superclass for detailed
* documentation.
*/
virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration);
virtual int InternalDestroyTimer(int platformTimerId);
int InternalCreateTimer(int timerId, int timerType, unsigned long duration) override;
int InternalDestroyTimer(int platformTimerId) override;
///@}
/**
......@@ -147,7 +155,9 @@ protected:
* call this method it will loop processing events until the
* application is exited.
*/
virtual void StartEventLoop();
void StartEventLoop() override;
vtkTypeBool OwnWindow;
private:
vtkAndroidRenderWindowInteractor(const vtkAndroidRenderWindowInteractor&) = delete;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment