Merge branch 'master' into image-readers

This commit is contained in:
artemp
2014-11-13 15:46:11 +00:00
15 changed files with 231 additions and 55 deletions

View File

@@ -9,7 +9,6 @@
namespace mbgl {
#if GL_ARB_vertex_array_object
class VertexArrayObject : public util::noncopyable {
public:
inline VertexArrayObject() {};
@@ -28,7 +27,9 @@ public:
if (bound_shader == 0) {
vertexBuffer.bind();
shader.bind(offset);
storeBinding(shader, vertexBuffer.getID(), 0, offset);
if (vao) {
storeBinding(shader, vertexBuffer.getID(), 0, offset);
}
} else {
verifyBinding(shader, vertexBuffer.getID(), 0, offset);
}
@@ -41,7 +42,9 @@ public:
vertexBuffer.bind();
elementsBuffer.bind();
shader.bind(offset);
storeBinding(shader, vertexBuffer.getID(), elementsBuffer.getID(), offset);
if (vao) {
storeBinding(shader, vertexBuffer.getID(), elementsBuffer.getID(), offset);
}
} else {
verifyBinding(shader, vertexBuffer.getID(), elementsBuffer.getID(), offset);
}
@@ -65,21 +68,6 @@ private:
char *bound_offset = 0;
};
#else
class VertexArrayObject : public util::noncopyable {
public:
template <typename Shader, typename Buffers>
void bind(Shader& shader, Buffers& buffers, char *offset) {
for (auto &buffer : buffers) {
buffer.bind();
}
shader.bind(offset);
}
};
#endif
}
#endif

View File

@@ -5,7 +5,7 @@
#define MBGL_USE_CGL 1
#else
#define GL_GLEXT_PROTOTYPES
#include <GL/glx.h>
#include <mbgl/platform/default/glx.h>
#define MBGL_USE_GLX 1
#endif
@@ -25,6 +25,7 @@ public:
~HeadlessView();
void createContext();
void loadExtensions();
void resize(uint16_t width, uint16_t height, float pixelRatio);
std::unique_ptr<uint32_t[]> readPixels();

View File

@@ -32,6 +32,7 @@ enum class Event : uint8_t {
Database,
HttpRequest,
Sprite,
OpenGL,
};
MBGL_DEFINE_ENUM_CLASS(EventClass, Event, {
@@ -44,6 +45,7 @@ MBGL_DEFINE_ENUM_CLASS(EventClass, Event, {
{ Event::Database, "Database" },
{ Event::HttpRequest, "HttpRequest" },
{ Event::Sprite, "Sprite" },
{ Event::OpenGL, "OpenGL" },
{ Event(-1), "Unknown" },
});

View File

@@ -3,38 +3,28 @@
#include <string>
#ifdef NVIDIA
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
extern PFNGLDISCARDFRAMEBUFFEREXTPROC glDiscardFramebufferEXT;
#define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
#elif __APPLE__
#if __APPLE__
#include "TargetConditionals.h"
#if TARGET_OS_IPHONE
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#define glGenVertexArrays glGenVertexArraysOES
#define glBindVertexArray glBindVertexArrayOES
#define glDeleteVertexArrays glDeleteVertexArraysOES
#define GL_ARB_vertex_array_object 1
#define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
// #define glGenVertexArrays glGenVertexArraysOES
// #define glBindVertexArray glBindVertexArrayOES
// #define glDeleteVertexArrays glDeleteVertexArraysOES
// #define GL_ARB_vertex_array_object 1
// #define GL_DEPTH24_STENCIL8 GL_DEPTH24_STENCIL8_OES
#elif TARGET_IPHONE_SIMULATOR
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#elif TARGET_OS_MAC
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#if GL_APPLE_vertex_array_object
#define GL_ARB_vertex_array_object 1
#define glGenVertexArrays glGenVertexArraysAPPLE
#define glBindVertexArray glBindVertexArrayAPPLE
#define glDeleteVertexArrays glDeleteVertexArraysAPPLE
#endif
#else
#error Unsupported Apple platform
#endif
#elif MBGL_USE_GLES2
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#else
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
@@ -43,8 +33,19 @@
namespace mbgl {
namespace gl {
typedef void (* PFNGLBINDVERTEXARRAYPROC) (GLuint array);
typedef void (* PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint* arrays);
typedef void (* PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint* arrays);
typedef GLboolean (* PFNGLISVERTEXARRAYPROC) (GLuint array);
extern PFNGLBINDVERTEXARRAYPROC BindVertexArray;
extern PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays;
extern PFNGLGENVERTEXARRAYSPROC GenVertexArrays;
extern PFNGLISVERTEXARRAYPROC IsVertexArray;
// Debug group markers, useful for debuggin on iOS
#if defined(__APPLE__) && defined(DEBUG) && defined(GL_EXT_debug_marker)
#if __APPLE__ && defined(DEBUG) && defined(GL_EXT_debug_marker)
// static int indent = 0;
inline void start_group(const std::string &str) {
glPushGroupMarkerEXT(0, str.c_str());

View File

@@ -1,4 +1,5 @@
#include <mbgl/platform/default/glfw_view.hpp>
#include <mbgl/platform/gl.hpp>
#include <mbgl/util/string.hpp>
@@ -26,6 +27,10 @@ void GLFWView::initialize(mbgl::Map *map_) {
monitor = glfwGetPrimaryMonitor();
}
#ifdef DEBUG
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
#endif
#ifdef GL_ES_VERSION_2_0
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
@@ -63,6 +68,25 @@ void GLFWView::initialize(mbgl::Map *map_) {
glfwSetScrollCallback(window, scroll);
glfwSetKeyCallback(window, key);
const std::string extensions = (char *)glGetString(GL_EXTENSIONS);
{
using namespace mbgl;
if (extensions.find("GL_ARB_vertex_array_object") != std::string::npos) {
gl::BindVertexArray = (gl::PFNGLBINDVERTEXARRAYPROC)glfwGetProcAddress("glBindVertexArrayARB");
gl::DeleteVertexArrays = (gl::PFNGLDELETEVERTEXARRAYSPROC)glfwGetProcAddress("glDeleteVertexArraysARB");
gl::GenVertexArrays = (gl::PFNGLGENVERTEXARRAYSPROC)glfwGetProcAddress("glGenVertexArraysARB");
gl::IsVertexArray = (gl::PFNGLISVERTEXARRAYPROC)glfwGetProcAddress("glIsVertexArrayARB");
} else if (extensions.find("GL_APPLE_vertex_array_object") != std::string::npos) {
gl::BindVertexArray = (gl::PFNGLBINDVERTEXARRAYPROC)glfwGetProcAddress("glBindVertexArrayAPPLE");
gl::DeleteVertexArrays = (gl::PFNGLDELETEVERTEXARRAYSPROC)glfwGetProcAddress("glDeleteVertexArraysAPPLE");
gl::GenVertexArrays = (gl::PFNGLGENVERTEXARRAYSPROC)glfwGetProcAddress("glGenVertexArraysAPPLE");
gl::IsVertexArray = (gl::PFNGLISVERTEXARRAYPROC)glfwGetProcAddress("glIsVertexArrayAPPLE");
}
}
glfwMakeContextCurrent(nullptr);
}

View File

@@ -48,7 +48,7 @@ HeadlessDisplay::HeadlessDisplay() {
// We're creating a dummy pbuffer anyway that we're not using.
static int pixelFormat[] = {
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
None
0
};
int configs = 0;

View File

@@ -11,16 +11,62 @@ static PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = nullptr;
#endif
#endif
#ifdef MBGL_USE_CGL
#include <CoreFoundation/CoreFoundation.h>
typedef void (* CGLProc)(void);
CGLProc CGLGetProcAddress(const char *proc) {
static CFBundleRef framework = nullptr;
if (!framework) {
framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
if (!framework) {
throw std::runtime_error("Failed to load OpenGL.framework");
}
}
CFStringRef name = CFStringCreateWithCString(kCFAllocatorDefault, proc, kCFStringEncodingASCII);
CGLProc symbol = (CGLProc)CFBundleGetFunctionPointerForName(framework, name);
CFRelease(name);
return symbol;
}
#endif
namespace mbgl {
HeadlessView::HeadlessView()
: display_(std::make_shared<HeadlessDisplay>()) {
createContext();
loadExtensions();
}
HeadlessView::HeadlessView(std::shared_ptr<HeadlessDisplay> display)
: display_(display) {
createContext();
loadExtensions();
}
void HeadlessView::loadExtensions() {
make_active();
const std::string extensions = (char *)glGetString(GL_EXTENSIONS);
#ifdef MBGL_USE_CGL
if (extensions.find("GL_APPLE_vertex_array_object") != std::string::npos) {
gl::BindVertexArray = (gl::PFNGLBINDVERTEXARRAYPROC)CGLGetProcAddress("glBindVertexArrayAPPLE");
gl::DeleteVertexArrays = (gl::PFNGLDELETEVERTEXARRAYSPROC)CGLGetProcAddress("glDeleteVertexArraysAPPLE");
gl::GenVertexArrays = (gl::PFNGLGENVERTEXARRAYSPROC)CGLGetProcAddress("glGenVertexArraysAPPLE");
gl::IsVertexArray = (gl::PFNGLISVERTEXARRAYPROC)CGLGetProcAddress("glIsVertexArrayAPPLE");
}
#endif
#ifdef MBGL_USE_GLX
if (extensions.find("GL_ARB_vertex_array_object") != std::string::npos) {
gl::BindVertexArray = (gl::PFNGLBINDVERTEXARRAYPROC)glXGetProcAddress((const GLubyte *)"glBindVertexArrayARB");
gl::DeleteVertexArrays = (gl::PFNGLDELETEVERTEXARRAYSPROC)glXGetProcAddress((const GLubyte *)"glDeleteVertexArraysARB");
gl::GenVertexArrays = (gl::PFNGLGENVERTEXARRAYSPROC)glXGetProcAddress((const GLubyte *)"glGenVertexArraysARB");
gl::IsVertexArray = (gl::PFNGLISVERTEXARRAYPROC)glXGetProcAddress((const GLubyte *)"glIsVertexArrayARB");
}
#endif
make_inactive();
}
@@ -61,7 +107,7 @@ GLXContext createCoreProfile(Display *dpy, GLXFBConfig fbconfig) {
const int context_flags[] = {
GLX_CONTEXT_MAJOR_VERSION_ARB, core_profile_versions[i].major,
GLX_CONTEXT_MINOR_VERSION_ARB, core_profile_versions[i].minor,
None
0
};
ctx = glXCreateContextAttribsARB(dpy, fbconfig, 0, True, context_flags);
if (context_creation_failed) {
@@ -126,7 +172,7 @@ void HeadlessView::createContext() {
int pbuffer_attributes[] = {
GLX_PBUFFER_WIDTH, 8,
GLX_PBUFFER_HEIGHT, 8,
None
0
};
glx_pbuffer = glXCreatePbuffer(x_display, fb_configs[0], pbuffer_attributes);
#endif

View File

@@ -1,6 +1,7 @@
#include <mbgl/storage/http_request_baton.hpp>
#include <mbgl/util/uv-messenger.h>
#include <mbgl/util/time.hpp>
#include <mbgl/util/string.hpp>
#include <uv.h>
#include <curl/curl.h>
@@ -9,6 +10,20 @@
#include <cassert>
#include <cstring>
// Check curl library version.
const static bool curl_version_check = []() {
const auto version = curl_version_info(CURLVERSION_NOW);
if (version->version_num != LIBCURL_VERSION_NUM) {
throw std::runtime_error(mbgl::util::sprintf<96>(
"libcurl version mismatch: headers report %d.%d.%d, but library reports %d.%d.%d",
(LIBCURL_VERSION_NUM >> 16) & 0xFF, (LIBCURL_VERSION_NUM >> 8) & 0xFF, LIBCURL_VERSION_NUM & 0xFF,
(version->version_num >> 16) & 0xFF, (version->version_num >> 8) & 0xFF, version->version_num & 0xFF));
}
return true;
}();
// This file contains code from http://curl.haxx.se/libcurl/c/multi-uv.html:
/***************************************************************************

View File

@@ -1,4 +1,5 @@
#include <mbgl/util/image.hpp>
#include <mbgl/util/string.hpp>
#include <png.h>
@@ -8,6 +9,19 @@
#include <cstring>
#include <mbgl/util/image_reader.hpp>
// Check png library version.
const static bool png_version_check = []() {
const png_uint_32 version = png_access_version_number();
if (version != PNG_LIBPNG_VER) {
throw std::runtime_error(mbgl::util::sprintf<96>(
"libpng version mismatch: headers report %d.%d.%d, but library reports %d.%d.%d",
PNG_LIBPNG_VER / 10000, (PNG_LIBPNG_VER / 100) % 100, PNG_LIBPNG_VER % 100,
version / 10000, (version / 100) % 100, version % 100));
}
return true;
}();
namespace mbgl {
namespace util {

View File

@@ -1,20 +1,30 @@
#include <mbgl/geometry/vao.hpp>
#include <mbgl/platform/log.hpp>
namespace mbgl {
#if GL_ARB_vertex_array_object
VertexArrayObject::~VertexArrayObject() {
if (!gl::DeleteVertexArrays) return;
if (vao) {
glDeleteVertexArrays(1, &vao);
gl::DeleteVertexArrays(1, &vao);
}
}
void VertexArrayObject::bindVertexArrayObject() {
if (!vao) {
glGenVertexArrays(1, &vao);
if (!gl::GenVertexArrays || !gl::BindVertexArray) {
static bool reported = false;
if (!reported) {
Log::Warning(Event::OpenGL, "Not using Vertex Array Objects");
reported = true;
}
return;
}
glBindVertexArray(vao);
if (!vao) {
gl::GenVertexArrays(1, &vao);
}
gl::BindVertexArray(vao);
}
void VertexArrayObject::verifyBinding(Shader &shader, GLuint vertexBuffer, GLuint elementsBuffer,
@@ -41,6 +51,4 @@ void VertexArrayObject::storeBinding(Shader &shader, GLuint vertexBuffer, GLuint
bound_elements_buffer = elementsBuffer;
}
#endif
}

View File

@@ -21,6 +21,7 @@
#include <mbgl/geometry/sprite_atlas.hpp>
#include <mbgl/storage/file_source.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/util/string.hpp>
#include <algorithm>
#include <iostream>
@@ -28,6 +29,60 @@
#define _USE_MATH_DEFINES
#include <cmath>
#include <uv.h>
// Check libuv library version.
const static bool uv_version_check = []() {
const unsigned int version = uv_version();
const unsigned int major = (version >> 16) & 0xFF;
const unsigned int minor = (version >> 8) & 0xFF;
const unsigned int patch = version & 0xFF;
#ifndef UV_VERSION_PATCH
// 0.10 doesn't have UV_VERSION_PATCH defined, so we "fake" it by using the library patch level.
const unsigned int UV_VERSION_PATCH = version & 0xFF;
#endif
if (major != UV_VERSION_MAJOR || minor != UV_VERSION_MINOR || patch != UV_VERSION_PATCH) {
throw std::runtime_error(mbgl::util::sprintf<96>(
"libuv version mismatch: headers report %d.%d.%d, but library reports %d.%d.%d", UV_VERSION_MAJOR,
UV_VERSION_MINOR, UV_VERSION_PATCH, major, minor, patch));
}
return true;
}();
#include <zlib.h>
// Check zlib library version.
const static bool zlib_version_check = []() {
const char *const version = zlibVersion();
if (version[0] != ZLIB_VERSION[0]) {
throw std::runtime_error(mbgl::util::sprintf<96>(
"zlib version mismatch: headers report %s, but library reports %s", ZLIB_VERSION, version));
}
return true;
}();
#include <sqlite3.h>
// Check sqlite3 library version.
const static bool sqlite_version_check = []() {
if (sqlite3_libversion_number() != SQLITE_VERSION_NUMBER) {
throw std::runtime_error(mbgl::util::sprintf<96>(
"sqlite3 libversion mismatch: headers report %d, but library reports %d",
SQLITE_VERSION_NUMBER, sqlite3_libversion_number()));
}
if (strcmp(sqlite3_sourceid(), SQLITE_SOURCE_ID) != 0) {
throw std::runtime_error(mbgl::util::sprintf<256>(
"sqlite3 sourceid mismatch: headers report \"%s\", but library reports \"%s\"",
SQLITE_SOURCE_ID, sqlite3_sourceid()));
}
return true;
}();
using namespace mbgl;
Map::Map(View& view_)

View File

@@ -2,9 +2,17 @@
#include <iostream>
#ifdef NVIDIA
PFNGLDISCARDFRAMEBUFFEREXTPROC glDiscardFramebufferEXT;
#endif
namespace mbgl {
namespace gl {
PFNGLBINDVERTEXARRAYPROC BindVertexArray = nullptr;
PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays = nullptr;
PFNGLGENVERTEXARRAYSPROC GenVertexArrays = nullptr;
PFNGLISVERTEXARRAYPROC IsVertexArray = nullptr;
}
}
void _CHECK_GL_ERROR(const char *cmd, const char *file, int line) {
std::cout << cmd << ";" << std::endl;

View File

@@ -49,7 +49,11 @@ void PrerenderedTexture::bindFramebuffer() {
// Create depth/stencil buffer
glGenRenderbuffers(1, &fbo_depth_stencil);
glBindRenderbuffer(GL_RENDERBUFFER, fbo_depth_stencil);
#ifdef GL_ES_VERSION_2_0
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, properties.size, properties.size);
#else
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, properties.size, properties.size);
#endif
glBindRenderbuffer(GL_RENDERBUFFER, 0);
}

View File

@@ -199,9 +199,19 @@
'../mapboxgl.gyp:mbgl-standalone',
'<(platform_library)',
],
'variables': {
'cflags_cc': [
'-I<(boost_root)/include',
]
},
'conditions': [
['OS == "mac"', { 'xcode_settings': { 'OTHER_LDFLAGS': [ '<@(ldflags)', '-framework Foundation' ] }
['OS == "mac"', {
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS': [ '<@(cflags_cc)' ],
'OTHER_LDFLAGS': [ '<@(ldflags)', '-framework Foundation' ]
},
}, {
'cflags_cc': [ '<@(cflags_cc)' ],
'libraries': [ '<@(ldflags)'],
}]
]