diff options
| author | Egor <egor.yusov@gmail.com> | 2018-02-10 19:56:36 +0000 |
|---|---|---|
| committer | Egor <egor.yusov@gmail.com> | 2018-02-10 19:56:36 +0000 |
| commit | d823930b20c37f92073791e18f9e6a744dc34d51 (patch) | |
| tree | 25d8dda1c46a05cd651af4818dd2ba20e44f47eb /unityplugin/UnityEmulator | |
| parent | Reworked win32 and uwp cmake build rules (diff) | |
| download | DiligentEngine-d823930b20c37f92073791e18f9e6a744dc34d51.tar.gz DiligentEngine-d823930b20c37f92073791e18f9e6a744dc34d51.zip | |
Fixed linux build
Diffstat (limited to 'unityplugin/UnityEmulator')
13 files changed, 145 insertions, 343 deletions
diff --git a/unityplugin/UnityEmulator/CMakeLists.txt b/unityplugin/UnityEmulator/CMakeLists.txt index 5e7cb42..c8c8da3 100644 --- a/unityplugin/UnityEmulator/CMakeLists.txt +++ b/unityplugin/UnityEmulator/CMakeLists.txt @@ -81,7 +81,7 @@ elseif(PLATFORM_ANDROID) list(APPEND INCLUDE include/UnityAppBase.h)
elseif(PLATFORM_LINUX)
list(APPEND SOURCE
- src/Linux/LinuxMain.cpp
+ src/Linux/UnityAppLinux.cpp
src/UnityAppBase.cpp
)
list(APPEND INCLUDE include/UnityAppBase.h)
diff --git a/unityplugin/UnityEmulator/include/UnityAppBase.h b/unityplugin/UnityEmulator/include/UnityAppBase.h index 10945f1..b227e5e 100644 --- a/unityplugin/UnityEmulator/include/UnityAppBase.h +++ b/unityplugin/UnityEmulator/include/UnityAppBase.h @@ -43,13 +43,20 @@ public: virtual const char* GetAppTitle()const override { return m_AppTitle.c_str(); } virtual void Render()override; virtual void Present()override; - virtual void Resize(int width, int height)override; + virtual void WindowResize(int width, int height)override; virtual void Update(double CurrTime, double ElapsedTime)override; bool LoadPlugin(); protected: - virtual void InitGraphics(void *NativeWindowHandle, int WindowWidth, int WindowHeight); + virtual void InitGraphics( +#if PLATFORM_LINUX + void *display, +#endif + void *NativeWindowHandle, + int WindowWidth, + int WindowHeight + ); virtual void InitScene(); std::unique_ptr<UnitySceneBase> m_Scene; diff --git a/unityplugin/UnityEmulator/include/UnityGraphicsGLCoreES_Emulator.h b/unityplugin/UnityEmulator/include/UnityGraphicsGLCoreES_Emulator.h index 694f962..fcaf44b 100644 --- a/unityplugin/UnityEmulator/include/UnityGraphicsGLCoreES_Emulator.h +++ b/unityplugin/UnityEmulator/include/UnityGraphicsGLCoreES_Emulator.h @@ -7,10 +7,10 @@ #include <memory> #include "UnityGraphicsEmulator.h" -#if defined(PLATFORM_ANDROID) +#if PLATFORM_ANDROID class UnityGraphicsGLESAndroid_Impl; using UnityGraphicsGL_Impl = UnityGraphicsGLESAndroid_Impl; -#elif defined(PLATFORM_WIN32) || defined(PLATFORM_UNIVERSAL_WINDOWS) || defined(PLATFORM_LINUX) || defined(PLATFORM_MACOS) +#elif PLATFORM_WIN32 || PLATFORM_UNIVERSAL_WINDOWS || PLATFORM_LINUX || PLATFORM_MACOS class UnityGraphicsGLCore_Impl; using UnityGraphicsGL_Impl = UnityGraphicsGLCore_Impl; #else @@ -23,7 +23,7 @@ class UnityGraphicsGLCoreES_Emulator final : public UnityGraphicsEmulator public: static UnityGraphicsGLCoreES_Emulator& GetInstance(); void InitGLContext(void *pNativeWndHandle, - #ifdef PLATFORM_LINUX + #if PLATFORM_LINUX void *pDisplay, #endif int MajorVersion, int MinorVersion); diff --git a/unityplugin/UnityEmulator/src/Linux/LinuxMain.cpp b/unityplugin/UnityEmulator/src/Linux/LinuxMain.cpp deleted file mode 100644 index 7ba760f..0000000 --- a/unityplugin/UnityEmulator/src/Linux/LinuxMain.cpp +++ /dev/null @@ -1,294 +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 <memory> -#include <iomanip> - -#include <GL/glx.h> -#include <GL/gl.h> - - // Undef symbols defined by XLib -#ifdef Bool -# undef Bool -#endif -#ifdef True -# undef True -#endif -#ifdef False -# undef False -#endif - -#include "DeviceCaps.h" -#include "Errors.h" -#include "Timer.h" - -#include "IUnityInterface.h" -#include "UnityGraphicsGLCoreES_Emulator.h" -#include "DiligentGraphicsAdapterGL.h" -#include "UnitySceneBase.h" -#include "StringTools.h" - -using namespace Diligent; - -#ifndef GLX_CONTEXT_MAJOR_VERSION_ARB -# define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 -#endif - -#ifndef GLX_CONTEXT_MINOR_VERSION_ARB -# define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 -#endif - -#ifndef GLX_CONTEXT_FLAGS_ARB -# define GLX_CONTEXT_FLAGS_ARB 0x2094 -#endif - -#ifndef GLX_CONTEXT_DEBUG_BIT_ARB -# define GLX_CONTEXT_DEBUG_BIT_ARB 0x0001 -#endif - -typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*); - -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. Android automagically sets function pointers - return true; -} - -void UnloadPlugin(UnityGraphicsEmulator *GraphicsEmulator) -{ - GraphicsEmulator->InvokeDeviceEventCallback(kUnityGfxDeviceEventShutdown); - UnityPluginUnload(); -} - - -int main (int argc, char ** argv) -{ - Display *display = XOpenDisplay(0); - - static int visual_attribs[] = - { - GLX_RENDER_TYPE, GLX_RGBA_BIT, - GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, - GLX_DOUBLEBUFFER, true, - - // The largest available total RGBA color buffer size (sum of GLX_RED_SIZE, - // GLX_GREEN_SIZE, GLX_BLUE_SIZE, and GLX_ALPHA_SIZE) of at least the minimum - // size specified for each color component is preferred. - GLX_RED_SIZE, 8, - GLX_GREEN_SIZE, 8, - GLX_BLUE_SIZE, 8, - GLX_ALPHA_SIZE, 8, - - // The largest available depth buffer of at least GLX_DEPTH_SIZE size is preferred - GLX_DEPTH_SIZE, 24, - - //GLX_SAMPLE_BUFFERS, 1, - GLX_SAMPLES, 1, - None - }; - - int fbcount = 0; - GLXFBConfig *fbc = glXChooseFBConfig(display, DefaultScreen(display), visual_attribs, &fbcount); - if (!fbc) - { - LOG_ERROR_MESSAGE("Failed to retrieve a framebuffer config"); - return -1; - } - - XVisualInfo *vi = glXGetVisualFromFBConfig(display, fbc[0]); - - XSetWindowAttributes swa; - swa.colormap = XCreateColormap(display, RootWindow(display, vi->screen), vi->visual, AllocNone); - swa.border_pixel = 0; - swa.event_mask = - StructureNotifyMask | - ExposureMask | - KeyPressMask | - KeyReleaseMask | - ButtonPressMask | - ButtonReleaseMask | - PointerMotionMask; - - Window win = XCreateWindow(display, RootWindow(display, vi->screen), 0, 0, 1024, 768, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel|CWColormap|CWEventMask, &swa); - if (!win) - { - LOG_ERROR_MESSAGE("Failed to create window."); - return -1; - } - - XMapWindow(display, win); - - glXCreateContextAttribsARBProc glXCreateContextAttribsARB = nullptr; - { - // Create an oldstyle context first, to get the correct function pointer for glXCreateContextAttribsARB - GLXContext ctx_old = glXCreateContext(display, vi, 0, GL_TRUE); - glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB"); - glXMakeCurrent(display, None, NULL); - glXDestroyContext(display, ctx_old); - } - - if (glXCreateContextAttribsARB == nullptr) - { - LOG_ERROR("glXCreateContextAttribsARB entry point not found. Aborting."); - return -1; - } - - int Flags = GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; -#ifdef _DEBUG - Flags |= GLX_CONTEXT_DEBUG_BIT_ARB; -#endif - - int major_version = 4; - int minor_version = 3; - static int context_attribs[] = - { - GLX_CONTEXT_MAJOR_VERSION_ARB, major_version, - GLX_CONTEXT_MINOR_VERSION_ARB, minor_version, - GLX_CONTEXT_FLAGS_ARB, Flags, - None - }; - - GLXContext ctx = glXCreateContextAttribsARB(display, fbc[0], NULL, true, context_attribs); - if (!ctx) - { - LOG_ERROR("Failed to create GL context."); - return -1; - } - XFree(fbc); - - glXMakeCurrent(display, win, ctx); - - auto &GraphicsGLCoreES_Emulator = UnityGraphicsGLCoreES_Emulator::GetInstance(); - GraphicsGLCoreES_Emulator.InitGLContext(reinterpret_cast<void*>(static_cast<size_t>(win)), display, major_version, minor_version); - - std::unique_ptr<DiligentGraphicsAdapter> pDiligentGraphics(new DiligentGraphicsAdapterGL(GraphicsGLCoreES_Emulator)); - UnityGraphicsEmulator *GraphicsEmulator = &GraphicsGLCoreES_Emulator; - - std::unique_ptr<UnitySceneBase> pScene(CreateScene()); - std::string Title = pScene->GetSceneName(); - pScene->SetDiligentGraphicsAdapter(pDiligentGraphics.get()); - pScene->OnGraphicsInitialized(); - //if (DevType == DeviceType::D3D12) - //{ - // UnityGraphicsD3D12Emulator::GetInstance().SetTransitionHandler(g_pScene->GetStateTransitionHandler()); - //} - - if (!LoadPlugin()) - { - return -1; - } - - pScene->OnPluginLoad(LoadPluginFunction); - UnityPluginLoad(&GraphicsEmulator->GeUnityInterfaces()); - - auto RenderEventFunc = GetRenderEventFunc(); - - Timer timer; - auto PrevTime = timer.GetElapsedTime(); - double filteredFrameTime = 0.0; - - while (true) - { - bool EscPressed = false; - XEvent xev; - // Handle all events in the queue - while(XCheckMaskEvent(display, 0xFFFFFFFF, &xev)) - { - switch(xev.type) - { - case KeyPress: - { - KeySym keysym; - char buffer[80]; - int num_char = XLookupString((XKeyEvent *)&xev, buffer, _countof(buffer), &keysym, 0); - EscPressed = (keysym==XK_Escape); - } - - case ConfigureNotify: - { - XConfigureEvent &xce = reinterpret_cast<XConfigureEvent &>(xev); - if(GraphicsEmulator) - { - pDiligentGraphics->PreSwapChainResize(); - GraphicsEmulator->ResizeSwapChain(static_cast<Uint32>(xce.width), static_cast<Uint32>(xce.height)); - pDiligentGraphics->PostSwapChainResize(); - pScene->OnWindowResize(static_cast<Uint32>(xce.width), static_cast<Uint32>(xce.height)); - } - break; - } - - default: - { - // if (pSample != nullptr ) - // pSample->HandleNativeMessage(&xev); - } - } - } - - if(EscPressed) - break; - - GraphicsEmulator->BeginFrame(); - pDiligentGraphics->BeginFrame(); - - auto CurrTime = timer.GetElapsedTime(); - auto ElapsedTime = CurrTime - PrevTime; - PrevTime = CurrTime; - - pScene->Render(RenderEventFunc, CurrTime, ElapsedTime); - - pDiligentGraphics->EndFrame(); - GraphicsEmulator->EndFrame(); - - GraphicsEmulator->Present(); - - double filterScale = 0.2; - filteredFrameTime = filteredFrameTime * (1.0 - filterScale) + filterScale * ElapsedTime; - std::stringstream fpsCounterSS; - fpsCounterSS << " - " << std::fixed << std::setprecision(1) << filteredFrameTime * 1000; - fpsCounterSS << " ms (" << 1.0 / filteredFrameTime << " fps)"; - XStoreName(display, win, (Title + fpsCounterSS.str()).c_str()); - } - - pScene->OnPluginUnload(); - pScene.reset(); - UnloadPlugin(GraphicsEmulator); - - pDiligentGraphics.reset(); - GraphicsEmulator->Release(); - - ctx = glXGetCurrentContext(); - glXMakeCurrent(display, None, NULL); - glXDestroyContext(display, ctx); - XDestroyWindow(display, win); - XCloseDisplay(display); -} diff --git a/unityplugin/UnityEmulator/src/Linux/UnityAppLinux.cpp b/unityplugin/UnityEmulator/src/Linux/UnityAppLinux.cpp new file mode 100644 index 0000000..e7cb6c9 --- /dev/null +++ b/unityplugin/UnityEmulator/src/Linux/UnityAppLinux.cpp @@ -0,0 +1,76 @@ +/* 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 UnityAppLinux : public UnityAppBase +{ +public: + UnityAppLinux() + { + m_DeviceType = Diligent::DeviceType::OpenGL; + } + + virtual void OnGLContextCreated(Display* display, Window window)override final + { + InitGraphics(display, reinterpret_cast<void*>(static_cast<size_t>(window)), 0/*Unused*/, 0/*Unused*/); + InitScene(); + } +}; + +NativeAppBase* CreateApplication() +{ + return new UnityAppLinux(); +} + +// 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 9a2a3df..b2c66d4 100644 --- a/unityplugin/UnityEmulator/src/UnityAppBase.cpp +++ b/unityplugin/UnityEmulator/src/UnityAppBase.cpp @@ -102,7 +102,14 @@ void UnityAppBase::ProcessCommandLine(const char *CmdLine) } } -void UnityAppBase::InitGraphics(void *NativeWindowHandle, int WindowWidth, int WindowHeight) +void UnityAppBase::InitGraphics( +#if PLATFORM_LINUX + void *display, +#endif + void *NativeWindowHandle, + int WindowWidth, + int WindowHeight + ) { switch (m_DeviceType) { @@ -145,7 +152,12 @@ void UnityAppBase::InitGraphics(void *NativeWindowHandle, int WindowWidth, int W { VERIFY_EXPR(NativeWindowHandle != nullptr); auto &GraphicsGLCoreES_Emulator = UnityGraphicsGLCoreES_Emulator::GetInstance(); - GraphicsGLCoreES_Emulator.InitGLContext(NativeWindowHandle, 4, 4); + GraphicsGLCoreES_Emulator.InitGLContext(NativeWindowHandle, + #if PLATFORM_LINUX + display, + #endif + 4, 4 + ); m_GraphicsEmulator = &GraphicsGLCoreES_Emulator; m_DiligentGraphics.reset(new DiligentGraphicsAdapterGL(GraphicsGLCoreES_Emulator)); } @@ -161,11 +173,12 @@ void UnityAppBase::InitScene() { m_Scene->SetDiligentGraphicsAdapter(m_DiligentGraphics.get()); m_Scene->OnGraphicsInitialized(); +#if D3D12_SUPPORTED if (m_DeviceType == DeviceType::D3D12) { UnityGraphicsD3D12Emulator::GetInstance().SetTransitionHandler(m_Scene->GetStateTransitionHandler()); } - +#endif if (!LoadPlugin()) { LOG_ERROR_AND_THROW("Failed to load plugin"); @@ -203,7 +216,7 @@ void UnityAppBase::Present() m_GraphicsEmulator->Present(); } -void UnityAppBase::Resize(int width, int height) +void UnityAppBase::WindowResize(int width, int height) { if (m_GraphicsEmulator) { diff --git a/unityplugin/UnityEmulator/src/UnityGraphicsD3D11Emulator.cpp b/unityplugin/UnityEmulator/src/UnityGraphicsD3D11Emulator.cpp index b8e6be5..e901a5f 100644 --- a/unityplugin/UnityEmulator/src/UnityGraphicsD3D11Emulator.cpp +++ b/unityplugin/UnityEmulator/src/UnityGraphicsD3D11Emulator.cpp @@ -51,7 +51,7 @@ void UnityGraphicsD3D11Impl::CreateDeviceAndContext() // description. All applications are assumed to support 9.1 unless otherwise stated. D3D_FEATURE_LEVEL featureLevels[] = { -#ifdef PLATFORM_UNIVERSAL_WINDOWS +#if PLATFORM_UNIVERSAL_WINDOWS D3D_FEATURE_LEVEL_11_1, #endif D3D_FEATURE_LEVEL_11_0, @@ -104,7 +104,7 @@ void UnityGraphicsD3D11Impl::CreateSwapChain(void* pNativeWndHandle, unsigned in m_BackBufferWidth = 0; m_BackBufferHeight = 0; -#ifdef PLATFORM_WIN32 +#if PLATFORM_WIN32 auto hWnd = reinterpret_cast<HWND>(pNativeWndHandle); RECT rc; GetClientRect( hWnd, &rc ); @@ -135,7 +135,7 @@ void UnityGraphicsD3D11Impl::CreateSwapChain(void* pNativeWndHandle, unsigned in CComPtr<IDXGISwapChain1> pSwapChain1; -#if defined( PLATFORM_WIN32 ) +#if PLATFORM_WIN32 // This sequence obtains the DXGI factory that was used to create the Direct3D device above. CComPtr<IDXGIDevice> pDXGIDevice; m_d3d11Device->QueryInterface(__uuidof(IDXGIDevice), reinterpret_cast<void**>( static_cast<IDXGIDevice**>(&pDXGIDevice) ) ); @@ -148,7 +148,7 @@ void UnityGraphicsD3D11Impl::CreateSwapChain(void* pNativeWndHandle, unsigned in if(FAILED(hr)) throw std::runtime_error( "Failed to create DXGI swap chain" ); -#elif defined( PLATFORM_UNIVERSAL_WINDOWS ) +#elif PLATFORM_UNIVERSAL_WINDOWS CComPtr<IDXGIDevice3> pDXGIDevice; m_d3d11Device->QueryInterface(__uuidof(IDXGIDevice3), reinterpret_cast<void**>(static_cast<IDXGIDevice3**>(&pDXGIDevice))); @@ -228,7 +228,7 @@ void UnityGraphicsD3D11Impl::CreateRTVandDSV() void UnityGraphicsD3D11Impl::Present() { UINT SyncInterval = 1; // 0 -#ifdef PLATFORM_UNIVERSAL_WINDOWS +#if PLATFORM_UNIVERSAL_WINDOWS SyncInterval = 1; // Interval 0 is not supported on Windows Phone #endif diff --git a/unityplugin/UnityEmulator/src/UnityGraphicsD3D11Impl.h b/unityplugin/UnityEmulator/src/UnityGraphicsD3D11Impl.h index 0377081..36dfcc1 100644 --- a/unityplugin/UnityEmulator/src/UnityGraphicsD3D11Impl.h +++ b/unityplugin/UnityEmulator/src/UnityGraphicsD3D11Impl.h @@ -1,8 +1,8 @@ #pragma once -#if defined(PLATFORM_WIN32) +#if PLATFORM_WIN32 #include <d3d11.h> -#elif defined(PLATFORM_UNIVERSAL_WINDOWS) +#elif PLATFORM_UNIVERSAL_WINDOWS #include <d3d11_2.h> #endif diff --git a/unityplugin/UnityEmulator/src/UnityGraphicsD3D12Emulator.cpp b/unityplugin/UnityEmulator/src/UnityGraphicsD3D12Emulator.cpp index fbcefdf..8d102d9 100644 --- a/unityplugin/UnityEmulator/src/UnityGraphicsD3D12Emulator.cpp +++ b/unityplugin/UnityEmulator/src/UnityGraphicsD3D12Emulator.cpp @@ -137,7 +137,7 @@ void UnityGraphicsD3D12Impl::CreateDeviceAndCommandQueue() void UnityGraphicsD3D12Impl::CreateSwapChain(void* pNativeWndHandle, unsigned int Width, unsigned int Height) { -#ifdef PLATFORM_WIN32 +#if PLATFORM_WIN32 auto hWnd = reinterpret_cast<HWND>(pNativeWndHandle); RECT rc; GetClientRect( hWnd, &rc ); @@ -170,14 +170,14 @@ void UnityGraphicsD3D12Impl::CreateSwapChain(void* pNativeWndHandle, unsigned in HRESULT hr = CreateDXGIFactory1(__uuidof(factory), reinterpret_cast<void**>(static_cast<IDXGIFactory4**>(&factory)) ); if(FAILED(hr))LOG_ERROR_AND_THROW("Failed to create DXGI factory"); -#if defined( PLATFORM_WIN32 ) +#if PLATFORM_WIN32 hr = factory->CreateSwapChainForHwnd(m_D3D12CmdQueue, hWnd, &swapChainDesc, nullptr, nullptr, &pSwapChain1); if(FAILED(hr))LOG_ERROR_AND_THROW("Failed to create Swap Chain" ); // This sample does not support fullscreen transitions. hr = factory->MakeWindowAssociation(hWnd, DXGI_MWA_NO_WINDOW_CHANGES | DXGI_MWA_NO_ALT_ENTER); -#elif defined( PLATFORM_UNIVERSAL_WINDOWS ) +#elif PLATFORM_UNIVERSAL_WINDOWS hr = factory->CreateSwapChainForCoreWindow( m_D3D12CmdQueue, @@ -282,7 +282,7 @@ void UnityGraphicsD3D12Impl::InitBuffersAndViews() void UnityGraphicsD3D12Impl::Present() { UINT SyncInterval = 0; -#ifdef PLATFORM_UNIVERSAL_WINDOWS +#if PLATFORM_UNIVERSAL_WINDOWS SyncInterval = 1; // Interval 0 is not supported on Windows Phone #endif diff --git a/unityplugin/UnityEmulator/src/UnityGraphicsGLCoreES_Emulator.cpp b/unityplugin/UnityEmulator/src/UnityGraphicsGLCoreES_Emulator.cpp index 0fd790f..a8b0290 100644 --- a/unityplugin/UnityEmulator/src/UnityGraphicsGLCoreES_Emulator.cpp +++ b/unityplugin/UnityEmulator/src/UnityGraphicsGLCoreES_Emulator.cpp @@ -17,14 +17,14 @@ UnityGraphicsGLCoreES_Emulator::UnityGraphicsGLCoreES_Emulator() } void UnityGraphicsGLCoreES_Emulator::InitGLContext(void *pNativeWndHandle, - #ifdef PLATFORM_LINUX + #if PLATFORM_LINUX void *pDisplay, #endif int MajorVersion, int MinorVersion) { m_GraphicsImpl->InitGLContext(pNativeWndHandle, - #ifdef PLATFORM_LINUX + #if PLATFORM_LINUX pDisplay, #endif MajorVersion, MinorVersion); diff --git a/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.cpp b/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.cpp index 30f1ae2..03b84ba 100644 --- a/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.cpp +++ b/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.cpp @@ -7,11 +7,11 @@ #include "DebugUtilities.h" #include "Errors.h" -#ifdef PLATFORM_MACOS +#if PLATFORM_MACOS #import <AppKit/AppKit.h> #endif -#if defined(PLATFORM_WIN32) || defined(PLATFORM_LINUX) +#if PLATFORM_WIN32 || PLATFORM_LINUX #ifndef APIENTRY # define APIENTRY @@ -68,9 +68,9 @@ void APIENTRY openglCallbackFunction( GLenum source, MessageSS << ")" << std::endl << message << std::endl; -#if defined(PLATFORM_WIN32) +#if PLATFORM_WIN32 OutputDebugStringA( MessageSS.str().c_str() ); -#elif defined(PLATFORM_LINUX) +#elif PLATFORM_LINUX std::cout << MessageSS.str().c_str(); #else # error Unknown platform @@ -83,10 +83,10 @@ UnityGraphicsGLCore_Impl::~UnityGraphicsGLCore_Impl() { if( m_Context ) { -#if defined(PLATFORM_WIN32) +#if PLATFORM_WIN32 wglMakeCurrent( m_WindowHandleToDeviceContext, 0 ); wglDeleteContext( m_Context ); -#elif defined(PLATFORM_LINUX) || defined(PLATFORM_MACOS) +#elif PLATFORM_LINUX || PLATFORM_MACOS // Do nothing. Context is managed by the app #else # error Unknown platform @@ -95,12 +95,12 @@ UnityGraphicsGLCore_Impl::~UnityGraphicsGLCore_Impl() } void UnityGraphicsGLCore_Impl::InitGLContext(void *pNativeWndHandle, - #ifdef PLATFORM_LINUX + #if PLATFORM_LINUX void *pDisplay, #endif int MajorVersion, int MinorVersion ) { -#if defined(PLATFORM_WIN32) +#if PLATFORM_WIN32 HWND hWnd = reinterpret_cast<HWND>(pNativeWndHandle); RECT rc; GetClientRect( hWnd, &rc ); @@ -173,7 +173,7 @@ void UnityGraphicsGLCore_Impl::InitGLContext(void *pNativeWndHandle, { //It's not possible to make a GL 3.x context. Use the old style context (GL 2.1 and before) m_Context = tempContext; } -#elif defined(PLATFORM_LINUX) +#elif PLATFORM_LINUX m_LinuxWindow = static_cast<Window>(reinterpret_cast<size_t>(pNativeWndHandle)); m_Display = reinterpret_cast<Display*>(pDisplay); m_Context = glXGetCurrentContext(); @@ -184,7 +184,7 @@ void UnityGraphicsGLCore_Impl::InitGLContext(void *pNativeWndHandle, GLenum err = glewInit(); if( GLEW_OK != err ) LOG_ERROR_AND_THROW( "Failed to initialize GLEW" ); -#elif defined(PLATFORM_MACOS) +#elif PLATFORM_MACOS NSOpenGLContext* CurrentCtx = [NSOpenGLContext currentContext]; m_Context = CurrentCtx; if (m_Context == nullptr) @@ -207,7 +207,7 @@ void UnityGraphicsGLCore_Impl::InitGLContext(void *pNativeWndHandle, glGetIntegerv( GL_MINOR_VERSION, &MinorVersion ); LOG_INFO_MESSAGE("Initialized OpenGL ", MajorVersion, '.', MinorVersion, " context (", GLVersionString, ")"); -#if defined(PLATFORM_WIN32) || defined(PLATFORM_LINUX) +#if PLATFORM_WIN32 || PLATFORM_LINUX if( glDebugMessageCallback ) { glEnable( GL_DEBUG_OUTPUT_SYNCHRONOUS ); @@ -240,11 +240,11 @@ void UnityGraphicsGLCore_Impl::ResizeSwapchain(int NewWidth, int NewHeight) void UnityGraphicsGLCore_Impl::SwapBuffers() { -#if defined(PLATFORM_WIN32) +#if PLATFORM_WIN32 ::SwapBuffers( m_WindowHandleToDeviceContext ); -#elif defined(PLATFORM_LINUX) +#elif PLATFORM_LINUX glXSwapBuffers(m_Display, m_LinuxWindow); -#elif defined(PLATFORM_MACOS) +#elif PLATFORM_MACOS UNEXPECTED("On MacOS, swap buffers operation is expected to be performed by the app"); #else # error Unsupported platform diff --git a/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.h b/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.h index 8ed3f90..5abc97e 100644 --- a/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.h +++ b/unityplugin/UnityEmulator/src/UnityGraphicsGLCore_Impl.h @@ -4,7 +4,7 @@ #if OPENGL_SUPPORTED -#if defined(PLATFORM_WIN32) +#if PLATFORM_WIN32 # ifndef GLEW_STATIC # define GLEW_STATIC @@ -14,7 +14,7 @@ # include "GL/wglew.h" # include <GL/GL.h> -#elif defined(PLATFORM_LINUX) +#elif PLATFORM_LINUX # ifndef GLEW_STATIC # define GLEW_STATIC // Must be defined to use static version of glew @@ -43,7 +43,7 @@ # undef Success # endif -#elif defined(PLATFORM_MACOS) +#elif PLATFORM_MACOS # ifndef GLEW_STATIC # define GLEW_STATIC // Must be defined to use static version of glew @@ -64,11 +64,11 @@ class UnityGraphicsGLCore_Impl { public: -#if defined(PLATFORM_WIN32) +#if PLATFORM_WIN32 typedef HGLRC NativeGLContextType; -#elif defined(PLATFORM_LINUX) +#elif PLATFORM_LINUX typedef GLXContext NativeGLContextType; -#elif defined(PLATFORM_MACOS) +#elif PLATFORM_MACOS typedef void* NativeGLContextType; #else # error Unsupported platform @@ -77,7 +77,7 @@ public: ~UnityGraphicsGLCore_Impl(); void InitGLContext(void *pNativeWndHandle, - #ifdef PLATFORM_LINUX + #if PLATFORM_LINUX void *pDisplay, #endif int MajorVersion, int MinorVersion); @@ -96,12 +96,12 @@ private: int m_BackBufferWidth = 0; int m_BackBufferHeight = 0; -#if defined(PLATFORM_WIN32) +#if PLATFORM_WIN32 HDC m_WindowHandleToDeviceContext; -#elif defined(PLATFORM_LINUX) +#elif PLATFORM_LINUX Window m_LinuxWindow; Display *m_Display; -#elif defined(PLATFORM_MACOS) +#elif PLATFORM_MACOS #else # error Unsupported platform diff --git a/unityplugin/UnityEmulator/src/UnityGraphicsGL_Impl.h b/unityplugin/UnityEmulator/src/UnityGraphicsGL_Impl.h index 0c437ea..b87e2a2 100644 --- a/unityplugin/UnityEmulator/src/UnityGraphicsGL_Impl.h +++ b/unityplugin/UnityEmulator/src/UnityGraphicsGL_Impl.h @@ -2,9 +2,9 @@ #include "PlatformDefinitions.h" -#if defined(PLATFORM_ANDROID) +#if PLATFORM_ANDROID # include "Android/UnityGraphicsGLESAndroid_Impl.h" -#elif defined(PLATFORM_WIN32) || defined(PLATFORM_UNIVERSAL_WINDOWS) || defined(PLATFORM_LINUX) || defined(PLATFORM_MACOS) +#elif PLATFORM_WIN32 || PLATFORM_UNIVERSAL_WINDOWS || PLATFORM_LINUX || PLATFORM_MACOS # include "UnityGraphicsGLCore_Impl.h" #else # error Unknown Platform |
