Browse Source

Android now builds!

Panagiotis Christopoulos Charitos 4 years ago
parent
commit
96e2f4cfdf

+ 1 - 1
AnKi/Collision/CMakeLists.txt

@@ -1,3 +1,3 @@
 file(GLOB SOURCES *.cpp)
 file(GLOB HEADERS *.h)
-addAnkiSourceFiles(${SOURCES} ${HEADERS})
+anki_add_source_files(${SOURCES} ${HEADERS})

+ 2 - 2
AnKi/Core/CMakeLists.txt

@@ -4,11 +4,11 @@ file(GLOB HEADERS *.h)
 if(SDL)
 	set(SOURCES ${SOURCES} NativeWindowSdl.cpp)
 elseif(ANDROID)
-set(SOURCES ${SOURCES} NativeWindowAndroid.cpp)
+	set(SOURCES ${SOURCES} NativeWindowAndroid.cpp)
 else()
 	message(FATAL_ERROR "Not implemented")
 endif()
 
 foreach(S ${SOURCES})
-	addAnkiSourceFiles("${CMAKE_CURRENT_SOURCE_DIR}/${S}" ${HEADERS})
+	anki_add_source_files("${CMAKE_CURRENT_SOURCE_DIR}/${S}" ${HEADERS})
 endforeach()

+ 39 - 0
AnKi/Core/NativeWindowAndroid.cpp

@@ -8,4 +8,43 @@
 namespace anki
 {
 
+Error NativeWindow::init(NativeWindowInitInfo& init, HeapAllocator<U8>& alloc)
+{
+	ANKI_CORE_LOGI("Initializing Android window");
+
+	m_impl = m_alloc.newInstance<NativeWindowImpl>();
+
+	// Loop until the window is ready
+	extern android_app* g_androidApp;
+	while(g_androidApp->window == nullptr)
+	{
+		int ident;
+		int events;
+		android_poll_source* source;
+
+		const int timeoutMs = 5;
+		while((ident = ALooper_pollAll(timeoutMs, NULL, &events, reinterpret_cast<void**>(&source))) >= 0)
+		{
+			if(source != NULL)
+			{
+				source->process(g_androidApp, source);
+			}
+		}
+	}
+
+	m_impl->m_nativeWindow = g_androidApp->window;
+
+	return Error::NONE;
+}
+
+void NativeWindow::destroy()
+{
+	// Nothing
+}
+
+void NativeWindow::setWindowTitle(CString title)
+{
+	// Nothing
+}
+
 } // end namespace anki

+ 2 - 0
AnKi/Core/NativeWindowAndroid.h

@@ -16,6 +16,8 @@ namespace anki
 /// Native window implementation for Android
 class NativeWindowImpl
 {
+public:
+	ANativeWindow* m_nativeWindow = nullptr;
 };
 
 } // end namespace anki

+ 6 - 2
AnKi/Gr/CMakeLists.txt

@@ -9,7 +9,7 @@ set(COMMON
 	"Utils/StackGpuAllocator.cpp")
 
 foreach(S ${COMMON})
-	addAnkiSourceFiles("${CMAKE_CURRENT_SOURCE_DIR}/${S}")
+	anki_add_source_files("${CMAKE_CURRENT_SOURCE_DIR}/${S}")
 endforeach()
 
 if(VULKAN)
@@ -56,7 +56,11 @@ if(VULKAN)
 		set(VKCPP ${VKCPP} "Vulkan/GrManagerImplSdl.cpp")
 	endif()
 
+	if(ANDROID)
+	set(VKCPP ${VKCPP} "Vulkan/GrManagerImplAndroid.cpp")
+	endif()
+
 	foreach(S ${VKCPP})
-		addAnkiSourceFiles("${CMAKE_CURRENT_SOURCE_DIR}/${S}")
+		anki_add_source_files("${CMAKE_CURRENT_SOURCE_DIR}/${S}")
 	endforeach()
 endif()

+ 3 - 0
AnKi/Gr/Vulkan/Common.cpp

@@ -5,6 +5,9 @@
 
 #include <AnKi/Gr/Vulkan/Common.h>
 
+#define VOLK_IMPLEMENTATION
+#include <Volk/volk.h>
+
 namespace anki
 {
 

+ 25 - 0
AnKi/Gr/Vulkan/GrManagerImplAndroid.cpp

@@ -0,0 +1,25 @@
+// Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#include <AnKi/Gr/Vulkan/GrManagerImpl.h>
+#include <AnKi/Gr/GrManager.h>
+#include <AnKi/Core/NativeWindow.h>
+#include <AnKi/Core/NativeWindowAndroid.h>
+
+namespace anki
+{
+
+Error GrManagerImpl::initSurface(const GrManagerInitInfo& init)
+{
+	VkAndroidSurfaceCreateInfoKHR createInfo = {};
+	createInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
+	createInfo.window = init.m_window->getNative().m_nativeWindow;
+
+	ANKI_VK_CHECK(vkCreateAndroidSurfaceKHR(m_instance, &createInfo, nullptr, &m_surface));
+
+	return Error::NONE;
+}
+
+} // end namespace anki

+ 1 - 1
AnKi/Importer/CMakeLists.txt

@@ -1,2 +1,2 @@
 file(GLOB SOURCES *.cpp)
-addAnkiSourceFiles(${SOURCES})
+anki_add_source_files(${SOURCES})

+ 1 - 1
AnKi/Input/CMakeLists.txt

@@ -7,5 +7,5 @@ else()
 endif()
 
 foreach(F ${SOURCES})
-	addAnkiSourceFiles("${CMAKE_CURRENT_SOURCE_DIR}/${F}")
+	anki_add_source_files("${CMAKE_CURRENT_SOURCE_DIR}/${F}")
 endforeach()

+ 1 - 1
AnKi/Math/CMakeLists.txt

@@ -1,2 +1,2 @@
 file(GLOB SOURCES *.cpp)
-addAnkiSourceFiles(${SOURCES})
+anki_add_source_files(${SOURCES})

+ 9 - 0
AnKi/Math/Mat.h

@@ -24,7 +24,16 @@ class alignas(MathSimd<T, I>::ALIGNMENT) TMat
 public:
 	using Scalar = T;
 	using Simd = typename MathSimd<T, I>::Type;
+
+#if ANKI_COMPILER_GCC_COMPATIBLE
+#	pragma GCC diagnostic push
+#	pragma GCC diagnostic ignored "-Wignored-attributes"
+#endif
 	using SimdArray = Array<Simd, J>;
+#if ANKI_COMPILER_GCC_COMPATIBLE
+#	pragma GCC diagnostic pop
+#endif
+
 	using RowVec = TVec<T, I>;
 	using ColumnVec = TVec<T, J>;
 

+ 1 - 1
AnKi/Physics/CMakeLists.txt

@@ -1,2 +1,2 @@
 file(GLOB SOURCES *.cpp)
-addAnkiSourceFiles(${SOURCES})
+anki_add_source_files(${SOURCES})

+ 1 - 1
AnKi/Physics/PhysicsCollisionShape.cpp

@@ -66,7 +66,7 @@ PhysicsTriangleSoup::PhysicsTriangleSoup(PhysicsWorld* world, ConstWeakArray<Vec
 	{
 		m_type = ShapeType::CONVEX; // Fake the type
 
-		m_convex.init(&positions[0][0], I32(positions.getSize()), sizeof(Vec3));
+		m_convex.init(&positions[0][0], I32(positions.getSize()), U32(sizeof(Vec3)));
 		m_convex->setMargin(getWorld().getCollisionMargin());
 		m_convex->setUserPointer(static_cast<PhysicsObject*>(this));
 	}

+ 1 - 1
AnKi/Renderer/CMakeLists.txt

@@ -1,2 +1,2 @@
 file(GLOB_RECURSE SOURCES *.cpp)
-addAnkiSourceFiles(${SOURCES})
+anki_add_source_files(${SOURCES})

+ 1 - 1
AnKi/Resource/CMakeLists.txt

@@ -1,2 +1,2 @@
 file(GLOB_RECURSE SOURCES *.cpp)
-addAnkiSourceFiles(${SOURCES})
+anki_add_source_files(${SOURCES})

+ 1 - 1
AnKi/Resource/ImageLoader.cpp

@@ -344,7 +344,7 @@ Error ImageLoader::loadAnkiImage(FileInterface& file, U32 maxImageSize,
 	ImageBinaryHeader header;
 	ANKI_CHECK(file.read(&header, sizeof(ImageBinaryHeader)));
 
-	if(std::memcmp(&header.m_magic[0], IMAGE_MAGIC, sizeof(IMAGE_MAGIC - 1)) != 0)
+	if(std::memcmp(&header.m_magic[0], IMAGE_MAGIC, sizeof(IMAGE_MAGIC) - 1) != 0)
 	{
 		ANKI_RESOURCE_LOGE("Wrong magic word");
 		return Error::USER_DATA;

+ 1 - 1
AnKi/Scene/CMakeLists.txt

@@ -1,2 +1,2 @@
 file(GLOB_RECURSE SOURCES *.cpp)
-addAnkiSourceFiles(${SOURCES})
+anki_add_source_files(${SOURCES})

+ 1 - 1
AnKi/Script/CMakeLists.txt

@@ -1,2 +1,2 @@
 file(GLOB_RECURSE SOURCES *.cpp)
-addAnkiSourceFiles(${SOURCES})
+anki_add_source_files(${SOURCES})

+ 1 - 1
AnKi/ShaderCompiler/CMakeLists.txt

@@ -1,2 +1,2 @@
 file(GLOB SOURCES *.cpp)
-addAnkiSourceFiles(${SOURCES})
+anki_add_source_files(${SOURCES})

+ 1 - 1
AnKi/Ui/CMakeLists.txt

@@ -1,2 +1,2 @@
 file(GLOB SOURCES *.cpp)
-addAnkiSourceFiles(${SOURCES})
+anki_add_source_files(${SOURCES})

+ 1 - 1
AnKi/Util/CMakeLists.txt

@@ -14,5 +14,5 @@ elseif(WINDOWS)
 endif()
 
 foreach(F ${SOURCES})
-	addAnkiSourceFiles("${CMAKE_CURRENT_SOURCE_DIR}/${F}")
+	anki_add_source_files("${CMAKE_CURRENT_SOURCE_DIR}/${F}")
 endforeach()

+ 2 - 2
AnKi/Util/ObjectAllocator.h

@@ -70,10 +70,10 @@ private:
 
 /// Convenience wrapper for ObjectAllocator.
 template<typename T, U32 T_OBJECTS_PER_CHUNK = 64, typename TIndexType = U8>
-class ObjectAllocatorSameType : public ObjectAllocator<sizeof(T), alignof(T), T_OBJECTS_PER_CHUNK, TIndexType>
+class ObjectAllocatorSameType : public ObjectAllocator<sizeof(T), U32(alignof(T)), T_OBJECTS_PER_CHUNK, TIndexType>
 {
 public:
-	using Base = ObjectAllocator<sizeof(T), alignof(T), T_OBJECTS_PER_CHUNK, TIndexType>;
+	using Base = ObjectAllocator<sizeof(T), U32(alignof(T)), T_OBJECTS_PER_CHUNK, TIndexType>;
 
 	/// Allocate and construct a new object instance.
 	/// @note Not thread-safe.

+ 0 - 11
AnKi/Util/StdTypes.h

@@ -301,17 +301,6 @@ static constexpr F32 operator""_mm(long double x)
 	typedef auto _selfFn()->decltype(*this); \
 	using _SelfRef = decltype(((_selfFn*)0)()); \
 	using Self = std::remove_reference<_SelfRef>::type;
-
-#if ANKI_COMPILER_GCC_COMPATIBLE
-/// Redefine the sizeof because the default returns size_t and that will require casting when used with U32 for example.
-#	define _ANKI_SIZEOF(type) ((anki::U32)(sizeof(type)))
-#	define sizeof(type) _ANKI_SIZEOF(type)
-
-/// Redefine the alignof because the default returns size_t and that will require casting when used with U32 for
-/// example.
-#	define _ANKI_ALIGNOF(type) ((anki::U32)(alignof(type)))
-#	define alignof(type) _ANKI_ALIGNOF(type)
-#endif
 /// @}
 
 } // end namespace anki

+ 30 - 15
CMakeLists.txt

@@ -8,13 +8,15 @@ PROJECT(AnKi)
 # Funcs                                                                        #
 ################################################################################
 
-macro(installExecutable exe)
-	add_custom_command(TARGET ${exe} POST_BUILD
-		COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/Bin
-		COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${exe}> ${CMAKE_BINARY_DIR}/Bin)
-endmacro()
+function(anki_install_executable EXE)
+	if(NOT ANDROID)
+		add_custom_command(TARGET ${EXE} POST_BUILD
+			COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/Bin
+			COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${EXE}> ${CMAKE_BINARY_DIR}/Bin)
+	endif()
+endfunction()
 
-macro(addAnkiSourceFiles)
+macro(anki_add_source_files)
 	foreach(f ${ARGV})
 		set(AK_SOURCES "${AK_SOURCES} ${f}")
 	endforeach()
@@ -22,6 +24,24 @@ macro(addAnkiSourceFiles)
 	set(AK_SOURCES ${AK_SOURCES} PARENT_SCOPE)
 endmacro()
 
+macro(anki_new_executable)
+	if(NOT ANDROID)
+		add_executable(${ARGV})
+		anki_install_executable(${ARGV0})
+	else()
+		set(_SKIP TRUE)
+		foreach(ARG ${ARGV})
+			if(_SKIP)
+				set(_SKIP FALSE)
+			else()
+				list(APPEND _TMP_LIST ${ARG})
+			endif()
+		endforeach()
+
+		add_library(${ARGV0} SHARED ${_TMP_LIST})
+	endif()
+endmacro()
+
 ################################################################################
 # Determin the system to build for. Do that first                              #
 ################################################################################
@@ -229,10 +249,6 @@ if((LINUX OR MACOS OR WINDOWS) AND GL)
 	set(ANKI_EXTERN_SUB_DIRS ${ANKI_EXTERN_SUB_DIRS} GLEW)
 endif()
 
-if(VULKAN)
-	set(ANKI_EXTERN_SUB_DIRS ${ANKI_EXTERN_SUB_DIRS} Volk)
-endif()
-
 # SDL
 if(SDL)
 	message("++ Configuring SDL2")
@@ -362,7 +378,6 @@ if(LINUX)
 	if(GL)
 		set(THIRD_PARTY_LIBS ${ANKI_GR_BACKEND} AnKiGlew)
 	else()
-		set(THIRD_PARTY_LIBS AnKiVolk)
 		if(SDL)
 			set(THIRD_PARTY_LIBS ${THIRD_PARTY_LIBS} X11-xcb)
 		else()
@@ -375,14 +390,14 @@ elseif(MACOS)
 	find_package(OpenGL REQUIRED)
 	set(THIRD_PARTY_LIBS ${OPENGL_LIBRARIES} AnKiGlew pthread)
 elseif(ANDROID)
-	set(THIRD_PARTY_LIBS GLESv3 EGL log android)
-	include_directories("${ANDROID_NDK}/sources/android/native_app_glue")
-	set(_SYS_SRC "${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c")
+	set(THIRD_PARTY_LIBS log android)
+	#include_directories("${ANDROID_NDK}/sources/android/native_app_glue")
+	#set(_SYS_SRC "${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c")
 elseif(WINDOWS)
 	if(GL)
 		set(THIRD_PARTY_LIBS ${THIRD_PARTY_LIBS} AnKiGlew opengl32)
 	else()
-		set(THIRD_PARTY_LIBS ${THIRD_PARTY_LIBS} AnKiVolk)
+		set(THIRD_PARTY_LIBS ${THIRD_PARTY_LIBS})
 	endif()
 
 	set(THIRD_PARTY_LIBS ${THIRD_PARTY_LIBS} version Imm32 Winmm DbgHelp)

+ 1 - 3
Samples/PhysicsPlayground/CMakeLists.txt

@@ -1,4 +1,2 @@
-add_executable(PhysicsPlayground Main.cpp ../Common/Framework.cpp)
+anki_new_executable(PhysicsPlayground Main.cpp ../Common/Framework.cpp)
 target_link_libraries(PhysicsPlayground AnKi)
-
-installExecutable(PhysicsPlayground)

+ 1 - 3
Samples/SimpleScene/CMakeLists.txt

@@ -1,4 +1,2 @@
-add_executable(SimpleScene Main.cpp ../Common/Framework.cpp)
+anki_new_executable(SimpleScene Main.cpp ../Common/Framework.cpp)
 target_link_libraries(SimpleScene AnKi)
-
-installExecutable(SimpleScene)

+ 1 - 2
Samples/SkeletalAnimation/CMakeLists.txt

@@ -1,3 +1,2 @@
-add_executable(SkeletalAnimation Main.cpp ../Common/Framework.cpp)
+anki_new_executable(SkeletalAnimation Main.cpp ../Common/Framework.cpp)
 target_link_libraries(SkeletalAnimation AnKi)
-installExecutable(SkeletalAnimation)

+ 1 - 2
Samples/Sponza/CMakeLists.txt

@@ -1,3 +1,2 @@
-add_executable(Sponza Main.cpp ../Common/Framework.cpp)
+anki_new_executable(Sponza Main.cpp ../Common/Framework.cpp)
 target_link_libraries(Sponza AnKi)
-installExecutable(Sponza)

+ 1 - 2
Sandbox/CMakeLists.txt

@@ -1,3 +1,2 @@
-add_executable(Sandbox Main.cpp)
+anki_new_executable(Sandbox Main.cpp)
 target_link_libraries(Sandbox AnKi)
-installExecutable(Sandbox)

+ 1 - 3
Tests/CMakeLists.txt

@@ -3,8 +3,6 @@ file(GLOB_RECURSE TESTS_HEADERS *.h)
 
 include_directories("..")
 
-add_executable(Tests ${TESTS_SOURCES} ${TESTS_HEADERS})
+anki_new_executable(Tests ${TESTS_SOURCES} ${TESTS_HEADERS})
 target_compile_definitions(Tests PRIVATE -DANKI_SOURCE_FILE)
 target_link_libraries(Tests AnKi)
-
-installExecutable(Tests)

+ 0 - 4
ThirdParty/Volk/CMakeLists.txt

@@ -1,4 +0,0 @@
-file(GLOB_RECURSE SOURCE_FILES *.c)
-include_directories(../Khronos)
-add_definitions("-DVK_KHR_ray_tracing_pipeline" "-DVK_KHR_acceleration_structure")
-add_library(AnKiVolk ${SOURCE_FILES})

+ 1 - 2
Tools/GltfImporter/CMakeLists.txt

@@ -1,5 +1,4 @@
 file(GLOB_RECURSE SOURCES *.cpp)
 
-add_executable(GltfImporter ${SOURCES})
+anki_new_executable(GltfImporter ${SOURCES})
 target_link_libraries(GltfImporter AnKi)
-installExecutable(GltfImporter)

+ 2 - 4
Tools/Image/CMakeLists.txt

@@ -1,7 +1,5 @@
-add_executable(ImageViewer ImageViewerMain.cpp)
+anki_new_executable(ImageViewer ImageViewerMain.cpp)
 target_link_libraries(ImageViewer AnKi)
-installExecutable(ImageViewer)
 
-add_executable(ImageImporter ImageImporterMain.cpp)
+anki_new_executable(ImageImporter ImageImporterMain.cpp)
 target_link_libraries(ImageImporter AnKi)
-installExecutable(ImageImporter)

+ 2 - 4
Tools/Shader/CMakeLists.txt

@@ -1,7 +1,5 @@
-add_executable(ShaderDump ShaderProgramBinaryDumpMain.cpp)
+anki_new_executable(ShaderDump ShaderProgramBinaryDumpMain.cpp)
 target_link_libraries(ShaderDump AnKi)
-installExecutable(ShaderDump)
 
-add_executable(ShaderCompiler ShaderProgramCompilerMain.cpp)
+anki_new_executable(ShaderCompiler ShaderProgramCompilerMain.cpp)
 target_link_libraries(ShaderCompiler AnKi)
-installExecutable(ShaderCompiler)