summaryrefslogtreecommitdiffstats
path: root/Common
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-02-12 06:07:27 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-02-12 06:07:27 +0000
commit4effe027896a64d1db24c46aff96bb5e09b67c8d (patch)
tree1d6621c96fd94799d6e1ccf9b8c19f5f5a233e4d /Common
parentRemoved unused Apple source from Unity emulator (diff)
downloadDiligentEngine-4effe027896a64d1db24c46aff96bb5e09b67c8d.tar.gz
DiligentEngine-4effe027896a64d1db24c46aff96bb5e09b67c8d.zip
Enabled iOS build; unified target platform app generation in cmake
Diffstat (limited to 'Common')
-rw-r--r--Common/NativeApp/Apple/Source/Classes/iOS/EAGLView.m18
-rw-r--r--Common/NativeApp/CMakeLists.txt84
-rw-r--r--Common/NativeApp/include/IOS/IOSAppBase.h39
-rw-r--r--Common/NativeApp/include/NativeAppBase.h5
-rw-r--r--Common/NativeApp/src/IOS/IOSAppBase.cpp34
5 files changed, 158 insertions, 22 deletions
diff --git a/Common/NativeApp/Apple/Source/Classes/iOS/EAGLView.m b/Common/NativeApp/Apple/Source/Classes/iOS/EAGLView.m
index e361cf2..42cb38d 100644
--- a/Common/NativeApp/Apple/Source/Classes/iOS/EAGLView.m
+++ b/Common/NativeApp/Apple/Source/Classes/iOS/EAGLView.m
@@ -8,12 +8,12 @@
#import "EAGLView.h"
-#include "Renderer.h"
+#include "NativeAppBase.h"
#include <memory>
@interface EAGLView ()
{
- std::unique_ptr<Renderer> _renderer;
+ std::unique_ptr<NativeAppBase> _theApp;
EAGLContext* _context;
NSInteger _animationFrameInterval;
CADisplayLink* _displayLink;
@@ -48,11 +48,11 @@
return nil;
}
- _renderer.reset(new Renderer());
+ _theApp.reset(CreateApplication());
// Init our renderer.
- _renderer->Init((__bridge void*)self.layer);
+ _theApp->OnGLContextCreated((__bridge void*)self.layer);
- if (!_renderer)
+ if (!_theApp)
{
return nil;
}
@@ -68,12 +68,14 @@
- (void) drawView:(id)sender
{
[EAGLContext setCurrentContext:_context];
- _renderer->Render();
+ _theApp->Update();
+ _theApp->Render();
+ _theApp->Present();
}
- (void) layoutSubviews
{
- _renderer->WindowResize(0, 0);
+ _theApp->WindowResize(0, 0);
[self drawView:nil];
}
@@ -131,7 +133,7 @@
- (void) dealloc
{
- _renderer.reset();
+ _theApp.reset();
// tear down context
if ([EAGLContext currentContext] == _context)
diff --git a/Common/NativeApp/CMakeLists.txt b/Common/NativeApp/CMakeLists.txt
index 1223b74..844aa3d 100644
--- a/Common/NativeApp/CMakeLists.txt
+++ b/Common/NativeApp/CMakeLists.txt
@@ -15,6 +15,10 @@ if(PLATFORM_WIN32)
add_executable(${TARGET_NAME} WIN32 ${SOURCE} ${INCLUDE} ${ASSETS})
endfunction()
+ function(add_target_platform_app TARGET_NAME SOURCE INCLUDE ASSETS)
+ add_win32_app("${TARGET_NAME}" "${SOURCE}" "${INCLUDE}" "${ASSETS}")
+ endfunction()
+
elseif(PLATFORM_UNIVERSAL_WINDOWS)
set(SOURCE
@@ -45,6 +49,7 @@ elseif(PLATFORM_UNIVERSAL_WINDOWS)
)
add_executable(${TARGET_NAME} WIN32 ${SOURCE} ${INCLUDE} ${ASSETS} ${UWP_SOURCE} ${UWP_INCLUDE})
+ set_source_files_properties(${ASSETS} PROPERTIES VS_DEPLOYMENT_CONTENT 1)
target_include_directories(${TARGET_NAME}
PUBLIC
@@ -56,6 +61,11 @@ elseif(PLATFORM_UNIVERSAL_WINDOWS)
endfunction(add_uwp_app)
+ function(add_target_platform_app TARGET_NAME SOURCE INCLUDE ASSETS)
+ add_uwp_app("${TARGET_NAME}" "${SOURCE}" "${INCLUDE}" "${ASSETS}")
+ endfunction()
+
+
elseif(PLATFORM_ANDROID)
set(SOURCE
@@ -82,6 +92,10 @@ elseif(PLATFORM_ANDROID)
source_group("Android" FILES ${ANDROID_SOURCE})
endfunction()
+ function(add_target_platform_app TARGET_NAME SOURCE INCLUDE ASSETS)
+ add_android_app("${TARGET_NAME}" "${SOURCE}" "${INCLUDE}" "${ASSETS}")
+ endfunction()
+
elseif(PLATFORM_LINUX)
set(SOURCE
@@ -90,6 +104,11 @@ elseif(PLATFORM_LINUX)
function(add_linux_app TARGET_NAME SOURCE INCLUDE ASSETS)
add_executable(${TARGET_NAME} ${SOURCE} ${INCLUDE} ${ASSETS})
endfunction()
+
+ function(add_target_platform_app TARGET_NAME SOURCE INCLUDE ASSETS)
+ add_linux_app("${TARGET_NAME}" "${SOURCE}" "${INCLUDE}" "${ASSETS}")
+ endfunction()
+
elseif(PLATFORM_MACOS)
@@ -155,19 +174,23 @@ elseif(PLATFORM_MACOS)
endfunction()
+ function(add_target_platform_app TARGET_NAME SOURCE INCLUDE ASSETS)
+ add_macos_app("${TARGET_NAME}" "${SOURCE}" "${INCLUDE}" "${ASSETS}")
+ endfunction()
+
elseif(PLATFORM_IOS)
set(SOURCE
- src/MacOS/Renderer.cpp
+ src/IOS/IOSAppBase.cpp
)
set(INCLUDE
- src/MacOS/Renderer.h
+ include/IOS/IOSAppBase.h
)
- function(get_native_app_ios_source APPLE_SOURCE APPLE_INCLUDE APPLE_RESOURCES APPLE_INFO_PLIST APPLE_INCLUDE_DIRS)
+ function(add_ios_app TARGET_NAME SOURCE INCLUDE ASSETS)
get_target_property(NATIVE_APP_SOURCE_DIR NativeAppBase SOURCE_DIR)
- set(${APPLE_SOURCE}
+ set(APPLE_SOURCE
${NATIVE_APP_SOURCE_DIR}/Apple/Source/main.m
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/iOS/AppDelegate.m
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/iOS/EAGLView.m
@@ -175,32 +198,61 @@ elseif(PLATFORM_IOS)
set_source_files_properties(${APPLE_SOURCE} PROPERTIES
COMPILE_FLAGS "-x objective-c++"
)
- set( APPLE_SOURCE ${APPLE_SOURCE} PARENT_SCOPE )
- set(${APPLE_INCLUDE}
+ set(APPLE_INCLUDE
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/iOS/AppDelegate.h
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/iOS/EAGLView.h
- PARENT_SCOPE
)
- set(${APPLE_RESOURCES}
+ set(APPLE_RESOURCES
${NATIVE_APP_SOURCE_DIR}/Apple/Data/iOS/Base.lproj/Main.storyboard
${NATIVE_APP_SOURCE_DIR}/Apple/Data/iOS/Base.lproj/LaunchScreen.xib
${NATIVE_APP_SOURCE_DIR}/Apple/Data/iOS/Images.xcassets/AppIcon.appiconset/dg-icon.png
- PARENT_SCOPE
)
- set(${APPLE_INFO_PLIST}
+ set(APPLE_INFO_PLIST
${NATIVE_APP_SOURCE_DIR}/Apple/Data/iOS/info.plist
- PARENT_SCOPE
)
- set(${APPLE_INCLUDE_DIRS}
+ set(APPLE_INCLUDE_DIRS
${NATIVE_APP_SOURCE_DIR}/Apple/Source/Classes/iOS
- PARENT_SCOPE
)
+
+ add_executable(${TARGET_NAME} MACOSX_BUNDLE ${SOURCE} ${APPLE_SOURCE} ${INCLUDE} ${APPLE_INCLUDE} ${ASSETS} ${APPLE_RESOURCES})
+ set_target_properties(${TARGET_NAME} PROPERTIES
+ MACOSX_BUNDLE_GUI_IDENTIFIER "com.diligentengine.samples.${TARGET_NAME}"
+ MACOSX_BUNDLE_INFO_PLIST "${APPLE_INFO_PLIST}"
+ RESOURCE "${APPLE_RESOURCES}"
+ )
+ source_group("iOS" FILES ${APPLE_SOURCE})
+ source_group("iOS" FILES ${APPLE_INCLUDE})
+ source_group("Resources" FILES ${APPLE_RESOURCES})
+ target_include_directories(${TARGET_NAME} PRIVATE ${APPLE_INCLUDE_DIRS})
+
+ find_library(OPENGLES OpenGLES)
+ if (NOT OPENGLES)
+ message(FATAL_ERROR "OpenGLES not found")
+ endif()
+
+ find_library(UIKIT UIKit)
+ if (NOT UIKIT)
+ message(FATAL_ERROR "UIKIT not found")
+ endif()
+
+ find_library(CORE_ANIMATION QuartzCore)
+ if (NOT CORE_ANIMATION)
+ message(FATAL_ERROR "QuartzCore (CoreAnimation) not found")
+ endif()
+
+ target_link_libraries(${TARGET_NAME} PRIVATE ${OPENGLES} ${UIKIT} ${CORE_ANIMATION})
+ endfunction()
+
+ function(add_target_platform_app TARGET_NAME SOURCE INCLUDE ASSETS)
+ add_ios_app("${TARGET_NAME}" "${SOURCE}" "${INCLUDE}" "${ASSETS}")
endfunction()
+else()
+ message(FATAL_ERROR "Unknown platform")
endif()
list(APPEND INCLUDE
@@ -266,11 +318,15 @@ elseif(PLATFORM_LINUX)
include/Linux
)
-elseif(PLATFORM_MACOS OR PLATFORM_IOS)
+elseif(PLATFORM_MACOS)
target_include_directories(NativeAppBase PUBLIC
src/MacOS
include/MacOS
)
+elseif(PLATFORM_IOS)
+ target_include_directories(NativeAppBase PUBLIC
+ include/IOS
+ )
endif()
source_group("src" FILES ${SOURCE})
diff --git a/Common/NativeApp/include/IOS/IOSAppBase.h b/Common/NativeApp/include/IOS/IOSAppBase.h
new file mode 100644
index 0000000..49e6089
--- /dev/null
+++ b/Common/NativeApp/include/IOS/IOSAppBase.h
@@ -0,0 +1,39 @@
+/* Copyright 2015-2018 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+#include "AppBase.h"
+#include "Timer.h"
+
+class IOSAppBase : public AppBase
+{
+public:
+ using AppBase::Update;
+ void Update();
+ virtual void OnGLContextCreated(void *eaglLayer) = 0;
+
+protected:
+ Diligent::Timer timer;
+ double PrevTime = 0.0;
+};
diff --git a/Common/NativeApp/include/NativeAppBase.h b/Common/NativeApp/include/NativeAppBase.h
index 6c0077d..7ea1938 100644
--- a/Common/NativeApp/include/NativeAppBase.h
+++ b/Common/NativeApp/include/NativeAppBase.h
@@ -47,6 +47,11 @@
#include "MacOSAppBase.h"
using NativeAppBase = MacOSAppBase;
+#elif PLATFORM_IOS
+
+ #include "IOSAppBase.h"
+ using NativeAppBase = IOSAppBase;
+
#else
# error Usnupported paltform
diff --git a/Common/NativeApp/src/IOS/IOSAppBase.cpp b/Common/NativeApp/src/IOS/IOSAppBase.cpp
new file mode 100644
index 0000000..eadbca5
--- /dev/null
+++ b/Common/NativeApp/src/IOS/IOSAppBase.cpp
@@ -0,0 +1,34 @@
+/* Copyright 2015-2018 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#include "IOSAppBase.h"
+
+void IOSAppBase::Update()
+{
+ // Render the scene
+ auto CurrTime = timer.GetElapsedTime();
+ auto ElapsedTime = CurrTime - PrevTime;
+ PrevTime = CurrTime;
+ Update(CurrTime, ElapsedTime);
+}
+