From 7e0259f7a584e3bb7f38633c779f10a479a31791 Mon Sep 17 00:00:00 2001 From: ExMix Date: Wed, 28 Jan 2015 08:16:54 +0300 Subject: [PATCH] [drape] GLFunctions::Init must be called in thread with valid OGL context and executed only once --- drape/drape_tests/glfunctions.cpp | 2 +- drape/glfunctions.cpp | 6 ++++++ drape_frontend/drape_engine.cpp | 1 - drape_frontend/frontend_renderer.cpp | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drape/drape_tests/glfunctions.cpp b/drape/drape_tests/glfunctions.cpp index 13ae00e13c..85a04553aa 100644 --- a/drape/drape_tests/glfunctions.cpp +++ b/drape/drape_tests/glfunctions.cpp @@ -239,7 +239,7 @@ int32_t GLFunctions::glGetInteger(glConst pname) return MOCK_CALL(glGetInteger(pname)); } -void CheckGLError() {} +void CheckGLError(my::SrcPoint const & /*srcPt*/) {} // @TODO add actual unit tests void GLFunctions::glEnable(glConst mode) {} diff --git a/drape/glfunctions.cpp b/drape/glfunctions.cpp index 73d62e2918..1fede51b83 100644 --- a/drape/glfunctions.cpp +++ b/drape/glfunctions.cpp @@ -12,6 +12,7 @@ #endif #include "std/cstring.hpp" +#include "std/atomic.hpp" #if defined(OMIM_OS_WINDOWS) #define APIENTRY __stdcall @@ -111,10 +112,15 @@ namespace int const GLCompileStatus = GL_COMPILE_STATUS; int const GLLinkStatus = GL_LINK_STATUS; + + atomic_flag s_inited = ATOMIC_FLAG_INIT; } void GLFunctions::Init() { + if (s_inited.test_and_set()) + return; + /// VAO #if defined(OMIM_OS_MAC) glGenVertexArraysFn = &glGenVertexArraysAPPLE; diff --git a/drape_frontend/drape_engine.cpp b/drape_frontend/drape_engine.cpp index 0917cd3b55..58fdf71e0e 100644 --- a/drape_frontend/drape_engine.cpp +++ b/drape_frontend/drape_engine.cpp @@ -15,7 +15,6 @@ DrapeEngine::DrapeEngine(dp::RefPointer contextfactory, MapDataProvider const & model) : m_viewport(viewport) { - GLFunctions::Init(); VisualParams::Init(viewport.GetPixelRatio(), df::CalculateTileSize(m_viewport.GetWidth(), m_viewport.GetHeight())); m_threadCommutator = dp::MasterPointer(new ThreadsCommutator()); diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index 55b8dcfa30..284169ef8b 100644 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -385,6 +385,7 @@ void FrontendRenderer::Routine::Do() { dp::OGLContext * context = m_renderer.m_contextFactory->getDrawContext(); context->makeCurrent(); + GLFunctions::Init(); my::Timer timer; //double processingTime = InitAvarageTimePerMessage; // By init we think that one message processed by 1ms