summaryrefslogtreecommitdiffstats
path: root/unityplugin/UnityEmulator
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2017-12-12 06:43:48 +0000
committerEgor Yusov <egor.yusov@gmail.com>2017-12-12 06:43:48 +0000
commitc4bf1a06ce887fe6eafad80c1a2fda4be52388e7 (patch)
tree68e209415527f553c2b1f8dd1adf4c6afb57e700 /unityplugin/UnityEmulator
parentUpdated Visual Studio cmake config (diff)
downloadDiligentEngine-c4bf1a06ce887fe6eafad80c1a2fda4be52388e7.tar.gz
DiligentEngine-c4bf1a06ce887fe6eafad80c1a2fda4be52388e7.zip
Added CMake files for Unity plugin & Emulator
Diffstat (limited to 'unityplugin/UnityEmulator')
-rw-r--r--unityplugin/UnityEmulator/CMakeLists.txt118
-rw-r--r--unityplugin/UnityEmulator/src/UnityGraphicsD3D11Emulator.cpp4
-rw-r--r--unityplugin/UnityEmulator/src/UnityGraphicsD3D12Emulator.cpp7
-rw-r--r--unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.cpp2
-rw-r--r--unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.h4
-rw-r--r--unityplugin/UnityEmulator/src/Windows/WinMain.cpp1
6 files changed, 128 insertions, 8 deletions
diff --git a/unityplugin/UnityEmulator/CMakeLists.txt b/unityplugin/UnityEmulator/CMakeLists.txt
new file mode 100644
index 0000000..59d3b55
--- /dev/null
+++ b/unityplugin/UnityEmulator/CMakeLists.txt
@@ -0,0 +1,118 @@
+cmake_minimum_required (VERSION 3.3)
+
+project(UnityEmulator CXX)
+
+set(SOURCE
+ src/UnityGraphicsEmulator.cpp
+)
+
+set(INCLUDE
+ include/DiligentGraphicsAdapter.h
+ include/ResourceStateTransitionHandler.h
+ include/UnityGraphicsEmulator.h
+ include/UnitySceneBase.h
+)
+
+if(D3D11_SUPPORTED)
+ list(APPEND SOURCE src/DiligentGraphicsAdapterD3D11.cpp)
+ list(APPEND SOURCE src/UnityGraphicsD3D11Emulator.cpp)
+ list(APPEND SOURCE src/UnityGraphicsD3D11Impl.h)
+ list(APPEND INCLUDE include/DiligentGraphicsAdapterD3D11.h)
+ list(APPEND INCLUDE include/UnityGraphicsD3D11Emulator.h)
+endif()
+
+if(D3D12_SUPPORTED)
+ list(APPEND SOURCE src/DiligentGraphicsAdapterD3D12.cpp)
+ list(APPEND SOURCE src/UnityGraphicsD3D12Emulator.cpp)
+ list(APPEND SOURCE src/UnityGraphicsD3D12Impl.h)
+
+ list(APPEND INCLUDE include/DiligentGraphicsAdapterD3D12.h)
+ list(APPEND INCLUDE include/UnityGraphicsD3D12Emulator.h)
+endif()
+
+if(GL_SUPPORTED OR GLES_SUPPORTED)
+ list(APPEND SOURCE src/UnityGraphicsGLCoreES_Emulator.cpp)
+ list(APPEND SOURCE src/DiligentGraphicsAdapterGL.cpp)
+
+ list(APPEND INCLUDE include/UnityGraphicsGLCoreES_Emulator.h)
+ list(APPEND INCLUDE include/DiligentGraphicsAdapterGL.h)
+endif()
+
+if(GL_SUPPORTED)
+ list(APPEND SOURCE src/UnityGraphicsGLCore_Impl.cpp)
+ list(APPEND INCLUDE src/UnityGraphicsGLCore_Impl.h)
+endif()
+
+if(GLES_SUPPORTED)
+ list(APPEND SOURCE src/Android/UnityGraphicsGLESAndroid_Impl.cpp)
+ list(APPEND INCLUDE src/Android/UnityGraphicsGLESAndroid_Impl.h)
+endif()
+
+if(PLATFORM_WIN32)
+ list(APPEND SOURCE src/Windows/WinMain.cpp)
+elseif(PLATFORM_UNIVERSAL_WINDOWS)
+ list(APPEND SOURCE src/UWP/App.cpp)
+ list(APPEND INCLUDE src/UWP/DeviceResources.cpp)
+ list(APPEND INCLUDE src/UWP/UnityEmulatorAppMain.cpp)
+
+ list(APPEND INCLUDE src/UWP/App.h)
+ list(APPEND INCLUDE src/UWP/DeviceResources.h)
+ list(APPEND INCLUDE src/UWP/DirectXHelper.h)
+ list(APPEND INCLUDE src/UWP/pch2.h)
+ list(APPEND INCLUDE src/UWP/StepTimer.h)
+ list(APPEND INCLUDE src/UWP/UnityEmulatorAppMain.h)
+elseif(PLATFORM_ANDROID)
+ list(APPEND SOURCE src/Android/AndroidMainImpl.cpp)
+else()
+ message(FATAL_ERROR "Unknown platform")
+endif()
+
+
+add_library(UnityEmulator STATIC ${SOURCE} ${INCLUDE})
+
+target_include_directories(UnityEmulator
+PRIVATE
+ ../GhostCubePlugin/PluginSource/src/Unity
+PUBLIC
+ include
+)
+
+if(MSVC)
+ target_compile_options(UnityEmulator PRIVATE -DUNICODE)
+
+ # Enable link-time code generation for release builds (I was not able to
+ # find any way to set these settings through interface library BuildSettings)
+ set_target_properties(UnityEmulator PROPERTIES
+ STATIC_LIBRARY_FLAGS_RELEASE /LTCG
+ STATIC_LIBRARY_FLAGS_MINSIZEREL /LTCG
+ STATIC_LIBRARY_FLAGS_RELWITHDEBINFO /LTCG
+ )
+endif()
+
+target_link_libraries(UnityEmulator
+PRIVATE
+ BuildSettings
+ glew-static
+PUBLIC
+ Common
+ GraphicsEngine
+ GraphicsEngineOpenGL-static
+ GraphicsTools
+ TargetPlatform
+)
+
+if(PLATFORM_WIN32 OR PLATFORM_UNIVERSAL_WINDOWS)
+ target_link_libraries(UnityEmulator
+ PUBLIC
+ GraphicsEngineD3DBase
+ GraphicsEngineD3D11-static
+ GraphicsEngineD3D12-static
+)
+endif()
+
+source_group("src" FILES ${SOURCE})
+source_group("include" FILES ${INCLUDE})
+
+set_target_properties(UnityEmulator PROPERTIES
+ FOLDER Unity
+)
diff --git a/unityplugin/UnityEmulator/src/UnityGraphicsD3D11Emulator.cpp b/unityplugin/UnityEmulator/src/UnityGraphicsD3D11Emulator.cpp
index f6dc7e2..2f5dfc6 100644
--- a/unityplugin/UnityEmulator/src/UnityGraphicsD3D11Emulator.cpp
+++ b/unityplugin/UnityEmulator/src/UnityGraphicsD3D11Emulator.cpp
@@ -108,8 +108,8 @@ void UnityGraphicsD3D11Impl::CreateSwapChain(void* pNativeWndHandle, unsigned in
auto hWnd = reinterpret_cast<HWND>(pNativeWndHandle);
RECT rc;
GetClientRect( hWnd, &rc );
- VERIFY_EXPR(Width = rc.right - rc.left);
- VERIFY_EXPR(Height = rc.bottom - rc.top);
+ VERIFY_EXPR( static_cast<LONG>(Width) == rc.right - rc.left);
+ VERIFY_EXPR(static_cast<LONG>(Height) == rc.bottom - rc.top);
#endif
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {};
diff --git a/unityplugin/UnityEmulator/src/UnityGraphicsD3D12Emulator.cpp b/unityplugin/UnityEmulator/src/UnityGraphicsD3D12Emulator.cpp
index 45b7332..19d1f20 100644
--- a/unityplugin/UnityEmulator/src/UnityGraphicsD3D12Emulator.cpp
+++ b/unityplugin/UnityEmulator/src/UnityGraphicsD3D12Emulator.cpp
@@ -112,7 +112,7 @@ void UnityGraphicsD3D12Impl::CreateDeviceAndCommandQueue()
#endif
{
- auto hr = m_D3D12Device->CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(m_D3D12FrameFence), reinterpret_cast<void**>(static_cast<ID3D12Fence**>(&m_D3D12FrameFence)));
+ hr = m_D3D12Device->CreateFence(0, D3D12_FENCE_FLAG_NONE, __uuidof(m_D3D12FrameFence), reinterpret_cast<void**>(static_cast<ID3D12Fence**>(&m_D3D12FrameFence)));
VERIFY(SUCCEEDED(hr), "Failed to create the fence");
m_D3D12FrameFence->SetName(L"Completed Frame Fence fence");
m_D3D12FrameFence->Signal(m_CompletedFenceValue); // 0 cmd lists are completed
@@ -141,8 +141,8 @@ void UnityGraphicsD3D12Impl::CreateSwapChain(void* pNativeWndHandle, unsigned in
auto hWnd = reinterpret_cast<HWND>(pNativeWndHandle);
RECT rc;
GetClientRect( hWnd, &rc );
- VERIFY_EXPR(Width = rc.right - rc.left);
- VERIFY_EXPR(Height = rc.bottom - rc.top);
+ VERIFY_EXPR(static_cast<LONG>(Width) == rc.right - rc.left);
+ VERIFY_EXPR(static_cast<LONG>(Height) == rc.bottom - rc.top);
#endif
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {};
@@ -233,6 +233,7 @@ void UnityGraphicsD3D12Impl::InitBuffersAndViews()
for (UINT n = 0; n < m_BackBuffersCount; n++)
{
auto hr = m_SwapChain->GetBuffer(n, IID_PPV_ARGS(&m_RenderTargets[n]));
+ VERIFY_EXPR(SUCCEEDED(hr))
D3D12_RENDER_TARGET_VIEW_DESC RTVDesc = {};
RTVDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;
diff --git a/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.cpp b/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.cpp
index 7a3d8c2..0e8c542 100644
--- a/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.cpp
+++ b/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.cpp
@@ -150,7 +150,7 @@ void UnityGraphicsGLCore_Impl::InitGLContext(void *pNativeWndHandle, int MajorVe
//Or better yet, use the GL3 way to get the version number
glGetIntegerv( GL_MAJOR_VERSION, &MajorVersion );
glGetIntegerv( GL_MINOR_VERSION, &MinorVersion );
- LOG_INFO_MESSAGE("Initialized OpenGL ", MajorVersion, '.', MinorVersion, " context")
+ LOG_INFO_MESSAGE("Initialized OpenGL ", MajorVersion, '.', MinorVersion, " context (", GLVersionString, ")")
if( glDebugMessageCallback )
{
diff --git a/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.h b/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.h
index d1bd531..ec65625 100644
--- a/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.h
+++ b/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.h
@@ -4,7 +4,9 @@
#if OPENGL_SUPPORTED
-#define GLEW_STATIC
+#ifndef GLEW_STATIC
+# define GLEW_STATIC
+#endif
#include "glew.h"
#define NOMINMAX
#include "wglew.h"
diff --git a/unityplugin/UnityEmulator/src/Windows/WinMain.cpp b/unityplugin/UnityEmulator/src/Windows/WinMain.cpp
index 9d3ea78..c8085aa 100644
--- a/unityplugin/UnityEmulator/src/Windows/WinMain.cpp
+++ b/unityplugin/UnityEmulator/src/Windows/WinMain.cpp
@@ -270,7 +270,6 @@ int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int cmdShow)
auto CurrTime = timer.GetElapsedTime();
auto ElapsedTime = CurrTime - PrevTime;
PrevTime = CurrTime;
- float fTime = static_cast<float>(CurrTime);
g_pScene->Render(RenderEventFunc, CurrTime, ElapsedTime);