summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-05-23 19:15:10 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-05-24 19:58:24 +0300
commit1769e6fcb42d41e042c488bf2023fed360b87357 (patch)
tree4febd99199574ecc2a84bcc2012ae7c80e445c53
parent876bf0687a6e2b6b5dd491b65dad587c688aa56d (diff)
downloadqtlocation-mapboxgl-1769e6fcb42d41e042c488bf2023fed360b87357.tar.gz
[core] Move GLFW stencil clip debug to core
This makes the stencil clip debug available to all platforms. Fixes #4669.
-rw-r--r--include/mbgl/map/mode.hpp4
-rw-r--r--include/mbgl/platform/default/glfw_view.hpp5
-rw-r--r--platform/default/glfw_view.cpp51
-rw-r--r--src/mbgl/map/map.cpp7
-rw-r--r--src/mbgl/renderer/painter.cpp5
-rw-r--r--src/mbgl/renderer/painter.hpp2
-rw-r--r--src/mbgl/renderer/painter_debug.cpp39
7 files changed, 57 insertions, 56 deletions
diff --git a/include/mbgl/map/mode.hpp b/include/mbgl/map/mode.hpp
index ae4328d6fd..d94cdc0eb5 100644
--- a/include/mbgl/map/mode.hpp
+++ b/include/mbgl/map/mode.hpp
@@ -43,6 +43,10 @@ enum class MapDebugOptions : EnumType {
Timestamps = 1 << 3,
Collision = 1 << 4,
Wireframe = 1 << 5,
+// FIXME: https://github.com/mapbox/mapbox-gl-native/issues/5117
+#ifndef GL_ES_VERSION_2_0
+ StencilClip = 1 << 6,
+#endif // GL_ES_VERSION_2_0
};
inline MapDebugOptions operator| (const MapDebugOptions& lhs, const MapDebugOptions& rhs) {
diff --git a/include/mbgl/platform/default/glfw_view.hpp b/include/mbgl/platform/default/glfw_view.hpp
index 3b74618e3e..80cf028f79 100644
--- a/include/mbgl/platform/default/glfw_view.hpp
+++ b/include/mbgl/platform/default/glfw_view.hpp
@@ -49,9 +49,6 @@ private:
makeSpriteImage(int width, int height, float pixelRatio);
void nextOrientation();
- void toggleClipMasks();
-
- void renderClipMasks();
void addRandomPointAnnotations(int count);
void addRandomShapeAnnotations(int count);
@@ -81,8 +78,6 @@ private:
int fbHeight;
float pixelRatio;
- bool showClipMasks = false;
-
double lastX = 0, lastY = 0;
double lastClick = -1;
diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp
index e3a38114bd..f5fdb60df7 100644
--- a/platform/default/glfw_view.cpp
+++ b/platform/default/glfw_view.cpp
@@ -141,9 +141,6 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
if (!mods)
view->map->resetPosition();
break;
- case GLFW_KEY_C:
- view->toggleClipMasks();
- break;
case GLFW_KEY_S:
if (view->changeStyleCallback)
view->changeStyleCallback();
@@ -256,11 +253,6 @@ void GLFWView::nextOrientation() {
}
}
-void GLFWView::toggleClipMasks() {
- showClipMasks = !showClipMasks;
- map->update(mbgl::Update::Repaint);
-}
-
void GLFWView::addRandomCustomPointAnnotations(int count) {
std::vector<mbgl::PointAnnotation> points;
@@ -432,10 +424,6 @@ void GLFWView::run() {
map->render();
- if (showClipMasks) {
- renderClipMasks();
- }
-
glfwSwapBuffers(window);
report(1000 * (glfwGetTime() - started));
@@ -480,45 +468,6 @@ void GLFWView::invalidate() {
glfwPostEmptyEvent();
}
-void GLFWView::renderClipMasks() {
- // Read the stencil buffer
- auto pixels = std::make_unique<uint8_t[]>(fbWidth * fbHeight);
- glReadPixels(0, // GLint x
- 0, // GLint y
- fbWidth, // GLsizei width
- fbHeight, // GLsizei height
- GL_STENCIL_INDEX, // GLenum format
- GL_UNSIGNED_BYTE, // GLenum type
- pixels.get() // GLvoid * data
- );
-
- // Scale the Stencil buffer to cover the entire color space.
- auto it = pixels.get();
- auto end = it + fbWidth * fbHeight;
- const auto factor = 255.0f / *std::max_element(it, end);
- for (; it != end; ++it) {
- *it *= factor;
- }
-
- using namespace mbgl::gl;
- Preserve<PixelZoom> pixelZoom;
- Preserve<RasterPos> rasterPos;
- Preserve<StencilTest> stencilTest;
- Preserve<DepthTest> depthTest;
- Preserve<Program> program;
- Preserve<ColorMask> colorMask;
-
- MBGL_CHECK_ERROR(glPixelZoom(1.0f, 1.0f));
- MBGL_CHECK_ERROR(glRasterPos2f(-1.0f, -1.0f));
- MBGL_CHECK_ERROR(glDisable(GL_STENCIL_TEST));
- MBGL_CHECK_ERROR(glDisable(GL_DEPTH_TEST));
- MBGL_CHECK_ERROR(glUseProgram(0));
- MBGL_CHECK_ERROR(glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE));
- MBGL_CHECK_ERROR(glWindowPos2i(0, 0));
-
- MBGL_CHECK_ERROR(glDrawPixels(fbWidth, fbHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels.get()));
-}
-
void GLFWView::report(float duration) {
frames++;
frameTime += duration;
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 51e8caa295..298255adac 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -797,8 +797,15 @@ void Map::setDebug(MapDebugOptions debugOptions) {
}
void Map::cycleDebugOptions() {
+#ifndef GL_ES_VERSION_2_0
+ if (impl->debugOptions & MapDebugOptions::StencilClip)
+ impl->debugOptions = MapDebugOptions::NoDebug;
+ else if (impl->debugOptions & MapDebugOptions::Wireframe)
+ impl->debugOptions = MapDebugOptions::StencilClip;
+#else
if (impl->debugOptions & MapDebugOptions::Wireframe)
impl->debugOptions = MapDebugOptions::NoDebug;
+#endif // GL_ES_VERSION_2_0
else if (impl->debugOptions & MapDebugOptions::Collision)
impl->debugOptions = MapDebugOptions::Collision | MapDebugOptions::Wireframe;
else if (impl->debugOptions & MapDebugOptions::Timestamps)
diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp
index b03e4d1afe..963639a7fd 100644
--- a/src/mbgl/renderer/painter.cpp
+++ b/src/mbgl/renderer/painter.cpp
@@ -169,6 +169,11 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a
drawClippingMasks(generator.getStencils());
}
+ if (frame.debugOptions & MapDebugOptions::StencilClip) {
+ renderClipMasks();
+ return;
+ }
+
// Actually render the layers
if (debug::renderTree) { Log::Info(Event::Render, "{"); indent++; }
diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp
index ac05da62fd..9b5ef75c50 100644
--- a/src/mbgl/renderer/painter.hpp
+++ b/src/mbgl/renderer/painter.hpp
@@ -99,6 +99,8 @@ public:
// Renders the red debug frame around a tile, visualizing its perimeter.
void renderDebugFrame(const mat4 &matrix);
+ void renderClipMasks();
+
void renderDebugText(TileData&, const mat4&);
void renderFill(FillBucket&, const FillLayer&, const UnwrappedTileID&, const mat4&);
void renderLine(LineBucket&, const LineLayer&, const UnwrappedTileID&, const mat4&);
diff --git a/src/mbgl/renderer/painter_debug.cpp b/src/mbgl/renderer/painter_debug.cpp
index ac23310b3d..d99bfbd22f 100644
--- a/src/mbgl/renderer/painter_debug.cpp
+++ b/src/mbgl/renderer/painter_debug.cpp
@@ -5,6 +5,9 @@
#include <mbgl/shader/plain_shader.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/gl/debugging.hpp>
+#include <mbgl/gl/gl.hpp>
+#include <mbgl/gl/gl_values.hpp>
+#include <mbgl/gl/gl_helper.hpp>
using namespace mbgl;
@@ -75,3 +78,39 @@ void Painter::renderDebugFrame(const mat4 &matrix) {
config.lineWidth = 4.0f * frame.pixelRatio;
MBGL_CHECK_ERROR(glDrawArrays(GL_LINE_STRIP, 0, (GLsizei)tileBorderBuffer.index()));
}
+
+void Painter::renderClipMasks() {
+ config.stencilTest = GL_FALSE;
+ config.depthTest = GL_FALSE;
+ config.program = 0;
+ config.colorMask = { GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE };
+
+#ifndef GL_ES_VERSION_2_0
+ config.pixelZoom = { 1, 1 };
+ config.rasterPos = {{ -1, -1, 0, 0 }};
+
+ // Read the stencil buffer
+ const auto& fbSize = frame.framebufferSize;
+ auto pixels = std::make_unique<uint8_t[]>(fbSize[0] * fbSize[1]);
+ MBGL_CHECK_ERROR(glReadPixels(
+ 0, // GLint x
+ 0, // GLint y
+ fbSize[0], // GLsizei width
+ fbSize[1], // GLsizei height
+ GL_STENCIL_INDEX, // GLenum format
+ GL_UNSIGNED_BYTE, // GLenum type
+ pixels.get() // GLvoid * data
+ ));
+
+ // Scale the Stencil buffer to cover the entire color space.
+ auto it = pixels.get();
+ auto end = it + fbSize[0] * fbSize[1];
+ const auto factor = 255.0f / *std::max_element(it, end);
+ for (; it != end; ++it) {
+ *it *= factor;
+ }
+
+ MBGL_CHECK_ERROR(glWindowPos2i(0, 0));
+ MBGL_CHECK_ERROR(glDrawPixels(fbSize[0], fbSize[1], GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels.get()));
+#endif // GL_ES_VERSION_2_0
+}