From 6900b76a098decb0cacc02fe7481493cda01a569 Mon Sep 17 00:00:00 2001 From: rokuz Date: Mon, 19 Jun 2023 09:41:32 +0100 Subject: [PATCH] Fix OpenGL issues with depth and context destroy Signed-off-by: rokuz --- drape/texture_manager.cpp | 41 ++++++++++++++-------------- drape/texture_manager.hpp | 2 ++ drape_frontend/arrow3d.cpp | 2 +- drape_frontend/backend_renderer.cpp | 8 +++++- drape_frontend/frontend_renderer.cpp | 10 ++++++- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/drape/texture_manager.cpp b/drape/texture_manager.cpp index 9e2068e367..cc3bc2a5ff 100644 --- a/drape/texture_manager.cpp +++ b/drape/texture_manager.cpp @@ -42,8 +42,6 @@ float const kGlyphAreaCoverage = 0.9f; std::string const kSymbolTextures[] = { "symbols" }; uint32_t const kDefaultSymbolsIndex = 0; -std::string const kArrowTextureDefaultName = "arrow-texture.png"; - void MultilineTextToUniString(TextureManager::TMultilineText const & text, strings::UniString & outString) { size_t cnt = 0; @@ -90,6 +88,22 @@ m2::PointU ColorTextureSize(size_t colorsCount, uint32_t maxTextureSize) colorTextureSize = std::min(maxTextureSize, colorTextureSize); return m2::PointU(colorTextureSize, colorTextureSize); } + +drape_ptr CreateArrowTexture(ref_ptr context, + ref_ptr textureAllocator, + std::optional const & texturePath, + bool useDefaultResourceFolder) +{ + if (texturePath.has_value()) + { + return make_unique_dp(context, texturePath.value(), + useDefaultResourceFolder ? std::make_optional(StaticTexture::kDefaultResource) : std::nullopt /* skinPathName */, + dp::TextureFormat::RGBA8, textureAllocator, true /* allowOptional */); + } + return make_unique_dp(context, "arrow-texture.png", StaticTexture::kDefaultResource, + dp::TextureFormat::RGBA8, textureAllocator, + true /* allowOptional */); +} } // namespace TextureManager::TextureManager(ref_ptr glyphGenerator) @@ -399,9 +413,9 @@ void TextureManager::Init(ref_ptr context, Params const & p dp::TextureFormat::RGBA8, make_ref(m_textureAllocator)); m_hatchingTexture = make_unique_dp(context, "area-hatching.png", m_resPostfix, dp::TextureFormat::RGBA8, make_ref(m_textureAllocator)); - m_arrowTexture = make_unique_dp(context, kArrowTextureDefaultName, StaticTexture::kDefaultResource, - dp::TextureFormat::RGBA8, make_ref(m_textureAllocator), - true /* allowOptional */); + m_arrowTexture = CreateArrowTexture(context, make_ref(m_textureAllocator), + params.m_arrowTexturePath, + params.m_arrowTextureUseDefaultResourceFolder); // SMAA is not supported on OpenGL ES2. if (apiVersion != dp::ApiVersion::OpenGLES2) @@ -499,22 +513,7 @@ void TextureManager::InvalidateArrowTexture(ref_ptr context bool useDefaultResourceFolder /* = false */) { CHECK(m_isInitialized, ()); - - if (texturePath.has_value()) - { - m_newArrowTexture = make_unique_dp(context, texturePath.value(), - useDefaultResourceFolder ? - std::make_optional(StaticTexture::kDefaultResource) : - std::nullopt /* skinPathName */, - dp::TextureFormat::RGBA8, make_ref(m_textureAllocator), - true /* allowOptional */); - } - else - { - m_newArrowTexture = make_unique_dp(context, kArrowTextureDefaultName, StaticTexture::kDefaultResource, - dp::TextureFormat::RGBA8, make_ref(m_textureAllocator), - true /* allowOptional */); - } + m_newArrowTexture = CreateArrowTexture(context, make_ref(m_textureAllocator), texturePath, useDefaultResourceFolder); } void TextureManager::ApplyInvalidatedStaticTextures() diff --git a/drape/texture_manager.hpp b/drape/texture_manager.hpp index 445e1b9cca..cb2c5a6fda 100644 --- a/drape/texture_manager.hpp +++ b/drape/texture_manager.hpp @@ -79,6 +79,8 @@ public: std::string m_colors; std::string m_patterns; GlyphManager::Params m_glyphMngParams; + std::optional m_arrowTexturePath; + bool m_arrowTextureUseDefaultResourceFolder = false; }; explicit TextureManager(ref_ptr glyphGenerator); diff --git a/drape_frontend/arrow3d.cpp b/drape_frontend/arrow3d.cpp index 1ac1382c60..c719d27a7a 100644 --- a/drape_frontend/arrow3d.cpp +++ b/drape_frontend/arrow3d.cpp @@ -283,7 +283,7 @@ Arrow3d::Arrow3d(ref_ptr context, , m_arrowMeshTexturingEnabled(preloadedData.m_arrowMeshTexturingEnabled) , m_texCoordFlipping(std::move(preloadedData.m_texCoordFlipping)) , m_shadowMesh(preloadedData.m_shadowMeshData.has_value() ? - std::make_unique(context, dp::MeshObject::DrawPrimitive::Triangles) : + make_unique_dp(context, dp::MeshObject::DrawPrimitive::Triangles) : nullptr) , m_state(CreateRenderState(gpu::Program::Arrow3d, DepthLayer::OverlayLayer)) , m_meshOffset(std::move(preloadedData.m_meshOffset)) diff --git a/drape_frontend/backend_renderer.cpp b/drape_frontend/backend_renderer.cpp index e59bc4ade2..cec74e4a87 100644 --- a/drape_frontend/backend_renderer.cpp +++ b/drape_frontend/backend_renderer.cpp @@ -765,7 +765,13 @@ void BackendRenderer::InitContextDependentResources() params.m_glyphMngParams.m_sdfScale = VisualParams::Instance().GetGlyphSdfScale(); params.m_glyphMngParams.m_baseGlyphHeight = VisualParams::Instance().GetGlyphBaseSize(); GetPlatform().GetFontNames(params.m_glyphMngParams.m_fonts); - + if (m_arrow3dCustomDecl.has_value()) + { + params.m_arrowTexturePath = m_arrow3dCustomDecl.value().m_arrowMeshTexturePath; + params.m_arrowTextureUseDefaultResourceFolder = + m_arrow3dCustomDecl.value().m_loadFromDefaultResourceFolder; + } + CHECK(m_context != nullptr, ()); m_texMng->Init(m_context, params); diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index b48b438ca8..9de12aaf60 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -1510,7 +1510,15 @@ void FrontendRenderer::RenderScene(ScreenBase const & modelView, bool activeFram return; if (IsValidCurrentZoom()) - m_myPositionController->Render(m_context, make_ref(m_gpuProgramManager), modelView, GetCurrentZoom(), m_frameValues); + { + uint32_t clearBits = dp::ClearBits::DepthBit; + if (m_apiVersion == dp::ApiVersion::OpenGLES2 || m_apiVersion == dp::ApiVersion::OpenGLES3) + clearBits |= dp::ClearBits::StencilBit; + m_context->Clear(clearBits, dp::kClearBitsStoreAll); + + m_myPositionController->Render(m_context, make_ref(m_gpuProgramManager), modelView, + GetCurrentZoom(), m_frameValues); + } if (m_guiRenderer && !m_screenshotMode) {