From f2603cc9aca1e668ad79dfb87244ae9351953909 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 20 Jan 2018 18:08:50 -0800 Subject: Fixed MacOS issues --- Graphics/GraphicsEngineOpenGL/CMakeLists.txt | 8 ++ .../GraphicsEngineOpenGL/include/GLContextMacOS.h | 2 - .../GraphicsEngineOpenGL/src/GLContextMacOS.cpp | 90 ++++------------------ .../src/GLProgramResources.cpp | 24 +++--- .../GraphicsEngineOpenGL/src/TexRegionRender.cpp | 15 ++-- 5 files changed, 42 insertions(+), 97 deletions(-) (limited to 'Graphics/GraphicsEngineOpenGL') diff --git a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt index 30e85828..ade8728a 100644 --- a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt +++ b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt @@ -171,6 +171,14 @@ else() message(FATAL_ERROR "Unknown platform") endif() +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # Disable the following clang warning + # '' hides overloaded virtual function + # as hiding is intended + target_compile_options(GraphicsEngineOpenGL-static PRIVATE -Wno-overloaded-virtual) + target_compile_options(GraphicsEngineOpenGL-shared PRIVATE -Wno-overloaded-virtual) +endif() + target_link_libraries(GraphicsEngineOpenGL-static PRIVATE ${PRIVATE_DEPENDENCIES} PUBLIC ${PUBLIC_DEPENDENCIES}) target_link_libraries(GraphicsEngineOpenGL-shared PRIVATE ${PRIVATE_DEPENDENCIES} PUBLIC ${PUBLIC_DEPENDENCIES}) target_compile_definitions(GraphicsEngineOpenGL-shared PUBLIC ENGINE_DLL) diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h b/Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h index 8ecf9822..399251c9 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h +++ b/Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h @@ -30,7 +30,6 @@ namespace Diligent { SwapChainDesc SwapChainAttribs; void *pNativeWndHandle = nullptr; - void *pDisplay = nullptr; }; class GLContext @@ -48,7 +47,6 @@ namespace Diligent private: void *m_pNativeWindow = nullptr; - void *m_pDisplay = nullptr; NativeGLContextType m_Context; SwapChainDesc m_SwapChainAttribs; }; diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.cpp index 74e3d996..d0c54c37 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.cpp @@ -29,78 +29,24 @@ 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_pNativeWindow(Info.pNativeWndHandle), - m_pDisplay(Info.pDisplay), m_Context(0), m_SwapChainAttribs(Info.SwapChainAttribs) { -#if 0 - auto CurrentCtx = glXGetCurrentContext(); - if (CurrentCtx == 0) - { - LOG_ERROR_AND_THROW("No current GL context found!"); - } + //auto CurrentCtx = glXGetCurrentContext(); + //if (CurrentCtx == 0) + //{ + // 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(reinterpret_cast(Info.pNativeWndHandle)); @@ -113,20 +59,11 @@ namespace Diligent 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 ); - } } +#endif + + m_SwapChainAttribs.Width = 1024; + m_SwapChainAttribs.Height = 768; //Checking GL version const GLubyte *GLVersionString = glGetString( GL_VERSION ); @@ -158,14 +95,15 @@ namespace Diligent DeviceCaps.DevType = DeviceType::OpenGL; DeviceCaps.MajorVersion = MajorVersion; DeviceCaps.MinorVersion = MinorVersion; - bool IsGL43OrAbove = MajorVersion >= 5 || MajorVersion == 4 && MinorVersion >= 3; + bool IsGL43OrAbove = MajorVersion >= 5 || (MajorVersion == 4 && MinorVersion >= 3); + bool IsGL42OrAbove = MajorVersion >= 5 || (MajorVersion == 4 && MinorVersion >= 2); + DeviceCaps.bComputeShadersSupported = IsGL42OrAbove; auto &TexCaps = DeviceCaps.TexCaps; TexCaps.bTexture2DMSSupported = IsGL43OrAbove; TexCaps.bTexture2DMSArraySupported = IsGL43OrAbove; TexCaps.bTextureViewSupported = IsGL43OrAbove; TexCaps.bCubemapArraysSupported = IsGL43OrAbove; DeviceCaps.bMultithreadedResourceCreationSupported = False; -#endif } GLContext::~GLContext() diff --git a/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp b/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp index bf90d650..5ec56f8d 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp @@ -83,19 +83,21 @@ namespace Diligent LOG_WARNING_MESSAGE( "Unable to get the maximum uniform block name length. Using 1024 as a workaround\n" ); activeUniformBlockMaxLength = 1024; } - - - GLint numActiveShaderStorageBlocks = 0; - glGetProgramInterfaceiv( GLProgram, GL_SHADER_STORAGE_BLOCK, GL_ACTIVE_RESOURCES, &numActiveShaderStorageBlocks ); - CHECK_GL_ERROR_AND_THROW( "Unable to get the number of shader storage blocks blocks\n" ); - - // Query the maximum name length of the active shader storage block (including null terminator) - GLint MaxShaderStorageBlockNameLen = 0; - glGetProgramInterfaceiv( GLProgram, GL_SHADER_STORAGE_BLOCK, GL_MAX_NAME_LENGTH, &MaxShaderStorageBlockNameLen ); - CHECK_GL_ERROR_AND_THROW( "Unable to get the maximum shader storage block name length\n" ); auto MaxNameLength = std::max( activeUniformMaxLength, activeUniformBlockMaxLength ); - MaxNameLength = std::max( MaxNameLength, MaxShaderStorageBlockNameLen ); + + GLint numActiveShaderStorageBlocks = 0; + if(glGetProgramInterfaceiv) + { + glGetProgramInterfaceiv( GLProgram, GL_SHADER_STORAGE_BLOCK, GL_ACTIVE_RESOURCES, &numActiveShaderStorageBlocks ); + CHECK_GL_ERROR_AND_THROW( "Unable to get the number of shader storage blocks blocks\n" ); + + // Query the maximum name length of the active shader storage block (including null terminator) + GLint MaxShaderStorageBlockNameLen = 0; + glGetProgramInterfaceiv( GLProgram, GL_SHADER_STORAGE_BLOCK, GL_MAX_NAME_LENGTH, &MaxShaderStorageBlockNameLen ); + CHECK_GL_ERROR_AND_THROW( "Unable to get the maximum shader storage block name length\n" ); + MaxNameLength = std::max( MaxNameLength, MaxShaderStorageBlockNameLen ); + } MaxNameLength = std::max( MaxNameLength, 512 ); std::vector Name( MaxNameLength + 1 ); diff --git a/Graphics/GraphicsEngineOpenGL/src/TexRegionRender.cpp b/Graphics/GraphicsEngineOpenGL/src/TexRegionRender.cpp index 0248a74d..6a842a45 100644 --- a/Graphics/GraphicsEngineOpenGL/src/TexRegionRender.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/TexRegionRender.cpp @@ -47,13 +47,11 @@ namespace Diligent "void main() \n" "{ \n" " vec4 Bounds = vec4(-1.0, -1.0, 1.0, 1.0); \n" - " vec2 PosXY[4] = \n" - " { \n" - " Bounds.xy, \n" - " Bounds.xw, \n" - " Bounds.zy, \n" - " Bounds.zw \n" - " }; \n" + " vec2 PosXY[4]; \n" + " PosXY[0] = Bounds.xy; \n" + " PosXY[1] = Bounds.xw; \n" + " PosXY[2] = Bounds.zy; \n" + " PosXY[3] = Bounds.zw; \n" " gl_Position = vec4(PosXY[gl_VertexID], 0.0, 1.0);\n" "} \n" }; @@ -174,7 +172,8 @@ namespace Diligent pCtxGL->SetViewports( (Uint32)m_OrigViewports.size(), m_OrigViewports.data(), 0, 0 ); - pCtxGL->SetPipelineState( m_pOrigPSO ); + if(m_pOrigPSO) + pCtxGL->SetPipelineState( m_pOrigPSO ); m_pOrigPSO.Release(); pCtxGL->SetStencilRef(m_OrigStencilRef); pCtxGL->SetBlendFactors(m_OrigBlendFactors); -- cgit v1.2.3