Skip to content

Commit 494a2d5

Browse files
committed
Updating common code
1 parent d4747ca commit 494a2d5

File tree

238 files changed

+42759
-21930
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

238 files changed

+42759
-21930
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,4 @@ vulkanCapsViewer/vulkanreport.json
205205
# DLLs in bin
206206
!bin/*.dll
207207
bin_debug
208+
/external/

CMakeLists.txt

Lines changed: 32 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,60 @@
1-
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
2-
cmake_policy(VERSION 3.8)
1+
cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
2+
cmake_policy(VERSION 3.6)
33
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
44
include("cmake/defaults.cmake")
55
set(NAME vulkanExamples)
66

77
project(${NAME})
88

9-
if (WIN32)
10-
if (MSVC)
11-
if (NOT MSVC14)
12-
message(FATAL_ERROR "Visual Studio 2015 is required for Windows builds")
13-
endif()
14-
if(NOT ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8"))
15-
message(FATAL_ERROR "You must build for the Win64 architecture")
16-
endif()
17-
endif()
18-
endif()
19-
20-
add_custom_target(SetupRelease ALL ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/bin)
21-
set_target_properties(SetupRelease PROPERTIES FOLDER "CMakeTargets")
22-
add_custom_target(SetupDebug ALL ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/bin_debug)
23-
set_target_properties(SetupDebug PROPERTIES FOLDER "CMakeTargets")
24-
25-
find_package(Vulkan REQUIRED)
26-
include_directories(${Vulkan_INCLUDE_DIR})
27-
link_libraries(${Vulkan_LIBRARY})
289

2910
if(WIN32)
30-
add_definitions(-DVK_USE_PLATFORM_WIN32_KHR)
31-
else()
32-
add_definitions(-DVK_USE_PLATFORM_XCB_KHR)
33-
find_package(XCB REQUIRED)
34-
link_libraries(${XCB_LIBRARIES})
11+
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
12+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
3513
endif()
3614

15+
if(NOT ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8"))
16+
message(FATAL_ERROR "32 bit builds not supported")
17+
endif()
3718

19+
find_package(Threads REQUIRED)
3820

39-
if (WIN32)
40-
add_dependency_external_projects(glfw3)
41-
list(APPEND EXTERNALS glfw3)
42-
include_directories(${GLFW3_INCLUDE_DIR})
43-
link_libraries(${GLFW3_LIBRARY})
44-
45-
add_dependency_external_projects(zlib)
46-
list(APPEND EXTERNALS zlib)
47-
include_directories(${ZLIB_INCLUDE_DIRS})
48-
link_libraries(${ZLIB_LIBRARIES})
21+
if (NOT ANDROID)
22+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
23+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_SOURCE_DIR}/bin")
24+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_SOURCE_DIR}/bin_debug")
25+
set(CMAKE_DEBUG_POSTFIX "d")
4926

50-
add_dependency_external_projects(assimp)
51-
list(APPEND EXTERNALS assimp)
52-
include_directories(${ASSIMP_INCLUDE_DIRS})
53-
link_libraries(${ASSIMP_LIBRARIES})
54-
else()
55-
pkg_check_modules(GLFW3 REQUIRED glfw3>=3.2)
56-
link_libraries(${GLFW3_LIBRARIES})
57-
include_directories(${GLFW3_INCLUDEDIR})
58-
link_directories(${GLFW3_LIBRARY_DIRS})
59-
60-
find_package(assimp)
61-
link_libraries(${ASSIMP_LIBRARIES})
62-
include_directories(${ASSIMP_INCLUDEDIR})
63-
link_directories(${ASSIMP_LIBRARY_DIRS})
27+
add_custom_target(SetupRelease ALL ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/bin)
28+
set_target_properties(SetupRelease PROPERTIES FOLDER "CMakeTargets")
29+
add_custom_target(SetupDebug ALL ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/bin_debug)
30+
set_target_properties(SetupDebug PROPERTIES FOLDER "CMakeTargets")
6431
endif()
6532

66-
add_dependency_external_projects(glm)
67-
list(APPEND EXTERNALS glm)
68-
include_directories(${GLM_INCLUDE_DIRS})
6933

70-
add_dependency_external_projects(gli)
71-
list(APPEND EXTERNALS gli)
72-
include_directories(${GLI_INCLUDE_DIRS})
34+
if (ANDROID)
35+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
36+
set(APP_GLUE_DIR ${ANDROID_NDK}/sources/android/native_app_glue)
37+
include_directories(${APP_GLUE_DIR})
38+
add_library(app-glue STATIC ${APP_GLUE_DIR}/android_native_app_glue.c)
39+
endif()
7340

74-
add_dependency_external_projects(glslang)
75-
list(APPEND EXTERNALS glslang)
76-
include_directories(${GLSLANG_INCLUDE_DIRS})
77-
link_libraries(${GLSLANG_LIBRARIES})
41+
if (ANDROID)
42+
add_definitions(-DVK_USE_PLATFORM_ANDROID_KHR)
43+
elseif (WIN32)
44+
add_definitions(-DVK_USE_PLATFORM_WIN32_KHR)
45+
else()
46+
add_definitions(-DVK_USE_PLATFORM_XCB_KHR)
47+
find_package(XCB REQUIRED)
48+
link_libraries(${XCB_LIBRARIES})
49+
endif()
7850

7951
add_subdirectory(base)
8052

8153
include_directories(base)
82-
link_libraries(common)
8354
if (NOT WIN32)
8455
set(THREADS_PREFER_PTHREAD_FLAG ON)
8556
find_package(Threads REQUIRED)
8657
link_libraries(${CMAKE_THREAD_LIBS_INIT})
8758
endif()
8859

89-
9060
add_subdirectory(examples)
91-

base/CMakeLists.txt

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
1-
file(GLOB COMMON_SOURCE *.cpp *.h *.hpp)
2-
add_library(common ${COMMON_SOURCE})
3-
set_target_properties(common PROPERTIES FOLDER "examples")
4-
foreach(EXTERNAL ${EXTERNALS})
5-
add_dependencies(common ${EXTERNAL})
1+
set(TARGET_NAME base)
2+
3+
set(SHADER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../data/shaders")
4+
file(GLOB_RECURSE SHADERS
5+
${SHADER_DIR}/*.vert
6+
${SHADER_DIR}/*.frag
7+
${SHADER_DIR}/*.comp
8+
${SHADER_DIR}/*.tesc
9+
${SHADER_DIR}/*.tese
10+
${SHADER_DIR}/*.geom
11+
)
12+
13+
GroupSources("base")
14+
GroupSources("data/shaders")
15+
foreach(SHADER ${SHADERS})
16+
compile_spirv_shader(${SHADER})
17+
list(APPEND COMPILED_SHADERS ${COMPILE_SPIRV_SHADER_RETURN})
18+
source_group("compiled" FILES ${COMPILE_SPIRV_SHADER_RETURN})
619
endforeach()
20+
add_custom_target(shaders SOURCES ${SHADERS} ${COMPILED_SHADERS})
21+
22+
file(GLOB_RECURSE COMMON_SOURCE *.cpp *.h *.hpp)
23+
add_library(${TARGET_NAME} STATIC ${COMMON_SOURCE})
24+
25+
target_glfw3()
26+
target_glm()
27+
target_gli()
28+
target_vulkan()
29+
target_assimp()
30+
31+
if (ANDROID)
32+
add_dependencies(${TARGET_NAME} app-glue)
33+
target_link_libraries(${TARGET_NAME} app-glue android log m)
34+
endif()

base/camera.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ class Camera {
119119
updateViewMatrix();
120120
};
121121

122+
void setPosition(const glm::vec3& translation) {
123+
setTranslation(translation);
124+
}
125+
122126
void setTranslation(const glm::vec3& translation) {
123127
position = vec3(-translation.x, - translation.y, translation.z);
124128
updateViewMatrix();
@@ -188,7 +192,7 @@ class Camera {
188192
bool retVal = false;
189193

190194
if (type == CameraType::firstperson) {
191-
// Use the common console thumbstick layout
195+
// Use the common console thumbstick layout
192196
// Left = view, right = move
193197

194198
const float deadZone = 0.0015f;

base/common.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "common.hpp"
22

3-
3+
#if defined(__ANDROID__)
4+
android_app* global_android_app { nullptr };
5+
#endif
46

57
const vec3 Vectors::UNIT_X{ 1.0f, 0.0f, 0.0f };
68
const vec3 Vectors::UNIT_Y{ 0.0f, 1.0f, 0.0f };

base/common.hpp

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <list>
2020
#include <memory>
2121
#include <mutex>
22+
#include <queue>
2223
#include <random>
2324
#include <set>
2425
#include <string>
@@ -29,9 +30,10 @@
2930
#include <thread>
3031
#include <vector>
3132

32-
33-
#ifdef GLEW_STATIC
34-
#include <GL/glew.h>
33+
#if defined(__ANDROID__)
34+
#include <android/native_activity.h>
35+
#include <android/asset_manager.h>
36+
#include <android_native_app_glue.h>
3537
#endif
3638

3739
#include <glm/glm.hpp>
@@ -46,6 +48,13 @@
4648
#include <glm/gtx/transform.hpp>
4749
#include <glm/gtx/quaternion.hpp>
4850

51+
// Image loading
52+
#include <gli/gli.hpp>
53+
54+
// Vulkan!
55+
#include <vulkan/vulkan.hpp>
56+
57+
4958
using glm::ivec2;
5059
using glm::uvec2;
5160
using glm::vec2;
@@ -90,19 +99,54 @@ class Vectors {
9099
static const vec3 ZERO4;
91100
};
92101

93-
94-
// Image loading
95-
#include <gli/gli.hpp>
96-
97-
// Vulkan!
98-
#include <vulkan/vulkan.hpp>
99-
100-
// Cross platform window management
101-
#include "glfw.hpp"
102+
#if defined(__ANDROID__)
103+
#include <android/keycodes.h>
104+
105+
extern android_app* global_android_app;
106+
#define GLFW_KEY_F1 AKEYCODE_F1
107+
#define GLFW_KEY_ESCAPE AKEYCODE_ESCAPE
108+
#define GLFW_KEY_KP_ADD AKEYCODE_NUMPAD_ADD
109+
#define GLFW_KEY_KP_SUBTRACT AKEYCODE_NUMPAD_SUBTRACT
110+
#define GLFW_KEY_SPACE AKEYCODE_SPACE
111+
#define GLFW_KEY_A AKEYCODE_A
112+
#define GLFW_KEY_B AKEYCODE_B
113+
#define GLFW_KEY_D AKEYCODE_D
114+
#define GLFW_KEY_F AKEYCODE_F
115+
#define GLFW_KEY_G AKEYCODE_G
116+
#define GLFW_KEY_L AKEYCODE_L
117+
#define GLFW_KEY_O AKEYCODE_O
118+
#define GLFW_KEY_P AKEYCODE_P
119+
#define GLFW_KEY_R AKEYCODE_R
120+
#define GLFW_KEY_S AKEYCODE_S
121+
#define GLFW_KEY_T AKEYCODE_T
122+
#define GLFW_KEY_W AKEYCODE_W
123+
124+
125+
#else
126+
// Cross platform window management (except android)
127+
#include "glfw/glfw.hpp"
128+
#endif
102129

103130
// Boilerplate for running an example
131+
#if defined(__ANDROID__)
132+
#define ENTRY_POINT_START \
133+
void android_main(android_app* state) { \
134+
global_android_app = state;
135+
136+
#define ENTRY_POINT_END \
137+
}
138+
#else
139+
#define ENTRY_POINT_START \
140+
int main(const int argc, const char *argv[]) {
141+
142+
#define ENTRY_POINT_END \
143+
return 0; \
144+
}
145+
#endif
146+
104147
#define RUN_EXAMPLE(ExampleType) \
105-
int main(const int argc, const char *argv[]) { \
106-
ExampleType().run(); \
107-
return 0; \
108-
}
148+
ENTRY_POINT_START \
149+
ExampleType* example = new ExampleType(); \
150+
example->run(); \
151+
delete(example); \
152+
ENTRY_POINT_END

0 commit comments

Comments
 (0)