Welcome to mirror list, hosted at ThFree Co, Russian Federation.

qtoglcontext.cpp « qt - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a423e46756eede93820b8d186815eee27360ff2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "qt/qtoglcontext.hpp"

#include "base/assert.hpp"
#include "base/logging.hpp"

#include "drape/glfunctions.hpp"

QtRenderOGLContext::QtRenderOGLContext(QOpenGLContext * nativeContext, QThread * guiThread,
                                       TRegisterThreadFn const & regFn, TSwapFn const & swapFn)
  : m_surface(nativeContext->surface())
  , m_ctx(nativeContext)
  , m_guiThread(guiThread)
  , m_regFn(regFn)
  , m_swapFn(swapFn)
  , m_isRegistered(false)
  , m_shutedDown(false)
{
}

void QtRenderOGLContext::present()
{
  if (m_shutedDown)
    return;

  MoveContextOnGui();
  m_swapFn();

  makeCurrent();
}

void QtRenderOGLContext::makeCurrent()
{
  if (!m_isRegistered)
  {
    m_regFn(QThread::currentThread());
    m_isRegistered = true;
  }

  m_ctx->makeCurrent(m_surface);
}

void QtRenderOGLContext::doneCurrent()
{
  MoveContextOnGui();
}

void QtRenderOGLContext::setDefaultFramebuffer()
{
  GLFunctions::glBindFramebuffer(GL_FRAMEBUFFER, m_ctx->defaultFramebufferObject());
}

void QtRenderOGLContext::shutDown()
{
  m_shutedDown = true;
}

void QtRenderOGLContext::MoveContextOnGui()
{
  m_ctx->doneCurrent();
  m_ctx->moveToThread(m_guiThread);
}

QtUploadOGLContext::QtUploadOGLContext(QSurface * surface, QOpenGLContext * contextToShareWith)
{
  m_surface = surface;
  m_nativeContext = new QOpenGLContext();

  ASSERT(contextToShareWith != nullptr, ());
  m_nativeContext->setShareContext(contextToShareWith);

  m_nativeContext->setFormat(contextToShareWith->format());
  VERIFY(m_nativeContext->create(), ());
}

QtUploadOGLContext::~QtUploadOGLContext()
{
  delete m_nativeContext;
}

void QtUploadOGLContext::makeCurrent()
{
  ASSERT(m_nativeContext->isValid(), ());
  m_nativeContext->makeCurrent(m_surface);
}

void QtUploadOGLContext::present()
{
  ASSERT(false, ());
}

void QtUploadOGLContext::setDefaultFramebuffer()
{
  ASSERT(false, ());
}