From 54d176fed0931f802bf5060a09beffeeb797384b Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Sun, 9 Nov 2014 01:22:38 +1100 Subject: [PATCH] Implement GL extensions --- android/cpp/NativeMapView.cpp | 28 ++++++++++++++++++++++++++++ android/cpp/NativeMapView.hpp | 2 ++ 2 files changed, 30 insertions(+) diff --git a/android/cpp/NativeMapView.cpp b/android/cpp/NativeMapView.cpp index add3e3bdb..a59c59857 100644 --- a/android/cpp/NativeMapView.cpp +++ b/android/cpp/NativeMapView.cpp @@ -432,6 +432,8 @@ void NativeMapView::start() { log_gl_string(GL_SHADING_LANGUAGE_VERSION, "SL Version"); log_gl_string(GL_EXTENSIONS, "Extensions"); + loadExtensions(); + if (!eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) { LOG_ERROR("eglMakeCurrent(EGL_NO_CONTEXT) returned error %d", @@ -444,6 +446,32 @@ void NativeMapView::start() { } } +void NativeMapView::loadExtensions() { + const GLubyte* str = glGetString(GL_EXTENSIONS); + if (str == nullptr) { + LOG_ERROR("glGetString(GL_EXTENSIONS) returned error %d", glGetError()); + return; + } + + std::string extensions(reinterpret_cast(str)); + + if (extensions.find("GL_OES_vertex_array_object") != std::string::npos) { + LOG_INFO("Using GL_OES_vertex_array_object."); + gl::BindVertexArray = (gl::PFNGLBINDVERTEXARRAYPROC)eglGetProcAddress("glBindVertexArrayOES"); + gl::DeleteVertexArrays = (gl::PFNGLDELETEVERTEXARRAYSPROC)eglGetProcAddress("glDeleteVertexArraysOES"); + gl::GenVertexArrays = (gl::PFNGLGENVERTEXARRAYSPROC)eglGetProcAddress("glGenVertexArraysOES"); + gl::IsVertexArray = (gl::PFNGLISVERTEXARRAYPROC)eglGetProcAddress("glIsVertexArrayOES"); + + if ((gl::BindVertexArray == nullptr) || (gl::DeleteVertexArrays == nullptr) || (gl::GenVertexArrays == nullptr) || (gl::IsVertexArray == nullptr)) { + LOG_ERROR("Could not load GL_OES_vertex_array_object functions."); + gl::BindVertexArray = nullptr; + gl::DeleteVertexArrays = nullptr; + gl::GenVertexArrays = nullptr; + gl::IsVertexArray = nullptr; + } + } +} + void NativeMapView::stop() { LOG_VERBOSE("NativeMapView::stop"); if ((display != EGL_NO_DISPLAY) && (surface != EGL_NO_SURFACE) diff --git a/android/cpp/NativeMapView.hpp b/android/cpp/NativeMapView.hpp index 866365c6d..aafd76189 100644 --- a/android/cpp/NativeMapView.hpp +++ b/android/cpp/NativeMapView.hpp @@ -68,6 +68,8 @@ private: EGLConfig chooseConfig(const EGLConfig configs[], EGLint num_configs, bool use565) const; + void loadExtensions(); + private: JavaVM* vm = nullptr; jobject obj = nullptr;