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

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'android/jni/com/mapswithme/opengl/androidoglcontextfactory.cpp')
-rw-r--r--android/jni/com/mapswithme/opengl/androidoglcontextfactory.cpp55
1 files changed, 47 insertions, 8 deletions
diff --git a/android/jni/com/mapswithme/opengl/androidoglcontextfactory.cpp b/android/jni/com/mapswithme/opengl/androidoglcontextfactory.cpp
index 011f5c53e6..38db410219 100644
--- a/android/jni/com/mapswithme/opengl/androidoglcontextfactory.cpp
+++ b/android/jni/com/mapswithme/opengl/androidoglcontextfactory.cpp
@@ -3,6 +3,7 @@
#include "base/assert.hpp"
#include "base/logging.hpp"
+#include "base/src_point.hpp"
#include <algorithm>
@@ -10,10 +11,13 @@
#include <android/native_window.h>
#include <android/native_window_jni.h>
+#define EGL_OPENGL_ES3_BIT 0x00000040
+
namespace android
{
-
-static EGLint * getConfigAttributesListRGB8()
+namespace
+{
+static EGLint * getConfigAttributesListRGB8(bool supportedES3)
{
static EGLint attr_list[] = {
EGL_RED_SIZE, 8,
@@ -26,11 +30,26 @@ static EGLint * getConfigAttributesListRGB8()
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT | EGL_WINDOW_BIT,
EGL_NONE
};
- return attr_list;
+ static EGLint attr_list_es3[] = {
+ EGL_RED_SIZE, 8,
+ EGL_GREEN_SIZE, 8,
+ EGL_BLUE_SIZE, 8,
+ EGL_ALPHA_SIZE, 0,
+ EGL_STENCIL_SIZE, 0,
+ EGL_DEPTH_SIZE, 16,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
+ EGL_SURFACE_TYPE, EGL_PBUFFER_BIT | EGL_WINDOW_BIT,
+ EGL_NONE
+ };
+ return supportedES3 ? attr_list_es3 : attr_list;
}
+int const kMaxConfigCount = 40;
+
static EGLint * getConfigAttributesListR5G6B5()
{
+ // We do not support OpenGL ES3 for R5G6B5, because some Android devices
+ // are not able to create OpenGL context in such mode.
static EGLint attr_list[] = {
EGL_RED_SIZE, 5,
EGL_GREEN_SIZE, 6,
@@ -44,6 +63,15 @@ static EGLint * getConfigAttributesListR5G6B5()
return attr_list;
}
+bool IsSupportedRGB8(EGLDisplay display, bool es3)
+{
+ EGLConfig configs[kMaxConfigCount];
+ int count = 0;
+ return eglChooseConfig(display, getConfigAttributesListRGB8(es3), configs,
+ kMaxConfigCount, &count) == EGL_TRUE;
+}
+} // namespace
+
AndroidOGLContextFactory::AndroidOGLContextFactory(JNIEnv * env, jobject jsurface)
: m_drawContext(NULL)
, m_uploadContext(NULL)
@@ -55,6 +83,7 @@ AndroidOGLContextFactory::AndroidOGLContextFactory(JNIEnv * env, jobject jsurfac
, m_surfaceWidth(0)
, m_surfaceHeight(0)
, m_windowSurfaceValid(false)
+ , m_supportedES3(false)
{
m_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (m_display == EGL_NO_DISPLAY)
@@ -70,6 +99,8 @@ AndroidOGLContextFactory::AndroidOGLContextFactory(JNIEnv * env, jobject jsurfac
return;
}
+ m_supportedES3 = gl3stubInit() && IsSupportedRGB8(m_display, true /* es3 */);
+
SetSurface(env, jsurface);
if (!createPixelbufferSurface())
@@ -202,7 +233,10 @@ dp::OGLContext * AndroidOGLContextFactory::getDrawContext()
ASSERT(IsValid(), ());
ASSERT(m_windowSurface != EGL_NO_SURFACE, ());
if (m_drawContext == nullptr)
- m_drawContext = new AndroidOGLContext(m_display, m_windowSurface, m_config, m_uploadContext);
+ {
+ m_drawContext = new AndroidOGLContext(m_supportedES3, m_display, m_windowSurface,
+ m_config, m_uploadContext);
+ }
return m_drawContext;
}
@@ -211,7 +245,10 @@ dp::OGLContext * AndroidOGLContextFactory::getResourcesUploadContext()
ASSERT(IsValid(), ());
ASSERT(m_pixelbufferSurface != EGL_NO_SURFACE, ());
if (m_uploadContext == nullptr)
- m_uploadContext = new AndroidOGLContext(m_display, m_pixelbufferSurface, m_config, m_drawContext);
+ {
+ m_uploadContext = new AndroidOGLContext(m_supportedES3, m_display, m_pixelbufferSurface,
+ m_config, m_drawContext);
+ }
return m_uploadContext;
}
@@ -227,12 +264,14 @@ bool AndroidOGLContextFactory::isUploadContextCreated() const
bool AndroidOGLContextFactory::createWindowSurface()
{
- int const kMaxConfigCount = 40;
EGLConfig configs[kMaxConfigCount];
int count = 0;
- if (eglChooseConfig(m_display, getConfigAttributesListRGB8(), configs, kMaxConfigCount, &count) != EGL_TRUE)
+ if (eglChooseConfig(m_display, getConfigAttributesListRGB8(m_supportedES3), configs,
+ kMaxConfigCount, &count) != EGL_TRUE)
{
- VERIFY(eglChooseConfig(m_display, getConfigAttributesListR5G6B5(), configs, kMaxConfigCount, &count) == EGL_TRUE, ());
+ ASSERT(!m_supportedES3, ());
+ VERIFY(eglChooseConfig(m_display, getConfigAttributesListR5G6B5(), configs,
+ kMaxConfigCount, &count) == EGL_TRUE, ());
LOG(LDEBUG, ("Backbuffer format: R5G6B5"));
}
else