summaryrefslogtreecommitdiffstats
path: root/Platforms
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 /Platforms
parentUpdate README.md (diff)
downloadDiligentCore-c2e99b91c06d26690b79fc548a5e1d2bc90591c8.tar.gz
DiligentCore-c2e99b91c06d26690b79fc548a5e1d2bc90591c8.zip
Enabled MacOS build
Diffstat (limited to 'Platforms')
-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
12 files changed, 375 insertions, 6 deletions
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