diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-02-11 21:38:53 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-02-11 21:38:53 +0000 |
| commit | 1fb16e012915f52dd35cc67ef07401c54c241c64 (patch) | |
| tree | c3fef4fa6672a233ab38d96d1ccfebac56df2c15 /unityplugin/UnityEmulator | |
| parent | Updated core submodule (diff) | |
| download | DiligentEngine-1fb16e012915f52dd35cc67ef07401c54c241c64.tar.gz DiligentEngine-1fb16e012915f52dd35cc67ef07401c54c241c64.zip | |
Fixed MacOS build
Diffstat (limited to 'unityplugin/UnityEmulator')
| -rw-r--r-- | unityplugin/UnityEmulator/CMakeLists.txt | 48 | ||||
| -rw-r--r-- | unityplugin/UnityEmulator/src/MacOS/Renderer.cpp | 126 | ||||
| -rw-r--r-- | unityplugin/UnityEmulator/src/MacOS/Renderer.h | 50 | ||||
| -rw-r--r-- | unityplugin/UnityEmulator/src/MacOS/UnityAppMacOS.cpp | 77 | ||||
| -rw-r--r-- | unityplugin/UnityEmulator/src/UnityAppBase.cpp | 2 |
5 files changed, 82 insertions, 221 deletions
diff --git a/unityplugin/UnityEmulator/CMakeLists.txt b/unityplugin/UnityEmulator/CMakeLists.txt index e26e6af..4b6eba0 100644 --- a/unityplugin/UnityEmulator/CMakeLists.txt +++ b/unityplugin/UnityEmulator/CMakeLists.txt @@ -87,58 +87,16 @@ elseif(PLATFORM_LINUX) list(APPEND INCLUDE include/UnityAppBase.h)
elseif(PLATFORM_MACOS)
list(APPEND SOURCE
- src/Linux/LinuxMain.cpp
- src/MacOS/Renderer.cpp
- src/UnityAppBase.cpp
+ src/MacOS/UnityAppMacOS.cpp
+ src/UnityAppBase.cpp
)
list(APPEND INCLUDE
- src/MacOS/Renderer.h
- include/UnityAppBase.h
+ include/UnityAppBase.h
)
set_source_files_properties(src/UnityGraphicsGLCore_Impl.cpp
PROPERTIES COMPILE_FLAGS "-x objective-c++"
)
- function(get_emulator_macos_source MAC_SOURCE MAC_INCLUDE MAC_RESOURCES MAC_INFO_PLIST MAC_INCLUDE_DIRS)
- get_target_property(EMULATOR_SOURCE_DIR UnityEmulator SOURCE_DIR)
-
- set(${MAC_SOURCE}
- ${EMULATOR_SOURCE_DIR}/Apple/Source/main.m
- ${EMULATOR_SOURCE_DIR}/Apple/Source/Classes/OSX/WindowController.m
- ${EMULATOR_SOURCE_DIR}/Apple/Source/Classes/OSX/AppDelegate.m
- ${EMULATOR_SOURCE_DIR}/Apple/Source/Classes/OSX/FullscreenWindow.m
- ${EMULATOR_SOURCE_DIR}/Apple/Source/Classes/OSX/GLView.m
- )
- set_source_files_properties(${MAC_SOURCE} PROPERTIES
- COMPILE_FLAGS "-x objective-c++"
- )
- set( MAC_SOURCE ${MAC_SOURCE} PARENT_SCOPE )
-
- set(${MAC_INCLUDE}
- ${EMULATOR_SOURCE_DIR}/Apple/Source/Classes/OSX/WindowController.h
- ${EMULATOR_SOURCE_DIR}/Apple/Source/Classes/OSX/AppDelegate.h
- ${EMULATOR_SOURCE_DIR}/Apple/Source/Classes/OSX/FullscreenWindow.h
- ${EMULATOR_SOURCE_DIR}/Apple/Source/Classes/OSX/GLView.h
- PARENT_SCOPE
- )
-
- set(${MAC_RESOURCES}
- ${EMULATOR_SOURCE_DIR}/Apple/Data/OSX/Base.lproj/Main.storyboard
- ${EMULATOR_SOURCE_DIR}/Apple/Data/OSX/Images.xcassets/AppIcon.appiconset/dg.icns
- PARENT_SCOPE
- )
-
- set(${MAC_INFO_PLIST}
- ${EMULATOR_SOURCE_DIR}/Apple/Data/OSX/Info.plist
- PARENT_SCOPE
- )
-
- set(${MAC_INCLUDE_DIRS}
- ${EMULATOR_SOURCE_DIR}/Apple/Source/Classes/OSX
- PARENT_SCOPE
- )
- endfunction()
-
elseif(PLATFORM_IOS)
else()
diff --git a/unityplugin/UnityEmulator/src/MacOS/Renderer.cpp b/unityplugin/UnityEmulator/src/MacOS/Renderer.cpp deleted file mode 100644 index b793965..0000000 --- a/unityplugin/UnityEmulator/src/MacOS/Renderer.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* 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 "Renderer.h" -#include "Errors.h" -#include "RenderDeviceFactoryOpenGL.h" - -#include "IUnityInterface.h" -#include "UnityGraphicsGLCoreES_Emulator.h" -#include "DiligentGraphicsAdapterGL.h" -#include "StringTools.h" - -using namespace Diligent; - -extern "C" -{ - void __attribute__((visibility("default"))) UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces); - void __attribute__((visibility("default"))) UNITY_INTERFACE_API UnityPluginUnload(); - UnityRenderingEvent __attribute__((visibility("default"))) UNITY_INTERFACE_API GetRenderEventFunc(); -} - -void* LoadPluginFunction(const char* FunctionName); - -bool LoadPlugin() -{ - // Do nothing. Function pointers are set automagically - return true; -} - -void UnloadPlugin(UnityGraphicsEmulator *GraphicsEmulator) -{ - GraphicsEmulator->InvokeDeviceEventCallback(kUnityGfxDeviceEventShutdown); - UnityPluginUnload(); -} - -Renderer::Renderer() -{ -} - -Renderer::~Renderer() -{ - - pScene->OnPluginUnload(); - pScene.reset(); - UnloadPlugin(GraphicsEmulator); - - pDiligentGraphics.reset(); - GraphicsEmulator->Release(); -} - -void Renderer::Init() -{ - int major_version = 4; - int minor_version = 1; - auto &GraphicsGLCoreES_Emulator = UnityGraphicsGLCoreES_Emulator::GetInstance(); - GraphicsGLCoreES_Emulator.InitGLContext(nullptr, major_version, minor_version); - - pDiligentGraphics.reset(new DiligentGraphicsAdapterGL(GraphicsGLCoreES_Emulator)); - GraphicsEmulator = &GraphicsGLCoreES_Emulator; - - pScene.reset(CreateScene()); - std::string Title = pScene->GetSceneName(); - pScene->SetDiligentGraphicsAdapter(pDiligentGraphics.get()); - pScene->OnGraphicsInitialized(); - //if (DevType == DeviceType::D3D12) - //{ - // UnityGraphicsD3D12Emulator::GetInstance().SetTransitionHandler(g_pScene->GetStateTransitionHandler()); - //} - - if (!LoadPlugin()) - { - LOG_ERROR_AND_THROW("Failed to load the plugin"); - } - - pScene->OnPluginLoad(LoadPluginFunction); - UnityPluginLoad(&GraphicsEmulator->GeUnityInterfaces()); - - RenderEventFunc = GetRenderEventFunc(); - - PrevTime = timer.GetElapsedTime(); -} - -void Renderer::WindowResize(int width, int height) -{ - pDiligentGraphics->PreSwapChainResize(); - GraphicsEmulator->ResizeSwapChain(static_cast<Uint32>(width), static_cast<Uint32>(height)); - pDiligentGraphics->PostSwapChainResize(); - pScene->OnWindowResize(static_cast<Uint32>(width), static_cast<Uint32>(height)); -} - -void Renderer::Render() -{ - // Render the scene - auto CurrTime = timer.GetElapsedTime(); - auto ElapsedTime = CurrTime - PrevTime; - PrevTime = CurrTime; - - GraphicsEmulator->BeginFrame(); - pDiligentGraphics->BeginFrame(); - - pScene->Render(RenderEventFunc, CurrTime, ElapsedTime); - - pDiligentGraphics->EndFrame(); - GraphicsEmulator->EndFrame(); -} - diff --git a/unityplugin/UnityEmulator/src/MacOS/Renderer.h b/unityplugin/UnityEmulator/src/MacOS/Renderer.h deleted file mode 100644 index f9e591e..0000000 --- a/unityplugin/UnityEmulator/src/MacOS/Renderer.h +++ /dev/null @@ -1,50 +0,0 @@ -/* 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 "RenderDevice.h" -#include "DeviceContext.h" -#include "SwapChain.h" -#include "RefCntAutoPtr.h" -#include "UnitySceneBase.h" -#include "Timer.h" -#include <queue> - -class Renderer -{ -public: - Renderer(); - ~Renderer(); - void Init(); - void WindowResize(int width, int height); - void Render(); - const char* GetSceneName()const{return pScene->GetSceneName();} - -private: - class UnityGraphicsEmulator *GraphicsEmulator = nullptr; - std::unique_ptr<class DiligentGraphicsAdapter> pDiligentGraphics; - std::unique_ptr<UnitySceneBase> pScene; - UnityRenderingEvent RenderEventFunc; - Diligent::Timer timer; - double PrevTime = 0.0; -}; - diff --git a/unityplugin/UnityEmulator/src/MacOS/UnityAppMacOS.cpp b/unityplugin/UnityEmulator/src/MacOS/UnityAppMacOS.cpp new file mode 100644 index 0000000..f0f7705 --- /dev/null +++ b/unityplugin/UnityEmulator/src/MacOS/UnityAppMacOS.cpp @@ -0,0 +1,77 @@ +/* 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 "UnityGraphicsEmulator.h" +#include "UnityAppBase.h" +#include "IUnityInterface.h" +#include "Errors.h" + +class UnityAppMacOS : public UnityAppBase +{ +public: + UnityAppMacOS() + { + m_DeviceType = Diligent::DeviceType::OpenGL; + } + + virtual void OnGLContextCreated()override final + { + InitGraphics(nullptr, 0/*Unused*/, 0/*Unused*/); + InitScene(); + } +}; + +NativeAppBase* CreateApplication() +{ + return new UnityAppMacOS(); +} + +// The function must be defined in the plugin +extern void *LoadPluginFunction(const char *name); +void* UnityAppBase::LoadPluginFunction(const char* FunctionName) +{ + return ::LoadPluginFunction(FunctionName); +} + +extern "C" +{ + void __attribute__((visibility("default"))) UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces); + void __attribute__((visibility("default"))) UNITY_INTERFACE_API UnityPluginUnload(); + UnityRenderingEvent __attribute__((visibility("default"))) UNITY_INTERFACE_API GetRenderEventFunc(); +} + +bool UnityAppBase::LoadPlugin() +{ + // Linux automagically sets function pointers + this->UnityPluginLoad = ::UnityPluginLoad; + this->UnityPluginUnload = ::UnityPluginUnload; + this->GetRenderEventFunc = ::GetRenderEventFunc; + return true; +} + +void UnityAppBase::UnloadPlugin() +{ + m_GraphicsEmulator->InvokeDeviceEventCallback(kUnityGfxDeviceEventShutdown); + UnityPluginUnload(); +} + diff --git a/unityplugin/UnityEmulator/src/UnityAppBase.cpp b/unityplugin/UnityEmulator/src/UnityAppBase.cpp index 8f93999..e84333b 100644 --- a/unityplugin/UnityEmulator/src/UnityAppBase.cpp +++ b/unityplugin/UnityEmulator/src/UnityAppBase.cpp @@ -151,7 +151,9 @@ void UnityAppBase::InitGraphics( case DeviceType::OpenGL: case DeviceType::OpenGLES: { +#if !PLATFORM_MACOS VERIFY_EXPR(NativeWindowHandle != nullptr); +#endif auto &GraphicsGLCoreES_Emulator = UnityGraphicsGLCoreES_Emulator::GetInstance(); # if PLATFORM_WIN32 || PLATFORM_LINUX |
