Skip to content

Commit ee177d3

Browse files
Moved Native App from master repository
1 parent 52fb48f commit ee177d3

119 files changed

Lines changed: 12819 additions & 13 deletions

File tree

Some content is hidden

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

AssetLoader/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ PRIVATE
4242
)
4343

4444
set_target_properties(Diligent-AssetLoader PROPERTIES
45-
FOLDER Tools
45+
FOLDER DiligentTools
4646
)

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ add_subdirectory(ThirdParty)
66
add_subdirectory(TextureLoader)
77
add_subdirectory(AssetLoader)
88
add_subdirectory(Imgui)
9+
add_subdirectory(NativeApp)
910

1011
if(${DILIGENT_BUILD_RENDER_SCRIPT})
1112
add_subdirectory(RenderScript)

HLSL2GLSLConverter/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ PRIVATE
3333
source_group("source" FILES ${SOURCE})
3434

3535
set_target_properties(HLSL2GLSLConverter PROPERTIES
36-
FOLDER Tools
36+
FOLDER DiligentTools
3737
)

Imgui/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,5 @@ PRIVATE
9999
)
100100

101101
set_target_properties(Diligent-Imgui PROPERTIES
102-
FOLDER Tools
102+
FOLDER DiligentTools
103103
)

NativeApp/Android/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/build
2+
/.externalNativeBuild
3+
*.iml
4+
.cxx

NativeApp/Android/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required (VERSION 3.6)
2+
3+
add_library(native_app_glue ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
4+
target_link_libraries(native_app_glue log)
5+
target_include_directories(native_app_glue INTERFACE ${ANDROID_NDK}/sources/android/native_app_glue)
6+
set_common_target_properties(native_app_glue)
7+
8+
add_subdirectory(ndk_helper)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
android {
2+
compileSdkVersion=28
3+
4+
defaultConfig {
5+
minSdkVersion 21
6+
targetSdkVersion 28
7+
versionCode 1
8+
versionName "1.0"
9+
10+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
11+
}
12+
}

NativeApp/Android/build.gradle

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apply plugin: 'com.android.library'
2+
apply from: "android_common.gradle"
3+
4+
android {
5+
defaultConfig {
6+
7+
ndk {
8+
abiFilters 'armeabi-v7a'//, 'armeabi', 'arm64-v8a','x86', 'x86_64'
9+
}
10+
externalNativeBuild {
11+
cmake {
12+
arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static', '-DENABLE_TESTS=TRUE'
13+
}
14+
}
15+
}
16+
17+
externalNativeBuild {
18+
cmake {
19+
version '3.10.2'
20+
path '../../../CMakeLists.txt'
21+
}
22+
}
23+
24+
sourceSets {
25+
main {
26+
java.srcDirs = ['src/main/java', 'ndk_helper/src/java']
27+
}
28+
}
29+
30+
buildTypes {
31+
release {
32+
minifyEnabled false
33+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34+
}
35+
}
36+
}
37+
38+
buildDir './build'
39+
40+
dependencies {
41+
implementation fileTree(dir: 'libs', include: ['*.jar'])
42+
implementation 'com.android.support:appcompat-v7:28.0.0'
43+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
cmake_minimum_required (VERSION 3.6)
2+
3+
project(NDKHelper CXX)
4+
5+
set(SOURCE
6+
src/gestureDetector.cpp
7+
src/JNIHelper.cpp
8+
src/perfMonitor.cpp
9+
src/sensorManager.cpp
10+
src/tapCamera.cpp
11+
src/vecmath.cpp
12+
)
13+
14+
set(INCLUDE
15+
include/gestureDetector.h
16+
include/JNIHelper.h
17+
include/perfMonitor.h
18+
include/sensorManager.h
19+
include/tapCamera.h
20+
)
21+
22+
add_library(NDKHelper STATIC ${SOURCE} ${INCLUDE})
23+
set_common_target_properties(NDKHelper)
24+
25+
target_include_directories(NDKHelper
26+
PUBLIC
27+
include
28+
)
29+
30+
target_link_libraries(NDKHelper
31+
PRIVATE
32+
Diligent-BuildSettings
33+
PUBLIC
34+
native_app_glue
35+
)
36+
37+
source_group("src" FILES ${SOURCE})
38+
source_group("include" FILES ${INCLUDE})
39+
40+
set_target_properties(NDKHelper PROPERTIES
41+
FOLDER Core/External
42+
)
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Copyright 2013 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
//--------------------------------------------------------------------------------
18+
// GLContext.h
19+
//--------------------------------------------------------------------------------
20+
#ifndef GLCONTEXT_H_
21+
#define GLCONTEXT_H_
22+
23+
#include <EGL/egl.h>
24+
#include <GLES2/gl2.h>
25+
#include <android/log.h>
26+
27+
#include "JNIHelper.h"
28+
29+
namespace ndk_helper {
30+
31+
//--------------------------------------------------------------------------------
32+
// Constants
33+
//--------------------------------------------------------------------------------
34+
35+
//--------------------------------------------------------------------------------
36+
// Class
37+
//--------------------------------------------------------------------------------
38+
39+
/******************************************************************
40+
* OpenGL context handler
41+
* The class handles OpenGL and EGL context based on Android activity life cycle
42+
* The caller needs to call corresponding methods for each activity life cycle
43+
*events as it's done in sample codes.
44+
*
45+
* Also the class initializes OpenGL ES3 when the compatible driver is installed
46+
*in the device.
47+
* getGLVersion() returns 3.0~ when the device supports OpenGLES3.0
48+
*
49+
* Thread safety: OpenGL context is expecting used within dedicated single
50+
*thread,
51+
* thus GLContext class is not designed as a thread-safe
52+
*/
53+
class GLContext {
54+
private:
55+
// EGL configurations
56+
ANativeWindow* window_;
57+
EGLDisplay display_;
58+
EGLSurface surface_;
59+
EGLContext context_;
60+
EGLConfig config_;
61+
62+
// Screen parameters
63+
int32_t screen_width_;
64+
int32_t screen_height_;
65+
int32_t color_size_;
66+
int32_t depth_size_;
67+
68+
// Flags
69+
bool gles_initialized_;
70+
bool egl_context_initialized_;
71+
bool es3_supported_;
72+
float gl_version_;
73+
bool context_valid_;
74+
75+
void InitGLES();
76+
void Terminate();
77+
bool InitEGLSurface();
78+
bool InitEGLContext();
79+
80+
GLContext(GLContext const&);
81+
void operator=(GLContext const&);
82+
GLContext();
83+
virtual ~GLContext();
84+
85+
public:
86+
static GLContext* GetInstance() {
87+
// Singleton
88+
static GLContext instance;
89+
90+
return &instance;
91+
}
92+
93+
bool Init(ANativeWindow* window);
94+
EGLint Swap();
95+
bool Invalidate();
96+
97+
void Suspend();
98+
EGLint Resume(ANativeWindow* window);
99+
100+
ANativeWindow* GetANativeWindow(void) const { return window_; };
101+
int32_t GetScreenWidth() const { return screen_width_; }
102+
int32_t GetScreenHeight() const { return screen_height_; }
103+
104+
int32_t GetBufferColorSize() const { return color_size_; }
105+
int32_t GetBufferDepthSize() const { return depth_size_; }
106+
float GetGLVersion() const { return gl_version_; }
107+
bool CheckExtension(const char* extension);
108+
109+
EGLDisplay GetDisplay() const { return display_; }
110+
EGLSurface GetSurface() const { return surface_; }
111+
};
112+
113+
} // namespace ndkHelper
114+
115+
#endif /* GLCONTEXT_H_ */

0 commit comments

Comments
 (0)