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
|
#include "androidoglcontext.hpp"
#include "android_gl_utils.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());
CHECK(m_nativeContext != EGL_NO_CONTEXT, ());
}
AndroidOGLContext::~AndroidOGLContext()
{
// Native context must exist
if (eglDestroyContext(m_display, m_nativeContext) == EGL_FALSE)
CHECK_EGL_CALL();
}
void AndroidOGLContext::setDefaultFramebuffer()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void AndroidOGLContext::makeCurrent()
{
ASSERT(m_surface != EGL_NO_SURFACE, ());
if (eglMakeCurrent(m_display, m_surface, m_surface, m_nativeContext) == EGL_FALSE)
CHECK_EGL_CALL();
}
void AndroidOGLContext::doneCurrent()
{
clearCurrent();
}
void AndroidOGLContext::clearCurrent()
{
if (eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT) == EGL_FALSE)
CHECK_EGL_CALL();
}
void AndroidOGLContext::setRenderingEnabled(bool enabled)
{
if (enabled)
makeCurrent();
else
clearCurrent();
}
void AndroidOGLContext::present()
{
ASSERT(m_surface != EGL_NO_SURFACE, ());
if (eglSwapBuffers(m_display, m_surface) == EGL_FALSE)
CHECK_EGL_CALL();
}
void AndroidOGLContext::setSurface(EGLSurface surface)
{
m_surface = surface;
ASSERT(m_surface != EGL_NO_SURFACE, ());
}
void AndroidOGLContext::resetSurface()
{
m_surface = EGL_NO_SURFACE;
}
} // namespace android
|