diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2017-12-12 06:43:48 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2017-12-12 06:43:48 +0000 |
| commit | c4bf1a06ce887fe6eafad80c1a2fda4be52388e7 (patch) | |
| tree | 68e209415527f553c2b1f8dd1adf4c6afb57e700 /unityplugin | |
| parent | Updated Visual Studio cmake config (diff) | |
| download | DiligentEngine-c4bf1a06ce887fe6eafad80c1a2fda4be52388e7.tar.gz DiligentEngine-c4bf1a06ce887fe6eafad80c1a2fda4be52388e7.zip | |
Added CMake files for Unity plugin & Emulator
Diffstat (limited to 'unityplugin')
| -rw-r--r-- | unityplugin/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | unityplugin/GhostCubePlugin/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | unityplugin/GhostCubePlugin/PluginSource/CMakeLists.txt | 106 | ||||
| -rw-r--r-- | unityplugin/GhostCubeScene/CMakeLists.txt | 69 | ||||
| -rw-r--r-- | unityplugin/GhostCubeScene/src/GhostCubeScene.cpp | 10 | ||||
| -rw-r--r-- | unityplugin/UnityEmulator/CMakeLists.txt | 118 | ||||
| -rw-r--r-- | unityplugin/UnityEmulator/src/UnityGraphicsD3D11Emulator.cpp | 4 | ||||
| -rw-r--r-- | unityplugin/UnityEmulator/src/UnityGraphicsD3D12Emulator.cpp | 7 | ||||
| -rw-r--r-- | unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.cpp | 2 | ||||
| -rw-r--r-- | unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.h | 4 | ||||
| -rw-r--r-- | unityplugin/UnityEmulator/src/Windows/WinMain.cpp | 1 |
11 files changed, 316 insertions, 13 deletions
diff --git a/unityplugin/CMakeLists.txt b/unityplugin/CMakeLists.txt new file mode 100644 index 0000000..bd06b94 --- /dev/null +++ b/unityplugin/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required (VERSION 3.3) + +add_subdirectory(UnityEmulator) +add_subdirectory(GhostCubeScene) +add_subdirectory(GhostCubePlugin) diff --git a/unityplugin/GhostCubePlugin/CMakeLists.txt b/unityplugin/GhostCubePlugin/CMakeLists.txt new file mode 100644 index 0000000..bf9d3c6 --- /dev/null +++ b/unityplugin/GhostCubePlugin/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required (VERSION 3.3) + +add_subdirectory(PluginSource) diff --git a/unityplugin/GhostCubePlugin/PluginSource/CMakeLists.txt b/unityplugin/GhostCubePlugin/PluginSource/CMakeLists.txt new file mode 100644 index 0000000..fd1d880 --- /dev/null +++ b/unityplugin/GhostCubePlugin/PluginSource/CMakeLists.txt @@ -0,0 +1,106 @@ +cmake_minimum_required (VERSION 3.3) + +project(GhostCubePlugin CXX) + +set(SOURCE + src/RenderAPI.cpp + src/RenderingPlugin.cpp + src/SamplePlugin.cpp +) + +set(INCLUDE + src/PlatformBase.h + src/RenderAPI.h + src/SamplePlugin.h +) + +if(D3D11_SUPPORTED) + list(APPEND SOURCE src/RenderAPI_D3D11.cpp) +endif() + +if(D3D12_SUPPORTED) + list(APPEND SOURCE src/RenderAPI_D3D12.cpp) +endif() + +if(GL_SUPPORTED OR GLES_SUPPORTED) + list(APPEND SOURCE src/RenderAPI_OpenGLCoreES.cpp) +endif() + +set(UNITY_INTERFACES + src/Unity/IUnityGraphics.h + src/Unity/IUnityGraphicsD3D9.h + src/Unity/IUnityGraphicsD3D11.h + src/Unity/IUnityGraphicsD3D12.h + src/Unity/IUnityGraphicsMetal.h + src/Unity/IUnityInterface.h +) + +add_library(GhostCubePlugin-shared SHARED + ${SOURCE} ${INCLUDE} ${UNITY_INTERFACES} +) + +if(PLATFORM_WIN32 OR PLATFORM_UNVIRSAL_WINDOWS) + if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") + set(ARCH 64) + else("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") + set(ARCH 32) + endif("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") +endif() + +set(DLL_REL_SUFFIX _${ARCH}r) +set(DLL_DBG_SUFFIX _${ARCH}d) + +set_target_properties(GhostCubePlugin-shared PROPERTIES + OUTPUT_NAME_DEBUG GhostCubePlugin${DLL_DBG_SUFFIX} + OUTPUT_NAME_RELEASE GhostCubePlugin${DLL_REL_SUFFIX} + OUTPUT_NAME_RELWITHDEBINFO GhostCubePlugin${DLL_REL_SUFFIX} + OUTPUT_NAME_MINSIZEREL GhostCubePlugin${DLL_REL_SUFFIX} +) + +if(PLATFORM_WIN32) + target_sources(GhostCubePlugin-shared + PRIVATE + src/RenderingPlugin.def + ) + source_group("src" FILES src/RenderingPlugin.def) +endif() + +target_link_libraries(GhostCubePlugin-shared +PRIVATE + BuildSettings + TargetPlatform + GraphicsTools +) + +if(D3D11_SUPPORTED) + target_link_libraries(GhostCubePlugin-shared PRIVATE GraphicsEngineD3D11-static) +endif() + +if(D3D12_SUPPORTED) + target_link_libraries(GhostCubePlugin-shared PRIVATE GraphicsEngineD3D12-static) +endif() + +if(GL_SUPPORTED OR GLES_SUPPORTED) + target_link_libraries(GhostCubePlugin-shared PRIVATE GraphicsEngineOpenGL-static) +endif() + +if(MSVC) + # Disable MSVC-specific warnings + # - w4201: nonstandard extension used: nameless struct/unio + target_compile_options(GhostCubePlugin-shared PRIVATE /wd4201) + # 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(GhostCubePlugin-shared PROPERTIES + LINK_FLAGS_RELEASE /LTCG + LINK_FLAGS_MINSIZEREL /LTCG + LINK_FLAGS_RELWITHDEBINFO /LTCG + ) +endif() + +source_group("src" FILES ${SOURCE}) +source_group("include" FILES ${INCLUDE}) +source_group("include\\Unity" FILES ${UNITY_INTERFACES}) + +set_target_properties(GhostCubePlugin-shared PROPERTIES + FOLDER Unity +) diff --git a/unityplugin/GhostCubeScene/CMakeLists.txt b/unityplugin/GhostCubeScene/CMakeLists.txt new file mode 100644 index 0000000..4f4aaf9 --- /dev/null +++ b/unityplugin/GhostCubeScene/CMakeLists.txt @@ -0,0 +1,69 @@ +cmake_minimum_required (VERSION 3.3) + +project(GhostCubeScene CXX) + +set(SOURCE + src/GhostCubeScene.cpp +) + +set(INCLUDE + src/GhostCubeScene.h +) + +if(PLATFORM_WIN32 OR PLATFORM_UNIVERSAL_WINDOWS) + list(APPEND SOURCE src/GhostCubeSceneResTrsnHelper.cpp) + list(APPEND INCLUDE src/GhostCubeSceneResTrsnHelper.h) +elseif(PLATFORM_ANDROID) + list(APPEND SOURCE src/Android/AndroidMain.cpp) +endif() + +if(PLATFORM_WIN32) + add_executable(GhostCubeScene WIN32 ${SOURCE} ${INCLUDE}) + set_target_properties(GhostCubeScene PROPERTIES + VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build/assets" + ) + + add_custom_command(TARGET GhostCubeScene POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "\"$<TARGET_FILE:GhostCubePlugin-shared>\"" + "\"$<TARGET_FILE_DIR:GhostCubeScene>\"") + +#elseif(APPLE) + #add_executable(GhostCubeScene MACOSX_BUNDLE Main.cpp) +#elseif(UNIX) + #add_executable(GhostCubeScene Main.cpp) +else() + message(FATAL_ERROR "Unknown platform") +endif() + +target_include_directories(GhostCubeScene +PRIVATE + ../GhostCubePlugin/PluginSource/src/Unity +) + +target_link_libraries(GhostCubeScene +PRIVATE + BuildSettings + UnityEmulator + TargetPlatform +) + +if(MSVC) + # Disable MSVC-specific warnings + # - w4201: nonstandard extension used: nameless struct/unio + target_compile_options(GhostCubeScene PRIVATE /wd4201) + # 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(GhostCubeScene PROPERTIES + LINK_FLAGS_RELEASE /LTCG + LINK_FLAGS_MINSIZEREL /LTCG + LINK_FLAGS_RELWITHDEBINFO /LTCG + ) +endif() + +source_group("src" FILES ${SOURCE}) +source_group("include" FILES ${INCLUDE}) + +set_target_properties(GhostCubeScene PROPERTIES + FOLDER Unity +) diff --git a/unityplugin/GhostCubeScene/src/GhostCubeScene.cpp b/unityplugin/GhostCubeScene/src/GhostCubeScene.cpp index 2fb3a97..dd3483f 100644 --- a/unityplugin/GhostCubeScene/src/GhostCubeScene.cpp +++ b/unityplugin/GhostCubeScene/src/GhostCubeScene.cpp @@ -177,11 +177,11 @@ void GhostCubeScene::Render(UnityRenderingEvent RenderEventFunc, double CurrTime float aspectRatio = 1.0f; float4x4 ReflectionCameraProj = Projection(PI_F / 4.f, aspectRatio, NearPlane, FarPlane, IsDX); auto wvp = CubeWorldView * ReflectionCameraProj; - float ReverseZ = IsDX ? -1.f : +1.f; - SetMatrixFromUnity(wvp._m00, ReverseZ * wvp._m01, wvp._m02, wvp._m03, - wvp._m10, ReverseZ * wvp._m11, wvp._m12, wvp._m13, - wvp._m20, ReverseZ * wvp._m21, wvp._m22, wvp._m23, - wvp._m30, ReverseZ * wvp._m31, wvp._m32, wvp._m33); + float fReverseZ = IsDX ? -1.f : +1.f; + SetMatrixFromUnity(wvp._m00, fReverseZ * wvp._m01, wvp._m02, wvp._m03, + wvp._m10, fReverseZ * wvp._m11, wvp._m12, wvp._m13, + wvp._m20, fReverseZ * wvp._m21, wvp._m22, wvp._m23, + wvp._m30, fReverseZ * wvp._m31, wvp._m32, wvp._m33); SetTexturesFromUnity(m_pRenderTarget->GetNativeHandle(), m_pDepthBuffer->GetNativeHandle()); 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); |
