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

androidoglcontext.cpp « opengl « mapswithme « com « jni « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 01331fd278593216d6b57a0d05ba3c4fa02a56e6 (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
#include "androidoglcontext.hpp"
#include "../../../base/assert.hpp"
#include "../../../base/logging.hpp"

namespace android
{

static EGLint * getContextAttributesList()
{
  static EGLint contextAttrList[] = {
    EGL_CONTEXT_CLIENT_VERSION, 2,
    EGL_NONE
  };
  return contextAttrList;
}

AndroidOGLContext::AndroidOGLContext(EGLDisplay display, EGLSurface surface, EGLConfig config, AndroidOGLContext * contextToShareWith)
  : m_nativeContext(EGL_NO_CONTEXT)
  , m_surface(surface)
  , m_display(display)
{
  ASSERT(m_surface != EGL_NO_SURFACE, ());
  ASSERT(m_display != EGL_NO_DISPLAY, ());

  EGLContext sharedContext = (contextToShareWith == NULL) ? EGL_NO_CONTEXT : contextToShareWith->m_nativeContext;
  m_nativeContext = eglCreateContext(m_display, config, sharedContext, getContextAttributesList());
  LOG(LINFO, ("UVR : Context created = ", m_nativeContext));

  CHECK(m_nativeContext != EGL_NO_CONTEXT, ());
  LOG(LINFO, ("UVR : Present"));
}

AndroidOGLContext::~AndroidOGLContext()
{
  // Native context must exist
  eglDestroyContext(m_display, m_nativeContext);
}

void AndroidOGLContext::setDefaultFramebuffer()
{
  glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

void AndroidOGLContext::makeCurrent()
{
  LOG(LINFO, ("UVR : Make current for context"));
  if (eglMakeCurrent(m_display, m_surface, m_surface, m_nativeContext) != EGL_TRUE)
    LOG(LINFO, ("Failed to set current context:", eglGetError()));
}

void AndroidOGLContext::present()
{
  LOG(LINFO, ("UVR : Present"));
  if(eglSwapBuffers(m_display, m_surface) != EGL_TRUE)
    LOG(LINFO, ("Failed to swap buffers:", eglGetError()));
}

} // namespace android