[core] add ability show visualize the depth buffer to the GLFW and macOS app
This commit is contained in:
@@ -47,6 +47,7 @@ enum class MapDebugOptions : EnumType {
|
||||
// FIXME: https://github.com/mapbox/mapbox-gl-native/issues/5117
|
||||
#ifndef GL_ES_VERSION_2_0
|
||||
StencilClip = 1 << 6,
|
||||
DepthBuffer = 1 << 7,
|
||||
#endif // GL_ES_VERSION_2_0
|
||||
};
|
||||
|
||||
@@ -55,11 +56,19 @@ constexpr MapDebugOptions operator|(MapDebugOptions lhs, MapDebugOptions rhs) {
|
||||
}
|
||||
|
||||
constexpr MapDebugOptions& operator|=(MapDebugOptions& lhs, MapDebugOptions rhs) {
|
||||
return (lhs = lhs | rhs);
|
||||
return (lhs = MapDebugOptions(mbgl::underlying_type(lhs) | mbgl::underlying_type(rhs)));
|
||||
}
|
||||
|
||||
constexpr bool operator&(MapDebugOptions lhs, MapDebugOptions rhs) {
|
||||
return mbgl::underlying_type(lhs) & mbgl::underlying_type(rhs);
|
||||
}
|
||||
|
||||
constexpr MapDebugOptions& operator&=(MapDebugOptions& lhs, MapDebugOptions rhs) {
|
||||
return (lhs = MapDebugOptions(mbgl::underlying_type(lhs) & mbgl::underlying_type(rhs)));
|
||||
}
|
||||
|
||||
constexpr MapDebugOptions operator~(MapDebugOptions value) {
|
||||
return MapDebugOptions(~mbgl::underlying_type(value));
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -97,6 +97,7 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_)
|
||||
printf("- Press `Z` to cycle through north orientations\n");
|
||||
printf("- Prezz `X` to cycle through the viewport modes\n");
|
||||
printf("- Press `A` to cycle through Mapbox offices in the world + dateline monument\n");
|
||||
printf("- Press `B` to cycle through the color, stencil, and depth buffer\n");
|
||||
printf("\n");
|
||||
printf("- Press `1` through `6` to add increasing numbers of point annotations for testing\n");
|
||||
printf("- Press `7` through `0` to add increasing numbers of shape annotations for testing\n");
|
||||
@@ -155,6 +156,18 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GLFW_KEY_B: {
|
||||
auto debug = view->map->getDebug();
|
||||
if (debug & mbgl::MapDebugOptions::StencilClip) {
|
||||
debug &= ~mbgl::MapDebugOptions::StencilClip;
|
||||
debug |= mbgl::MapDebugOptions::DepthBuffer;
|
||||
} else if (debug & mbgl::MapDebugOptions::DepthBuffer) {
|
||||
debug &= ~mbgl::MapDebugOptions::DepthBuffer;
|
||||
} else {
|
||||
debug |= mbgl::MapDebugOptions::StencilClip;
|
||||
}
|
||||
view->map->setDebug(debug);
|
||||
} break;
|
||||
case GLFW_KEY_N:
|
||||
if (!mods)
|
||||
view->map->resetNorth();
|
||||
|
||||
@@ -474,6 +474,12 @@
|
||||
<action selector="showStencilBuffer:" target="-1" id="WkN-t9-Mpv"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Depth Buffer" keyEquivalent="d" id="CDq-70-oPa">
|
||||
<modifierMask key="keyEquivalentModifierMask" control="YES" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="showDepthBuffer:" target="-1" id="h7r-eM-ZEu"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="dYw-bb-tr1"/>
|
||||
<menuItem title="Show Tooltips on Dropped Pins" id="uir-Rx-zmw">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
|
||||
@@ -283,12 +283,19 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio
|
||||
|
||||
- (IBAction)showColorBuffer:(id)sender {
|
||||
self.mapView.debugMask &= ~MGLMapDebugStencilBufferMask;
|
||||
self.mapView.debugMask &= ~MGLMapDebugDepthBufferMask;
|
||||
}
|
||||
|
||||
- (IBAction)showStencilBuffer:(id)sender {
|
||||
self.mapView.debugMask &= ~MGLMapDebugDepthBufferMask;
|
||||
self.mapView.debugMask |= MGLMapDebugStencilBufferMask;
|
||||
}
|
||||
|
||||
- (IBAction)showDepthBuffer:(id)sender {
|
||||
self.mapView.debugMask &= ~MGLMapDebugStencilBufferMask;
|
||||
self.mapView.debugMask |= MGLMapDebugDepthBufferMask;
|
||||
}
|
||||
|
||||
- (IBAction)toggleShowsToolTipsOnDroppedPins:(id)sender {
|
||||
_showsToolTipsOnDroppedPins = !_showsToolTipsOnDroppedPins;
|
||||
}
|
||||
@@ -642,7 +649,7 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio
|
||||
return YES;
|
||||
}
|
||||
if (menuItem.action == @selector(showColorBuffer:)) {
|
||||
BOOL enabled = self.mapView.debugMask & MGLMapDebugStencilBufferMask;
|
||||
BOOL enabled = self.mapView.debugMask & (MGLMapDebugStencilBufferMask | MGLMapDebugDepthBufferMask);
|
||||
menuItem.state = enabled ? NSOffState : NSOnState;
|
||||
return YES;
|
||||
}
|
||||
@@ -651,6 +658,11 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio
|
||||
menuItem.state = enabled ? NSOnState : NSOffState;
|
||||
return YES;
|
||||
}
|
||||
if (menuItem.action == @selector(showDepthBuffer:)) {
|
||||
BOOL enabled = self.mapView.debugMask & MGLMapDebugDepthBufferMask;
|
||||
menuItem.state = enabled ? NSOnState : NSOffState;
|
||||
return YES;
|
||||
}
|
||||
if (menuItem.action == @selector(toggleShowsToolTipsOnDroppedPins:)) {
|
||||
BOOL isShown = _showsToolTipsOnDroppedPins;
|
||||
menuItem.title = isShown ? @"Hide Tooltips on Dropped Pins" : @"Show Tooltips on Dropped Pins";
|
||||
|
||||
@@ -32,6 +32,11 @@ typedef NS_OPTIONS(NSUInteger, MGLMapDebugMaskOptions) {
|
||||
@note This option does nothing in Release builds of the SDK.
|
||||
*/
|
||||
MGLMapDebugStencilBufferMask = 1 << 6,
|
||||
|
||||
/** The depth buffer is shown instead of the color buffer.
|
||||
@note This option does nothing in Release builds of the SDK.
|
||||
*/
|
||||
MGLMapDebugDepthBufferMask = 1 << 7,
|
||||
};
|
||||
|
||||
@class MGLAnnotationImage;
|
||||
|
||||
@@ -2450,6 +2450,9 @@ public:
|
||||
if (options & mbgl::MapDebugOptions::StencilClip) {
|
||||
mask |= MGLMapDebugStencilBufferMask;
|
||||
}
|
||||
if (options & mbgl::MapDebugOptions::DepthBuffer) {
|
||||
mask |= MGLMapDebugDepthBufferMask;
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
@@ -2473,6 +2476,9 @@ public:
|
||||
if (debugMask & MGLMapDebugStencilBufferMask) {
|
||||
options |= mbgl::MapDebugOptions::StencilClip;
|
||||
}
|
||||
if (debugMask & MGLMapDebugDepthBufferMask) {
|
||||
options |= mbgl::MapDebugOptions::DepthBuffer;
|
||||
}
|
||||
_mbglMap->setDebug(options);
|
||||
}
|
||||
|
||||
|
||||
@@ -198,6 +198,12 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
if (frame.debugOptions & MapDebugOptions::DepthBuffer) {
|
||||
renderDepthBuffer();
|
||||
}
|
||||
#endif
|
||||
|
||||
// TODO: Find a better way to unbind VAOs after we're done with them without introducing
|
||||
// unnecessary bind(0)/bind(N) sequences.
|
||||
{
|
||||
|
||||
@@ -89,6 +89,8 @@ public:
|
||||
#ifndef NDEBUG
|
||||
// Renders tile clip boundaries, using stencil buffer to calculate fill color.
|
||||
void renderClipMasks();
|
||||
// Renders the depth buffer.
|
||||
void renderDepthBuffer();
|
||||
#endif
|
||||
|
||||
void renderDebugText(Tile&, const mat4&);
|
||||
|
||||
@@ -125,4 +125,39 @@ void Painter::renderClipMasks() {
|
||||
}
|
||||
#endif // NDEBUG
|
||||
|
||||
#ifndef NDEBUG
|
||||
void Painter::renderDepthBuffer() {
|
||||
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<GLubyte[]>(fbSize[0] * fbSize[1]);
|
||||
|
||||
const double base = 1.0 / (1.0 - depthRangeSize);
|
||||
glPixelTransferf(GL_DEPTH_SCALE, base);
|
||||
glPixelTransferf(GL_DEPTH_BIAS, 1.0 - base);
|
||||
|
||||
MBGL_CHECK_ERROR(glReadPixels(
|
||||
0, // GLint x
|
||||
0, // GLint y
|
||||
fbSize[0], // GLsizei width
|
||||
fbSize[1], // GLsizei height
|
||||
GL_DEPTH_COMPONENT, // GLenum format
|
||||
GL_UNSIGNED_BYTE, // GLenum type
|
||||
pixels.get() // GLvoid * data
|
||||
));
|
||||
|
||||
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
|
||||
}
|
||||
#endif // NDEBUG
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
Reference in New Issue
Block a user