From f7326f6aaa2e3194937bf361e0ba10e7b2ea9e94 Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 11 May 2020 11:39:52 -0700 Subject: Added EngineGLCreateInfo::CreateDebugContext member (API Version 240060) --- .../include/GLContextAndroid.hpp | 7 ++-- .../GraphicsEngineOpenGL/include/GLStubsAndroid.h | 4 +++ .../GraphicsEngineOpenGL/src/GLContextAndroid.cpp | 39 ++++++++++++++++++---- .../GraphicsEngineOpenGL/src/GLContextLinux.cpp | 5 ++- .../GraphicsEngineOpenGL/src/GLContextWindows.cpp | 10 +++--- 5 files changed, 49 insertions(+), 16 deletions(-) (limited to 'Graphics/GraphicsEngineOpenGL') diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.hpp b/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.hpp index ed4e94b2..f8a573a2 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.hpp +++ b/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.hpp @@ -61,6 +61,11 @@ private: EGLContext context_ = EGL_NO_CONTEXT; EGLConfig config_; + const bool create_debug_context_; + + EGLint egl_major_version_ = 0; + EGLint egl_minor_version_ = 0; + //Screen parameters int32_t color_size_ = 0; int32_t depth_size_ = 0; @@ -77,8 +82,6 @@ private: bool egl_context_initialized_ = false; bool context_valid_ = false; - SwapChainDesc SwapChainAttribs_; - void InitGLES(); void Terminate(); bool InitEGLSurface(); diff --git a/Graphics/GraphicsEngineOpenGL/include/GLStubsAndroid.h b/Graphics/GraphicsEngineOpenGL/include/GLStubsAndroid.h index 7cd6f0e2..faa28354 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLStubsAndroid.h +++ b/Graphics/GraphicsEngineOpenGL/include/GLStubsAndroid.h @@ -924,6 +924,10 @@ extern PFNGLMEMORYBARRIERPROC glMemoryBarrier; /* ------------------------------ GL_KHR_debug ----------------------------- */ +#ifndef GL_DEBUG_OUTPUT +# define GL_DEBUG_OUTPUT 0x92E0 +#endif + #ifndef GL_DEBUG_OUTPUT_SYNCHRONOUS # define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242 #endif diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp index b7f2e0b2..27b46cce 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp @@ -23,6 +23,7 @@ #include "pch.h" #include +#include #include "GLContextAndroid.hpp" @@ -101,11 +102,12 @@ bool GLContext::InitEGLSurface() LOG_ERROR_AND_THROW("No EGL display found"); } - auto success = eglInitialize(display_, 0, 0); + auto success = eglInitialize(display_, &egl_major_version_, &egl_minor_version_); if (!success) { LOG_ERROR_AND_THROW("Failed to initialise EGL"); } + LOG_INFO_MESSAGE("Initialized EGL ", egl_major_version_, '.', egl_minor_version_); /* * Here specify the attributes of the desired configuration. @@ -198,13 +200,34 @@ bool GLContext::InitEGLContext() major_version_ = version.first; minor_version_ = version.second; - const EGLint context_attribs[] = + // clang-format off + std::vector context_attribs = + { + EGL_CONTEXT_MAJOR_VERSION, major_version_, + EGL_CONTEXT_MINOR_VERSION, minor_version_ + }; + // clang-format on + +#if 0 + // No matter what I do, eglCreateContext fails when EGL_CONTEXT_OPENGL_DEBUG attribute + // is present, even when it is EGL 1.5. + if (create_debug_context_) + { + // EGL_CONTEXT_OPENGL_DEBUG is only valid as of EGL 1.5. + if (egl_major_version_ >= 2 || (egl_major_version_ == 1 && egl_minor_version_ >= 5)) { - EGL_CONTEXT_CLIENT_VERSION, major_version_, - EGL_CONTEXT_MINOR_VERSION_KHR, minor_version_, - EGL_NONE}; + context_attribs.push_back(EGL_CONTEXT_OPENGL_DEBUG); + context_attribs.push_back(EGL_TRUE); + } + else + { + LOG_WARNING_MESSAGE("EGL_CONTEXT_OPENGL_DEBUG is only available in EGL 1.5+"); + } + } +#endif + context_attribs.push_back(EGL_NONE); - context_ = eglCreateContext(display_, config_, NULL, context_attribs); + context_ = eglCreateContext(display_, config_, NULL, context_attribs.data()); } if (context_ == EGL_NO_CONTEXT) @@ -282,8 +305,9 @@ bool GLContext::Init(ANativeWindow* window) } InitGLES(); - if (glDebugMessageCallback) + if (create_debug_context_ && glDebugMessageCallback != nullptr) { + glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); glDebugMessageCallback(openglCallbackFunction, nullptr); if (glGetError() != GL_NO_ERROR) @@ -299,6 +323,7 @@ GLContext::GLContext(const EngineGLCreateInfo& InitAttribs, DeviceCaps& deviceCa display_(EGL_NO_DISPLAY), surface_(EGL_NO_SURFACE), context_(EGL_NO_CONTEXT), + create_debug_context_(InitAttribs.CreateDebugContext), egl_context_initialized_(false), gles_initialized_(false), major_version_(0), diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextLinux.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextLinux.cpp index cf77409e..6901dde0 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLContextLinux.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLContextLinux.cpp @@ -103,10 +103,9 @@ GLContext::GLContext(const EngineGLCreateInfo& InitAttribs, DeviceCaps& deviceCa if (InitAttribs.Window.WindowId != 0 && InitAttribs.Window.pDisplay != nullptr) { - //glXSwapIntervalEXT(0); - - if (glDebugMessageCallback) + if (InitAttribs.CreateDebugContext && glDebugMessageCallback != nullptr) { + glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); glDebugMessageCallback(openglCallbackFunction, nullptr); GLuint unusedIds = 0; diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp index a61df72e..4d4b2916 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp @@ -207,9 +207,10 @@ GLContext::GLContext(const EngineGLCreateInfo& InitAttribs, DeviceCaps& deviceCa 0, 0 // }; -#ifdef DILIGENT_DEBUG - attribs[5] |= WGL_CONTEXT_DEBUG_BIT_ARB; -#endif + if (InitAttribs.CreateDebugContext) + { + attribs[5] |= WGL_CONTEXT_DEBUG_BIT_ARB; + } // Create new rendering context // In order to create new OpenGL rendering context we have to call function wglCreateContextAttribsARB(), @@ -236,8 +237,9 @@ GLContext::GLContext(const EngineGLCreateInfo& InitAttribs, DeviceCaps& deviceCa m_Context = tempContext; } - if (glDebugMessageCallback) + if (InitAttribs.CreateDebugContext && glDebugMessageCallback != nullptr) { + glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); glDebugMessageCallback(openglCallbackFunction, nullptr); GLuint unusedIds = 0; -- cgit v1.2.3