Skip to content

Commit 43de03e

Browse files
Merge branch 'android' of github.com:Devsh-Graphics-Programming/Nabla into android
2 parents 81df376 + 35b9511 commit 43de03e

File tree

7 files changed

+106
-54
lines changed

7 files changed

+106
-54
lines changed

CMakeLists.txt

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,65 @@ cmake_minimum_required(VERSION 3.20)
77
cmake_policy(SET CMP0072 OLD) #not yet, would need to get pointers to all OpenGL functions
88
set(OpenGL_GL_PREFERENCE LEGACY)
99
#cmake_policy(SET CMP )
10-
option(NBL_BUILD_ANDROID "Build for Android?" OFF)
10+
set(NBL_BUILD_ANDROID OFF)
1111

12-
if(DEFINED CMAKE_TOOLCHAIN_FILE) # TODO - validate paths due to CMake path-policy (errors when no path passed in)
13-
cmake_path(GET CMAKE_TOOLCHAIN_FILE FILENAME _NBL_CMAKE_TOOLCHAIN_FILENAME_)
12+
if(DEFINED CMAKE_TOOLCHAIN_FILE)
13+
14+
if(EXISTS "${CMAKE_TOOLCHAIN_FILE}")
15+
cmake_path(GET CMAKE_TOOLCHAIN_FILE FILENAME _NBL_CMAKE_TOOLCHAIN_FILENAME_)
16+
else()
17+
message(FATAL_ERROR "CMAKE_TOOLCHAIN_FILE as '${CMAKE_TOOLCHAIN_FILE}' is invalid!")
18+
endif()
1419

1520
if(${_NBL_CMAKE_TOOLCHAIN_FILENAME_} STREQUAL "android.toolchain.cmake")
1621
message(STATUS "Found Android toolchain! Validating...")
1722

18-
set(_NBL_SUPPORTED_NDK_ "android-ndk-r22b") # supported NDK version
19-
set(_NBL_SUPPORTED_ABI_ "x86_64") # supported ABI
20-
21-
# quering ${_NBL_EXPECTED_ANDROID_SDK_ROOT_DIRECTORY_}/${_NBL_SUPPORTED_NDK_}/build/cmake/android.toolchain.cmake
22-
cmake_path(GET CMAKE_TOOLCHAIN_FILE PARENT_PATH _NBL_TOOLCHAIN_NDK_CMAKE_DIRECTORY_)
23-
cmake_path(GET _NBL_TOOLCHAIN_NDK_CMAKE_DIRECTORY_ PARENT_PATH _NBL_TOOLCHAIN_NDK_BUILD_DIRECTORY_)
24-
cmake_path(GET _NBL_TOOLCHAIN_NDK_BUILD_DIRECTORY_ PARENT_PATH _NBL_TOOLCHAIN_NDK_ROOT_DIRECTORY_)
25-
cmake_path(GET _NBL_TOOLCHAIN_NDK_ROOT_DIRECTORY_ PARENT_PATH _NBL_EXPECTED_ANDROID_SDK_ROOT_DIRECTORY_)
26-
27-
string(LENGTH ${CMAKE_TOOLCHAIN_FILE} _NBL_CMAKE_TOOLCHAIN_FILE_LENGTH_)
28-
string(LENGTH ${_NBL_EXPECTED_ANDROID_SDK_ROOT_DIRECTORY_} _NBL_EXPECTED_ANDROID_SDK_ROOT_DIRECTORY_LENGTH_)
29-
math(EXPR _NBL_PARENT_NDK_TO_TOOLCHAIN_FILE_LENGTH_ "${_NBL_CMAKE_TOOLCHAIN_FILE_LENGTH_} - ${_NBL_EXPECTED_ANDROID_SDK_ROOT_DIRECTORY_LENGTH_}" OUTPUT_FORMAT DECIMAL)
30-
string(SUBSTRING ${CMAKE_TOOLCHAIN_FILE} ${_NBL_EXPECTED_ANDROID_SDK_ROOT_DIRECTORY_LENGTH_} ${_NBL_PARENT_NDK_TO_TOOLCHAIN_FILE_LENGTH_} _NBL_PARENT_NDK_TO_TOOLCHAIN_FILEPATH_)
31-
32-
if(${_NBL_PARENT_NDK_TO_TOOLCHAIN_FILEPATH_} STREQUAL "/${_NBL_SUPPORTED_NDK_}/build/cmake/android.toolchain.cmake")
33-
message(STATUS "Found Android NDK '${_NBL_SUPPORTED_NDK_}' is appropriate!")
34-
else()
35-
message(FATAL_ERROR "Found Android NDK version isn't appropriate. Use '${_NBL_SUPPORTED_NDK_}'!")
36-
endif()
23+
set(_NBL_SUPPORTED_ABI_
24+
"x86_64"
25+
# "arm64-v8a" in future
26+
)
3727

38-
if(EXISTS "${_NBL_EXPECTED_ANDROID_SDK_ROOT_DIRECTORY_}/build-tools")
39-
if(DEFINED ANDROID_ABI)
40-
if(${ANDROID_ABI} STREQUAL ${_NBL_SUPPORTED_ABI_})
41-
message(STATUS "Supported '${_NBL_SUPPORTED_ABI_}' ABI!")
42-
43-
else()
44-
message(FATAL_ERROR "Found '${ANDROID_ABI}' isn't appropriate. Use '${_NBL_SUPPORTED_ABI_}'!")
28+
if(DEFINED ANDROID_ABI) # see _NBL_SUPPORTED_ABI_
29+
set(FOUND 0)
30+
foreach(CURRENT_ABI IN LISTS _NBL_SUPPORTED_ABI_)
31+
if("${CURRENT_ABI}" STREQUAL ${ANDROID_ABI})
32+
message(STATUS "Selecting found ${CURRENT_ABI} ABI!")
33+
set(FOUND 1)
34+
break()
4535
endif()
36+
endforeach()
37+
38+
if(NOT FOUND)
39+
message(FATAL_ERROR "Selected ${ANDROID_ABI} isn't appropriate. Supported ABIs: ${_NBL_SUPPORTED_ABI_}!")
4640
else()
47-
message(STATUS "Could not find 'ANDROID_ABI', using supported ABI: '${_NBL_SUPPORTED_ABI_}'")
48-
set(ANDROID_ABI ${_NBL_SUPPORTED_ABI_} CACHE INTERNAL "" FORCE)
41+
unset(FOUND)
4942
endif()
43+
else()
44+
message(FATAL_ERROR "ANDROID_ABI must be specified at the very beginning of execution!")
45+
endif()
5046

51-
message(STATUS "'${_NBL_SUPPORTED_NDK_}' located in Android SDK path. Building Nabla with Android toolchain!")
47+
if(NOT DEFINED ANDROID_PLATFORM) # android-28
48+
message(FATAL_ERROR "ANDROID_PLATFORM must be specified at the very beginning of execution!")
49+
endif()
50+
51+
include(${CMAKE_TOOLCHAIN_FILE})
52+
53+
if(${ANDROID_NDK_MAJOR} LESS 22)
54+
message(FATAL_ERROR "Update your NDK to at least 22. We don't support ${ANDROID_NDK_REVISION} NDK version!")
55+
endif()
5256

53-
set(ANDROID_SDK_ROOT_PATH "${_NBL_EXPECTED_ANDROID_SDK_ROOT_DIRECTORY_}")
54-
set(ANDROID_NDK_ROOT_PATH ${ANDROID_SDK_ROOT_PATH}/${_NBL_SUPPORTED_NDK_})
55-
56-
set(NBL_BUILD_ANDROID ON)
57-
set(_NBL_ANDROID_VALIDATED_ ON)
58-
else()
59-
message(FATAL_ERROR "${_NBL_SUPPORTED_NDK_} must be placed in Android SDK path!")
57+
# note that we assume NDK has been installed using Android Studio, so the existing paths should look as followning:
58+
# ${ANDROID_SDK_ROOT_PATH}/ndk/${ANDROID_NDK_REVISION}/build/cmake/android.toolchain.cmake
59+
60+
set(ANDROID_NDK_ROOT_PATH ${CMAKE_ANDROID_NDK})
61+
get_filename_component(ANDROID_SDK_ROOT_PATH "${ANDROID_NDK_ROOT_PATH}/../../" ABSOLUTE)
62+
63+
if(EXISTS "${ANDROID_SDK_ROOT_PATH}/build-tools")
64+
message(STATUS "Building Nabla with ${ANDROID_NDK_REVISION} NDK!")
6065
endif()
66+
67+
set(NBL_BUILD_ANDROID ON)
68+
set(_NBL_ANDROID_VALIDATED_ ON)
6169
endif()
6270

6371
# TODO - another toolchains in future
@@ -119,9 +127,6 @@ if(NBL_BUILD_ANDROID)
119127

120128
#option(STRIP_ANDROID_LIBRARY "Strip the resulting android library" OFF)
121129

122-
if(NOT ANDROID_PLATFORM)
123-
set(ANDROID_PLATFORM "android-25")
124-
endif()
125130
string(SUBSTRING
126131
"${ANDROID_PLATFORM}"
127132
8 # length of "android-"
@@ -152,7 +157,11 @@ if(NBL_BUILD_ANDROID)
152157
unset(__buildTools)
153158
endif()
154159
set(ANDROID_BUILD_TOOLS "${ANDROID_SDK_ROOT_PATH}/build-tools/${ANDROID_BUILD_TOOLS_VERSION}")
160+
if(MSVC)
155161
set(ANDROID_JAVA_BIN "${JAVA_HOME}")
162+
else()
163+
set(ANDROID_JAVA_BIN "${JAVA_HOME}/bin")
164+
endif()
156165
set(ANDROID_JAVA_RT_JAR "${JAVA_HOME}/jre/lib/rt.jar")
157166

158167
set(ANDROID_APK_TARGET_ID "" CACHE STRING "The Target ID to build the APK for like 'android-99', use <android list targets> to choose another one.")

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Contact ***[@devshgraphicsprogramming](https://github.com/devshgraphicsprogrammi
160160

161161
- [x] **Linux**
162162

163-
- [ ] **Android 7.0 +**
163+
- [x] **Android 7.0 +**
164164

165165
- [ ] **Mac OS**
166166

@@ -174,7 +174,7 @@ Contact ***[@devshgraphicsprogramming](https://github.com/devshgraphicsprogrammi
174174
- **[CMake](https://cmake.org/download/)**
175175
- **[MSVC](https://visualstudio.microsoft.com/pl/downloads/)** or **[GCC](https://sourceforge.net/projects/mingw-w64/)**
176176
- **[Vulkan SDK](https://vulkan.lunarg.com/sdk/home)**
177-
- **[Perl](https://www.perl.org/get.html)**
177+
- **[Perl 5.28 executable version](https://www.perl.org/get.html)**
178178
- **[NASM](https://www.nasm.us/pub/nasm/releasebuilds/?C=M;O=D)**
179179
- **[Python 3.8](https://www.python.org/downloads/release/python-380/)** or later
180180

@@ -205,20 +205,27 @@ After dealing with *CUDA* installing just install *Optix SKD*.
205205
**Required:**
206206

207207
- **[Android Studio](https://developer.android.com/studio)**
208-
- **[NDK r22b](https://developer.android.com/ndk/downloads#stable-downloads)**
209-
- **[Java 8](https://www.java.com/download/)**
208+
- **[JDK 8](https://www.java.com/download/)**
210209

211-
The first step is to install Android Studio and Java 8. When done, extract NDK r22b into *Android SDK root directory* usually located at `C:/Users/<your_user>/AppData/Local/AndroidSdk`. If you however can't find it, open Android Studio and go to **File** and **Project Structure** that will show you where your Android SDKs are installed.
210+
The first step is to install Android Studio and JDK 8. When done, open Android Studio and navigate to **Tools** -> **SDK Manager** -> **System Settings** -> **Android SDK**.
211+
Select *SDK Platforms* and install proper individual SDK components - install Android version with Android API level you will be targeting. Then switch to *SDK Tools* and make sure to install **Android SDK Build-Tools 32** and **NDK (Side by side)** - it's a *requirement*! Also you must make sure that your **JAVA_HOME** enviroment variable is set to proper JDK installation path.
212212

213-
Now you can begin CMake generating. On Android Build there is an extra optional Ninja generator available. *Important note is that Nabla Android Build has been performed and tested so far on Windows as cross compile OS with **ninja** generator and on Linux as cross compile OS with **makefile** and **ninja** generators.* Before configuring you need to specify toolchain file for cross-compiling by passing path to `android.toolchain.cmake`. You can find it in NDK directory in `build/cmake/android.toolchain.cmake` and according to example of Android SDK root directory path it should look entirely like `C:/Users/<your_user>/AppData/Local/AndroidSdk/android-ndk-r22b/build/cmake/android.toolchain.cmake`.
213+
Now you can begin CMake'ing. We use **Ninja** generator tools as a generator for building Nabla for Android on both Windows and Linux Host-OSes. *Note that Nabla Android build has been performed and tested so far on Windows as cross compile OS with **Ninja** generator and on Linux as cross compile OS with **Makefile** and **Ninja** generators, but we recommend using **Ninja** for both OSes.*
214+
215+
Before configuring CMake you must add 2 cache variables:
216+
217+
- **ANDROID_PLATFORM**
218+
- **ANDROID_ABI**
219+
220+
**ANDROID_PLATFORM** is a target API platform that you pass as `android-x` where `x` is your android API level (you can pass 28 for instance). **ANDROID_ABI** is Application Binary Interface and note, that we support only `x86_64` currently. Those 2 cache variables *must be* specified before CMake configuration. Having done it you can specify toolchain file for cross-compiling by passing path to `android.toolchain.cmake`. You can find it in Android Studio's SDK directory in `ndk/<version>/build/cmake/android.toolchain.cmake`. Basically the entire path should look like this one `C:/Users/<your_user>/AppData/Local/AndroidSdk/ndk/<version>/build/cmake/android.toolchain.cmake`. With all of this feel free to generate.
214221

215222
Having Nabla generated you need to enter build directory, launch the terminal and type `cmake --build . --target Nabla -j4 -v` or if you want build android sample example you would type `cmake --build . --target android_sample_apk -j4 -v`. The android sample example produces *.apk* file you can use for debugging and profiling.
216223

217-
**Note:** each example provided by the engine builds as an executable with non-cross builds and with target of a name called *"a_target"*, in following example above it would be *"android_sample"*. When building cross-compile for android **to produce the APK file you need to add *"_apk"* postfix to the "*a_target"***, because "*a_target*" gets built then as a library.
224+
**Note:** each example provided by the engine builds as an executable with non-cross builds and with target of a name called `a_target`, in following example above it would be `android_sample`. When building cross-compile for android **to produce the APK file you need to add `_apk` postfix to the `a_target`, because `a_target` gets built then as a library.
218225

219226
#### Chrome Book SDK version
220227

221-
In order for the chromebook to work with the apk you build you need to install the right SDK version. Go to *Tools -> SDK Manager ->System and Settings -> Android SDK* then Select the *SDK Platforms* tab and tick the "Show Packake Details" checkbox in the bottom-right corner. After that select *Android 9.0 (Pie) -> Android SDK Platform 28* and hit "OK".
228+
In order for the chromebook to work with the apk you build you need to install the right SDK version. Go to **Tools** -> **SDK Manager** -> **System Settings** -> **Android SDK** then select the *SDK Platforms* tab and tick the "Show Packake Details" checkbox in the bottom-right corner. After that select *Android 9.0 (Pie) -> Android SDK Platform 28* and hit "OK".
222229

223230
#### Chrome Book upload
224231

cmake/common.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ macro(nbl_android_create_apk _TARGET)
364364
)
365365
set(D8_SCRIPT "${ANDROID_BUILD_TOOLS}/d8.bat")
366366
if(NOT EXISTS ${D8_SCRIPT})
367-
set(DEX_COMMAND ${ANDROID_BUILD_TOOLS}/dx --dex --output=bin/classes.dex ./obj)
367+
set(DEX_COMMAND ${ANDROID_BUILD_TOOLS}/d8 ./obj/eu/devsh/${TARGET_NAME}/Loader.class --output ./bin/)
368368
else()
369369
set(DEX_COMMAND ${D8_SCRIPT} --output ./bin/ ./obj/eu/devsh/${TARGET_NAME}/*.class)
370370
endif()
@@ -587,4 +587,4 @@ endmacro()
587587

588588
macro(write_source_definitions NBL_FILE NBL_WRAPPER_CODE_TO_WRITE)
589589
file(WRITE "${NBL_FILE}" "${NBL_WRAPPER_CODE_TO_WRITE}")
590-
endmacro()
590+
endmacro()

include/matrix4SIMD.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,28 @@ class matrix4SIMD// : public AlignedBase<_NBL_SIMD_ALIGNMENT> don't inherit from
169169

170170
bool isBoxInFrustum(const aabbox3d<float>& bbox);
171171

172+
bool perspectiveTransformVect(core::vectorSIMDf& inOutVec)
173+
{
174+
transformVect(inOutVec);
175+
const bool inFront = inOutVec[3] > 0.f;
176+
inOutVec /= inOutVec.wwww();
177+
return inFront;
178+
}
179+
180+
core::vector2di fragCoordTransformVect(const core::vectorSIMDf& _in, const core::dimension2du& viewportDimensions)
181+
{
182+
core::vectorSIMDf pos(_in);
183+
pos.w = 1.f;
184+
if (perspectiveTransformVect(pos))
185+
core::vector2di(-0x80000000, -0x80000000);
186+
187+
pos[0] *= 0.5f;
188+
pos[1] *= 0.5f;
189+
pos[0] += 0.5f;
190+
pos[1] += 0.5f;
191+
192+
return core::vector2di(pos[0] * float(viewportDimensions.Width), pos[1] * float(viewportDimensions.Height));
193+
}
172194

173195
static inline matrix4SIMD buildProjectionMatrixPerspectiveFovRH(float fieldOfViewRadians, float aspectRatio, float zNear, float zFar);
174196
static inline matrix4SIMD buildProjectionMatrixPerspectiveFovLH(float fieldOfViewRadians, float aspectRatio, float zNear, float zFar);

include/nbl/system/ISystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ class ISystem : public core::IReferenceCounted
372372
bool deleteDirectory(const system::path& p)
373373
{
374374
if (std::filesystem::exists(p))
375-
return std::filesystem::remove(p);
375+
return std::filesystem::remove_all(p);
376376
else
377377
return false;
378378
}

include/nbl/ui/CWindowManagerWin32.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,16 @@ namespace nbl::ui
295295
case ERT_CHANGE_CURSOR_VISIBILITY:
296296
{
297297
auto& params = req.changeCursorVisibilityParam;
298-
ShowCursor(params.visible);
298+
if(params.visible)
299+
{
300+
int ret = ShowCursor(true);
301+
while (ret < 0) ret = ShowCursor(true);
302+
}
303+
else
304+
{
305+
int ret = ShowCursor(false);
306+
while (ret >= 0) ret = ShowCursor(false);
307+
}
299308
break;
300309
}
301310
}
@@ -313,6 +322,10 @@ namespace nbl::ui
313322
{
314323
req.destroyWindowParam = std::move(params);
315324
}
325+
else if constexpr (std::is_same_v<RequestParams, SRequestParams_ChangeCursorVisibility&>)
326+
{
327+
req.changeCursorVisibilityParam = std::move(params);
328+
}
316329
}
317330

318331
bool wakeupPredicate() const { return true; }

src/nbl/builtin/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function(nbl_add_builtin_resources)
1818
endfunction()
1919

2020
set(nbl_resources_to_embed
21+
"nbl/builtin/glsl/utils/acceleration_structures.glsl"
2122
"nbl/builtin/shader/loader/mtl/vertex_impl.glsl"
2223
"nbl/builtin/shader/loader/mtl/vertex_no_uv.vert" # TODO: remove naming tautology
2324
"nbl/builtin/shader/loader/mtl/vertex_uv.vert" # TODO: remove naming tautology

0 commit comments

Comments
 (0)