mirror of
				https://github.com/android/ndk-samples
				synced 2025-11-04 06:15:39 +08:00 
			
		
		
		
	Compare commits
	
		
			4 Commits
		
	
	
		
			2c2b5c5ff5
			...
			ba7d3c1c66
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					ba7d3c1c66 | ||
| 
						 | 
					2f3460850f | ||
| 
						 | 
					76db40ba73 | ||
| 
						 | 
					84d452a9ab | 
@@ -15,24 +15,22 @@
 | 
			
		||||
#]]
 | 
			
		||||
 | 
			
		||||
cmake_minimum_required(VERSION 4.1.0)
 | 
			
		||||
project(hellovkjni)
 | 
			
		||||
project(HelloVulkan LANGUAGES CXX)
 | 
			
		||||
 | 
			
		||||
# Include the GameActivity static lib to the project.
 | 
			
		||||
include(AppLibrary)
 | 
			
		||||
find_package(game-activity REQUIRED CONFIG)
 | 
			
		||||
 | 
			
		||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
 | 
			
		||||
add_app_library(hellovkjni SHARED
 | 
			
		||||
    vk_main.cpp
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
# Now build app's shared lib
 | 
			
		||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
 | 
			
		||||
target_compile_definitions(hellovkjni PRIVATE
 | 
			
		||||
    VK_USE_PLATFORM_ANDROID_KHR=1
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
add_definitions(-DVK_USE_PLATFORM_ANDROID_KHR=1)
 | 
			
		||||
 | 
			
		||||
add_library(${PROJECT_NAME} SHARED
 | 
			
		||||
    vk_main.cpp)
 | 
			
		||||
 | 
			
		||||
# add lib dependencies
 | 
			
		||||
target_link_libraries(${PROJECT_NAME} PUBLIC
 | 
			
		||||
target_link_libraries(hellovkjni PUBLIC
 | 
			
		||||
    vulkan
 | 
			
		||||
    $<LINK_LIBRARY:WHOLE_ARCHIVE,game-activity::game-activity_static>
 | 
			
		||||
    android
 | 
			
		||||
    log)
 | 
			
		||||
    log
 | 
			
		||||
)
 | 
			
		||||
 
 | 
			
		||||
@@ -468,8 +468,7 @@ void HelloVK::render() {
 | 
			
		||||
 * getPrerotationMatrix handles screen rotation with 3 hardcoded rotation
 | 
			
		||||
 * matrices (detailed below). We skip the 180 degrees rotation.
 | 
			
		||||
 */
 | 
			
		||||
void getPrerotationMatrix(const VkSurfaceCapabilitiesKHR& capabilities,
 | 
			
		||||
                          const VkSurfaceTransformFlagBitsKHR& pretransformFlag,
 | 
			
		||||
void getPrerotationMatrix(const VkSurfaceTransformFlagBitsKHR& pretransformFlag,
 | 
			
		||||
                          std::array<float, 16>& mat) {
 | 
			
		||||
  // mat is initialized to the identity matrix
 | 
			
		||||
  mat = {1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1.};
 | 
			
		||||
@@ -533,8 +532,7 @@ void HelloVK::updateUniformBuffer(uint32_t currentImage) {
 | 
			
		||||
  SwapChainSupportDetails swapChainSupport =
 | 
			
		||||
      querySwapChainSupport(physicalDevice);
 | 
			
		||||
  UniformBufferObject ubo{};
 | 
			
		||||
  getPrerotationMatrix(swapChainSupport.capabilities, pretransformFlag,
 | 
			
		||||
                       ubo.mvp);
 | 
			
		||||
  getPrerotationMatrix(pretransformFlag, ubo.mvp);
 | 
			
		||||
  void* data;
 | 
			
		||||
  vkMapMemory(device, uniformBuffersMemory[currentImage], 0, sizeof(ubo), 0,
 | 
			
		||||
              &data);
 | 
			
		||||
 
 | 
			
		||||
@@ -89,10 +89,10 @@ static void HandleCmd(struct android_app* app, int32_t cmd) {
 | 
			
		||||
 * not use/process any input events, return false for all input events so system
 | 
			
		||||
 * can still process them.
 | 
			
		||||
 */
 | 
			
		||||
extern "C" bool VulkanKeyEventFilter(const GameActivityKeyEvent* event) {
 | 
			
		||||
extern "C" bool VulkanKeyEventFilter(const GameActivityKeyEvent*) {
 | 
			
		||||
  return false;
 | 
			
		||||
}
 | 
			
		||||
extern "C" bool VulkanMotionEventFilter(const GameActivityMotionEvent* event) {
 | 
			
		||||
extern "C" bool VulkanMotionEventFilter(const GameActivityMotionEvent*) {
 | 
			
		||||
  return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -14,34 +14,28 @@
 | 
			
		||||
# limitations under the License.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
cmake_minimum_required(VERSION 3.22.1)
 | 
			
		||||
cmake_minimum_required(VERSION 4.1.0)
 | 
			
		||||
project(NativeActivity LANGUAGES C CXX)
 | 
			
		||||
 | 
			
		||||
# build native_app_glue as a static lib
 | 
			
		||||
set(${CMAKE_C_FLAGS}, "${CMAKE_C_FLAGS}")
 | 
			
		||||
include(AppLibrary)
 | 
			
		||||
 | 
			
		||||
add_library(native_app_glue STATIC
 | 
			
		||||
    ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
 | 
			
		||||
    ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
# now build app's shared lib
 | 
			
		||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
 | 
			
		||||
 | 
			
		||||
# Export ANativeActivity_onCreate(),
 | 
			
		||||
# Refer to: https://github.com/android-ndk/ndk/issues/381.
 | 
			
		||||
set(CMAKE_SHARED_LINKER_FLAGS
 | 
			
		||||
    "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
 | 
			
		||||
 | 
			
		||||
add_library(native-activity SHARED main.cpp)
 | 
			
		||||
add_app_library(native-activity SHARED main.cpp)
 | 
			
		||||
 | 
			
		||||
target_include_directories(native-activity PRIVATE
 | 
			
		||||
    ${ANDROID_NDK}/sources/android/native_app_glue)
 | 
			
		||||
    ${ANDROID_NDK}/sources/android/native_app_glue
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
# add lib dependencies
 | 
			
		||||
target_link_libraries(native-activity
 | 
			
		||||
    android
 | 
			
		||||
    native_app_glue
 | 
			
		||||
    $<LINK_LIBRARY:WHOLE_ARCHIVE,native_app_glue>
 | 
			
		||||
    EGL
 | 
			
		||||
    GLESv1_CM
 | 
			
		||||
    log)
 | 
			
		||||
    log
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
if (ANDROID_ABI STREQUAL riscv64)
 | 
			
		||||
    # This sample uses Sensor Manager and Choreographer APIs which are
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user