4 Commits

Author SHA1 Message Date
Dan Albert
ba7d3c1c66 Merge 2d36bf2ee3 into 2f3460850f 2025-09-11 08:31:39 -04:00
Dan Albert
2f3460850f Cleanup native-activity CMakeLists.txt. 2025-09-11 12:31:26 +00:00
Dan Albert
76db40ba73 CMake cleanup/modernization in hello-vulkan. 2025-09-11 12:29:36 +00:00
Dan Albert
84d452a9ab Increase warning level in hello-vulkan. 2025-09-11 12:29:36 +00:00
4 changed files with 26 additions and 36 deletions

View File

@@ -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
)

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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