diff --git a/.github/workflows/linux-check.yaml b/.github/workflows/linux-check.yaml index 17adeecbd2..bce6b20487 100644 --- a/.github/workflows/linux-check.yaml +++ b/.github/workflows/linux-check.yaml @@ -61,6 +61,10 @@ jobs: libgl1-mesa-dev \ libglvnd-dev \ libharfbuzz-dev \ + libxrandr-dev \ + libxinerama-dev \ + libxcursor-dev \ + libxi-dev \ qt6-base-dev \ libqt6svg6-dev \ qt6-positioning-dev \ @@ -128,6 +132,10 @@ jobs: libgl1-mesa-dev \ libglvnd-dev \ libharfbuzz-dev \ + libxrandr-dev \ + libxinerama-dev \ + libxcursor-dev \ + libxi-dev \ qt6-base-dev \ libqt6svg6-dev \ qt6-positioning-dev \ diff --git a/.gitmodules b/.gitmodules index 7d35fe8264..b059cf9425 100644 --- a/.gitmodules +++ b/.gitmodules @@ -59,3 +59,12 @@ [submodule "3party/utfcpp"] path = 3party/utfcpp url = https://github.com/nemtrif/utfcpp.git +[submodule "3party/glfw"] + path = 3party/glfw + url = https://github.com/glfw/glfw.git +[submodule "3party/CMake-MetalShaderSupport"] + path = 3party/CMake-MetalShaderSupport + url = https://github.com/dpogue/CMake-MetalShaderSupport.git +[submodule "3party/imgui/imgui"] + path = 3party/imgui/imgui + url = https://github.com/ocornut/imgui diff --git a/3party/CMake-MetalShaderSupport b/3party/CMake-MetalShaderSupport new file mode 160000 index 0000000000..989857d2e5 --- /dev/null +++ b/3party/CMake-MetalShaderSupport @@ -0,0 +1 @@ +Subproject commit 989857d2e5e54869c35ad06fb21a67d12a2dbc67 diff --git a/3party/CMakeLists.txt b/3party/CMakeLists.txt index 57d0592dc3..d5635d56fb 100644 --- a/3party/CMakeLists.txt +++ b/3party/CMakeLists.txt @@ -66,4 +66,19 @@ add_subdirectory(vulkan_wrapper) if (PLATFORM_DESKTOP) add_subdirectory(libtess2) + + set(GLFW_BUILD_DOCS OFF CACHE BOOL "") + set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "") + set(GLFW_BUILD_TESTS OFF CACHE BOOL "") + set(GLFW_INSTALL OFF CACHE BOOL "") + set(GLFW_VULKAN_STATIC OFF CACHE BOOL "") + set(GLFW_BUILD_WAYLAND OFF CACHE BOOL "") + # Disable ARC for glfw and re-enable after it because it's globally set in the root CMakeLists.txt + set(CMAKE_OBJC_FLAGS "") + add_subdirectory(glfw) + set_target_properties(glfw PROPERTIES UNITY_BUILD OFF) + set_target_properties(glfw PROPERTIES XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC NO) + set(CMAKE_OBJC_FLAGS -fobjc-arc) + + add_subdirectory(imgui) endif() diff --git a/3party/glfw b/3party/glfw new file mode 160000 index 0000000000..21fea01161 --- /dev/null +++ b/3party/glfw @@ -0,0 +1 @@ +Subproject commit 21fea01161e0d6b70c0c5c1f52dc8e7a7df14a50 diff --git a/3party/imgui/CMakeLists.txt b/3party/imgui/CMakeLists.txt new file mode 100644 index 0000000000..ebbdde8c48 --- /dev/null +++ b/3party/imgui/CMakeLists.txt @@ -0,0 +1,16 @@ +project(imgui) + +set(SRC + imgui/imgui_draw.cpp + imgui/imgui_tables.cpp + imgui/imgui_widgets.cpp + imgui/imgui.cpp + imgui/backends/imgui_impl_glfw.cpp +) + +add_library(${PROJECT_NAME} ${SRC}) +target_include_directories(${PROJECT_NAME} + PRIVATE ${OMIM_ROOT}/3party/glfw/include + PUBLIC ${OMIM_ROOT}/3party/imgui/imgui + PUBLIC . +) diff --git a/3party/imgui/imgui b/3party/imgui/imgui new file mode 160000 index 0000000000..6982ce43f5 --- /dev/null +++ b/3party/imgui/imgui @@ -0,0 +1 @@ +Subproject commit 6982ce43f5b143c5dce5fab0ce07dd4867b705ae diff --git a/CMakeLists.txt b/CMakeLists.txt index 30c1a0e496..c62396a763 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,19 @@ else() message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}") endif() +if(${PLATFORM_MAC}) + set(XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES) + + # Metal language support + list(APPEND CMAKE_MODULE_PATH ${OMIM_ROOT}/3party/CMake-MetalShaderSupport/cmake) + include(CheckLanguage) + include(MetalShaderSupport) + check_language(Metal) + if(CMAKE_Metal_COMPILER) + enable_language(Metal) + endif() +endif() + # Sanitizer if (PLATFORM_DESKTOP) # https://clang.llvm.org/docs/UsersManual.html#controlling-code-generation @@ -394,6 +407,7 @@ if (PLATFORM_DESKTOP) add_subdirectory(qt) omim_add_tool_subdirectory(skin_generator) endif() + add_subdirectory(dev_sandbox) endif() omim_add_test_subdirectory(qt_tstfrm) diff --git a/android/app/src/main/cpp/app/organicmaps/Framework.cpp b/android/app/src/main/cpp/app/organicmaps/Framework.cpp index 905a6b36fe..223aaa3b45 100644 --- a/android/app/src/main/cpp/app/organicmaps/Framework.cpp +++ b/android/app/src/main/cpp/app/organicmaps/Framework.cpp @@ -224,8 +224,7 @@ bool Framework::CreateDrapeEngine(JNIEnv * env, jobject jSurface, int densityDpi LOG(LWARNING, ("Invalid GL context.")); return false; } - p.m_apiVersion = oglFactory->IsSupportedOpenGLES3() ? dp::ApiVersion::OpenGLES3 : - dp::ApiVersion::OpenGLES2; + p.m_apiVersion = dp::ApiVersion::OpenGLES3; p.m_surfaceWidth = oglFactory->GetWidth(); p.m_surfaceHeight = oglFactory->GetHeight(); diff --git a/android/app/src/main/cpp/app/organicmaps/opengl/androidoglcontext.cpp b/android/app/src/main/cpp/app/organicmaps/opengl/androidoglcontext.cpp index 0c73761217..bfe5b38410 100644 --- a/android/app/src/main/cpp/app/organicmaps/opengl/androidoglcontext.cpp +++ b/android/app/src/main/cpp/app/organicmaps/opengl/androidoglcontext.cpp @@ -8,20 +8,16 @@ namespace android { -static EGLint * getContextAttributesList(bool supportedES3) +static EGLint * getContextAttributesList() { static EGLint contextAttrList[] = { - EGL_CONTEXT_CLIENT_VERSION, 2, - EGL_NONE - }; - static EGLint contextAttrListES3[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE }; - return supportedES3 ? contextAttrListES3 : contextAttrList; + return contextAttrList; } -AndroidOGLContext::AndroidOGLContext(bool supportedES3, EGLDisplay display, EGLSurface surface, +AndroidOGLContext::AndroidOGLContext(EGLDisplay display, EGLSurface surface, EGLConfig config, AndroidOGLContext * contextToShareWith) : m_nativeContext(EGL_NO_CONTEXT) , m_surface(surface) @@ -32,7 +28,7 @@ AndroidOGLContext::AndroidOGLContext(bool supportedES3, EGLDisplay display, EGLS ASSERT(m_display != EGL_NO_DISPLAY, ()); EGLContext sharedContext = (contextToShareWith == NULL) ? EGL_NO_CONTEXT : contextToShareWith->m_nativeContext; - m_nativeContext = eglCreateContext(m_display, config, sharedContext, getContextAttributesList(supportedES3)); + m_nativeContext = eglCreateContext(m_display, config, sharedContext, getContextAttributesList()); CHECK(m_nativeContext != EGL_NO_CONTEXT, ()); } diff --git a/android/app/src/main/cpp/app/organicmaps/opengl/androidoglcontext.hpp b/android/app/src/main/cpp/app/organicmaps/opengl/androidoglcontext.hpp index 385d801548..6f7885b644 100644 --- a/android/app/src/main/cpp/app/organicmaps/opengl/androidoglcontext.hpp +++ b/android/app/src/main/cpp/app/organicmaps/opengl/androidoglcontext.hpp @@ -10,7 +10,7 @@ namespace android class AndroidOGLContext : public dp::OGLContext { public: - AndroidOGLContext(bool supportedES3, EGLDisplay display, EGLSurface surface, + AndroidOGLContext(EGLDisplay display, EGLSurface surface, EGLConfig config, AndroidOGLContext * contextToShareWith); ~AndroidOGLContext(); diff --git a/android/app/src/main/cpp/app/organicmaps/opengl/androidoglcontextfactory.cpp b/android/app/src/main/cpp/app/organicmaps/opengl/androidoglcontextfactory.cpp index 00f576dbe9..88b0c93911 100644 --- a/android/app/src/main/cpp/app/organicmaps/opengl/androidoglcontextfactory.cpp +++ b/android/app/src/main/cpp/app/organicmaps/opengl/androidoglcontextfactory.cpp @@ -16,26 +16,13 @@ #define EGL_OPENGL_ES3_BIT 0x00000040 -int constexpr kMinSdkVersionForES3 = 21; - namespace android { namespace { -static EGLint * getConfigAttributesListRGB8(bool supportedES3) +static EGLint * getConfigAttributesListRGB8() { static EGLint attr_list[] = { - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_ALPHA_SIZE, 0, - EGL_STENCIL_SIZE, 0, - EGL_DEPTH_SIZE, 16, - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, - EGL_SURFACE_TYPE, EGL_PBUFFER_BIT | EGL_WINDOW_BIT, - EGL_NONE - }; - static EGLint attr_list_es3[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, @@ -46,33 +33,16 @@ static EGLint * getConfigAttributesListRGB8(bool supportedES3) EGL_SURFACE_TYPE, EGL_PBUFFER_BIT | EGL_WINDOW_BIT, EGL_NONE }; - return supportedES3 ? attr_list_es3 : attr_list; + return attr_list; } int const kMaxConfigCount = 40; -static EGLint * getConfigAttributesListR5G6B5() -{ - // We do not support OpenGL ES3 for R5G6B5, because some Android devices - // are not able to create OpenGL context in such mode. - static EGLint attr_list[] = { - EGL_RED_SIZE, 5, - EGL_GREEN_SIZE, 6, - EGL_BLUE_SIZE, 5, - EGL_STENCIL_SIZE, 0, - EGL_DEPTH_SIZE, 16, - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, - EGL_SURFACE_TYPE, EGL_PBUFFER_BIT | EGL_WINDOW_BIT, - EGL_NONE - }; - return attr_list; -} - -bool IsSupportedRGB8(EGLDisplay display, bool es3) +bool IsSupportedRGB8(EGLDisplay display) { EGLConfig configs[kMaxConfigCount]; int count = 0; - return eglChooseConfig(display, getConfigAttributesListRGB8(es3), configs, + return eglChooseConfig(display, getConfigAttributesListRGB8(), configs, kMaxConfigCount, &count) == EGL_TRUE && count != 0; } @@ -90,7 +60,6 @@ AndroidOGLContextFactory::AndroidOGLContextFactory(JNIEnv * env, jobject jsurfac , m_surfaceWidth(0) , m_surfaceHeight(0) , m_windowSurfaceValid(false) - , m_supportedES3(false) { m_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (m_display == EGL_NO_DISPLAY) @@ -106,10 +75,7 @@ AndroidOGLContextFactory::AndroidOGLContextFactory(JNIEnv * env, jobject jsurfac return; } - // Check ES3 availability. - bool const isES3Supported = IsSupportedRGB8(m_display, true /* es3 */) && - android_get_device_api_level() >= kMinSdkVersionForES3; - m_supportedES3 = isES3Supported && gl3stubInit(); + CHECK(gl3stubInit(), ("Could not initialize OpenGL ES3")); SetSurface(env, jsurface); @@ -266,7 +232,7 @@ dp::GraphicsContext * AndroidOGLContextFactory::GetDrawContext() ASSERT(m_windowSurface != EGL_NO_SURFACE, ()); if (m_drawContext == nullptr) { - m_drawContext = new AndroidOGLContext(m_supportedES3, m_display, m_windowSurface, + m_drawContext = new AndroidOGLContext(m_display, m_windowSurface, m_config, m_uploadContext); } return m_drawContext; @@ -278,7 +244,7 @@ dp::GraphicsContext * AndroidOGLContextFactory::GetResourcesUploadContext() ASSERT(m_pixelbufferSurface != EGL_NO_SURFACE, ()); if (m_uploadContext == nullptr) { - m_uploadContext = new AndroidOGLContext(m_supportedES3, m_display, m_pixelbufferSurface, + m_uploadContext = new AndroidOGLContext(m_display, m_pixelbufferSurface, m_config, m_drawContext); } return m_uploadContext; @@ -322,17 +288,15 @@ bool AndroidOGLContextFactory::CreateWindowSurface() { EGLConfig configs[kMaxConfigCount]; int count = 0; - if (eglChooseConfig(m_display, getConfigAttributesListRGB8(m_supportedES3), configs, - kMaxConfigCount, &count) != EGL_TRUE) + if (eglChooseConfig(m_display, getConfigAttributesListRGB8(), configs, + kMaxConfigCount, &count) == EGL_TRUE) { - ASSERT(!m_supportedES3, ()); - VERIFY(eglChooseConfig(m_display, getConfigAttributesListR5G6B5(), configs, - kMaxConfigCount, &count) == EGL_TRUE, ()); - LOG(LDEBUG, ("Backbuffer format: R5G6B5")); + CHECK(IsSupportedRGB8(m_display), ("RGB8 is not suported on this device")); + LOG(LDEBUG, ("Backbuffer format: RGB8")); } else { - LOG(LDEBUG, ("Backbuffer format: RGB8")); + CHECK(false, ("OpenGL ES3 is not supported")); } ASSERT(count > 0, ("Didn't find any configs.")); diff --git a/android/app/src/main/cpp/app/organicmaps/opengl/androidoglcontextfactory.hpp b/android/app/src/main/cpp/app/organicmaps/opengl/androidoglcontextfactory.hpp index 8f886a9c4e..edbc425550 100644 --- a/android/app/src/main/cpp/app/organicmaps/opengl/androidoglcontextfactory.hpp +++ b/android/app/src/main/cpp/app/organicmaps/opengl/androidoglcontextfactory.hpp @@ -33,8 +33,6 @@ public: int GetHeight() const; void UpdateSurfaceSize(int w, int h); - bool IsSupportedOpenGLES3() const { return m_supportedES3; } - private: bool QuerySurfaceSize(); @@ -56,7 +54,6 @@ private: int m_surfaceHeight; bool m_windowSurfaceValid; - bool m_supportedES3; bool m_isInitialized = false; size_t m_initializationCounter = 0; diff --git a/data/copyright.html b/data/copyright.html index b83b74ae60..c517a2b17c 100644 --- a/data/copyright.html +++ b/data/copyright.html @@ -155,6 +155,12 @@
  • Chromium's Courgette; BSD License
  • +
  • CMake Metal support files
    + © 2024 Darryl Pogue and Contributors;License
  • + +
  • Dear ImGui
    + © 2014-2025 Omar Cornut; MIT License
  • +
  • Expat
    © 1998–2000 Thai Open Source Software Center Ltd and Clark Cooper, © 2001–2019 Expat maintainers; MIT License
  • @@ -164,6 +170,9 @@
  • FreeType
    © 2013 The FreeType Project; FTL
  • +
  • GLFW
    + © 2002-2006 Marcus Geelnard;2006-2019 Camilla Löwy; Zlib License
  • +
  • GLM
    © 2005–2014 G-Truc Creation; MIT License
  • @@ -1058,6 +1067,54 @@ of the copyright holder.

    +
    + +

    CMake Metal support files

    +

    Copyright 2024 Darryl Pogue and Contributors

    +

    All rights reserved.

    + +

    Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    + +

    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

    + +

    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

    + +

    * Neither the name of Kitware, Inc. nor the names of Contributors may be used to endorse or promote products derived from this software without specific prior written permission.

    + +

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

    + +

    ------------------------------------------------------------------------------

    + +

    See version control history for details of individual contributions.

    + +

    The above copyright and license notice applies to distributions of + CMake in source and binary form. Third-party software packages supplied + with CMake under compatible licenses provide their own copyright notices + documented in corresponding subdirectories or source files.

    + +

    ------------------------------------------------------------------------------

    + +

    CMake was initially developed by Kitware with the following sponsorship:

    + +

    * National Library of Medicine at the National Institutes of Health as part of the Insight Segmentation and Registration Toolkit (ITK).

    + +

    * US National Labs (Los Alamos, Livermore, Sandia) ASC Parallel Visualization Initiative.

    + +

    * National Alliance for Medical Image Computing (NAMIC) is funded by the National Institutes of Health through the NIH Roadmap for Medical Research, Grant U54 EB005149.

    + +

    * Kitware, Inc.

    +
    +

    The FreeType Project License

    diff --git a/data/vulkan_shaders/reflection.json b/data/vulkan_shaders/reflection.json index bca74ae8eb..e2784fb8a2 100644 --- a/data/vulkan_shaders/reflection.json +++ b/data/vulkan_shaders/reflection.json @@ -1 +1 @@ -[{"prg":0,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0}],"fs_uni":0},"vs_off":0,"vs_size":3772,"fs_off":3772,"fs_size":2552},{"prg":1,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":6324,"vs_size":3412,"fs_off":9736,"fs_size":1508},{"prg":2,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1},{"name":"u_maskTex","idx":2,"frag":1}]},"vs_off":11244,"vs_size":3560,"fs_off":14804,"fs_size":1756},{"prg":3,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":16560,"vs_size":4468,"fs_off":21028,"fs_size":2508},{"prg":4,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":23536,"vs_size":4468,"fs_off":28004,"fs_size":2508},{"prg":5,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0},{"name":"u_maskTex","idx":2,"frag":1}],"fs_uni":0},"vs_off":30512,"vs_size":4440,"fs_off":34952,"fs_size":2084},{"prg":6,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0},{"name":"u_maskTex","idx":2,"frag":1}],"fs_uni":0},"vs_off":37036,"vs_size":3768,"fs_off":40804,"fs_size":2084},{"prg":7,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0},{"name":"u_maskTex","idx":2,"frag":1}],"fs_uni":0},"vs_off":42888,"vs_size":3104,"fs_off":45992,"fs_size":1992},{"prg":8,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0},{"name":"u_maskTex","idx":2,"frag":1}],"fs_uni":0},"vs_off":47984,"vs_size":3104,"fs_off":51088,"fs_size":1992},{"prg":9,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0}],"fs_uni":0},"vs_off":53080,"vs_size":3352,"fs_off":56432,"fs_size":1336},{"prg":10,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0}],"fs_uni":0},"vs_off":57768,"vs_size":3352,"fs_off":61120,"fs_size":1336},{"prg":11,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":62456,"vs_size":3692,"fs_off":66148,"fs_size":1904},{"prg":12,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0}],"fs_uni":0},"vs_off":68052,"vs_size":2716,"fs_off":70768,"fs_size":1336},{"prg":13,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0}],"fs_uni":0},"vs_off":72104,"vs_size":5084,"fs_off":77188,"fs_size":1332},{"prg":14,"info":{"vs_uni":0,"fs_uni":-1,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":78520,"vs_size":5436,"fs_off":83956,"fs_size":1800},{"prg":15,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1},{"name":"u_maskTex","idx":2,"frag":1}]},"vs_off":85756,"vs_size":5452,"fs_off":91208,"fs_size":1828},{"prg":16,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":93036,"vs_size":3988,"fs_off":97024,"fs_size":1508},{"prg":17,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0}],"fs_uni":0},"vs_off":98532,"vs_size":3352,"fs_off":101884,"fs_size":1336},{"prg":18,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0}],"fs_uni":0},"vs_off":103220,"vs_size":3696,"fs_off":106916,"fs_size":2092},{"prg":19,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0},{"name":"u_maskTex","idx":2,"frag":1}],"fs_uni":0},"vs_off":109008,"vs_size":3516,"fs_off":112524,"fs_size":1716},{"prg":20,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":114240,"vs_size":1820,"fs_off":116060,"fs_size":1416},{"prg":21,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":117476,"vs_size":2064,"fs_off":119540,"fs_size":1416},{"prg":22,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":120956,"vs_size":3640,"fs_off":124596,"fs_size":1540},{"prg":23,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":126136,"vs_size":4140,"fs_off":130276,"fs_size":1540},{"prg":24,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0}],"fs_uni":0},"vs_off":131816,"vs_size":5812,"fs_off":137628,"fs_size":1868},{"prg":25,"info":{"vs_uni":0,"fs_uni":-1,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":139496,"vs_size":4976,"fs_off":144472,"fs_size":832},{"prg":26,"info":{"vs_uni":0,"fs_uni":-1,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":145304,"vs_size":4440,"fs_off":149744,"fs_size":1984},{"prg":27,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":151728,"vs_size":5928,"fs_off":157656,"fs_size":4644},{"prg":28,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":162300,"vs_size":5928,"fs_off":168228,"fs_size":4240},{"prg":29,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":172468,"vs_size":5228,"fs_off":177696,"fs_size":2332},{"prg":30,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":180028,"vs_size":4772,"fs_off":184800,"fs_size":3332},{"prg":31,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":188132,"vs_size":3624,"fs_off":191756,"fs_size":2344},{"prg":32,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":194100,"vs_size":4468,"fs_off":198568,"fs_size":2508},{"prg":33,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":201076,"vs_size":4468,"fs_off":205544,"fs_size":2508},{"prg":34,"info":{"vs_uni":-1,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":208052,"vs_size":1104,"fs_off":209156,"fs_size":992},{"prg":35,"info":{"vs_uni":-1,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":210148,"vs_size":920,"fs_off":211068,"fs_size":1180},{"prg":36,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":212248,"vs_size":2044,"fs_off":214292,"fs_size":1904},{"prg":37,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":216196,"vs_size":2416,"fs_off":218612,"fs_size":1856},{"prg":38,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":220468,"vs_size":1880,"fs_off":222348,"fs_size":1628},{"prg":39,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":223976,"vs_size":1880,"fs_off":225856,"fs_size":1692},{"prg":40,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0}],"fs_uni":0},"vs_off":227548,"vs_size":4280,"fs_off":231828,"fs_size":2552},{"prg":41,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":234380,"vs_size":4056,"fs_off":238436,"fs_size":1508},{"prg":42,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1},{"name":"u_maskTex","idx":2,"frag":1}]},"vs_off":239944,"vs_size":4204,"fs_off":244148,"fs_size":1756},{"prg":43,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":245904,"vs_size":4904,"fs_off":250808,"fs_size":2508},{"prg":44,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":253316,"vs_size":4904,"fs_off":258220,"fs_size":2508},{"prg":45,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":260728,"vs_size":4904,"fs_off":265632,"fs_size":2508},{"prg":46,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":268140,"vs_size":4904,"fs_off":273044,"fs_size":2508},{"prg":47,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0},{"name":"u_maskTex","idx":2,"frag":1}],"fs_uni":0},"vs_off":275552,"vs_size":4928,"fs_off":280480,"fs_size":2084},{"prg":48,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0},{"name":"u_maskTex","idx":2,"frag":1}],"fs_uni":0},"vs_off":282564,"vs_size":4412,"fs_off":286976,"fs_size":2084},{"prg":49,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1},{"name":"u_maskTex","idx":2,"frag":1}]},"vs_off":289060,"vs_size":6368,"fs_off":295428,"fs_size":3820},{"prg":50,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":299248,"vs_size":3492,"fs_off":302740,"fs_size":1616},{"prg":51,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":304356,"vs_size":5984,"fs_off":310340,"fs_size":2428},{"prg":52,"info":{"vs_uni":0,"fs_uni":-1,"tex":[{"name":"u_colorTex","idx":1,"frag":1}]},"vs_off":312768,"vs_size":1924,"fs_off":314692,"fs_size":4236},{"prg":53,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1},{"name":"u_smaaArea","idx":2,"frag":1},{"name":"u_smaaSearch","idx":3,"frag":1}]},"vs_off":318928,"vs_size":2300,"fs_off":321228,"fs_size":12356},{"prg":54,"info":{"vs_uni":0,"fs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1},{"name":"u_blendingWeightTex","idx":2,"frag":1}]},"vs_off":333584,"vs_size":1372,"fs_off":334956,"fs_size":3696}] \ No newline at end of file +[{"prg":0,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0}],"fs_uni":0},"vs_off":0,"vs_size":3920,"fs_off":3920,"fs_size":2712},{"prg":1,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":6632,"vs_size":3560,"fs_off":10192,"fs_size":1636},{"prg":2,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1},{"name":"u_maskTex","idx":2,"frag":1}],"fs_uni":0},"vs_off":11828,"vs_size":3708,"fs_off":15536,"fs_size":1884},{"prg":3,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":17420,"vs_size":4612,"fs_off":22032,"fs_size":2636},{"prg":4,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":24668,"vs_size":4612,"fs_off":29280,"fs_size":2636},{"prg":5,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0},{"name":"u_maskTex","idx":2,"frag":1}],"fs_uni":0},"vs_off":31916,"vs_size":4584,"fs_off":36500,"fs_size":2228},{"prg":6,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0},{"name":"u_maskTex","idx":2,"frag":1}],"fs_uni":0},"vs_off":38728,"vs_size":3916,"fs_off":42644,"fs_size":2228},{"prg":7,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0},{"name":"u_maskTex","idx":2,"frag":1}],"fs_uni":0},"vs_off":44872,"vs_size":3228,"fs_off":48100,"fs_size":2132},{"prg":8,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0},{"name":"u_maskTex","idx":2,"frag":1}],"fs_uni":0},"vs_off":50232,"vs_size":3228,"fs_off":53460,"fs_size":2132},{"prg":9,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0}],"fs_uni":0},"vs_off":55592,"vs_size":3500,"fs_off":59092,"fs_size":1480},{"prg":10,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0}],"fs_uni":0},"vs_off":60572,"vs_size":3500,"fs_off":64072,"fs_size":1480},{"prg":11,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":65552,"vs_size":3832,"fs_off":69384,"fs_size":2032},{"prg":12,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0}],"fs_uni":0},"vs_off":71416,"vs_size":2860,"fs_off":74276,"fs_size":1480},{"prg":13,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0}],"fs_uni":0},"vs_off":75756,"vs_size":5232,"fs_off":80988,"fs_size":1476},{"prg":14,"info":{"vs_uni":0,"tex":[],"fs_uni":-1},"vs_off":82464,"vs_size":5464,"fs_off":87928,"fs_size":1448},{"prg":15,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1},{"name":"u_maskTex","idx":2,"frag":1}],"fs_uni":0},"vs_off":89376,"vs_size":5600,"fs_off":94976,"fs_size":1972},{"prg":16,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":96948,"vs_size":4136,"fs_off":101084,"fs_size":1636},{"prg":17,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0}],"fs_uni":0},"vs_off":102720,"vs_size":3500,"fs_off":106220,"fs_size":1480},{"prg":18,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0},{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":107700,"vs_size":3844,"fs_off":111544,"fs_size":2396},{"prg":19,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0},{"name":"u_maskTex","idx":2,"frag":1}],"fs_uni":0},"vs_off":113940,"vs_size":3664,"fs_off":117604,"fs_size":1844},{"prg":20,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":119448,"vs_size":1964,"fs_off":121412,"fs_size":1540},{"prg":21,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":122952,"vs_size":2176,"fs_off":125128,"fs_size":1540},{"prg":22,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":126668,"vs_size":3788,"fs_off":130456,"fs_size":1676},{"prg":23,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":132132,"vs_size":4272,"fs_off":136404,"fs_size":1676},{"prg":24,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0}],"fs_uni":0},"vs_off":138080,"vs_size":5968,"fs_off":144048,"fs_size":1812},{"prg":25,"info":{"vs_uni":0,"tex":[],"fs_uni":-1},"vs_off":145860,"vs_size":5016,"fs_off":150876,"fs_size":464},{"prg":26,"info":{"vs_uni":0,"tex":[],"fs_uni":-1},"vs_off":151340,"vs_size":4484,"fs_off":155824,"fs_size":1632},{"prg":27,"info":{"vs_uni":0,"tex":[],"fs_uni":0},"vs_off":157456,"vs_size":6080,"fs_off":163536,"fs_size":4432},{"prg":28,"info":{"vs_uni":0,"tex":[],"fs_uni":0},"vs_off":167968,"vs_size":6080,"fs_off":174048,"fs_size":4028},{"prg":29,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":178076,"vs_size":5376,"fs_off":183452,"fs_size":2464},{"prg":30,"info":{"vs_uni":0,"tex":[],"fs_uni":0},"vs_off":185916,"vs_size":4924,"fs_off":190840,"fs_size":3128},{"prg":31,"info":{"vs_uni":0,"tex":[],"fs_uni":0},"vs_off":193968,"vs_size":3772,"fs_off":197740,"fs_size":2120},{"prg":32,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":199860,"vs_size":4612,"fs_off":204472,"fs_size":2636},{"prg":33,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":207108,"vs_size":4612,"fs_off":211720,"fs_size":2636},{"prg":34,"info":{"vs_uni":-1,"tex":[],"fs_uni":0},"vs_off":214356,"vs_size":1104,"fs_off":215460,"fs_size":616},{"prg":35,"info":{"vs_uni":-1,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":216076,"vs_size":920,"fs_off":216996,"fs_size":1152},{"prg":36,"info":{"vs_uni":0,"tex":[],"fs_uni":0},"vs_off":218148,"vs_size":2060,"fs_off":220208,"fs_size":1488},{"prg":37,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":221696,"vs_size":2388,"fs_off":224084,"fs_size":1856},{"prg":38,"info":{"vs_uni":0,"tex":[],"fs_uni":0},"vs_off":225940,"vs_size":1880,"fs_off":227820,"fs_size":1212},{"prg":39,"info":{"vs_uni":0,"tex":[],"fs_uni":0},"vs_off":229032,"vs_size":1880,"fs_off":230912,"fs_size":1276},{"prg":40,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0}],"fs_uni":0},"vs_off":232188,"vs_size":4428,"fs_off":236616,"fs_size":2712},{"prg":41,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":239328,"vs_size":4200,"fs_off":243528,"fs_size":1636},{"prg":42,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1},{"name":"u_maskTex","idx":2,"frag":1}],"fs_uni":0},"vs_off":245164,"vs_size":4348,"fs_off":249512,"fs_size":1884},{"prg":43,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":251396,"vs_size":5048,"fs_off":256444,"fs_size":2636},{"prg":44,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":259080,"vs_size":5048,"fs_off":264128,"fs_size":2636},{"prg":45,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":266764,"vs_size":5048,"fs_off":271812,"fs_size":2636},{"prg":46,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":274448,"vs_size":5048,"fs_off":279496,"fs_size":2636},{"prg":47,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0},{"name":"u_maskTex","idx":2,"frag":1}],"fs_uni":0},"vs_off":282132,"vs_size":5084,"fs_off":287216,"fs_size":2228},{"prg":48,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":0},{"name":"u_maskTex","idx":2,"frag":1}],"fs_uni":0},"vs_off":289444,"vs_size":4556,"fs_off":294000,"fs_size":2228},{"prg":49,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1},{"name":"u_maskTex","idx":2,"frag":1}],"fs_uni":0},"vs_off":296228,"vs_size":6476,"fs_off":302704,"fs_size":3952},{"prg":50,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":306656,"vs_size":3600,"fs_off":310256,"fs_size":1688},{"prg":51,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":0},"vs_off":311944,"vs_size":6012,"fs_off":317956,"fs_size":2532},{"prg":52,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":-1},"vs_off":320488,"vs_size":1916,"fs_off":322404,"fs_size":4236},{"prg":53,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1},{"name":"u_smaaArea","idx":2,"frag":1},{"name":"u_smaaSearch","idx":3,"frag":1}],"fs_uni":0},"vs_off":326640,"vs_size":2292,"fs_off":328932,"fs_size":12348},{"prg":54,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1},{"name":"u_blendingWeightTex","idx":2,"frag":1}],"fs_uni":0},"vs_off":341280,"vs_size":1364,"fs_off":342644,"fs_size":3688},{"prg":55,"info":{"vs_uni":0,"tex":[{"name":"u_colorTex","idx":1,"frag":1}],"fs_uni":-1},"vs_off":346332,"vs_size":1692,"fs_off":348024,"fs_size":892}] \ No newline at end of file diff --git a/data/vulkan_shaders/shaders_pack.spv b/data/vulkan_shaders/shaders_pack.spv index 2e8dcdff7c..cf7b08f3a1 100644 Binary files a/data/vulkan_shaders/shaders_pack.spv and b/data/vulkan_shaders/shaders_pack.spv differ diff --git a/dev_sandbox/CMakeLists.txt b/dev_sandbox/CMakeLists.txt new file mode 100644 index 0000000000..4680cfbe5e --- /dev/null +++ b/dev_sandbox/CMakeLists.txt @@ -0,0 +1,144 @@ +project(dev_sandbox) + +set(SRC + main.cpp + imgui_renderer.cpp + imgui_renderer.hpp +) + +if (${PLATFORM_MAC}) + append(SRC + main.mm + ../iphone/Maps/Classes/MetalContextFactory.h + ../iphone/Maps/Classes/MetalContextFactory.mm + ) + + file(GLOB_RECURSE SHADER_SOURCES_FILES ${OMIM_ROOT}/shaders/Metal/*.metal) + add_metal_shader_library(shaders_metal + ${SHADER_SOURCES_FILES} + ) +endif() + +if (${PLATFORM_LINUX}) + append(SRC + main_linux.cpp + ) +endif() + +omim_add_executable(${PROJECT_NAME} MACOSX_BUNDLE ${SRC}) + +target_link_libraries(${PROJECT_NAME} + generator # For borders::LoadBorders + qt_common + map + gflags::gflags + glfw + imgui +) + +# Installing Vulkan SDK is optional, however without it Vulkan dynamic libraries +# should be discovered via system paths and validation layers may not be available +find_package(Vulkan QUIET) +if (Vulkan_FOUND) + message(STATUS "Vulkan found") + target_link_libraries(${PROJECT_NAME} Vulkan::Vulkan) +endif() + +if(PLATFORM_MAC) + target_embed_metal_shader_libraries(${PROJECT_NAME} shaders_metal) +endif() + +target_compile_definitions(${PROJECT_NAME} PUBLIC GL_SILENCE_DEPRECATION) +if (PLATFORM_MAC) + set_target_properties(${PROJECT_NAME} PROPERTIES XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES) +endif() + +if (PLATFORM_LINUX) + target_compile_definitions(${PROJECT_NAME} PRIVATE VK_USE_PLATFORM_XLIB_KHR) +endif() + +target_include_directories(${PROJECT_NAME} PUBLIC ${OMIM_ROOT}/3party/glfw/include) +target_include_directories(${PROJECT_NAME} PUBLIC ${OMIM_ROOT}/3party/imgui) + +set(BUNDLE_NAME "OMapsDevSandbox") +set(BUNDLE_DISPLAY_NAME "Organic Maps: Developer Sandbox") + +set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${BUNDLE_NAME}) + +set(BUNDLE_EXECUTABLE ${BUNDLE_NAME}) + +set(BUNDLE_FOLDER ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${BUNDLE_NAME}.app) +set(RESOURCES_FOLDER ${BUNDLE_FOLDER}/Contents/Resources) +set(DATA_DIR ${OMIM_ROOT}/data) + +execute_process( + COMMAND mkdir -p ${RESOURCES_FOLDER}/shaders_compiler +) + +function(copy_resources) + foreach(file ${ARGN}) + execute_process( + COMMAND cp -r ${DATA_DIR}/${file} ${RESOURCES_FOLDER} + ) + endforeach() +endfunction() + +copy_resources( + countries-strings + resources-default + resources-mdpi_light + resources-hdpi_light + resources-xhdpi_light + resources-xxhdpi_light + resources-xxxhdpi_light + resources-6plus_light + + categories.txt + categories_cuisines.txt + classificator.txt + colors.txt + countries.txt + drules_proto_default_light.bin + drules_proto_default_dark.bin + drules_proto_vehicle_light.bin + drules_proto_vehicle_dark.bin + editor.config + fonts_blacklist.txt + fonts_whitelist.txt + packed_polygons.bin + patterns.txt + transit_colors.txt + types.txt + unicode_blocks.txt + World.mwm + WorldCoasts.mwm + + 00_NotoNaskhArabic-Regular.ttf + 00_NotoSansBengali-Regular.ttf + 00_NotoSansHebrew-Regular.ttf + 00_NotoSansMalayalam-Regular.ttf + 00_NotoSansThai-Regular.ttf + 00_NotoSerifDevanagari-Regular.ttf + 01_dejavusans.ttf + 02_droidsans-fallback.ttf + 03_jomolhari-id-a3d.ttf + 04_padauk.ttf + 05_khmeros.ttf + 06_code2000.ttf + 07_roboto_medium.ttf +) + +if (NOT PLATFORM_LINUX) + # On Linux, ICU data is loaded from the shared library. + copy_resources(icudt75l.dat) +endif() + +if (PLATFORM_MAC) + execute_process( + COMMAND cp -r ${OMIM_ROOT}/tools/shaders_compiler/macos ${RESOURCES_FOLDER}/shaders_compiler + ) +elseif (PLATFORM_LINUX) + execute_process( + COMMAND cp -r ${OMIM_ROOT}/tools/shaders_compiler/linux ${RESOURCES_FOLDER}/shaders_compiler + ) +endif() diff --git a/dev_sandbox/imgui_renderer.cpp b/dev_sandbox/imgui_renderer.cpp new file mode 100644 index 0000000000..689b2cb471 --- /dev/null +++ b/dev_sandbox/imgui_renderer.cpp @@ -0,0 +1,257 @@ +#include "imgui_renderer.hpp" + +#include "base/logging.hpp" +#include "base/macros.hpp" + +#include + +#include + +#include + +#include +#include + +ImguiRenderer::ImguiRenderer() + : m_state(df::CreateRenderState(gpu::Program::ImGui, df::DepthLayer::GuiLayer)) +{ + m_state.SetDepthTestEnabled(false); + m_state.SetBlending(dp::Blending(true)); +} + +void ImguiRenderer::Render(ref_ptr context, ref_ptr textureManager, + ref_ptr programManager) +{ + std::lock_guard lock(m_bufferMutex); + size_t renderDataIndex = (m_updateIndex + 1) % m_uiDataBuffer.size(); + UiDataBuffer & dataBuffer = m_uiDataBuffer[renderDataIndex]; + + auto gpuProgram = programManager->GetProgram(m_state.GetProgram()); + + bool needUpdate = true; + if (!m_mesh || dataBuffer.m_vertices.size() > m_vertexCount || dataBuffer.m_indices.size() > m_indexCount) + { + while (dataBuffer.m_vertices.size() > m_vertexCount) + m_vertexCount *= 2; + while (dataBuffer.m_indices.size() > m_indexCount) + m_indexCount *= 2; + m_indexCount = std::min(m_indexCount, static_cast(std::numeric_limits::max())); + + dataBuffer.m_vertices.resize(m_vertexCount); + dataBuffer.m_indices.resize(m_indexCount); + + m_mesh = make_unique_dp(context, dp::MeshObject::DrawPrimitive::Triangles, "imGui"); + + m_mesh->SetBuffer(0, std::move(dataBuffer.m_vertices)); + m_mesh->SetAttribute("a_position", 0, 0 /* offset */, 2); + m_mesh->SetAttribute("a_texCoords", 0, 2 * sizeof(float) /* offset */, 2); + m_mesh->SetAttribute("a_color", 0, 4 * sizeof(float) /* offset */, 4); + m_mesh->SetIndexBuffer(std::move(dataBuffer.m_indices)); + m_mesh->Build(context, gpuProgram); + + dataBuffer.m_vertices.clear(); + dataBuffer.m_indices.clear(); + needUpdate = false; + } + + if (!m_texture) + { + std::lock_guard lock(m_textureMutex); + if (!m_textureData.empty()) + { + m_texture = make_unique_dp(); + m_texture->Create(context, + dp::Texture::Params{ + .m_width = m_textureWidth, + .m_height = m_textureHeight, + .m_format = dp::TextureFormat::RGBA8, + .m_allocator = textureManager->GetTextureAllocator(), + }, + m_textureData.data()); + m_textureData.clear(); + m_state.SetColorTexture(make_ref(m_texture)); + } + else + { + // Can't render without texture. + return; + } + } + + if (dataBuffer.m_drawCalls.empty()) + return; + + if (needUpdate && !dataBuffer.m_vertices.empty() && !dataBuffer.m_indices.empty()) + { + m_mesh->UpdateBuffer(context, 0, dataBuffer.m_vertices); + m_mesh->UpdateIndexBuffer(context, dataBuffer.m_indices); + dataBuffer.m_vertices.clear(); + dataBuffer.m_indices.clear(); + } + + gpu::ImGuiProgramParams const params{.m_projection = m_projection}; + context->PushDebugLabel("ImGui Rendering"); + m_mesh->Render(context, gpuProgram, m_state, programManager->GetParamsSetter(), params, + [&, this]() + { + context->SetCullingEnabled(false); + for (auto const & drawCall : dataBuffer.m_drawCalls) + { + uint32_t y = drawCall.clipRect.y; + if (context->GetApiVersion() == dp::ApiVersion::OpenGLES3) + y = dataBuffer.m_height - y - drawCall.clipRect.w; + context->SetScissor(drawCall.clipRect.x, y, drawCall.clipRect.z, drawCall.clipRect.w); + m_mesh->DrawPrimitivesSubsetIndexed(context, drawCall.indexCount, drawCall.startIndex); + } + context->SetCullingEnabled(true); + context->SetScissor(0, 0, dataBuffer.m_width, dataBuffer.m_height); + }); + context->PopDebugLabel(); +} + +void ImguiRenderer::Update(std::function const & uiCallback) +{ + CHECK(uiCallback, ()); + ImGuiIO & io = ImGui::GetIO(); + if (!io.Fonts->IsBuilt()) + io.Fonts->Build(); + if (!m_texture) + UpdateTexture(); + + ImGui::NewFrame(); + uiCallback(); + ImGui::Render(); + UpdateBuffers(); +} + +void ImguiRenderer::Reset() +{ + { + std::lock_guard lock(m_textureMutex); + m_texture.reset(); + } + + { + std::lock_guard lock(m_bufferMutex); + m_mesh.reset(); + } +} + +void ImguiRenderer::UpdateTexture() +{ + std::lock_guard lock(m_textureMutex); + unsigned char * pixels; + int width, height; + ImGui::GetIO().Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); + + auto const sizeInBytes = width * height * sizeof(uint32_t); + m_textureData.resize(sizeInBytes); + memcpy(m_textureData.data(), pixels, sizeInBytes); + m_textureWidth = static_cast(width); + m_textureHeight = static_cast(height); +} + +void ImguiRenderer::UpdateBuffers() +{ + UiDataBuffer & dataBuffer = m_uiDataBuffer[m_updateIndex]; + dataBuffer.m_drawCalls.clear(); + + ImDrawData * dd = ImGui::GetDrawData(); + auto const fbWidth = static_cast(dd->DisplaySize.x * dd->FramebufferScale.x); + auto const fbHeight = static_cast(dd->DisplaySize.y * dd->FramebufferScale.y); + if (fbWidth <= 0 || fbHeight <= 0 || dd->CmdListsCount == 0 || dd->TotalIdxCount == 0 || dd->TotalVtxCount == 0) + return; + dataBuffer.m_width = static_cast(fbWidth); + dataBuffer.m_height = static_cast(fbHeight); + + CHECK(dd->TotalVtxCount <= std::numeric_limits::max(), + ("UI is so complex and now requires 32-bit indices. You need to improve dp::MeshObject or simplify UI")); + + CHECK((ImGui::GetIO().BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset) == 0, ()); + + dataBuffer.m_vertices.resize(dd->TotalVtxCount); + dataBuffer.m_indices.resize(dd->TotalIdxCount); + + int totalDrawCallsCount = 0; + for (int i = 0; i < dd->CmdListsCount; ++i) + totalDrawCallsCount += dd->CmdLists[i]->CmdBuffer.Size; + dataBuffer.m_drawCalls.reserve(totalDrawCallsCount); + + ImVec2 const clipOff = dd->DisplayPos; + ImVec2 const clipScale = dd->FramebufferScale; + + uint32_t vertexOffset = 0; + uint32_t indexOffset = 0; + for (int i = 0; i < dd->CmdListsCount; ++i) + { + ImDrawList const * cmdList = dd->CmdLists[i]; + for (int j = 0; j < cmdList->VtxBuffer.Size; ++j) + { + dp::Color color(cmdList->VtxBuffer.Data[j].col); + dataBuffer.m_vertices[j + vertexOffset] = { + .position = {cmdList->VtxBuffer.Data[j].pos.x, cmdList->VtxBuffer.Data[j].pos.y}, + .texCoords = {cmdList->VtxBuffer.Data[j].uv.x, cmdList->VtxBuffer.Data[j].uv.y}, + .color = {color.GetAlphaF(), color.GetBlueF(), color.GetGreenF(), + color.GetRedF()} // Byte order is reversed in imGui + }; + } + + static_assert(sizeof(uint16_t) == sizeof(ImDrawIdx)); + memcpy(dataBuffer.m_indices.data() + indexOffset, cmdList->IdxBuffer.Data, + cmdList->IdxBuffer.Size * sizeof(ImDrawIdx)); + for (int j = 0; j < cmdList->IdxBuffer.Size; ++j) + { + uint32_t indexValue = dataBuffer.m_indices[j + indexOffset]; + indexValue += vertexOffset; + CHECK(indexValue <= std::numeric_limits::max(), ()); + dataBuffer.m_indices[j + indexOffset] = static_cast(indexValue); + } + + for (int cmdIndex = 0; cmdIndex < cmdList->CmdBuffer.Size; ++cmdIndex) + { + const ImDrawCmd cmd = cmdList->CmdBuffer[cmdIndex]; + ImVec2 clipMin((cmd.ClipRect.x - clipOff.x) * clipScale.x, (cmd.ClipRect.y - clipOff.y) * clipScale.y); + ImVec2 clipMax((cmd.ClipRect.z - clipOff.x) * clipScale.x, (cmd.ClipRect.w - clipOff.y) * clipScale.y); + if (clipMin.x < 0.0f) + clipMin.x = 0.0f; + if (clipMin.y < 0.0f) + clipMin.y = 0.0f; + if (clipMax.x > fbWidth) + clipMax.x = static_cast(fbWidth); + if (clipMax.y > fbHeight) + clipMax.y = static_cast(fbHeight); + if (clipMax.x <= clipMin.x || clipMax.y <= clipMin.y) + continue; + + dataBuffer.m_drawCalls.emplace_back(DrawCall{ + .indexCount = static_cast(cmd.ElemCount), + .startIndex = static_cast(indexOffset + cmd.IdxOffset), + .clipRect = {static_cast(clipMin.x), static_cast(clipMin.y), + static_cast(clipMax.x - clipMin.x), static_cast(clipMax.y - clipMin.y)}}); + } + + vertexOffset += static_cast(cmdList->VtxBuffer.Size); + indexOffset += static_cast(cmdList->IdxBuffer.Size); + } + CHECK(vertexOffset == dataBuffer.m_vertices.size(), ()); + CHECK(indexOffset == dataBuffer.m_indices.size(), ()); + + { + std::lock_guard lock(m_bufferMutex); + + // Projection + float const left = dd->DisplayPos.x; + float const right = dd->DisplayPos.x + dd->DisplaySize.x; + float const top = dd->DisplayPos.y; + float const bottom = dd->DisplayPos.y + dd->DisplaySize.y; + m_projection[0][0] = 2.0f / (right - left); + m_projection[1][1] = 2.0f / (top - bottom); + m_projection[2][2] = -1.0f; + m_projection[3][3] = 1.0f; + m_projection[0][3] = -(right + left) / (right - left); + m_projection[1][3] = -(top + bottom) / (top - bottom); + + // Swap buffers + m_updateIndex = (m_updateIndex + 1) % m_uiDataBuffer.size(); + } +} diff --git a/dev_sandbox/imgui_renderer.hpp b/dev_sandbox/imgui_renderer.hpp new file mode 100644 index 0000000000..6e048c8e0c --- /dev/null +++ b/dev_sandbox/imgui_renderer.hpp @@ -0,0 +1,72 @@ +#pragma once + +#include "drape/glsl_types.hpp" +#include "drape/graphics_context.hpp" +#include "drape/mesh_object.hpp" +#include "drape/pointers.hpp" +#include "drape/render_state.hpp" +#include "drape/static_texture.hpp" +#include "drape/texture_manager.hpp" + +#include +#include +#include +#include +#include + +class ImguiRenderer +{ +public: + ImguiRenderer(); + void Render(ref_ptr context, + ref_ptr textureManager, + ref_ptr programManager); + void Update(std::function const & uiCallback); + void Reset(); + +private: + void UpdateTexture(); + void UpdateBuffers(); + + struct ImguiVertex + { + glsl::vec2 position; + glsl::vec2 texCoords; + glsl::vec4 color; + }; + static_assert(sizeof(ImguiVertex) == 2 * sizeof(glsl::vec4)); + + struct DrawCall + { + uint32_t indexCount = 0; + uint32_t startIndex = 0; + glsl::uvec4 clipRect{}; + }; + + drape_ptr m_mesh; + uint32_t m_vertexCount = 2000; + uint32_t m_indexCount = 3000; + + drape_ptr m_texture; + std::vector m_textureData; + uint32_t m_textureWidth = 0; + uint32_t m_textureHeight = 0; + + dp::RenderState m_state; + + struct UiDataBuffer + { + std::vector m_vertices; + std::vector m_indices; + std::vector m_drawCalls; + uint32_t m_width; + uint32_t m_height; + }; + std::array m_uiDataBuffer; + size_t m_updateIndex = 0; + + glsl::mat4 m_projection; + + std::mutex m_bufferMutex; + std::mutex m_textureMutex; +}; diff --git a/dev_sandbox/main.cpp b/dev_sandbox/main.cpp new file mode 100644 index 0000000000..8c66d4c9e2 --- /dev/null +++ b/dev_sandbox/main.cpp @@ -0,0 +1,672 @@ +#include "dev_sandbox/imgui_renderer.hpp" + +#include "map/framework.hpp" + +#include "platform/platform.hpp" +#include "platform/settings.hpp" + +#include "coding/reader.hpp" + +#include "base/logging.hpp" +#include "base/macros.hpp" + +#include "std/target_os.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#if defined(OMIM_OS_WINDOWS) +#define GLFW_EXPOSE_NATIVE_WIN32 +#elif defined(OMIM_OS_LINUX) +#define GLFW_EXPOSE_NATIVE_X11 +#elif defined(OMIM_OS_MAC) +#define GLFW_EXPOSE_NATIVE_COCOA +#else +#error Unsupported plaform +#endif +#define GLFW_INCLUDE_NONE +#include +#include +#include +#include + +DEFINE_string(data_path, "", "Path to data directory."); +DEFINE_string(log_abort_level, base::ToString(base::GetDefaultLogAbortLevel()), + "Log messages severity that causes termination."); +DEFINE_string(resources_path, "", "Path to resources directory."); +DEFINE_string(lang, "", "Device language."); + +#if defined(OMIM_OS_MAC) || defined(OMIM_OS_LINUX) +drape_ptr CreateContextFactory(GLFWwindow * window, dp::ApiVersion api, m2::PointU size); +void PrepareDestroyContextFactory(ref_ptr contextFactory); +void OnCreateDrapeEngine(GLFWwindow * window, dp::ApiVersion api, ref_ptr contextFactory); +void UpdateContentScale(GLFWwindow * window, float scale); +void UpdateSize(ref_ptr contextFactory, int w, int h); +#endif + +#if defined(OMIM_OS_LINUX) +// Workaround for storage::Status compilation issue: +// /usr/include/X11/Xlib.h:83:16: note: expanded from macro 'Status' +#undef Status +#endif + +namespace +{ +bool ValidateLogAbortLevel(char const * flagname, std::string const & value) +{ + if (auto level = base::FromString(value); !level) + { + std::cerr << "Invalid value for --" << flagname << ": " << value << ", must be one of: "; + auto const & names = base::GetLogLevelNames(); + for (size_t i = 0; i < names.size(); ++i) + { + if (i != 0) + std::cerr << ", "; + std::cerr << names[i]; + } + std::cerr << '\n'; + return false; + } + return true; +} + +bool const g_logAbortLevelDummy = gflags::RegisterFlagValidator(&FLAGS_log_abort_level, &ValidateLogAbortLevel); + +void errorCallback(int error, char const * description) { LOG(LERROR, ("GLFW (", error, "):", description)); } + +std::function onResize; +std::function onMouseButton; +std::function onMouseMove; +std::function onScroll; +std::function onKeyboardButton; +std::function onContentScale; + +df::Touch GetTouch(double x, double y) +{ + return df::Touch{.m_location = m2::PointF(static_cast(x), static_cast(y)), .m_id = 0}; +} + +df::Touch GetSymmetricalTouch(Framework & framework, df::Touch const & touch) +{ + m2::PointD const pixelCenter = framework.GetVisiblePixelCenter(); + m2::PointD const symmetricalLocation = pixelCenter + pixelCenter - m2::PointD(touch.m_location); + + df::Touch result; + result.m_id = touch.m_id + 1; + result.m_location = symmetricalLocation; + + return result; +} + +df::TouchEvent GetTouchEvent(Framework & framework, double x, double y, int mods, df::TouchEvent::ETouchType type) +{ + df::TouchEvent event; + event.SetTouchType(type); + event.SetFirstTouch(GetTouch(x, y)); + if (mods & GLFW_MOD_SUPER) + event.SetSecondTouch(GetSymmetricalTouch(framework, event.GetFirstTouch())); + return event; +} + +void FormatMapSize(uint64_t sizeInBytes, std::string & units, size_t & sizeToDownload) +{ + int const mbInBytes = 1024 * 1024; + int const kbInBytes = 1024; + if (sizeInBytes > mbInBytes) + { + sizeToDownload = (sizeInBytes + mbInBytes - 1) / mbInBytes; + units = "MB"; + } + else if (sizeInBytes > kbInBytes) + { + sizeToDownload = (sizeInBytes + kbInBytes - 1) / kbInBytes; + units = "KB"; + } + else + { + sizeToDownload = sizeInBytes; + units = "B"; + } +} + +std::string_view GetMyPoisitionText(location::EMyPositionMode mode) +{ + switch(mode) + { + case location::EMyPositionMode::PendingPosition: return "Pending"; + case location::EMyPositionMode::NotFollowNoPosition: return "No position"; + case location::EMyPositionMode::NotFollow: return "Not follow"; + case location::EMyPositionMode::Follow: return "Follow"; + case location::EMyPositionMode::FollowAndRotate: return "Follow and Rotate"; + } + return ""; +} + +dp::ApiVersion GetApiVersion(char const * apiLabel) +{ + std::string_view v(apiLabel); + if (v == "Metal") return dp::ApiVersion::Metal; + if (v == "Vulkan") return dp::ApiVersion::Vulkan; + if (v == "OpenGL") return dp::ApiVersion::OpenGLES3; + return dp::ApiVersion::Invalid; +} + +#if defined(OMIM_OS_LINUX) +class LinuxGuiThread : public base::TaskLoop +{ +public: + PushResult Push(Task && task) override + { + std::lock_guard lock(m_mutex); + m_tasks.emplace_back(std::move(task)); + return {true, base::TaskLoop::kNoId}; + } + + PushResult Push(Task const & task) override + { + std::lock_guard lock(m_mutex); + m_tasks.emplace_back(task); + return {true, base::TaskLoop::kNoId}; + } + + void ExecuteTasks() + { + std::lock_guard lock(m_mutex); + for (auto & task : m_tasks) + task(); + m_tasks.clear(); + } + +private: + std::vector m_tasks; + std::mutex m_mutex; +}; +#endif +} // namespace + +int main(int argc, char * argv[]) +{ + // Our double parsing code (base/string_utils.hpp) needs dots as a floating point delimiters, not commas. + // TODO: Refactor our doubles parsing code to use locale-independent delimiters. + // For example, https://github.com/google/double-conversion can be used. + // See http://dbaron.org/log/20121222-locale for more details. + (void)::setenv("LC_NUMERIC", "C", 1); + + Platform & platform = GetPlatform(); + + LOG(LINFO, ("Organic Maps: Developer Sandbox", platform.Version(), "detected CPU cores:", platform.CpuCores())); + + gflags::SetUsageMessage("Developer Sandbox."); + gflags::SetVersionString(platform.Version()); + gflags::ParseCommandLineFlags(&argc, &argv, true); + + if (!FLAGS_resources_path.empty()) + platform.SetResourceDir(FLAGS_resources_path); + if (!FLAGS_data_path.empty()) + platform.SetWritableDirForTests(FLAGS_data_path); + + if (auto const logLevel = base::FromString(FLAGS_log_abort_level); logLevel) + base::g_LogAbortLevel = *logLevel; + else + LOG(LCRITICAL, ("Invalid log level:", FLAGS_log_abort_level)); + +#if defined(OMIM_OS_LINUX) + auto guiThread = std::make_unique(); + auto guiThreadPtr = guiThread.get(); + platform.SetGuiThread(std::move(guiThread)); +#endif + + // Init GLFW. + glfwSetErrorCallback(errorCallback); + if (!glfwInit()) + { + return -1; + } + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); +#if defined(OMIM_OS_WINDOWS) + glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE); +#endif + auto monitor = glfwGetPrimaryMonitor(); + auto mode = glfwGetVideoMode(monitor); + GLFWwindow * window = + glfwCreateWindow(mode->width, mode->height, "Organic Maps: Developer Sandbox", nullptr, nullptr); + int fbWidth = 0, fbHeight = 0; + glfwGetFramebufferSize(window, &fbWidth, &fbHeight); + float xs = 1.0f, ys = 1.0f; + glfwGetWindowContentScale(window, &xs, &ys); + float visualScale = std::max(xs, ys); + + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; + ImGui::StyleColorsClassic(); + glfwMaximizeWindow(window); + + platform.SetupMeasurementSystem(); + + bool outvalue; + if (!settings::Get(settings::kDeveloperMode, outvalue)) + settings::Set(settings::kDeveloperMode, true); + + if (!FLAGS_lang.empty()) + (void)::setenv("LANGUAGE", FLAGS_lang.c_str(), 1); + + FrameworkParams frameworkParams; + Framework framework(frameworkParams); + + ImguiRenderer imguiRenderer; + Framework::DrapeCreationParams drapeParams{ +#if defined(OMIM_OS_MAC) + .m_apiVersion = dp::ApiVersion::Metal, +#else + .m_apiVersion = dp::ApiVersion::Vulkan, +#endif + .m_visualScale = visualScale, + .m_surfaceWidth = fbWidth, + .m_surfaceHeight = fbHeight, + .m_renderInjectionHandler = [&](ref_ptr context, + ref_ptr textureManager, + ref_ptr programManager, + bool shutdown) + { + if (shutdown) + imguiRenderer.Reset(); + else + imguiRenderer.Render(context, textureManager, programManager); + }}; + gui::Skin guiSkin(gui::ResolveGuiSkinFile("default"), visualScale); + guiSkin.Resize(fbWidth, fbHeight); + guiSkin.ForEach([&](gui::EWidget widget, gui::Position const & pos) { drapeParams.m_widgetsInitInfo[widget] = pos; }); + drapeParams.m_widgetsInitInfo[gui::WIDGET_SCALE_FPS_LABEL] = gui::Position(dp::LeftTop); + + drape_ptr contextFactory; + auto CreateDrapeEngine = [&](dp::ApiVersion version) + { + drapeParams.m_apiVersion = version; + drapeParams.m_visualScale = visualScale; + drapeParams.m_surfaceWidth = fbWidth; + drapeParams.m_surfaceHeight = fbHeight; + contextFactory = CreateContextFactory(window, drapeParams.m_apiVersion, + m2::PointU(static_cast(drapeParams.m_surfaceWidth), + static_cast(drapeParams.m_surfaceHeight))); + auto params = drapeParams; + framework.CreateDrapeEngine(make_ref(contextFactory), std::move(params)); + OnCreateDrapeEngine(window, version, make_ref(contextFactory)); + framework.SetRenderingEnabled(nullptr); + }; + CreateDrapeEngine(drapeParams.m_apiVersion); + + auto DestroyDrapeEngine = [&]() + { + framework.SetRenderingDisabled(true); + framework.DestroyDrapeEngine(); + PrepareDestroyContextFactory(make_ref(contextFactory)); + contextFactory.reset(); + }; + + // Process resizing. + onResize = [&](int w, int h) + { + fbWidth = w; + fbHeight = h; + if (fbWidth > 0 && fbHeight > 0) + { + UpdateSize(make_ref(contextFactory), fbWidth, fbHeight); + framework.OnSize(fbWidth, fbHeight); + + guiSkin.Resize(w, h); + gui::TWidgetsLayoutInfo layout; + guiSkin.ForEach([&layout](gui::EWidget w, gui::Position const & pos) { layout[w] = pos.m_pixelPivot; }); + framework.SetWidgetLayout(std::move(layout)); + framework.MakeFrameActive(); + } + }; + glfwSetFramebufferSizeCallback(window, [](GLFWwindow * wnd, int w, int h) { onResize(w, h); }); + + // Process change content scale. + onContentScale = [&](float xscale, float yscale) + { + visualScale = std::max(xscale, yscale); + framework.UpdateVisualScale(visualScale); + + int w = 0, h = 0; + glfwGetWindowSize(window, &w, &h); +#if defined(OMIM_OS_MAC) + w *= xscale; + h *= yscale; +#endif + + if (w != fbWidth || h != fbHeight) + { +#if defined(OMIM_OS_MAC) + UpdateContentScale(window, xscale); +#endif + fbWidth = w; + fbHeight = h; + UpdateSize(make_ref(contextFactory), fbWidth, fbHeight); + framework.OnSize(fbWidth, fbHeight); + } + }; + glfwSetWindowContentScaleCallback(window, + [](GLFWwindow *, float xscale, float yscale) { onContentScale(xscale, yscale); }); + + // Location handler + std::optional lastLatLon; + bool bearingEnabled = false; + float bearing = 0.0f; + auto setUserLocation = [&]() + { + if (lastLatLon) + { + framework.OnLocationUpdate( + location::GpsInfo{.m_source = location::EUser, + .m_timestamp = static_cast(std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()) + .count()) / + 1000, + .m_latitude = lastLatLon->m_lat, + .m_longitude = lastLatLon->m_lon, + .m_horizontalAccuracy = 10, + .m_bearing = bearingEnabled ? bearing : -1.0f}); + if (bearingEnabled) + { + framework.OnCompassUpdate(location::CompassInfo{.m_bearing = base::DegToRad(bearing)}); + } + } + }; + + // Download maps handler + std::string downloadButtonLabel; + std::string retryButtonLabel; + std::string downloadStatusLabel; + storage::CountryId lastCountry; + auto const onCountryChanged = [&](storage::CountryId const & countryId) + { + downloadButtonLabel.clear(); + retryButtonLabel.clear(); + downloadStatusLabel.clear(); + lastCountry = countryId; + // Called by Framework in World zoom level. + if (countryId.empty()) + return; + + auto const & storage = framework.GetStorage(); + auto status = storage.CountryStatusEx(countryId); + auto const & countryName = countryId; + + if (status == storage::Status::NotDownloaded) + { + std::string units; + size_t sizeToDownload = 0; + FormatMapSize(storage.CountrySizeInBytes(countryId).second, units, sizeToDownload); + std::stringstream str; + str << "Download (" << countryName << ") " << sizeToDownload << units; + downloadButtonLabel = str.str(); + } + else if (status == storage::Status::InQueue) + { + std::stringstream str; + str << countryName << " is waiting for downloading"; + downloadStatusLabel = str.str(); + } + else if (status != storage::Status::Downloading && status != storage::Status::OnDisk && + status != storage::Status::OnDiskOutOfDate) + { + std::stringstream str; + str << "Retry to download " << countryName; + retryButtonLabel = str.str(); + } + }; + framework.SetCurrentCountryChangedListener(onCountryChanged); + + framework.GetStorage().Subscribe( + [&](storage::CountryId const & countryId) + { + // Storage also calls notifications for parents, but we are interested in leafs only. + if (framework.GetStorage().IsLeaf(countryId)) + onCountryChanged(countryId); + }, + [&](storage::CountryId const & countryId, downloader::Progress const & progress) + { + std::stringstream str; + str << "Downloading (" << countryId << ") " << (progress.m_bytesDownloaded * 100 / progress.m_bytesTotal) + << "%"; + downloadStatusLabel = str.str(); + framework.MakeFrameActive(); + }); + + // Handle mouse buttons. + bool touchActive = false; + int touchMods = 0; + bool setUpLocationByLeftClick = false; + onMouseButton = [&](double x, double y, int button, int action, int mods) + { +#if defined(OMIM_OS_LINUX) + ImGui::GetIO().MousePos = ImVec2(x / visualScale, y / visualScale); +#endif + if (ImGui::GetIO().WantCaptureMouse) + { + framework.MakeFrameActive(); + return; + } + +#if defined(OMIM_OS_MAC) + x *= visualScale; + y *= visualScale; +#endif + lastLatLon = mercator::ToLatLon(framework.PtoG(m2::PointD(x, y))); + + if (setUpLocationByLeftClick) + { + setUserLocation(); + return; + } + + if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) + { + framework.TouchEvent(GetTouchEvent(framework, x, y, mods, df::TouchEvent::TOUCH_DOWN)); + touchActive = true; + touchMods = mods; + } + + if (touchActive && action == GLFW_RELEASE) + { + framework.TouchEvent(GetTouchEvent(framework, x, y, 0, df::TouchEvent::TOUCH_UP)); + touchActive = false; + touchMods = 0; + } + }; + glfwSetMouseButtonCallback(window, + [](GLFWwindow * wnd, int button, int action, int mods) + { + double x, y; + glfwGetCursorPos(wnd, &x, &y); + onMouseButton(x, y, button, action, mods); + }); + + // Handle mouse moving. + onMouseMove = [&](double x, double y) + { +#if defined(OMIM_OS_LINUX) + ImGui::GetIO().MousePos = ImVec2(x / visualScale, y / visualScale); +#endif + if (ImGui::GetIO().WantCaptureMouse) + framework.MakeFrameActive(); + + if (touchActive) + { +#if defined(OMIM_OS_MAC) + x *= visualScale; + y *= visualScale; +#endif + framework.TouchEvent( + GetTouchEvent(framework, x, y, touchMods, df::TouchEvent::TOUCH_MOVE)); + } + }; + glfwSetCursorPosCallback(window, [](GLFWwindow *, double x, double y) { onMouseMove(x, y); }); + + // Handle scroll. + onScroll = [&](double x, double y, double xOffset, double yOffset) + { +#if defined(OMIM_OS_LINUX) + ImGui::GetIO().MousePos = ImVec2(x / visualScale, y / visualScale); +#endif + if (ImGui::GetIO().WantCaptureMouse) + { + framework.MakeFrameActive(); + return; + } + +#if defined(OMIM_OS_MAC) + x *= visualScale; + y *= visualScale; +#endif + constexpr double kSensitivity = 0.01; + double const factor = yOffset * kSensitivity; + framework.Scale(exp(factor), m2::PointD(x, y), false); + }; + glfwSetScrollCallback(window, + [](GLFWwindow * wnd, double xoffset, double yoffset) + { + double x, y; + glfwGetCursorPos(wnd, &x, &y); + onScroll(x, y, xoffset, yoffset); + }); + + // Keys. + onKeyboardButton = [&](int key, int scancode, int action, int mods) {}; + glfwSetKeyCallback(window, [](GLFWwindow *, int key, int scancode, int action, int mods) + { onKeyboardButton(key, scancode, action, mods); }); + + // imGui UI + bool enableDebugRectRendering = false; + bool enableAA = false; + auto imGuiUI = [&]() + { + ImGui::SetNextWindowPos(ImVec2(5, 20), ImGuiCond_Appearing); + ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize); + + // Drape controls + char const * apiLabels[] = { +#if defined(OMIM_OS_MAC) + "Metal", + "Vulkan", + "OpenGL" +#elif defined(OMIM_OS_LINUX) + "Vulkan", + "OpenGL" +#endif + }; + static int currentAPI = 0; + if (ImGui::Combo("API", ¤tAPI, apiLabels, IM_ARRAYSIZE(apiLabels))) + { + auto const apiVersion = GetApiVersion(apiLabels[currentAPI]); + if (framework.GetDrapeEngine()->GetApiVersion() != apiVersion) + { + DestroyDrapeEngine(); + CreateDrapeEngine(apiVersion); + } + } + if (ImGui::Checkbox("Debug rect rendering", &enableDebugRectRendering)) + framework.EnableDebugRectRendering(enableDebugRectRendering); + if (ImGui::Checkbox("Antialiasing", &enableAA)) + framework.GetDrapeEngine()->SetPosteffectEnabled(df::PostprocessRenderer::Antialiasing, enableAA); + ImGui::NewLine(); + ImGui::Separator(); + ImGui::NewLine(); + + // Map controls + if (ImGui::Button("Scale +")) + framework.Scale(Framework::SCALE_MAG, true); + ImGui::SameLine(); + if (ImGui::Button("Scale -")) + framework.Scale(Framework::SCALE_MIN, true); + ImGui::Checkbox("Set up location by left click", &setUpLocationByLeftClick); + if (setUpLocationByLeftClick) + { + if (ImGui::Checkbox("Bearing", &bearingEnabled)) + setUserLocation(); + ImGui::SameLine(); + if (ImGui::SliderFloat(" ", &bearing, 0.0f, 360.0f, "%.1f")) + setUserLocation(); + } + ImGui::Text("My positon mode: %s", GetMyPoisitionText(framework.GetMyPositionMode()).data()); + if (ImGui::Button("Next Position Mode")) + framework.SwitchMyPositionNextMode(); + ImGui::NewLine(); + ImGui::Separator(); + ImGui::NewLine(); + + // No downloading on Linux at the moment, need to implement http_thread without Qt. +#if !defined(OMIM_OS_LINUX) + // Download controls + if (!downloadButtonLabel.empty()) + { + if (ImGui::Button(downloadButtonLabel.c_str())) + framework.GetStorage().DownloadNode(lastCountry); + } + if (!retryButtonLabel.empty()) + { + if (ImGui::Button(retryButtonLabel.c_str())) + framework.GetStorage().RetryDownloadNode(lastCountry); + } + if (!downloadStatusLabel.empty()) + ImGui::Text("%s", downloadStatusLabel.c_str()); + if (!downloadButtonLabel.empty() || !retryButtonLabel.empty() || !downloadStatusLabel.empty()) + { + ImGui::NewLine(); + ImGui::Separator(); + ImGui::NewLine(); + } +#endif + + ImGui::End(); + }; + + ImGui_ImplGlfw_InitForOther(window, true); + + // Main loop. + while (!glfwWindowShouldClose(window)) + { + glfwPollEvents(); + +#if defined(OMIM_OS_LINUX) + guiThreadPtr->ExecuteTasks(); +#endif + + // Render imGui UI + ImGui_ImplGlfw_NewFrame(); + ImGuiIO& io = ImGui::GetIO(); +#if defined(OMIM_OS_LINUX) + // Apply correct visual scale on Linux + // In glfw for Linux, window size and framebuffer size are the same, + // even if visual scale is not 1.0. It's different from behaviour on Mac. + io.DisplaySize = ImVec2(fbWidth / visualScale, fbHeight / visualScale); + io.DisplayFramebufferScale = ImVec2(visualScale, visualScale); + double mouseX, mouseY; + glfwGetCursorPos(window, &mouseX, &mouseY); + io.AddMousePosEvent((float)mouseX / visualScale, (float)mouseY / visualScale); +#endif + io.IniFilename = nullptr; + imguiRenderer.Update(imGuiUI); + std::this_thread::sleep_for(std::chrono::milliseconds(1000 / 30)); + } + + framework.EnterBackground(); + DestroyDrapeEngine(); + + ImGui_ImplGlfw_Shutdown(); + ImGui::DestroyContext(); + + glfwDestroyWindow(window); + glfwTerminate(); + return 0; +} diff --git a/dev_sandbox/main.mm b/dev_sandbox/main.mm new file mode 100644 index 0000000000..8ad4d03c7e --- /dev/null +++ b/dev_sandbox/main.mm @@ -0,0 +1,370 @@ +#include "iphone/Maps/Classes/MetalContextFactory.h" + +#include "drape/gl_functions.hpp" +#include "drape/oglcontext.hpp" +#include "drape/metal/metal_base_context.hpp" +#include "drape/vulkan/vulkan_context_factory.hpp" + +#define GLFW_INCLUDE_NONE +#include + +#if __APPLE__ +#define GLFW_EXPOSE_NATIVE_COCOA +#else +#error Unsupported OS +#endif +#include + +#import +#import +#import +#import + +#include + +#include +#include + +class MacOSVulkanContextFactory : public dp::vulkan::VulkanContextFactory +{ +public: + MacOSVulkanContextFactory() + : dp::vulkan::VulkanContextFactory(1, 33, false) {} + + void SetSurface(CAMetalLayer *layer) + { + VkMacOSSurfaceCreateInfoMVK createInfo = { + .sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK, + .flags = 0, + .pView = static_cast(CFBridgingRetain(layer)), + }; + + VkResult statusCode; + CHECK(vkCreateMacOSSurfaceMVK, ()); + statusCode = vkCreateMacOSSurfaceMVK(m_vulkanInstance, &createInfo, nullptr, + &m_surface); + if (statusCode != VK_SUCCESS) + { + LOG_ERROR_VK_CALL(vkCreateMacOSSurfaceMVK, statusCode); + return; + } + + uint32_t const renderingQueueIndex = m_drawContext->GetRenderingQueueFamilyIndex(); + VkBool32 supportsPresent; + statusCode = vkGetPhysicalDeviceSurfaceSupportKHR(m_gpu, renderingQueueIndex, m_surface, &supportsPresent); + if (statusCode != VK_SUCCESS) + { + LOG_ERROR_VK_CALL(vkGetPhysicalDeviceSurfaceSupportKHR, statusCode); + return; + } + CHECK_EQUAL(supportsPresent, VK_TRUE, ()); + + CHECK(QuerySurfaceSize(), ()); + + if (m_drawContext) + m_drawContext->SetSurface(m_surface, m_surfaceFormat, m_surfaceCapabilities); + } + + void ResetSurface() + { + if (m_drawContext) + m_drawContext->ResetSurface(false); + + vkDestroySurfaceKHR(m_vulkanInstance, m_surface, nullptr); + } +}; + +class MacGLContext : public dp::OGLContext +{ +public: + MacGLContext(MacGLContext * contextToShareWith) + : m_viewSet(false) + { + NSOpenGLPixelFormatAttribute attributes[] = { + NSOpenGLPFAAccelerated, + NSOpenGLPFAOpenGLProfile, + NSOpenGLProfileVersion4_1Core, + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAColorSize, + 24, + NSOpenGLPFAAlphaSize, + 8, + NSOpenGLPFADepthSize, + 24, + NSOpenGLPFAStencilSize, + 8, + 0 + }; + m_pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; + CHECK(m_pixelFormat, ("Pixel format is not found")); + m_context = [[NSOpenGLContext alloc] initWithFormat:m_pixelFormat + shareContext:(contextToShareWith ? contextToShareWith->m_context : nil)]; + int interval = 1; + [m_context getValues:&interval forParameter:NSOpenGLContextParameterSwapInterval]; + } + + ~MacGLContext() + { + @autoreleasepool { + [m_context clearDrawable]; + m_pixelFormat = nil; + m_context = nil; + } + } + + bool BeginRendering() override { return m_viewSet; } + + void Present() override + { + if (m_viewSet) + { + std::lock_guard lock(m_updateSizeMutex); + [m_context flushBuffer]; + } + } + + void MakeCurrent() override + { + [m_context makeCurrentContext]; + } + + void DoneCurrent() override + { + [NSOpenGLContext clearCurrentContext]; + } + + void SetFramebuffer(ref_ptr framebuffer) override + { + if (framebuffer) + framebuffer->Bind(); + else + GLFunctions::glBindFramebuffer(0); + } + + void SetView(NSView* view) + { + [m_context setView: view]; + [m_context update]; + m_viewSet = true; + } + + void UpdateSize(int w, int h) + { + std::lock_guard lock(m_updateSizeMutex); + [m_context update]; + } + +private: + NSOpenGLPixelFormat * m_pixelFormat = nil; + NSOpenGLContext* m_context = nil; + std::atomic m_viewSet; + + std::mutex m_updateSizeMutex; +}; + +class MacGLContextFactory: public dp::GraphicsContextFactory +{ +public: + dp::GraphicsContext * GetDrawContext() override + { + bool needNotify = false; + { + std::lock_guard lock(m_contextAccess); + if (m_drawContext == nullptr) + { + m_drawContext = std::make_unique(m_uploadContext.get()); + needNotify = true; + } + } + if (needNotify) + NotifyView(); + + std::lock_guard lock(m_contextAccess); + return m_drawContext.get(); + } + + dp::GraphicsContext * GetResourcesUploadContext() override + { + std::lock_guard lock(m_contextAccess); + if (m_uploadContext == nullptr) + m_uploadContext = std::make_unique(m_drawContext.get()); + return m_uploadContext.get(); + } + + void WaitForInitialization(dp::GraphicsContext *) override + { + std::unique_lock lock(m_initializationMutex); + if (m_isInitialized) + return; + + m_initializationCounter++; + if (m_initializationCounter >= kGLThreadsCount) + { + m_isInitialized = true; + m_initializationCondition.notify_all(); + } + else + { + m_initializationCondition.wait(lock, [this] { return m_isInitialized; }); + } + } + + bool IsDrawContextCreated() const override + { + std::lock_guard lock(m_contextAccess); + return m_drawContext != nullptr; + } + + bool IsUploadContextCreated() const override + { + std::lock_guard lock(m_contextAccess); + return m_uploadContext != nullptr; + } + + void SetView(NSView* view) + { + bool needWait; + { + std::lock_guard lock(m_contextAccess); + needWait = (m_drawContext == nullptr); + } + if (needWait) + { + std::unique_lock lock(m_viewSetMutex); + m_viewSetCondition.wait(lock, [this] { return m_viewSet; }); + } + + std::lock_guard lock(m_contextAccess); + CHECK(m_drawContext, ()); + m_drawContext->SetView(view); + } + + void UpdateSize(int w, int h) + { + std::lock_guard lock(m_contextAccess); + if (m_drawContext) + m_drawContext->UpdateSize(w, h); + } + +private: + void NotifyView() + { + std::lock_guard lock(m_viewSetMutex); + m_viewSet = true; + m_viewSetCondition.notify_all(); + } + + static size_t constexpr kGLThreadsCount = 2; + + std::unique_ptr m_drawContext; + std::unique_ptr m_uploadContext; + + mutable std::mutex m_contextAccess; + + bool m_isInitialized = false; + size_t m_initializationCounter = 0; + std::condition_variable m_initializationCondition; + std::mutex m_initializationMutex; + + bool m_viewSet = false; + std::condition_variable m_viewSetCondition; + std::mutex m_viewSetMutex; +}; + +drape_ptr CreateContextFactory(GLFWwindow *window, dp::ApiVersion api, m2::PointU size) +{ + if (api == dp::ApiVersion::Metal) + { + CAMetalLayer *layer = [CAMetalLayer layer]; + layer.device = MTLCreateSystemDefaultDevice(); + layer.opaque = YES; + layer.displaySyncEnabled = YES; + + NSWindow *nswindow = glfwGetCocoaWindow(window); + NSScreen *screen = [NSScreen mainScreen]; + CGFloat factor = [screen backingScaleFactor]; + layer.contentsScale = factor; + nswindow.contentView.layer = layer; + nswindow.contentView.wantsLayer = YES; + + return make_unique_dp(layer, size); + } + + if (api == dp::ApiVersion::Vulkan) + { + CAMetalLayer *layer = [CAMetalLayer layer]; + layer.device = MTLCreateSystemDefaultDevice(); + layer.opaque = YES; + layer.displaySyncEnabled = YES; + + NSWindow *nswindow = glfwGetCocoaWindow(window); + NSScreen *screen = [NSScreen mainScreen]; + CGFloat factor = [screen backingScaleFactor]; + layer.contentsScale = factor; + nswindow.contentView.layer = layer; + nswindow.contentView.wantsLayer = YES; + + auto contextFactory = make_unique_dp(); + contextFactory->SetSurface(layer); + return contextFactory; + } + + if (api == dp::ApiVersion::OpenGLES3) + { + NSWindow *nswindow = glfwGetCocoaWindow(window); + [nswindow.contentView setWantsBestResolutionOpenGLSurface:YES]; + return make_unique_dp(); + } + + ASSERT(false, ("API is not available yet")); + return nullptr; +} + +void OnCreateDrapeEngine(GLFWwindow *window, dp::ApiVersion api, + ref_ptr contextFactory) +{ + if (api == dp::ApiVersion::OpenGLES3) + { + NSWindow *nswindow = glfwGetCocoaWindow(window); + ref_ptr macosContextFactory = contextFactory; + macosContextFactory->SetView(nswindow.contentView); + } +} + +void PrepareDestroyContextFactory(ref_ptr contextFactory) +{ + auto const api = contextFactory->GetDrawContext()->GetApiVersion(); + if (api == dp::ApiVersion::Metal || api == dp::ApiVersion::OpenGLES3) + { + // Do nothing + } + else if (api == dp::ApiVersion::Vulkan) + { + ref_ptr macosContextFactory = contextFactory; + macosContextFactory->ResetSurface(); + } + else + { + ASSERT(false, ("API is not available yet")); + } +} + +void UpdateContentScale(GLFWwindow *window, float scale) +{ + NSWindow *nswindow = glfwGetCocoaWindow(window); + if (nswindow.contentView.layer) + nswindow.contentView.layer.contentsScale = scale; +} + +void UpdateSize(ref_ptr contextFactory, int w, int h) +{ + if (!contextFactory || !contextFactory->GetDrawContext()) + return; + + auto const api = contextFactory->GetDrawContext()->GetApiVersion(); + if (api == dp::ApiVersion::OpenGLES3) + { + ref_ptr macosContextFactory = contextFactory; + macosContextFactory->UpdateSize(w, h); + } +} diff --git a/dev_sandbox/main_linux.cpp b/dev_sandbox/main_linux.cpp new file mode 100644 index 0000000000..43113d6346 --- /dev/null +++ b/dev_sandbox/main_linux.cpp @@ -0,0 +1,411 @@ +#include "std/target_os.hpp" +#if !defined(OMIM_OS_LINUX) +#error Unsupported OS +#endif + +#define GLFW_INCLUDE_NONE +#include +#define GLFW_EXPOSE_NATIVE_X11 +#include + +#include +#include + +#include +#include +// Workaround for TestFunction::Always compilation issue: +// /usr/include/X11/X.h:441:33: note: expanded from macro 'Always' +#undef Always +// Workaround for storage::Status compilation issue: +// /usr/include/X11/Xlib.h:83:16: note: expanded from macro 'Status' +#undef Status + +#include "drape/vulkan/vulkan_context_factory.hpp" + +#include "drape/gl_functions.hpp" +#include "drape/gl_includes.hpp" +#include "drape/oglcontext.hpp" + +#include +#include +#include + +class LinuxVulkanContextFactory : public dp::vulkan::VulkanContextFactory +{ +public: + LinuxVulkanContextFactory() : dp::vulkan::VulkanContextFactory(1, 33, false) {} + + void SetSurface(Display * display, Window window) + { + VkXlibSurfaceCreateInfoKHR const createInfo = { + .sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR, + .pNext = nullptr, + .flags = 0, + .dpy = display, + .window = window, + }; + + VkResult statusCode; + CHECK(vkCreateXlibSurfaceKHR, ()); + statusCode = vkCreateXlibSurfaceKHR(m_vulkanInstance, &createInfo, nullptr, &m_surface); + if (statusCode != VK_SUCCESS) + { + LOG_ERROR_VK_CALL(vkCreateXlibSurfaceKHR, statusCode); + return; + } + + uint32_t const renderingQueueIndex = m_drawContext->GetRenderingQueueFamilyIndex(); + VkBool32 supportsPresent; + statusCode = vkGetPhysicalDeviceSurfaceSupportKHR(m_gpu, renderingQueueIndex, m_surface, &supportsPresent); + if (statusCode != VK_SUCCESS) + { + LOG_ERROR_VK_CALL(vkGetPhysicalDeviceSurfaceSupportKHR, statusCode); + return; + } + CHECK_EQUAL(supportsPresent, VK_TRUE, ()); + + CHECK(QuerySurfaceSize(), ()); + + if (m_drawContext) + m_drawContext->SetSurface(m_surface, m_surfaceFormat, m_surfaceCapabilities); + } + + void ResetSurface() + { + if (m_drawContext) + m_drawContext->ResetSurface(false); + + vkDestroySurfaceKHR(m_vulkanInstance, m_surface, nullptr); + } +}; + +// Based on: https://github.com/glfw/glfw/blob/master/src/glx_context.c +#define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 +#define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126 +#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 +#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 +#define GLX_PBUFFER_HEIGHT 0x8040 +#define GLX_PBUFFER_WIDTH 0x8041 +#define GLX_DOUBLEBUFFER 5 +#define GLX_DRAWABLE_TYPE 0x8010 +#define GLX_RENDER_TYPE 0x8011 +#define GLX_WINDOW_BIT 0x00000001 +#define GLX_PBUFFER_BIT 0x00000004 +#define GLX_RGBA_BIT 0x00000001 +#define GLX_RED_SIZE 8 +#define GLX_GREEN_SIZE 9 +#define GLX_BLUE_SIZE 10 +#define GLX_ALPHA_SIZE 11 +#define GLX_DEPTH_SIZE 12 +#define GLX_STENCIL_SIZE 13 + +typedef XID GLXDrawable; +typedef struct __GLXcontext * GLXContext; +typedef XID GLXPbuffer; +typedef struct __GLXFBConfig * GLXFBConfig; +typedef void (*__GLXextproc)(void); + +typedef __GLXextproc (*PFNGLXGETPROCADDRESSPROC)(const GLubyte * procName); + +typedef int (*PFNXFREE)(void *); +typedef GLXFBConfig * (*PFNGLXCHOOSEFBCONFIGPROC)(Display *, int, const int *, int *); +typedef GLXContext (*PFNGLXCREATECONTEXTATTRIBSARB)(Display *, GLXFBConfig, GLXContext, Bool, const int *); +typedef void (*PFNGLXDESTROYCONTEXT)(Display *, GLXContext); +typedef GLXPbuffer (*PFNGLXCREATEPBUFFERPROC)(Display *, GLXFBConfig, const int *); +typedef void (*PFNGLXDESTROYPBUFFER)(Display *, GLXPbuffer); +typedef Bool (*PFNGLXMAKECURRENTPROC)(Display *, GLXDrawable, GLXContext); +typedef void (*PFNGLXSWAPBUFFERSPROC)(Display *, GLXDrawable); + +struct GLXFunctions +{ + GLXFunctions() + { + std::array libs = { + "libGLX.so.0", + "libGL.so.1", + "libGL.so", + }; + + for (char const * lib : libs) + { + m_module = dlopen(lib, RTLD_LAZY | RTLD_LOCAL); + if (m_module) + { + break; + } + } + + CHECK(m_module != nullptr, ("Failed to initialize GLX")); + + XFree = loadFunction("XFree"); + + glXGetProcAddress = loadFunction("glXGetProcAddress"); + glXGetProcAddressARB = loadFunction("glXGetProcAddressARB"); + + glXChooseFBConfig = loadGlxFunction("glXChooseFBConfig"); + glXCreateContextAttribsARB = loadGlxFunction("glXCreateContextAttribsARB"); + + glXDestroyContext = loadGlxFunction("glXDestroyContext"); + glXCreatePbuffer = loadGlxFunction("glXCreatePbuffer"); + glXDestroyPbuffer = loadGlxFunction("glXDestroyPbuffer"); + glXMakeCurrent = loadGlxFunction("glXMakeCurrent"); + glXSwapBuffers = loadGlxFunction("glXSwapBuffers"); + } + + ~GLXFunctions() + { + if (m_module) + { + dlclose(m_module); + } + } + + PFNXFREE XFree = nullptr; + + PFNGLXGETPROCADDRESSPROC glXGetProcAddress = nullptr; + PFNGLXGETPROCADDRESSPROC glXGetProcAddressARB = nullptr; + + PFNGLXCHOOSEFBCONFIGPROC glXChooseFBConfig = nullptr; + PFNGLXCREATECONTEXTATTRIBSARB glXCreateContextAttribsARB = nullptr; + PFNGLXDESTROYCONTEXT glXDestroyContext = nullptr; + PFNGLXCREATEPBUFFERPROC glXCreatePbuffer = nullptr; + PFNGLXDESTROYPBUFFER glXDestroyPbuffer = nullptr; + PFNGLXMAKECURRENTPROC glXMakeCurrent = nullptr; + PFNGLXSWAPBUFFERSPROC glXSwapBuffers = nullptr; + +private: + template + T loadFunction(char const * func) + { + auto f = reinterpret_cast(dlsym(m_module, func)); + ASSERT(f, ("Failed to initialize GLX:", func, "is not found")); + return f; + } + + template + T loadGlxFunction(char const * func) + { + if (auto f = reinterpret_cast(glXGetProcAddress(reinterpret_cast(func)))) + return f; + + if (auto f = reinterpret_cast(glXGetProcAddressARB(reinterpret_cast(func)))) + return f; + + return loadFunction(func); + } + + void * m_module = nullptr; +}; + +class LinuxGLContext : public dp::OGLContext +{ +public: + LinuxGLContext(GLXFunctions const & glx, Display * display, Window window, LinuxGLContext * contextToShareWith, + bool usePixelBuffer) + : m_glx(glx), m_display(display), m_window(window) + { + static int visualAttribs[] = { + GLX_DOUBLEBUFFER, True, + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_DRAWABLE_TYPE, (usePixelBuffer ? GLX_PBUFFER_BIT : GLX_WINDOW_BIT), + GLX_RED_SIZE, 8, + GLX_GREEN_SIZE, 8, + GLX_BLUE_SIZE, 8, + GLX_ALPHA_SIZE, 8, + GLX_DEPTH_SIZE, 24, + GLX_STENCIL_SIZE, 8, + None + }; + int contextAttribs[] = { + GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, + GLX_CONTEXT_MAJOR_VERSION_ARB, 4, + GLX_CONTEXT_MINOR_VERSION_ARB, 1, + None}; + int fbcount = 0; + if (GLXFBConfig * config = m_glx.glXChooseFBConfig(display, DefaultScreen(display), visualAttribs, &fbcount)) + { + m_context = + m_glx.glXCreateContextAttribsARB(display, config[0], contextToShareWith ? contextToShareWith->m_context : 0, True, contextAttribs); + CHECK(m_context != nullptr, ("Failed to create GLX context")); + + if (usePixelBuffer) + { + int pbufferAttribs[] = {GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, None}; + + m_pixelBufferHandle = m_glx.glXCreatePbuffer(display, config[0], pbufferAttribs); + CHECK(m_pixelBufferHandle != 0, ("Failed to create GLX pbuffer")); + } + + m_glx.XFree(config); + } + } + + ~LinuxGLContext() override + { + if (m_pixelBufferHandle) + { + m_glx.glXDestroyPbuffer(m_display, m_pixelBufferHandle); + m_pixelBufferHandle = 0; + } + if (m_context) + { + m_glx.glXDestroyContext(m_display, m_context); + m_context = nullptr; + } + } + + void Present() override + { + if (!m_pixelBufferHandle) + m_glx.glXSwapBuffers(m_display, m_window); + } + + void MakeCurrent() override + { + if (!m_glx.glXMakeCurrent(m_display, m_pixelBufferHandle ? m_pixelBufferHandle : m_window, m_context)) + LOG(LERROR, ("MakeCurrent(): glXMakeCurrent failed")); + } + + void DoneCurrent() override + { + if (!m_glx.glXMakeCurrent(m_display, None, nullptr)) + LOG(LERROR, ("DoneCurrent(): glXMakeCurrent failed")); + } + + void SetFramebuffer(ref_ptr framebuffer) override + { + if (framebuffer) + framebuffer->Bind(); + else + GLFunctions::glBindFramebuffer(0); + } + +private: + GLXFunctions const & m_glx; + + Display * m_display = nullptr; + Window m_window = 0; + GLXDrawable m_pixelBufferHandle = 0; + GLXContext m_context = nullptr; +}; + +class LinuxContextFactory : public dp::GraphicsContextFactory +{ +public: + LinuxContextFactory(Display * display, Window window) : m_display(display), m_window(window) {} + + dp::GraphicsContext * GetDrawContext() override + { + std::lock_guard lock(m_contextAccess); + if (m_drawContext == nullptr) + m_drawContext = std::make_unique(m_glx, m_display, m_window, m_uploadContext.get(), false); + return m_drawContext.get(); + } + + dp::GraphicsContext * GetResourcesUploadContext() override + { + std::lock_guard lock(m_contextAccess); + if (m_uploadContext == nullptr) + m_uploadContext = std::make_unique(m_glx, m_display, 0, m_drawContext.get(), true); + return m_uploadContext.get(); + } + + void WaitForInitialization(dp::GraphicsContext *) override + { + std::unique_lock lock(m_initializationMutex); + if (m_isInitialized) + return; + + m_initializationCounter++; + if (m_initializationCounter >= kGLThreadsCount) + { + m_isInitialized = true; + m_initializationCondition.notify_all(); + } + else + { + m_initializationCondition.wait(lock, [this] { return m_isInitialized; }); + } + } + + bool IsDrawContextCreated() const override + { + std::lock_guard lock(m_contextAccess); + return m_drawContext != nullptr; + } + + bool IsUploadContextCreated() const override + { + std::lock_guard lock(m_contextAccess); + return m_uploadContext != nullptr; + } + +private: + static size_t constexpr kGLThreadsCount = 2; + + GLXFunctions m_glx; + + Display * m_display = nullptr; + Window m_window = 0; + + std::unique_ptr m_drawContext; + std::unique_ptr m_uploadContext; + + mutable std::mutex m_contextAccess; + + bool m_isInitialized = false; + size_t m_initializationCounter = 0; + std::condition_variable m_initializationCondition; + std::mutex m_initializationMutex; +}; + +drape_ptr CreateContextFactory(GLFWwindow * window, dp::ApiVersion api, m2::PointU size) +{ + if (api == dp::ApiVersion::Vulkan) + { + auto contextFactory = make_unique_dp(); + contextFactory->SetSurface(glfwGetX11Display(), glfwGetX11Window(window)); + return contextFactory; + } + + if (api == dp::ApiVersion::OpenGLES3) + { + return make_unique_dp(glfwGetX11Display(), glfwGetX11Window(window)); + } + + ASSERT(false, ("API is not available yet")); + return nullptr; +} + +void OnCreateDrapeEngine(GLFWwindow * window, dp::ApiVersion api, ref_ptr contextFactory) +{ + // Do nothing +} + +void PrepareDestroyContextFactory(ref_ptr contextFactory) +{ + auto const api = contextFactory->GetDrawContext()->GetApiVersion(); + if (api == dp::ApiVersion::OpenGLES3) + { + // Do nothing + } + else if (api == dp::ApiVersion::Vulkan) + { + ref_ptr linuxContextFactory = contextFactory; + linuxContextFactory->ResetSurface(); + } + else + { + ASSERT(false, ("API is not available yet")); + } +} + +void UpdateContentScale(GLFWwindow * window, float scale) +{ + // Do nothing +} + +void UpdateSize(ref_ptr contextFactory, int w, int h) +{ + // Do nothing +} diff --git a/docs/INSTALL.md b/docs/INSTALL.md index e4095ce611..77660b127e 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -115,6 +115,10 @@ sudo apt update && sudo apt install -y \ libqt6positioning6-plugins \ libqt6positioning6 \ libsqlite3-dev \ + libxrandr-dev \ + libxinerama-dev \ + libxcursor-dev \ + libxi-dev \ zlib1g-dev ``` diff --git a/drape/data_buffer.cpp b/drape/data_buffer.cpp index 8040056ccf..878757782a 100644 --- a/drape/data_buffer.cpp +++ b/drape/data_buffer.cpp @@ -21,7 +21,7 @@ void DataBuffer::MoveToGPU(ref_ptr context, GPUBuffer::Target t uint32_t const currentSize = m_impl->GetCurrentSize(); auto const apiVersion = context->GetApiVersion(); - if (apiVersion == dp::ApiVersion::OpenGLES2 || apiVersion == dp::ApiVersion::OpenGLES3) + if (apiVersion == dp::ApiVersion::OpenGLES3) { if (currentSize != 0) { diff --git a/drape/drape_global.hpp b/drape/drape_global.hpp index d0f449483b..3939ad9420 100644 --- a/drape/drape_global.hpp +++ b/drape/drape_global.hpp @@ -26,7 +26,6 @@ namespace dp enum class ApiVersion { Invalid = -1, - OpenGLES2 = 0, OpenGLES3, Metal, Vulkan @@ -101,7 +100,6 @@ inline std::string DebugPrint(dp::ApiVersion apiVersion) switch (apiVersion) { case dp::ApiVersion::Invalid: return "Invalid"; - case dp::ApiVersion::OpenGLES2: return "OpenGLES2"; case dp::ApiVersion::OpenGLES3: return "OpenGLES3"; case dp::ApiVersion::Metal: return "Metal"; case dp::ApiVersion::Vulkan: return "Vulkan"; @@ -121,9 +119,6 @@ inline dp::ApiVersion ApiVersionFromString(std::string const & str) return dp::ApiVersion::Vulkan; #endif - if (str == "OpenGLES2") - return dp::ApiVersion::OpenGLES2; - if (str == "OpenGLES3") return dp::ApiVersion::OpenGLES3; diff --git a/drape/drape_tests/font_texture_tests.cpp b/drape/drape_tests/font_texture_tests.cpp index a835e16697..3e58d99102 100644 --- a/drape/drape_tests/font_texture_tests.cpp +++ b/drape/drape_tests/font_texture_tests.cpp @@ -105,7 +105,7 @@ UNIT_TEST(UploadingGlyphs) TestingGraphicsContext context; Texture::Params p; p.m_allocator = GetDefaultAllocator(make_ref(&context)); - p.m_format = dp::TextureFormat::Alpha; + p.m_format = dp::TextureFormat::Red; p.m_width = p.m_height = kTextureSize; DummyTexture tex; diff --git a/drape/drape_tests/testing_graphics_context.hpp b/drape/drape_tests/testing_graphics_context.hpp index 95b9580c3c..e7f3d1da70 100644 --- a/drape/drape_tests/testing_graphics_context.hpp +++ b/drape/drape_tests/testing_graphics_context.hpp @@ -2,7 +2,7 @@ #include "drape/graphics_context.hpp" -// Testing context simulates OpenGLES2 API version. +// Testing context simulates OpenGLES3 API version. class TestingGraphicsContext : public dp::GraphicsContext { public: @@ -38,5 +38,5 @@ public: void SetCullingEnabled(bool enabled) override {} private: - dp::ApiVersion m_apiVersion = dp::ApiVersion::OpenGLES2; + dp::ApiVersion m_apiVersion = dp::ApiVersion::OpenGLES3; }; diff --git a/drape/font_texture.hpp b/drape/font_texture.hpp index ac25ad0948..b658ba0dc2 100644 --- a/drape/font_texture.hpp +++ b/drape/font_texture.hpp @@ -81,7 +81,7 @@ public: FontTexture(m2::PointU const & size, ref_ptr glyphMng, ref_ptr allocator) : m_index(size, glyphMng) { - DynamicTextureParams const params{size, TextureFormat::Alpha, TextureFilter::Linear, true /* m_usePixelBuffer */}; + DynamicTextureParams const params{size, TextureFormat::Red, TextureFilter::Linear, true /* m_usePixelBuffer */}; Init(allocator, make_ref(&m_index), params); } diff --git a/drape/framebuffer.cpp b/drape/framebuffer.cpp index 72b6d098b3..c2b5f4f99a 100644 --- a/drape/framebuffer.cpp +++ b/drape/framebuffer.cpp @@ -134,7 +134,7 @@ void Framebuffer::SetSize(ref_ptr context, uint32_t width, m_depthStencilRef->SetSize(context, m_width, m_height); auto const apiVersion = context->GetApiVersion(); - if (apiVersion == dp::ApiVersion::OpenGLES2 || apiVersion == dp::ApiVersion::OpenGLES3) + if (apiVersion == dp::ApiVersion::OpenGLES3) { glConst depthAttachmentId = 0; glConst stencilAttachmentId = 0; diff --git a/drape/gl_extensions_list.cpp b/drape/gl_extensions_list.cpp index bd80605cfe..a616d232d2 100644 --- a/drape/gl_extensions_list.cpp +++ b/drape/gl_extensions_list.cpp @@ -7,67 +7,14 @@ namespace dp { -void GLExtensionsList::Init(dp::ApiVersion apiVersion) +void GLExtensionsList::Init() { -#if defined(OMIM_OS_MOBILE) - if (apiVersion == dp::ApiVersion::OpenGLES2) - { #ifdef OMIM_OS_ANDROID - SetExtension(VertexArrayObject, false); - // On some Android devices glMapBufferRange/glMapBuffer works very slow. - // We have to substitute these functions to glBufferData/glBufferSubData. - SetExtension(MapBuffer, false); - SetExtension(MapBufferRange, false); -#else - CheckExtension(VertexArrayObject, "GL_OES_vertex_array_object"); - CheckExtension(MapBuffer, "GL_OES_mapbuffer"); - CheckExtension(MapBufferRange, "GL_EXT_map_buffer_range"); -#endif - CheckExtension(UintIndices, "GL_OES_element_index_uint"); - } - else - { -#ifdef OMIM_OS_ANDROID - SetExtension(MapBuffer, false); - SetExtension(MapBufferRange, false); -#else - SetExtension(MapBuffer, true); - SetExtension(MapBufferRange, true); -#endif - SetExtension(VertexArrayObject, true); - SetExtension(UintIndices, true); - } -#elif defined(OMIM_OS_LINUX) - SetExtension(MapBuffer, true); - SetExtension(UintIndices, true); - SetExtension(VertexArrayObject, true); - SetExtension(MapBufferRange, true); -#elif defined(OMIM_OS_WINDOWS) - SetExtension(MapBuffer, true); - SetExtension(UintIndices, true); - if (apiVersion == dp::ApiVersion::OpenGLES2) - { - SetExtension(VertexArrayObject, false); - SetExtension(MapBufferRange, false); - } - else - { - SetExtension(VertexArrayObject, true); - SetExtension(MapBufferRange, true); - } + // NOTE: MapBuffer/MapBufferRange are disabled by performance reasons according to + // https://github.com/organicmaps/organicmaps/commit/d72ab7c8cd8be0eb5a622d9d33ae943b391d5707 + SetExtension(MapBuffer, false); #else SetExtension(MapBuffer, true); - SetExtension(UintIndices, true); - if (apiVersion == dp::ApiVersion::OpenGLES2) - { - CheckExtension(VertexArrayObject, "GL_APPLE_vertex_array_object"); - SetExtension(MapBufferRange, false); - } - else - { - SetExtension(VertexArrayObject, true); - SetExtension(MapBufferRange, true); - } #endif } diff --git a/drape/gl_extensions_list.hpp b/drape/gl_extensions_list.hpp index c5fb4dfc1b..c962c0714c 100644 --- a/drape/gl_extensions_list.hpp +++ b/drape/gl_extensions_list.hpp @@ -14,14 +14,11 @@ class GLExtensionsList public: enum ExtensionName { - VertexArrayObject, MapBuffer, - UintIndices, - MapBufferRange }; GLExtensionsList() = default; - void Init(dp::ApiVersion apiVersion); + void Init(); bool IsSupported(ExtensionName extName) const; private: diff --git a/drape/gl_functions.cpp b/drape/gl_functions.cpp index 14c6ecf3eb..7efebf1acf 100644 --- a/drape/gl_functions.cpp +++ b/drape/gl_functions.cpp @@ -239,81 +239,26 @@ void GLFunctions::Init(dp::ApiVersion apiVersion) return; CurrentApiVersion = apiVersion; - ExtensionsList.Init(apiVersion); + ExtensionsList.Init(); s_inited = true; -/// VAO #if !defined(OMIM_OS_WINDOWS) - if (CurrentApiVersion == dp::ApiVersion::OpenGLES2) - { -#if defined(OMIM_OS_MAC) - - glGenVertexArraysFn = &glGenVertexArraysAPPLE; - glBindVertexArrayFn = &glBindVertexArrayAPPLE; - glDeleteVertexArrayFn = &glDeleteVertexArraysAPPLE; - glMapBufferFn = &::glMapBuffer; - glUnmapBufferFn = &::glUnmapBuffer; - -#elif defined(OMIM_OS_LINUX) - void *libhandle = dlopen("libGL.so.1", RTLD_LAZY); - if (!libhandle) - LOG(LCRITICAL, ("Failed to open libGL.so.1:", dlerror())); - glGenVertexArraysFn = (TglGenVertexArraysFn)dlsym(libhandle,"glGenVertexArraysOES"); - glBindVertexArrayFn = (TglBindVertexArrayFn)dlsym(libhandle, "glBindVertexArrayOES"); - glDeleteVertexArrayFn = (TglDeleteVertexArrayFn)dlsym(libhandle,"glDeleteVertexArraysOES"); - glMapBufferFn = (TglMapBufferFn)dlsym(libhandle, "glMapBufferOES"); - glUnmapBufferFn = (TglUnmapBufferFn)dlsym(libhandle, "glUnmapBufferOES"); - glMapBufferRangeFn = (TglMapBufferRangeFn)dlsym(libhandle, "glMapBufferRangeEXT"); - glFlushMappedBufferRangeFn = - (TglFlushMappedBufferRangeFn)dlsym(libhandle, "glFlushMappedBufferRangeEXT"); - -#elif defined(OMIM_OS_ANDROID) - - glGenVertexArraysFn = (TglGenVertexArraysFn)eglGetProcAddress("glGenVertexArraysOES"); - glBindVertexArrayFn = (TglBindVertexArrayFn)eglGetProcAddress("glBindVertexArrayOES"); - glDeleteVertexArrayFn = (TglDeleteVertexArrayFn)eglGetProcAddress("glDeleteVertexArraysOES"); - glMapBufferFn = &::glMapBufferOES; - glUnmapBufferFn = &::glUnmapBufferOES; - glMapBufferRangeFn = (TglMapBufferRangeFn)eglGetProcAddress("glMapBufferRangeEXT"); - glFlushMappedBufferRangeFn = - (TglFlushMappedBufferRangeFn)eglGetProcAddress("glFlushMappedBufferRangeEXT"); - -#elif defined(OMIM_OS_MOBILE) - - glGenVertexArraysFn = &glGenVertexArraysOES; - glBindVertexArrayFn = &glBindVertexArrayOES; - glDeleteVertexArrayFn = &glDeleteVertexArraysOES; - glMapBufferFn = &::glMapBufferOES; - glUnmapBufferFn = &::glUnmapBufferOES; - glMapBufferRangeFn = &::glMapBufferRangeEXT; - glFlushMappedBufferRangeFn = &::glFlushMappedBufferRangeEXT; -#endif // #if defined(OMIM_OS_MAC) - } - else if (CurrentApiVersion == dp::ApiVersion::OpenGLES3) - { - // OpenGL ES3 api is the same for all systems, except WINDOWS. - glGenVertexArraysFn = ::glGenVertexArrays; - glBindVertexArrayFn = ::glBindVertexArray; - glDeleteVertexArrayFn = ::glDeleteVertexArrays; - glUnmapBufferFn = ::glUnmapBuffer; - glMapBufferRangeFn = ::glMapBufferRange; - glFlushMappedBufferRangeFn = ::glFlushMappedBufferRange; - glGetStringiFn = ::glGetStringi; - } - else - { - CHECK(false, ("Unknown Graphics API")); - } - + // OpenGL ES3 api is the same for all systems, except WINDOWS. + glGenVertexArraysFn = ::glGenVertexArrays; + glBindVertexArrayFn = ::glBindVertexArray; + glDeleteVertexArrayFn = ::glDeleteVertexArrays; + glUnmapBufferFn = ::glUnmapBuffer; + glMapBufferRangeFn = ::glMapBufferRange; + glFlushMappedBufferRangeFn = ::glFlushMappedBufferRange; + glGetStringiFn = ::glGetStringi; #else // OMIM_OS_WINDOWS - if (ExtensionsList.IsSupported(dp::GLExtensionsList::VertexArrayObject)) - { - glGenVertexArraysFn = LOAD_GL_FUNC(TglGenVertexArraysFn, glGenVertexArrays); - glBindVertexArrayFn = LOAD_GL_FUNC(TglBindVertexArrayFn, glBindVertexArray); - glDeleteVertexArrayFn = LOAD_GL_FUNC(TglDeleteVertexArrayFn, glDeleteVertexArrays); - } - glMapBufferFn = LOAD_GL_FUNC(TglMapBufferFn, glMapBuffer); + glGenVertexArraysFn = LOAD_GL_FUNC(TglGenVertexArraysFn, glGenVertexArrays); + glBindVertexArrayFn = LOAD_GL_FUNC(TglBindVertexArrayFn, glBindVertexArray); + glDeleteVertexArrayFn = LOAD_GL_FUNC(TglDeleteVertexArrayFn, glDeleteVertexArrays); glUnmapBufferFn = LOAD_GL_FUNC(TglUnmapBufferFn, glUnmapBuffer); + glMapBufferFn = LOAD_GL_FUNC(TglMapBufferFn, glMapBuffer); + glFlushMappedBufferRangeFn = LOAD_GL_FUNC(TglFlushMappedBufferRangeFn, glFlushMappedBufferRange); + glGetStringiFn = LOAD_GL_FUNC(TglGetStringiFn, glGetStringi); #endif glClearColorFn = LOAD_GL_FUNC(TglClearColorFn, glClearColor); @@ -393,115 +338,94 @@ void GLFunctions::Init(dp::ApiVersion apiVersion) bool GLFunctions::glHasExtension(std::string const & name) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); - if (CurrentApiVersion == dp::ApiVersion::OpenGLES2) + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); + ASSERT(glGetStringiFn != nullptr, ()); + GLint n = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &n); + for (GLint i = 0; i < n; i++) { - char const * extensions = reinterpret_cast(::glGetString(GL_EXTENSIONS)); - GLCHECKCALL(); - if (extensions == nullptr) - return false; - - char const * extName = name.c_str(); - char const * ptr = nullptr; - while ((ptr = strstr(extensions, extName)) != nullptr) - { - char const * end = ptr + strlen(extName); - if (isspace(*end) || *end == '\0') - return true; - - extensions = end; - } - } - else if (CurrentApiVersion == dp::ApiVersion::OpenGLES3) - { - ASSERT(glGetStringiFn != nullptr, ()); - GLint n = 0; - glGetIntegerv(GL_NUM_EXTENSIONS, &n); - for (GLint i = 0; i < n; i++) - { - std::string const extension = - std::string(reinterpret_cast(glGetStringiFn(GL_EXTENSIONS, i))); - if (extension == name) - return true; - } + std::string const extension = + std::string(reinterpret_cast(glGetStringiFn(GL_EXTENSIONS, i))); + if (extension == name) + return true; } return false; } void GLFunctions::glClearColor(float r, float g, float b, float a) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glClearColorFn != nullptr, ()); GLCHECK(glClearColorFn(r, g, b, a)); } void GLFunctions::glClear(uint32_t clearBits) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glClearFn != nullptr, ()); GLCHECK(glClearFn(clearBits)); } void GLFunctions::glViewport(uint32_t x, uint32_t y, uint32_t w, uint32_t h) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glViewportFn != nullptr, ()); GLCHECK(glViewportFn(x, y, w, h)); } void GLFunctions::glScissor(uint32_t x, uint32_t y, uint32_t w, uint32_t h) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glScissorFn != nullptr, ()); GLCHECK(glScissorFn(x, y, w, h)); } void GLFunctions::glFlush() { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glFlushFn != nullptr, ()); GLCHECK(glFlushFn()); } void GLFunctions::glFinish() { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLCHECK(::glFinish()); } void GLFunctions::glFrontFace(glConst mode) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLCHECK(::glFrontFace(mode)); } void GLFunctions::glCullFace(glConst face) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLCHECK(::glCullFace(face)); } void GLFunctions::glStencilOpSeparate(glConst face, glConst sfail, glConst dpfail, glConst dppass) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLCHECK(::glStencilOpSeparate(face, sfail, dpfail, dppass)); } void GLFunctions::glStencilFuncSeparate(glConst face, glConst func, int ref, uint32_t mask) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLCHECK(::glStencilFuncSeparate(face, func, ref, mask)); } void GLFunctions::glPixelStore(glConst name, uint32_t value) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLCHECK(::glPixelStorei(name, value)); } int32_t GLFunctions::glGetInteger(glConst pname) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLint value; GLCHECK(::glGetIntegerv(pname, &value)); return (int32_t)value; @@ -509,7 +433,7 @@ int32_t GLFunctions::glGetInteger(glConst pname) std::string GLFunctions::glGetString(glConst pname) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); char const * str = reinterpret_cast(::glGetString(pname)); GLCHECKCALL(); if (str == nullptr) @@ -520,7 +444,7 @@ std::string GLFunctions::glGetString(glConst pname) int32_t GLFunctions::glGetMaxLineWidth() { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLint range[2]; GLCHECK(::glGetIntegerv(GL_ALIASED_LINE_WIDTH_RANGE, range)); return std::max(range[0], range[1]); @@ -528,7 +452,7 @@ int32_t GLFunctions::glGetMaxLineWidth() int32_t GLFunctions::glGetBufferParameter(glConst target, glConst name) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLint result; ASSERT(glGetBufferParameterFn != nullptr, ()); GLCHECK(glGetBufferParameterFn(target, name, &result)); @@ -537,19 +461,19 @@ int32_t GLFunctions::glGetBufferParameter(glConst target, glConst name) void GLFunctions::glEnable(glConst mode) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLCHECK(::glEnable(mode)); } void GLFunctions::glDisable(glConst mode) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLCHECK(::glDisable(mode)); } void GLFunctions::glClearDepthValue(double depth) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); #if defined(OMIM_OS_IPHONE) || defined(OMIM_OS_ANDROID) || defined(OMIM_OS_LINUX) GLCHECK(::glClearDepthf(static_cast(depth))); #else @@ -559,32 +483,32 @@ void GLFunctions::glClearDepthValue(double depth) void GLFunctions::glDepthMask(bool needWriteToDepthBuffer) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLCHECK(::glDepthMask(convert(needWriteToDepthBuffer))); } void GLFunctions::glDepthFunc(glConst depthFunc) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLCHECK(::glDepthFunc(depthFunc)); } void GLFunctions::glBlendEquation(glConst function) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glBlendEquationFn != nullptr, ()); GLCHECK(glBlendEquationFn(function)); } void GLFunctions::glBlendFunc(glConst srcFactor, glConst dstFactor) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLCHECK(::glBlendFunc(srcFactor, dstFactor)); } bool GLFunctions::CanEnableDebugMessages() { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); if (glDebugMessageCallbackFn == nullptr) return false; if (glDebugMessageControlFn == nullptr) @@ -596,7 +520,7 @@ bool GLFunctions::CanEnableDebugMessages() void GLFunctions::glDebugMessageCallback(TglDebugProc messageCallback, void * userParam) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glDebugMessageCallbackFn != nullptr, ()); GLCHECK(glDebugMessageCallbackFn(reinterpret_cast(messageCallback), userParam)); } @@ -604,14 +528,14 @@ void GLFunctions::glDebugMessageCallback(TglDebugProc messageCallback, void * us void GLFunctions::glDebugMessageControl(glConst source, glConst type, glConst severity, int32_t count, uint32_t const * ids, uint8_t enabled) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glDebugMessageControlFn != nullptr, ()); GLCHECK(glDebugMessageControlFn(source, type, severity, count, ids, enabled)); } uint32_t GLFunctions::glGenVertexArray() { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glGenVertexArraysFn != nullptr, ()); GLuint result = std::numeric_limits::max(); GLCHECK(glGenVertexArraysFn(1, &result)); @@ -620,21 +544,21 @@ uint32_t GLFunctions::glGenVertexArray() void GLFunctions::glBindVertexArray(uint32_t vao) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glBindVertexArrayFn != nullptr, ()); GLCHECK(glBindVertexArrayFn(vao)); } void GLFunctions::glDeleteVertexArray(uint32_t vao) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glDeleteVertexArrayFn != nullptr, ()); GLCHECK(glDeleteVertexArrayFn(1, &vao)); } uint32_t GLFunctions::glGenBuffer() { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glGenBuffersFn != nullptr, ()); GLuint result = std::numeric_limits::max(); GLCHECK(glGenBuffersFn(1, &result)); @@ -643,7 +567,7 @@ uint32_t GLFunctions::glGenBuffer() void GLFunctions::glBindBuffer(uint32_t vbo, uint32_t target) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glBindBufferFn != nullptr, ()); #ifdef DEBUG std::lock_guard guard(g_boundBuffersMutex); @@ -654,7 +578,7 @@ void GLFunctions::glBindBuffer(uint32_t vbo, uint32_t target) void GLFunctions::glDeleteBuffer(uint32_t vbo) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glDeleteBuffersFn != nullptr, ()); #ifdef DEBUG std::lock_guard guard(g_boundBuffersMutex); @@ -666,21 +590,21 @@ void GLFunctions::glDeleteBuffer(uint32_t vbo) void GLFunctions::glBufferData(glConst target, uint32_t size, void const * data, glConst usage) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glBufferDataFn != nullptr, ()); GLCHECK(glBufferDataFn(target, size, data, usage)); } void GLFunctions::glBufferSubData(glConst target, uint32_t size, void const * data, uint32_t offset) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glBufferSubDataFn != nullptr, ()); GLCHECK(glBufferSubDataFn(target, offset, size, data)); } void * GLFunctions::glMapBuffer(glConst target, glConst access) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glMapBufferFn != nullptr, ()); void * result = glMapBufferFn(target, access); GLCHECKCALL(); @@ -689,7 +613,7 @@ void * GLFunctions::glMapBuffer(glConst target, glConst access) void GLFunctions::glUnmapBuffer(glConst target) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glUnmapBufferFn != nullptr, ()); VERIFY(glUnmapBufferFn(target) == GL_TRUE, ()); GLCHECKCALL(); @@ -698,7 +622,7 @@ void GLFunctions::glUnmapBuffer(glConst target) void * GLFunctions::glMapBufferRange(glConst target, uint32_t offset, uint32_t length, glConst access) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glMapBufferRangeFn != nullptr, ()); void * result = glMapBufferRangeFn(target, offset, length, access); GLCHECKCALL(); @@ -707,14 +631,14 @@ void * GLFunctions::glMapBufferRange(glConst target, uint32_t offset, uint32_t l void GLFunctions::glFlushMappedBufferRange(glConst target, uint32_t offset, uint32_t length) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glFlushMappedBufferRangeFn != nullptr, ()); GLCHECK(glFlushMappedBufferRangeFn(target, offset, length)); } uint32_t GLFunctions::glCreateShader(glConst type) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glCreateShaderFn != nullptr, ()); GLuint result = glCreateShaderFn(type); GLCHECKCALL(); @@ -723,7 +647,7 @@ uint32_t GLFunctions::glCreateShader(glConst type) void GLFunctions::glShaderSource(uint32_t shaderID, std::string const & src, std::string const & defines) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glShaderSourceFn != nullptr, ()); std::string fullSrc; @@ -746,7 +670,7 @@ void GLFunctions::glShaderSource(uint32_t shaderID, std::string const & src, std bool GLFunctions::glCompileShader(uint32_t shaderID, std::string & errorLog) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glCompileShaderFn != nullptr, ()); ASSERT(glGetShaderivFn != nullptr, ()); ASSERT(glGetShaderInfoLogFn != nullptr, ()); @@ -766,14 +690,14 @@ bool GLFunctions::glCompileShader(uint32_t shaderID, std::string & errorLog) void GLFunctions::glDeleteShader(uint32_t shaderID) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glDeleteShaderFn != nullptr, ()); GLCHECK(glDeleteBuffersFn(1, &shaderID)); } uint32_t GLFunctions::glCreateProgram() { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glCreateProgramFn != nullptr, ()); GLuint result = glCreateProgramFn(); GLCHECKCALL(); @@ -782,21 +706,21 @@ uint32_t GLFunctions::glCreateProgram() void GLFunctions::glAttachShader(uint32_t programID, uint32_t shaderID) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glAttachShaderFn != nullptr, ()); GLCHECK(glAttachShaderFn(programID, shaderID)); } void GLFunctions::glDetachShader(uint32_t programID, uint32_t shaderID) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glDetachShaderFn != nullptr, ()); GLCHECK(glDetachShaderFn(programID, shaderID)); } bool GLFunctions::glLinkProgram(uint32_t programID, std::string & errorLog) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glLinkProgramFn != nullptr, ()); ASSERT(glGetProgramivFn != nullptr, ()); ASSERT(glGetProgramInfoLogFn != nullptr, ()); @@ -817,21 +741,21 @@ bool GLFunctions::glLinkProgram(uint32_t programID, std::string & errorLog) void GLFunctions::glDeleteProgram(uint32_t programID) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glDeleteProgramFn != nullptr, ()); GLCHECK(glDeleteProgramFn(programID)); } void GLFunctions::glUseProgram(uint32_t programID) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glUseProgramFn != nullptr, ()); GLCHECK(glUseProgramFn(programID)); } int8_t GLFunctions::glGetAttribLocation(uint32_t programID, std::string const & name) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glGetAttribLocationFn != nullptr, ()); int result = glGetAttribLocationFn(programID, name.c_str()); GLCHECKCALL(); @@ -841,14 +765,14 @@ int8_t GLFunctions::glGetAttribLocation(uint32_t programID, std::string const & void GLFunctions::glBindAttribLocation(uint32_t programID, uint8_t index, std::string const & name) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glBindAttribLocationFn != nullptr, ()); GLCHECK(glBindAttribLocationFn(programID, index, name.c_str())); } void GLFunctions::glEnableVertexAttribute(int attributeLocation) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glEnableVertexAttributeFn != nullptr, ()); GLCHECK(glEnableVertexAttributeFn(attributeLocation)); } @@ -856,7 +780,7 @@ void GLFunctions::glEnableVertexAttribute(int attributeLocation) void GLFunctions::glVertexAttributePointer(int attrLocation, uint32_t count, glConst type, bool needNormalize, uint32_t stride, uint32_t offset) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glVertexAttributePointerFn != nullptr, ()); GLCHECK(glVertexAttributePointerFn(attrLocation, count, type, convert(needNormalize), stride, reinterpret_cast(offset))); @@ -865,7 +789,7 @@ void GLFunctions::glVertexAttributePointer(int attrLocation, uint32_t count, glC void GLFunctions::glGetActiveUniform(uint32_t programID, uint32_t uniformIndex, int32_t * uniformSize, glConst * type, std::string & name) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glGetActiveUniformFn != nullptr, ()); GLchar buff[256]; GLCHECK(glGetActiveUniformFn(programID, uniformIndex, ARRAY_SIZE(buff), nullptr, uniformSize, @@ -875,17 +799,17 @@ void GLFunctions::glGetActiveUniform(uint32_t programID, uint32_t uniformIndex, int8_t GLFunctions::glGetUniformLocation(uint32_t programID, std::string const & name) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glGetUniformLocationFn != nullptr, ()); int result = glGetUniformLocationFn(programID, name.c_str()); GLCHECKCALL(); - ASSERT(result != -1, ()); + ASSERT(result != -1, (name)); return static_cast(result); } void GLFunctions::glUniformValuei(int8_t location, int32_t v) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glUniform1iFn != nullptr, ()); ASSERT(location != -1, ()); GLCHECK(glUniform1iFn(location, v)); @@ -893,7 +817,7 @@ void GLFunctions::glUniformValuei(int8_t location, int32_t v) void GLFunctions::glUniformValuei(int8_t location, int32_t v1, int32_t v2) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glUniform2iFn != nullptr, ()); ASSERT(location != -1, ()); GLCHECK(glUniform2iFn(location, v1, v2)); @@ -901,7 +825,7 @@ void GLFunctions::glUniformValuei(int8_t location, int32_t v1, int32_t v2) void GLFunctions::glUniformValuei(int8_t location, int32_t v1, int32_t v2, int32_t v3) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glUniform3iFn != nullptr, ()); ASSERT(location != -1, ()); GLCHECK(glUniform3iFn(location, v1, v2, v3)); @@ -909,7 +833,7 @@ void GLFunctions::glUniformValuei(int8_t location, int32_t v1, int32_t v2, int32 void GLFunctions::glUniformValuei(int8_t location, int32_t v1, int32_t v2, int32_t v3, int32_t v4) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glUniform4iFn != nullptr, ()); ASSERT(location != -1, ()); GLCHECK(glUniform4iFn(location, v1, v2, v3, v4)); @@ -917,7 +841,7 @@ void GLFunctions::glUniformValuei(int8_t location, int32_t v1, int32_t v2, int32 void GLFunctions::glUniformValueiv(int8_t location, int32_t * v, uint32_t size) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glUniform1ivFn != nullptr, ()); ASSERT(location != -1, ()); GLCHECK(glUniform1ivFn(location, size, v)); @@ -925,7 +849,7 @@ void GLFunctions::glUniformValueiv(int8_t location, int32_t * v, uint32_t size) void GLFunctions::glUniformValuef(int8_t location, float v) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glUniform1fFn != nullptr, ()); ASSERT(location != -1, ()); GLCHECK(glUniform1fFn(location, v)); @@ -933,7 +857,7 @@ void GLFunctions::glUniformValuef(int8_t location, float v) void GLFunctions::glUniformValuef(int8_t location, float v1, float v2) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glUniform2fFn != nullptr, ()); ASSERT(location != -1, ()); GLCHECK(glUniform2fFn(location, v1, v2)); @@ -941,7 +865,7 @@ void GLFunctions::glUniformValuef(int8_t location, float v1, float v2) void GLFunctions::glUniformValuef(int8_t location, float v1, float v2, float v3) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glUniform3fFn != nullptr, ()); ASSERT(location != -1, ()); GLCHECK(glUniform3fFn(location, v1, v2, v3)); @@ -949,7 +873,7 @@ void GLFunctions::glUniformValuef(int8_t location, float v1, float v2, float v3) void GLFunctions::glUniformValuef(int8_t location, float v1, float v2, float v3, float v4) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glUniform4fFn != nullptr, ()); ASSERT(location != -1, ()); GLCHECK(glUniform4fFn(location, v1, v2, v3, v4)); @@ -957,7 +881,7 @@ void GLFunctions::glUniformValuef(int8_t location, float v1, float v2, float v3, void GLFunctions::glUniformValuefv(int8_t location, float * v, uint32_t size) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glUniform1fvFn != nullptr, ()); ASSERT(location != -1, ()); GLCHECK(glUniform1fvFn(location, size, v)); @@ -965,7 +889,7 @@ void GLFunctions::glUniformValuefv(int8_t location, float * v, uint32_t size) void GLFunctions::glUniformMatrix4x4Value(int8_t location, float const * values) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glUniformMatrix4fvFn != nullptr, ()); ASSERT(location != -1, ()); GLCHECK(glUniformMatrix4fvFn(location, 1, GL_FALSE, values)); @@ -973,7 +897,7 @@ void GLFunctions::glUniformMatrix4x4Value(int8_t location, float const * values) uint32_t GLFunctions::glGetCurrentProgram() { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLint programIndex = 0; GLCHECK(glGetIntegerv(GL_CURRENT_PROGRAM, &programIndex)); ASSERT_GREATER_OR_EQUAL(programIndex, 0, ()); @@ -982,7 +906,7 @@ uint32_t GLFunctions::glGetCurrentProgram() int32_t GLFunctions::glGetProgramiv(uint32_t program, glConst paramName) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glGetProgramivFn != nullptr, ()); GLint paramValue = 0; GLCHECK(glGetProgramivFn(program, paramName, ¶mValue)); @@ -991,14 +915,14 @@ int32_t GLFunctions::glGetProgramiv(uint32_t program, glConst paramName) void GLFunctions::glActiveTexture(glConst texBlock) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glActiveTextureFn != nullptr, ()); GLCHECK(glActiveTextureFn(texBlock)); } uint32_t GLFunctions::glGenTexture() { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLuint result = std::numeric_limits::max(); GLCHECK(::glGenTextures(1, &result)); return result; @@ -1006,20 +930,20 @@ uint32_t GLFunctions::glGenTexture() void GLFunctions::glDeleteTexture(uint32_t id) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLCHECK(::glDeleteTextures(1, &id)); } void GLFunctions::glBindTexture(uint32_t textureID) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLCHECK(::glBindTexture(GL_TEXTURE_2D, textureID)); } void GLFunctions::glTexImage2D(int width, int height, glConst layout, glConst pixelType, void const * data) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); // In OpenGL ES3: // - we can't create unsized GL_RED texture, so we use GL_R8; // - we can't create unsized GL_RG texture, so we use GL_RG8; @@ -1058,20 +982,20 @@ void GLFunctions::glTexImage2D(int width, int height, glConst layout, glConst pi void GLFunctions::glTexSubImage2D(int x, int y, int width, int height, glConst layout, glConst pixelType, void const * data) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLCHECK(::glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, layout, pixelType, data)); } void GLFunctions::glTexParameter(glConst param, glConst value) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLCHECK(::glTexParameteri(GL_TEXTURE_2D, param, value)); } void GLFunctions::glDrawElements(glConst primitive, uint32_t sizeOfIndex, uint32_t indexCount, uint32_t startIndex) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLCHECK(::glDrawElements(primitive, indexCount, sizeOfIndex == sizeof(uint32_t) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, reinterpret_cast(startIndex * sizeOfIndex))); @@ -1079,41 +1003,41 @@ void GLFunctions::glDrawElements(glConst primitive, uint32_t sizeOfIndex, uint32 void GLFunctions::glDrawArrays(glConst mode, int32_t first, uint32_t count) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLCHECK(::glDrawArrays(mode, first, count)); } void GLFunctions::glGenFramebuffer(uint32_t * fbo) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glGenFramebuffersFn != nullptr, ()); GLCHECK(glGenFramebuffersFn(1, fbo)); } void GLFunctions::glDeleteFramebuffer(uint32_t * fbo) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glDeleteFramebuffersFn != nullptr, ()); GLCHECK(glDeleteFramebuffersFn(1, fbo)); } void GLFunctions::glFramebufferTexture2D(glConst attachment, glConst texture) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glFramebufferTexture2DFn != nullptr, ()); GLCHECK(glFramebufferTexture2DFn(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, texture, 0)); } void GLFunctions::glBindFramebuffer(uint32_t fbo) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glBindFramebufferFn != nullptr, ()); GLCHECK(glBindFramebufferFn(GL_FRAMEBUFFER, fbo)); } uint32_t GLFunctions::glCheckFramebufferStatus() { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); ASSERT(glCheckFramebufferStatusFn != nullptr, ()); uint32_t const result = glCheckFramebufferStatusFn(GL_FRAMEBUFFER); GLCHECKCALL(); @@ -1122,7 +1046,7 @@ uint32_t GLFunctions::glCheckFramebufferStatus() void GLFunctions::glLineWidth(uint32_t value) { - ASSERT_NOT_EQUAL(CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLCHECK(::glLineWidth(static_cast(value))); } @@ -1143,7 +1067,7 @@ std::string GetGLError(GLenum error) void CheckGLError(base::SrcPoint const & srcPoint) { - ASSERT_NOT_EQUAL(GLFunctions::CurrentApiVersion, dp::ApiVersion::Invalid, ()); + ASSERT_EQUAL(GLFunctions::CurrentApiVersion, dp::ApiVersion::OpenGLES3, ()); GLenum result = glGetError(); while (result != GL_NO_ERROR) { diff --git a/drape/gl_gpu_program.cpp b/drape/gl_gpu_program.cpp index 3a3bfedbcf..2778a38ec7 100644 --- a/drape/gl_gpu_program.cpp +++ b/drape/gl_gpu_program.cpp @@ -23,26 +23,14 @@ GLGpuProgram::GLGpuProgram(std::string const & programName, if (!GLFunctions::glLinkProgram(m_programID, errorLog)) LOG(LERROR, ("Program ", programName, " link error = ", errorLog)); - // On Tegra3 glGetActiveUniform isn't work if you detach shaders after linking. LoadUniformLocations(); - // On Tegra2 we cannot detach shaders at all. - // https://devtalk.nvidia.com/default/topic/528941/alpha-blending-not-working-on-t20-and-t30-under-ice-cream-sandwich/ - if (!SupportManager::Instance().IsTegraDevice()) - { - GLFunctions::glDetachShader(m_programID, m_vertexShader->GetID()); - GLFunctions::glDetachShader(m_programID, m_fragmentShader->GetID()); - } + GLFunctions::glDetachShader(m_programID, m_vertexShader->GetID()); + GLFunctions::glDetachShader(m_programID, m_fragmentShader->GetID()); } GLGpuProgram::~GLGpuProgram() { - if (SupportManager::Instance().IsTegraDevice()) - { - GLFunctions::glDetachShader(m_programID, m_vertexShader->GetID()); - GLFunctions::glDetachShader(m_programID, m_fragmentShader->GetID()); - } - GLFunctions::glDeleteProgram(m_programID); } @@ -107,7 +95,7 @@ void GLGpuProgram::LoadUniformLocations() std::string name; GLFunctions::glGetActiveUniform(m_programID, static_cast(i), &size, &info.m_type, name); CHECK(kSupportedTypes.find(info.m_type) != kSupportedTypes.cend(), - ("Used uniform has unsupported type. Program =", m_programName, "Type =", info.m_type)); + ("Used uniform has unsupported type. Program =", m_programName, "; Type =", info.m_type, "; Name =", name)); info.m_location = GLFunctions::glGetUniformLocation(m_programID, name); m_uniforms[name] = std::move(info); diff --git a/drape/gpu_buffer.cpp b/drape/gpu_buffer.cpp index af84906909..a280aeddd3 100644 --- a/drape/gpu_buffer.cpp +++ b/drape/gpu_buffer.cpp @@ -87,26 +87,17 @@ void * GPUBuffer::Map(uint32_t elementOffset, uint32_t elementCount) m_isMapped = true; #endif - if (GLFunctions::CurrentApiVersion == dp::ApiVersion::OpenGLES2) + if (!IsMapBufferSupported()) { m_mappingOffset = elementOffset; - return IsMapBufferSupported() ? GLFunctions::glMapBuffer(glTarget(m_t)) : nullptr; + return nullptr; } - else if (GLFunctions::CurrentApiVersion == dp::ApiVersion::OpenGLES3) - { - if (!IsMapBufferSupported()) - { - m_mappingOffset = elementOffset; - return nullptr; - } - m_mappingOffset = 0; - uint32_t const elementSize = GetElementSize(); - uint32_t const byteOffset = elementOffset * elementSize; - uint32_t const byteCount = elementCount * elementSize; - return GLFunctions::glMapBufferRange(glTarget(m_t), byteOffset, byteCount, - gl_const::GLWriteBufferBit); - } - return nullptr; + m_mappingOffset = 0; + uint32_t const elementSize = GetElementSize(); + uint32_t const byteOffset = elementOffset * elementSize; + uint32_t const byteCount = elementCount * elementSize; + return GLFunctions::glMapBufferRange(glTarget(m_t), byteOffset, byteCount, + gl_const::GLWriteBufferBit); } void GPUBuffer::UpdateData(void * gpuPtr, void const * data, uint32_t elementOffset, diff --git a/drape/hw_texture.cpp b/drape/hw_texture.cpp index 560e8978f3..1d99e20284 100644 --- a/drape/hw_texture.cpp +++ b/drape/hw_texture.cpp @@ -36,7 +36,7 @@ void UnpackFormat(ref_ptr context, TextureFormat format, glConst & layout, glConst & pixelType) { auto const apiVersion = context->GetApiVersion(); - CHECK(apiVersion == dp::ApiVersion::OpenGLES2 || apiVersion == dp::ApiVersion::OpenGLES3, ()); + CHECK(apiVersion == dp::ApiVersion::OpenGLES3, ()); switch (format) { @@ -45,21 +45,17 @@ void UnpackFormat(ref_ptr context, TextureFormat format, pixelType = gl_const::GL8BitOnChannel; return; - case TextureFormat::Alpha: - // On OpenGL ES3 GLAlpha is not supported, we use GLRed instead. - layout = apiVersion == dp::ApiVersion::OpenGLES2 ? gl_const::GLAlpha : gl_const::GLRed; + case TextureFormat::Red: + layout = gl_const::GLRed; pixelType = gl_const::GL8BitOnChannel; return; case TextureFormat::RedGreen: - // On OpenGL ES2 2-channel textures are not supported. - layout = (apiVersion == dp::ApiVersion::OpenGLES2) ? gl_const::GLRGBA : gl_const::GLRedGreen; + layout = gl_const::GLRedGreen; pixelType = gl_const::GL8BitOnChannel; return; case TextureFormat::DepthStencil: - // OpenGLES2 does not support texture-based depth-stencil. - CHECK(apiVersion != dp::ApiVersion::OpenGLES2, ()); layout = gl_const::GLDepthStencil; pixelType = gl_const::GLUnsignedInt24_8Type; return; diff --git a/drape/hw_texture_ios.mm b/drape/hw_texture_ios.mm index f83725f411..658ce02e03 100644 --- a/drape/hw_texture_ios.mm +++ b/drape/hw_texture_ios.mm @@ -61,7 +61,7 @@ CVPixelBufferRef HWTextureAllocatorApple::CVCreatePixelBuffer(uint32_t width, ui cvRetval = CVPixelBufferCreate(kCFAllocatorDefault, width, height, kCVPixelFormatType_32BGRA, attrsRef, &result); break; - case dp::TextureFormat::Alpha: + case dp::TextureFormat::Red: cvRetval = CVPixelBufferCreate(kCFAllocatorDefault, width, height, kCVPixelFormatType_OneComponent8, attrsRef, &result); break; diff --git a/drape/index_storage.cpp b/drape/index_storage.cpp index 5f6bb8fc91..3432e8be9f 100644 --- a/drape/index_storage.cpp +++ b/drape/index_storage.cpp @@ -56,7 +56,7 @@ void const * IndexStorage::GetRawConst() const bool IndexStorage::IsSupported32bit() { // We do not use 32-bit indices now to reduce size of index buffers. - static bool const supports32Bit = false;//GLFunctions::ExtensionsList.IsSupported(GLExtensionsList::UintIndices); + static bool const supports32Bit = false; return supports32Bit; } diff --git a/drape/mesh_object.cpp b/drape/mesh_object.cpp index 525c31b0cb..4fbaa899e0 100644 --- a/drape/mesh_object.cpp +++ b/drape/mesh_object.cpp @@ -36,13 +36,8 @@ public: { UNUSED_VALUE(context); - bool const isVAOSupported = - GLFunctions::ExtensionsList.IsSupported(dp::GLExtensionsList::VertexArrayObject); - if (isVAOSupported) - { - m_VAO = GLFunctions::glGenVertexArray(); - GLFunctions::glBindVertexArray(m_VAO); - } + m_VAO = GLFunctions::glGenVertexArray(); + GLFunctions::glBindVertexArray(m_VAO); for (auto & buffer : m_mesh->m_buffers) { @@ -64,23 +59,19 @@ public: m_mesh->m_indices.data(), gl_const::GLStaticDraw); } - if (isVAOSupported) + ref_ptr p = program; + for (auto const & attribute : buffer->m_attributes) { - ref_ptr p = program; - for (auto const & attribute : buffer->m_attributes) - { - int8_t const attributePosition = p->GetAttributeLocation(attribute.m_attributeName); - ASSERT_NOT_EQUAL(attributePosition, -1, ()); - GLFunctions::glEnableVertexAttribute(attributePosition); - GLFunctions::glVertexAttributePointer(attributePosition, attribute.m_componentsCount, - attribute.m_type, false, buffer->GetStrideInBytes(), - attribute.m_offset); - } + int8_t const attributePosition = p->GetAttributeLocation(attribute.m_attributeName); + ASSERT_NOT_EQUAL(attributePosition, -1, ()); + GLFunctions::glEnableVertexAttribute(attributePosition); + GLFunctions::glVertexAttributePointer(attributePosition, attribute.m_componentsCount, + attribute.m_type, false, buffer->GetStrideInBytes(), + attribute.m_offset); } } - if (isVAOSupported) - GLFunctions::glBindVertexArray(0); + GLFunctions::glBindVertexArray(0); GLFunctions::glBindBuffer(0, gl_const::GLArrayBuffer); if (!m_mesh->m_indices.empty()) GLFunctions::glBindBuffer(0, gl_const::GLElementArrayBuffer); @@ -134,34 +125,12 @@ public: void Bind(ref_ptr program) override { - if (GLFunctions::ExtensionsList.IsSupported(dp::GLExtensionsList::VertexArrayObject)) - { - GLFunctions::glBindVertexArray(m_VAO); - return; - } - - ref_ptr p = program; - for (auto const & buffer : m_mesh->m_buffers) - { - GLFunctions::glBindBuffer(buffer->m_bufferId, gl_const::GLArrayBuffer); - if (m_indexBuffer != 0) - GLFunctions::glBindBuffer(m_indexBuffer, gl_const::GLElementArrayBuffer); - for (auto const & attribute : buffer->m_attributes) - { - int8_t const attributePosition = p->GetAttributeLocation(attribute.m_attributeName); - ASSERT_NOT_EQUAL(attributePosition, -1, ()); - GLFunctions::glEnableVertexAttribute(attributePosition); - GLFunctions::glVertexAttributePointer(attributePosition, attribute.m_componentsCount, - attribute.m_type, false, buffer->GetStrideInBytes(), - attribute.m_offset); - } - } + GLFunctions::glBindVertexArray(m_VAO); } void Unbind() override { - if (GLFunctions::ExtensionsList.IsSupported(dp::GLExtensionsList::VertexArrayObject)) - GLFunctions::glBindVertexArray(0); + GLFunctions::glBindVertexArray(0); GLFunctions::glBindBuffer(0, gl_const::GLArrayBuffer); if (m_indexBuffer != 0) GLFunctions::glBindBuffer(0, gl_const::GLElementArrayBuffer); @@ -197,7 +166,7 @@ MeshObject::MeshObject(ref_ptr context, DrawPrimitive drawP , m_debugName(debugName) { auto const apiVersion = context->GetApiVersion(); - if (apiVersion == dp::ApiVersion::OpenGLES2 || apiVersion == dp::ApiVersion::OpenGLES3) + if (apiVersion == dp::ApiVersion::OpenGLES3) { InitForOpenGL(); } diff --git a/drape/metal/metal_texture.mm b/drape/metal/metal_texture.mm index cd0a946171..89d674ef00 100644 --- a/drape/metal/metal_texture.mm +++ b/drape/metal/metal_texture.mm @@ -25,7 +25,7 @@ MTLPixelFormat UnpackFormat(TextureFormat format) switch (format) { case TextureFormat::RGBA8: return MTLPixelFormatRGBA8Unorm; - case TextureFormat::Alpha: return MTLPixelFormatA8Unorm; + case TextureFormat::Red: return MTLPixelFormatA8Unorm; // TODO: change to R8, fix shaders case TextureFormat::RedGreen: return MTLPixelFormatRG8Unorm; case TextureFormat::DepthStencil: return MTLPixelFormatDepth32Float_Stencil8; case TextureFormat::Depth: return MTLPixelFormatDepth32Float; diff --git a/drape/render_state.cpp b/drape/render_state.cpp index 5c09fd8078..55611a2030 100644 --- a/drape/render_state.cpp +++ b/drape/render_state.cpp @@ -30,7 +30,7 @@ void AlphaBlendingState::Apply(ref_ptr context) { // For Metal Rendering these settings must be set in the pipeline state. auto const apiVersion = context->GetApiVersion(); - if (apiVersion == dp::ApiVersion::OpenGLES2 || apiVersion == dp::ApiVersion::OpenGLES3) + if (apiVersion == dp::ApiVersion::OpenGLES3) { GLFunctions::glBlendEquation(gl_const::GLAddBlend); GLFunctions::glBlendFunc(gl_const::GLSrcAlpha, gl_const::GLOneMinusSrcAlpha); @@ -45,7 +45,7 @@ void Blending::Apply(ref_ptr context, ref_ptr progr { // For Metal Rendering these settings must be set in the pipeline state. auto const apiVersion = context->GetApiVersion(); - if (apiVersion == dp::ApiVersion::OpenGLES2 || apiVersion == dp::ApiVersion::OpenGLES3) + if (apiVersion == dp::ApiVersion::OpenGLES3) { if (m_isEnabled) GLFunctions::glEnable(gl_const::GLBlending); @@ -216,7 +216,7 @@ void TextureState::ApplyTextures(ref_ptr context, RenderState c { m_usedSlots = 0; auto const apiVersion = context->GetApiVersion(); - if (apiVersion == dp::ApiVersion::OpenGLES2 || apiVersion == dp::ApiVersion::OpenGLES3) + if (apiVersion == dp::ApiVersion::OpenGLES3) { ref_ptr p = program; for (auto const & texture : state.GetTextures()) @@ -324,7 +324,7 @@ void ApplyState(ref_ptr context, ref_ptr program, R if (state.GetDrawAsLine()) { - if (apiVersion == dp::ApiVersion::OpenGLES2 || apiVersion == dp::ApiVersion::OpenGLES3) + if (apiVersion == dp::ApiVersion::OpenGLES3) { ASSERT_GREATER_OR_EQUAL(state.GetLineWidth(), 0, ()); GLFunctions::glLineWidth(static_cast(state.GetLineWidth())); diff --git a/drape/stipple_pen_resource.cpp b/drape/stipple_pen_resource.cpp index cb642f0aee..6158d1ed03 100644 --- a/drape/stipple_pen_resource.cpp +++ b/drape/stipple_pen_resource.cpp @@ -175,7 +175,7 @@ ref_ptr StipplePenIndex::MapResource(StipplePenKey const void StipplePenIndex::UploadResources(ref_ptr context, ref_ptr texture) { - ASSERT(texture->GetFormat() == dp::TextureFormat::Alpha, ()); + ASSERT(texture->GetFormat() == dp::TextureFormat::Red, ()); TPendingNodes pendingNodes; { std::lock_guard g(m_lock); diff --git a/drape/stipple_pen_resource.hpp b/drape/stipple_pen_resource.hpp index b8788ad731..7629c38ade 100644 --- a/drape/stipple_pen_resource.hpp +++ b/drape/stipple_pen_resource.hpp @@ -138,7 +138,7 @@ public: StipplePenTexture(m2::PointU const & size, ref_ptr allocator) : m_index(size) { - TBase::DynamicTextureParams params{size, TextureFormat::Alpha, TextureFilter::Nearest, + TBase::DynamicTextureParams params{size, TextureFormat::Red, TextureFilter::Nearest, false /* m_usePixelBuffer */}; TBase::Init(allocator, make_ref(&m_index), params); } diff --git a/drape/support_manager.cpp b/drape/support_manager.cpp index ca956a7187..3b213636ea 100644 --- a/drape/support_manager.cpp +++ b/drape/support_manager.cpp @@ -32,31 +32,8 @@ void SupportManager::Init(ref_ptr context) m_rendererVersion = context->GetRendererVersion(); LOG(LINFO, ("Renderer =", m_rendererName, "| Api =", context->GetApiVersion(), "| Version =", m_rendererVersion)); - m_isSamsungGoogleNexus = (m_rendererName == "PowerVR SGX 540" && - m_rendererVersion.find("GOOGLENEXUS.ED945322") != std::string::npos); - if (m_isSamsungGoogleNexus) - LOG(LINFO, ("Samsung Google Nexus detected.")); - - if (m_rendererName.find("Adreno") != std::string::npos) - { - std::array constexpr models = { "200", "203", "205", "220", "225" }; - for (auto const & model : models) - { - if (m_rendererName.find(model) != std::string::npos) - { - LOG(LINFO, ("Adreno 200 device detected.")); - m_isAdreno200 = true; - break; - } - } - } - - m_isTegra = (m_rendererName.find("Tegra") != std::string::npos); - if (m_isTegra) - LOG(LINFO, ("NVidia Tegra device detected.")); - auto const apiVersion = context->GetApiVersion(); - if (apiVersion == dp::ApiVersion::OpenGLES2 || apiVersion == dp::ApiVersion::OpenGLES3) + if (apiVersion == dp::ApiVersion::OpenGLES3) { m_maxLineWidth = static_cast(std::max(1, GLFunctions::glGetMaxLineWidth())); m_maxTextureSize = static_cast(GLFunctions::glGetInteger(gl_const::GLMaxTextureSize)); diff --git a/drape/support_manager.hpp b/drape/support_manager.hpp index fe2c54f4b9..f84c085b1c 100644 --- a/drape/support_manager.hpp +++ b/drape/support_manager.hpp @@ -26,9 +26,6 @@ public: // reinitialization. void Init(ref_ptr context); - bool IsSamsungGoogleNexus() const { return m_isSamsungGoogleNexus; } - bool IsAdreno200Device() const { return m_isAdreno200; } - bool IsTegraDevice() const { return m_isTegra; } bool IsAntialiasingEnabledByDefault() const { return m_isAntialiasingEnabledByDefault; } float GetMaxLineWidth() const { return m_maxLineWidth; } @@ -50,9 +47,6 @@ private: std::string m_rendererName; std::string m_rendererVersion; - bool m_isSamsungGoogleNexus = false; - bool m_isAdreno200 = false; - bool m_isTegra = false; bool m_isAntialiasingEnabledByDefault = false; float m_maxLineWidth = 1; diff --git a/drape/texture_manager.cpp b/drape/texture_manager.cpp index 00db093e56..d688e27294 100644 --- a/drape/texture_manager.cpp +++ b/drape/texture_manager.cpp @@ -183,7 +183,7 @@ bool TextureManager::UpdateDynamicTextures(ref_ptr context) if (m_nothingToUpload.test_and_set()) { auto const apiVersion = context->GetApiVersion(); - if (apiVersion == dp::ApiVersion::OpenGLES2 || apiVersion == dp::ApiVersion::OpenGLES3) + if (apiVersion == dp::ApiVersion::OpenGLES3) { // For some reasons OpenGL can not update textures immediately. // Here we use some timeout to prevent rendering frozening. @@ -302,7 +302,7 @@ void TextureManager::Init(ref_ptr context, Params const & p m_maxTextureSize = std::min(kMaxTextureSize, dp::SupportManager::Instance().GetMaxTextureSize()); auto const apiVersion = context->GetApiVersion(); - if (apiVersion == dp::ApiVersion::OpenGLES2 || apiVersion == dp::ApiVersion::OpenGLES3) + if (apiVersion == dp::ApiVersion::OpenGLES3) GLFunctions::glPixelStore(gl_const::GLUnpackAlignment, 1); // Initialize symbols. @@ -323,16 +323,13 @@ void TextureManager::Init(ref_ptr context, Params const & p CreateArrowTexture(context, make_ref(m_textureAllocator), params.m_arrowTexturePath, params.m_arrowTextureUseDefaultResourceFolder); - // SMAA is not supported on OpenGL ES2. - if (apiVersion != dp::ApiVersion::OpenGLES2) - { - m_smaaAreaTexture = - make_unique_dp(context, "smaa-area.png", StaticTexture::kDefaultResource, - dp::TextureFormat::RedGreen, make_ref(m_textureAllocator)); - m_smaaSearchTexture = - make_unique_dp(context, "smaa-search.png", StaticTexture::kDefaultResource, - dp::TextureFormat::Alpha, make_ref(m_textureAllocator)); - } + // SMAA. + m_smaaAreaTexture = + make_unique_dp(context, "smaa-area.png", StaticTexture::kDefaultResource, + dp::TextureFormat::RedGreen, make_ref(m_textureAllocator)); + m_smaaSearchTexture = + make_unique_dp(context, "smaa-search.png", StaticTexture::kDefaultResource, + dp::TextureFormat::Red, make_ref(m_textureAllocator)); // Initialize patterns (reserved ./data/patterns.txt lines count). std::set patterns; diff --git a/drape/texture_types.hpp b/drape/texture_types.hpp index 5aa79221d5..ff95c59d3a 100644 --- a/drape/texture_types.hpp +++ b/drape/texture_types.hpp @@ -9,7 +9,7 @@ namespace dp enum class TextureFormat : uint8_t { RGBA8, - Alpha, + Red, RedGreen, DepthStencil, Depth, @@ -21,7 +21,7 @@ inline std::string DebugPrint(TextureFormat tf) switch (tf) { case TextureFormat::RGBA8: return "RGBA8"; - case TextureFormat::Alpha: return "Alpha"; + case TextureFormat::Red: return "Red"; case TextureFormat::RedGreen: return "RedGreen"; case TextureFormat::DepthStencil: return "DepthStencil"; case TextureFormat::Depth: return "Depth"; @@ -50,7 +50,7 @@ inline uint8_t GetBytesPerPixel(TextureFormat format) switch (format) { case TextureFormat::RGBA8: result = 4; break; - case TextureFormat::Alpha: result = 1; break; + case TextureFormat::Red: result = 1; break; case TextureFormat::RedGreen: result = 2; break; case TextureFormat::DepthStencil: result = 4; break; case TextureFormat::Depth: result = 4; break; diff --git a/drape/vertex_array_buffer.cpp b/drape/vertex_array_buffer.cpp index 6190fa0298..8c417bfcde 100644 --- a/drape/vertex_array_buffer.cpp +++ b/drape/vertex_array_buffer.cpp @@ -56,9 +56,6 @@ public: return false; m_program = program; - // If OES_vertex_array_object not supported, than buffers will be bound on each render call. - if (!GLFunctions::ExtensionsList.IsSupported(GLExtensionsList::VertexArrayObject)) - return false; if (m_VAO != 0) GLFunctions::glDeleteVertexArray(m_VAO); @@ -68,19 +65,14 @@ public: bool Bind() override { - if (GLFunctions::ExtensionsList.IsSupported(GLExtensionsList::VertexArrayObject)) - { - ASSERT(m_VAO != 0, ("You need to call Build method before bind it and render.")); - GLFunctions::glBindVertexArray(m_VAO); - return true; - } - return false; + ASSERT(m_VAO != 0, ("You need to call Build method before bind it and render.")); + GLFunctions::glBindVertexArray(m_VAO); + return true; } void Unbind() override { - if (GLFunctions::ExtensionsList.IsSupported(GLExtensionsList::VertexArrayObject)) - GLFunctions::glBindVertexArray(0); + GLFunctions::glBindVertexArray(0); } void BindBuffers(BuffersMap const & buffers) const override @@ -126,10 +118,6 @@ VertexArrayBuffer::VertexArrayBuffer(uint32_t indexBufferSize, uint32_t dataBuff , m_batcherHash(batcherHash) { m_indexBuffer = make_unique_dp(indexBufferSize); - - // Adreno 200 GPUs aren't able to share OpenGL resources between 2 OGL-contexts correctly, - // so we have to create and destroy VBO on one context. - m_moveToGpuOnBuild = SupportManager::Instance().IsAdreno200Device(); } VertexArrayBuffer::~VertexArrayBuffer() @@ -142,8 +130,7 @@ VertexArrayBuffer::~VertexArrayBuffer() void VertexArrayBuffer::Preflush(ref_ptr context) { - if (!m_moveToGpuOnBuild) - PreflushImpl(context); + PreflushImpl(context); } void VertexArrayBuffer::PreflushImpl(ref_ptr context) @@ -163,7 +150,7 @@ void VertexArrayBuffer::PreflushImpl(ref_ptr context) // Preflush can be called on BR, where impl is not initialized. // For Metal rendering this code has no meaning. auto const apiVersion = context->GetApiVersion(); - if (apiVersion == dp::ApiVersion::OpenGLES2 || apiVersion == dp::ApiVersion::OpenGLES3) + if (apiVersion == dp::ApiVersion::OpenGLES3) { GLFunctions::glBindBuffer(0, gl_const::GLElementArrayBuffer); GLFunctions::glBindBuffer(0, gl_const::GLArrayBuffer); @@ -199,7 +186,7 @@ void VertexArrayBuffer::RenderRange(ref_ptr context, void VertexArrayBuffer::Build(ref_ptr context, ref_ptr program) { - if (m_moveToGpuOnBuild && !m_isPreflushed) + if (!m_isPreflushed) PreflushImpl(context); if (!HasBuffers()) @@ -208,7 +195,7 @@ void VertexArrayBuffer::Build(ref_ptr context, ref_ptrGetApiVersion(); - if (apiVersion == dp::ApiVersion::OpenGLES2 || apiVersion == dp::ApiVersion::OpenGLES3) + if (apiVersion == dp::ApiVersion::OpenGLES3) { m_impl = make_unique_dp(); } diff --git a/drape/vertex_array_buffer.hpp b/drape/vertex_array_buffer.hpp index 34a7277049..bc4f69fccc 100644 --- a/drape/vertex_array_buffer.hpp +++ b/drape/vertex_array_buffer.hpp @@ -124,7 +124,6 @@ private: drape_ptr m_indexBuffer; bool m_isPreflushed = false; - bool m_moveToGpuOnBuild = false; bool m_isChanged = false; BindingInfoArray m_bindingInfo; uint8_t m_bindingInfoCount = 0; diff --git a/drape/vulkan/vulkan_utils.cpp b/drape/vulkan/vulkan_utils.cpp index f32af92f3d..1472358e8d 100644 --- a/drape/vulkan/vulkan_utils.cpp +++ b/drape/vulkan/vulkan_utils.cpp @@ -158,7 +158,7 @@ VkFormat VulkanFormatUnpacker::Unpack(TextureFormat format) switch (format) { case TextureFormat::RGBA8: return VK_FORMAT_R8G8B8A8_UNORM; - case TextureFormat::Alpha: return VK_FORMAT_R8_UNORM; + case TextureFormat::Red: return VK_FORMAT_R8_UNORM; case TextureFormat::RedGreen: return VK_FORMAT_R8G8_UNORM; #if defined(OMIM_OS_MAC) case TextureFormat::DepthStencil: return VK_FORMAT_D32_SFLOAT_S8_UINT; diff --git a/drape_frontend/arrow3d.cpp b/drape_frontend/arrow3d.cpp index 48bf8f6e60..d763407571 100644 --- a/drape_frontend/arrow3d.cpp +++ b/drape_frontend/arrow3d.cpp @@ -308,7 +308,7 @@ Arrow3d::Arrow3d(ref_ptr context, ref_ptrGetApiVersion(); - if (apiVersion == dp::ApiVersion::OpenGLES2 || apiVersion == dp::ApiVersion::OpenGLES3) + if (apiVersion == dp::ApiVersion::OpenGLES3) m_state.SetColorTexture(texMng->GetSymbolsTexture()); m_isValid = preloadedData.m_meshData.has_value(); diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index 8f0861e488..2904ef8eb2 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -1426,7 +1426,7 @@ void FrontendRenderer::RenderScene(ScreenBase const & modelView, bool activeFram RefreshBgColor(); uint32_t clearBits = dp::ClearBits::ColorBit | dp::ClearBits::DepthBit; - if (m_apiVersion == dp::ApiVersion::OpenGLES2 || m_apiVersion == dp::ApiVersion::OpenGLES3) + if (m_apiVersion == dp::ApiVersion::OpenGLES3) clearBits |= dp::ClearBits::StencilBit; uint32_t storeBits = dp::ClearBits::ColorBit; @@ -1524,7 +1524,7 @@ void FrontendRenderer::RenderScene(ScreenBase const & modelView, bool activeFram if (IsValidCurrentZoom()) { uint32_t clearBits = dp::ClearBits::DepthBit; - if (m_apiVersion == dp::ApiVersion::OpenGLES2 || m_apiVersion == dp::ApiVersion::OpenGLES3) + if (m_apiVersion == dp::ApiVersion::OpenGLES3) clearBits |= dp::ClearBits::StencilBit; m_context->Clear(clearBits, dp::kClearBitsStoreAll); diff --git a/drape_frontend/gui/layer_render.cpp b/drape_frontend/gui/layer_render.cpp index bace4c1a54..5ab3239c9a 100644 --- a/drape_frontend/gui/layer_render.cpp +++ b/drape_frontend/gui/layer_render.cpp @@ -369,7 +369,6 @@ void LayerCacher::CacheScaleFpsLabel(ref_ptr context, Posit std::string apiLabel; switch (apiVersion) { - case dp::ApiVersion::OpenGLES2: apiLabel = "GL2"; break; case dp::ApiVersion::OpenGLES3: apiLabel = "GL3"; break; case dp::ApiVersion::Metal: apiLabel = "M"; break; case dp::ApiVersion::Vulkan: apiLabel = "V"; break; diff --git a/drape_frontend/postprocess_renderer.cpp b/drape_frontend/postprocess_renderer.cpp index 0118f5dd1e..083eeabe28 100644 --- a/drape_frontend/postprocess_renderer.cpp +++ b/drape_frontend/postprocess_renderer.cpp @@ -203,10 +203,6 @@ bool PostprocessRenderer::IsEnabled() const void PostprocessRenderer::SetEffectEnabled(ref_ptr context, Effect effect, bool enabled) { - // Do not support AA for OpenGLES 2.0. - if (m_apiVersion == dp::ApiVersion::OpenGLES2 && effect == Effect::Antialiasing) - return; - auto const oldValue = m_effects; auto const effectMask = static_cast(effect); m_effects = (m_effects & ~effectMask) | (enabled ? effectMask : 0); @@ -238,7 +234,7 @@ bool PostprocessRenderer::CanRenderAntialiasing() const return false; } - if (m_apiVersion == dp::ApiVersion::OpenGLES2 || m_apiVersion == dp::ApiVersion::OpenGLES3) + if (m_apiVersion == dp::ApiVersion::OpenGLES3) { return m_staticTextures->m_smaaAreaTexture->GetID() != 0 && m_staticTextures->m_smaaSearchTexture->GetID() != 0; @@ -289,7 +285,7 @@ bool PostprocessRenderer::EndFrame(ref_ptr context, ASSERT(m_staticTextures->m_smaaAreaTexture != nullptr, ()); ASSERT(m_staticTextures->m_smaaSearchTexture != nullptr, ()); - if (m_apiVersion == dp::ApiVersion::OpenGLES2 || m_apiVersion == dp::ApiVersion::OpenGLES3) + if (m_apiVersion == dp::ApiVersion::OpenGLES3) { ASSERT_GREATER(m_staticTextures->m_smaaAreaTexture->GetID(), 0, ()); ASSERT_GREATER(m_staticTextures->m_smaaSearchTexture->GetID(), 0, ()); @@ -418,15 +414,12 @@ void PostprocessRenderer::UpdateFramebuffers(ref_ptr contex ASSERT_NOT_EQUAL(height, 0, ()); CHECK_EQUAL(m_apiVersion, context->GetApiVersion(), ()); - InitFramebuffer(context, m_mainFramebuffer, width, height, true /* depthEnabled */, - m_apiVersion != dp::ApiVersion::OpenGLES2 /* stencilEnabled */); + InitFramebuffer(context, m_mainFramebuffer, width, height, true /* depthEnabled */, true /* stencilEnabled */); m_isMainFramebufferRendered = false; m_isSmaaFramebufferRendered = false; if (!m_isRouteFollowingActive && IsEffectEnabled(Effect::Antialiasing)) { - CHECK_NOT_EQUAL(m_apiVersion, dp::ApiVersion::OpenGLES2, ()); - InitFramebuffer(context, m_edgesFramebuffer, dp::TextureFormat::RedGreen, m_mainFramebuffer->GetDepthStencilRef(), width, height); diff --git a/iphone/Maps/Classes/EAGLView.mm b/iphone/Maps/Classes/EAGLView.mm index 1a730321c2..9c14c163ff 100644 --- a/iphone/Maps/Classes/EAGLView.mm +++ b/iphone/Maps/Classes/EAGLView.mm @@ -81,7 +81,7 @@ double getExactDPI(double contentScaleFactor) if (tempContext != nil) apiVersion = dp::ApiVersion::OpenGLES3; else - apiVersion = dp::ApiVersion::OpenGLES2; + CHECK(false, ("OpenGL ES3 is not supported")); } return apiVersion; diff --git a/iphone/Maps/Classes/iosOGLContext.mm b/iphone/Maps/Classes/iosOGLContext.mm index ec18d14c81..04b86cb0d1 100644 --- a/iphone/Maps/Classes/iosOGLContext.mm +++ b/iphone/Maps/Classes/iosOGLContext.mm @@ -17,20 +17,14 @@ iosOGLContext::iosOGLContext(CAEAGLLayer * layer, dp::ApiVersion apiVersion, , m_frameBufferId(0) , m_presentAvailable(true) { - EAGLRenderingAPI api; - if (m_apiVersion == dp::ApiVersion::OpenGLES3) - api = kEAGLRenderingAPIOpenGLES3; - else - api = kEAGLRenderingAPIOpenGLES2; - if (contextToShareWith != NULL) { - m_nativeContext = [[EAGLContext alloc] initWithAPI:api + m_nativeContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3 sharegroup: contextToShareWith->m_nativeContext.sharegroup]; } else { - m_nativeContext = [[EAGLContext alloc] initWithAPI:api]; + m_nativeContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; } } diff --git a/map/framework.hpp b/map/framework.hpp index c46de8942d..1eda2269f3 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -395,7 +395,7 @@ private: public: struct DrapeCreationParams { - dp::ApiVersion m_apiVersion = dp::ApiVersion::OpenGLES2; + dp::ApiVersion m_apiVersion = dp::ApiVersion::OpenGLES3; float m_visualScale = 1.0f; int m_surfaceWidth = 0; int m_surfaceHeight = 0; diff --git a/qt/qt_common/map_widget.cpp b/qt/qt_common/map_widget.cpp index 07da1e31f3..dc3f2455a9 100644 --- a/qt/qt_common/map_widget.cpp +++ b/qt/qt_common/map_widget.cpp @@ -107,7 +107,7 @@ void MapWidget::CreateEngine() { Framework::DrapeCreationParams p; - p.m_apiVersion = m_apiOpenGLES3 ? dp::ApiVersion::OpenGLES3 : dp::ApiVersion::OpenGLES2; + p.m_apiVersion = dp::ApiVersion::OpenGLES3; p.m_surfaceWidth = m_screenshotMode ? width() : static_cast(m_ratio * width()); p.m_surfaceHeight = m_screenshotMode ? height() : static_cast(m_ratio * height()); @@ -232,8 +232,6 @@ void MapWidget::Build() { std::string_view vertexSrc; std::string_view fragmentSrc; - if (m_apiOpenGLES3) - { #if defined(OMIM_OS_LINUX) vertexSrc = ":common/shaders/gles_300.vsh.glsl"; fragmentSrc = ":common/shaders/gles_300.fsh.glsl"; @@ -241,12 +239,6 @@ void MapWidget::Build() vertexSrc = ":common/shaders/gl_150.vsh.glsl"; fragmentSrc = ":common/shaders/gl_150.fsh.glsl"; #endif - } - else - { - vertexSrc = ":common/shaders/gles_200.vsh.glsl"; - fragmentSrc = ":common/shaders/gles_200.fsh.glsl"; - } m_program = std::make_unique(this); m_program->addShaderFromSourceFile(QOpenGLShader::Vertex, vertexSrc.data()); @@ -348,8 +340,6 @@ void MapWidget::initializeGL() if (!m_screenshotMode) m_ratio = devicePixelRatio(); - m_apiOpenGLES3 = true; - #if defined(OMIM_OS_LINUX) { QOpenGLFunctions * funcs = context()->functions(); @@ -367,29 +357,14 @@ void MapWidget::initializeGL() auto fmt = context()->format(); if (context()->format().version() < qMakePair(3, 0)) { - LOG(LINFO, ("OpenGL ES version is below 3.0, taking the OpenGL ES 2.0 path")); - m_apiOpenGLES3 = false; - - constexpr const char* requiredExtensions[3] = - { "GL_EXT_map_buffer_range", "GL_OES_mapbuffer", "GL_OES_vertex_array_object" }; - for (auto & requiredExtension : requiredExtensions) - { - if (context()->hasExtension(QByteArray::fromStdString(requiredExtension))) - LOG(LDEBUG, ("Found OpenGL ES 2.0 extension: ", requiredExtension)); - else - LOG(LCRITICAL, ("A required OpenGL ES 2.0 extension is missing:", requiredExtension)); - } - fmt.setProfile(QSurfaceFormat::CompatibilityProfile); - fmt.setVersion(2, 0); + CHECK(false, ("OpenGL ES2 is not supported")); } else { LOG(LINFO, ("OpenGL version is at least 3.0, enabling GLSL '#version 300 es'")); - m_apiOpenGLES3 = true; fmt.setVersion(3, 0); } - QSurfaceFormat::setDefaultFormat(fmt); } #endif diff --git a/qt/qt_common/map_widget.hpp b/qt/qt_common/map_widget.hpp index 304a51aea0..aacb292370 100644 --- a/qt/qt_common/map_widget.hpp +++ b/qt/qt_common/map_widget.hpp @@ -97,7 +97,6 @@ protected: void wheelEvent(QWheelEvent * e) override; Framework & m_framework; - bool m_apiOpenGLES3; bool m_screenshotMode; ScaleSlider * m_slider; SliderState m_sliderState; diff --git a/qt/qt_common/res/resources_common.qrc b/qt/qt_common/res/resources_common.qrc index 8aa243bd91..0bc03d9f7e 100644 --- a/qt/qt_common/res/resources_common.qrc +++ b/qt/qt_common/res/resources_common.qrc @@ -16,8 +16,6 @@ spinner12.png shaders/gl_150.fsh.glsl shaders/gl_150.vsh.glsl - shaders/gles_200.fsh.glsl - shaders/gles_200.vsh.glsl shaders/gles_300.fsh.glsl shaders/gles_300.vsh.glsl diff --git a/qt/qt_common/res/shaders/gles_200.fsh.glsl b/qt/qt_common/res/shaders/gles_200.fsh.glsl deleted file mode 100644 index baa46225b3..0000000000 --- a/qt/qt_common/res/shaders/gles_200.fsh.glsl +++ /dev/null @@ -1,15 +0,0 @@ -#ifdef GL_ES -#ifdef GL_FRAGMENT_PRECISION_HIGH -precision highp float; -#else -precision mediump float; -#endif -#endif - -uniform sampler2D u_sampler; -varying vec2 v_texCoord; - -void main() -{ - gl_FragColor = vec4(texture2D(u_sampler, v_texCoord).rgb, 1.0); -} diff --git a/qt/qt_common/res/shaders/gles_200.vsh.glsl b/qt/qt_common/res/shaders/gles_200.vsh.glsl deleted file mode 100644 index 7d1208f962..0000000000 --- a/qt/qt_common/res/shaders/gles_200.vsh.glsl +++ /dev/null @@ -1,9 +0,0 @@ -attribute vec4 a_position; -uniform vec2 u_samplerSize; -varying vec2 v_texCoord; - -void main() -{ - v_texCoord = vec2(a_position.z * u_samplerSize.x, a_position.w * u_samplerSize.y); - gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0); -} diff --git a/qt_tstfrm/test_main_loop.cpp b/qt_tstfrm/test_main_loop.cpp index 1f773c3073..ecd0518864 100644 --- a/qt_tstfrm/test_main_loop.cpp +++ b/qt_tstfrm/test_main_loop.cpp @@ -51,8 +51,7 @@ void RunTestLoop(char const * testName, testing::RenderFunction && fn, bool auto app.exec(); } -void RunTestInOpenGLOffscreenEnvironment(char const * testName, bool apiOpenGLES3, - testing::TestFunction const & fn) +void RunTestInOpenGLOffscreenEnvironment(char const * testName, testing::TestFunction const & fn) { std::vector buf(strlen(testName) + 1); strcpy(buf.data(), testName); @@ -71,16 +70,8 @@ void RunTestInOpenGLOffscreenEnvironment(char const * testName, bool apiOpenGLES fmt.setSwapBehavior(QSurfaceFormat::DoubleBuffer); fmt.setSwapInterval(1); fmt.setDepthBufferSize(16); - if (apiOpenGLES3) - { - fmt.setProfile(QSurfaceFormat::CoreProfile); - fmt.setVersion(3, 2); - } - else - { - fmt.setProfile(QSurfaceFormat::CompatibilityProfile); - fmt.setVersion(2, 1); - } + fmt.setProfile(QSurfaceFormat::CoreProfile); + fmt.setVersion(3, 2); auto surface = std::make_unique(); surface->setFormat(fmt); @@ -92,7 +83,7 @@ void RunTestInOpenGLOffscreenEnvironment(char const * testName, bool apiOpenGLES context->makeCurrent(surface.get()); if (fn) - fn(apiOpenGLES3); + fn(); context->doneCurrent(); surface->destroy(); diff --git a/qt_tstfrm/test_main_loop.hpp b/qt_tstfrm/test_main_loop.hpp index f47e0a2ee7..4796b99f70 100644 --- a/qt_tstfrm/test_main_loop.hpp +++ b/qt_tstfrm/test_main_loop.hpp @@ -6,9 +6,9 @@ class QPaintDevice; namespace testing { using RenderFunction = std::function; -using TestFunction = std::function; +using TestFunction = std::function; } // namespace testing extern void RunTestLoop(char const * testName, testing::RenderFunction && fn, bool autoExit = true); -extern void RunTestInOpenGLOffscreenEnvironment(char const * testName, bool apiOpenGLES3, testing::TestFunction const & fn); +extern void RunTestInOpenGLOffscreenEnvironment(char const * testName, testing::TestFunction const & fn); diff --git a/shaders/GL/area.vsh.glsl b/shaders/GL/area.vsh.glsl index fd47ba1ef0..66b88cae8b 100644 --- a/shaders/GL/area.vsh.glsl +++ b/shaders/GL/area.vsh.glsl @@ -1,15 +1,26 @@ -attribute vec3 a_position; -attribute vec2 a_colorTexCoords; - -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; +layout (location = 0) in vec3 a_position; +layout (location = 1) in vec2 a_colorTexCoords; #ifdef ENABLE_VTF -uniform sampler2D u_colorTex; -varying LOW_P vec4 v_color; +layout (location = 0) out LOW_P vec4 v_color; #else -varying vec2 v_colorTexCoords; +layout (location = 1) out vec2 v_colorTexCoords; +#endif + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + +#ifdef ENABLE_VTF +layout (binding = 1) uniform sampler2D u_colorTex; #endif void main() @@ -17,7 +28,7 @@ void main() vec4 pos = vec4(a_position, 1) * u_modelView * u_projection; gl_Position = applyPivotTransform(pos, u_pivotTransform, 0.0); #ifdef ENABLE_VTF - v_color = texture2D(u_colorTex, a_colorTexCoords); + v_color = texture(u_colorTex, a_colorTexCoords); #else v_colorTexCoords = a_colorTexCoords; #endif diff --git a/shaders/GL/area3d.vsh.glsl b/shaders/GL/area3d.vsh.glsl index a0a4490b2c..9ace4cc361 100644 --- a/shaders/GL/area3d.vsh.glsl +++ b/shaders/GL/area3d.vsh.glsl @@ -1,34 +1,36 @@ -attribute vec3 a_position; -attribute vec3 a_normal; -attribute vec2 a_colorTexCoords; +layout (location = 0) in vec3 a_position; +layout (location = 1) in vec3 a_normal; +layout (location = 2) in vec2 a_colorTexCoords; +layout (location = 0) out vec2 v_colorTexCoords; +layout (location = 1) out float v_intensity; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; -uniform float u_zScale; - -varying vec2 v_colorTexCoords; -varying float v_intensity; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; const vec4 kNormalizedLightDir = vec4(0.3162, 0.0, 0.9486, 0.0); void main() { vec4 pos = vec4(a_position, 1.0) * u_modelView; - vec4 normal = vec4(a_position + a_normal, 1.0) * u_modelView; normal.xyw = (normal * u_projection).xyw; normal.z = normal.z * u_zScale; - pos.xyw = (pos * u_projection).xyw; pos.z = a_position.z * u_zScale; - vec4 normDir = normal - pos; if (dot(normDir, normDir) != 0.0) v_intensity = max(0.0, -dot(kNormalizedLightDir, normalize(normDir))); else v_intensity = 0.0; - gl_Position = u_pivotTransform * pos; #ifdef VULKAN gl_Position.y = -gl_Position.y; diff --git a/shaders/GL/area3d_outline.vsh.glsl b/shaders/GL/area3d_outline.vsh.glsl index c5a04b0df9..2b608d56af 100644 --- a/shaders/GL/area3d_outline.vsh.glsl +++ b/shaders/GL/area3d_outline.vsh.glsl @@ -1,16 +1,26 @@ -attribute vec3 a_position; -attribute vec2 a_colorTexCoords; - -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; -uniform float u_zScale; +layout (location = 0) in vec3 a_position; +layout (location = 1) in vec2 a_colorTexCoords; #ifdef ENABLE_VTF -uniform sampler2D u_colorTex; -varying LOW_P vec4 v_color; +layout (location = 0) out LOW_P vec4 v_color; #else -varying vec2 v_colorTexCoords; +layout (location = 1) out vec2 v_colorTexCoords; +#endif + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + +#ifdef ENABLE_VTF +layout (binding = 1) uniform sampler2D u_colorTex; #endif void main() @@ -23,9 +33,8 @@ void main() gl_Position.y = -gl_Position.y; gl_Position.z = (gl_Position.z + gl_Position.w) * 0.5; #endif - #ifdef ENABLE_VTF - v_color = texture2D(u_colorTex, a_colorTexCoords); + v_color = texture(u_colorTex, a_colorTexCoords); #else v_colorTexCoords = a_colorTexCoords; #endif diff --git a/shaders/GL/arrow3d.fsh.glsl b/shaders/GL/arrow3d.fsh.glsl index 5870c40dd4..a88df9fe4d 100644 --- a/shaders/GL/arrow3d.fsh.glsl +++ b/shaders/GL/arrow3d.fsh.glsl @@ -1,16 +1,19 @@ -varying vec3 v_normal; +layout (location = 0) in vec3 v_normal; -#ifdef SAMSUNG_GOOGLE_NEXUS -uniform sampler2D u_colorTex; -#endif +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + mat4 u_transform; + mat4 u_normalTransform; + vec4 u_color; + vec2 u_texCoordFlipping; +}; const vec3 lightDir = vec3(0.316, 0.0, 0.948); -uniform vec4 u_color; - void main() { float phongDiffuse = max(0.0, -dot(lightDir, v_normal)); - vec4 resColor = vec4((phongDiffuse * 0.5 + 0.5) * u_color.rgb, u_color.a); - gl_FragColor = samsungGoogleNexusWorkaround(resColor); + v_FragColor = vec4((phongDiffuse * 0.5 + 0.5) * u_color.rgb, u_color.a); } diff --git a/shaders/GL/arrow3d.vsh.glsl b/shaders/GL/arrow3d.vsh.glsl index 4b2772b995..0b0c237883 100644 --- a/shaders/GL/arrow3d.vsh.glsl +++ b/shaders/GL/arrow3d.vsh.glsl @@ -1,10 +1,15 @@ -attribute vec3 a_pos; -attribute vec3 a_normal; +layout (location = 0) in vec3 a_pos; +layout (location = 1) in vec3 a_normal; -uniform mat4 u_transform; -uniform mat4 u_normalTransform; +layout (location = 0) out vec3 v_normal; -varying vec3 v_normal; +layout (binding = 0) uniform UBO +{ + mat4 u_transform; + mat4 u_normalTransform; + vec4 u_color; + vec2 u_texCoordFlipping; +}; void main() { diff --git a/shaders/GL/arrow3d_outline.fsh.glsl b/shaders/GL/arrow3d_outline.fsh.glsl index 4b523a8cf1..4bc8388f32 100644 --- a/shaders/GL/arrow3d_outline.fsh.glsl +++ b/shaders/GL/arrow3d_outline.fsh.glsl @@ -1,13 +1,16 @@ -varying float v_intensity; +layout (location = 0) in float v_intensity; -#ifdef SAMSUNG_GOOGLE_NEXUS -uniform sampler2D u_colorTex; -#endif +layout (location = 0) out vec4 v_FragColor; -uniform vec4 u_color; +layout (binding = 0) uniform UBO +{ + mat4 u_transform; + mat4 u_normalTransform; + vec4 u_color; + vec2 u_texCoordFlipping; +}; void main() { - vec4 resColor = vec4(u_color.rgb, u_color.a * smoothstep(0.7, 1.0, v_intensity)); - gl_FragColor = samsungGoogleNexusWorkaround(resColor); + v_FragColor = vec4(u_color.rgb, u_color.a * smoothstep(0.7, 1.0, v_intensity)); } diff --git a/shaders/GL/arrow3d_shadow.fsh.glsl b/shaders/GL/arrow3d_shadow.fsh.glsl index ba53653dfe..40143c69ad 100644 --- a/shaders/GL/arrow3d_shadow.fsh.glsl +++ b/shaders/GL/arrow3d_shadow.fsh.glsl @@ -1,13 +1,16 @@ -varying float v_intensity; +layout (location = 0) in float v_intensity; -#ifdef SAMSUNG_GOOGLE_NEXUS -uniform sampler2D u_colorTex; -#endif +layout (location = 0) out vec4 v_FragColor; -uniform vec4 u_color; +layout (binding = 0) uniform UBO +{ + mat4 u_transform; + mat4 u_normalTransform; + vec4 u_color; + vec2 u_texCoordFlipping; +}; void main() { - vec4 resColor = vec4(u_color.rgb, u_color.a * v_intensity); - gl_FragColor = samsungGoogleNexusWorkaround(resColor); + v_FragColor = vec4(u_color.rgb, u_color.a * v_intensity); } diff --git a/shaders/GL/arrow3d_shadow.vsh.glsl b/shaders/GL/arrow3d_shadow.vsh.glsl index a8491441e7..97060408d3 100644 --- a/shaders/GL/arrow3d_shadow.vsh.glsl +++ b/shaders/GL/arrow3d_shadow.vsh.glsl @@ -1,9 +1,15 @@ -attribute vec3 a_pos; -attribute vec2 a_texCoords; +layout (location = 0) in vec3 a_pos; +layout (location = 1) in vec2 a_texCoords; -uniform mat4 u_transform; +layout (location = 0) out float v_intensity; -varying float v_intensity; +layout (binding = 0) uniform UBO +{ + mat4 u_transform; + mat4 u_normalTransform; + vec4 u_color; + vec2 u_texCoordFlipping; +}; void main() { diff --git a/shaders/GL/arrow3d_textured.fsh.glsl b/shaders/GL/arrow3d_textured.fsh.glsl index 56ab3b8ced..ac93c59a3b 100644 --- a/shaders/GL/arrow3d_textured.fsh.glsl +++ b/shaders/GL/arrow3d_textured.fsh.glsl @@ -1,15 +1,23 @@ -varying vec3 v_normal; -varying vec2 v_texCoords; +layout (location = 0) in vec3 v_normal; +layout (location = 1) in vec2 v_texCoords; -uniform sampler2D u_colorTex; +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + mat4 u_transform; + mat4 u_normalTransform; + vec4 u_color; + vec2 u_texCoordFlipping; +}; + +layout (binding = 1) uniform sampler2D u_colorTex; const vec3 lightDir = vec3(0.316, 0.0, 0.948); -uniform vec4 u_color; - void main() { float phongDiffuse = max(0.0, -dot(lightDir, v_normal)); - vec4 color = texture2D(u_colorTex, v_texCoords) * u_color; - gl_FragColor = vec4((phongDiffuse * 0.5 + 0.5) * color.rgb, color.a); + vec4 color = texture(u_colorTex, v_texCoords) * u_color; + v_FragColor = vec4((phongDiffuse * 0.5 + 0.5) * color.rgb, color.a); } diff --git a/shaders/GL/arrow3d_textured.vsh.glsl b/shaders/GL/arrow3d_textured.vsh.glsl index 6aafa796d9..a6ad64b1f6 100644 --- a/shaders/GL/arrow3d_textured.vsh.glsl +++ b/shaders/GL/arrow3d_textured.vsh.glsl @@ -1,13 +1,17 @@ -attribute vec3 a_pos; -attribute vec3 a_normal; -attribute vec2 a_texCoords; +layout (location = 0) in vec3 a_pos; +layout (location = 1) in vec3 a_normal; +layout (location = 2) in vec2 a_texCoords; -uniform mat4 u_transform; -uniform mat4 u_normalTransform; -uniform vec2 u_texCoordFlipping; +layout (location = 0) out vec3 v_normal; +layout (location = 1) out vec2 v_texCoords; -varying vec3 v_normal; -varying vec2 v_texCoords; +layout (binding = 0) uniform UBO +{ + mat4 u_transform; + mat4 u_normalTransform; + vec4 u_color; + vec2 u_texCoordFlipping; +}; void main() { diff --git a/shaders/GL/circle.fsh.glsl b/shaders/GL/circle.fsh.glsl index e81ece0678..c75364b973 100644 --- a/shaders/GL/circle.fsh.glsl +++ b/shaders/GL/circle.fsh.glsl @@ -1,12 +1,27 @@ -uniform float u_opacity; #ifdef ENABLE_VTF -varying LOW_P vec4 v_color; +layout (location = 0) in LOW_P vec4 v_color; #else -uniform sampler2D u_colorTex; -varying vec2 v_colorTexCoords; +layout (location = 1) in vec2 v_colorTexCoords; #endif +layout (location = 2) in vec3 v_radius; -varying vec3 v_radius; +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + +#ifdef ENABLE_VTF +layout (binding = 1) uniform sampler2D u_colorTex; +#endif const float aaPixelsCount = 2.5; @@ -15,12 +30,11 @@ void main() #ifdef ENABLE_VTF LOW_P vec4 finalColor = v_color; #else - LOW_P vec4 finalColor = texture2D(u_colorTex, v_colorTexCoords); + LOW_P vec4 finalColor = texture(u_colorTex, v_colorTexCoords); #endif - float smallRadius = v_radius.z - aaPixelsCount; float stepValue = smoothstep(smallRadius * smallRadius, v_radius.z * v_radius.z, v_radius.x * v_radius.x + v_radius.y * v_radius.y); finalColor.a = finalColor.a * u_opacity * (1.0 - stepValue); - gl_FragColor = finalColor; + v_FragColor = finalColor; } diff --git a/shaders/GL/circle.vsh.glsl b/shaders/GL/circle.vsh.glsl index 1191464057..b186af21c1 100644 --- a/shaders/GL/circle.vsh.glsl +++ b/shaders/GL/circle.vsh.glsl @@ -1,19 +1,29 @@ -attribute vec3 a_position; -attribute vec3 a_normal; -attribute vec2 a_colorTexCoords; - -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; +layout (location = 0) in vec3 a_position; +layout (location = 1) in vec3 a_normal; +layout (location = 2) in vec2 a_colorTexCoords; #ifdef ENABLE_VTF -uniform sampler2D u_colorTex; -varying LOW_P vec4 v_color; +layout (location = 0) out LOW_P vec4 v_color; #else -varying vec2 v_colorTexCoords; +layout (location = 1) out vec2 v_colorTexCoords; #endif +layout (location = 2) out vec3 v_radius; -varying vec3 v_radius; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + +#ifdef ENABLE_VTF +layout (binding = 1) uniform sampler2D u_colorTex; +#endif void main() { @@ -21,7 +31,7 @@ void main() vec4 pos = vec4(a_normal.xy, 0, 0) + p; gl_Position = applyPivotTransform(pos * u_projection, u_pivotTransform, 0.0); #ifdef ENABLE_VTF - v_color = texture2D(u_colorTex, a_colorTexCoords); + v_color = texture(u_colorTex, a_colorTexCoords); #else v_colorTexCoords = a_colorTexCoords; #endif diff --git a/shaders/GL/circle_point.fsh.glsl b/shaders/GL/circle_point.fsh.glsl index f96beba503..debb2230c2 100644 --- a/shaders/GL/circle_point.fsh.glsl +++ b/shaders/GL/circle_point.fsh.glsl @@ -1,11 +1,19 @@ -#ifdef SAMSUNG_GOOGLE_NEXUS -uniform sampler2D u_colorTex; -#endif +layout (location = 0) in vec3 v_radius; +layout (location = 1) in vec4 v_color; -uniform float u_opacity; +layout (location = 0) out vec4 v_FragColor; -varying vec3 v_radius; -varying vec4 v_color; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; const float kAntialiasingScalar = 0.9; @@ -13,10 +21,8 @@ void main() { float d = dot(v_radius.xy, v_radius.xy); vec4 finalColor = v_color; - float aaRadius = v_radius.z * kAntialiasingScalar; float stepValue = smoothstep(aaRadius * aaRadius, v_radius.z * v_radius.z, d); finalColor.a = finalColor.a * u_opacity * (1.0 - stepValue); - - gl_FragColor = samsungGoogleNexusWorkaround(finalColor); + v_FragColor = finalColor; } diff --git a/shaders/GL/circle_point.vsh.glsl b/shaders/GL/circle_point.vsh.glsl index ca165c806b..3a174db6b6 100644 --- a/shaders/GL/circle_point.vsh.glsl +++ b/shaders/GL/circle_point.vsh.glsl @@ -1,13 +1,21 @@ -attribute vec3 a_normal; -attribute vec3 a_position; -attribute vec4 a_color; +layout (location = 0) in vec3 a_normal; +layout (location = 1) in vec3 a_position; +layout (location = 2) in vec4 a_color; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; +layout (location = 0) out vec3 v_radius; +layout (location = 1) out vec4 v_color; -varying vec3 v_radius; -varying vec4 v_color; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; void main() { @@ -15,7 +23,6 @@ void main() vec4 pos = vec4(a_position.xy, 0, 1) * u_modelView; vec4 shiftedPos = vec4(radius.xy, 0, 0) + pos; gl_Position = applyPivotTransform(shiftedPos * u_projection, u_pivotTransform, 0.0); - v_radius = radius; v_color = a_color; } diff --git a/shaders/GL/colored_symbol.fsh.glsl b/shaders/GL/colored_symbol.fsh.glsl index 4329d213e2..a43dc0a76c 100644 --- a/shaders/GL/colored_symbol.fsh.glsl +++ b/shaders/GL/colored_symbol.fsh.glsl @@ -1,13 +1,25 @@ -uniform float u_opacity; - -varying vec4 v_normal; +layout (location = 0) in vec4 v_normal; #ifdef ENABLE_VTF -varying LOW_P vec4 v_color; +layout (location = 1) in LOW_P vec4 v_color; #else -uniform sampler2D u_colorTex; -varying vec2 v_colorTexCoords; +layout (location = 2) in vec2 v_colorTexCoords; +layout (binding = 1) uniform sampler2D u_colorTex; #endif +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + const float aaPixelsCount = 2.5; void main() @@ -15,18 +27,15 @@ void main() #ifdef ENABLE_VTF LOW_P vec4 color = v_color; #else - LOW_P vec4 color = texture2D(u_colorTex, v_colorTexCoords); + LOW_P vec4 color = texture(u_colorTex, v_colorTexCoords); #endif - float r1 = (v_normal.z - aaPixelsCount) * (v_normal.z - aaPixelsCount); float r2 = v_normal.x * v_normal.x + v_normal.y * v_normal.y; float r3 = v_normal.z * v_normal.z; float alpha = mix(step(r3, r2), smoothstep(r1, r3, r2), v_normal.w); - LOW_P vec4 finalColor = color; finalColor.a = finalColor.a * u_opacity * (1.0 - alpha); if (finalColor.a == 0.0) discard; - - gl_FragColor = finalColor; + v_FragColor = finalColor; } diff --git a/shaders/GL/colored_symbol.vsh.glsl b/shaders/GL/colored_symbol.vsh.glsl index 1d75acf942..8b6b8beaa5 100644 --- a/shaders/GL/colored_symbol.vsh.glsl +++ b/shaders/GL/colored_symbol.vsh.glsl @@ -1,17 +1,28 @@ -attribute vec3 a_position; -attribute vec4 a_normal; -attribute vec4 a_colorTexCoords; +layout (location = 0) in vec3 a_position; +layout (location = 1) in vec4 a_normal; +layout (location = 2) in vec4 a_colorTexCoords; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; - -varying vec4 v_normal; +layout (location = 0) out vec4 v_normal; #ifdef ENABLE_VTF -uniform sampler2D u_colorTex; -varying LOW_P vec4 v_color; +layout (location = 1) out LOW_P vec4 v_color; #else -varying vec2 v_colorTexCoords; +layout (location = 2) out vec2 v_colorTexCoords; +#endif + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + +#ifdef ENABLE_VTF +layout (binding = 1) uniform sampler2D u_colorTex; #endif void main() @@ -19,9 +30,8 @@ void main() vec4 p = vec4(a_position, 1) * u_modelView; vec4 pos = vec4(a_normal.xy + a_colorTexCoords.zw, 0, 0) + p; gl_Position = applyPivotTransform(pos * u_projection, u_pivotTransform, 0.0); - #ifdef ENABLE_VTF - v_color = texture2D(u_colorTex, a_colorTexCoords.xy); + v_color = texture(u_colorTex, a_colorTexCoords.xy); #else v_colorTexCoords = a_colorTexCoords.xy; #endif diff --git a/shaders/GL/colored_symbol_billboard.vsh.glsl b/shaders/GL/colored_symbol_billboard.vsh.glsl index f521d272da..b2ac3c6d30 100644 --- a/shaders/GL/colored_symbol_billboard.vsh.glsl +++ b/shaders/GL/colored_symbol_billboard.vsh.glsl @@ -1,17 +1,28 @@ -attribute vec3 a_position; -attribute vec4 a_normal; -attribute vec4 a_colorTexCoords; +layout (location = 0) in vec3 a_position; +layout (location = 1) in vec4 a_normal; +layout (location = 2) in vec4 a_colorTexCoords; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; - -varying vec4 v_normal; +layout (location = 0) out vec4 v_normal; #ifdef ENABLE_VTF -uniform sampler2D u_colorTex; -varying LOW_P vec4 v_color; +layout (location = 1) out LOW_P vec4 v_color; #else -varying vec2 v_colorTexCoords; +layout (location = 2) out vec2 v_colorTexCoords; +#endif + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + +#ifdef ENABLE_VTF +layout (binding = 1) uniform sampler2D u_colorTex; #endif void main() @@ -19,9 +30,8 @@ void main() vec4 pivot = vec4(a_position.xyz, 1.0) * u_modelView; vec4 offset = vec4(a_normal.xy + a_colorTexCoords.zw, 0.0, 0.0) * u_projection; gl_Position = applyBillboardPivotTransform(pivot * u_projection, u_pivotTransform, 0.0, offset.xy); - #ifdef ENABLE_VTF - v_color = texture2D(u_colorTex, a_colorTexCoords.xy); + v_color = texture(u_colorTex, a_colorTexCoords.xy); #else v_colorTexCoords = a_colorTexCoords.xy; #endif diff --git a/shaders/GL/dashed_line.fsh.glsl b/shaders/GL/dashed_line.fsh.glsl index c32101bac2..beb0fb4169 100644 --- a/shaders/GL/dashed_line.fsh.glsl +++ b/shaders/GL/dashed_line.fsh.glsl @@ -1,28 +1,35 @@ -varying vec2 v_colorTexCoord; -varying vec2 v_maskTexCoord; -//varying vec2 v_halfLength; +layout (location = 0) in vec2 v_colorTexCoord; +layout (location = 1) in vec2 v_maskTexCoord; +//layout (location = 2) in vec2 v_halfLength; -uniform sampler2D u_colorTex; -uniform sampler2D u_maskTex; -uniform float u_opacity; +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + +layout (binding = 1) uniform sampler2D u_colorTex; +layout (binding = 2) uniform sampler2D u_maskTex; //const float aaPixelsCount = 2.5; void main() { - vec4 color = texture2D(u_colorTex, v_colorTexCoord); -#ifdef GLES3 - float mask = texture2D(u_maskTex, v_maskTexCoord).r; -#else - float mask = texture2D(u_maskTex, v_maskTexCoord).a; -#endif + vec4 color = texture(u_colorTex, v_colorTexCoord); + float mask = texture(u_maskTex, v_maskTexCoord).r; color.a = color.a * mask * u_opacity; - // Disabled too agressive AA-like blurring of edges, // see https://github.com/organicmaps/organicmaps/issues/6583. //float currentW = abs(v_halfLength.x); //float diff = v_halfLength.y - currentW; //color.a *= mix(0.3, 1.0, clamp(diff / aaPixelsCount, 0.0, 1.0)); - - gl_FragColor = color; + v_FragColor = color; } diff --git a/shaders/GL/dashed_line.vsh.glsl b/shaders/GL/dashed_line.vsh.glsl index 8fb2501581..355fa6e3c0 100644 --- a/shaders/GL/dashed_line.vsh.glsl +++ b/shaders/GL/dashed_line.vsh.glsl @@ -1,15 +1,23 @@ -attribute vec3 a_position; -attribute vec3 a_normal; -attribute vec2 a_colorTexCoord; -attribute vec4 a_maskTexCoord; +layout (location = 0) in vec3 a_position; +layout (location = 1) in vec3 a_normal; +layout (location = 2) in vec2 a_colorTexCoord; +layout (location = 3) in vec4 a_maskTexCoord; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; +layout (location = 0) out vec2 v_colorTexCoord; +layout (location = 1) out vec2 v_maskTexCoord; +//layout (location = 2) out vec2 v_halfLength; -varying vec2 v_colorTexCoord; -varying vec2 v_maskTexCoord; -//varying vec2 v_halfLength; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; void main() { @@ -21,12 +29,10 @@ void main() transformedAxisPos = calcLineTransformedAxisPos(transformedAxisPos, a_position.xy + normal, u_modelView, halfWidth); } - float uOffset = min(length(vec4(kShapeCoordScalar, 0, 0, 0) * u_modelView) * a_maskTexCoord.x, 1.0); v_colorTexCoord = a_colorTexCoord; v_maskTexCoord = vec2(a_maskTexCoord.y + uOffset * a_maskTexCoord.z, a_maskTexCoord.w); //v_halfLength = vec2(sign(a_normal.z) * halfWidth, abs(a_normal.z)); vec4 pos = vec4(transformedAxisPos, a_position.z, 1.0) * u_projection; - gl_Position = applyPivotTransform(pos, u_pivotTransform, 0.0); } diff --git a/shaders/GL/debug_rect.fsh.glsl b/shaders/GL/debug_rect.fsh.glsl index 137df16712..b8bf153547 100644 --- a/shaders/GL/debug_rect.fsh.glsl +++ b/shaders/GL/debug_rect.fsh.glsl @@ -1,10 +1,11 @@ -uniform vec4 u_color; +layout (location = 0) out vec4 v_FragColor; -#ifdef SAMSUNG_GOOGLE_NEXUS -uniform sampler2D u_colorTex; -#endif +layout (binding = 0) uniform UBO +{ + vec4 u_color; +}; void main() { - gl_FragColor = samsungGoogleNexusWorkaround(u_color); + v_FragColor = u_color; } diff --git a/shaders/GL/debug_rect.vsh.glsl b/shaders/GL/debug_rect.vsh.glsl index dca1cd66e1..99070edf74 100644 --- a/shaders/GL/debug_rect.vsh.glsl +++ b/shaders/GL/debug_rect.vsh.glsl @@ -1,4 +1,4 @@ -attribute vec2 a_position; +layout (location = 0) in vec2 a_position; void main() { diff --git a/shaders/GL/hatching_area.fsh.glsl b/shaders/GL/hatching_area.fsh.glsl index 3cc7e5867d..aa47ac1c2a 100644 --- a/shaders/GL/hatching_area.fsh.glsl +++ b/shaders/GL/hatching_area.fsh.glsl @@ -1,24 +1,35 @@ -uniform float u_opacity; - #ifdef ENABLE_VTF -varying LOW_P vec4 v_color; +layout (location = 0) in LOW_P vec4 v_color; #else -uniform sampler2D u_colorTex; -varying vec2 v_colorTexCoords; +layout (location = 1) in vec2 v_colorTexCoords; +layout (binding = 1) uniform sampler2D u_colorTex; #endif +layout (location = 2) in vec2 v_maskTexCoords; -uniform sampler2D u_maskTex; -varying vec2 v_maskTexCoords; +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + +layout (binding = 2) uniform sampler2D u_maskTex; void main() { #ifdef ENABLE_VTF LOW_P vec4 color = v_color; #else - LOW_P vec4 color = texture2D(u_colorTex, v_colorTexCoords); + LOW_P vec4 color = texture(u_colorTex, v_colorTexCoords); #endif - color *= texture2D(u_maskTex, v_maskTexCoords); + color *= texture(u_maskTex, v_maskTexCoords); color.a *= u_opacity; - gl_FragColor = color; + v_FragColor = color; } - diff --git a/shaders/GL/hatching_area.vsh.glsl b/shaders/GL/hatching_area.vsh.glsl index 9b5407ad5a..92565fec1a 100644 --- a/shaders/GL/hatching_area.vsh.glsl +++ b/shaders/GL/hatching_area.vsh.glsl @@ -1,25 +1,36 @@ -attribute vec3 a_position; -attribute vec2 a_colorTexCoords; -attribute vec2 a_maskTexCoords; - -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; +layout (location = 0) in vec3 a_position; +layout (location = 1) in vec2 a_colorTexCoords; +layout (location = 2) in vec2 a_maskTexCoords; #ifdef ENABLE_VTF -uniform sampler2D u_colorTex; -varying LOW_P vec4 v_color; +layout (location = 0) out LOW_P vec4 v_color; #else -varying vec2 v_colorTexCoords; +layout (location = 1) out vec2 v_colorTexCoords; +#endif +layout (location = 2) out vec2 v_maskTexCoords; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + +#ifdef ENABLE_VTF +layout (binding = 1) uniform sampler2D u_colorTex; #endif -varying vec2 v_maskTexCoords; void main() { vec4 pos = vec4(a_position, 1) * u_modelView * u_projection; gl_Position = applyPivotTransform(pos, u_pivotTransform, 0.0); #ifdef ENABLE_VTF - v_color = texture2D(u_colorTex, a_colorTexCoords); + v_color = texture(u_colorTex, a_colorTexCoords); #else v_colorTexCoords = a_colorTexCoords; #endif diff --git a/shaders/GL/imgui.fsh.glsl b/shaders/GL/imgui.fsh.glsl new file mode 100644 index 0000000000..0114ac1443 --- /dev/null +++ b/shaders/GL/imgui.fsh.glsl @@ -0,0 +1,12 @@ +layout (location = 0) in vec2 v_texCoords; +layout (location = 1) in vec4 v_color; + +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 1) uniform sampler2D u_colorTex; + +void main() +{ + LOW_P vec4 color = texture(u_colorTex, v_texCoords); + v_FragColor = color * v_color; +} diff --git a/shaders/GL/imgui.vsh.glsl b/shaders/GL/imgui.vsh.glsl new file mode 100644 index 0000000000..a83b787811 --- /dev/null +++ b/shaders/GL/imgui.vsh.glsl @@ -0,0 +1,22 @@ +layout (location = 0) in vec2 a_position; +layout (location = 1) in vec2 a_texCoords; +layout (location = 2) in vec4 a_color; + +layout (location = 0) out vec2 v_texCoords; +layout (location = 1) out vec4 v_color; + +layout (binding = 0) uniform UBO +{ + mat4 u_projection; +}; + +void main() +{ + v_texCoords = a_texCoords; + v_color = a_color; + gl_Position = vec4(a_position, 0, 1) * u_projection; +#ifdef VULKAN + gl_Position.y = -gl_Position.y; + gl_Position.z = (gl_Position.z + gl_Position.w) * 0.5; +#endif +} diff --git a/shaders/GL/line.fsh.glsl b/shaders/GL/line.fsh.glsl index b39c459f98..3f640fc86a 100644 --- a/shaders/GL/line.fsh.glsl +++ b/shaders/GL/line.fsh.glsl @@ -1,12 +1,24 @@ -uniform float u_opacity; #ifdef ENABLE_VTF -varying LOW_P vec4 v_color; +layout (location = 0) in LOW_P vec4 v_color; #else -uniform sampler2D u_colorTex; -varying vec2 v_colorTexCoord; +layout (location = 1) in vec2 v_colorTexCoord; +layout (binding = 1) uniform sampler2D u_colorTex; #endif +//layout (location = 2) in vec2 v_halfLength; -//varying vec2 v_halfLength; +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; //const float aaPixelsCount = 2.5; @@ -15,15 +27,13 @@ void main() #ifdef ENABLE_VTF LOW_P vec4 color = v_color; #else - LOW_P vec4 color = texture2D(u_colorTex, v_colorTexCoord); + LOW_P vec4 color = texture(u_colorTex, v_colorTexCoord); #endif color.a *= u_opacity; - // Disabled too agressive AA-like blurring of edges, // see https://github.com/organicmaps/organicmaps/issues/6583. //float currentW = abs(v_halfLength.x); //float diff = v_halfLength.y - currentW; //color.a *= mix(0.3, 1.0, clamp(diff / aaPixelsCount, 0.0, 1.0)); - - gl_FragColor = color; + v_FragColor = color; } diff --git a/shaders/GL/line.vsh.glsl b/shaders/GL/line.vsh.glsl index 8daebc3241..122e03dd23 100644 --- a/shaders/GL/line.vsh.glsl +++ b/shaders/GL/line.vsh.glsl @@ -1,19 +1,30 @@ -attribute vec3 a_position; -attribute vec3 a_normal; -attribute vec2 a_colorTexCoord; - -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; +layout (location = 0) in vec3 a_position; +layout (location = 1) in vec3 a_normal; +layout (location = 2) in vec2 a_colorTexCoord; #ifdef ENABLE_VTF -uniform sampler2D u_colorTex; -varying LOW_P vec4 v_color; +layout (location = 0) out LOW_P vec4 v_color; #else -varying vec2 v_colorTexCoord; +layout (location = 1) out vec2 v_colorTexCoord; #endif -//varying vec2 v_halfLength; +//layout (location = 2) out vec2 v_halfLength; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + +#ifdef ENABLE_VTF +layout (binding = 1) uniform sampler2D u_colorTex; +#endif void main() { @@ -25,9 +36,8 @@ void main() transformedAxisPos = calcLineTransformedAxisPos(transformedAxisPos, a_position.xy + normal, u_modelView, halfWidth); } - #ifdef ENABLE_VTF - v_color = texture2D(u_colorTex, a_colorTexCoord); + v_color = texture(u_colorTex, a_colorTexCoord); #else v_colorTexCoord = a_colorTexCoord; #endif diff --git a/shaders/GL/masked_texturing.fsh.glsl b/shaders/GL/masked_texturing.fsh.glsl index 2c33afb604..24553f694f 100644 --- a/shaders/GL/masked_texturing.fsh.glsl +++ b/shaders/GL/masked_texturing.fsh.glsl @@ -1,13 +1,26 @@ -uniform sampler2D u_colorTex; -uniform sampler2D u_maskTex; -uniform float u_opacity; +layout (location = 0) in vec2 v_colorTexCoords; +layout (location = 1) in vec2 v_maskTexCoords; -varying vec2 v_colorTexCoords; -varying vec2 v_maskTexCoords; +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + +layout (binding = 1) uniform sampler2D u_colorTex; +layout (binding = 2) uniform sampler2D u_maskTex; void main() { - vec4 finalColor = texture2D(u_colorTex, v_colorTexCoords) * texture2D(u_maskTex, v_maskTexCoords); + vec4 finalColor = texture(u_colorTex, v_colorTexCoords) * texture(u_maskTex, v_maskTexCoords); finalColor.a *= u_opacity; - gl_FragColor = finalColor; + v_FragColor = finalColor; } diff --git a/shaders/GL/masked_texturing.vsh.glsl b/shaders/GL/masked_texturing.vsh.glsl index f39284265c..1f6d9a1e51 100644 --- a/shaders/GL/masked_texturing.vsh.glsl +++ b/shaders/GL/masked_texturing.vsh.glsl @@ -1,14 +1,22 @@ -attribute vec4 a_position; -attribute vec2 a_normal; -attribute vec2 a_colorTexCoords; -attribute vec2 a_maskTexCoords; +layout (location = 0) in vec4 a_position; +layout (location = 1) in vec2 a_normal; +layout (location = 2) in vec2 a_colorTexCoords; +layout (location = 3) in vec2 a_maskTexCoords; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; +layout (location = 0) out vec2 v_colorTexCoords; +layout (location = 1) out vec2 v_maskTexCoords; -varying vec2 v_colorTexCoords; -varying vec2 v_maskTexCoords; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; void main() { diff --git a/shaders/GL/masked_texturing_billboard.vsh.glsl b/shaders/GL/masked_texturing_billboard.vsh.glsl index 8363abafc9..0caccd80e1 100644 --- a/shaders/GL/masked_texturing_billboard.vsh.glsl +++ b/shaders/GL/masked_texturing_billboard.vsh.glsl @@ -1,15 +1,22 @@ -attribute vec4 a_position; -attribute vec2 a_normal; -attribute vec2 a_colorTexCoords; -attribute vec2 a_maskTexCoords; +layout (location = 0) in vec4 a_position; +layout (location = 1) in vec2 a_normal; +layout (location = 2) in vec2 a_colorTexCoords; +layout (location = 3) in vec2 a_maskTexCoords; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; -uniform float u_zScale; +layout (location = 0) out vec2 v_colorTexCoords; +layout (location = 1) out vec2 v_maskTexCoords; -varying vec2 v_colorTexCoords; -varying vec2 v_maskTexCoords; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; void main() { diff --git a/shaders/GL/my_position.vsh.glsl b/shaders/GL/my_position.vsh.glsl index 73bdc2ba15..8489cc6ad6 100644 --- a/shaders/GL/my_position.vsh.glsl +++ b/shaders/GL/my_position.vsh.glsl @@ -1,30 +1,33 @@ -attribute vec2 a_normal; -attribute vec2 a_colorTexCoords; +layout (location = 0) in vec2 a_normal; +layout (location = 1) in vec2 a_colorTexCoords; -uniform vec3 u_position; -uniform float u_azimut; +layout (location = 0) out vec2 v_colorTexCoords; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; - -varying vec2 v_colorTexCoords; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_position; + vec2 u_lineParams; + float u_accuracy; + float u_zScale; + float u_opacity; + float u_azimut; +}; void main() { float sinV = sin(u_azimut); float cosV = cos(u_azimut); - mat4 rotation; rotation[0] = vec4(cosV, sinV, 0.0, 0.0); rotation[1] = vec4(-sinV, cosV, 0.0, 0.0); rotation[2] = vec4(0.0, 0.0, 1.0, 0.0); rotation[3] = vec4(0.0, 0.0, 0.0, 1.0); - - vec4 pos = vec4(u_position, 1.0) * u_modelView; + vec4 pos = vec4(u_position.xyz, 1.0) * u_modelView; vec4 normal = vec4(a_normal, 0, 0); vec4 shiftedPos = normal * rotation + pos; - gl_Position = applyPivotTransform(shiftedPos * u_projection, u_pivotTransform, 0.0); v_colorTexCoords = a_colorTexCoords; } diff --git a/shaders/GL/path_symbol.vsh.glsl b/shaders/GL/path_symbol.vsh.glsl index 708a4edc04..72d81d96b9 100644 --- a/shaders/GL/path_symbol.vsh.glsl +++ b/shaders/GL/path_symbol.vsh.glsl @@ -1,23 +1,29 @@ -attribute vec4 a_position; -attribute vec2 a_normal; -attribute vec2 a_colorTexCoords; +layout (location = 0) in vec4 a_position; +layout (location = 1) in vec2 a_normal; +layout (location = 2) in vec2 a_colorTexCoords; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; +layout (location = 0) out vec2 v_colorTexCoords; -varying vec2 v_colorTexCoords; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; void main() { vec4 pos = vec4(a_position.xyz, 1) * u_modelView; - float normalLen = length(a_normal); vec4 n = vec4(a_position.xy + a_normal * kShapeCoordScalar, 0.0, 0.0) * u_modelView; vec4 norm = vec4(0.0, 0.0, 0.0, 0.0); if (dot(n, n) != 0.0) norm = normalize(n) * normalLen; - vec4 shiftedPos = norm + pos; gl_Position = applyPivotTransform(shiftedPos * u_projection, u_pivotTransform, 0.0); v_colorTexCoords = a_colorTexCoords; diff --git a/shaders/GL/position_accuracy3d.vsh.glsl b/shaders/GL/position_accuracy3d.vsh.glsl index d46aeeecad..196c6d7363 100644 --- a/shaders/GL/position_accuracy3d.vsh.glsl +++ b/shaders/GL/position_accuracy3d.vsh.glsl @@ -1,15 +1,20 @@ -attribute vec2 a_normal; -attribute vec2 a_colorTexCoords; +layout (location = 0) in vec2 a_normal; +layout (location = 1) in vec2 a_colorTexCoords; -uniform vec3 u_position; -uniform float u_accuracy; +layout (location = 0) out vec2 v_colorTexCoords; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; -uniform float u_zScale; - -varying vec2 v_colorTexCoords; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_position; + vec2 u_lineParams; + float u_accuracy; + float u_zScale; + float u_opacity; + float u_azimut; +}; void main() { @@ -17,6 +22,5 @@ void main() vec4 normal = vec4(a_normal * u_accuracy, 0.0, 0.0); position = (position + normal) * u_projection; gl_Position = applyPivotTransform(position, u_pivotTransform, u_position.z * u_zScale); - v_colorTexCoords = a_colorTexCoords; } diff --git a/shaders/GL/route.fsh.glsl b/shaders/GL/route.fsh.glsl index 3e811131f0..fab19eedc7 100644 --- a/shaders/GL/route.fsh.glsl +++ b/shaders/GL/route.fsh.glsl @@ -1,25 +1,30 @@ // Warning! Beware to use this shader. "discard" command may significally reduce performance. -// Unfortunately some CG algorithms cannot be implemented on OpenGL ES 2.0 without discarding -// fragments from depth buffer. +// Unfortunately some CG algorithms cannot be implemented without discarding fragments from depth buffer. -varying vec3 v_length; -varying vec4 v_color; +layout (location = 0) in vec3 v_length; +layout (location = 1) in vec4 v_color; -#ifdef SAMSUNG_GOOGLE_NEXUS -uniform sampler2D u_colorTex; -#endif +layout (location = 0) out vec4 v_FragColor; -uniform vec4 u_color; -uniform vec4 u_outlineColor; -uniform vec4 u_routeParams; -uniform vec4 u_maskColor; - -uniform vec2 u_fakeBorders; -uniform vec4 u_fakeColor; -uniform vec4 u_fakeOutlineColor; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_routeParams; + vec4 u_color; + vec4 u_maskColor; + vec4 u_outlineColor; + vec4 u_fakeColor; + vec4 u_fakeOutlineColor; + vec2 u_fakeBorders; + vec2 u_pattern; + vec2 u_angleCosSin; + float u_arrowHalfWidth; + float u_opacity; +}; const float kAntialiasingThreshold = 0.92; - const float kOutlineThreshold1 = 0.81; const float kOutlineThreshold2 = 0.71; @@ -27,18 +32,16 @@ void main() { if (v_length.x < v_length.z) discard; - vec2 coefs = step(v_length.xx, u_fakeBorders); coefs.y = 1.0 - coefs.y; vec4 mainColor = mix(u_color, u_fakeColor, coefs.x); mainColor = mix(mainColor, u_fakeColor, coefs.y); vec4 mainOutlineColor = mix(u_outlineColor, u_fakeOutlineColor, coefs.x); mainOutlineColor = mix(mainOutlineColor, u_fakeOutlineColor, coefs.y); - vec4 color = mix(mix(mainColor, vec4(v_color.rgb, 1.0), v_color.a), mainColor, step(u_routeParams.w, 0.0)); color = mix(color, mainOutlineColor, step(kOutlineThreshold1, abs(v_length.y))); color = mix(color, mainOutlineColor, smoothstep(kOutlineThreshold2, kOutlineThreshold1, abs(v_length.y))); color.a *= (1.0 - smoothstep(kAntialiasingThreshold, 1.0, abs(v_length.y))); color = vec4(mix(color.rgb, u_maskColor.rgb, u_maskColor.a), color.a); - gl_FragColor = samsungGoogleNexusWorkaround(color); + v_FragColor = color; } diff --git a/shaders/GL/route.vsh.glsl b/shaders/GL/route.vsh.glsl index 588000cab5..5915b92afa 100644 --- a/shaders/GL/route.vsh.glsl +++ b/shaders/GL/route.vsh.glsl @@ -1,16 +1,28 @@ -attribute vec3 a_position; -attribute vec2 a_normal; -attribute vec3 a_length; -attribute vec4 a_color; +layout (location = 0) in vec3 a_position; +layout (location = 1) in vec2 a_normal; +layout (location = 2) in vec3 a_length; +layout (location = 3) in vec4 a_color; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; +layout (location = 0) out vec3 v_length; +layout (location = 1) out vec4 v_color; -uniform vec4 u_routeParams; - -varying vec3 v_length; -varying vec4 v_color; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_routeParams; + vec4 u_color; + vec4 u_maskColor; + vec4 u_outlineColor; + vec4 u_fakeColor; + vec4 u_fakeOutlineColor; + vec2 u_fakeBorders; + vec2 u_pattern; + vec2 u_angleCosSin; + float u_arrowHalfWidth; + float u_opacity; +}; void main() { @@ -24,7 +36,6 @@ void main() if (u_routeParams.y != 0.0) len = vec2(a_length.x + a_length.y * u_routeParams.y, a_length.z); } - v_length = vec3(len, u_routeParams.z); v_color = a_color; vec4 pos = vec4(transformedAxisPos, a_position.z, 1.0) * u_projection; diff --git a/shaders/GL/route_arrow.fsh.glsl b/shaders/GL/route_arrow.fsh.glsl index 1f5d22e4fb..c926c7f50c 100644 --- a/shaders/GL/route_arrow.fsh.glsl +++ b/shaders/GL/route_arrow.fsh.glsl @@ -1,19 +1,36 @@ // Warning! Beware to use this shader. "discard" command may significally reduce performance. -// Unfortunately some CG algorithms cannot be implemented on OpenGL ES 2.0 without discarding -// fragments from depth buffer. +// Unfortunately some CG algorithms cannot be implemented without discarding fragments from depth buffer. -uniform sampler2D u_colorTex; -uniform float u_opacity; -uniform vec4 u_maskColor; +layout (location = 0) in vec2 v_colorTexCoords; -varying vec2 v_colorTexCoords; +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_routeParams; + vec4 u_color; + vec4 u_maskColor; + vec4 u_outlineColor; + vec4 u_fakeColor; + vec4 u_fakeOutlineColor; + vec2 u_fakeBorders; + vec2 u_pattern; + vec2 u_angleCosSin; + float u_arrowHalfWidth; + float u_opacity; +}; + +layout (binding = 1) uniform sampler2D u_colorTex; void main() { - vec4 finalColor = texture2D(u_colorTex, v_colorTexCoords); + vec4 finalColor = texture(u_colorTex, v_colorTexCoords); finalColor.a *= u_opacity; if (finalColor.a < 0.01) discard; finalColor = vec4(mix(finalColor.rgb, u_maskColor.rgb, u_maskColor.a), finalColor.a); - gl_FragColor = finalColor; + v_FragColor = finalColor; } diff --git a/shaders/GL/route_arrow.vsh.glsl b/shaders/GL/route_arrow.vsh.glsl index 31220de914..93a742dab2 100644 --- a/shaders/GL/route_arrow.vsh.glsl +++ b/shaders/GL/route_arrow.vsh.glsl @@ -1,14 +1,26 @@ -attribute vec4 a_position; -attribute vec2 a_normal; -attribute vec2 a_colorTexCoords; +layout (location = 0) in vec4 a_position; +layout (location = 1) in vec2 a_normal; +layout (location = 2) in vec2 a_colorTexCoords; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; +layout (location = 0) out vec2 v_colorTexCoords; -uniform float u_arrowHalfWidth; - -varying vec2 v_colorTexCoords; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_routeParams; + vec4 u_color; + vec4 u_maskColor; + vec4 u_outlineColor; + vec4 u_fakeColor; + vec4 u_fakeOutlineColor; + vec2 u_fakeBorders; + vec2 u_pattern; + vec2 u_angleCosSin; + float u_arrowHalfWidth; + float u_opacity; +}; void main() { @@ -19,9 +31,7 @@ void main() transformedAxisPos = calcLineTransformedAxisPos(transformedAxisPos, a_position.xy + norm, u_modelView, length(norm)); } - v_colorTexCoords = a_colorTexCoords; - vec4 pos = vec4(transformedAxisPos, a_position.z, 1.0) * u_projection; gl_Position = applyPivotTransform(pos, u_pivotTransform, 0.0); } diff --git a/shaders/GL/route_dash.fsh.glsl b/shaders/GL/route_dash.fsh.glsl index 484fd2ccc7..1f928e041d 100644 --- a/shaders/GL/route_dash.fsh.glsl +++ b/shaders/GL/route_dash.fsh.glsl @@ -1,20 +1,28 @@ // Warning! Beware to use this shader. "discard" command may significally reduce performance. -// Unfortunately some CG algorithms cannot be implemented on OpenGL ES 2.0 without discarding -// fragments from depth buffer. +// Unfortunately some CG algorithms cannot be implemented without discarding fragments from depth buffer. -varying vec3 v_length; -varying vec4 v_color; +layout (location = 0) in vec3 v_length; +layout (location = 1) in vec4 v_color; -#ifdef SAMSUNG_GOOGLE_NEXUS -uniform sampler2D u_colorTex; -#endif +layout (location = 0) out vec4 v_FragColor; -uniform vec4 u_color; -uniform vec2 u_pattern; -uniform vec4 u_maskColor; - -uniform vec2 u_fakeBorders; -uniform vec4 u_fakeColor; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_routeParams; + vec4 u_color; + vec4 u_maskColor; + vec4 u_outlineColor; + vec4 u_fakeColor; + vec4 u_fakeOutlineColor; + vec2 u_fakeBorders; + vec2 u_pattern; + vec2 u_angleCosSin; + float u_arrowHalfWidth; + float u_opacity; +}; const float kAntialiasingThreshold = 0.92; @@ -29,15 +37,13 @@ void main() { if (v_length.x < v_length.z) discard; - vec2 coefs = step(v_length.xx, u_fakeBorders); coefs.y = 1.0 - coefs.y; vec4 mainColor = mix(u_color, u_fakeColor, coefs.x); mainColor = mix(mainColor, u_fakeColor, coefs.y); - vec4 color = mainColor + v_color; color.a *= (1.0 - smoothstep(kAntialiasingThreshold, 1.0, abs(v_length.y))) * alphaFromPattern(v_length.x, u_pattern.x, u_pattern.y); color = vec4(mix(color.rgb, u_maskColor.rgb, u_maskColor.a), color.a); - gl_FragColor = samsungGoogleNexusWorkaround(color); + v_FragColor = color; } diff --git a/shaders/GL/route_marker.fsh.glsl b/shaders/GL/route_marker.fsh.glsl index 6b2f3f0f30..95bca7fdbe 100644 --- a/shaders/GL/route_marker.fsh.glsl +++ b/shaders/GL/route_marker.fsh.glsl @@ -1,31 +1,40 @@ // Warning! Beware to use this shader. "discard" command may significally reduce performance. -// Unfortunately some CG algorithms cannot be implemented on OpenGL ES 2.0 without discarding -// fragments from depth buffer. +// Unfortunately some CG algorithms cannot be implemented without discarding fragments from depth buffer. -#ifdef SAMSUNG_GOOGLE_NEXUS -uniform sampler2D u_colorTex; -#endif +layout (location = 0) in vec4 v_radius; +layout (location = 1) in vec4 v_color; -uniform vec4 u_routeParams; -uniform vec4 u_maskColor; -uniform float u_opacity; +layout (location = 0) out vec4 v_FragColor; -varying vec4 v_radius; -varying vec4 v_color; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_routeParams; + vec4 u_color; + vec4 u_maskColor; + vec4 u_outlineColor; + vec4 u_fakeColor; + vec4 u_fakeOutlineColor; + vec2 u_fakeBorders; + vec2 u_pattern; + vec2 u_angleCosSin; + float u_arrowHalfWidth; + float u_opacity; +}; const float kAntialiasingPixelsCount = 2.5; void main() { vec4 finalColor = v_color; - float aaRadius = max(v_radius.z - kAntialiasingPixelsCount, 0.0); float stepValue = smoothstep(aaRadius * aaRadius, v_radius.z * v_radius.z, dot(v_radius.xy, v_radius.xy)); finalColor.a = finalColor.a * u_opacity * (1.0 - stepValue); if (finalColor.a < 0.01 || u_routeParams.y > v_radius.w) discard; - finalColor = vec4(mix(finalColor.rgb, u_maskColor.rgb, u_maskColor.a), finalColor.a); - gl_FragColor = samsungGoogleNexusWorkaround(finalColor); + v_FragColor = finalColor; } diff --git a/shaders/GL/route_marker.vsh.glsl b/shaders/GL/route_marker.vsh.glsl index 5337255100..7bee7f473f 100644 --- a/shaders/GL/route_marker.vsh.glsl +++ b/shaders/GL/route_marker.vsh.glsl @@ -1,16 +1,27 @@ -attribute vec4 a_position; -attribute vec3 a_normal; -attribute vec4 a_color; +layout (location = 0) in vec4 a_position; +layout (location = 1) in vec3 a_normal; +layout (location = 2) in vec4 a_color; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; +layout (location = 0) out vec4 v_radius; +layout (location = 1) out vec4 v_color; -uniform vec2 u_angleCosSin; -uniform vec4 u_routeParams; - -varying vec4 v_radius; -varying vec4 v_color; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_routeParams; + vec4 u_color; + vec4 u_maskColor; + vec4 u_outlineColor; + vec4 u_fakeColor; + vec4 u_fakeOutlineColor; + vec2 u_fakeBorders; + vec2 u_pattern; + vec2 u_angleCosSin; + float u_arrowHalfWidth; + float u_opacity; +}; void main() { diff --git a/shaders/GL/ruler.fsh.glsl b/shaders/GL/ruler.fsh.glsl new file mode 100644 index 0000000000..667d16c4fa --- /dev/null +++ b/shaders/GL/ruler.fsh.glsl @@ -0,0 +1,23 @@ +layout (location = 0) in vec2 v_colorTexCoords; + +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + vec2 u_contrastGamma; + vec2 u_position; + float u_isOutlinePass; + float u_opacity; + float u_length; +}; + +layout (binding = 1) uniform sampler2D u_colorTex; + +void main() +{ + vec4 finalColor = texture(u_colorTex, v_colorTexCoords); + finalColor.a *= u_opacity; + v_FragColor = finalColor; +} diff --git a/shaders/GL/ruler.vsh.glsl b/shaders/GL/ruler.vsh.glsl index 9e07d36630..434df4c5f3 100644 --- a/shaders/GL/ruler.vsh.glsl +++ b/shaders/GL/ruler.vsh.glsl @@ -1,12 +1,19 @@ -attribute vec2 a_position; -attribute vec2 a_normal; -attribute vec2 a_colorTexCoords; +layout (location = 0) in vec2 a_position; +layout (location = 1) in vec2 a_normal; +layout (location = 2) in vec2 a_colorTexCoords; -uniform vec2 u_position; -uniform float u_length; -uniform mat4 u_projection; +layout (location = 0) out vec2 v_colorTexCoords; -varying vec2 v_colorTexCoords; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + vec2 u_contrastGamma; + vec2 u_position; + float u_isOutlinePass; + float u_opacity; + float u_length; +}; void main() { diff --git a/shaders/GL/screen_quad.fsh.glsl b/shaders/GL/screen_quad.fsh.glsl new file mode 100644 index 0000000000..d30f795529 --- /dev/null +++ b/shaders/GL/screen_quad.fsh.glsl @@ -0,0 +1,17 @@ +layout (location = 0) in vec2 v_colorTexCoords; + +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + float u_opacity; +}; + +layout (binding = 1) uniform sampler2D u_colorTex; + +void main() +{ + vec4 finalColor = texture(u_colorTex, v_colorTexCoords); + finalColor.a *= u_opacity; + v_FragColor = finalColor; +} diff --git a/shaders/GL/screen_quad.vsh.glsl b/shaders/GL/screen_quad.vsh.glsl index 388b7070ca..11485fc5a1 100644 --- a/shaders/GL/screen_quad.vsh.glsl +++ b/shaders/GL/screen_quad.vsh.glsl @@ -1,11 +1,10 @@ -attribute vec2 a_pos; -attribute vec2 a_tcoord; +layout (location = 0) in vec2 a_pos; +layout (location = 1) in vec2 a_tcoord; -varying vec2 v_colorTexCoords; +layout (location = 0) out vec2 v_colorTexCoords; void main() { v_colorTexCoords = a_tcoord; gl_Position = vec4(a_pos, 0.0, 1.0); } - diff --git a/shaders/GL/selection_line.fsh.glsl b/shaders/GL/selection_line.fsh.glsl index eec57e2987..55a832c62f 100644 --- a/shaders/GL/selection_line.fsh.glsl +++ b/shaders/GL/selection_line.fsh.glsl @@ -1,12 +1,25 @@ #ifdef ENABLE_VTF -varying LOW_P vec4 v_color; +layout (location = 0) in LOW_P vec4 v_color; #else -uniform sampler2D u_colorTex; -varying vec2 v_colorTexCoord; +layout (location = 1) in vec2 v_colorTexCoord; +layout (binding = 1) uniform sampler2D u_colorTex; #endif -uniform float u_opacity; +layout (location = 2) in float v_lengthY; -varying float v_lengthY; +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_position; + vec2 u_lineParams; + float u_accuracy; + float u_zScale; + float u_opacity; + float u_azimut; +}; const float kAntialiasingThreshold = 0.92; @@ -15,10 +28,9 @@ void main() #ifdef ENABLE_VTF LOW_P vec4 color = v_color; #else - LOW_P vec4 color = texture2D(u_colorTex, v_colorTexCoord); + LOW_P vec4 color = texture(u_colorTex, v_colorTexCoord); #endif color.a *= u_opacity; color.a *= (1.0 - smoothstep(kAntialiasingThreshold, 1.0, abs(v_lengthY))); - - gl_FragColor = samsungGoogleNexusWorkaround(color); + v_FragColor = color; } diff --git a/shaders/GL/selection_line.vsh.glsl b/shaders/GL/selection_line.vsh.glsl index 19c1137acd..4c262ff691 100644 --- a/shaders/GL/selection_line.vsh.glsl +++ b/shaders/GL/selection_line.vsh.glsl @@ -1,22 +1,33 @@ -attribute vec3 a_position; -attribute vec2 a_normal; -attribute vec2 a_colorTexCoords; -attribute vec3 a_length; - -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; - -uniform vec2 u_lineParams; +layout (location = 0) in vec3 a_position; +layout (location = 1) in vec2 a_normal; +layout (location = 2) in vec2 a_colorTexCoords; +layout (location = 3) in vec3 a_length; #ifdef ENABLE_VTF -uniform sampler2D u_colorTex; -varying LOW_P vec4 v_color; +layout (location = 0) out LOW_P vec4 v_color; #else -varying vec2 v_colorTexCoord; +layout (location = 1) out vec2 v_colorTexCoord; +#endif +layout (location = 2) out float v_lengthY; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_position; + vec2 u_lineParams; + float u_accuracy; + float u_zScale; + float u_opacity; + float u_azimut; +}; + +#ifdef ENABLE_VTF +layout (binding = 1) uniform sampler2D u_colorTex; #endif -varying float v_lengthY; +const float kAntialiasingThreshold = 0.92; void main() { @@ -30,9 +41,8 @@ void main() if (u_lineParams.y != 0.0) len = vec2(a_length.x + a_length.y * u_lineParams.y, a_length.z); } - #ifdef ENABLE_VTF - v_color = texture2D(u_colorTex, a_colorTexCoords); + v_color = texture(u_colorTex, a_colorTexCoords); #else v_colorTexCoord = a_colorTexCoords; #endif diff --git a/shaders/GL/shader_index.txt b/shaders/GL/shader_index.txt index 6103d27589..c7271a255a 100644 --- a/shaders/GL/shader_index.txt +++ b/shaders/GL/shader_index.txt @@ -5,8 +5,8 @@ Bookmark user_mark.vsh.glsl user_mark.fsh.glsl BookmarkAnim user_mark.vsh.glsl user_mark.fsh.glsl TextOutlined text_outlined.vsh.glsl text.fsh.glsl Text text.vsh.glsl text.fsh.glsl -TextStaticOutlinedGui text_outlined_gui.vsh.glsl text.fsh.glsl -TextOutlinedGui text_outlined_gui.vsh.glsl text.fsh.glsl +TextStaticOutlinedGui text_outlined_gui.vsh.glsl text_outlined_gui.fsh.glsl +TextOutlinedGui text_outlined_gui.vsh.glsl text_outlined_gui.fsh.glsl Area area.vsh.glsl solid_color.fsh.glsl AreaOutline area.vsh.glsl solid_color.fsh.glsl Area3d area3d.vsh.glsl texturing3d.fsh.glsl @@ -18,10 +18,10 @@ PathSymbol path_symbol.vsh.glsl texturing.fsh.glsl TransparentArea area.vsh.glsl solid_color.fsh.glsl CapJoin circle.vsh.glsl circle.fsh.glsl HatchingArea hatching_area.vsh.glsl hatching_area.fsh.glsl -TexturingGui texturing_gui.vsh.glsl texturing.fsh.glsl -Ruler ruler.vsh.glsl texturing.fsh.glsl -Accuracy position_accuracy3d.vsh.glsl texturing.fsh.glsl -MyPosition my_position.vsh.glsl texturing.fsh.glsl +TexturingGui texturing_gui.vsh.glsl texturing_gui.fsh.glsl +Ruler ruler.vsh.glsl ruler.fsh.glsl +Accuracy position_accuracy3d.vsh.glsl texturing_position.fsh.glsl +MyPosition my_position.vsh.glsl texturing_position.fsh.glsl SelectionLine selection_line.vsh.glsl selection_line.fsh.glsl Transit transit.vsh.glsl transit.fsh.glsl TransitMarker transit_marker.vsh.glsl transit_marker.fsh.glsl @@ -33,7 +33,7 @@ CirclePoint circle_point.vsh.glsl circle_point.fsh.glsl BookmarkAboveText user_mark.vsh.glsl user_mark.fsh.glsl BookmarkAnimAboveText user_mark.vsh.glsl user_mark.fsh.glsl DebugRect debug_rect.vsh.glsl debug_rect.fsh.glsl -ScreenQuad screen_quad.vsh.glsl texturing.fsh.glsl +ScreenQuad screen_quad.vsh.glsl screen_quad.fsh.glsl Arrow3d arrow3d.vsh.glsl arrow3d.fsh.glsl Arrow3dTextured arrow3d_textured.vsh.glsl arrow3d_textured.fsh.glsl Arrow3dShadow arrow3d_shadow.vsh.glsl arrow3d_shadow.fsh.glsl @@ -53,3 +53,4 @@ TrafficCircle traffic_circle.vsh.glsl traffic_circle.fsh.glsl SmaaEdges smaa_edges.vsh.glsl smaa_edges.fsh.glsl SmaaBlendingWeight smaa_blending_weight.vsh.glsl smaa_blending_weight.fsh.glsl SmaaFinal smaa_final.vsh.glsl smaa_final.fsh.glsl +ImGui imgui.vsh.glsl imgui.fsh.glsl diff --git a/shaders/GL/shaders_lib.glsl b/shaders/GL/shaders_lib.glsl index a7d41db76b..e70eb01516 100644 --- a/shaders/GL/shaders_lib.glsl +++ b/shaders/GL/shaders_lib.glsl @@ -47,15 +47,3 @@ vec2 calcLineTransformedAxisPos(vec2 originalAxisPos, vec2 shiftedPos, mat4 mode } // FS (DO NOT modify this comment, it marks up block of fragment shader functions). - -// Because of a bug in OpenGL driver on Samsung Google Nexus this workaround is here. -// It must be used in shaders which do not have any sampler2D usage. -vec4 samsungGoogleNexusWorkaround(vec4 color) -{ -#ifdef SAMSUNG_GOOGLE_NEXUS - const float kFakeColorScalar = 0.0; - return color + texture2D(u_colorTex, vec2(0.0, 0.0)) * kFakeColorScalar; -#else - return color; -#endif -} diff --git a/shaders/GL/smaa_blending_weight.fsh.glsl b/shaders/GL/smaa_blending_weight.fsh.glsl index 3fccfd2d71..15aec1ce80 100644 --- a/shaders/GL/smaa_blending_weight.fsh.glsl +++ b/shaders/GL/smaa_blending_weight.fsh.glsl @@ -1,37 +1,30 @@ // Implementation of Subpixel Morphological Antialiasing (SMAA) is based on https://github.com/iryoku/smaa +layout (location = 0) in vec4 v_coords; +layout (location = 1) in vec4 v_offset0; +layout (location = 2) in vec4 v_offset1; +layout (location = 3) in vec4 v_offset2; -uniform sampler2D u_colorTex; -uniform sampler2D u_smaaArea; -uniform sampler2D u_smaaSearch; +layout (location = 0) out vec4 v_FragColor; -uniform vec4 u_framebufferMetrics; +layout (binding = 0) uniform UBO +{ + vec4 u_framebufferMetrics; +}; -varying vec4 v_coords; -varying vec4 v_offset0; -varying vec4 v_offset1; -varying vec4 v_offset2; +layout (binding = 1) uniform sampler2D u_colorTex; +layout (binding = 2) uniform sampler2D u_smaaArea; +layout (binding = 3) uniform sampler2D u_smaaSearch; #define SMAA_SEARCHTEX_SIZE vec2(66.0, 33.0) #define SMAA_SEARCHTEX_PACKED_SIZE vec2(64.0, 16.0) #define SMAA_AREATEX_MAX_DISTANCE 16.0 #define SMAA_AREATEX_PIXEL_SIZE (vec2(1.0 / 256.0, 1.0 / 1024.0)) - -#ifdef GLES3 - #define SMAALoopBegin(condition) while (condition) { - #define SMAALoopEnd } - #define SMAASampleLevelZero(tex, coord) textureLod(tex, coord, 0.0) - #define SMAASampleLevelZeroOffset(tex, coord, offset) textureLodOffset(tex, coord, 0.0, offset) - #define SMAARound(v) round((v)) - #define SMAAOffset(x,y) ivec2(x,y) -#else - #define SMAA_MAX_SEARCH_STEPS 8 - #define SMAALoopBegin(condition) for (int i = 0; i < SMAA_MAX_SEARCH_STEPS; i++) { if (!(condition)) break; - #define SMAALoopEnd } - #define SMAASampleLevelZero(tex, coord) texture2D(tex, coord) - #define SMAASampleLevelZeroOffset(tex, coord, offset) texture2D(tex, coord + vec2(offset) * u_framebufferMetrics.xy) - #define SMAARound(v) floor((v) + 0.5) - #define SMAAOffset(x,y) vec2(x,y) -#endif +#define SMAALoopBegin(condition) while (condition) { +#define SMAALoopEnd } +#define SMAASampleLevelZero(tex, coord) textureLod(tex, coord, 0.0) +#define SMAASampleLevelZeroOffset(tex, coord, offset) textureLodOffset(tex, coord, 0.0, offset) +#define SMAARound(v) round((v)) +#define SMAAOffset(x,y) ivec2(x,y) const vec2 kAreaTexMaxDistance = vec2(SMAA_AREATEX_MAX_DISTANCE, SMAA_AREATEX_MAX_DISTANCE); const float kActivationThreshold = 0.8281; @@ -42,22 +35,15 @@ float SMAASearchLength(vec2 e, float offset) // of the space horizontally. vec2 scale = SMAA_SEARCHTEX_SIZE * vec2(0.5, -1.0); vec2 bias = SMAA_SEARCHTEX_SIZE * vec2(offset, 1.0); - // Scale and bias to access texel centers. scale += vec2(-1.0, 1.0); bias += vec2( 0.5, -0.5); - // Convert from pixel coordinates to texcoords. // (We use SMAA_SEARCHTEX_PACKED_SIZE because the texture is cropped). scale *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE; bias *= 1.0 / SMAA_SEARCHTEX_PACKED_SIZE; - // Lookup the search texture. -#ifdef GLES3 return SMAASampleLevelZero(u_smaaSearch, scale * e + bias).r; -#else - return SMAASampleLevelZero(u_smaaSearch, scale * e + bias).a; -#endif } float SMAASearchXLeft(vec2 texcoord, float end) @@ -118,74 +104,57 @@ vec2 SMAAArea(vec2 dist, float e1, float e2) void main() { vec4 weights = vec4(0.0, 0.0, 0.0, 0.0); - vec2 e = texture2D(u_colorTex, v_coords.xy).rg; - + vec2 e = texture(u_colorTex, v_coords.xy).rg; if (e.g > 0.0) // Edge at north { vec2 d; - // Find the distance to the left. vec3 coords; coords.x = SMAASearchXLeft(v_offset0.xy, v_offset2.x); coords.y = v_offset1.y; d.x = coords.x; - // Now fetch the left crossing edges, two at a time using bilinear // filtering. Sampling at -0.25 enables to discern what value each edge has. float e1 = SMAASampleLevelZero(u_colorTex, coords.xy).r; - // Find the distance to the right. coords.z = SMAASearchXRight(v_offset0.zw, v_offset2.y); d.y = coords.z; - // We want the distances to be in pixel units (doing this here allow to // better interleave arithmetic and memory accesses). vec2 zz = u_framebufferMetrics.zz; d = abs(SMAARound(zz * d - v_coords.zz)); - // SMAAArea below needs a sqrt, as the areas texture is compressed // quadratically. vec2 sqrt_d = sqrt(d); - // Fetch the right crossing edges. float e2 = SMAASampleLevelZeroOffset(u_colorTex, coords.zy, SMAAOffset(1, 0)).r; - // Here we know how this pattern looks like, now it is time for getting // the actual area. weights.rg = SMAAArea(sqrt_d, e1, e2); } - if (e.r > 0.0) // Edge at west { vec2 d; - // Find the distance to the top. vec3 coords; coords.y = SMAASearchYUp(v_offset1.xy, v_offset2.z); coords.x = v_offset0.x; d.x = coords.y; - // Fetch the top crossing edges. float e1 = SMAASampleLevelZero(u_colorTex, coords.xy).g; - // Find the distance to the bottom. coords.z = SMAASearchYDown(v_offset1.zw, v_offset2.w); d.y = coords.z; - // We want the distances to be in pixel units. vec2 ww = u_framebufferMetrics.ww; d = abs(SMAARound(ww * d - v_coords.ww)); - // SMAAArea below needs a sqrt, as the areas texture is compressed // quadratically. vec2 sqrt_d = sqrt(d); - // Fetch the bottom crossing edges. float e2 = SMAASampleLevelZeroOffset(u_colorTex, coords.xz, SMAAOffset(0, 1)).g; - // Get the area for this direction. weights.ba = SMAAArea(sqrt_d, e1, e2); } - - gl_FragColor = weights; + v_FragColor = weights; } diff --git a/shaders/GL/smaa_blending_weight.vsh.glsl b/shaders/GL/smaa_blending_weight.vsh.glsl index 621cd2a332..56444480c3 100644 --- a/shaders/GL/smaa_blending_weight.vsh.glsl +++ b/shaders/GL/smaa_blending_weight.vsh.glsl @@ -1,14 +1,16 @@ // Implementation of Subpixel Morphological Antialiasing (SMAA) is based on https://github.com/iryoku/smaa +layout (location = 0) in vec2 a_pos; +layout (location = 1) in vec2 a_tcoord; -attribute vec2 a_pos; -attribute vec2 a_tcoord; +layout (location = 0) out vec4 v_coords; +layout (location = 1) out vec4 v_offset0; +layout (location = 2) out vec4 v_offset1; +layout (location = 3) out vec4 v_offset2; -uniform vec4 u_framebufferMetrics; - -varying vec4 v_coords; -varying vec4 v_offset0; -varying vec4 v_offset1; -varying vec4 v_offset2; +layout (binding = 0) uniform UBO +{ + vec4 u_framebufferMetrics; +}; // SMAA_MAX_SEARCH_STEPS specifies the maximum steps performed in the // horizontal/vertical pattern searches, at each side of the pixel. diff --git a/shaders/GL/smaa_edges.fsh.glsl b/shaders/GL/smaa_edges.fsh.glsl index 69322a954d..a9efdf7d66 100644 --- a/shaders/GL/smaa_edges.fsh.glsl +++ b/shaders/GL/smaa_edges.fsh.glsl @@ -1,11 +1,12 @@ // Implementation of Subpixel Morphological Antialiasing (SMAA) is based on https://github.com/iryoku/smaa +layout (location = 0) in vec2 v_colorTexCoords; +layout (location = 1) in vec4 v_offset0; +layout (location = 2) in vec4 v_offset1; +layout (location = 3) in vec4 v_offset2; -uniform sampler2D u_colorTex; +layout (location = 0) out vec4 v_FragColor; -varying vec2 v_colorTexCoords; -varying vec4 v_offset0; -varying vec4 v_offset1; -varying vec4 v_offset2; +layout (binding = 1) uniform sampler2D u_colorTex; // SMAA_THRESHOLD specifies the threshold or sensitivity to edges. // Lowering this value you will be able to detect more edges at the expense of @@ -22,7 +23,6 @@ const vec2 kThreshold = vec2(SMAA_THRESHOLD, SMAA_THRESHOLD); // that, if there is too much contrast in a direction, that will hide // perceptually contrast in the other neighbors. #define SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR 2.0 - // Standard relative luminance weights. // https://en.wikipedia.org/wiki/Relative_luminance const vec3 kWeights = vec3(0.2126, 0.7152, 0.0722); @@ -30,36 +30,29 @@ const vec3 kWeights = vec3(0.2126, 0.7152, 0.0722); void main() { // Calculate lumas. - float L = dot(texture2D(u_colorTex, v_colorTexCoords).rgb, kWeights); - float Lleft = dot(texture2D(u_colorTex, v_offset0.xy).rgb, kWeights); - float Ltop = dot(texture2D(u_colorTex, v_offset0.zw).rgb, kWeights); - + float L = dot(texture(u_colorTex, v_colorTexCoords).rgb, kWeights); + float Lleft = dot(texture(u_colorTex, v_offset0.xy).rgb, kWeights); + float Ltop = dot(texture(u_colorTex, v_offset0.zw).rgb, kWeights); // We do the usual threshold. vec4 delta; delta.xy = abs(L - vec2(Lleft, Ltop)); vec2 edges = step(kThreshold, delta.xy); if (dot(edges, vec2(1.0, 1.0)) == 0.0) discard; - // Calculate right and bottom deltas. - float Lright = dot(texture2D(u_colorTex, v_offset1.xy).rgb, kWeights); - float Lbottom = dot(texture2D(u_colorTex, v_offset1.zw).rgb, kWeights); + float Lright = dot(texture(u_colorTex, v_offset1.xy).rgb, kWeights); + float Lbottom = dot(texture(u_colorTex, v_offset1.zw).rgb, kWeights); delta.zw = abs(L - vec2(Lright, Lbottom)); - // Calculate the maximum delta in the direct neighborhood. vec2 maxDelta = max(delta.xy, delta.zw); - // Calculate left-left and top-top deltas. - float Lleftleft = dot(texture2D(u_colorTex, v_offset2.xy).rgb, kWeights); - float Ltoptop = dot(texture2D(u_colorTex, v_offset2.zw).rgb, kWeights); + float Lleftleft = dot(texture(u_colorTex, v_offset2.xy).rgb, kWeights); + float Ltoptop = dot(texture(u_colorTex, v_offset2.zw).rgb, kWeights); delta.zw = abs(vec2(Lleft, Ltop) - vec2(Lleftleft, Ltoptop)); - // Calculate the final maximum delta. maxDelta = max(maxDelta.xy, delta.zw); float finalDelta = max(maxDelta.x, maxDelta.y); - // Local contrast adaptation edges *= step(finalDelta, SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR * delta.xy); - - gl_FragColor = vec4(edges, 0.0, 1.0); + v_FragColor = vec4(edges, 0.0, 1.0); } diff --git a/shaders/GL/smaa_edges.vsh.glsl b/shaders/GL/smaa_edges.vsh.glsl index efcd5e118d..67dc428804 100644 --- a/shaders/GL/smaa_edges.vsh.glsl +++ b/shaders/GL/smaa_edges.vsh.glsl @@ -1,14 +1,16 @@ // Implementation of Subpixel Morphological Antialiasing (SMAA) is based on https://github.com/iryoku/smaa +layout (location = 0) in vec2 a_pos; +layout (location = 1) in vec2 a_tcoord; -attribute vec2 a_pos; -attribute vec2 a_tcoord; +layout (location = 0) out vec2 v_colorTexCoords; +layout (location = 1) out vec4 v_offset0; +layout (location = 2) out vec4 v_offset1; +layout (location = 3) out vec4 v_offset2; -uniform vec4 u_framebufferMetrics; - -varying vec2 v_colorTexCoords; -varying vec4 v_offset0; -varying vec4 v_offset1; -varying vec4 v_offset2; +layout (binding = 0) uniform UBO +{ + vec4 u_framebufferMetrics; +}; void main() { @@ -18,4 +20,3 @@ void main() v_offset2 = u_framebufferMetrics.xyxy * vec4(-2.0, 0.0, 0.0, -2.0) + a_tcoord.xyxy; gl_Position = vec4(a_pos, 0.0, 1.0); } - diff --git a/shaders/GL/smaa_final.fsh.glsl b/shaders/GL/smaa_final.fsh.glsl index 01054dedb4..767f34c8a9 100644 --- a/shaders/GL/smaa_final.fsh.glsl +++ b/shaders/GL/smaa_final.fsh.glsl @@ -1,31 +1,31 @@ // Implementation of Subpixel Morphological Antialiasing (SMAA) is based on https://github.com/iryoku/smaa +layout (location = 0) in vec2 v_colorTexCoords; +layout (location = 1) in vec4 v_offset; -uniform sampler2D u_colorTex; -uniform sampler2D u_blendingWeightTex; +layout (location = 0) out vec4 v_FragColor; -uniform vec4 u_framebufferMetrics; +layout (binding = 0) uniform UBO +{ + vec4 u_framebufferMetrics; +}; -varying vec2 v_colorTexCoords; -varying vec4 v_offset; +layout (binding = 1) uniform sampler2D u_colorTex; -#ifdef GLES3 - #define SMAASampleLevelZero(tex, coord) textureLod(tex, coord, 0.0) -#else - #define SMAASampleLevelZero(tex, coord) texture2D(tex, coord) -#endif +layout (binding = 2) uniform sampler2D u_blendingWeightTex; + +#define SMAASampleLevelZero(tex, coord) textureLod(tex, coord, 0.0) void main() { // Fetch the blending weights for current pixel. vec4 a; - a.x = texture2D(u_blendingWeightTex, v_offset.xy).a; // Right - a.y = texture2D(u_blendingWeightTex, v_offset.zw).g; // Top - a.wz = texture2D(u_blendingWeightTex, v_colorTexCoords).xz; // Bottom / Left - + a.x = texture(u_blendingWeightTex, v_offset.xy).a; // Right + a.y = texture(u_blendingWeightTex, v_offset.zw).g; // Top + a.wz = texture(u_blendingWeightTex, v_colorTexCoords).xz; // Bottom / Left // Is there any blending weight with a value greater than 0.0? if (dot(a, vec4(1.0, 1.0, 1.0, 1.0)) < 1e-5) { - gl_FragColor = texture2D(u_colorTex, v_colorTexCoords); + v_FragColor = texture(u_colorTex, v_colorTexCoords); } else { @@ -38,14 +38,12 @@ void main() blendingWeight = a.xz; } blendingWeight /= dot(blendingWeight, vec2(1.0, 1.0)); - // Calculate the texture coordinates. vec4 bc = blendingOffset * vec4(u_framebufferMetrics.xy, -u_framebufferMetrics.xy); bc += v_colorTexCoords.xyxy; - // We exploit bilinear filtering to mix current pixel with the chosen neighbor. vec4 color = blendingWeight.x * SMAASampleLevelZero(u_colorTex, bc.xy); color += blendingWeight.y * SMAASampleLevelZero(u_colorTex, bc.zw); - gl_FragColor = color; + v_FragColor = color; } } diff --git a/shaders/GL/smaa_final.vsh.glsl b/shaders/GL/smaa_final.vsh.glsl index 7f872d4f1d..8a9752ac4b 100644 --- a/shaders/GL/smaa_final.vsh.glsl +++ b/shaders/GL/smaa_final.vsh.glsl @@ -1,12 +1,14 @@ // Implementation of Subpixel Morphological Antialiasing (SMAA) is based on https://github.com/iryoku/smaa +layout (location = 0) in vec2 a_pos; +layout (location = 1) in vec2 a_tcoord; -attribute vec2 a_pos; -attribute vec2 a_tcoord; +layout (location = 0) out vec2 v_colorTexCoords; +layout (location = 1) out vec4 v_offset; -uniform vec4 u_framebufferMetrics; - -varying vec2 v_colorTexCoords; -varying vec4 v_offset; +layout (binding = 0) uniform UBO +{ + vec4 u_framebufferMetrics; +}; void main() { diff --git a/shaders/GL/solid_color.fsh.glsl b/shaders/GL/solid_color.fsh.glsl index ac4440148e..5b1f53ba5e 100644 --- a/shaders/GL/solid_color.fsh.glsl +++ b/shaders/GL/solid_color.fsh.glsl @@ -1,20 +1,31 @@ -uniform float u_opacity; - #ifdef ENABLE_VTF -varying LOW_P vec4 v_color; +layout (location = 0) in LOW_P vec4 v_color; #else -uniform sampler2D u_colorTex; -varying vec2 v_colorTexCoords; +layout (location = 1) in vec2 v_colorTexCoords; +layout (binding = 1) uniform sampler2D u_colorTex; #endif +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + void main() { #ifdef ENABLE_VTF LOW_P vec4 finalColor = v_color; #else - LOW_P vec4 finalColor = texture2D(u_colorTex, v_colorTexCoords); + LOW_P vec4 finalColor = texture(u_colorTex, v_colorTexCoords); #endif finalColor.a *= u_opacity; - gl_FragColor = finalColor; + v_FragColor = finalColor; } - diff --git a/shaders/GL/text.fsh.glsl b/shaders/GL/text.fsh.glsl index b97e06f23d..eb1e15bada 100644 --- a/shaders/GL/text.fsh.glsl +++ b/shaders/GL/text.fsh.glsl @@ -1,29 +1,36 @@ #ifdef ENABLE_VTF -varying LOW_P vec4 v_color; +layout (location = 0) in LOW_P vec4 v_color; #else -varying vec2 v_colorTexCoord; -uniform sampler2D u_colorTex; +layout (location = 1) in vec2 v_colorTexCoord; +layout (binding = 1) uniform sampler2D u_colorTex; #endif +layout (location = 2) in vec2 v_maskTexCoord; -varying vec2 v_maskTexCoord; +layout (location = 0) out vec4 v_FragColor; -uniform sampler2D u_maskTex; -uniform float u_opacity; -uniform vec2 u_contrastGamma; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + +layout (binding = 2) uniform sampler2D u_maskTex; void main() { #ifdef ENABLE_VTF LOW_P vec4 glyphColor = v_color; #else - LOW_P vec4 glyphColor = texture2D(u_colorTex, v_colorTexCoord); -#endif -#ifdef GLES3 - float dist = texture2D(u_maskTex, v_maskTexCoord).r; -#else - float dist = texture2D(u_maskTex, v_maskTexCoord).a; + LOW_P vec4 glyphColor = texture(u_colorTex, v_colorTexCoord); #endif + float dist = texture(u_maskTex, v_maskTexCoord).r; float alpha = smoothstep(u_contrastGamma.x - u_contrastGamma.y, u_contrastGamma.x + u_contrastGamma.y, dist) * u_opacity; glyphColor.a *= alpha; - gl_FragColor = glyphColor; + v_FragColor = glyphColor; } diff --git a/shaders/GL/text.vsh.glsl b/shaders/GL/text.vsh.glsl index 0e8ced460b..b2669589a7 100644 --- a/shaders/GL/text.vsh.glsl +++ b/shaders/GL/text.vsh.glsl @@ -1,29 +1,38 @@ -attribute vec2 a_colorTexCoord; -attribute vec2 a_maskTexCoord; -attribute vec4 a_position; -attribute vec2 a_normal; - -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; +layout (location = 0) in vec2 a_colorTexCoord; +layout (location = 1) in vec2 a_maskTexCoord; +layout (location = 2) in vec4 a_position; +layout (location = 3) in vec2 a_normal; #ifdef ENABLE_VTF -uniform sampler2D u_colorTex; -varying LOW_P vec4 v_color; +layout (location = 0) out LOW_P vec4 v_color; #else -varying vec2 v_colorTexCoord; +layout (location = 1) out vec2 v_colorTexCoord; #endif +layout (location = 2) out vec2 v_maskTexCoord; -varying vec2 v_maskTexCoord; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + +#ifdef ENABLE_VTF +layout (binding = 1) uniform sampler2D u_colorTex; +#endif void main() { vec4 pos = vec4(a_position.xyz, 1) * u_modelView; vec4 shiftedPos = vec4(a_normal, 0.0, 0.0) + pos; gl_Position = applyPivotTransform(shiftedPos * u_projection, u_pivotTransform, 0.0); - #ifdef ENABLE_VTF - v_color = texture2D(u_colorTex, a_colorTexCoord); + v_color = texture(u_colorTex, a_colorTexCoord); #else v_colorTexCoord = a_colorTexCoord; #endif diff --git a/shaders/GL/text_billboard.vsh.glsl b/shaders/GL/text_billboard.vsh.glsl index 728b84979f..d11c440110 100644 --- a/shaders/GL/text_billboard.vsh.glsl +++ b/shaders/GL/text_billboard.vsh.glsl @@ -1,22 +1,28 @@ -attribute vec2 a_colorTexCoord; -attribute vec2 a_maskTexCoord; -attribute vec4 a_position; -attribute vec2 a_normal; - -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; -uniform float u_isOutlinePass; -uniform float u_zScale; +layout (location = 0) in vec2 a_colorTexCoord; +layout (location = 1) in vec2 a_maskTexCoord; +layout (location = 2) in vec4 a_position; +layout (location = 3) in vec2 a_normal; #ifdef ENABLE_VTF -uniform sampler2D u_colorTex; -varying LOW_P vec4 v_color; +layout (location = 0) out LOW_P vec4 v_color; #else -varying vec2 v_colorTexCoord; +layout (location = 1) out vec2 v_colorTexCoord; #endif +layout (location = 2) out vec2 v_maskTexCoord; -varying vec2 v_maskTexCoord; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + +layout (binding = 1) uniform sampler2D u_colorTex; void main() { @@ -25,7 +31,7 @@ void main() gl_Position = applyBillboardPivotTransform(pivot * u_projection, u_pivotTransform, a_position.w * u_zScale, offset.xy); #ifdef ENABLE_VTF - v_color = texture2D(u_colorTex, a_colorTexCoord); + v_color = texture(u_colorTex, a_colorTexCoord); #else v_colorTexCoord = a_colorTexCoord; #endif diff --git a/shaders/GL/text_outlined.vsh.glsl b/shaders/GL/text_outlined.vsh.glsl index 7e7b2d2d7c..851f0e09f3 100644 --- a/shaders/GL/text_outlined.vsh.glsl +++ b/shaders/GL/text_outlined.vsh.glsl @@ -1,22 +1,31 @@ -attribute vec2 a_colorTexCoord; -attribute vec2 a_outlineColorTexCoord; -attribute vec2 a_maskTexCoord; -attribute vec4 a_position; -attribute vec2 a_normal; - -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; -uniform float u_isOutlinePass; +layout (location = 0) in vec2 a_colorTexCoord; +layout (location = 1) in vec2 a_outlineColorTexCoord; +layout (location = 2) in vec2 a_maskTexCoord; +layout (location = 3) in vec4 a_position; +layout (location = 4) in vec2 a_normal; #ifdef ENABLE_VTF -uniform sampler2D u_colorTex; -varying LOW_P vec4 v_color; +layout (location = 0) out LOW_P vec4 v_color; #else -varying vec2 v_colorTexCoord; +layout (location = 1) out vec2 v_colorTexCoord; #endif +layout (location = 2) out vec2 v_maskTexCoord; -varying vec2 v_maskTexCoord; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + +#ifdef ENABLE_VTF +layout (binding = 1) uniform sampler2D u_colorTex; +#endif const float BaseDepthShift = -10.0; @@ -25,13 +34,12 @@ void main() float isOutline = step(0.5, u_isOutlinePass); float notOutline = 1.0 - isOutline; float depthShift = BaseDepthShift * isOutline; - vec4 pos = (vec4(a_position.xyz, 1) + vec4(0.0, 0.0, depthShift, 0.0)) * u_modelView; vec4 shiftedPos = vec4(a_normal, 0.0, 0.0) + pos; gl_Position = applyPivotTransform(shiftedPos * u_projection, u_pivotTransform, 0.0); vec2 colorTexCoord = a_colorTexCoord * notOutline + a_outlineColorTexCoord * isOutline; #ifdef ENABLE_VTF - v_color = texture2D(u_colorTex, colorTexCoord); + v_color = texture(u_colorTex, colorTexCoord); #else v_colorTexCoord = colorTexCoord; #endif diff --git a/shaders/GL/text_outlined_billboard.vsh.glsl b/shaders/GL/text_outlined_billboard.vsh.glsl index 0f23286d06..c7f1f6dbb2 100644 --- a/shaders/GL/text_outlined_billboard.vsh.glsl +++ b/shaders/GL/text_outlined_billboard.vsh.glsl @@ -1,23 +1,29 @@ -attribute vec2 a_colorTexCoord; -attribute vec2 a_outlineColorTexCoord; -attribute vec2 a_maskTexCoord; -attribute vec4 a_position; -attribute vec2 a_normal; - -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; -uniform float u_isOutlinePass; -uniform float u_zScale; +layout (location = 0) in vec2 a_colorTexCoord; +layout (location = 1) in vec2 a_outlineColorTexCoord; +layout (location = 2) in vec2 a_maskTexCoord; +layout (location = 3) in vec4 a_position; +layout (location = 4) in vec2 a_normal; #ifdef ENABLE_VTF -uniform sampler2D u_colorTex; -varying LOW_P vec4 v_color; +layout (location = 0) out LOW_P vec4 v_color; #else -varying vec2 v_colorTexCoord; +layout (location = 1) out vec2 v_colorTexCoord; #endif +layout (location = 2) out vec2 v_maskTexCoord; -varying vec2 v_maskTexCoord; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + +layout (binding = 1) uniform sampler2D u_colorTex; const float kBaseDepthShift = -10.0; @@ -25,15 +31,13 @@ void main() { float isOutline = step(0.5, u_isOutlinePass); float depthShift = kBaseDepthShift * isOutline; - vec4 pivot = (vec4(a_position.xyz, 1.0) + vec4(0.0, 0.0, depthShift, 0.0)) * u_modelView; vec4 offset = vec4(a_normal, 0.0, 0.0) * u_projection; gl_Position = applyBillboardPivotTransform(pivot * u_projection, u_pivotTransform, a_position.w * u_zScale, offset.xy); - vec2 colorTexCoord = mix(a_colorTexCoord, a_outlineColorTexCoord, isOutline); #ifdef ENABLE_VTF - v_color = texture2D(u_colorTex, colorTexCoord); + v_color = texture(u_colorTex, colorTexCoord); #else v_colorTexCoord = colorTexCoord; #endif diff --git a/shaders/GL/text_outlined_gui.fsh.glsl b/shaders/GL/text_outlined_gui.fsh.glsl new file mode 100644 index 0000000000..e5cd02a342 --- /dev/null +++ b/shaders/GL/text_outlined_gui.fsh.glsl @@ -0,0 +1,35 @@ +#ifdef ENABLE_VTF +layout (location = 0) in LOW_P vec4 v_color; +#else +layout (location = 1) in vec2 v_colorTexCoord; +layout (binding = 1) uniform sampler2D u_colorTex; +#endif +layout (location = 2) in vec2 v_maskTexCoord; + +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + vec2 u_contrastGamma; + vec2 u_position; + float u_isOutlinePass; + float u_opacity; + float u_length; +}; + +layout (binding = 2) uniform sampler2D u_maskTex; + +void main() +{ +#ifdef ENABLE_VTF + LOW_P vec4 glyphColor = v_color; +#else + LOW_P vec4 glyphColor = texture(u_colorTex, v_colorTexCoord); +#endif + float dist = texture(u_maskTex, v_maskTexCoord).r; + float alpha = smoothstep(u_contrastGamma.x - u_contrastGamma.y, u_contrastGamma.x + u_contrastGamma.y, dist) * u_opacity; + glyphColor.a *= alpha; + v_FragColor = glyphColor; +} diff --git a/shaders/GL/text_outlined_gui.vsh.glsl b/shaders/GL/text_outlined_gui.vsh.glsl index 29637d475f..a242ba5d1b 100644 --- a/shaders/GL/text_outlined_gui.vsh.glsl +++ b/shaders/GL/text_outlined_gui.vsh.glsl @@ -1,21 +1,30 @@ -attribute vec3 a_position; -attribute vec2 a_colorTexCoord; -attribute vec2 a_outlineColorTexCoord; -attribute vec2 a_normal; -attribute vec2 a_maskTexCoord; - -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform float u_isOutlinePass; +layout (location = 0) in vec3 a_position; +layout (location = 1) in vec2 a_colorTexCoord; +layout (location = 2) in vec2 a_outlineColorTexCoord; +layout (location = 3) in vec2 a_normal; +layout (location = 4) in vec2 a_maskTexCoord; #ifdef ENABLE_VTF -uniform sampler2D u_colorTex; -varying LOW_P vec4 v_color; +layout (location = 0) out LOW_P vec4 v_color; #else -varying vec2 v_colorTexCoord; +layout (location = 1) out vec2 v_colorTexCoord; #endif +layout (location = 2) out vec2 v_maskTexCoord; -varying vec2 v_maskTexCoord; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + vec2 u_contrastGamma; + vec2 u_position; + float u_isOutlinePass; + float u_opacity; + float u_length; +}; + +#ifdef ENABLE_VTF +layout (binding = 1) uniform sampler2D u_colorTex; +#endif const float kBaseDepthShift = -10.0; @@ -23,7 +32,6 @@ void main() { float isOutline = step(0.5, u_isOutlinePass); float depthShift = kBaseDepthShift * isOutline; - vec4 pos = (vec4(a_position, 1.0) + vec4(0.0, 0.0, depthShift, 0.0)) * u_modelView; vec4 shiftedPos = vec4(a_normal, 0.0, 0.0) + pos; gl_Position = shiftedPos * u_projection; @@ -33,7 +41,7 @@ void main() #endif vec2 colorTexCoord = mix(a_colorTexCoord, a_outlineColorTexCoord, isOutline); #ifdef ENABLE_VTF - v_color = texture2D(u_colorTex, colorTexCoord); + v_color = texture(u_colorTex, colorTexCoord); #else v_colorTexCoord = colorTexCoord; #endif diff --git a/shaders/GL/texturing.fsh.glsl b/shaders/GL/texturing.fsh.glsl index 8cc8109387..d8a628df66 100644 --- a/shaders/GL/texturing.fsh.glsl +++ b/shaders/GL/texturing.fsh.glsl @@ -1,11 +1,24 @@ -uniform sampler2D u_colorTex; -uniform float u_opacity; +layout (location = 0) in vec2 v_colorTexCoords; -varying vec2 v_colorTexCoords; +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + +layout (binding = 1) uniform sampler2D u_colorTex; void main() { - vec4 finalColor = texture2D(u_colorTex, v_colorTexCoords); + vec4 finalColor = texture(u_colorTex, v_colorTexCoords); finalColor.a *= u_opacity; - gl_FragColor = finalColor; + v_FragColor = finalColor; } diff --git a/shaders/GL/texturing.vsh.glsl b/shaders/GL/texturing.vsh.glsl index 9121006cf5..224778c7c2 100644 --- a/shaders/GL/texturing.vsh.glsl +++ b/shaders/GL/texturing.vsh.glsl @@ -1,12 +1,20 @@ -attribute vec4 a_position; -attribute vec2 a_normal; -attribute vec2 a_colorTexCoords; +layout (location = 0) in vec4 a_position; +layout (location = 1) in vec2 a_normal; +layout (location = 2) in vec2 a_colorTexCoords; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; +layout (location = 0) out vec2 v_colorTexCoords; -varying vec2 v_colorTexCoords; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; void main() { diff --git a/shaders/GL/texturing3d.fsh.glsl b/shaders/GL/texturing3d.fsh.glsl index 961ab161f4..22c6516cf3 100644 --- a/shaders/GL/texturing3d.fsh.glsl +++ b/shaders/GL/texturing3d.fsh.glsl @@ -1,11 +1,24 @@ -uniform sampler2D u_colorTex; -uniform float u_opacity; +layout (location = 0) in vec2 v_colorTexCoords; +layout (location = 1) in float v_intensity; -varying vec2 v_colorTexCoords; -varying float v_intensity; +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + +layout (binding = 1) uniform sampler2D u_colorTex; void main() { - vec4 finalColor = vec4(texture2D(u_colorTex, v_colorTexCoords).rgb, u_opacity); - gl_FragColor = vec4((v_intensity * 0.2 + 0.8) * finalColor.rgb, finalColor.a); + vec4 finalColor = vec4(texture(u_colorTex, v_colorTexCoords).rgb, u_opacity); + v_FragColor = vec4((v_intensity * 0.2 + 0.8) * finalColor.rgb, finalColor.a); } diff --git a/shaders/GL/texturing_billboard.vsh.glsl b/shaders/GL/texturing_billboard.vsh.glsl index 5c3d5774d9..e68b97c8f2 100644 --- a/shaders/GL/texturing_billboard.vsh.glsl +++ b/shaders/GL/texturing_billboard.vsh.glsl @@ -1,13 +1,20 @@ -attribute vec4 a_position; -attribute vec2 a_normal; -attribute vec2 a_colorTexCoords; +layout (location = 0) in vec4 a_position; +layout (location = 1) in vec2 a_normal; +layout (location = 2) in vec2 a_colorTexCoords; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; -uniform float u_zScale; +layout (location = 0) out vec2 v_colorTexCoords; -varying vec2 v_colorTexCoords; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; void main() { diff --git a/shaders/GL/texturing_gui.fsh.glsl b/shaders/GL/texturing_gui.fsh.glsl new file mode 100644 index 0000000000..667d16c4fa --- /dev/null +++ b/shaders/GL/texturing_gui.fsh.glsl @@ -0,0 +1,23 @@ +layout (location = 0) in vec2 v_colorTexCoords; + +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + vec2 u_contrastGamma; + vec2 u_position; + float u_isOutlinePass; + float u_opacity; + float u_length; +}; + +layout (binding = 1) uniform sampler2D u_colorTex; + +void main() +{ + vec4 finalColor = texture(u_colorTex, v_colorTexCoords); + finalColor.a *= u_opacity; + v_FragColor = finalColor; +} diff --git a/shaders/GL/texturing_gui.vsh.glsl b/shaders/GL/texturing_gui.vsh.glsl index eaff57467a..74aac5d49d 100644 --- a/shaders/GL/texturing_gui.vsh.glsl +++ b/shaders/GL/texturing_gui.vsh.glsl @@ -1,10 +1,18 @@ -attribute vec2 a_position; -attribute vec2 a_colorTexCoords; +layout (location = 0) in vec2 a_position; +layout (location = 1) in vec2 a_colorTexCoords; -uniform mat4 u_modelView; -uniform mat4 u_projection; +layout (location = 0) out vec2 v_colorTexCoords; -varying vec2 v_colorTexCoords; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + vec2 u_contrastGamma; + vec2 u_position; + float u_isOutlinePass; + float u_opacity; + float u_length; +}; void main() { diff --git a/shaders/GL/texturing_position.fsh.glsl b/shaders/GL/texturing_position.fsh.glsl new file mode 100644 index 0000000000..c5ad5a77e0 --- /dev/null +++ b/shaders/GL/texturing_position.fsh.glsl @@ -0,0 +1,25 @@ +layout (location = 0) in vec2 v_colorTexCoords; + +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_position; + vec2 u_lineParams; + float u_accuracy; + float u_zScale; + float u_opacity; + float u_azimut; +}; + +layout (binding = 1) uniform sampler2D u_colorTex; + +void main() +{ + vec4 finalColor = texture(u_colorTex, v_colorTexCoords); + finalColor.a *= u_opacity; + v_FragColor = finalColor; +} diff --git a/shaders/GL/traffic.fsh.glsl b/shaders/GL/traffic.fsh.glsl index 82a43bf0ad..9e631f075e 100644 --- a/shaders/GL/traffic.fsh.glsl +++ b/shaders/GL/traffic.fsh.glsl @@ -1,34 +1,41 @@ -varying vec2 v_colorTexCoord; -varying vec2 v_maskTexCoord; -varying float v_halfLength; +layout (location = 0) in vec2 v_colorTexCoord; +layout (location = 1) in vec2 v_maskTexCoord; +layout (location = 2) in float v_halfLength; -uniform sampler2D u_colorTex; -uniform sampler2D u_maskTex; -uniform float u_opacity; -uniform float u_outline; +layout (location = 0) out vec4 v_FragColor; -uniform vec3 u_lightArrowColor; -uniform vec3 u_darkArrowColor; -uniform vec3 u_outlineColor; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_trafficParams; + vec4 u_outlineColor; + vec4 u_lightArrowColor; + vec4 u_darkArrowColor; + float u_outline; + float u_opacity; +}; + +layout (binding = 1) uniform sampler2D u_colorTex; +layout (binding = 2) uniform sampler2D u_maskTex; const float kAntialiasingThreshold = 0.92; - const float kOutlineThreshold1 = 0.8; const float kOutlineThreshold2 = 0.5; - const float kMaskOpacity = 0.7; void main() { - vec4 color = texture2D(u_colorTex, v_colorTexCoord); + vec4 color = texture(u_colorTex, v_colorTexCoord); float alphaCode = color.a; - vec4 mask = texture2D(u_maskTex, v_maskTexCoord); + vec4 mask = texture(u_maskTex, v_maskTexCoord); color.a = u_opacity * (1.0 - smoothstep(kAntialiasingThreshold, 1.0, abs(v_halfLength))); - color.rgb = mix(color.rgb, mask.rgb * mix(u_lightArrowColor, u_darkArrowColor, step(alphaCode, 0.6)), mask.a * kMaskOpacity); + color.rgb = mix(color.rgb, mask.rgb * mix(u_lightArrowColor.rgb, u_darkArrowColor.rgb, step(alphaCode, 0.6)), mask.a * kMaskOpacity); if (u_outline > 0.0) { - color.rgb = mix(color.rgb, u_outlineColor, step(kOutlineThreshold1, abs(v_halfLength))); - color.rgb = mix(color.rgb, u_outlineColor, smoothstep(kOutlineThreshold2, kOutlineThreshold1, abs(v_halfLength))); + color.rgb = mix(color.rgb, u_outlineColor.rgb, step(kOutlineThreshold1, abs(v_halfLength))); + color.rgb = mix(color.rgb, u_outlineColor.rgb, smoothstep(kOutlineThreshold2, kOutlineThreshold1, abs(v_halfLength))); } - gl_FragColor = color; + v_FragColor = color; } diff --git a/shaders/GL/traffic.vsh.glsl b/shaders/GL/traffic.vsh.glsl index 6706859bbd..ae06dfdb4f 100644 --- a/shaders/GL/traffic.vsh.glsl +++ b/shaders/GL/traffic.vsh.glsl @@ -1,16 +1,23 @@ -attribute vec3 a_position; -attribute vec4 a_normal; -attribute vec4 a_colorTexCoord; +layout (location = 0) in vec3 a_position; +layout (location = 1) in vec4 a_normal; +layout (location = 2) in vec4 a_colorTexCoord; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; +layout (location = 0) out vec2 v_colorTexCoord; +layout (location = 1) out vec2 v_maskTexCoord; +layout (location = 2) out float v_halfLength; -uniform vec4 u_trafficParams; - -varying vec2 v_colorTexCoord; -varying vec2 v_maskTexCoord; -varying float v_halfLength; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_trafficParams; + vec4 u_outlineColor; + vec4 u_lightArrowColor; + vec4 u_darkArrowColor; + float u_outline; + float u_opacity; +}; const float kArrowVSize = 0.25; @@ -26,7 +33,6 @@ void main() transformedAxisPos = calcLineTransformedAxisPos(transformedAxisPos, a_position.xy + norm, u_modelView, length(norm)); } - float uOffset = length(vec4(kShapeCoordScalar, 0, 0, 0) * u_modelView) * a_normal.w; v_colorTexCoord = a_colorTexCoord.xy; float v = mix(a_colorTexCoord.z, a_colorTexCoord.z + kArrowVSize, 0.5 * a_normal.z + 0.5); diff --git a/shaders/GL/traffic_circle.fsh.glsl b/shaders/GL/traffic_circle.fsh.glsl index e26402112d..42c952913c 100644 --- a/shaders/GL/traffic_circle.fsh.glsl +++ b/shaders/GL/traffic_circle.fsh.glsl @@ -1,23 +1,36 @@ // Warning! Beware to use this shader. "discard" command may significally reduce performance. -// Unfortunately some CG algorithms cannot be implemented on OpenGL ES 2.0 without discarding -// fragments from depth buffer. +// Unfortunately some CG algorithms cannot be implemented without discarding fragments from depth buffer. -varying vec2 v_colorTexCoord; -varying vec3 v_radius; +layout (location = 0) in vec2 v_colorTexCoord; +layout (location = 1) in vec3 v_radius; -uniform sampler2D u_colorTex; -uniform float u_opacity; +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_trafficParams; + vec4 u_outlineColor; + vec4 u_lightArrowColor; + vec4 u_darkArrowColor; + float u_outline; + float u_opacity; +}; + +layout (binding = 1) uniform sampler2D u_colorTex; const float kAntialiasingThreshold = 0.92; void main() { - vec4 color = texture2D(u_colorTex, v_colorTexCoord); + vec4 color = texture(u_colorTex, v_colorTexCoord); float smallRadius = v_radius.z * kAntialiasingThreshold; float stepValue = smoothstep(smallRadius * smallRadius, v_radius.z * v_radius.z, v_radius.x * v_radius.x + v_radius.y * v_radius.y); color.a = u_opacity * (1.0 - stepValue); if (color.a < 0.01) discard; - gl_FragColor = color; + v_FragColor = color; } diff --git a/shaders/GL/traffic_circle.vsh.glsl b/shaders/GL/traffic_circle.vsh.glsl index 914f0ba838..e0e022ffe7 100644 --- a/shaders/GL/traffic_circle.vsh.glsl +++ b/shaders/GL/traffic_circle.vsh.glsl @@ -1,16 +1,22 @@ -attribute vec4 a_position; -attribute vec4 a_normal; -attribute vec2 a_colorTexCoord; +layout (location = 0) in vec4 a_position; +layout (location = 1) in vec4 a_normal; +layout (location = 2) in vec2 a_colorTexCoord; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; +layout (location = 0) out vec2 v_colorTexCoord; +layout (location = 1) out vec3 v_radius; -uniform vec3 u_lightArrowColor; // Here we store left sizes by road classes. -uniform vec3 u_darkArrowColor; // Here we store right sizes by road classes. - -varying vec2 v_colorTexCoord; -varying vec3 v_radius; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_trafficParams; + vec4 u_outlineColor; + vec4 u_lightArrowColor; + vec4 u_darkArrowColor; + float u_outline; + float u_opacity; +}; void main() { @@ -28,7 +34,6 @@ void main() } // radius = (leftSize + rightSize) / 2 v_radius = vec3(a_normal.zw, 1.0) * 0.5 * (leftSize + rightSize); - vec2 finalPos = transformedAxisPos + v_radius.xy; v_colorTexCoord = a_colorTexCoord; vec4 pos = vec4(finalPos, a_position.z, 1.0) * u_projection; diff --git a/shaders/GL/traffic_line.fsh.glsl b/shaders/GL/traffic_line.fsh.glsl index ad8a8fdbba..230dd72f1d 100644 --- a/shaders/GL/traffic_line.fsh.glsl +++ b/shaders/GL/traffic_line.fsh.glsl @@ -1,10 +1,24 @@ -uniform sampler2D u_colorTex; -uniform float u_opacity; +layout (location = 0) in vec2 v_colorTexCoord; -varying vec2 v_colorTexCoord; +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_trafficParams; + vec4 u_outlineColor; + vec4 u_lightArrowColor; + vec4 u_darkArrowColor; + float u_outline; + float u_opacity; +}; + +layout (binding = 1) uniform sampler2D u_colorTex; void main() { - vec4 color = texture2D(u_colorTex, v_colorTexCoord); - gl_FragColor = vec4(color.rgb, u_opacity); + vec4 color = texture(u_colorTex, v_colorTexCoord); + v_FragColor = vec4(color.rgb, u_opacity); } diff --git a/shaders/GL/traffic_line.vsh.glsl b/shaders/GL/traffic_line.vsh.glsl index 3162dd5761..0b21a74b37 100644 --- a/shaders/GL/traffic_line.vsh.glsl +++ b/shaders/GL/traffic_line.vsh.glsl @@ -1,11 +1,20 @@ -attribute vec3 a_position; -attribute vec2 a_colorTexCoord; +layout (location = 0) in vec3 a_position; +layout (location = 1) in vec2 a_colorTexCoord; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; +layout (location = 0) out vec2 v_colorTexCoord; -varying vec2 v_colorTexCoord; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_trafficParams; + vec4 u_outlineColor; + vec4 u_lightArrowColor; + vec4 u_darkArrowColor; + float u_outline; + float u_opacity; +}; void main() { diff --git a/shaders/GL/transit.fsh.glsl b/shaders/GL/transit.fsh.glsl index 2ba51ec669..db534f2d45 100644 --- a/shaders/GL/transit.fsh.glsl +++ b/shaders/GL/transit.fsh.glsl @@ -1,10 +1,8 @@ -#ifdef SAMSUNG_GOOGLE_NEXUS -uniform sampler2D u_colorTex; -#endif +layout (location = 0) in vec4 v_color; -varying vec4 v_color; +layout (location = 0) out vec4 v_FragColor; void main() { - gl_FragColor = samsungGoogleNexusWorkaround(v_color); + v_FragColor = v_color; } diff --git a/shaders/GL/transit.vsh.glsl b/shaders/GL/transit.vsh.glsl index 39f7ffd7ec..4765e91d8d 100644 --- a/shaders/GL/transit.vsh.glsl +++ b/shaders/GL/transit.vsh.glsl @@ -1,14 +1,18 @@ -attribute vec3 a_position; -attribute vec4 a_normal; -attribute vec4 a_color; +layout (location = 0) in vec3 a_position; +layout (location = 1) in vec4 a_normal; +layout (location = 2) in vec4 a_color; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; +layout (location = 0) out vec4 v_color; -uniform float u_lineHalfWidth; - -varying vec4 v_color; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_params; + float u_lineHalfWidth; + float u_maxRadius; +}; void main() { diff --git a/shaders/GL/transit_circle.fsh.glsl b/shaders/GL/transit_circle.fsh.glsl index 8eb6bb9aea..d173f68f72 100644 --- a/shaders/GL/transit_circle.fsh.glsl +++ b/shaders/GL/transit_circle.fsh.glsl @@ -1,25 +1,21 @@ // Warning! Beware to use this shader. "discard" command may significally reduce performance. -// Unfortunately some CG algorithms cannot be implemented on OpenGL ES 2.0 without discarding -// fragments from depth buffer. +// Unfortunately some CG algorithms cannot be implemented without discarding fragments from depth buffer. -varying vec3 v_radius; -varying vec4 v_color; +layout (location = 0) in vec3 v_radius; +layout (location = 1) in vec4 v_color; -#ifdef SAMSUNG_GOOGLE_NEXUS -uniform sampler2D u_colorTex; -#endif +layout (location = 0) out vec4 v_FragColor; const float aaPixelsCount = 2.5; void main() { vec4 finalColor = v_color; - float smallRadius = v_radius.z - aaPixelsCount; float stepValue = smoothstep(smallRadius * smallRadius, v_radius.z * v_radius.z, dot(v_radius.xy, v_radius.xy)); finalColor.a = finalColor.a * (1.0 - stepValue); if (finalColor.a < 0.01) discard; - gl_FragColor = samsungGoogleNexusWorkaround(finalColor); + v_FragColor = finalColor; } diff --git a/shaders/GL/transit_circle.vsh.glsl b/shaders/GL/transit_circle.vsh.glsl index b2bc5c1d6d..6595d1c13c 100644 --- a/shaders/GL/transit_circle.vsh.glsl +++ b/shaders/GL/transit_circle.vsh.glsl @@ -1,16 +1,19 @@ -attribute vec3 a_position; -attribute vec4 a_normal; -attribute vec4 a_color; +layout (location = 0) in vec3 a_position; +layout (location = 1) in vec4 a_normal; +layout (location = 2) in vec4 a_color; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; +layout (location = 0) out vec3 v_radius; +layout (location = 1) out vec4 v_color; -uniform float u_lineHalfWidth; -uniform float u_maxRadius; - -varying vec3 v_radius; -varying vec4 v_color; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_params; + float u_lineHalfWidth; + float u_maxRadius; +}; void main() { diff --git a/shaders/GL/transit_marker.fsh.glsl b/shaders/GL/transit_marker.fsh.glsl index d50f86528b..9a44781a11 100644 --- a/shaders/GL/transit_marker.fsh.glsl +++ b/shaders/GL/transit_marker.fsh.glsl @@ -1,9 +1,7 @@ -#ifdef SAMSUNG_GOOGLE_NEXUS -uniform sampler2D u_colorTex; -#endif +layout (location = 0) in vec4 v_offsets; +layout (location = 1) in vec4 v_color; -varying vec4 v_offsets; -varying vec4 v_color; +layout (location = 0) out vec4 v_FragColor; void main() { @@ -11,11 +9,9 @@ void main() vec2 radius; radius.x = max(0.0, abs(v_offsets.x) - v_offsets.z); radius.y = max(0.0, abs(v_offsets.y) - v_offsets.w); - float maxRadius = 1.0; float aaRadius = 0.9; float stepValue = smoothstep(aaRadius * aaRadius, maxRadius * maxRadius, dot(radius.xy, radius.xy)); finalColor.a = finalColor.a * (1.0 - stepValue); - - gl_FragColor = samsungGoogleNexusWorkaround(finalColor); + v_FragColor = finalColor; } diff --git a/shaders/GL/transit_marker.vsh.glsl b/shaders/GL/transit_marker.vsh.glsl index 6e9d560a0c..27a6c12c8e 100644 --- a/shaders/GL/transit_marker.vsh.glsl +++ b/shaders/GL/transit_marker.vsh.glsl @@ -1,15 +1,19 @@ -attribute vec3 a_position; -attribute vec4 a_normal; -attribute vec4 a_color; +layout (location = 0) in vec3 a_position; +layout (location = 1) in vec4 a_normal; +layout (location = 2) in vec4 a_color; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; +layout (location = 0) out vec4 v_offsets; +layout (location = 1) out vec4 v_color; -uniform vec3 u_params; - -varying vec4 v_offsets; -varying vec4 v_color; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec4 u_params; + float u_lineHalfWidth; + float u_maxRadius; +}; void main() { diff --git a/shaders/GL/user_mark.fsh.glsl b/shaders/GL/user_mark.fsh.glsl index c6e4753b1c..ef07a95de3 100644 --- a/shaders/GL/user_mark.fsh.glsl +++ b/shaders/GL/user_mark.fsh.glsl @@ -1,20 +1,32 @@ // Warning! Beware to use this shader. "discard" command may significally reduce performance. -// Unfortunately some CG algorithms cannot be implemented on OpenGL ES 2.0 without discarding -// fragments from depth buffer. +// Unfortunately some CG algorithms cannot be implemented without discarding fragments from depth buffer. -uniform sampler2D u_colorTex; -uniform float u_opacity; +layout (location = 0) in vec4 v_texCoords; +layout (location = 1) in vec4 v_maskColor; -varying vec4 v_texCoords; -varying vec4 v_maskColor; +layout (location = 0) out vec4 v_FragColor; + +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; + +layout (binding = 1) uniform sampler2D u_colorTex; void main() { - vec4 color = texture2D(u_colorTex, v_texCoords.xy); - vec4 bgColor = texture2D(u_colorTex, v_texCoords.zw) * vec4(v_maskColor.xyz, 1.0); + vec4 color = texture(u_colorTex, v_texCoords.xy); + vec4 bgColor = texture(u_colorTex, v_texCoords.zw) * vec4(v_maskColor.xyz, 1.0); vec4 finalColor = mix(color, mix(bgColor, color, color.a), bgColor.a); finalColor.a = clamp(color.a + bgColor.a, 0.0, 1.0) * u_opacity * v_maskColor.w; if (finalColor.a < 0.01) discard; - gl_FragColor = finalColor; + v_FragColor = finalColor; } diff --git a/shaders/GL/user_mark.vsh.glsl b/shaders/GL/user_mark.vsh.glsl index 6c17cf4cc7..d9e150e6c0 100644 --- a/shaders/GL/user_mark.vsh.glsl +++ b/shaders/GL/user_mark.vsh.glsl @@ -1,22 +1,28 @@ -attribute vec3 a_position; -attribute vec3 a_normalAndAnimateOrZ; -attribute vec4 a_texCoords; -attribute vec4 a_color; +layout (location = 0) in vec3 a_position; +layout (location = 1) in vec3 a_normalAndAnimateOrZ; +layout (location = 2) in vec4 a_texCoords; +layout (location = 3) in vec4 a_color; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; -uniform float u_interpolation; +layout (location = 0) out vec4 v_texCoords; +layout (location = 1) out vec4 v_maskColor; -varying vec4 v_texCoords; -varying vec4 v_maskColor; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; void main() { vec2 normal = a_normalAndAnimateOrZ.xy; if (a_normalAndAnimateOrZ.z > 0.0) normal = u_interpolation * normal; - vec4 p = vec4(a_position, 1.0) * u_modelView; vec4 pos = vec4(normal, 0.0, 0.0) + p; vec4 projectedPivot = p * u_projection; diff --git a/shaders/GL/user_mark_billboard.vsh.glsl b/shaders/GL/user_mark_billboard.vsh.glsl index 1454c7f71c..607ad08d2a 100644 --- a/shaders/GL/user_mark_billboard.vsh.glsl +++ b/shaders/GL/user_mark_billboard.vsh.glsl @@ -1,22 +1,28 @@ -attribute vec3 a_position; -attribute vec3 a_normalAndAnimateOrZ; -attribute vec4 a_texCoords; -attribute vec4 a_color; +layout (location = 0) in vec3 a_position; +layout (location = 1) in vec3 a_normalAndAnimateOrZ; +layout (location = 2) in vec4 a_texCoords; +layout (location = 3) in vec4 a_color; -uniform mat4 u_modelView; -uniform mat4 u_projection; -uniform mat4 u_pivotTransform; -uniform float u_interpolation; +layout (location = 0) out vec4 v_texCoords; +layout (location = 1) out vec4 v_maskColor; -varying vec4 v_texCoords; -varying vec4 v_maskColor; +layout (binding = 0) uniform UBO +{ + mat4 u_modelView; + mat4 u_projection; + mat4 u_pivotTransform; + vec2 u_contrastGamma; + float u_opacity; + float u_zScale; + float u_interpolation; + float u_isOutlinePass; +}; void main() { vec2 normal = a_normalAndAnimateOrZ.xy; if (a_normalAndAnimateOrZ.z > 0.0) normal = u_interpolation * normal; - vec4 pivot = vec4(a_position, 1.0) * u_modelView; vec4 offset = vec4(normal, 0.0, 0.0) * u_projection; vec4 projectedPivot = pivot * u_projection; diff --git a/shaders/Metal/imgui.metal b/shaders/Metal/imgui.metal new file mode 100644 index 0000000000..932fb5ca9a --- /dev/null +++ b/shaders/Metal/imgui.metal @@ -0,0 +1,39 @@ +#include +#include +using namespace metal; + +typedef struct +{ + float2 a_position [[attribute(0)]]; + float2 a_texCoords [[attribute(1)]]; + float4 a_color [[attribute(2)]]; +} Vertex_T; + +typedef struct +{ + float4 position [[position]]; + float2 texCoords; + float4 color; +} Fragment_T; + +typedef struct +{ + float4x4 u_projection; +} Uniforms_T; + +vertex Fragment_T vsImGui(const Vertex_T in [[stage_in]], + constant Uniforms_T & uniforms [[buffer(1)]]) +{ + Fragment_T out; + out.position = float4(in.a_position, 0.0, 1.0) * uniforms.u_projection; + out.texCoords = in.a_texCoords; + out.color = in.a_color; + return out; +} + +fragment float4 fsImGui(const Fragment_T in [[stage_in]], + texture2d u_colorTex [[texture(0)]], + sampler u_colorTexSampler [[sampler(0)]]) +{ + return in.color * u_colorTex.sample(u_colorTexSampler, in.texCoords); +} diff --git a/shaders/Metal/map.metal b/shaders/Metal/map.metal index ec5698d697..7e7d27db6e 100644 --- a/shaders/Metal/map.metal +++ b/shaders/Metal/map.metal @@ -8,11 +8,11 @@ typedef struct float4x4 u_modelView; float4x4 u_projection; float4x4 u_pivotTransform; + packed_float2 u_contrastGamma; float u_opacity; float u_zScale; float u_interpolation; float u_isOutlinePass; - packed_float2 u_contrastGamma; } Uniforms_T; // Area/AreaOutline diff --git a/shaders/Metal/route.metal b/shaders/Metal/route.metal index 39e0a0f412..8d5681aa4b 100644 --- a/shaders/Metal/route.metal +++ b/shaders/Metal/route.metal @@ -12,13 +12,13 @@ typedef struct float4 u_color; float4 u_maskColor; float4 u_outlineColor; + float4 u_fakeColor; + float4 u_fakeOutlineColor; + packed_float2 u_fakeBorders; packed_float2 u_pattern; packed_float2 u_angleCosSin; float u_arrowHalfWidth; float u_opacity; - packed_float2 u_fakeBorders; - float4 u_fakeColor; - float4 u_fakeOutlineColor; } Uniforms_T; // Route/RouteDash diff --git a/shaders/Metal/shapes.metal b/shaders/Metal/shapes.metal index 322f58c62d..9b3cba892b 100644 --- a/shaders/Metal/shapes.metal +++ b/shaders/Metal/shapes.metal @@ -10,8 +10,9 @@ typedef struct float4x4 u_projection; float4x4 u_pivotTransform; packed_float3 u_position; - float u_accuracy; + float u_dummy1; packed_float2 u_lineParams; + float u_accuracy; float u_zScale; float u_opacity; float u_azimut; diff --git a/shaders/Metal/traffic.metal b/shaders/Metal/traffic.metal index 2196c154b2..0ce95d9986 100644 --- a/shaders/Metal/traffic.metal +++ b/shaders/Metal/traffic.metal @@ -10,10 +10,13 @@ typedef struct float4x4 u_pivotTransform; float4 u_trafficParams; packed_float3 u_outlineColor; - float u_outline; + float u_dummy1; // alignment packed_float3 u_lightArrowColor; - float u_opacity; + float u_dummy2; // alignment packed_float3 u_darkArrowColor; + float u_dummy3; // alignment + float u_outline; + float u_opacity; } Uniforms_T; // Traffic diff --git a/shaders/Metal/transit.metal b/shaders/Metal/transit.metal index 602be7f70a..c8c8f74b50 100644 --- a/shaders/Metal/transit.metal +++ b/shaders/Metal/transit.metal @@ -9,6 +9,7 @@ typedef struct float4x4 u_projection; float4x4 u_pivotTransform; packed_float3 u_params; + float u_dummy1; float u_lineHalfWidth; float u_maxRadius; } Uniforms_T; diff --git a/shaders/gl_program_params.cpp b/shaders/gl_program_params.cpp index 59f13ea7dc..e524908ba1 100644 --- a/shaders/gl_program_params.cpp +++ b/shaders/gl_program_params.cpp @@ -46,12 +46,12 @@ template class GLTypeWrapper; BIND_GL_TYPE(float, gl_const::GLFloatType) BIND_GL_TYPE(glsl::vec2, gl_const::GLFloatVec2) -BIND_GL_TYPE(glsl::vec3, gl_const::GLFloatVec3) +BIND_GL_TYPE(glsl::vec3, gl_const::GLFloatVec4) BIND_GL_TYPE(glsl::vec4, gl_const::GLFloatVec4) BIND_GL_TYPE(glsl::mat4, gl_const::GLFloatMat4) BIND_GL_TYPE(int, gl_const::GLIntType) BIND_GL_TYPE(glsl::ivec2, gl_const::GLIntVec2) -BIND_GL_TYPE(glsl::ivec3, gl_const::GLIntVec3) +BIND_GL_TYPE(glsl::ivec3, gl_const::GLIntVec4) BIND_GL_TYPE(glsl::ivec4, gl_const::GLIntVec4) class Parameter @@ -230,4 +230,14 @@ void GLProgramParamsSetter::Apply(ref_ptr context, Parameter::CheckApply(guard, "u_framebufferMetrics", params.m_framebufferMetrics); } + +void GLProgramParamsSetter::Apply(ref_ptr context, + ref_ptr program, + ImGuiProgramParams const & params) +{ + UNUSED_VALUE(context); + UniformsGuard guard(program, params); + + Parameter::CheckApply(guard, "u_projection", params.m_projection); +} } // namespace gpu diff --git a/shaders/gl_program_params.hpp b/shaders/gl_program_params.hpp index 2ce8fe028d..20626abdc7 100644 --- a/shaders/gl_program_params.hpp +++ b/shaders/gl_program_params.hpp @@ -29,5 +29,7 @@ public: ref_ptr program, ScreenQuadProgramParams const & params) override; void Apply(ref_ptr context, ref_ptr program, SMAAProgramParams const & params) override; + void Apply(ref_ptr context, + ref_ptr program, ImGuiProgramParams const & params) override; }; } // namespace gpu diff --git a/shaders/gl_program_pool.cpp b/shaders/gl_program_pool.cpp index 83e4234444..d441870918 100644 --- a/shaders/gl_program_pool.cpp +++ b/shaders/gl_program_pool.cpp @@ -15,7 +15,7 @@ GLProgramPool::GLProgramPool(dp::ApiVersion apiVersion) if (m_apiVersion == dp::ApiVersion::OpenGLES3) { #if defined(OMIM_OS_DESKTOP) && !defined(OMIM_OS_LINUX) - m_baseDefines = std::string(GL3_SHADER_VERSION) + "#define GLES3\n"; + m_baseDefines = std::string(GL3_SHADER_VERSION); #else m_baseDefines = std::string(GLES3_SHADER_VERSION); #endif diff --git a/shaders/gl_shaders_preprocessor.py b/shaders/gl_shaders_preprocessor.py index f327697be9..b81717bf63 100755 --- a/shaders/gl_shaders_preprocessor.py +++ b/shaders/gl_shaders_preprocessor.py @@ -10,8 +10,9 @@ MEDIUMP_SEARCH = "mediump" HIGHP_SEARCH = "highp" VERTEX_SHADER_EXT = ".vsh.glsl" FRAG_SHADER_EXT = ".fsh.glsl" -GLES3_PREFIX = "GLES3_" -GLES3_SHADER_PREFIX = "gles3_" + +UBO_KEY = "UBO" +UNIFORMS_KEY = "Uniforms" SHADERS_LIB_COMMON_PATTERN = "// Common" SHADERS_LIB_VS_PATTERN = "// VS" @@ -127,7 +128,7 @@ def write_definition_file(defines_file, generation_dir): output_file.write("{\n") output_file.write("extern char const * GL3_SHADER_VERSION;\n") output_file.write("extern char const * GLES3_SHADER_VERSION;\n\n") - output_file.write("extern GLProgramInfo GetProgramInfo(dp::ApiVersion apiVersion, Program program);\n") + output_file.write("extern GLProgramInfo const & GetProgramInfo(dp::ApiVersion apiVersion, Program program);\n") output_file.write("} // namespace gpu\n") if not os.path.isfile(defines_file) or not filecmp.cmp(defines_file, defines_file_tmp, False): @@ -164,77 +165,143 @@ def get_shaders_lib_content(shader_file, shaders_library): return lib_content -def write_shader_line(output_file, line, convert_to_gles3, is_fragment_shader): +def write_shader_line(output_file, line, shader_file, binding_info): if line.lstrip().startswith("//") or line == '\n' or len(line) == 0: - return + return False if line.find(LOWP_SEARCH) >= 0: - print("Incorrect shader. Do not use lowp in shader, use LOW_P instead.") + print(f"Incorrect shader {shader_file}. Do not use lowp in shader, use LOW_P instead.") exit(2) if line.find(MEDIUMP_SEARCH) >= 0: - print("Incorrect shader. Do not use mediump in shader, use MEDIUM_P instead.") + print(f"Incorrect shader {shader_file}. Do not use mediump in shader, use MEDIUM_P instead.") exit(2) if line.find(HIGHP_SEARCH) >= 0: - print("Incorrect shader. Do not use highp in shader, use HIGH_P instead.") + print(f"Incorrect shader {shader_file}. Do not use highp in shader, use HIGH_P instead.") exit(2) output_line = line.rstrip() - if convert_to_gles3: - output_line = output_line.replace("attribute", "in") - if is_fragment_shader: - output_line = output_line.replace("varying", "in") + + # Extract and remove layout binding + binding_match = re.search(r"layout\s*\(\s*binding\s*=\s*(\d+)\s*\)", output_line) + if binding_match: + binding_index = int(binding_match.group(1)) + # Remove the matched layout part from the string + output_line = re.sub(r"layout\s*\(\s*binding\s*=\s*\d+\s*\)\s*", "", output_line) + else: + binding_index = None + + # Extract sampler name + sampler_match = re.search(r"sampler2D\s+(\w+)", output_line) + sampler_name = sampler_match.group(1) if sampler_match else None + + if binding_index is None and sampler_name is not None: + print(f"Incorrect shader {shader_file}. Sampler must have binding index") + exit(2) + + ubo_started = False + if line.find("uniform UBO") >= 0: + if binding_index is not None: + binding_info[shader_file].append({UBO_KEY: binding_index}) + ubo_started = True else: - output_line = output_line.replace("varying", "out") - output_line = output_line.replace("texture2D", "texture") - output_line = output_line.replace("gl_FragColor", "v_FragColor") - output_file.write(" %s \\n\\\n" % output_line) + print(f"Incorrect shader {shader_file}. Uniform block must have binding index") + exit(2) + + if binding_index and sampler_name: + binding_info[shader_file].append({sampler_name: binding_index}) + + if not ubo_started: + output_file.write(" %s \\n\\\n" % output_line) + + return ubo_started -def write_shader_body(output_file, shader_file, shader_dir, shaders_library, convert_to_gles3): - is_fragment_shader = shader_file.find(FRAG_SHADER_EXT) >= 0 +def find_by_name_in_list(lst, name): + return next((item[name] for item in lst if name in item), None) + + +def write_uniform_shader_line(output_file, line, shader_file, binding_info): + if line.lstrip().startswith("//") or line == '\n' or len(line) == 0: + return False + output_line = line.lstrip().rstrip() + if output_line.find("};") >= 0: + return True + if output_line.find("{") >= 0: + return False + if output_line.find(",") >= 0 or output_line.count("u_") > 1: + print(f"Incorrect shader {shader_file}. Only one uniform per line") + exit(2) + + find_by_name_in_list(binding_info[shader_file], UNIFORMS_KEY).append(output_line) + + output_file.write(" uniform %s \\n\\\n" % output_line) + return False + + +def write_shader_body(output_file, shader_file, shader_dir, shaders_library, binding_info): lib_content = get_shaders_lib_content(shader_file, shaders_library) + ubo_started = False for line in open(os.path.join(shader_dir, shader_file)): + if ubo_started: + if write_uniform_shader_line(output_file, line, shader_file, binding_info): + ubo_started = False + continue if line.lstrip().startswith("void main"): for lib_line in lib_content.splitlines(): - write_shader_line(output_file, lib_line, convert_to_gles3, is_fragment_shader) - if convert_to_gles3 and is_fragment_shader: - output_file.write(" out vec4 v_FragColor; \\n\\\n") - write_shader_line(output_file, line, convert_to_gles3, is_fragment_shader) + write_shader_line(output_file, lib_line, shader_file, binding_info) + ubo_started = write_shader_line(output_file, line, shader_file, binding_info) + if ubo_started: + binding_info[shader_file].append({UNIFORMS_KEY: []}) + output_file.write("\";\n\n") -def write_shader(output_file, shader_file, shader_dir, shaders_library): - output_file.write("char const %s[] = \" \\\n" % (format_shader_source_name(shader_file))) +def write_shader(output_file, shader_file, shader_dir, shaders_library, binding_info): + output_file.write("char const %s[] = \" \\\n" % format_shader_source_name(shader_file)) write_shader_gles_header(output_file) - write_shader_body(output_file, shader_file, shader_dir, shaders_library, False) + write_shader_body(output_file, shader_file, shader_dir, shaders_library, binding_info) -def write_gles3_shader(output_file, shader_file, shader_dir, shaders_library): - output_file.write("char const %s[] = \" \\\n" % (GLES3_PREFIX + format_shader_source_name(shader_file))) - write_shader_gles_header(output_file) - if os.path.exists(os.path.join(shader_dir, GLES3_SHADER_PREFIX + shader_file)): - write_shader_body(output_file, GLES3_SHADER_PREFIX + shader_file, shader_dir, shaders_library, False) - else: - write_shader_body(output_file, shader_file, shader_dir, shaders_library, True) - - -def write_gpu_programs_map(file, programs_def, source_prefix): +def write_gpu_programs_map(file, programs_def, binding_info): for program in programs_def.keys(): vertex_shader = programs_def[program][0] - vertex_source_name = source_prefix + format_shader_source_name(vertex_shader) + vertex_source_name = format_shader_source_name(vertex_shader) fragment_shader = programs_def[program][1] - fragment_source_name = source_prefix + format_shader_source_name(fragment_shader) + fragment_source_name = format_shader_source_name(fragment_shader) + + check_bindings(vertex_shader, fragment_shader, binding_info[vertex_shader], binding_info[fragment_shader]) - file.write(" GLProgramInfo(\"%s\", \"%s\", %s, %s),\n" % ( + file.write(" GLProgramInfo(\"%s\", \"%s\", %s, %s),\n" % ( vertex_source_name, fragment_source_name, vertex_source_name, fragment_source_name)) +def check_bindings(vs, fs, vs_bindings, fs_bindings): + dict1 = {k: v for d in vs_bindings for k, v in d.items()} + dict2 = {k: v for d in fs_bindings for k, v in d.items()} + if UBO_KEY in dict1 and UBO_KEY in dict2: + if dict1[UBO_KEY] != dict2[UBO_KEY]: + print(f"Shaders {vs} and {fs} must use the same binding indexes for the UBO. VS:{dict1[UBO_KEY]}, FS:{dict2[UBO_KEY]}") + exit(2) + if UNIFORMS_KEY in dict1 and UNIFORMS_KEY in dict2: + if dict1[UNIFORMS_KEY] != dict2[UNIFORMS_KEY]: + print(f"Shaders {vs} and {fs} must use the same unforms inside the UBO. VS:{dict1[UNIFORMS_KEY]}, FS:{dict2[UNIFORMS_KEY]}") + exit(2) + common_keys = dict1.keys() & dict2.keys() + for key in common_keys: + if key == UBO_KEY or key == UNIFORMS_KEY: + continue + if dict1[key] != dict2[key]: + print(f"Shaders {vs} and {fs} must use the same binding indexes for textures. VS:{dict1[key]}, FS:{dict2[key]}") + exit(2) + + def write_implementation_file(programs_def, shader_index, shader_dir, impl_file, def_file, generation_dir, shaders_library): impl_file = os.path.join(generation_dir, impl_file) # Write to temporary file first, and then compare if its content has changed to avoid unnecessary code rebuilds. impl_file_tmp = impl_file + ".tmp" + binding_info = dict() with open(impl_file_tmp, 'w') as file: file.write("#include \"shaders/%s\"\n\n" % (def_file)) file.write("#include \"base/assert.hpp\"\n\n") @@ -243,35 +310,23 @@ def write_implementation_file(programs_def, shader_index, shader_dir, impl_file, file.write("namespace gpu\n") file.write("{\n") - # TODO: Drop this GL3_SHADER_VERSION once MacOS code has been migrated to Metal - file.write("char const * GL3_SHADER_VERSION = \"#version 150 core \\n\";\n") + file.write("char const * GL3_SHADER_VERSION = \"#version 410 core \\n\";\n") file.write("char const * GLES3_SHADER_VERSION = \"#version 300 es \\n\";\n\n") for shader in shader_index.keys(): - write_shader(file, shader, shader_dir, shaders_library) - write_gles3_shader(file, shader, shader_dir, shaders_library) + binding_info[shader] = [] + write_shader(file, shader, shader_dir, shaders_library, binding_info) - file.write("GLProgramInfo GetProgramInfo(dp::ApiVersion apiVersion, Program program)\n") + file.write("GLProgramInfo const & GetProgramInfo(dp::ApiVersion apiVersion, Program program)\n") file.write("{\n") - file.write(" if (apiVersion == dp::ApiVersion::OpenGLES2)\n") - file.write(" {\n") - file.write(" static std::array(Program::ProgramsCount)> gpuIndex = {{\n") - write_gpu_programs_map(file, programs_def, '') - file.write(" }};\n") - file.write(" return gpuIndex[static_cast(program)];\n") - file.write(" }\n") - file.write(" else if (apiVersion == dp::ApiVersion::OpenGLES3)\n") - file.write(" {\n") - file.write(" static std::array(Program::ProgramsCount)> gpuIndex = {{\n") - write_gpu_programs_map(file, programs_def, GLES3_PREFIX) - file.write(" }};\n") - file.write(" return gpuIndex[static_cast(program)];\n") - file.write(" }\n") - file.write(" CHECK(false, (\"Unsupported API version.\"));\n") - file.write(" return {};\n") + file.write(" CHECK_EQUAL(apiVersion, dp::ApiVersion::OpenGLES3, ());\n") + file.write(" static std::array(Program::ProgramsCount)> gpuIndex = {{\n") + write_gpu_programs_map(file, programs_def, binding_info) + file.write(" }};\n") + file.write(" return gpuIndex[static_cast(program)];\n") file.write("}\n") file.write("} // namespace gpu\n") - + if not os.path.isfile(impl_file) or not filecmp.cmp(impl_file, impl_file_tmp, False): os.replace(impl_file_tmp, impl_file) print(impl_file + " was replaced") @@ -295,13 +350,13 @@ if __name__ == '__main__': shaders = [file for file in os.listdir(shader_dir) if os.path.isfile(os.path.join(shader_dir, file)) and ( file.endswith(VERTEX_SHADER_EXT) or file.endswith(FRAG_SHADER_EXT))] - shaderIndex = generate_shader_indexes(shaders) + shader_index = generate_shader_indexes(shaders) programs_order = read_programs_file(os.path.join(shader_dir, '..', programs_file_name)) - programDefinition = read_index_file(os.path.join(shader_dir, index_file_name), programs_order) + program_definition = read_index_file(os.path.join(shader_dir, index_file_name), programs_order) shaders_library = read_shaders_lib_file(os.path.join(shader_dir, shaders_lib_file)) write_definition_file(defines_file, generation_dir) - write_implementation_file(programDefinition, shaderIndex, shader_dir, impl_file, defines_file, generation_dir, + write_implementation_file(program_definition, shader_index, shader_dir, impl_file, defines_file, generation_dir, shaders_library) diff --git a/shaders/metal_program_params.hpp b/shaders/metal_program_params.hpp index 4134e770b0..fa0cc09752 100644 --- a/shaders/metal_program_params.hpp +++ b/shaders/metal_program_params.hpp @@ -31,6 +31,8 @@ public: ScreenQuadProgramParams const & params) override; void Apply(ref_ptr context, ref_ptr program, SMAAProgramParams const & params) override; + void Apply(ref_ptr context, ref_ptr program, + ImGuiProgramParams const & params) override; }; } // namespace metal } // namespace gpu diff --git a/shaders/metal_program_params.mm b/shaders/metal_program_params.mm index d5da8217d7..d63396d258 100644 --- a/shaders/metal_program_params.mm +++ b/shaders/metal_program_params.mm @@ -101,5 +101,12 @@ void MetalProgramParamsSetter::Apply(ref_ptr context, { ApplyBytes(context, program, params); } + +void MetalProgramParamsSetter::Apply(ref_ptr context, + ref_ptr program, + ImGuiProgramParams const & params) +{ + ApplyBytes(context, program, params); +} } // namespace metal } // namespace gpu diff --git a/shaders/metal_program_pool.mm b/shaders/metal_program_pool.mm index 11dca8c56f..9926082ba4 100644 --- a/shaders/metal_program_pool.mm +++ b/shaders/metal_program_pool.mm @@ -102,6 +102,7 @@ std::array(Program::ProgramsCount)> const kMeta ProgramInfo("vsSmaaEdges", "fsSmaaEdges", {{0, 1}}), // SmaaEdges ProgramInfo("vsSmaaBlendingWeight", "fsSmaaBlendingWeight", {{0, 1}}), // SmaaBlendingWeight ProgramInfo("vsSmaaFinal", "fsSmaaFinal", {{0, 1}}), // SmaaFinal + ProgramInfo("vsImGui", "fsImGui", {{0, 2}}), // ImGui }}; MTLVertexFormat GetFormatByDataType(MTLDataType dataType) diff --git a/shaders/program_manager.cpp b/shaders/program_manager.cpp index e983eb2da1..ae69d0fc9b 100644 --- a/shaders/program_manager.cpp +++ b/shaders/program_manager.cpp @@ -19,7 +19,7 @@ void ProgramManager::Init(ref_ptr context) { CHECK_THREAD_CHECKER(m_threadChecker, ()); auto const apiVersion = context->GetApiVersion(); - if (apiVersion == dp::ApiVersion::OpenGLES2 || apiVersion == dp::ApiVersion::OpenGLES3) + if (apiVersion == dp::ApiVersion::OpenGLES3) { InitForOpenGL(context); } @@ -69,13 +69,7 @@ void ProgramManager::InitForOpenGL(ref_ptr context) } #endif - if (dp::SupportManager::Instance().IsSamsungGoogleNexus()) - globalDefines.append("#define SAMSUNG_GOOGLE_NEXUS\n"); - auto const apiVersion = context->GetApiVersion(); - if (apiVersion == dp::ApiVersion::OpenGLES3) - globalDefines.append("#define GLES3\n"); - m_pool = make_unique_dp(apiVersion); ref_ptr pool = make_ref(m_pool); pool->SetDefines(globalDefines); diff --git a/shaders/program_params.cpp b/shaders/program_params.cpp index e9119948f3..a774b2eec3 100644 --- a/shaders/program_params.cpp +++ b/shaders/program_params.cpp @@ -18,6 +18,7 @@ void ProgramParams::Init() DebugRectProgramParams::BindPrograms(m_boundParams); ScreenQuadProgramParams::BindPrograms(m_boundParams); SMAAProgramParams::BindPrograms(m_boundParams); + ImGuiProgramParams::BindPrograms(m_boundParams); } // static diff --git a/shaders/program_params.hpp b/shaders/program_params.hpp index c2bea7925a..f8ffa5d438 100644 --- a/shaders/program_params.hpp +++ b/shaders/program_params.hpp @@ -48,17 +48,22 @@ private: #define ALIGNMENT alignas(16) +// NOTE: structs may contain dummy elements to fit MSL and GLSL struct alignment rules +// 1. Add new fields in order from the highest byte size to the lowest, it minimizes alignment overhead +// 2. Keep 16 bytes alignment for the whole struct, it complements the size of the latest element to vec4 +// 3. Consider vec3 as vec4, add float complement and don't reuse it + struct ALIGNMENT MapProgramParams { glsl::mat4 m_modelView; glsl::mat4 m_projection; glsl::mat4 m_pivotTransform; + glsl::vec2 m_contrastGamma; float m_opacity = 1.0f; float m_zScale = 1.0f; float m_interpolation = 1.0f; float m_isOutlinePass = 1.0f; - glsl::vec2 m_contrastGamma; - + BIND_PROGRAMS(MapProgramParams, Program::Area, Program::Area3d, @@ -100,14 +105,14 @@ struct ALIGNMENT RouteProgramParams glsl::vec4 m_color; glsl::vec4 m_maskColor; glsl::vec4 m_outlineColor; + glsl::vec4 m_fakeColor; + glsl::vec4 m_fakeOutlineColor; + glsl::vec2 m_fakeBorders; glsl::vec2 m_pattern; glsl::vec2 m_angleCosSin; float m_arrowHalfWidth = 0.0f; float m_opacity = 1.0f; - glsl::vec2 m_fakeBorders; - glsl::vec4 m_fakeColor; - glsl::vec4 m_fakeOutlineColor; - + BIND_PROGRAMS(RouteProgramParams, Program::Route, Program::RouteDash, @@ -122,10 +127,13 @@ struct ALIGNMENT TrafficProgramParams glsl::mat4 m_pivotTransform; glsl::vec4 m_trafficParams; glsl::vec3 m_outlineColor; - float m_outline = 0.0f; + float m_dummy1; // alignment glsl::vec3 m_lightArrowColor; - float m_opacity = 1.0f; + float m_dummy2; // alignment glsl::vec3 m_darkArrowColor; + float m_dummy3; // alignment + float m_outline = 0.0f; + float m_opacity = 1.0f; BIND_PROGRAMS(TrafficProgramParams, Program::Traffic, @@ -139,6 +147,7 @@ struct ALIGNMENT TransitProgramParams glsl::mat4 m_projection; glsl::mat4 m_pivotTransform; glsl::vec3 m_params; + float m_dummy1; // alignment float m_lineHalfWidth = 0.0f; float m_maxRadius = 0.0f; @@ -171,8 +180,9 @@ struct ALIGNMENT ShapesProgramParams glsl::mat4 m_projection; glsl::mat4 m_pivotTransform; glsl::vec3 m_position; - float m_accuracy = 0.0; + float m_dummy1; // alignment glsl::vec2 m_lineParams; + float m_accuracy = 0.0; float m_zScale = 1.0f; float m_opacity = 1.0f; float m_azimut = 0.0; @@ -222,6 +232,14 @@ struct ALIGNMENT SMAAProgramParams Program::SmaaFinal) }; +struct ALIGNMENT ImGuiProgramParams +{ + glsl::mat4 m_projection; + + BIND_PROGRAMS(ImGuiProgramParams, + Program::ImGui) +}; + #undef ALIGNMENT class ProgramParamsSetter @@ -248,5 +266,7 @@ public: ref_ptr program, ScreenQuadProgramParams const & params) = 0; virtual void Apply(ref_ptr context, ref_ptr program, SMAAProgramParams const & params) = 0; + virtual void Apply(ref_ptr context, + ref_ptr program, ImGuiProgramParams const & params) = 0; }; } // namespace gpu diff --git a/shaders/programs.hpp b/shaders/programs.hpp index ca74e7a067..2804d29a06 100644 --- a/shaders/programs.hpp +++ b/shaders/programs.hpp @@ -65,6 +65,7 @@ enum class Program SmaaEdges, SmaaBlendingWeight, SmaaFinal, + ImGui, ProgramsCount }; @@ -128,6 +129,7 @@ inline std::string DebugPrint(Program p) case Program::SmaaEdges: return "SmaaEdges"; case Program::SmaaBlendingWeight: return "SmaaBlendingWeight"; case Program::SmaaFinal: return "SmaaFinal"; + case Program::ImGui: return "ImGui"; case Program::ProgramsCount: CHECK(false, ("Try to output ProgramsCount")); diff --git a/shaders/shaders_tests/gl_program_params_tests.cpp b/shaders/shaders_tests/gl_program_params_tests.cpp index 6a69ff0ed9..3b96e0d532 100644 --- a/shaders/shaders_tests/gl_program_params_tests.cpp +++ b/shaders/shaders_tests/gl_program_params_tests.cpp @@ -15,9 +15,9 @@ using namespace std::placeholders; template -void TestProgramParams(bool apiOpenGLES3) +void TestProgramParams() { - auto const api = apiOpenGLES3 ? dp::ApiVersion::OpenGLES3 : dp::ApiVersion::OpenGLES2; + auto constexpr api = dp::ApiVersion::OpenGLES3; TestingGraphicsContext context(api); GLFunctions::Init(api); gpu::GLProgramPool pool(api); @@ -37,91 +37,61 @@ void TestProgramParams(bool apiOpenGLES3) #ifdef OMIM_OS_MAC UNIT_TEST(MapProgramParams_Test) { - RunTestInOpenGLOffscreenEnvironment("MapProgramParams_Test", false /* apiOpenGLES3 */, - std::bind(&TestProgramParams, _1)); - - RunTestInOpenGLOffscreenEnvironment("MapProgramParams_Test", true /* apiOpenGLES3 */, - std::bind(&TestProgramParams, _1)); + RunTestInOpenGLOffscreenEnvironment("MapProgramParams_Test", + std::bind(&TestProgramParams)); } UNIT_TEST(RouteProgramParams_Test) { - RunTestInOpenGLOffscreenEnvironment("RouteProgramParams_Test", false /* apiOpenGLES3 */, - std::bind(&TestProgramParams, _1)); - - RunTestInOpenGLOffscreenEnvironment("RouteProgramParams_Test", true /* apiOpenGLES3 */, - std::bind(&TestProgramParams, _1)); + RunTestInOpenGLOffscreenEnvironment("RouteProgramParams_Test", + std::bind(&TestProgramParams)); } UNIT_TEST(TrafficProgramParams_Test) { - RunTestInOpenGLOffscreenEnvironment("TrafficProgramParams_Test", false /* apiOpenGLES3 */, - std::bind(&TestProgramParams, _1)); - - RunTestInOpenGLOffscreenEnvironment("TrafficProgramParams_Test", true /* apiOpenGLES3 */, - std::bind(&TestProgramParams, _1)); + RunTestInOpenGLOffscreenEnvironment("TrafficProgramParams_Test", + std::bind(&TestProgramParams)); } UNIT_TEST(TransitProgramParams_Test) { - RunTestInOpenGLOffscreenEnvironment("TransitProgramParams_Test", false /* apiOpenGLES3 */, - std::bind(&TestProgramParams, _1)); - - RunTestInOpenGLOffscreenEnvironment("TransitProgramParams_Test", true /* apiOpenGLES3 */, - std::bind(&TestProgramParams, _1)); + RunTestInOpenGLOffscreenEnvironment("TransitProgramParams_Test", + std::bind(&TestProgramParams)); } UNIT_TEST(GuiProgramParams_Test) { - RunTestInOpenGLOffscreenEnvironment("GuiProgramParams_Test", false /* apiOpenGLES3 */, - std::bind(&TestProgramParams, _1)); - - RunTestInOpenGLOffscreenEnvironment("GuiProgramParams_Test", true /* apiOpenGLES3 */, - std::bind(&TestProgramParams, _1)); + RunTestInOpenGLOffscreenEnvironment("GuiProgramParams_Test", + std::bind(&TestProgramParams)); } UNIT_TEST(ShapesProgramParams_Test) { - RunTestInOpenGLOffscreenEnvironment("ShapesProgramParams_Test", false /* apiOpenGLES3 */, - std::bind(&TestProgramParams, _1)); - - RunTestInOpenGLOffscreenEnvironment("ShapesProgramParams_Test", true /* apiOpenGLES3 */, - std::bind(&TestProgramParams, _1)); + RunTestInOpenGLOffscreenEnvironment("ShapesProgramParams_Test", + std::bind(&TestProgramParams)); } UNIT_TEST(Arrow3dProgramParams_Test) { - RunTestInOpenGLOffscreenEnvironment("Arrow3dProgramParams_Test", false /* apiOpenGLES3 */, - std::bind(&TestProgramParams, _1)); - - RunTestInOpenGLOffscreenEnvironment("Arrow3dProgramParams_Test", true /* apiOpenGLES3 */, - std::bind(&TestProgramParams, _1)); + RunTestInOpenGLOffscreenEnvironment("Arrow3dProgramParams_Test", + std::bind(&TestProgramParams)); } UNIT_TEST(DebugRectProgramParams_Test) { - RunTestInOpenGLOffscreenEnvironment("DebugRectProgramParams_Test", false /* apiOpenGLES3 */, - std::bind(&TestProgramParams, _1)); - - RunTestInOpenGLOffscreenEnvironment("DebugRectProgramParams_Test", true /* apiOpenGLES3 */, - std::bind(&TestProgramParams, _1)); + RunTestInOpenGLOffscreenEnvironment("DebugRectProgramParams_Test", + std::bind(&TestProgramParams)); } UNIT_TEST(ScreenQuadProgramParams_Test) { - RunTestInOpenGLOffscreenEnvironment("ScreenQuadProgramParams_Test", false /* apiOpenGLES3 */, - std::bind(&TestProgramParams, _1)); - - RunTestInOpenGLOffscreenEnvironment("ScreenQuadProgramParams_Test", true /* apiOpenGLES3 */, - std::bind(&TestProgramParams, _1)); + RunTestInOpenGLOffscreenEnvironment("ScreenQuadProgramParams_Test", + std::bind(&TestProgramParams)); } UNIT_TEST(SMAAProgramParams_Test) { - RunTestInOpenGLOffscreenEnvironment("SMAAProgramParams_Test", false /* apiOpenGLES3 */, - std::bind(&TestProgramParams, _1)); - - RunTestInOpenGLOffscreenEnvironment("SMAAProgramParams_Test", true /* apiOpenGLES3 */, - std::bind(&TestProgramParams, _1)); + RunTestInOpenGLOffscreenEnvironment("SMAAProgramParams_Test", + std::bind(&TestProgramParams)); } #endif diff --git a/shaders/shaders_tests/gl_shaders_desktop_compile_tests.cpp b/shaders/shaders_tests/gl_shaders_desktop_compile_tests.cpp index 67c84e9fbc..10f8eeec8f 100644 --- a/shaders/shaders_tests/gl_shaders_desktop_compile_tests.cpp +++ b/shaders/shaders_tests/gl_shaders_desktop_compile_tests.cpp @@ -10,9 +10,9 @@ using namespace std::placeholders; -void CompileShaders(bool apiOpenGLES3, bool enableVTF) +void CompileShaders(bool enableVTF) { - auto const api = apiOpenGLES3 ? dp::ApiVersion::OpenGLES3 : dp::ApiVersion::OpenGLES2; + auto constexpr api = dp::ApiVersion::OpenGLES3; GLFunctions::Init(api); gpu::GLProgramPool pool(api); if (enableVTF) @@ -24,29 +24,17 @@ void CompileShaders(bool apiOpenGLES3, bool enableVTF) // These unit tests create Qt application and OGL context so can't be run in GUI-less Linux machine. #ifdef OMIM_OS_MAC -UNIT_TEST(DesktopCompileShaders_GLES2_Test) -{ - RunTestInOpenGLOffscreenEnvironment("DesktopCompileShaders_GLES2_Test", false /* apiOpenGLES3 */, - std::bind(&CompileShaders, _1, false /* enableVTF */)); -} - UNIT_TEST(DesktopCompileShaders_GLES3_Test) { - RunTestInOpenGLOffscreenEnvironment("DesktopCompileShaders_GLES3_Test", true /* apiOpenGLES3 */, - std::bind(&CompileShaders, _1, false /* enableVTF */)); + RunTestInOpenGLOffscreenEnvironment("DesktopCompileShaders_GLES3_Test", + std::bind(&CompileShaders, false /* enableVTF */)); } -UNIT_TEST(DesktopCompileShaders_GLES2_VTF_Test) -{ - RunTestInOpenGLOffscreenEnvironment("DesktopCompileShaders_GLES2_VTF_Test", false /* apiOpenGLES3 */, - std::bind(&CompileShaders, _1, true /* enableVTF */)); -} - UNIT_TEST(DesktopCompileShaders_GLES3_VTF_Test) { - RunTestInOpenGLOffscreenEnvironment("DesktopCompileShaders_GLES3_VTF_Test", true /* apiOpenGLES3 */, - std::bind(&CompileShaders, _1, true /* enableVTF */)); + RunTestInOpenGLOffscreenEnvironment("DesktopCompileShaders_GLES3_VTF_Test", + std::bind(&CompileShaders, true /* enableVTF */)); } #endif diff --git a/shaders/shaders_tests/gl_shaders_mobile_compile_test.cpp b/shaders/shaders_tests/gl_shaders_mobile_compile_test.cpp index 9ef3dc22c8..0285e0beb2 100644 --- a/shaders/shaders_tests/gl_shaders_mobile_compile_test.cpp +++ b/shaders/shaders_tests/gl_shaders_mobile_compile_test.cpp @@ -26,9 +26,7 @@ std::string const kCompilersDir = "shaders_compiler"; #if defined(OMIM_OS_MAC) -std::string const kMaliCompilerOpenGLES2Dir = "macos/mali_compiler"; std::string const kMaliCompilerOpenGLES3Dir = "macos/mali_compiler_es3"; -std::string const kCompilerMaliOpenGLES2 = kMaliCompilerOpenGLES2Dir + "/malisc"; std::string const kCompilerMaliOpenGLES3 = kMaliCompilerOpenGLES3Dir + "/malisc"; std::string const kCompilerOpenGLES = "macos/glslangValidator"; #elif defined(OMIM_OS_LINUX) @@ -152,48 +150,27 @@ void CompileShaders(CompilerData const & compiler, std::string const & additiona args << fileName; }; - std::string const defines = compiler.m_apiVersion == dp::ApiVersion::OpenGLES3 ? - "#define GLES3\n" + additionalDefines : additionalDefines; - TestShaders(compiler.m_apiVersion, defines, ".vert", GetVertexShaders(compiler.m_apiVersion), + TestShaders(compiler.m_apiVersion, additionalDefines, ".vert", GetVertexShaders(compiler.m_apiVersion), compilerPath, [](QProcess const &) {}, argsPrepareFn, successChecker, ss); - TestShaders(compiler.m_apiVersion, defines, ".frag", GetFragmentShaders(compiler.m_apiVersion), + TestShaders(compiler.m_apiVersion, additionalDefines, ".frag", GetFragmentShaders(compiler.m_apiVersion), compilerPath, [](QProcess const &) {}, argsPrepareFn, successChecker, ss); - TEST_EQUAL(errorLog.isEmpty(), true, ("Defines:", defines, additionalDefines, "\n", errorLog)); + TEST_EQUAL(errorLog.isEmpty(), true, ("Defines:", additionalDefines, "\n", errorLog)); } UNIT_TEST(MobileCompileShaders_Test) { base::DelayedThreadPool workerThread(6 /* threadsCount */); - workerThread.Push([] { - CompileShaders({dp::ApiVersion::OpenGLES2, GetCompilerPath(kCompilerOpenGLES)}); - }); - workerThread.Push([] { CompileShaders({dp::ApiVersion::OpenGLES3, GetCompilerPath(kCompilerOpenGLES)}); }); - workerThread.Push([] { - CompileShaders({dp::ApiVersion::OpenGLES2, GetCompilerPath(kCompilerOpenGLES)}, - "#define ENABLE_VTF\n"); - }); - workerThread.Push([] { CompileShaders({dp::ApiVersion::OpenGLES3, GetCompilerPath(kCompilerOpenGLES)}, "#define ENABLE_VTF\n"); }); - workerThread.Push([] { - CompileShaders({dp::ApiVersion::OpenGLES2, GetCompilerPath(kCompilerOpenGLES)}, - "#define SAMSUNG_GOOGLE_NEXUS\n"); - }); - - workerThread.Push([] { - CompileShaders({dp::ApiVersion::OpenGLES3, GetCompilerPath(kCompilerOpenGLES)}, - "#define SAMSUNG_GOOGLE_NEXUS\n"); - }); - workerThread.Shutdown(base::DelayedThreadPool::Exit::ExecPending); } @@ -239,19 +216,16 @@ void MaliCompileShaders(MaliCompilerData const & compiler, MaliDriverSet const & << "-r" << version.m_version << "-c" << version.m_series << "-d" << driverSet.m_driverName << fileName; }; - std::string const defines = - compiler.m_apiVersion == dp::ApiVersion::OpenGLES3 ? "#define GLES3\n" : ""; QString const compilerPath = QString::fromStdString(compiler.m_compilerPath); - TestShaders(compiler.m_apiVersion, defines, {}, GetVertexShaders(compiler.m_apiVersion), + TestShaders(compiler.m_apiVersion, "", {}, GetVertexShaders(compiler.m_apiVersion), compilerPath, procPrepare, argForming, successChecker, ss); shaderType = "-f"; - TestShaders(compiler.m_apiVersion, defines, {}, GetFragmentShaders(compiler.m_apiVersion), + TestShaders(compiler.m_apiVersion, "", {}, GetFragmentShaders(compiler.m_apiVersion), compilerPath, procPrepare, argForming, successChecker, ss); TEST(errorLog.isEmpty(), - (shaderType, version.m_series, version.m_version, driverSet.m_driverName, defines, errorLog)); + (shaderType, version.m_series, version.m_version, driverSet.m_driverName, "", errorLog)); // MALI GPUs do not support ENABLE_VTF. Do not test it here. - // SAMSUNG_GOOGLE_NEXUS doesn't use Mali GPU. Do not test it here. } UNIT_TEST(MALI_MobileCompileShaders_Test) @@ -474,16 +448,6 @@ UNIT_TEST(MALI_MobileCompileShaders_Test) driversES2new.insert(driversES2new.end(), driversES3new.begin(), driversES3new.end()); std::vector const compilers = { -#if defined(OMIM_OS_MAC) - {dp::ApiVersion::OpenGLES2, - GetCompilerPath(kCompilerMaliOpenGLES2), - GetCompilerPath(kMaliCompilerOpenGLES2Dir), - driversES2old}, -#endif - {dp::ApiVersion::OpenGLES2, - GetCompilerPath(kCompilerMaliOpenGLES3), - GetCompilerPath(kMaliCompilerOpenGLES3Dir), - driversES2new}, {dp::ApiVersion::OpenGLES3, GetCompilerPath(kCompilerMaliOpenGLES3), GetCompilerPath(kMaliCompilerOpenGLES3Dir), diff --git a/shaders/vulkan_program_params.cpp b/shaders/vulkan_program_params.cpp index a764e3a9e5..58dd83ffac 100644 --- a/shaders/vulkan_program_params.cpp +++ b/shaders/vulkan_program_params.cpp @@ -229,5 +229,12 @@ void VulkanProgramParamsSetter::Apply(ref_ptr context, { ApplyImpl(context, program, params); } + +void VulkanProgramParamsSetter::Apply(ref_ptr context, + ref_ptr program, + ImGuiProgramParams const & params) +{ + ApplyImpl(context, program, params); +} } // namespace vulkan } // namespace gpu diff --git a/shaders/vulkan_program_params.hpp b/shaders/vulkan_program_params.hpp index 91ab62f50b..25a2dcf8f9 100644 --- a/shaders/vulkan_program_params.hpp +++ b/shaders/vulkan_program_params.hpp @@ -55,6 +55,8 @@ public: ScreenQuadProgramParams const & params) override; void Apply(ref_ptr context, ref_ptr program, SMAAProgramParams const & params) override; + void Apply(ref_ptr context, ref_ptr program, + ImGuiProgramParams const & params) override; private: template diff --git a/shaders/vulkan_shaders_preprocessor.py b/shaders/vulkan_shaders_preprocessor.py index 5c4e164d0a..aff77e02b3 100644 --- a/shaders/vulkan_shaders_preprocessor.py +++ b/shaders/vulkan_shaders_preprocessor.py @@ -16,8 +16,6 @@ SHADERS_LIB_COMMON_INDEX = 0 SHADERS_LIB_VS_INDEX = 1 SHADERS_LIB_FS_INDEX = 2 -IN = 'in' -OUT = 'out' UNIFORMS = 'uniforms' SAMPLERS = 'samplers' @@ -25,7 +23,7 @@ debug_output = False # Read index file which contains program to shaders bindings. -def read_index_file(file_path, programs_order): +def read_index_file(file_path): gpu_programs = dict() with open(file_path, 'r') as f: index = 0 @@ -35,10 +33,6 @@ def read_index_file(file_path, programs_order): print('Incorrect GPU program definition : ' + line) exit(1) - if line_parts[0] != programs_order[index]: - print('Incorrect GPU program order or name : ' + line) - exit(1) - vertex_shader = next(f for f in line_parts if f.endswith(VERTEX_SHADER_EXT)) fragment_shader = next(f for f in line_parts if f.endswith(FRAG_SHADER_EXT)) @@ -64,76 +58,6 @@ def read_index_file(file_path, programs_order): return gpu_programs_cache -# Read hpp-file with programs enumeration. -def read_programs_file(file_path): - gpu_programs = [] - with open(file_path, 'r') as f: - found = False - for line in f: - if not found and line.find('enum class Program') >= 0: - found = True - continue - if found and line.find('}') >= 0: - break - if found and line.find('{') == -1: - line_parts = re.split(',|=', line) - name = line_parts[0].strip() - if name and name != 'ProgramsCount': - gpu_programs.append(name) - return gpu_programs - - -def drop_variable_initialization(line): - equal_found = line.find('=') - if equal_found: - return line[:equal_found - 1] - return line.replace(';', '') - - -def get_program_param(line): - glsl_found = line.find('glsl::') - if glsl_found >= 0: - return drop_variable_initialization(line[glsl_found + 6:].replace('m_', 'u_')) - if line.find('float ') >= 0 or line.find('int ') >= 0: - return drop_variable_initialization(line.lstrip().replace('m_', 'u_')) - return None - - -def get_program(line): - program_found = line.find('Program::') - if program_found >= 0: - return line[program_found + 9:].replace(',', '').replace(')', '').replace('\n', '') - return None - - -# Read hpp-file with program parameters declaration. -def read_program_params_file(file_path): - program_params = [] - programs = [] - result = dict() - with open(file_path, 'r') as f: - block_found = False - for line in f: - if line.find('struct') >= 0 and line.find('ProgramParams') >= 0: - block_found = True - program_params = [] - programs = [] - continue - if block_found and line.find('}') >= 0: - block_found = False - for p in programs: - result[p] = program_params - continue - if block_found: - param = get_program_param(line) - if param: - program_params.append(param.split(' ')) - program = get_program(line) - if program: - programs.append(program) - return result - - # Read GLSL-file with common shader functions. def read_shaders_lib_file(file_path): shaders_library = ['', '', ''] @@ -174,112 +98,43 @@ def get_shaders_lib_content(shader_file, shaders_library): return lib_content -def get_shader_line(line, layout_counters, is_fragment_shader): +def get_shader_line(line, layout_counters): if line.lstrip().startswith('//') or line == '\n' or len(line) == 0: return None output_line = line.rstrip() - if output_line.find('uniform ') >= 0: + if output_line.find('layout (binding') >= 0: if output_line.find('sampler') >= 0: - layout_counters[SAMPLERS][1].append(output_line) + match = re.search(r"binding\s*=\s*(\d+)", output_line) + sampler_match = re.search(r"sampler2D\s+(\w+)", output_line) + if match and sampler_match: + binding_index = int(match.group(1)) + sampler_name = sampler_match.group(1) + if binding_index == 0: + print('Binding index must not be 0 for sampler in the line: ' + line) + exit(1) + layout_counters[SAMPLERS][sampler_name] = binding_index + else: + print('Sampler name or binding index is not found in the line: ' + line) + exit(1) else: + match = re.search(r"binding\s*=\s*(\d+)", output_line) + if match: + binding_index = int(match.group(1)) + if binding_index != 0: + print('Binding index must be 0 in the line: ' + line) + exit(1) + else: + print('Binding index is not found in the line: ' + line) + exit(1) layout_counters[UNIFORMS] += 1 - return None - if output_line.find('attribute ') >= 0: - location = layout_counters[IN] - layout_counters[IN] += 1 - output_line = output_line.replace('attribute', 'layout (location = {0}) in'.format(location)) - - if output_line.find('varying ') >= 0: - if is_fragment_shader: - location = layout_counters[IN] - layout_counters[IN] += 1 - output_line = output_line.replace('varying', 'layout (location = {0}) in'.format(location)) - else: - location = layout_counters[OUT] - layout_counters[OUT] += 1 - output_line = output_line.replace('varying', 'layout (location = {0}) out'.format(location)) - output_line = output_line.replace('texture2D', 'texture') - output_line = output_line.replace('gl_FragColor', 'v_FragColor') return output_line -def get_size_by_type(type): - if type == 'float' or type == 'int': - return 1 - if type == 'vec2': - return 2 - if type == 'vec3': - return 3 - if type == 'vec4': - return 4 - if type == 'mat4': - return 16 - print('Type is not supported' + type) - exit(1) - - -def get_subscript(offset, param): - symbols = ['x', 'y', 'z', 'w'] - subscript = '' - for i in range(0, get_size_by_type(param[0])): - subscript += symbols[offset + i] - return subscript - - -def write_uniform_block(output_file, program_params): - groups = [] - c = 0 - group_index = 0 - group_params = [] - for p in program_params: - sz = get_size_by_type(p[0]) - if sz % 4 == 0: - groups.append((p[0], p[1], [p])) - else: - if c + sz < 4: - group_params.append(p) - c += sz - elif c + sz == 4: - group_params.append(p) - groups.append(('vec4', 'u_grouped{0}'.format(group_index), group_params)) - group_index += 1 - group_params = [] - c = 0 - else: - print('Must be possible to unite sequential variables to vec4') - exit(1) - if c != 0: - groups.append(('vec4', 'u_grouped{0}'.format(group_index), group_params)) - - output_file.write('layout (binding = 0) uniform UBO\n') - output_file.write('{\n') - for g in groups: - output_file.write(' {0} {1};\n'.format(g[0], g[1])) - output_file.write('} uniforms;\n') - for k in groups: - name = k[1] - params = k[2] - offset = 0 - if len(params) == 1 and get_size_by_type(params[0][0]) % 4 == 0: - output_file.write('#define {0} uniforms.{1}\n'.format(params[0][1], name)) - continue - for param in params: - output_file.write('#define {0} uniforms.{1}.{2}\n'.format(param[1], name, get_subscript(offset, param))) - offset += get_size_by_type(param[0]) - - -def get_size_of_attributes_block(lines_before_main): - for i, line in reversed(list(enumerate(lines_before_main))): - if line.find('layout (location') >= 0: - return i + 1 - return len(lines_before_main) - - def generate_spirv_compatible_glsl_shader(output_file, shader_file, shader_dir, shaders_library, - program_params, layout_counters, reflection_dict): + layout_counters, reflection_dict): output_file.write('#version 310 es\n') output_file.write('precision highp float;\n') output_file.write('#define LOW_P lowp\n') @@ -290,8 +145,6 @@ def generate_spirv_compatible_glsl_shader(output_file, shader_file, shader_dir, lib_content = get_shaders_lib_content(shader_file, shaders_library) conditional_started = False conditional_skip = False - lines_before_main = [] - main_found = False for line in open(os.path.join(shader_dir, shader_file)): # Remove some useless conditional compilation. if conditional_started and line.lstrip().startswith('#else'): @@ -303,67 +156,40 @@ def generate_spirv_compatible_glsl_shader(output_file, shader_file, shader_dir, continue if conditional_skip: continue - if line.lstrip().startswith('#ifdef ENABLE_VTF') or line.lstrip().startswith('#ifdef GLES3'): + if line.lstrip().startswith('#ifdef ENABLE_VTF'): conditional_started = True continue if line.lstrip().startswith('void main'): - main_found = True - - # Write attributes. - sz = get_size_of_attributes_block(lines_before_main) - for i in range(0, sz): - output_file.write('%s\n' % lines_before_main[i]) - - if is_fragment_shader: - output_file.write('layout (location = 0) out vec4 v_FragColor;\n') - - # Write uniforms block. + # Write reflection for uniforms block. uniforms_index = 'vs_uni'; if is_fragment_shader: uniforms_index = 'fs_uni' if layout_counters[UNIFORMS] > 0: - write_uniform_block(output_file, program_params) reflection_dict[uniforms_index] = 0 else: reflection_dict[uniforms_index] = -1 - # Write samplers. + # Write reflection for samplers. sample_index = 'tex' - samplers_offset = layout_counters[SAMPLERS][0] - if layout_counters[UNIFORMS] > 0 and samplers_offset == 0: - samplers_offset = 1 - for idx, s in enumerate(layout_counters[SAMPLERS][1]): - output_file.write('layout (binding = {0}) {1}\n'.format(samplers_offset + idx, s)) - sampler = {'name': s[s.find('u_'):-1], 'idx': samplers_offset + idx, 'frag':int(is_fragment_shader)} - if not sample_index in reflection_dict: - reflection_dict[sample_index] = [sampler] - else: - reflection_dict[sample_index].append(sampler) - layout_counters[SAMPLERS][0] = samplers_offset + len(layout_counters[SAMPLERS][1]) - layout_counters[SAMPLERS][1] = [] + if not sample_index in reflection_dict: + reflection_dict[sample_index] = [] + for (s, idx) in layout_counters[SAMPLERS].items(): + sampler = {'name': s, 'idx': idx, 'frag':int(is_fragment_shader)} + reflection_dict[sample_index].append(sampler) # Write shaders library. for lib_line in lib_content.splitlines(): - shader_line = get_shader_line(lib_line, layout_counters, is_fragment_shader) + shader_line = get_shader_line(lib_line, layout_counters) if shader_line: output_file.write('%s\n' % shader_line) - # Write rest lines. - for i in range(sz, len(lines_before_main)): - output_file.write('%s\n' % lines_before_main[i]) - - shader_line = get_shader_line(line, layout_counters, is_fragment_shader) - if not shader_line: - continue - - if main_found: + shader_line = get_shader_line(line, layout_counters) + if shader_line: output_file.write('%s\n' % shader_line) - else: - lines_before_main.append(shader_line) - layout_counters[IN] = 0 - layout_counters[OUT] = 0 + layout_counters[UNIFORMS] = 0 + layout_counters[SAMPLERS] = dict() # Execute external program. @@ -377,12 +203,12 @@ def execute_external(options): # Generate SPIR-V shader from GLSL source. -def generate_shader(shader, shader_dir, generation_dir, shaders_library, program_name, program_params, +def generate_shader(shader, shader_dir, generation_dir, shaders_library, program_name, layout_counters, output_name, reflection_dict, glslc_path): output_path = os.path.join(generation_dir, output_name) with open(output_path, 'w') as file: generate_spirv_compatible_glsl_shader(file, shader, shader_dir, shaders_library, - program_params, layout_counters, reflection_dict) + layout_counters, reflection_dict) spv_path = output_path + '.spv' try: execute_external([glslc_path, '-c', output_path, '-o', spv_path, '-std=310es', '--target-env=vulkan']) @@ -402,21 +228,6 @@ def generate_shader(shader, shader_dir, generation_dir, shaders_library, program return spv_path -# Check if varying are in the same order in vertex and fragment shaders. -def check_varying_consistency(vs_file_name, fs_file_name): - vs_varyings = [] - for line in open(vs_file_name): - line = line.lstrip().rstrip() - if line.startswith('varying '): - vs_varyings.append(line) - fs_varyings = [] - for line in open(fs_file_name): - line = line.lstrip().rstrip() - if line.startswith('varying '): - fs_varyings.append(line) - return vs_varyings == fs_varyings - - def write_shader_to_pack(pack_file, shader_file_name): offset = pack_file.tell() with open(shader_file_name, 'rb') as shader_file: @@ -427,48 +238,38 @@ def write_shader_to_pack(pack_file, shader_file_name): if __name__ == '__main__': if len(sys.argv) < 7: - print('Usage : ' + sys.argv[0] + ' [--debug]') + print('Usage : ' + sys.argv[0] + ' [--debug]') exit(1) shader_dir = sys.argv[1] index_file_name = sys.argv[2] - programs_file_name = sys.argv[3] - program_params_file_name = sys.argv[4] - shaders_lib_file = sys.argv[5] - generation_dir = sys.argv[6] - glslc_path = sys.argv[7] + shaders_lib_file = sys.argv[3] + generation_dir = sys.argv[4] + glslc_path = sys.argv[5] - if len(sys.argv) >= 9: - debug_output = (sys.argv[8] == '--debug') + if len(sys.argv) >= 7: + debug_output = (sys.argv[6] == '--debug') shaders = [file for file in os.listdir(shader_dir) if os.path.isfile(os.path.join(shader_dir, file)) and ( file.endswith(VERTEX_SHADER_EXT) or file.endswith(FRAG_SHADER_EXT))] - programs_order = read_programs_file(os.path.join(shader_dir, '..', programs_file_name)) - program_params = read_program_params_file(os.path.join(shader_dir, '..', program_params_file_name)) - gpu_programs_cache = read_index_file(os.path.join(shader_dir, index_file_name), programs_order) + gpu_programs_cache = read_index_file(os.path.join(shader_dir, index_file_name)) shaders_library = read_shaders_lib_file(os.path.join(shader_dir, shaders_lib_file)) reflection = [] current_offset = 0 with open(os.path.join(generation_dir, 'shaders_pack.spv'), 'wb') as pack_file: for (k, v) in gpu_programs_cache.items(): - if not k in program_params: - print('Program params were not found for the shader ' + k) - exit(1) - if not check_varying_consistency(os.path.join(shader_dir, v[0]), os.path.join(shader_dir, v[1])): - print('Varyings must be in the same order in VS and FS. Shaders: {0}, {1} / Program: {2}.'.format(v[0], v[1], k)) - exit(1) - layout_counters = {IN: 0, OUT: 0, UNIFORMS: 0, SAMPLERS: [0, list()]} + layout_counters = {UNIFORMS: 0, SAMPLERS: dict()} reflection_dict = {'prg': v[2], 'info': dict()} vs_offset = write_shader_to_pack(pack_file, generate_shader(v[0], shader_dir, generation_dir, - shaders_library, k, program_params[k], + shaders_library, k, layout_counters, k + VERTEX_SHADER_EXT_OUT, reflection_dict['info'], glslc_path)) reflection_dict['vs_off'] = vs_offset[0] reflection_dict['vs_size'] = vs_offset[1] fs_offset = write_shader_to_pack(pack_file, generate_shader(v[1], shader_dir, generation_dir, - shaders_library, k, program_params[k], + shaders_library, k, layout_counters, k + FRAG_SHADER_EXT_OUT, reflection_dict['info'], glslc_path)) reflection_dict['fs_off'] = fs_offset[0] diff --git a/tools/shaders_compiler/macos/mali_compiler/libcompiler_manager.dylib b/tools/shaders_compiler/macos/mali_compiler/libcompiler_manager.dylib deleted file mode 100644 index ef06b5d17b..0000000000 Binary files a/tools/shaders_compiler/macos/mali_compiler/libcompiler_manager.dylib and /dev/null differ diff --git a/tools/shaders_compiler/macos/mali_compiler/malisc b/tools/shaders_compiler/macos/mali_compiler/malisc deleted file mode 100755 index 53eb505915..0000000000 Binary files a/tools/shaders_compiler/macos/mali_compiler/malisc and /dev/null differ diff --git a/tools/shaders_compiler/macos/mali_compiler/openglessl/libMali-400_r4p0-00rel1.dylib b/tools/shaders_compiler/macos/mali_compiler/openglessl/libMali-400_r4p0-00rel1.dylib deleted file mode 100644 index 45a0ced31b..0000000000 Binary files a/tools/shaders_compiler/macos/mali_compiler/openglessl/libMali-400_r4p0-00rel1.dylib and /dev/null differ diff --git a/tools/shaders_compiler/macos/mali_compiler/openglessl/libMali-T600_r4p0-00rel0.dylib b/tools/shaders_compiler/macos/mali_compiler/openglessl/libMali-T600_r4p0-00rel0.dylib deleted file mode 100644 index 9ab53fdac8..0000000000 Binary files a/tools/shaders_compiler/macos/mali_compiler/openglessl/libMali-T600_r4p0-00rel0.dylib and /dev/null differ diff --git a/tools/shaders_compiler/macos/mali_compiler/openglessl/libMali-T600_r4p1-00rel0.dylib b/tools/shaders_compiler/macos/mali_compiler/openglessl/libMali-T600_r4p1-00rel0.dylib deleted file mode 100644 index 1c94e5a015..0000000000 Binary files a/tools/shaders_compiler/macos/mali_compiler/openglessl/libMali-T600_r4p1-00rel0.dylib and /dev/null differ diff --git a/tools/unix/generate_vulkan_shaders.sh b/tools/unix/generate_vulkan_shaders.sh index 1db5795797..e4f05849ca 100755 --- a/tools/unix/generate_vulkan_shaders.sh +++ b/tools/unix/generate_vulkan_shaders.sh @@ -29,4 +29,4 @@ fi OMIM_PATH="${OMIM_PATH:-$(cd "$(dirname "$0")/../.."; pwd)}" SHADERS_GENERATOR="$OMIM_PATH/shaders/vulkan_shaders_preprocessor.py" -python3 "$SHADERS_GENERATOR" "$OMIM_PATH/shaders/GL" shader_index.txt programs.hpp program_params.hpp shaders_lib.glsl "$OMIM_PATH/data/vulkan_shaders" "$GLSLC_PATH" "$DEBUG" \ No newline at end of file +python3 "$SHADERS_GENERATOR" "$OMIM_PATH/shaders/GL" shader_index.txt shaders_lib.glsl "$OMIM_PATH/data/vulkan_shaders" "$GLSLC_PATH" "$DEBUG" \ No newline at end of file