From 08084854531065d6cc52115f9822c26d6ec7924f Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Wed, 10 Dec 2014 21:32:11 +1100 Subject: Use CHECK_ERROR on every GL call --- platform/default/glfw_view.cpp | 28 ++++++++++++++++++---------- platform/default/headless_view.cpp | 38 +++++++++++++++++++------------------- 2 files changed, 37 insertions(+), 29 deletions(-) (limited to 'platform') diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp index 7cfb132133..701ce2023d 100644 --- a/platform/default/glfw_view.cpp +++ b/platform/default/glfw_view.cpp @@ -1,5 +1,6 @@ #include #include +#include GLFWView::GLFWView(bool fullscreen_) : fullscreen(fullscreen_) { #ifdef NVIDIA @@ -11,9 +12,16 @@ GLFWView::~GLFWView() { glfwTerminate(); } +void glfwError(int error, const char *description) { + mbgl::Log::Error(mbgl::Event::OpenGL, "GLFW error (%i): %s", error, description); + assert(false); +} + void GLFWView::initialize(mbgl::Map *map_) { View::initialize(map_); + glfwSetErrorCallback(glfwError); + if (!glfwInit()) { fprintf(stderr, "Failed to initialize glfw\n"); exit(1); @@ -65,7 +73,7 @@ void GLFWView::initialize(mbgl::Map *map_) { glfwSetScrollCallback(window, scroll); glfwSetKeyCallback(window, key); - const std::string extensions = (char *)glGetString(GL_EXTENSIONS); + const std::string extensions = (char *)CHECK_ERROR(glGetString(GL_EXTENSIONS)); { using namespace mbgl; @@ -345,9 +353,9 @@ void show_debug_image(std::string name, const char *data, size_t width, size_t h glfwGetFramebufferSize(debug_window, &fb_width, &fb_height); float scale = (float)fb_width / (float)width; - glPixelZoom(scale, -scale); - glRasterPos2f(-1.0f, 1.0f); - glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, data); + CHECK_ERROR(glPixelZoom(scale, -scale)); + CHECK_ERROR(glRasterPos2f(-1.0f, 1.0f)); + CHECK_ERROR(glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, data)); glfwSwapBuffers(debug_window); glfwMakeContextCurrent(current_window); @@ -377,13 +385,13 @@ void show_color_debug_image(std::string name, const char *data, size_t logical_w float x_scale = (float)fb_width / (float)width; float y_scale = (float)fb_height / (float)height; - glClear(GL_COLOR_BUFFER_BIT); - glEnable(GL_BLEND); - glBlendFunc(GL_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT)); + CHECK_ERROR(glEnable(GL_BLEND)); + CHECK_ERROR(glBlendFunc(GL_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); - glPixelZoom(x_scale, -y_scale); - glRasterPos2f(-1.0f, 1.0f); - glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, data); + CHECK_ERROR(glPixelZoom(x_scale, -y_scale)); + CHECK_ERROR(glRasterPos2f(-1.0f, 1.0f)); + CHECK_ERROR(glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, data)); glfwSwapBuffers(debug_window); glfwMakeContextCurrent(current_window); diff --git a/platform/default/headless_view.cpp b/platform/default/headless_view.cpp index d414c3f450..e3273a0972 100644 --- a/platform/default/headless_view.cpp +++ b/platform/default/headless_view.cpp @@ -52,7 +52,7 @@ HeadlessView::HeadlessView(std::shared_ptr display) void HeadlessView::loadExtensions() { make_active(); - const std::string extensions = (char *)glGetString(GL_EXTENSIONS); + const std::string extensions = (char *)CHECK_ERROR(glGetString(GL_EXTENSIONS)); #ifdef MBGL_USE_CGL if (extensions.find("GL_APPLE_vertex_array_object") != std::string::npos) { @@ -204,23 +204,23 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { make_active(); // Create depth/stencil buffer - glGenRenderbuffersEXT(1, &fboDepthStencil); - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fboDepthStencil); - glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, w, h); - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); + CHECK_ERROR(glGenRenderbuffersEXT(1, &fboDepthStencil)); + CHECK_ERROR(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fboDepthStencil)); + CHECK_ERROR(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, w, h)); + CHECK_ERROR(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0)); - glGenRenderbuffersEXT(1, &fboColor); - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fboColor); - glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, w, h); - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); + CHECK_ERROR(glGenRenderbuffersEXT(1, &fboColor)); + CHECK_ERROR(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fboColor)); + CHECK_ERROR(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, w, h)); + CHECK_ERROR(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0)); - glGenFramebuffersEXT(1, &fbo); - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); + CHECK_ERROR(glGenFramebuffersEXT(1, &fbo)); + CHECK_ERROR(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo)); - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, fboColor); - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER_EXT, fboDepthStencil); + CHECK_ERROR(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, fboColor)); + CHECK_ERROR(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER_EXT, fboDepthStencil)); - GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + GLenum status = CHECK_ERROR(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { std::stringstream error("Couldn't create framebuffer: "); @@ -247,7 +247,7 @@ std::unique_ptr HeadlessView::readPixels() { auto pixels = util::make_unique(w * h); make_active(); - glReadPixels(0, 0, width_, height_, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get()); + CHECK_ERROR(glReadPixels(0, 0, width_, height_, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get())); make_inactive(); const int stride = w * 4; @@ -265,20 +265,20 @@ std::unique_ptr HeadlessView::readPixels() { void HeadlessView::clear_buffers() { make_active(); - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + CHECK_ERROR(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0)); if (fbo) { - glDeleteFramebuffersEXT(1, &fbo); + CHECK_ERROR(glDeleteFramebuffersEXT(1, &fbo)); fbo = 0; } if (fboColor) { - glDeleteTextures(1, &fboColor); + CHECK_ERROR(glDeleteTextures(1, &fboColor)); fboColor = 0; } if (fboDepthStencil) { - glDeleteRenderbuffersEXT(1, &fboDepthStencil); + CHECK_ERROR(glDeleteRenderbuffersEXT(1, &fboDepthStencil)); fboDepthStencil = 0; } -- cgit v1.2.1 From 93d56294cf6f7af39679a871f51087be34f813a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Wed, 10 Dec 2014 13:21:08 +0100 Subject: update error reporting function --- platform/default/glfw_view.cpp | 20 ++++++++++---------- platform/default/headless_view.cpp | 38 +++++++++++++++++++------------------- 2 files changed, 29 insertions(+), 29 deletions(-) (limited to 'platform') diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp index 701ce2023d..e33f8eed15 100644 --- a/platform/default/glfw_view.cpp +++ b/platform/default/glfw_view.cpp @@ -73,7 +73,7 @@ void GLFWView::initialize(mbgl::Map *map_) { glfwSetScrollCallback(window, scroll); glfwSetKeyCallback(window, key); - const std::string extensions = (char *)CHECK_ERROR(glGetString(GL_EXTENSIONS)); + const std::string extensions = (char *)MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS)); { using namespace mbgl; @@ -353,9 +353,9 @@ void show_debug_image(std::string name, const char *data, size_t width, size_t h glfwGetFramebufferSize(debug_window, &fb_width, &fb_height); float scale = (float)fb_width / (float)width; - CHECK_ERROR(glPixelZoom(scale, -scale)); - CHECK_ERROR(glRasterPos2f(-1.0f, 1.0f)); - CHECK_ERROR(glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, data)); + 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); glfwMakeContextCurrent(current_window); @@ -385,13 +385,13 @@ void show_color_debug_image(std::string name, const char *data, size_t logical_w float x_scale = (float)fb_width / (float)width; float y_scale = (float)fb_height / (float)height; - CHECK_ERROR(glClear(GL_COLOR_BUFFER_BIT)); - CHECK_ERROR(glEnable(GL_BLEND)); - CHECK_ERROR(glBlendFunc(GL_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); + 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)); - CHECK_ERROR(glPixelZoom(x_scale, -y_scale)); - CHECK_ERROR(glRasterPos2f(-1.0f, 1.0f)); - CHECK_ERROR(glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, data)); + MBGL_CHECK_ERROR(glPixelZoom(x_scale, -y_scale)); + 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); glfwMakeContextCurrent(current_window); diff --git a/platform/default/headless_view.cpp b/platform/default/headless_view.cpp index e3273a0972..b0fa60fc12 100644 --- a/platform/default/headless_view.cpp +++ b/platform/default/headless_view.cpp @@ -52,7 +52,7 @@ HeadlessView::HeadlessView(std::shared_ptr display) void HeadlessView::loadExtensions() { make_active(); - const std::string extensions = (char *)CHECK_ERROR(glGetString(GL_EXTENSIONS)); + const std::string extensions = (char *)MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS)); #ifdef MBGL_USE_CGL if (extensions.find("GL_APPLE_vertex_array_object") != std::string::npos) { @@ -204,23 +204,23 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) { make_active(); // Create depth/stencil buffer - CHECK_ERROR(glGenRenderbuffersEXT(1, &fboDepthStencil)); - CHECK_ERROR(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fboDepthStencil)); - CHECK_ERROR(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, w, h)); - CHECK_ERROR(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0)); + MBGL_CHECK_ERROR(glGenRenderbuffersEXT(1, &fboDepthStencil)); + MBGL_CHECK_ERROR(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fboDepthStencil)); + MBGL_CHECK_ERROR(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, w, h)); + MBGL_CHECK_ERROR(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0)); - CHECK_ERROR(glGenRenderbuffersEXT(1, &fboColor)); - CHECK_ERROR(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fboColor)); - CHECK_ERROR(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, w, h)); - CHECK_ERROR(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0)); + MBGL_CHECK_ERROR(glGenRenderbuffersEXT(1, &fboColor)); + MBGL_CHECK_ERROR(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fboColor)); + MBGL_CHECK_ERROR(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, w, h)); + MBGL_CHECK_ERROR(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0)); - CHECK_ERROR(glGenFramebuffersEXT(1, &fbo)); - CHECK_ERROR(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo)); + MBGL_CHECK_ERROR(glGenFramebuffersEXT(1, &fbo)); + MBGL_CHECK_ERROR(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo)); - CHECK_ERROR(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, fboColor)); - CHECK_ERROR(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER_EXT, fboDepthStencil)); + MBGL_CHECK_ERROR(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, fboColor)); + MBGL_CHECK_ERROR(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER_EXT, fboDepthStencil)); - GLenum status = CHECK_ERROR(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)); + GLenum status = MBGL_CHECK_ERROR(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { std::stringstream error("Couldn't create framebuffer: "); @@ -247,7 +247,7 @@ std::unique_ptr HeadlessView::readPixels() { auto pixels = util::make_unique(w * h); make_active(); - CHECK_ERROR(glReadPixels(0, 0, width_, height_, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get())); + MBGL_CHECK_ERROR(glReadPixels(0, 0, width_, height_, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get())); make_inactive(); const int stride = w * 4; @@ -265,20 +265,20 @@ std::unique_ptr HeadlessView::readPixels() { void HeadlessView::clear_buffers() { make_active(); - CHECK_ERROR(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0)); + MBGL_CHECK_ERROR(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0)); if (fbo) { - CHECK_ERROR(glDeleteFramebuffersEXT(1, &fbo)); + MBGL_CHECK_ERROR(glDeleteFramebuffersEXT(1, &fbo)); fbo = 0; } if (fboColor) { - CHECK_ERROR(glDeleteTextures(1, &fboColor)); + MBGL_CHECK_ERROR(glDeleteTextures(1, &fboColor)); fboColor = 0; } if (fboDepthStencil) { - CHECK_ERROR(glDeleteRenderbuffersEXT(1, &fboDepthStencil)); + MBGL_CHECK_ERROR(glDeleteRenderbuffersEXT(1, &fboDepthStencil)); fboDepthStencil = 0; } -- cgit v1.2.1