summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineOpenGL
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-01-22 02:46:41 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-01-22 02:46:41 +0000
commitade81ab598df652e507c14ff3065d72b7116de1b (patch)
treef2757e5165e54b0874a03920fb8901f6fc10a61f /Graphics/GraphicsEngineOpenGL
parentFixed MacOS issues (diff)
downloadDiligentCore-ade81ab598df652e507c14ff3065d72b7116de1b.tar.gz
DiligentCore-ade81ab598df652e507c14ff3065d72b7116de1b.zip
Updated OpenGL context initialization on MacOS
Diffstat (limited to 'Graphics/GraphicsEngineOpenGL')
-rw-r--r--Graphics/GraphicsEngineOpenGL/CMakeLists.txt10
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h6
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.cpp58
3 files changed, 24 insertions, 50 deletions
diff --git a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt
index ade8728a..5f028151 100644
--- a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt
+++ b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt
@@ -99,6 +99,10 @@ elseif(PLATFORM_LINUX)
elseif(PLATFORM_MACOS)
list(APPEND SOURCE src/GLContextMacOS.cpp)
list(APPEND INCLUDE include/GLContextMacOS.h)
+ set_source_files_properties(
+ src/GLContextMacOS.cpp
+ COMPILE_FLAGS "-x objective-c++"
+ )
else()
message(FATAL_ERROR "Unknown platform")
endif()
@@ -166,7 +170,11 @@ 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})
+ find_library(APP_KIT AppKit)
+ if (NOT APP_KIT)
+ message(FATAL_ERROR "AppKit not found")
+ endif()
+ set(PRIVATE_DEPENDENCIES ${PRIVATE_DEPENDENCIES} glew-static ${OPENGL_LIBRARY} ${APP_KIT})
else()
message(FATAL_ERROR "Unknown platform")
endif()
diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h b/Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h
index 399251c9..3e5b77bb 100644
--- a/Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h
+++ b/Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h
@@ -25,7 +25,6 @@
namespace Diligent
{
-
struct ContextInitInfo
{
SwapChainDesc SwapChainAttribs;
@@ -35,10 +34,9 @@ namespace Diligent
class GLContext
{
public:
- typedef void* NativeGLContextType;
+ typedef void* NativeGLContextType; // NSOpenGLContext*
GLContext(const ContextInitInfo &Info, struct DeviceCaps &DeviceCaps);
- ~GLContext();
void SwapBuffers();
const SwapChainDesc& GetSwapChainDesc()const{ return m_SwapChainAttribs; }
@@ -46,8 +44,6 @@ namespace Diligent
NativeGLContextType GetCurrentNativeGLContext();
private:
- void *m_pNativeWindow = nullptr;
- NativeGLContextType m_Context;
SwapChainDesc m_SwapChainAttribs;
};
}
diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.cpp
index d0c54c37..81e0efdd 100644
--- a/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.cpp
+++ b/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.cpp
@@ -23,6 +23,8 @@
#include "pch.h"
+#import <AppKit/AppKit.h>
+
#include "GLContextMacOS.h"
#include "DeviceCaps.h"
#include "GLTypeConversions.h"
@@ -31,39 +33,24 @@ namespace Diligent
{
GLContext::GLContext( const ContextInitInfo &Info, DeviceCaps &DeviceCaps ) :
- m_pNativeWindow(Info.pNativeWndHandle),
- m_Context(0),
m_SwapChainAttribs(Info.SwapChainAttribs)
{
- //auto CurrentCtx = glXGetCurrentContext();
- //if (CurrentCtx == 0)
- //{
- // LOG_ERROR_AND_THROW("No current GL context found!");
- //}
+ if (GetCurrentNativeGLContext() == nullptr)
+ {
+ LOG_ERROR_AND_THROW("No current GL context found!");
+ }
// Initialize GLEW
glewExperimental = true; // This is required on MacOS
GLenum err = glewInit();
if( GLEW_OK != err )
LOG_ERROR_AND_THROW( "Failed to initialize GLEW" );
-#if 0
- 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);
- }
-#endif
-
- m_SwapChainAttribs.Width = 1024;
- m_SwapChainAttribs.Height = 768;
+ //Set dummy width and height until resize is called by the app
+ if(m_SwapChainAttribs.Width == 0)
+ m_SwapChainAttribs.Width = 1024;
+ if(m_SwapChainAttribs.Height)
+ m_SwapChainAttribs.Height = 768;
//Checking GL version
const GLubyte *GLVersionString = glGetString( GL_VERSION );
@@ -106,31 +93,14 @@ namespace Diligent
DeviceCaps.bMultithreadedResourceCreationSupported = False;
}
- 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
+ LOG_ERROR("Swap buffers operation must be performed by the app on MacOS");
}
GLContext::NativeGLContextType GLContext::GetCurrentNativeGLContext()
{
-#if 0
- return glXGetCurrentContext();
-#endif
- return nullptr;
+ NSOpenGLContext* CurrentCtx = [NSOpenGLContext currentContext];
+ return CurrentCtx;
}
}