summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-01-19 17:05:04 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-01-19 17:05:04 +0000
commitc2e99b91c06d26690b79fc548a5e1d2bc90591c8 (patch)
treef726feda9c9d389274bc7f60295d08e2e0869eaa
parentUpdate README.md (diff)
downloadDiligentCore-c2e99b91c06d26690b79fc548a5e1d2bc90591c8.tar.gz
DiligentCore-c2e99b91c06d26690b79fc548a5e1d2bc90591c8.zip
Enabled MacOS build
-rw-r--r--CMakeLists.txt9
-rw-r--r--Common/interface/StringTools.h4
-rw-r--r--External/CMakeLists.txt2
-rw-r--r--Graphics/GraphicsEngineOpenGL/CMakeLists.txt6
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/GLContext.h2
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h55
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/pch.h13
-rw-r--r--Graphics/GraphicsEngineOpenGL/interface/BaseInterfacesGL.h2
-rw-r--r--Graphics/GraphicsEngineOpenGL/interface/RenderDeviceFactoryOpenGL.h2
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.cpp198
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp2
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp5
-rw-r--r--Graphics/GraphicsTools/src/GraphicsUtilities.cpp2
-rw-r--r--Platforms/CMakeLists.txt3
-rw-r--r--Platforms/MacOS/CMakeLists.txt38
-rw-r--r--Platforms/MacOS/include/MacOSDebug.h32
-rw-r--r--Platforms/MacOS/include/MacOSFileSystem.h47
-rw-r--r--Platforms/MacOS/include/MacOSPlatformDefinitions.h30
-rw-r--r--Platforms/MacOS/include/MacOSPlatformMisc.h43
-rw-r--r--Platforms/MacOS/src/MacOSDebug.cpp59
-rw-r--r--Platforms/MacOS/src/MacOSFileSystem.cpp86
-rw-r--r--Platforms/interface/FileSystem.h10
-rw-r--r--Platforms/interface/PlatformDebug.h4
-rw-r--r--Platforms/interface/PlatformDefinitions.h22
-rw-r--r--Platforms/interface/PlatformMisc.h7
25 files changed, 668 insertions, 15 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index abb69700..4bfb583d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,6 +4,7 @@ set(PLATFORM_WIN32 FALSE CACHE INTERNAL "")
set(PLATFORM_UNIVERSAL_WINDOWS FALSE CACHE INTERNAL "")
set(PLATFORM_ANDROID FALSE CACHE INTERNAL "")
set(PLATFORM_LINUX FALSE CACHE INTERNAL "")
+set(PLATFORM_MACOS FALSE CACHE INTERNAL "")
set(D3D11_SUPPORTED FALSE CACHE INTERNAL "D3D11 is not spported")
set(D3D12_SUPPORTED FALSE CACHE INTERNAL "D3D12 is not spported")
set(GL_SUPPORTED FALSE CACHE INTERNAL "GL is not spported")
@@ -26,6 +27,9 @@ else()
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(PLATFORM_LINUX TRUE CACHE INTERNAL "Target platform: Linux")
message("Target Platform: Linux")
+ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
+ set(PLATFORM_MACOS TRUE CACHE INTERNAL "Target platform: MacOS")
+ message("Target Platform: MacOS")
else()
message(FATAL_ERROR "Unsupported platform")
endif()
@@ -48,6 +52,9 @@ elseif(PLATFORM_ANDROID)
elseif(PLATFORM_LINUX)
set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL supported on Linux platform")
target_compile_definitions(BuildSettings INTERFACE PLATFORM_LINUX=1)
+elseif(PLATFORM_MACOS)
+ set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL supported on MacOS platform")
+ target_compile_definitions(BuildSettings INTERFACE PLATFORM_MACOS=1)
else()
message(FATAL_ERROR "No PLATFORM_XXX variable defined. Make sure that 'DiligentCore' folder is processed first")
endif()
@@ -106,7 +113,7 @@ else()
set(ARCH 32 CACHE INTERNAL "32-bit architecture")
endif()
-if(PLATFORM_WIN32 OR PLATFORM_UNIVERSAL_WINDOWS)
+if(PLATFORM_WIN32 OR PLATFORM_UNIVERSAL_WINDOWS OR PLATFORM_MACOS)
# https://cmake.org/cmake/help/v3.8/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html#prop_gbl:CMAKE_CXX_KNOWN_FEATURES
target_compile_features(BuildSettings INTERFACE cxx_std_11) # Generates an error in gradle build on Android
diff --git a/Common/interface/StringTools.h b/Common/interface/StringTools.h
index 08982fe0..bb48f5c1 100644
--- a/Common/interface/StringTools.h
+++ b/Common/interface/StringTools.h
@@ -69,7 +69,7 @@ inline std::wstring WidenString(const std::string &Str)
inline int StrCmpNoCase(const char* Str1, const char* Str2, size_t NumChars)
{
-#if defined(PLATFORM_ANDROID) || defined(PLATFORM_LINUX)
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_LINUX) || defined(PLATFORM_MACOS)
# define _strnicmp strncasecmp
#endif
@@ -78,7 +78,7 @@ inline int StrCmpNoCase(const char* Str1, const char* Str2, size_t NumChars)
inline int StrCmpNoCase(const char* Str1, const char* Str2)
{
-#if defined(PLATFORM_ANDROID) || defined(PLATFORM_LINUX)
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_LINUX) || defined(PLATFORM_MACOS)
# define _stricmp strcasecmp
#endif
diff --git a/External/CMakeLists.txt b/External/CMakeLists.txt
index 55616bd8..e78c714a 100644
--- a/External/CMakeLists.txt
+++ b/External/CMakeLists.txt
@@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.6)
-if(PLATFORM_WIN32 OR PLATFORM_LINUX)
+if(PLATFORM_WIN32 OR PLATFORM_LINUX OR PLATFORM_MACOS)
add_subdirectory(glew)
endif()
diff --git a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt
index 524d9d2a..30e85828 100644
--- a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt
+++ b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt
@@ -96,6 +96,9 @@ elseif(PLATFORM_ANDROID)
elseif(PLATFORM_LINUX)
list(APPEND SOURCE src/GLContextLinux.cpp)
list(APPEND INCLUDE include/GLContextLinux.h)
+elseif(PLATFORM_MACOS)
+ list(APPEND SOURCE src/GLContextMacOS.cpp)
+ list(APPEND INCLUDE include/GLContextMacOS.h)
else()
message(FATAL_ERROR "Unknown platform")
endif()
@@ -161,6 +164,9 @@ elseif(PLATFORM_ANDROID)
set_target_properties(GraphicsEngineOpenGL-shared PROPERTIES CXX_VISIBILITY_PRESET hidden) # -fvisibility=hidden
elseif(PLATFORM_LINUX)
set(PRIVATE_DEPENDENCIES ${PRIVATE_DEPENDENCIES} glew-static)
+elseif(PLATFORM_MACOS)
+ find_package(OpenGL REQUIRED)
+ set(PRIVATE_DEPENDENCIES ${PRIVATE_DEPENDENCIES} glew-static ${OPENGL_LIBRARY})
else()
message(FATAL_ERROR "Unknown platform")
endif()
diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContext.h b/Graphics/GraphicsEngineOpenGL/include/GLContext.h
index f70c9020..935d0dbc 100644
--- a/Graphics/GraphicsEngineOpenGL/include/GLContext.h
+++ b/Graphics/GraphicsEngineOpenGL/include/GLContext.h
@@ -29,6 +29,8 @@
# include "GLContextAndroid.h"
#elif defined(PLATFORM_LINUX)
# include "GLContextLinux.h"
+#elif defined(PLATFORM_MACOS)
+# include "GLContextMacOS.h"
#else
# error Unsupported platform
#endif
diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h b/Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h
new file mode 100644
index 00000000..8ecf9822
--- /dev/null
+++ b/Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h
@@ -0,0 +1,55 @@
+/* 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
+
+namespace Diligent
+{
+
+ struct ContextInitInfo
+ {
+ SwapChainDesc SwapChainAttribs;
+ void *pNativeWndHandle = nullptr;
+ void *pDisplay = nullptr;
+ };
+
+ class GLContext
+ {
+ public:
+ typedef void* NativeGLContextType;
+
+ GLContext(const ContextInitInfo &Info, struct DeviceCaps &DeviceCaps);
+ ~GLContext();
+ void SwapBuffers();
+
+ const SwapChainDesc& GetSwapChainDesc()const{ return m_SwapChainAttribs; }
+
+ NativeGLContextType GetCurrentNativeGLContext();
+
+ private:
+ void *m_pNativeWindow = nullptr;
+ void *m_pDisplay = nullptr;
+ NativeGLContextType m_Context;
+ SwapChainDesc m_SwapChainAttribs;
+ };
+}
diff --git a/Graphics/GraphicsEngineOpenGL/include/pch.h b/Graphics/GraphicsEngineOpenGL/include/pch.h
index e9e04272..77815ec8 100644
--- a/Graphics/GraphicsEngineOpenGL/include/pch.h
+++ b/Graphics/GraphicsEngineOpenGL/include/pch.h
@@ -75,7 +75,18 @@
# undef Success
# endif
-# elif defined(PLATFORM_ANDROID)
+#elif defined(PLATFORM_MACOS)
+
+# ifndef GLEW_STATIC
+# define GLEW_STATIC // Must be defined to use static version of glew
+# endif
+# ifndef GLEW_NO_GLU
+# define GLEW_NO_GLU
+# endif
+
+# include "GL/glew.h"
+
+#elif defined(PLATFORM_ANDROID)
# ifndef USE_GL3_STUB
# define USE_GL3_STUB 0
diff --git a/Graphics/GraphicsEngineOpenGL/interface/BaseInterfacesGL.h b/Graphics/GraphicsEngineOpenGL/interface/BaseInterfacesGL.h
index e3899b69..36ccd33b 100644
--- a/Graphics/GraphicsEngineOpenGL/interface/BaseInterfacesGL.h
+++ b/Graphics/GraphicsEngineOpenGL/interface/BaseInterfacesGL.h
@@ -29,7 +29,7 @@
{
using IGLDeviceBaseInterface = IRenderDeviceGLES;
}
-#elif defined(PLATFORM_WIN32) || defined(PLATFORM_LINUX)
+#elif defined(PLATFORM_WIN32) || defined(PLATFORM_LINUX) || defined(PLATFORM_MACOS)
#include "RenderDeviceGL.h"
namespace Diligent
{
diff --git a/Graphics/GraphicsEngineOpenGL/interface/RenderDeviceFactoryOpenGL.h b/Graphics/GraphicsEngineOpenGL/interface/RenderDeviceFactoryOpenGL.h
index 31fe9c1f..a9c4891f 100644
--- a/Graphics/GraphicsEngineOpenGL/interface/RenderDeviceFactoryOpenGL.h
+++ b/Graphics/GraphicsEngineOpenGL/interface/RenderDeviceFactoryOpenGL.h
@@ -35,7 +35,7 @@
# define API_QUALIFIER
-#elif defined(PLATFORM_ANDROID) || defined(PLATFORM_LINUX)
+#elif defined(PLATFORM_ANDROID) || defined(PLATFORM_LINUX) || defined(PLATFORM_MACOS)
# ifdef ENGINE_DLL
# ifdef BUILDING_DLL
diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.cpp
new file mode 100644
index 00000000..be1a37fc
--- /dev/null
+++ b/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.cpp
@@ -0,0 +1,198 @@
+/* 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 "pch.h"
+
+#include "GLContextMacOS.h"
+#include "DeviceCaps.h"
+#include "GLTypeConversions.h"
+
+namespace Diligent
+{
+ /*void openglCallbackFunction( GLenum source,
+ GLenum type,
+ GLuint id,
+ GLenum severity,
+ GLsizei length,
+ const GLchar* message,
+ const void* userParam )
+ {
+ std::stringstream MessageSS;
+
+ MessageSS << "OpenGL debug message (";
+ switch( type )
+ {
+ case GL_DEBUG_TYPE_ERROR:
+ MessageSS << "ERROR";
+ break;
+ case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
+ MessageSS << "DEPRECATED_BEHAVIOR";
+ break;
+ case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
+ MessageSS << "UNDEFINED_BEHAVIOR";
+ break;
+ case GL_DEBUG_TYPE_PORTABILITY:
+ MessageSS << "PORTABILITY";
+ break;
+ case GL_DEBUG_TYPE_PERFORMANCE:
+ MessageSS << "PERFORMANCE";
+ break;
+ case GL_DEBUG_TYPE_OTHER:
+ MessageSS << "OTHER";
+ break;
+ }
+
+ switch( severity )
+ {
+ case GL_DEBUG_SEVERITY_LOW:
+ MessageSS << ", low severity";
+ break;
+ case GL_DEBUG_SEVERITY_MEDIUM:
+ MessageSS << ", medium severity";
+ break;
+ case GL_DEBUG_SEVERITY_HIGH:
+ MessageSS << ", HIGH severity";
+ break;
+ case GL_DEBUG_SEVERITY_NOTIFICATION:
+ MessageSS << ", notification";
+ break;
+ }
+
+ MessageSS << ")" << std::endl << message << std::endl;
+
+ LOG_INFO_MESSAGE_ONCE( MessageSS.str().c_str() );
+ }*/
+
+ GLContext::GLContext( const ContextInitInfo &Info, DeviceCaps &DeviceCaps ) :
+ m_SwapChainAttribs(Info.SwapChainAttribs),
+ m_Context(0),
+ m_pNativeWindow(Info.pNativeWndHandle),
+ m_pDisplay(Info.pDisplay)
+ {
+#if 0
+ auto CurrentCtx = glXGetCurrentContext();
+ if (CurrentCtx == 0)
+ {
+ LOG_ERROR_AND_THROW("No current GL context found!");
+ }
+
+ // Initialize GLEW
+ GLenum err = glewInit();
+ if( GLEW_OK != err )
+ LOG_ERROR_AND_THROW( "Failed to initialize GLEW" );
+
+ if(Info.pNativeWndHandle != nullptr && Info.pDisplay != nullptr)
+ {
+ auto wnd = static_cast<Window>(reinterpret_cast<size_t>(Info.pNativeWndHandle));
+ auto display = reinterpret_cast<Display*>(Info.pDisplay);
+
+ XWindowAttributes XWndAttribs;
+ XGetWindowAttributes(display, wnd, &XWndAttribs);
+
+ m_SwapChainAttribs.Width = XWndAttribs.width;
+ m_SwapChainAttribs.Height = XWndAttribs.height;
+
+ //glXSwapIntervalEXT(0);
+
+ if( glDebugMessageCallback )
+ {
+ glEnable( GL_DEBUG_OUTPUT_SYNCHRONOUS );
+ glDebugMessageCallback( openglCallbackFunction, nullptr );
+ GLuint unusedIds = 0;
+ glDebugMessageControl( GL_DONT_CARE,
+ GL_DONT_CARE,
+ GL_DONT_CARE,
+ 0,
+ &unusedIds,
+ true );
+ }
+ }
+
+ //Checking GL version
+ const GLubyte *GLVersionString = glGetString( GL_VERSION );
+ const GLubyte *GLRenderer = glGetString(GL_RENDERER);
+
+ Int32 MajorVersion = 0, MinorVersion = 0;
+ //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(Info.pNativeWndHandle != nullptr ? "Initialized OpenGL " : "Attached to OpenGL ", MajorVersion, '.', MinorVersion, " context (", GLVersionString, ", ", GLRenderer, ')');
+
+ // Under the standard filtering rules for cubemaps, filtering does not work across faces of the cubemap.
+ // This results in a seam across the faces of a cubemap. This was a hardware limitation in the past, but
+ // modern hardware is capable of interpolating across a cube face boundary.
+ // GL_TEXTURE_CUBE_MAP_SEAMLESS is not defined in OpenGLES
+ glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
+ if( glGetError() != GL_NO_ERROR )
+ LOG_ERROR_MESSAGE("Failed to enable seamless cubemap filtering");
+
+ // When GL_FRAMEBUFFER_SRGB is enabled, and if the destination image is in the sRGB colorspace
+ // then OpenGL will assume the shader's output is in the linear RGB colorspace. It will therefore
+ // convert the output from linear RGB to sRGB.
+ // Any writes to images that are not in the sRGB format should not be affected.
+ // Thus this setting should be just set once and left that way
+ glEnable(GL_FRAMEBUFFER_SRGB);
+ if( glGetError() != GL_NO_ERROR )
+ LOG_ERROR_MESSAGE("Failed to enable SRGB framebuffers");
+
+ DeviceCaps.DevType = DeviceType::OpenGL;
+ DeviceCaps.MajorVersion = MajorVersion;
+ DeviceCaps.MinorVersion = MinorVersion;
+ bool IsGL43OrAbove = MajorVersion >= 5 || MajorVersion == 4 && MinorVersion >= 3;
+ auto &TexCaps = DeviceCaps.TexCaps;
+ TexCaps.bTexture2DMSSupported = IsGL43OrAbove;
+ TexCaps.bTexture2DMSArraySupported = IsGL43OrAbove;
+ TexCaps.bTextureViewSupported = IsGL43OrAbove;
+ TexCaps.bCubemapArraysSupported = IsGL43OrAbove;
+ DeviceCaps.bMultithreadedResourceCreationSupported = False;
+#endif
+ }
+
+ GLContext::~GLContext()
+ {
+ }
+
+ void GLContext::SwapBuffers()
+ {
+#if 0
+ if(m_pNativeWindow != nullptr && m_pDisplay != nullptr)
+ {
+ auto wnd = static_cast<Window>(reinterpret_cast<size_t>(m_pNativeWindow));
+ auto display = reinterpret_cast<Display*>(m_pDisplay);
+ glXSwapBuffers(display, wnd);
+ }
+ else
+ {
+ LOG_ERROR("Swap buffer failed because window and/or display handle is not initialized");
+ }
+#endif
+ }
+
+ GLContext::NativeGLContextType GLContext::GetCurrentNativeGLContext()
+ {
+#if 0
+ return glXGetCurrentContext();
+#endif
+ return nullptr;
+ }
+}
diff --git a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp
index fd467523..bf172073 100644
--- a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp
+++ b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp
@@ -39,7 +39,7 @@
namespace Diligent
{
-#if defined(PLATFORM_WIN32) || defined(PLATFORM_UNIVERSAL_WINDOWS) || defined(PLATFORM_LINUX)
+#if defined(PLATFORM_WIN32) || defined(PLATFORM_UNIVERSAL_WINDOWS) || defined(PLATFORM_LINUX) || defined(PLATFORM_MACOS)
typedef RenderDeviceGLImpl TRenderDeviceGLImpl;
#elif defined(PLATFORM_ANDROID)
typedef RenderDeviceGLESImpl TRenderDeviceGLImpl;
diff --git a/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp
index d088141f..b0b69563 100644
--- a/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp
+++ b/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp
@@ -52,6 +52,11 @@ ShaderGLImpl::ShaderGLImpl(IReferenceCounters *pRefCounters, RenderDeviceGLImpl
"#version 430 core\n"
"#define DESKTOP_GL 1\n"
);
+#elif defined(PLATFORM_MACOS)
+ Settings.append(
+ "#version 410 core\n"
+ "#define DESKTOP_GL 1\n"
+ );
#elif defined(ANDROID)
Settings.append(
"#version 310 es\n"
diff --git a/Graphics/GraphicsTools/src/GraphicsUtilities.cpp b/Graphics/GraphicsTools/src/GraphicsUtilities.cpp
index 67af25b1..7b987947 100644
--- a/Graphics/GraphicsTools/src/GraphicsUtilities.cpp
+++ b/Graphics/GraphicsTools/src/GraphicsUtilities.cpp
@@ -26,7 +26,7 @@
#include "DebugUtilities.h"
#include "GraphicsAccessories.h"
#include <algorithm>
-#include <math.h>
+#include <cmath>
#define PI_F 3.1415926f
diff --git a/Platforms/CMakeLists.txt b/Platforms/CMakeLists.txt
index 92ef3ba4..bc978cd4 100644
--- a/Platforms/CMakeLists.txt
+++ b/Platforms/CMakeLists.txt
@@ -26,6 +26,9 @@ elseif(PLATFORM_ANDROID)
elseif(PLATFORM_LINUX)
add_subdirectory(Linux)
add_library(TargetPlatform ALIAS LinuxPlatform)
+elseif(PLATFORM_MACOS)
+ add_subdirectory(MacOS)
+ add_library(TargetPlatform ALIAS MacOSPlatform)
else()
message(FATAL_ERROR "No PLATFORM_XXX variable defined. Make sure that 'DiligentCore' folder is processed first")
endif()
diff --git a/Platforms/MacOS/CMakeLists.txt b/Platforms/MacOS/CMakeLists.txt
new file mode 100644
index 00000000..c7fe8b5a
--- /dev/null
+++ b/Platforms/MacOS/CMakeLists.txt
@@ -0,0 +1,38 @@
+cmake_minimum_required (VERSION 3.6)
+
+project(MacOSPlatform CXX)
+
+set(INCLUDE
+ include/MacOSDebug.h
+ include/MacOSFileSystem.h
+ include/MacOSPlatformDefinitions.h
+ include/MacOSPlatformMisc.h
+)
+
+set(SOURCE
+ src/MacOSDebug.cpp
+ src/MacOSFileSystem.cpp
+)
+
+add_library(MacOSPlatform ${SOURCE} ${INCLUDE} ${PLATFORM_INTERFACE_HEADERS})
+set_common_target_properties(MacOSPlatform)
+
+target_include_directories(MacOSPlatform
+PUBLIC
+ include
+)
+
+target_link_libraries(MacOSPlatform
+PUBLIC
+ BuildSettings
+ BasicPlatform
+ PlatformInterface
+)
+
+source_group("src" FILES ${SOURCE})
+source_group("include" FILES ${INCLUDE})
+source_group("interface" FILES ${PLATFORM_INTERFACE_HEADERS})
+
+set_target_properties(MacOSPlatform PROPERTIES
+ FOLDER Core/Platforms
+)
diff --git a/Platforms/MacOS/include/MacOSDebug.h b/Platforms/MacOS/include/MacOSDebug.h
new file mode 100644
index 00000000..f570f73c
--- /dev/null
+++ b/Platforms/MacOS/include/MacOSDebug.h
@@ -0,0 +1,32 @@
+/* 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 "BasicPlatformDebug.h"
+
+struct MacOSDebug : public BasicPlatformDebug
+{
+ static void AssertionFailed( const Diligent::Char *Message, const char *Function, const char *File, int Line );
+ static void OutputDebugMessage( DebugMessageSeverity Severity, const Diligent::Char *Message );
+};
diff --git a/Platforms/MacOS/include/MacOSFileSystem.h b/Platforms/MacOS/include/MacOSFileSystem.h
new file mode 100644
index 00000000..ad2bc3b7
--- /dev/null
+++ b/Platforms/MacOS/include/MacOSFileSystem.h
@@ -0,0 +1,47 @@
+/* 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 "BasicFileSystem.h"
+#include "StandardFile.h"
+
+#include <memory>
+#include <vector>
+
+using MacOSFile = StandardFile;
+
+struct MacOSFileSystem : public BasicFileSystem
+{
+public:
+ static MacOSFile* OpenFile( const FileOpenAttribs &OpenAttribs );
+ static inline Diligent::Char GetSlashSymbol(){ return '/'; }
+
+ static bool FileExists( const Diligent::Char *strFilePath );
+ static bool PathExists( const Diligent::Char *strPath );
+
+ static bool CreateDirectory( const Diligent::Char *strPath );
+ static void ClearDirectory( const Diligent::Char *strPath );
+ static void DeleteFile( const Diligent::Char *strPath );
+ static std::vector<std::unique_ptr<FindFileData>> Search(const Diligent::Char *SearchPattern);
+};
diff --git a/Platforms/MacOS/include/MacOSPlatformDefinitions.h b/Platforms/MacOS/include/MacOSPlatformDefinitions.h
new file mode 100644
index 00000000..c00cbe3d
--- /dev/null
+++ b/Platforms/MacOS/include/MacOSPlatformDefinitions.h
@@ -0,0 +1,30 @@
+/* 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 <cstddef>
+
+template <typename _CountofType, std::size_t _SizeOfArray>
+char (*__countof_helper(_CountofType (&_Array)[_SizeOfArray]))[_SizeOfArray];
+#define _countof(_Array) (sizeof(*__countof_helper(_Array)) + 0)
diff --git a/Platforms/MacOS/include/MacOSPlatformMisc.h b/Platforms/MacOS/include/MacOSPlatformMisc.h
new file mode 100644
index 00000000..ffdc2451
--- /dev/null
+++ b/Platforms/MacOS/include/MacOSPlatformMisc.h
@@ -0,0 +1,43 @@
+/* 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 "BasicPlatformMisc.h"
+#include "DebugUtilities.h"
+
+struct MacOSMisc : public BasicPlatformMisc
+{
+ static Diligent::Uint32 GetMSB(Diligent::Uint32 Val)
+ {
+ if( Val == 0 )return 32;
+
+ // Returns the number of leading 0-bits in x, starting at the
+ // most significant bit position. If x is 0, the result is undefined.
+ auto LeadingZeros = __builtin_clz(Val);
+ auto MSB = 31 - LeadingZeros;
+ VERIFY_EXPR(MSB == BasicPlatformMisc::GetMSB(Val));
+
+ return MSB;
+ }
+};
diff --git a/Platforms/MacOS/src/MacOSDebug.cpp b/Platforms/MacOS/src/MacOSDebug.cpp
new file mode 100644
index 00000000..bfd3bf1f
--- /dev/null
+++ b/Platforms/MacOS/src/MacOSDebug.cpp
@@ -0,0 +1,59 @@
+/* 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 <csignal>
+#include <iostream>
+
+#include "MacOSDebug.h"
+#include "FormatMessage.h"
+
+using namespace Diligent;
+
+void MacOSDebug :: AssertionFailed( const Char *Message, const char *Function, const char *File, int Line )
+{
+ auto AssertionFailedMessage = FormatAssertionFailedMessage(Message, Function, File, Line);
+ OutputDebugMessage(DebugMessageSeverity::Error, AssertionFailedMessage.c_str());
+
+ raise( SIGTRAP );
+};
+
+
+void MacOSDebug::OutputDebugMessage( DebugMessageSeverity Severity, const Char *Message )
+{
+ static const Char* const strSeverities[] = { "Info: ", "Warning: ", "ERROR: ", "CRITICAL ERROR: " };
+ auto* MessageSevery = strSeverities[static_cast<int>(Severity)];
+ String str = MessageSevery;
+ str += Message;
+ str += '\n';
+ std::cerr << str;
+}
+
+void DebugAssertionFailed(const Diligent::Char* Message, const char* Function, const char* File, int Line)
+{
+ MacOSDebug :: AssertionFailed( Message, Function, File, Line );
+}
+
+void OutputDebugMessage(BasicPlatformDebug::DebugMessageSeverity Severity, const Diligent::Char* Message)
+{
+ MacOSDebug::OutputDebugMessage( Severity, Message );
+}
diff --git a/Platforms/MacOS/src/MacOSFileSystem.cpp b/Platforms/MacOS/src/MacOSFileSystem.cpp
new file mode 100644
index 00000000..eb9ee4c2
--- /dev/null
+++ b/Platforms/MacOS/src/MacOSFileSystem.cpp
@@ -0,0 +1,86 @@
+/* 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 <stdio.h>
+#include <unistd.h>
+#include <cstdio>
+
+#include "MacOSFileSystem.h"
+#include "Errors.h"
+#include "DebugUtilities.h"
+
+MacOSFile* MacOSFileSystem::OpenFile( const FileOpenAttribs &OpenAttribs )
+{
+ MacOSFile *pFile = nullptr;
+ try
+ {
+ pFile = new MacOSFile(OpenAttribs, MacOSFileSystem::GetSlashSymbol());
+ }
+ catch( const std::runtime_error &err )
+ {
+
+ }
+ return pFile;
+}
+
+
+bool MacOSFileSystem::FileExists( const Diligent::Char *strFilePath )
+{
+ FileOpenAttribs OpenAttribs;
+ OpenAttribs.strFilePath = strFilePath;
+ BasicFile DummyFile( OpenAttribs, MacOSFileSystem::GetSlashSymbol() );
+ const auto& Path = DummyFile.GetPath(); // This is necessary to correct slashes
+ FILE *pFile = fopen( Path.c_str(), "r" );
+ bool Exists = (pFile != nullptr);
+ if( Exists && pFile )
+ fclose( pFile );
+ return Exists;
+}
+
+bool MacOSFileSystem::PathExists( const Diligent::Char *strPath )
+{
+ UNSUPPORTED( "Not implemented" );
+ return false;
+}
+
+bool MacOSFileSystem::CreateDirectory( const Diligent::Char *strPath )
+{
+ UNSUPPORTED( "Not implemented" );
+ return false;
+}
+
+void MacOSFileSystem::ClearDirectory( const Diligent::Char *strPath )
+{
+ UNSUPPORTED( "Not implemented" );
+}
+
+void MacOSFileSystem::DeleteFile( const Diligent::Char *strPath )
+{
+ remove(strPath);
+}
+
+std::vector<std::unique_ptr<FindFileData>> MacOSFileSystem::Search(const Diligent::Char *SearchPattern)
+{
+ UNSUPPORTED( "Not implemented" );
+ return std::vector<std::unique_ptr<FindFileData>>();
+}
diff --git a/Platforms/interface/FileSystem.h b/Platforms/interface/FileSystem.h
index a9a99d57..89c795e9 100644
--- a/Platforms/interface/FileSystem.h
+++ b/Platforms/interface/FileSystem.h
@@ -49,6 +49,14 @@
typedef LinuxFileSystem FileSystem;
typedef LinuxFile CFile;
-#elif
+#elif defined ( PLATFORM_MACOS )
+
+ #include "MacOSFileSystem.h"
+ typedef MacOSFileSystem FileSystem;
+ typedef MacOSFile CFile;
+
+#else
+
#error Unsupported platform
+
#endif
diff --git a/Platforms/interface/PlatformDebug.h b/Platforms/interface/PlatformDebug.h
index aaea8fd7..019ede1e 100644
--- a/Platforms/interface/PlatformDebug.h
+++ b/Platforms/interface/PlatformDebug.h
@@ -41,6 +41,10 @@
#include "LinuxDebug.h"
typedef LinuxDebug PlatformDebug;
+#elif defined ( PLATFORM_LINUX )
+ #include "MacOSDebug.h"
+ typedef MacOSDebug PlatformDebug;
+
#else
#error Unsupported platform
#endif
diff --git a/Platforms/interface/PlatformDefinitions.h b/Platforms/interface/PlatformDefinitions.h
index 1c29e220..d41173dc 100644
--- a/Platforms/interface/PlatformDefinitions.h
+++ b/Platforms/interface/PlatformDefinitions.h
@@ -29,13 +29,13 @@
# endif
#endif
-#if !defined(PLATFORM_WIN32) && !defined(PLATFORM_UNIVERSAL_WINDOWS) && !defined(PLATFORM_ANDROID) && !defined(PLATFORM_LINUX)
+#if !defined(PLATFORM_WIN32) && !defined(PLATFORM_UNIVERSAL_WINDOWS) && !defined(PLATFORM_ANDROID) && !defined(PLATFORM_LINUX) && !defined(PLATFORM_MACOS)
#error Platform is not defined
#endif
#if defined( PLATFORM_WIN32 )
-# if defined(PLATFORM_UNIVERSAL_WINDOWS) || defined(PLATFORM_ANDROID) || defined(PLATFORM_LINUX)
+# if defined(PLATFORM_UNIVERSAL_WINDOWS) || defined(PLATFORM_ANDROID) || defined(PLATFORM_LINUX) || defined(PLATFORM_MACOS)
# error Conflicting platform macros
# endif
@@ -47,7 +47,7 @@
#elif defined( PLATFORM_UNIVERSAL_WINDOWS )
-# if defined(PLATFORM_WIN32) || defined(PLATFORM_ANDROID) || defined(PLATFORM_LINUX)
+# if defined(PLATFORM_WIN32) || defined(PLATFORM_ANDROID) || defined(PLATFORM_LINUX) || defined(PLATFORM_MACOS)
# error Conflicting platform macros
# endif
@@ -59,7 +59,7 @@
#elif defined( PLATFORM_ANDROID )
-# if defined (PLATFORM_WIN32) || defined(PLATFORM_UNIVERSAL_WINDOWS) || defined (PLATFORM_LINUX)
+# if defined (PLATFORM_WIN32) || defined(PLATFORM_UNIVERSAL_WINDOWS) || defined (PLATFORM_LINUX) || defined(PLATFORM_MACOS)
# error Conflicting platform macros
# endif
@@ -71,7 +71,7 @@
#elif defined( PLATFORM_LINUX )
-# if defined(PLATFORM_WIN32) || defined(PLATFORM_UNIVERSAL_WINDOWS) || defined(PLATFORM_ANDROID)
+# if defined(PLATFORM_WIN32) || defined(PLATFORM_UNIVERSAL_WINDOWS) || defined(PLATFORM_ANDROID) || defined(PLATFORM_MACOS)
# error Conflicting platform macros
# endif
@@ -81,6 +81,18 @@
# define D3D11_SUPPORTED 0
# define D3D12_SUPPORTED 0
+#elif defined( PLATFORM_MACOS )
+
+# if defined(PLATFORM_WIN32) || defined(PLATFORM_UNIVERSAL_WINDOWS) || defined(PLATFORM_ANDROID) || defined(PLATFORM_LINUX)
+# error Conflicting platform macros
+# endif
+
+# include "MacOSPlatformDefinitions.h"
+
+# define OPENGL_SUPPORTED 1
+# define D3D11_SUPPORTED 0
+# define D3D12_SUPPORTED 0
+
#else
# error Unsupported platform
diff --git a/Platforms/interface/PlatformMisc.h b/Platforms/interface/PlatformMisc.h
index 828c195d..9aaae658 100644
--- a/Platforms/interface/PlatformMisc.h
+++ b/Platforms/interface/PlatformMisc.h
@@ -36,6 +36,13 @@
#elif defined ( PLATFORM_LINUX )
#include "LinuxPlatformMisc.h"
typedef LinuxMisc PlatformMisc;
+
+#elif defined ( PLATFORM_MACOS )
+ #include "MacOSPlatformMisc.h"
+ typedef MacOSMisc PlatformMisc;
+
#else
+
#error Unsupported platform
+
#endif