summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2017-12-20 05:41:39 +0000
committerEgor Yusov <egor.yusov@gmail.com>2017-12-20 05:41:39 +0000
commit45ca3b1c4cfcf791c5884697f18ff96da77a2cdc (patch)
tree9143b7e6945d5fbfa5039bd8d09770c156339e4f
parentFixed file paths ('\' -> '/') to fix Android build on linux (diff)
downloadDiligentCore-45ca3b1c4cfcf791c5884697f18ff96da77a2cdc.tar.gz
DiligentCore-45ca3b1c4cfcf791c5884697f18ff96da77a2cdc.zip
Enabling linux build (in progress)
-rw-r--r--CMakeLists.txt20
-rw-r--r--Common/include/StringTools.h4
-rw-r--r--External/CMakeLists.txt2
-rw-r--r--External/glew/CMakeLists.txt3
-rw-r--r--Graphics/GraphicsEngine/interface/Sampler.h1
-rw-r--r--Graphics/GraphicsEngineOpenGL/CMakeLists.txt4
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/GLContext.h14
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.h2
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/GLContextLinux.h52
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/GLContextWindows.h2
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/pch.h53
-rw-r--r--Graphics/GraphicsEngineOpenGL/interface/BaseInterfacesGL.h8
-rw-r--r--Graphics/GraphicsEngineOpenGL/interface/RenderDeviceFactoryOpenGL.h2
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp4
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/Texture2DArray_OGL.cpp2
-rw-r--r--Platforms/CMakeLists.txt3
-rw-r--r--Platforms/Linux/CMakeLists.txt39
-rw-r--r--Platforms/Linux/include/LinuxDebug.h32
-rw-r--r--Platforms/Linux/include/LinuxFileSystem.h66
-rw-r--r--Platforms/Linux/include/LinuxPlatformDefinitions.h30
-rw-r--r--Platforms/Linux/include/LinuxPlatformMisc.h43
-rw-r--r--Platforms/Linux/src/LinuxDebug.cpp50
-rw-r--r--Platforms/Linux/src/LinuxFileSystem.cpp190
-rw-r--r--Platforms/interface/FileSystem.h9
-rw-r--r--Platforms/interface/PlatformDebug.h7
-rw-r--r--Platforms/interface/PlatformDefinitions.h33
-rw-r--r--Platforms/interface/PlatformMisc.h6
27 files changed, 637 insertions, 44 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dc7a4927..e7eb682a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,6 +3,7 @@ cmake_minimum_required (VERSION 3.6)
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(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")
@@ -13,12 +14,18 @@ set(CMAKE_OBJECT_PATH_MAX 4096)
if(WIN32)
if(${CMAKE_SYSTEM_NAME} STREQUAL "WindowsStore")
set(PLATFORM_UNIVERSAL_WINDOWS TRUE CACHE INTERNAL "Target platform: Windows Store")
+ message("Target platform: Universal Windows")
else()
set(PLATFORM_WIN32 TRUE CACHE INTERNAL "Target platform: Win32") #WIN32 is a variable, so we cannot use string "WIN32"
+ message("Target platform: Win32")
endif()
else()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
set(PLATFORM_ANDROID TRUE CACHE INTERNAL "Target platform: Android")
+ message("Target platform: Android")
+ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
+ set(PLATFORM_LINUX TRUE CACHE INTERNAL "Target platform: Linux")
+ message("Target Platform: Linux")
else()
message(FATAL_ERROR "Unsupported platform")
endif()
@@ -38,6 +45,9 @@ elseif(PLATFORM_UNIVERSAL_WINDOWS)
elseif(PLATFORM_ANDROID)
set(GLES_SUPPORTED TRUE CACHE INTERNAL "OpenGLES supported on Android platform")
target_compile_definitions(BuildSettings INTERFACE PLATFORM_ANDROID=1)
+elseif(PLATFORM_LINUX)
+ set(GL_SUPPORTED TRUE CACHE INTERNAL "OpenGL supported on Linux platform")
+ target_compile_definitions(BuildSettings INTERFACE PLATFORM_LINUX=1)
else()
message(FATAL_ERROR "No PLATFORM_XXX variable defined. Make sure that 'DiligentCore' folder is processed first")
endif()
@@ -71,6 +81,16 @@ if(MSVC)
# does not work as expected
endif(MSVC)
+if(PLATFORM_LINUX)
+ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
+ # Without -fPIC option GCC fails to link static libraries into dynamic library:
+ # -fPIC
+ # If supported for the target machine, emit position-independent code, suitable for
+ # dynamic linking and avoiding any limit on the size of the global offset table.
+ target_compile_options(BuildSettings INTERFACE -fPIC)
+ endif()
+endif()
+
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
set(ARCH 64 CACHE INTERNAL "64-bit architecture")
else()
diff --git a/Common/include/StringTools.h b/Common/include/StringTools.h
index 6bf713de..74b6e7dd 100644
--- a/Common/include/StringTools.h
+++ b/Common/include/StringTools.h
@@ -70,7 +70,7 @@ inline std::wstring WidenString(const std::string &Str)
inline int StrCmpNoCase(const char* Str1, const char* Str2, size_t NumChars)
{
-#ifdef PLATFORM_ANDROID
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_LINUX)
# define _strnicmp strncasecmp
#endif
@@ -79,7 +79,7 @@ inline int StrCmpNoCase(const char* Str1, const char* Str2, size_t NumChars)
inline int StrCmpNoCase(const char* Str1, const char* Str2)
{
-#ifdef PLATFORM_ANDROID
+#if defined(PLATFORM_ANDROID) || defined(PLATFORM_LINUX)
# define _stricmp strcasecmp
#endif
diff --git a/External/CMakeLists.txt b/External/CMakeLists.txt
index 14890b34..55616bd8 100644
--- a/External/CMakeLists.txt
+++ b/External/CMakeLists.txt
@@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.6)
-if(PLATFORM_WIN32)
+if(PLATFORM_WIN32 OR PLATFORM_LINUX)
add_subdirectory(glew)
endif()
diff --git a/External/glew/CMakeLists.txt b/External/glew/CMakeLists.txt
index 28f2a493..1562088e 100644
--- a/External/glew/CMakeLists.txt
+++ b/External/glew/CMakeLists.txt
@@ -16,7 +16,8 @@ set_common_target_properties(glew-static)
target_compile_definitions(glew-static
PUBLIC
- -DGLEW_STATIC
+ GLEW_STATIC
+ GLEW_NO_GLU
)
target_include_directories(glew-static
diff --git a/Graphics/GraphicsEngine/interface/Sampler.h b/Graphics/GraphicsEngine/interface/Sampler.h
index a36eeae0..bc8a649d 100644
--- a/Graphics/GraphicsEngine/interface/Sampler.h
+++ b/Graphics/GraphicsEngine/interface/Sampler.h
@@ -26,6 +26,7 @@
/// \file
/// Definition of the Diligent::ISampler interface and related data structures
+#include <cfloat>
#include "DeviceObject.h"
namespace Diligent
diff --git a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt
index 4ce567d0..bc4b423a 100644
--- a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt
+++ b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt
@@ -94,6 +94,8 @@ elseif(PLATFORM_ANDROID)
set(APPEND INCLUDE include/RenderDeviceGLESImpl.h)
set(APPEND INTERFACE interface/RenderDeviceGLES.h)
+elseif(PLATFORM_LINUX)
+ set(APPEND INCLUDE include/GLContextLinux.h)
else()
message(FATAL_ERROR "Unknown platform")
endif()
@@ -151,6 +153,8 @@ elseif(PLATFORM_ANDROID)
target_compile_definitions(GraphicsEngineOpenGL-static PRIVATE BUILDING_DLL USE_GL3_STUB=0)
target_compile_definitions(GraphicsEngineOpenGL-shared PRIVATE BUILDING_DLL USE_GL3_STUB=0)
set_target_properties(GraphicsEngineOpenGL-shared PROPERTIES CXX_VISIBILITY_PRESET hidden) # -fvisibility=hidden
+elseif(PLATFORM_LINUX)
+ set(PRIVATE_DEPENDENCIES ${PRIVATE_DEPENDENCIES} glew-static)
else()
message(FATAL_ERROR "Unknown platform")
endif()
diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContext.h b/Graphics/GraphicsEngineOpenGL/include/GLContext.h
index 2db25f4c..d5ca746e 100644
--- a/Graphics/GraphicsEngineOpenGL/include/GLContext.h
+++ b/Graphics/GraphicsEngineOpenGL/include/GLContext.h
@@ -23,10 +23,12 @@
#pragma once
-#ifdef PLATFORM_WIN32
-#include "GLContextWindows.h"
-#endif
-
-#ifdef ANDROID
-#include "GLContextAndroid.h"
+#if defined(PLATFORM_WIN32)
+# include "GLContextWindows.h"
+#elif defined(PLATFORM_ANDROID)
+# include "GLContextAndroid.h"
+#elif defined(PLATFORM_LINUX)
+# include "GLContextLinux.h"
+#else
+# error Unsupported platform
#endif
diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.h b/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.h
index d2892c1e..68270a8f 100644
--- a/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.h
+++ b/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.h
@@ -51,7 +51,7 @@ namespace Diligent
void Suspend();
EGLint Resume( ANativeWindow* window );
- const SwapChainDesc& GetSwapChainDesc(){ return SwapChainAttribs_; }
+ const SwapChainDesc& GetSwapChainDesc()const{ return SwapChainAttribs_; }
NativeGLContextType GetCurrentNativeGLContext();
diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextLinux.h b/Graphics/GraphicsEngineOpenGL/include/GLContextLinux.h
new file mode 100644
index 00000000..ff6796cb
--- /dev/null
+++ b/Graphics/GraphicsEngineOpenGL/include/GLContextLinux.h
@@ -0,0 +1,52 @@
+/* Copyright 2015-2017 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;
+ };
+
+ 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() { return nullptr; }
+
+ private:
+ void* m_Context;
+ SwapChainDesc m_SwapChainAttribs;
+ };
+}
diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.h b/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.h
index adc2984a..38895afa 100644
--- a/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.h
+++ b/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.h
@@ -41,7 +41,7 @@ namespace Diligent
~GLContext();
void SwapBuffers();
- const SwapChainDesc& GetSwapChainDesc(){ return m_SwapChainAttribs; }
+ const SwapChainDesc& GetSwapChainDesc()const{ return m_SwapChainAttribs; }
NativeGLContextType GetCurrentNativeGLContext();
diff --git a/Graphics/GraphicsEngineOpenGL/include/pch.h b/Graphics/GraphicsEngineOpenGL/include/pch.h
index 9e6faac7..dd037ed6 100644
--- a/Graphics/GraphicsEngineOpenGL/include/pch.h
+++ b/Graphics/GraphicsEngineOpenGL/include/pch.h
@@ -35,35 +35,48 @@
#include <unordered_set>
#include <algorithm>
-// Must be defined to use static version of glew
-#ifdef PLATFORM_WIN32
+#if defined(PLATFORM_WIN32)
+
# ifndef GLEW_STATIC
-# define GLEW_STATIC
+# define GLEW_STATIC // Must be defined to use static version of glew
# endif
- #include "glew.h"
+# include "glew.h"
// Glew includes <windows.h>
- #define NOMINMAX
- #include "wglew.h"
- #include <GL/GL.h>
-#endif
+# define NOMINMAX
+# include "wglew.h"
+# include <GL/GL.h>
+#elif defined(PLATFORM_LINUX)
-#ifdef ANDROID
-#ifndef USE_GL3_STUB
- #define USE_GL3_STUB 0
-#endif
- #if USE_GL3_STUB
- #include "gl3stub.h"
- #include <GLES2/gl2platform.h>
- #else
- #include <GLES3/gl3.h>
- #include <GLES3/gl3ext.h>
- #endif
+# 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 "glew.h"
+
+# elif defined(PLATFORM_ANDROID)
+
+# ifndef USE_GL3_STUB
+# define USE_GL3_STUB 0
+# endif
+# if USE_GL3_STUB
+# include "gl3stub.h"
+# include <GLES2/gl2platform.h>
+# else
+# include <GLES3/gl3.h>
+# include <GLES3/gl3ext.h>
+# endif
+
+#else
+# error Unsupported platform
#endif
#include "Errors.h"
-#ifdef ANDROID
+#ifdef PLATFORM_ANDROID
// GLStubs must be included after GLFeatures!
#include "GLStubs.h"
#endif
diff --git a/Graphics/GraphicsEngineOpenGL/interface/BaseInterfacesGL.h b/Graphics/GraphicsEngineOpenGL/interface/BaseInterfacesGL.h
index cad22936..45a281d7 100644
--- a/Graphics/GraphicsEngineOpenGL/interface/BaseInterfacesGL.h
+++ b/Graphics/GraphicsEngineOpenGL/interface/BaseInterfacesGL.h
@@ -23,20 +23,20 @@
#pragma once
-#ifdef ANDROID
+#if defined(PLATFORM_ANDROID)
#include "RenderDeviceGLES.h"
namespace Diligent
{
using IGLDeviceBaseInterface = IRenderDeviceGLES;
}
-#endif
-
-#ifdef PLATFORM_WIN32
+#elif defined(PLATFORM_WIN32) || defined(PLATFORM_LINUX)
#include "RenderDeviceGL.h"
namespace Diligent
{
using IGLDeviceBaseInterface = IRenderDeviceGL;
}
+#else
+# error Unsupported platform
#endif
#include "DeviceContextGL.h"
diff --git a/Graphics/GraphicsEngineOpenGL/interface/RenderDeviceFactoryOpenGL.h b/Graphics/GraphicsEngineOpenGL/interface/RenderDeviceFactoryOpenGL.h
index 8876b9ae..cbf67c8a 100644
--- a/Graphics/GraphicsEngineOpenGL/interface/RenderDeviceFactoryOpenGL.h
+++ b/Graphics/GraphicsEngineOpenGL/interface/RenderDeviceFactoryOpenGL.h
@@ -35,7 +35,7 @@
# define API_QUALIFIER
-#elif defined(PLATFORM_ANDROID)
+#elif defined(PLATFORM_ANDROID) || defined(PLATFORM_LINUX)
# ifdef ENGINE_DLL
# ifdef BUILDING_DLL
diff --git a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp
index a18ca767..aa19f8ee 100644
--- a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp
+++ b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp
@@ -39,10 +39,12 @@
namespace Diligent
{
-#if defined(PLATFORM_WIN32) || defined(PLATFORM_UNIVERSAL_WINDOWS)
+#if defined(PLATFORM_WIN32) || defined(PLATFORM_UNIVERSAL_WINDOWS) || defined(PLATFORM_LINUX)
typedef RenderDeviceGLImpl TRenderDeviceGLImpl;
#elif defined(PLATFORM_ANDROID)
typedef RenderDeviceGLESImpl TRenderDeviceGLImpl;
+#else
+# error Unsupported platform
#endif
/// Engine factory for OpenGL implementation
diff --git a/Graphics/GraphicsEngineOpenGL/src/Texture2DArray_OGL.cpp b/Graphics/GraphicsEngineOpenGL/src/Texture2DArray_OGL.cpp
index b199439d..44507f58 100644
--- a/Graphics/GraphicsEngineOpenGL/src/Texture2DArray_OGL.cpp
+++ b/Graphics/GraphicsEngineOpenGL/src/Texture2DArray_OGL.cpp
@@ -48,7 +48,7 @@ Texture2DArray_OGL::Texture2DArray_OGL( IReferenceCounters *pRefCounters,
if( m_Desc.SampleCount > 1 )
{
// format width height depth
- glTexStorage3DMultisample(m_BindTarget, m_Desc.SampleCount, m_GLTexFormat, m_Desc.Width, m_Desc.Height, m_Desc.ArraySize, TRUE);
+ glTexStorage3DMultisample(m_BindTarget, m_Desc.SampleCount, m_GLTexFormat, m_Desc.Width, m_Desc.Height, m_Desc.ArraySize, GL_TRUE);
// The last parameter specifies whether the image will use identical sample locations and the same number of
// samples for all texels in the image, and the sample locations will not depend on the internal format or size
// of the image.
diff --git a/Platforms/CMakeLists.txt b/Platforms/CMakeLists.txt
index 77fa5ce6..d51bdb08 100644
--- a/Platforms/CMakeLists.txt
+++ b/Platforms/CMakeLists.txt
@@ -15,6 +15,9 @@ elseif(PLATFORM_UNIVERSAL_WINDOWS)
elseif(PLATFORM_ANDROID)
add_subdirectory(Android)
add_library(TargetPlatform ALIAS AndroidPlatform)
+elseif(PLATFORM_LINUX)
+ add_subdirectory(Linux)
+ add_library(TargetPlatform ALIAS LinuxPlatform)
else()
message(FATAL_ERROR "No PLATFORM_XXX variable defined. Make sure that 'DiligentCore' folder is processed first")
endif()
diff --git a/Platforms/Linux/CMakeLists.txt b/Platforms/Linux/CMakeLists.txt
new file mode 100644
index 00000000..220160af
--- /dev/null
+++ b/Platforms/Linux/CMakeLists.txt
@@ -0,0 +1,39 @@
+cmake_minimum_required (VERSION 3.6)
+
+project(LinuxPlatform CXX)
+
+set(INCLUDE
+ include/LinuxDebug.h
+ include/LinuxFileSystem.h
+ include/LinuxPlatformDefinitions.h
+ include/LinuxPlatformMisc.h
+)
+
+set(SOURCE
+ src/LinuxDebug.cpp
+ src/LinuxFileSystem.cpp
+)
+
+add_library(LinuxPlatform ${SOURCE} ${INCLUDE})
+set_common_target_properties(LinuxPlatform)
+
+target_include_directories(LinuxPlatform
+PUBLIC
+ include
+)
+
+target_link_libraries(LinuxPlatform
+PRIVATE
+ BuildSettings
+ Common
+PUBLIC
+ PlatformInterface
+ BasicPlatform
+)
+
+source_group("src" FILES ${SOURCE})
+source_group("include" FILES ${INCLUDE})
+
+set_target_properties(LinuxPlatform PROPERTIES
+ FOLDER Core/Platforms
+)
diff --git a/Platforms/Linux/include/LinuxDebug.h b/Platforms/Linux/include/LinuxDebug.h
new file mode 100644
index 00000000..1c24f6d1
--- /dev/null
+++ b/Platforms/Linux/include/LinuxDebug.h
@@ -0,0 +1,32 @@
+/* Copyright 2015-2017 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 "../Basic/include/BasicPlatformDebug.h"
+
+struct LinuxDebug : 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/Linux/include/LinuxFileSystem.h b/Platforms/Linux/include/LinuxFileSystem.h
new file mode 100644
index 00000000..0fa33a54
--- /dev/null
+++ b/Platforms/Linux/include/LinuxFileSystem.h
@@ -0,0 +1,66 @@
+/* Copyright 2015-2017 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 "../Basic/include/BasicFileSystem.h"
+
+#include <memory>
+#include <vector>
+
+class LinuxFile : public BasicFile
+{
+public:
+ LinuxFile( const FileOpenAttribs &OpenAttribs );
+ ~LinuxFile();
+
+ void Read( Diligent::IDataBlob *pData );
+
+ bool Read( void* Data, size_t BufferSize );
+
+ bool Write( const void *Data, size_t BufferSize );
+
+ size_t GetSize();
+
+ size_t GetPos();
+
+ void SetPos(size_t Offset, FilePosOrigin Origin);
+
+private:
+ //FILE *m_pFile;
+};
+
+struct LinuxFileSystem : public BasicFileSystem
+{
+public:
+ static LinuxFile* 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/Linux/include/LinuxPlatformDefinitions.h b/Platforms/Linux/include/LinuxPlatformDefinitions.h
new file mode 100644
index 00000000..454c7446
--- /dev/null
+++ b/Platforms/Linux/include/LinuxPlatformDefinitions.h
@@ -0,0 +1,30 @@
+/* Copyright 2015-2017 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/Linux/include/LinuxPlatformMisc.h b/Platforms/Linux/include/LinuxPlatformMisc.h
new file mode 100644
index 00000000..a961f468
--- /dev/null
+++ b/Platforms/Linux/include/LinuxPlatformMisc.h
@@ -0,0 +1,43 @@
+/* Copyright 2015-2017 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 "../Basic/include/BasicPlatformMisc.h"
+#include "DebugUtilities.h"
+
+struct LinuxMisc : 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/Linux/src/LinuxDebug.cpp b/Platforms/Linux/src/LinuxDebug.cpp
new file mode 100644
index 00000000..2ffb7a12
--- /dev/null
+++ b/Platforms/Linux/src/LinuxDebug.cpp
@@ -0,0 +1,50 @@
+/* Copyright 2015-2017 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 "LinuxDebug.h"
+#include "FormatMessage.h"
+#include "FileSystem.h"
+//#include <Linux/log.h>
+#include <csignal>
+#include <cassert>
+
+void LinuxDebug :: AssertionFailed( const Diligent::Char *Message, const char *Function, const char *File, int Line )
+{
+ assert(false);
+ //std::string FileName;
+ //FileSystem::SplitFilePath( File, nullptr, &FileName );
+ //std::stringstream msgss;
+ //Diligent::FormatMsg( msgss, "\nDebug assertion failed in ", Function, "(), file ", FileName, ", line ", Line, ":\n", Message);
+ //auto FullMsg = msgss.str();
+ //OutputDebugMessage( DebugMessageSeverity::Error, FullMsg.c_str() );
+
+ //raise( SIGTRAP );
+};
+
+
+void LinuxDebug::OutputDebugMessage( DebugMessageSeverity Severity, const Diligent::Char *Message )
+{
+ assert(false);
+ //static const Linux_LogPriority Priorities[] = { Linux_LOG_INFO, Linux_LOG_WARN, Linux_LOG_ERROR, Linux_LOG_FATAL };
+ //__Linux_log_print( Priorities[static_cast<int>(Severity)], "Graphics Engine", "%s", Message );
+}
diff --git a/Platforms/Linux/src/LinuxFileSystem.cpp b/Platforms/Linux/src/LinuxFileSystem.cpp
new file mode 100644
index 00000000..2ac59630
--- /dev/null
+++ b/Platforms/Linux/src/LinuxFileSystem.cpp
@@ -0,0 +1,190 @@
+/* Copyright 2015-2017 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 "LinuxFileSystem.h"
+#include "Errors.h"
+#include "DebugUtilities.h"
+
+LinuxFile::LinuxFile( const FileOpenAttribs &OpenAttribs ) :
+ BasicFile(OpenAttribs, LinuxFileSystem::GetSlashSymbol())/*,
+ m_pFile(nullptr)*/
+{
+ //auto OpenModeStr = GetOpenModeStr();
+
+ //for (;; )
+ //{
+ // errno_t err = fopen_s(&m_pFile, m_OpenAttribs.strFilePath, OpenModeStr.c_str());
+ // if (err == 0)
+ // {
+ // break;
+ // }
+ // else if (err == ENFILE || // Too many files open in system
+ // err == EMFILE) // Too many open files
+ // {
+ // // No more file descriptors are available: we have to wait
+ // //g_SystemMetricsStream << "Failed to open file " << FileName;
+ // //g_SystemMetricsStream << "\nWaiting 50 ms...\n";
+ // //Sleep(50);
+ // continue;
+ // }
+ // else
+ // {
+ // char errstr[128];
+ // strerror_s(errstr, _countof(errstr), err);
+ // LOG_ERROR_AND_THROW("Failed to open file ", m_OpenAttribs.strFilePath,
+ // "\nThe following error occured: ", errstr);
+ // }
+ //}
+}
+
+LinuxFile::~LinuxFile()
+{
+ //if( m_pFile )
+ //{
+ // fclose( m_pFile );
+ // m_pFile = nullptr;
+ //}
+}
+
+void LinuxFile::Read( Diligent::IDataBlob *pData )
+{
+#if 0
+ auto FullPath = m_OpenAttribs.strFilePath;
+ std::vector<Diligent::Uint8> Data;
+ bool b = JNIHelper::GetInstance()->ReadFile( FullPath, &Data );
+ if( b )
+ {
+ pData->Resize( Data.size() );
+ memcpy( pData->GetDataPtr(), Data.data(), Data.size() );
+ }
+ else
+ {
+ LOG_ERROR_MESSAGE( "Unable to open file ", m_OpenAttribs.strFilePath, "\nFull path: ", FullPath );
+ }
+#endif
+ UNSUPPORTED("Not implemented")
+}
+
+size_t LinuxFile::GetSize()
+{
+ UNSUPPORTED( "Not implemented" );
+
+ return 0;
+}
+
+bool LinuxFile::Read( void *Data, size_t BufferSize )
+{
+ UNSUPPORTED( "Not implemented" );
+
+ //VERIFY( m_pFile, "File not opened" );
+ //auto OrigPos = ftell( m_pFile );
+ //fseek( m_pFile, 0, SEEK_END );
+ //auto FileSize = ftell( m_pFile );
+ //fseek( m_pFile, 0, SEEK_SET );
+ //Data.resize( FileSize );
+ //auto ItemsRead = fread( Data.data(), FileSize, 1, m_pFile );
+ //fseek( m_pFile, OrigPos, SEEK_SET );
+ //return ItemsRead == 1;
+ return false;
+}
+
+bool LinuxFile::Write( const void *Data, size_t BufferSize )
+{
+ UNSUPPORTED( "Not implemented" );
+
+ return false;
+}
+
+size_t LinuxFile::GetPos()
+{
+ UNSUPPORTED( "Not implemented" );
+
+ return 0;
+}
+
+void LinuxFile::SetPos(size_t Offset, FilePosOrigin Origin)
+{
+ UNSUPPORTED( "Not implemented" );
+}
+
+
+LinuxFile* LinuxFileSystem::OpenFile( const FileOpenAttribs &OpenAttribs )
+{
+ LinuxFile *pFile = nullptr;
+#if 0
+ try
+ {
+ pFile = new LinuxFile( OpenAttribs );
+ }
+ catch( const std::runtime_error &err )
+ {
+
+ }
+#endif
+ UNSUPPORTED("Not implemented")
+ return pFile;
+}
+
+
+bool LinuxFileSystem::FileExists( const Diligent::Char *strFilePath )
+{
+#if 0
+ FileOpenAttribs OpenAttribs;
+ OpenAttribs.strFilePath = strFilePath;
+ BasicFile DummyFile( OpenAttribs, LinuxFileSystem::GetSlashSymbol() );
+ const auto& Path = DummyFile.GetPath();
+ std::vector<Diligent::Uint8> Data;
+ bool b = JNIHelper::GetInstance()->ReadFile( Path.c_str(), &Data );
+ return b;
+#endif
+ UNSUPPORTED("Not implemented")
+ return false;
+}
+
+bool LinuxFileSystem::PathExists( const Diligent::Char *strPath )
+{
+ UNSUPPORTED( "Not implemented" );
+ return false;
+}
+
+bool LinuxFileSystem::CreateDirectory( const Diligent::Char *strPath )
+{
+ UNSUPPORTED( "Not implemented" );
+ return false;
+}
+
+void LinuxFileSystem::ClearDirectory( const Diligent::Char *strPath )
+{
+ UNSUPPORTED( "Not implemented" );
+}
+
+void LinuxFileSystem::DeleteFile( const Diligent::Char *strPath )
+{
+ UNSUPPORTED( "Not implemented" );
+}
+
+std::vector<std::unique_ptr<FindFileData>> LinuxFileSystem::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 91f20e58..f9ce26f3 100644
--- a/Platforms/interface/FileSystem.h
+++ b/Platforms/interface/FileSystem.h
@@ -42,4 +42,13 @@
#include "../Android/include/AndroidFileSystem.h"
typedef AndroidFileSystem FileSystem;
typedef AndroidFile CFile;
+
+#elif defined ( PLATFORM_LINUX )
+
+ #include "../Linux/include/LinuxFileSystem.h"
+ typedef LinuxFileSystem FileSystem;
+ typedef LinuxFile CFile;
+
+#elif
+ #error Unsupported platform
#endif
diff --git a/Platforms/interface/PlatformDebug.h b/Platforms/interface/PlatformDebug.h
index 994f6849..0e00e76c 100644
--- a/Platforms/interface/PlatformDebug.h
+++ b/Platforms/interface/PlatformDebug.h
@@ -36,4 +36,11 @@
#elif defined ( PLATFORM_ANDROID )
#include "../Android/include/AndroidDebug.h"
typedef AndroidDebug PlatformDebug;
+
+#elif defined ( PLATFORM_LINUX )
+ #include "../Linux/include/LinuxDebug.h"
+ typedef LinuxDebug PlatformDebug;
+
+#else
+ #error Unsupported platform
#endif
diff --git a/Platforms/interface/PlatformDefinitions.h b/Platforms/interface/PlatformDefinitions.h
index 6d1adcec..3f8638e2 100644
--- a/Platforms/interface/PlatformDefinitions.h
+++ b/Platforms/interface/PlatformDefinitions.h
@@ -24,18 +24,21 @@
#pragma once
#if defined(ANDROID)
-# if defined (PLATFORM_UNIVERSAL_WINDOWS) || defined (PLATFORM_WIN32)
-# error Conflicting platform macros
-# endif
# ifndef PLATFORM_ANDROID
# define PLATFORM_ANDROID
# endif
-#elif !defined (PLATFORM_UNIVERSAL_WINDOWS) && !defined (PLATFORM_WIN32)
+#endif
+
+#if !defined(PLATFORM_WIN32) && !defined(PLATFORM_UNIVERSAL_WINDOWS) && !defined(PLATFORM_ANDROID) && !defined(PLATFORM_LINUX)
#error Platform is not defined
#endif
#if defined( PLATFORM_WIN32 )
+# if defined(PLATFORM_UNIVERSAL_WINDOWS) || defined(PLATFORM_ANDROID) || defined(PLATFORM_LINUX)
+# error Conflicting platform macros
+# endif
+
# include "..\Win32\include\Win32PlatformDefinitions.h"
# define OPENGL_SUPPORTED 1
@@ -44,13 +47,21 @@
#elif defined( PLATFORM_UNIVERSAL_WINDOWS )
+# if defined(PLATFORM_WIN32) || defined(PLATFORM_ANDROID) || defined(PLATFORM_LINUX)
+# error Conflicting platform macros
+# endif
+
# include "..\UWP\include\UWPDefinitions.h"
# define OPENGL_SUPPORTED 0
# define D3D11_SUPPORTED 1
# define D3D12_SUPPORTED 1
-#elif defined ( PLATFORM_ANDROID )
+#elif defined( PLATFORM_ANDROID )
+
+# if defined (PLATFORM_WIN32) || defined(PLATFORM_UNIVERSAL_WINDOWS) || defined (PLATFORM_LINUX)
+# error Conflicting platform macros
+# endif
# include "../Android/include/AndroidPlatformDefinitions.h"
@@ -58,4 +69,16 @@
# define D3D11_SUPPORTED 0
# define D3D12_SUPPORTED 0
+#elif defined( PLATFORM_LINUX )
+
+# if defined(PLATFORM_WIN32) || defined(PLATFORM_UNIVERSAL_WINDOWS) || defined(PLATFORM_ANDROID)
+# error Conflicting platform macros
+# endif
+
+# include "../Linux/include/LinuxPlatformDefinitions.h"
+
+# define OPENGL_SUPPORTED 1
+# define D3D11_SUPPORTED 0
+# define D3D12_SUPPORTED 0
+
#endif
diff --git a/Platforms/interface/PlatformMisc.h b/Platforms/interface/PlatformMisc.h
index fbcbcff6..b4d10aaa 100644
--- a/Platforms/interface/PlatformMisc.h
+++ b/Platforms/interface/PlatformMisc.h
@@ -32,4 +32,10 @@
#elif defined ( PLATFORM_ANDROID )
#include "../Android/include/AndroidPlatformMisc.h"
typedef AndroidMisc PlatformMisc;
+
+#elif defined ( PLATFORM_LINUX )
+ #include "../Linux/include/LinuxPlatformMisc.h"
+ typedef LinuxMisc PlatformMisc;
+#else
+ #error Unsupported platform
#endif