Merge pull request #731 from mapbox/view-rename

Rename View functions to match conventions
This commit is contained in:
John Firebaugh
2014-12-22 13:14:44 -08:00
9 changed files with 159 additions and 161 deletions

View File

@@ -33,18 +33,18 @@ public:
// Called from the render thread. Makes the GL context active in the current
// thread. This is typically just called once at the beginning of the
// renderer setup since the render thread doesn't switch the contexts.
virtual void make_active() = 0;
virtual void activate() = 0;
// Called from the render thread. Makes the GL context inactive in the current
// thread. This is called once just before the rendering thread terminates.
virtual void make_inactive() = 0;
virtual void deactivate() = 0;
virtual void notify() = 0;
// Notifies a watcher of map x/y/scale/rotation changes.
// Must only be called from the same thread that caused the change.
// Must not be called from the render thread.
virtual void notify_map_change(MapChange change, timestamp delay = 0) = 0;
virtual void notifyMapChange(MapChange change, timestamp delay = 0) = 0;
protected:
mbgl::Map *map = nullptr;

View File

@@ -16,16 +16,16 @@ public:
void initialize(mbgl::Map *map);
void swap();
void make_active();
void make_inactive();
void activate();
void deactivate();
void notify();
void notify_map_change(mbgl::MapChange change, mbgl::timestamp delay = 0);
void notifyMapChange(mbgl::MapChange change, mbgl::timestamp delay = 0);
static void key(GLFWwindow *window, int key, int scancode, int action, int mods);
static void scroll(GLFWwindow *window, double xoffset, double yoffset);
static void resize(GLFWwindow *window, int, int);
static void mouseclick(GLFWwindow *window, int button, int action, int modifiers);
static void mousemove(GLFWwindow *window, double x, double y);
static void resize(GLFWwindow *window, int width, int height);
static void mouseClick(GLFWwindow *window, int button, int action, int modifiers);
static void mouseMove(GLFWwindow *window, double x, double y);
static void eventloop(void *arg);
@@ -35,12 +35,12 @@ public:
public:
bool fullscreen = false;
double last_x = 0, last_y = 0;
double lastX = 0, lastY = 0;
bool tracking = false;
bool rotating = false;
double last_click = -1;
double lastClick = -1;
GLFWwindow *window = nullptr;
};

View File

@@ -31,13 +31,13 @@ public:
std::unique_ptr<uint32_t[]> readPixels();
void notify();
void notify_map_change(MapChange change, timestamp delay = 0);
void make_active();
void make_inactive();
void notifyMapChange(MapChange change, timestamp delay = 0);
void activate();
void deactivate();
void swap();
private:
void clear_buffers();
void clearBuffers();
private:
std::shared_ptr<HeadlessDisplay> display_;

View File

@@ -4,7 +4,7 @@
GLFWView::GLFWView(bool fullscreen_) : fullscreen(fullscreen_) {
#ifdef NVIDIA
glDiscardFramebufferEXT = (PFNGLDISCARDFRAMEBUFFEREXTPROC)glfwGetProcAddress("glDiscardFramebufferEXT");
glDiscardFramebufferEXT = reinterpret_cast<PFNGLDISCARDFRAMEBUFFEREXTPROC>(glfwGetProcAddress("glDiscardFramebufferEXT"));
#endif
}
@@ -61,34 +61,34 @@ void GLFWView::initialize(mbgl::Map *map_) {
int width, height;
glfwGetWindowSize(window, &width, &height);
int fb_width, fb_height;
glfwGetFramebufferSize(window, &fb_width, &fb_height);
int fbWidth, fbHeight;
glfwGetFramebufferSize(window, &fbWidth, &fbHeight);
resize(window, 0, 0);
glfwSetCursorPosCallback(window, mousemove);
glfwSetMouseButtonCallback(window, mouseclick);
glfwSetCursorPosCallback(window, mouseMove);
glfwSetMouseButtonCallback(window, mouseClick);
glfwSetWindowSizeCallback(window, resize);
glfwSetFramebufferSizeCallback(window, resize);
glfwSetScrollCallback(window, scroll);
glfwSetKeyCallback(window, key);
const std::string extensions = (char *)MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS));
const std::string extensions = reinterpret_cast<const char *>(MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS)));
{
using namespace mbgl;
if (extensions.find("GL_KHR_debug") != std::string::npos) {
gl::DebugMessageControl = (gl::PFNGLDEBUGMESSAGECONTROLPROC)glfwGetProcAddress("glDebugMessageControl");
gl::DebugMessageInsert = (gl::PFNGLDEBUGMESSAGEINSERTPROC)glfwGetProcAddress("glDebugMessageInsert");
gl::DebugMessageCallback = (gl::PFNGLDEBUGMESSAGECALLBACKPROC)glfwGetProcAddress("glDebugMessageCallback");
gl::GetDebugMessageLog = (gl::PFNGLGETDEBUGMESSAGELOGPROC)glfwGetProcAddress("glGetDebugMessageLog");
gl::GetPointerv = (gl::PFNGLGETPOINTERVPROC)glfwGetProcAddress("glGetPointerv");
gl::PushDebugGroup = (gl::PFNGLPUSHDEBUGGROUPPROC)glfwGetProcAddress("glPushDebugGroup");
gl::PopDebugGroup = (gl::PFNGLPOPDEBUGGROUPPROC)glfwGetProcAddress("glPopDebugGroup");
gl::ObjectLabel = (gl::PFNGLOBJECTLABELPROC)glfwGetProcAddress("glObjectLabel");
gl::GetObjectLabel = (gl::PFNGLGETOBJECTLABELPROC)glfwGetProcAddress("glGetObjectLabel");
gl::ObjectPtrLabel = (gl::PFNGLOBJECTPTRLABELPROC)glfwGetProcAddress("glObjectPtrLabel");
gl::GetObjectPtrLabel = (gl::PFNGLGETOBJECTPTRLABELPROC)glfwGetProcAddress("glGetObjectPtrLabel");
gl::DebugMessageControl = reinterpret_cast<gl::PFNGLDEBUGMESSAGECONTROLPROC>(glfwGetProcAddress("glDebugMessageControl"));
gl::DebugMessageInsert = reinterpret_cast<gl::PFNGLDEBUGMESSAGEINSERTPROC>(glfwGetProcAddress("glDebugMessageInsert"));
gl::DebugMessageCallback = reinterpret_cast<gl::PFNGLDEBUGMESSAGECALLBACKPROC>(glfwGetProcAddress("glDebugMessageCallback"));
gl::GetDebugMessageLog = reinterpret_cast<gl::PFNGLGETDEBUGMESSAGELOGPROC>(glfwGetProcAddress("glGetDebugMessageLog"));
gl::GetPointerv = reinterpret_cast<gl::PFNGLGETPOINTERVPROC>(glfwGetProcAddress("glGetPointerv"));
gl::PushDebugGroup = reinterpret_cast<gl::PFNGLPUSHDEBUGGROUPPROC>(glfwGetProcAddress("glPushDebugGroup"));
gl::PopDebugGroup = reinterpret_cast<gl::PFNGLPOPDEBUGGROUPPROC>(glfwGetProcAddress("glPopDebugGroup"));
gl::ObjectLabel = reinterpret_cast<gl::PFNGLOBJECTLABELPROC>(glfwGetProcAddress("glObjectLabel"));
gl::GetObjectLabel = reinterpret_cast<gl::PFNGLGETOBJECTLABELPROC>(glfwGetProcAddress("glGetObjectLabel"));
gl::ObjectPtrLabel = reinterpret_cast<gl::PFNGLOBJECTPTRLABELPROC>(glfwGetProcAddress("glObjectPtrLabel"));
gl::GetObjectPtrLabel = reinterpret_cast<gl::PFNGLGETOBJECTPTRLABELPROC>(glfwGetProcAddress("glGetObjectPtrLabel"));
assert(gl::DebugMessageControl != nullptr);
assert(gl::DebugMessageInsert != nullptr);
assert(gl::DebugMessageCallback != nullptr);
@@ -102,11 +102,11 @@ void GLFWView::initialize(mbgl::Map *map_) {
assert(gl::GetObjectPtrLabel != nullptr);
} else {
if (extensions.find("GL_ARB_debug_output") != std::string::npos) {
gl::DebugMessageControl = (gl::PFNGLDEBUGMESSAGECONTROLPROC)glfwGetProcAddress("glDebugMessageControlARB");
gl::DebugMessageInsert = (gl::PFNGLDEBUGMESSAGEINSERTPROC)glfwGetProcAddress("glDebugMessageInsertARB");
gl::DebugMessageCallback = (gl::PFNGLDEBUGMESSAGECALLBACKPROC)glfwGetProcAddress("glDebugMessageCallbackARB");
gl::GetDebugMessageLog = (gl::PFNGLGETDEBUGMESSAGELOGPROC)glfwGetProcAddress("glGetDebugMessageLogARB");
gl::GetPointerv = (gl::PFNGLGETPOINTERVPROC)glfwGetProcAddress("glGetPointerv");
gl::DebugMessageControl = reinterpret_cast<gl::PFNGLDEBUGMESSAGECONTROLPROC>(glfwGetProcAddress("glDebugMessageControlARB"));
gl::DebugMessageInsert = reinterpret_cast<gl::PFNGLDEBUGMESSAGEINSERTPROC>(glfwGetProcAddress("glDebugMessageInsertARB"));
gl::DebugMessageCallback = reinterpret_cast<gl::PFNGLDEBUGMESSAGECALLBACKPROC>(glfwGetProcAddress("glDebugMessageCallbackARB"));
gl::GetDebugMessageLog = reinterpret_cast<gl::PFNGLGETDEBUGMESSAGELOGPROC>(glfwGetProcAddress("glGetDebugMessageLogARB"));
gl::GetPointerv = reinterpret_cast<gl::PFNGLGETPOINTERVPROC>(glfwGetProcAddress("glGetPointerv"));
assert(gl::DebugMessageControl != nullptr);
assert(gl::DebugMessageInsert != nullptr);
assert(gl::DebugMessageCallback != nullptr);
@@ -115,36 +115,36 @@ void GLFWView::initialize(mbgl::Map *map_) {
}
if (extensions.find("GL_EXT_debug_marker") != std::string::npos) {
gl::InsertEventMarkerEXT = (gl::PFNGLINSERTEVENTMARKEREXTPROC)glfwGetProcAddress("glInsertEventMarkerEXT");
gl::PushGroupMarkerEXT = (gl::PFNGLPUSHGROUPMARKEREXTPROC)glfwGetProcAddress("glPushGroupMarkerEXT");
gl::PopGroupMarkerEXT = (gl::PFNGLPOPGROUPMARKEREXTPROC)glfwGetProcAddress("glPopGroupMarkerEXT");
gl::InsertEventMarkerEXT = reinterpret_cast<gl::PFNGLINSERTEVENTMARKEREXTPROC>(glfwGetProcAddress("glInsertEventMarkerEXT"));
gl::PushGroupMarkerEXT = reinterpret_cast<gl::PFNGLPUSHGROUPMARKEREXTPROC>(glfwGetProcAddress("glPushGroupMarkerEXT"));
gl::PopGroupMarkerEXT = reinterpret_cast<gl::PFNGLPOPGROUPMARKEREXTPROC>(glfwGetProcAddress("glPopGroupMarkerEXT"));
assert(gl::InsertEventMarkerEXT != nullptr);
assert(gl::PushGroupMarkerEXT != nullptr);
assert(gl::PopGroupMarkerEXT != nullptr);
}
if (extensions.find("GL_EXT_debug_label") != std::string::npos) {
gl::LabelObjectEXT = (gl::PFNGLLABELOBJECTEXTPROC)glfwGetProcAddress("glLabelObjectEXT");
gl::GetObjectLabelEXT = (gl::PFNGLGETOBJECTLABELEXTPROC)glfwGetProcAddress("glGetObjectLabelEXT");
gl::LabelObjectEXT = reinterpret_cast<gl::PFNGLLABELOBJECTEXTPROC>(glfwGetProcAddress("glLabelObjectEXT"));
gl::GetObjectLabelEXT = reinterpret_cast<gl::PFNGLGETOBJECTLABELEXTPROC>(glfwGetProcAddress("glGetObjectLabelEXT"));
assert(gl::LabelObjectEXT != nullptr);
assert(gl::GetObjectLabelEXT != nullptr);
}
}
if (extensions.find("GL_ARB_vertex_array_object") != std::string::npos) {
gl::BindVertexArray = (gl::PFNGLBINDVERTEXARRAYPROC)glfwGetProcAddress("glBindVertexArray");
gl::DeleteVertexArrays = (gl::PFNGLDELETEVERTEXARRAYSPROC)glfwGetProcAddress("glDeleteVertexArrays");
gl::GenVertexArrays = (gl::PFNGLGENVERTEXARRAYSPROC)glfwGetProcAddress("glGenVertexArrays");
gl::IsVertexArray = (gl::PFNGLISVERTEXARRAYPROC)glfwGetProcAddress("glIsVertexArray");
gl::BindVertexArray = reinterpret_cast<gl::PFNGLBINDVERTEXARRAYPROC>(glfwGetProcAddress("glBindVertexArray"));
gl::DeleteVertexArrays = reinterpret_cast<gl::PFNGLDELETEVERTEXARRAYSPROC>(glfwGetProcAddress("glDeleteVertexArrays"));
gl::GenVertexArrays = reinterpret_cast<gl::PFNGLGENVERTEXARRAYSPROC>(glfwGetProcAddress("glGenVertexArrays"));
gl::IsVertexArray = reinterpret_cast<gl::PFNGLISVERTEXARRAYPROC>(glfwGetProcAddress("glIsVertexArray"));
assert(gl::BindVertexArray != nullptr);
assert(gl::DeleteVertexArrays != nullptr);
assert(gl::GenVertexArrays != nullptr);
assert(gl::IsVertexArray != nullptr);
} 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");
gl::BindVertexArray = reinterpret_cast<gl::PFNGLBINDVERTEXARRAYPROC>(glfwGetProcAddress("glBindVertexArrayAPPLE"));
gl::DeleteVertexArrays = reinterpret_cast<gl::PFNGLDELETEVERTEXARRAYSPROC>(glfwGetProcAddress("glDeleteVertexArraysAPPLE"));
gl::GenVertexArrays = reinterpret_cast<gl::PFNGLGENVERTEXARRAYSPROC>(glfwGetProcAddress("glGenVertexArraysAPPLE"));
gl::IsVertexArray = reinterpret_cast<gl::PFNGLISVERTEXARRAYPROC>(glfwGetProcAddress("glIsVertexArrayAPPLE"));
assert(gl::BindVertexArray != nullptr);
assert(gl::DeleteVertexArrays != nullptr);
assert(gl::GenVertexArrays != nullptr);
@@ -155,9 +155,9 @@ void GLFWView::initialize(mbgl::Map *map_) {
GLint numBinaryFormats;
MBGL_CHECK_ERROR(glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &numBinaryFormats));
if (numBinaryFormats > 0) {
gl::GetProgramBinary = (gl::PFNGLGETPROGRAMBINARYPROC)glfwGetProcAddress("glGetProgramBinary");
gl::ProgramBinary = (gl::PFNGLPROGRAMBINARYPROC)glfwGetProcAddress("glProgramBinary");
gl::ProgramParameteri = (gl::PFNGLPROGRAMPARAMETERIPROC)glfwGetProcAddress("glProgramParameteri");
gl::GetProgramBinary = reinterpret_cast<gl::PFNGLGETPROGRAMBINARYPROC>(glfwGetProcAddress("glGetProgramBinary"));
gl::ProgramBinary = reinterpret_cast<gl::PFNGLPROGRAMBINARYPROC>(glfwGetProcAddress("glProgramBinary"));
gl::ProgramParameteri = reinterpret_cast<gl::PFNGLPROGRAMPARAMETERIPROC>(glfwGetProcAddress("glProgramParameteri"));
assert(gl::GetProgramBinary != nullptr);
assert(gl::ProgramBinary != nullptr);
assert(gl::ProgramParameteri != nullptr);
@@ -169,7 +169,7 @@ void GLFWView::initialize(mbgl::Map *map_) {
}
void GLFWView::key(GLFWwindow *window, int key, int /*scancode*/, int action, int mods) {
GLFWView *view = (GLFWView *)glfwGetWindowUserPointer(window);
GLFWView *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window));
if (action == GLFW_RELEASE) {
switch (key) {
@@ -197,17 +197,17 @@ void GLFWView::key(GLFWwindow *window, int key, int /*scancode*/, int action, in
}
}
void GLFWView::scroll(GLFWwindow *window, double /*xoffset*/, double yoffset) {
GLFWView *view = (GLFWView *)glfwGetWindowUserPointer(window);
double delta = yoffset * 40;
void GLFWView::scroll(GLFWwindow *window, double /*xOffset*/, double yOffset) {
GLFWView *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window));
double delta = yOffset * 40;
bool is_wheel = delta != 0 && std::fmod(delta, 4.000244140625) == 0;
bool isWheel = delta != 0 && std::fmod(delta, 4.000244140625) == 0;
double absdelta = delta < 0 ? -delta : delta;
double scale = 2.0 / (1.0 + std::exp(-absdelta / 100.0));
double absDelta = delta < 0 ? -delta : delta;
double scale = 2.0 / (1.0 + std::exp(-absDelta / 100.0));
// Make the scroll wheel a bit slower.
if (!is_wheel) {
if (!isWheel) {
scale = (scale - 1.0) / 2.0 + 1.0;
}
@@ -217,22 +217,20 @@ void GLFWView::scroll(GLFWwindow *window, double /*xoffset*/, double yoffset) {
}
view->map->startScaling();
view->map->scaleBy(scale, view->last_x, view->last_y);
view->map->scaleBy(scale, view->lastX, view->lastY);
}
void GLFWView::resize(GLFWwindow *window, int, int) {
GLFWView *view = (GLFWView *)glfwGetWindowUserPointer(window);
void GLFWView::resize(GLFWwindow *window, int width, int height ) {
GLFWView *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window));
int width, height;
glfwGetWindowSize(window, &width, &height);
int fb_width, fb_height;
glfwGetFramebufferSize(window, &fb_width, &fb_height);
int fbWidth, fbHeight;
glfwGetFramebufferSize(window, &fbWidth, &fbHeight);
view->map->resize(width, height, (float)fb_width / (float)width, fb_width, fb_height);
view->map->resize(width, height, static_cast<float>(fbWidth) / static_cast<float>(width), fbWidth, fbHeight);
}
void GLFWView::mouseclick(GLFWwindow *window, int button, int action, int modifiers) {
GLFWView *view = (GLFWView *)glfwGetWindowUserPointer(window);
void GLFWView::mouseClick(GLFWwindow *window, int button, int action, int modifiers) {
GLFWView *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window));
if (button == GLFW_MOUSE_BUTTON_RIGHT ||
(button == GLFW_MOUSE_BUTTON_LEFT && modifiers & GLFW_MOD_CONTROL)) {
@@ -246,33 +244,33 @@ void GLFWView::mouseclick(GLFWwindow *window, int button, int action, int modifi
if (action == GLFW_RELEASE) {
view->map->stopPanning();
double now = glfwGetTime();
if (now - view->last_click < 0.4 /* ms */) {
if (now - view->lastClick < 0.4 /* ms */) {
if (modifiers & GLFW_MOD_SHIFT) {
view->map->scaleBy(0.5, view->last_x, view->last_y, 0.5);
view->map->scaleBy(0.5, view->lastX, view->lastY, 0.5);
} else {
view->map->scaleBy(2.0, view->last_x, view->last_y, 0.5);
view->map->scaleBy(2.0, view->lastX, view->lastY, 0.5);
}
}
view->last_click = now;
view->lastClick = now;
}
}
}
void GLFWView::mousemove(GLFWwindow *window, double x, double y) {
GLFWView *view = (GLFWView *)glfwGetWindowUserPointer(window);
void GLFWView::mouseMove(GLFWwindow *window, double x, double y) {
GLFWView *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window));
if (view->tracking) {
double dx = x - view->last_x;
double dy = y - view->last_y;
double dx = x - view->lastX;
double dy = y - view->lastY;
if (dx || dy) {
view->map->startPanning();
view->map->moveBy(dx, dy);
}
} else if (view->rotating) {
view->map->startRotating();
view->map->rotateBy(view->last_x, view->last_y, x, y);
view->map->rotateBy(view->lastX, view->lastY, x, y);
}
view->last_x = x;
view->last_y = y;
view->lastX = x;
view->lastY = y;
}
int GLFWView::run() {
@@ -295,11 +293,11 @@ int GLFWView::run() {
return 0;
}
void GLFWView::make_active() {
void GLFWView::activate() {
glfwMakeContextCurrent(window);
}
void GLFWView::make_inactive() {
void GLFWView::deactivate() {
glfwMakeContextCurrent(nullptr);
}
@@ -311,20 +309,20 @@ void GLFWView::swap() {
glfwPostEmptyEvent();
}
void GLFWView::notify_map_change(mbgl::MapChange /*change*/, mbgl::timestamp /*delay*/) {
void GLFWView::notifyMapChange(mbgl::MapChange /*change*/, mbgl::timestamp /*delay*/) {
// no-op
}
void GLFWView::fps() {
static int frames = 0;
static double time_elapsed = 0;
static double timeElapsed = 0;
frames++;
double current_time = glfwGetTime();
double currentTime = glfwGetTime();
if (current_time - time_elapsed >= 1) {
fprintf(stderr, "FPS: %4.2f\n", frames / (current_time - time_elapsed));
time_elapsed = current_time;
if (currentTime - timeElapsed >= 1) {
fprintf(stderr, "FPS: %4.2f\n", frames / (currentTime - timeElapsed));
timeElapsed = currentTime;
frames = 0;
}
}
@@ -335,70 +333,70 @@ namespace platform {
double elapsed() { return glfwGetTime(); }
#ifndef GL_ES_VERSION_2_0
void show_debug_image(std::string name, const char *data, size_t width, size_t height) {
void showDebugImage(std::string name, const char *data, size_t width, size_t height) {
glfwInit();
static GLFWwindow *debug_window = nullptr;
if (!debug_window) {
debug_window = glfwCreateWindow(width, height, name.c_str(), nullptr, nullptr);
if (!debug_window) {
static GLFWwindow *debugWindow = nullptr;
if (!debugWindow) {
debugWindow = glfwCreateWindow(width, height, name.c_str(), nullptr, nullptr);
if (!debugWindow) {
glfwTerminate();
fprintf(stderr, "Failed to initialize window\n");
exit(1);
}
}
GLFWwindow *current_window = glfwGetCurrentContext();
GLFWwindow *currentWindow = glfwGetCurrentContext();
glfwSetWindowSize(debug_window, width, height);
glfwMakeContextCurrent(debug_window);
glfwSetWindowSize(debugWindow, width, height);
glfwMakeContextCurrent(debugWindow);
int fb_width, fb_height;
glfwGetFramebufferSize(debug_window, &fb_width, &fb_height);
float scale = (float)fb_width / (float)width;
int fbWidth, fbHeight;
glfwGetFramebufferSize(debugWindow, &fbWidth, &fbHeight);
float scale = static_cast<float>(fbWidth) / static_cast<float>(width);
MBGL_CHECK_ERROR(glPixelZoom(scale, -scale));
MBGL_CHECK_ERROR(glRasterPos2f(-1.0f, 1.0f));
MBGL_CHECK_ERROR(glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, data));
glfwSwapBuffers(debug_window);
glfwSwapBuffers(debugWindow);
glfwMakeContextCurrent(current_window);
glfwMakeContextCurrent(currentWindow);
}
void show_color_debug_image(std::string name, const char *data, size_t logical_width, size_t logical_height, size_t width, size_t height) {
void showColorDebugImage(std::string name, const char *data, size_t logicalWidth, size_t logicalHeight, size_t width, size_t height) {
glfwInit();
static GLFWwindow *debug_window = nullptr;
if (!debug_window) {
debug_window = glfwCreateWindow(logical_width, logical_height, name.c_str(), nullptr, nullptr);
if (!debug_window) {
static GLFWwindow *debugWindow = nullptr;
if (!debugWindow) {
debugWindow = glfwCreateWindow(logicalWidth, logicalHeight, name.c_str(), nullptr, nullptr);
if (!debugWindow) {
glfwTerminate();
fprintf(stderr, "Failed to initialize window\n");
exit(1);
}
}
GLFWwindow *current_window = glfwGetCurrentContext();
GLFWwindow *currentWindow = glfwGetCurrentContext();
glfwSetWindowSize(debug_window, logical_width, logical_height);
glfwMakeContextCurrent(debug_window);
glfwSetWindowSize(debugWindow, logicalWidth, logicalHeight);
glfwMakeContextCurrent(debugWindow);
int fb_width, fb_height;
glfwGetFramebufferSize(debug_window, &fb_width, &fb_height);
float x_scale = (float)fb_width / (float)width;
float y_scale = (float)fb_height / (float)height;
int fbWidth, fbHeight;
glfwGetFramebufferSize(debugWindow, &fbWidth, &fbHeight);
float xScale = static_cast<float>(fbWidth) / static_cast<float>(width);
float yScale = static_cast<float>(fbHeight) / static_cast<float>(height);
MBGL_CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT));
MBGL_CHECK_ERROR(glEnable(GL_BLEND));
MBGL_CHECK_ERROR(glBlendFunc(GL_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
MBGL_CHECK_ERROR(glPixelZoom(x_scale, -y_scale));
MBGL_CHECK_ERROR(glPixelZoom(xScale, -yScale));
MBGL_CHECK_ERROR(glRasterPos2f(-1.0f, 1.0f));
MBGL_CHECK_ERROR(glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, data));
glfwSwapBuffers(debug_window);
glfwSwapBuffers(debugWindow);
glfwMakeContextCurrent(current_window);
glfwMakeContextCurrent(currentWindow);
}
#endif

View File

@@ -11,9 +11,9 @@ HeadlessDisplay::HeadlessDisplay() {
// If it is, use kCGLOGLPVersion_3_2_Core and enable that extension.
CGLPixelFormatAttribute attributes[] = {
kCGLPFAOpenGLProfile,
(CGLPixelFormatAttribute) kCGLOGLPVersion_Legacy,
static_cast<CGLPixelFormatAttribute>(kCGLOGLPVersion_Legacy),
kCGLPFAAccelerated,
(CGLPixelFormatAttribute) 0
static_cast<CGLPixelFormatAttribute>(0)
};
GLint num;
@@ -38,7 +38,7 @@ HeadlessDisplay::HeadlessDisplay() {
throw std::runtime_error("Failed to open X display.");
}
const char *extensions = (char *)glXQueryServerString(xDisplay, DefaultScreen(xDisplay), GLX_EXTENSIONS);
const char *extensions = reinterpret_cast<const char *>(glXQueryServerString(xDisplay, DefaultScreen(xDisplay), GLX_EXTENSIONS));
if (!extensions) {
throw std::runtime_error("Cannot read GLX extensions.");
}

View File

@@ -24,7 +24,7 @@ CGLProc CGLGetProcAddress(const char *proc) {
}
CFStringRef name = CFStringCreateWithCString(kCFAllocatorDefault, proc, kCFStringEncodingASCII);
CGLProc symbol = (CGLProc)CFBundleGetFunctionPointerForName(framework, name);
CGLProc symbol = reinterpret_cast<CGLProc>(CFBundleGetFunctionPointerForName(framework, name));
CFRelease(name);
return symbol;
}
@@ -46,18 +46,18 @@ HeadlessView::HeadlessView(std::shared_ptr<HeadlessDisplay> display)
}
void HeadlessView::loadExtensions() {
make_active();
const char *extension_ptr = (char *)MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS));
activate();
const char *extension_ptr = reinterpret_cast<const char *>(MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS)));
if (extension_ptr) {
const std::string extensions = extension_ptr;
#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");
gl::BindVertexArray = reinterpret_cast<gl::PFNGLBINDVERTEXARRAYPROC>(CGLGetProcAddress("glBindVertexArrayAPPLE"));
gl::DeleteVertexArrays = reinterpret_cast<gl::PFNGLDELETEVERTEXARRAYSPROC>(CGLGetProcAddress("glDeleteVertexArraysAPPLE"));
gl::GenVertexArrays = reinterpret_cast<gl::PFNGLGENVERTEXARRAYSPROC>(CGLGetProcAddress("glGenVertexArraysAPPLE"));
gl::IsVertexArray = reinterpret_cast<gl::PFNGLISVERTEXARRAYPROC>(CGLGetProcAddress("glIsVertexArrayAPPLE"));
assert(gl::BindVertexArray != nullptr);
assert(gl::DeleteVertexArrays != nullptr);
assert(gl::GenVertexArrays != nullptr);
@@ -66,10 +66,10 @@ void HeadlessView::loadExtensions() {
#endif
#ifdef MBGL_USE_GLX
if (extensions.find("GL_ARB_vertex_array_object") != std::string::npos) {
gl::BindVertexArray = (gl::PFNGLBINDVERTEXARRAYPROC)glXGetProcAddress((const GLubyte *)"glBindVertexArray");
gl::DeleteVertexArrays = (gl::PFNGLDELETEVERTEXARRAYSPROC)glXGetProcAddress((const GLubyte *)"glDeleteVertexArrays");
gl::GenVertexArrays = (gl::PFNGLGENVERTEXARRAYSPROC)glXGetProcAddress((const GLubyte *)"glGenVertexArrays");
gl::IsVertexArray = (gl::PFNGLISVERTEXARRAYPROC)glXGetProcAddress((const GLubyte *)"glIsVertexArray");
gl::BindVertexArray = reinterpret_cast<gl::PFNGLBINDVERTEXARRAYPROC>(glXGetProcAddress((const GLubyte *)"glBindVertexArray"));
gl::DeleteVertexArrays = reinterpret_cast<gl::PFNGLDELETEVERTEXARRAYSPROC>(glXGetProcAddress((const GLubyte *)"glDeleteVertexArrays"));
gl::GenVertexArrays = reinterpret_cast<gl::PFNGLGENVERTEXARRAYSPROC>(glXGetProcAddress((const GLubyte *)"glGenVertexArrays"));
gl::IsVertexArray = reinterpret_cast<gl::PFNGLISVERTEXARRAYPROC>(glXGetProcAddress((const GLubyte *)"glIsVertexArray"));
assert(gl::BindVertexArray != nullptr);
assert(gl::DeleteVertexArrays != nullptr);
assert(gl::GenVertexArrays != nullptr);
@@ -78,7 +78,7 @@ void HeadlessView::loadExtensions() {
#endif
}
make_inactive();
deactivate();
}
void HeadlessView::createContext() {
@@ -126,7 +126,7 @@ void HeadlessView::createContext() {
}
void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) {
clear_buffers();
clearBuffers();
width_ = width;
height_ = height;
@@ -135,7 +135,7 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) {
const unsigned int w = width_ * pixelRatio_;
const unsigned int h = height_ * pixelRatio_;
make_active();
activate();
// Create depth/stencil buffer
MBGL_CHECK_ERROR(glGenRenderbuffersEXT(1, &fboDepthStencil));
@@ -171,7 +171,7 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) {
throw std::runtime_error(error.str());
}
make_inactive();
deactivate();
}
std::unique_ptr<uint32_t[]> HeadlessView::readPixels() {
@@ -180,9 +180,9 @@ std::unique_ptr<uint32_t[]> HeadlessView::readPixels() {
auto pixels = util::make_unique<uint32_t[]>(w * h);
make_active();
activate();
MBGL_CHECK_ERROR(glReadPixels(0, 0, width_, height_, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()));
make_inactive();
deactivate();
const int stride = w * 4;
auto tmp = util::make_unique<char[]>(stride);
@@ -196,8 +196,8 @@ std::unique_ptr<uint32_t[]> HeadlessView::readPixels() {
return pixels;
}
void HeadlessView::clear_buffers() {
make_active();
void HeadlessView::clearBuffers() {
activate();
MBGL_CHECK_ERROR(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
@@ -216,11 +216,11 @@ void HeadlessView::clear_buffers() {
fboDepthStencil = 0;
}
make_inactive();
deactivate();
}
HeadlessView::~HeadlessView() {
clear_buffers();
clearBuffers();
#if MBGL_USE_CGL
CGLDestroyContext(glContext);
@@ -240,11 +240,11 @@ void HeadlessView::notify() {
// no-op
}
void HeadlessView::notify_map_change(mbgl::MapChange /*change*/, mbgl::timestamp /*delay*/) {
void HeadlessView::notifyMapChange(mbgl::MapChange /*change*/, mbgl::timestamp /*delay*/) {
// no-op
}
void HeadlessView::make_active() {
void HeadlessView::activate() {
#if MBGL_USE_CGL
CGLError error = CGLSetCurrentContext(glContext);
if (error != kCGLNoError) {
@@ -259,7 +259,7 @@ void HeadlessView::make_active() {
#endif
}
void HeadlessView::make_inactive() {
void HeadlessView::deactivate() {
#if MBGL_USE_CGL
CGLError error = CGLSetCurrentContext(nullptr);
if (error != kCGLNoError) {

View File

@@ -33,7 +33,7 @@
#include <uv.h>
// Check libuv library version.
const static bool uv_version_check = []() {
const static bool uvVersionCheck = []() {
const unsigned int version = uv_version();
const unsigned int major = (version >> 16) & 0xFF;
const unsigned int minor = (version >> 8) & 0xFF;
@@ -55,7 +55,7 @@ const static bool uv_version_check = []() {
#include <zlib.h>
// Check zlib library version.
const static bool zlib_version_check = []() {
const static bool zlibVersionCheck = []() {
const char *const version = zlibVersion();
if (version[0] != ZLIB_VERSION[0]) {
throw std::runtime_error(mbgl::util::sprintf<96>(
@@ -68,7 +68,7 @@ const static bool zlib_version_check = []() {
#include <sqlite3.h>
// Check sqlite3 library version.
const static bool sqlite_version_check = []() {
const static bool sqliteVersionCheck = []() {
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",
@@ -287,9 +287,9 @@ void Map::terminate() {
void Map::setup() {
assert(std::this_thread::get_id() == mapThread);
assert(painter);
view.make_active();
view.activate();
painter->setup();
view.make_inactive();
view.deactivate();
}
void Map::setStyleURL(const std::string &url) {
@@ -613,7 +613,7 @@ void Map::prepare() {
}
void Map::render() {
view.make_active();
view.activate();
assert(painter);
painter->render(*style, activeSources,
@@ -623,5 +623,5 @@ void Map::render() {
update();
}
view.make_inactive();
view.deactivate();
}

View File

@@ -29,7 +29,7 @@ bool Transform::resize(const uint16_t w, const uint16_t h, const float ratio,
if (final.width != w || final.height != h || final.pixelRatio != ratio ||
final.framebuffer[0] != fb_w || final.framebuffer[1] != fb_h) {
view.notify_map_change(MapChangeRegionWillChange);
view.notifyMapChange(MapChangeRegionWillChange);
current.width = final.width = w;
current.height = final.height = h;
@@ -38,7 +38,7 @@ bool Transform::resize(const uint16_t w, const uint16_t h, const float ratio,
current.framebuffer[1] = final.framebuffer[1] = fb_h;
constrain(current.scale, current.y);
view.notify_map_change(MapChangeRegionDidChange);
view.notifyMapChange(MapChangeRegionDidChange);
return true;
} else {
@@ -57,7 +57,7 @@ void Transform::moveBy(const double dx, const double dy, const timestamp duratio
void Transform::_moveBy(const double dx, const double dy, const timestamp duration) {
// This is only called internally, so we don't need a lock here.
view.notify_map_change(duration ?
view.notifyMapChange(duration ?
MapChangeRegionWillChangeAnimated :
MapChangeRegionWillChange);
@@ -78,7 +78,7 @@ void Transform::_moveBy(const double dx, const double dy, const timestamp durati
std::make_shared<util::ease_transition<double>>(current.y, final.y, current.y, start, duration));
}
view.notify_map_change(duration ?
view.notifyMapChange(duration ?
MapChangeRegionDidChangeAnimated :
MapChangeRegionDidChange,
duration);
@@ -268,7 +268,7 @@ void Transform::_setScaleXY(const double new_scale, const double xn, const doubl
const timestamp duration) {
// This is only called internally, so we don't need a lock here.
view.notify_map_change(duration ?
view.notifyMapChange(duration ?
MapChangeRegionWillChangeAnimated :
MapChangeRegionWillChange);
@@ -297,7 +297,7 @@ void Transform::_setScaleXY(const double new_scale, const double xn, const doubl
Bc = s / 360;
Cc = s / (2 * M_PI);
view.notify_map_change(duration ?
view.notifyMapChange(duration ?
MapChangeRegionDidChangeAnimated :
MapChangeRegionDidChange,
duration);
@@ -376,7 +376,7 @@ void Transform::setAngle(const double new_angle, const double cx, const double c
void Transform::_setAngle(double new_angle, const timestamp duration) {
// This is only called internally, so we don't need a lock here.
view.notify_map_change(duration ?
view.notifyMapChange(duration ?
MapChangeRegionWillChangeAnimated :
MapChangeRegionWillChange);
@@ -395,7 +395,7 @@ void Transform::_setAngle(double new_angle, const timestamp duration) {
current.angle, final.angle, current.angle, start, duration));
}
view.notify_map_change(duration ?
view.notifyMapChange(duration ?
MapChangeRegionDidChangeAnimated :
MapChangeRegionDidChange,
duration);