summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineOpenGL
diff options
context:
space:
mode:
Diffstat (limited to 'Graphics/GraphicsEngineOpenGL')
-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
9 files changed, 281 insertions, 4 deletions
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"