From 55bfdc105b5fbdf2e2e8c5b6e968c1f443607161 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sun, 14 Jan 2018 10:22:18 -0800 Subject: [PATCH] Switch android to GLAD --- android/build.gradle | 5 ++ cmake/macros/TargetGlad.cmake | 47 +++++++++++-------- cmake/macros/TargetOpenGL.cmake | 11 +---- interface/src/ui/ResourceImageItem.cpp | 15 ++---- interface/src/ui/ResourceImageItem.h | 2 + libraries/gl/src/gl/Config.cpp | 13 ++++- libraries/gl/src/gl/Config.h | 7 +-- libraries/gl/src/gl/ContextQt.cpp | 6 ++- libraries/gl/src/gl/GLHelpers.cpp | 4 +- libraries/gl/src/gl/GLWindow.cpp | 1 + libraries/gl/src/gl/OffscreenGLCanvas.cpp | 2 + .../gpu-gles/src/gpu/gl/GLBackendOutput.cpp | 1 - .../gpu-gles/src/gpu/gl/GLTexelFormat.cpp | 4 +- 13 files changed, 67 insertions(+), 51 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index a5cb8b7614..9559b586b7 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -97,6 +97,11 @@ def packages = [ versionId: 'cA3tVJSmkvb1naA3l6D_Jv2Noh.4yc4m', checksum: '617a80d213a5ec69fbfa21a1f2f738cd', ], + glad: [ + file: 'glad_armv8-libcpp.zip', + versionId: 'Q9szthzeye8fFyAA.cY26Lgn2B8kezEE', + checksum: 'a8ee8584cf1ccd34766c7ddd9d5e5449', + ], glm: [ file: 'glm-0.9.8.tgz', versionId: 'BlkJNwaYV2Gfy5XwMeU7K0uzPDRKFMt2', diff --git a/cmake/macros/TargetGlad.cmake b/cmake/macros/TargetGlad.cmake index fd64524fe9..59cb14a31b 100644 --- a/cmake/macros/TargetGlad.cmake +++ b/cmake/macros/TargetGlad.cmake @@ -6,29 +6,38 @@ # See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html # macro(TARGET_GLAD) - - if (APPLE) - set(GLAD_VER "41") + if (ANDROID) + set(INSTALL_DIR ${HIFI_ANDROID_PRECOMPILED}/glad) + set(GLAD_INCLUDE_DIRS "${INSTALL_DIR}/include") + set(GLAD_LIBRARY_DEBUG ${INSTALL_DIR}/lib/libglad_d.a) + set(GLAD_LIBRARY_RELEASE ${INSTALL_DIR}/lib/libglad.a) + select_library_configurations(GLAD) + find_library(EGL EGL) + target_link_libraries(${TARGET_NAME} ${EGL}) else() - if (USE_GLES) - set(GLAD_VER "32es") + if (APPLE) + set(GLAD_VER "41") else() - set(GLAD_VER "45") - add_dependency_external_projects(glad45) - endif() - if (WIN32) - find_package(OpenGL REQUIRED) - target_link_libraries(${TARGET_NAME} "${OPENGL_LIBRARY}") - # we don't need the include, because we get everything from GLAD - #target_include_directories(${TARGET_NAME} PUBLIC ${OPENGL_INCLUDE_DIR}) + if (USE_GLES) + set(GLAD_VER "32es") + else() + set(GLAD_VER "45") + add_dependency_external_projects(glad45) + endif() + if (WIN32) + find_package(OpenGL REQUIRED) + target_link_libraries(${TARGET_NAME} "${OPENGL_LIBRARY}") + # we don't need the include, because we get everything from GLAD + #target_include_directories(${TARGET_NAME} PUBLIC ${OPENGL_INCLUDE_DIR}) + endif() endif() + set(GLAD "glad${GLAD_VER}") + string(TOUPPER ${GLAD} GLAD_UPPER) + add_dependency_external_projects(${GLAD}) + set(GLAD_INCLUDE_DIRS ${${GLAD_UPPER}_INCLUDE_DIRS}) + set(GLAD_LIBRARY ${${GLAD_UPPER}_LIBRARY}) endif() - set(GLAD "glad${GLAD_VER}") - string(TOUPPER ${GLAD} GLAD_UPPER) - add_dependency_external_projects(${GLAD}) - set(GLAD_INCLUDE_DIRS ${${GLAD_UPPER}_INCLUDE_DIRS}) - set(GLAD_LIBRARY ${${GLAD_UPPER}_LIBRARY}) - + target_include_directories(${TARGET_NAME} PUBLIC ${GLAD_INCLUDE_DIRS}) target_link_libraries(${TARGET_NAME} ${GLAD_LIBRARY}) endmacro() diff --git a/cmake/macros/TargetOpenGL.cmake b/cmake/macros/TargetOpenGL.cmake index a14b41db52..84fe5a7a5a 100644 --- a/cmake/macros/TargetOpenGL.cmake +++ b/cmake/macros/TargetOpenGL.cmake @@ -6,13 +6,6 @@ # See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html # macro(TARGET_OPENGL) - if (ANDROID) - find_library(EGL EGL) - find_library(OpenGLES3 GLESv3) - list(APPEND IGNORE_COPY_LIBS ${OpenGLES3} ${OpenGLES2} ${EGL}) - target_link_libraries(${TARGET_NAME} ${OpenGLES3} ${EGL}) - else() - target_glad() - target_nsight() - endif() + target_glad() + target_nsight() endmacro() diff --git a/interface/src/ui/ResourceImageItem.cpp b/interface/src/ui/ResourceImageItem.cpp index 7447e9f88b..f14f4ca78e 100644 --- a/interface/src/ui/ResourceImageItem.cpp +++ b/interface/src/ui/ResourceImageItem.cpp @@ -10,15 +10,12 @@ #include "ResourceImageItem.h" +#include + #include -#include -#include -#include #include -#ifdef Q_OS_ANDROID -#include -#endif + ResourceImageItem::ResourceImageItem() : QQuickFramebufferObject() { auto textureCache = DependencyManager::get(); connect(textureCache.data(), SIGNAL(spectatorCameraFramebufferReset()), this, SLOT(update())); @@ -91,11 +88,9 @@ QOpenGLFramebufferObject* ResourceImageItemRenderer::createFramebufferObject(con } void ResourceImageItemRenderer::render() { - auto f = QOpenGLContext::currentContext()->extraFunctions(); - if (_fenceSync) { - f->glWaitSync(_fenceSync, 0, GL_TIMEOUT_IGNORED); - f->glDeleteSync(_fenceSync); + glWaitSync(_fenceSync, 0, GL_TIMEOUT_IGNORED); + glDeleteSync(_fenceSync); _fenceSync = 0; } if (_ready) { diff --git a/interface/src/ui/ResourceImageItem.h b/interface/src/ui/ResourceImageItem.h index 985ab5a66e..d154588094 100644 --- a/interface/src/ui/ResourceImageItem.h +++ b/interface/src/ui/ResourceImageItem.h @@ -14,6 +14,8 @@ #include "Application.h" +#include + #include #include #include diff --git a/libraries/gl/src/gl/Config.cpp b/libraries/gl/src/gl/Config.cpp index a34190a83b..6b486539cf 100644 --- a/libraries/gl/src/gl/Config.cpp +++ b/libraries/gl/src/gl/Config.cpp @@ -44,8 +44,18 @@ PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT; PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT; PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB; PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB; + +#elif defined(Q_OS_ANDROID) + +static void* getGlProcessAddress(const char *namez) { + auto result = eglGetProcAddress(namez); + return (void*)result; +} + #endif + + void gl::initModuleGl() { static std::once_flag once; std::call_once(once, [] { @@ -54,11 +64,12 @@ void gl::initModuleGl() { wglGetSwapIntervalEXT = (PFNWGLGETSWAPINTERVALEXTPROC)getGlProcessAddress("wglGetSwapIntervalEXT"); wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)getGlProcessAddress("wglChoosePixelFormatARB"); wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)getGlProcessAddress("wglCreateContextAttribsARB"); +#endif + #if defined(USE_GLES) gladLoadGLES2Loader(getGlProcessAddress); #else gladLoadGLLoader(getGlProcessAddress); -#endif #endif }); } diff --git a/libraries/gl/src/gl/Config.h b/libraries/gl/src/gl/Config.h index ce50d3c226..0d296ea7e5 100644 --- a/libraries/gl/src/gl/Config.h +++ b/libraries/gl/src/gl/Config.h @@ -32,12 +32,7 @@ #if defined(Q_OS_ANDROID) #include -#include -#define GL_DEPTH_COMPONENT32_OES 0x81A7 -#define GL_FRAMEBUFFER_SRGB_EXT 0x8DB9 -#define GL_R16_EXT 0x822A -#define GL_R16_SNORM_EXT 0x8F98 -#define GL_SLUMINANCE8_EXT 0x8C47 +#include #else #include #ifndef GL_SLUMINANCE8_EXT diff --git a/libraries/gl/src/gl/ContextQt.cpp b/libraries/gl/src/gl/ContextQt.cpp index cf07f5ccd5..dd65c3076c 100644 --- a/libraries/gl/src/gl/ContextQt.cpp +++ b/libraries/gl/src/gl/ContextQt.cpp @@ -8,6 +8,8 @@ #include "Context.h" +#include "Config.h" + #include #include @@ -48,7 +50,9 @@ void Context::moveToThread(QThread* thread) { #ifndef GL_CUSTOM_CONTEXT bool Context::makeCurrent() { updateSwapchainMemoryCounter(); - return _context->makeCurrent(_window); + bool result = _context->makeCurrent(_window); + gl::initModuleGl(); + return result; } void Context::swapBuffers() { diff --git a/libraries/gl/src/gl/GLHelpers.cpp b/libraries/gl/src/gl/GLHelpers.cpp index 8413942301..d5e3bb5a67 100644 --- a/libraries/gl/src/gl/GLHelpers.cpp +++ b/libraries/gl/src/gl/GLHelpers.cpp @@ -2,6 +2,8 @@ #include +#include "Config.h" + #include #include #include @@ -11,8 +13,6 @@ #include #include -#include - size_t evalGLFormatSwapchainPixelSize(const QSurfaceFormat& format) { size_t pixelSize = format.redBufferSize() + format.greenBufferSize() + format.blueBufferSize() + format.alphaBufferSize(); // We don't apply the length of the swap chain into this pixelSize since it is not vsible for the Process (on windows). diff --git a/libraries/gl/src/gl/GLWindow.cpp b/libraries/gl/src/gl/GLWindow.cpp index 1894aeb8d8..360c49a5f2 100644 --- a/libraries/gl/src/gl/GLWindow.cpp +++ b/libraries/gl/src/gl/GLWindow.cpp @@ -8,6 +8,7 @@ #include "GLWindow.h" +#include "Config.h" #include #include diff --git a/libraries/gl/src/gl/OffscreenGLCanvas.cpp b/libraries/gl/src/gl/OffscreenGLCanvas.cpp index 67eb3520c9..8a476c45ad 100644 --- a/libraries/gl/src/gl/OffscreenGLCanvas.cpp +++ b/libraries/gl/src/gl/OffscreenGLCanvas.cpp @@ -12,6 +12,8 @@ #include "OffscreenGLCanvas.h" +#include "Config.h" + #include #include #include diff --git a/libraries/gpu-gles/src/gpu/gl/GLBackendOutput.cpp b/libraries/gpu-gles/src/gpu/gl/GLBackendOutput.cpp index 1552aff563..45c0de8ed7 100644 --- a/libraries/gpu-gles/src/gpu/gl/GLBackendOutput.cpp +++ b/libraries/gpu-gles/src/gpu/gl/GLBackendOutput.cpp @@ -147,7 +147,6 @@ void GLBackend::do_clearFramebuffer(const Batch& batch, size_t paramOffset) { (void) CHECK_GL_ERROR(); } -#pragma optimize( "", on ) void GLBackend::downloadFramebuffer(const FramebufferPointer& srcFramebuffer, const Vec4i& region, QImage& destImage) { auto readFBO = getFramebufferID(srcFramebuffer); if (srcFramebuffer && readFBO) { diff --git a/libraries/gpu-gles/src/gpu/gl/GLTexelFormat.cpp b/libraries/gpu-gles/src/gpu/gl/GLTexelFormat.cpp index 1d58b845d5..2a39901ee7 100644 --- a/libraries/gpu-gles/src/gpu/gl/GLTexelFormat.cpp +++ b/libraries/gpu-gles/src/gpu/gl/GLTexelFormat.cpp @@ -106,7 +106,7 @@ GLenum GLTexelFormat::evalGLTexelFormatInternal(const gpu::Element& dstFormat) { break; case gpu::NUINT8: if ((dstFormat.getSemantic() == gpu::SRGB || dstFormat.getSemantic() == gpu::SRGBA)) { - result = GL_SLUMINANCE8_EXT; + result = GL_SLUMINANCE8_NV; } else { result = GL_R8; } @@ -445,7 +445,7 @@ GLTexelFormat GLTexelFormat::evalGLTexelFormat(const Element& dstFormat, const E } case gpu::NUINT8: { if ((dstFormat.getSemantic() == gpu::SRGB || dstFormat.getSemantic() == gpu::SRGBA)) { - texel.internalFormat = GL_SLUMINANCE8_EXT; + texel.internalFormat = GL_SLUMINANCE8_NV; } else { texel.internalFormat = GL_R8; }