Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[core] Refactor wireframe to match JS overdraw #5403

Merged
merged 6 commits into from
Jun 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions include/mbgl/gl/gl_values.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,23 @@ struct BlendFunc {
}
};

constexpr bool operator!=(const BlendFunc::Type& a, const BlendFunc::Type& b) {
return a.sfactor != b.sfactor || a.dfactor != b.dfactor;
}

struct BlendColor {
using Type = Color;
static const Type Default;
inline static void Set(const Type& value) {
MBGL_CHECK_ERROR(glBlendColor(value.r, value.g, value.b, value.a));
}
inline static Type Get() {
GLfloat floats[4];
MBGL_CHECK_ERROR(glGetFloatv(GL_BLEND_COLOR, floats));
return { floats[0], floats[1], floats[2], floats[3] };
}
};

struct Program {
using Type = GLuint;
static const Type Default;
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/map/mode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ enum class MapDebugOptions : EnumType {
ParseStatus = 1 << 2,
Timestamps = 1 << 3,
Collision = 1 << 4,
Wireframe = 1 << 5,
Overdraw = 1 << 5,
// FIXME: https://github.com/mapbox/mapbox-gl-native/issues/5117
#ifndef GL_ES_VERSION_2_0
StencilClip = 1 << 6,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"express": "^4.11.1",
"mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#59e998295d548f208ee3ec10cdd21ff2630e2079",
"mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#194fc55b6a7dd54c1e2cf2dd9048fbb5e836716d",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#3a6baea2f364410e6d0873b71babfe0484870a72",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#85d2319dd5ad75da1f39b8cd9e08f1e51ede58cb",
"node-gyp": "^3.3.1",
"request": "^2.72.0",
"tape": "^4.5.1"
Expand Down
2 changes: 1 addition & 1 deletion platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CON
- Removed unused SVG files from the SDK’s resource bundle. ([#4641](https://github.com/mapbox/mapbox-gl-native/pull/4641))
- Deprecated `-[MGLMapView emptyMemoryCache]`. ([#4725](https://github.com/mapbox/mapbox-gl-native/pull/4725))
- Added `MGLCoordinateInCoordinateBounds()`, a function that tests whether or not a coordinate is in a given bounds. ([#5053](https://github.com/mapbox/mapbox-gl-native/pull/5053))
- Added a new option to `MGLMapDebugMaskOptions`, `MGLMapDebugWireframesMask`, that shows wireframes instead of the usual rendered output. ([#4359](https://github.com/mapbox/mapbox-gl-native/pull/4359))
- Added a new option to `MGLMapDebugMaskOptions`, `MGLMapDebugOverdrawsMask`, that shows wireframes for overdraw inspection instead of the usual rendered output. ([#4359](https://github.com/mapbox/mapbox-gl-native/pull/4359))

## 3.2.3

Expand Down
8 changes: 4 additions & 4 deletions platform/ios/app/MBXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ - (IBAction)showSettings:(__unused id)sender
((debugMask & MGLMapDebugCollisionBoxesMask)
? @"Hide Collision Boxes"
: @"Show Collision Boxes"),
((debugMask & MGLMapDebugWireframesMask)
? @"Hide Wireframes"
: @"Show Wireframes"),
((debugMask & MGLMapDebugOverdrawsMask)
? @"Hide Overdraws"
: @"Show Overdraws"),
@"Add 100 Points",
@"Add 1,000 Points",
@"Add 10,000 Points",
Expand Down Expand Up @@ -226,7 +226,7 @@ - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSIn
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 5)
{
self.mapView.debugMask ^= MGLMapDebugWireframesMask;
self.mapView.debugMask ^= MGLMapDebugOverdrawsMask;
}
else if (buttonIndex == actionSheet.firstOtherButtonIndex + 6)
{
Expand Down
5 changes: 2 additions & 3 deletions platform/ios/src/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ typedef NS_OPTIONS(NSUInteger, MGLMapDebugMaskOptions) {
/** Edges of glyphs and symbols are shown as faint, green lines to help
diagnose collision and label placement issues. */
MGLMapDebugCollisionBoxesMask = 1 << 4,
/** Line widths, backgrounds, and fill colors are ignored to create a
wireframe effect. */
MGLMapDebugWireframesMask = 1 << 5,
/** Overdraw inspector. */
MGLMapDebugOverdrawsMask = 1 << 5,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enum value needs a more descriptive name, and the comment is somewhat nonsensical to an iOS developer.

};

/**
Expand Down
8 changes: 4 additions & 4 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1829,9 +1829,9 @@ - (MGLMapDebugMaskOptions)debugMask
{
mask |= MGLMapDebugCollisionBoxesMask;
}
if (options & mbgl::MapDebugOptions::Wireframe)
if (options & mbgl::MapDebugOptions::Overdraw)
{
mask |= MGLMapDebugWireframesMask;
mask |= MGLMapDebugOverdrawsMask;
}
return mask;
}
Expand All @@ -1855,9 +1855,9 @@ - (void)setDebugMask:(MGLMapDebugMaskOptions)debugMask
{
options |= mbgl::MapDebugOptions::Collision;
}
if (debugMask & MGLMapDebugWireframesMask)
if (debugMask & MGLMapDebugOverdrawsMask)
{
options |= mbgl::MapDebugOptions::Wireframe;
options |= mbgl::MapDebugOptions::Overdraw;
}
_mbglMap->setDebug(options);
}
Expand Down
1 change: 1 addition & 0 deletions platform/macos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog for Mapbox macOS SDK

## master
* Refactor wireframe mode to match GL JS overdraw implementation. ([#5403](https://github.com/mapbox/mapbox-gl-native/pull/5403)).

## 0.2.0

Expand Down
4 changes: 2 additions & 2 deletions platform/macos/app/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,10 @@
<action selector="toggleCollisionBoxes:" target="-1" id="EYa-7n-iWZ"/>
</connections>
</menuItem>
<menuItem title="Show Wireframes" id="hSX-Be-8xC">
<menuItem title="Show Overdraws" id="hSX-Be-8xC">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleWireframes:" target="-1" id="usj-ug-upt"/>
<action selector="toggleOverdraws:" target="-1" id="usj-ug-upt"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="2EG-Hp-4FA"/>
Expand Down
10 changes: 5 additions & 5 deletions platform/macos/app/MapDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ - (IBAction)toggleCollisionBoxes:(id)sender {
self.mapView.debugMask ^= MGLMapDebugCollisionBoxesMask;
}

- (IBAction)toggleWireframes:(id)sender {
self.mapView.debugMask ^= MGLMapDebugWireframesMask;
- (IBAction)toggleOverdraws:(id)sender {
self.mapView.debugMask ^= MGLMapDebugOverdrawsMask;
}

- (IBAction)showColorBuffer:(id)sender {
Expand Down Expand Up @@ -604,9 +604,9 @@ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
menuItem.title = isShown ? @"Hide Collision Boxes" : @"Show Collision Boxes";
return YES;
}
if (menuItem.action == @selector(toggleWireframes:)) {
BOOL isShown = self.mapView.debugMask & MGLMapDebugWireframesMask;
menuItem.title = isShown ? @"Hide Wireframes" : @"Show Wireframes";
if (menuItem.action == @selector(toggleOverdraws:)) {
BOOL isShown = self.mapView.debugMask & MGLMapDebugOverdrawsMask;
menuItem.title = isShown ? @"Hide Overdraws" : @"Show Overdraws";
return YES;
}
if (menuItem.action == @selector(showColorBuffer:)) {
Expand Down
5 changes: 2 additions & 3 deletions platform/macos/src/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ typedef NS_OPTIONS(NSUInteger, MGLMapDebugMaskOptions) {
diagnose collision and label placement issues. */
MGLMapDebugCollisionBoxesMask = 1 << 4,

/** Line widths, backgrounds, and fill colors are ignored to create a
wireframe effect. */
MGLMapDebugWireframesMask = 1 << 5,
/** Overdraw inspector. */
MGLMapDebugOverdrawsMask = 1 << 5,

/** The stencil buffer is shown instead of the color buffer. */
MGLMapDebugStencilBufferMask = 1 << 6,
Expand Down
8 changes: 4 additions & 4 deletions platform/macos/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2398,8 +2398,8 @@ - (MGLMapDebugMaskOptions)debugMask {
if (options & mbgl::MapDebugOptions::Collision) {
mask |= MGLMapDebugCollisionBoxesMask;
}
if (options & mbgl::MapDebugOptions::Wireframe) {
mask |= MGLMapDebugWireframesMask;
if (options & mbgl::MapDebugOptions::Overdraw) {
mask |= MGLMapDebugOverdrawsMask;
}
if (options & mbgl::MapDebugOptions::StencilClip) {
mask |= MGLMapDebugStencilBufferMask;
Expand All @@ -2421,8 +2421,8 @@ - (void)setDebugMask:(MGLMapDebugMaskOptions)debugMask {
if (debugMask & MGLMapDebugCollisionBoxesMask) {
options |= mbgl::MapDebugOptions::Collision;
}
if (debugMask & MGLMapDebugWireframesMask) {
options |= mbgl::MapDebugOptions::Wireframe;
if (debugMask & MGLMapDebugOverdrawsMask) {
options |= mbgl::MapDebugOptions::Overdraw;
}
if (debugMask & MGLMapDebugStencilBufferMask) {
options |= mbgl::MapDebugOptions::StencilClip;
Expand Down
5 changes: 5 additions & 0 deletions platform/node/src/node_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ NodeMap::RenderOptions NodeMap::ParseOptions(v8::Local<v8::Object> obj) {
options.debugOptions = options.debugOptions | mbgl::MapDebugOptions::Collision;
}
}
if (Nan::Has(debug, Nan::New("overdraw").ToLocalChecked()).FromJust()) {
if (Nan::Get(debug, Nan::New("overdraw").ToLocalChecked()).ToLocalChecked()->BooleanValue()) {
options.debugOptions = mbgl::MapDebugOptions::Overdraw;
}
}
}

return options;
Expand Down
3 changes: 2 additions & 1 deletion platform/node/test/suite_implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ module.exports = function (style, options, callback) {
options.pitch = style.pitch;
options.debug = {
tileBorders: options.debug,
collision: options.collisionDebug
collision: options.collisionDebug,
overdraw: options.showOverdrawInspector,
};

map.load(style);
Expand Down
5 changes: 5 additions & 0 deletions scripts/build-shaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def replace_uniform_pragmas(line):
namespace shaders {{
namespace {name} {{

#ifndef MBGL_SHADER_NAME_{NAME}
#define MBGL_SHADER_NAME_{NAME}
constexpr const char* name = "{name}";
#endif // MBGL_SHADER_NAME_{NAME}

#ifdef GL_ES_VERSION_2_0
constexpr const char* {type} = R"MBGL_SHADER(precision highp float;\n{data})MBGL_SHADER";
#else
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/geometry/vao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void VertexArrayObject::bindVertexArrayObject(gl::ObjectStore& store) {
MBGL_CHECK_ERROR(gl::BindVertexArray(*vao));
}

void VertexArrayObject::verifyBinding(Shader &shader, GLuint vertexBuffer, GLuint elementsBuffer,
void VertexArrayObject::verifyBinding(Shader& shader, GLuint vertexBuffer, GLuint elementsBuffer,
GLbyte *offset) {
if (bound_shader != shader.getID()) {
throw std::runtime_error(std::string("trying to rebind VAO to another shader from " +
Expand Down
12 changes: 5 additions & 7 deletions src/mbgl/geometry/vao.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@

namespace mbgl {

class Shader;

class VertexArrayObject : public util::noncopyable {
public:
static void Unbind();

VertexArrayObject();
~VertexArrayObject();

template <typename Shader, typename VertexBuffer>
void bind(Shader& shader, VertexBuffer &vertexBuffer, GLbyte *offset, gl::ObjectStore& store) {
template <typename VertexBuffer>
void bind(Shader& shader, VertexBuffer& vertexBuffer, GLbyte* offset, gl::ObjectStore& store) {
bindVertexArrayObject(store);
if (bound_shader == 0) {
vertexBuffer.bind(store);
Expand All @@ -33,8 +31,8 @@ class VertexArrayObject : public util::noncopyable {
}
}

template <typename Shader, typename VertexBuffer, typename ElementsBuffer>
void bind(Shader& shader, VertexBuffer &vertexBuffer, ElementsBuffer &elementsBuffer, GLbyte *offset, gl::ObjectStore& store) {
template <typename VertexBuffer, typename ElementsBuffer>
void bind(Shader& shader, VertexBuffer& vertexBuffer, ElementsBuffer& elementsBuffer, GLbyte* offset, gl::ObjectStore& store) {
bindVertexArrayObject(store);
if (bound_shader == 0) {
vertexBuffer.bind(store);
Expand Down Expand Up @@ -62,7 +60,7 @@ class VertexArrayObject : public util::noncopyable {
// For debug reasons, we're storing the bind information so that we can
// detect errors and report
GLuint bound_shader = 0;
const char *bound_shader_name = "";
const char* bound_shader_name = "";
GLuint bound_vertex_buffer = 0;
GLuint bound_elements_buffer = 0;
GLbyte *bound_offset = nullptr;
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/gl/gl_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const DepthTest::Type DepthTest::Default = GL_FALSE;
const DepthFunc::Type DepthFunc::Default = GL_LEQUAL;
const Blend::Type Blend::Default = GL_TRUE;
const BlendFunc::Type BlendFunc::Default = { GL_ONE, GL_ONE_MINUS_SRC_ALPHA };
const BlendColor::Type BlendColor::Default = { 0, 0, 0, 0 };
const ColorMask::Type ColorMask::Default = { GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE };
const ClearDepth::Type ClearDepth::Default = 1;
const ClearColor::Type ClearColor::Default = { 0, 0, 0, 0 };
Expand Down
3 changes: 3 additions & 0 deletions src/mbgl/gl/gl_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Config {
depthFunc.reset();
blend.reset();
blendFunc.reset();
blendColor.reset();
colorMask.reset();
clearDepth.reset();
clearColor.reset();
Expand All @@ -80,6 +81,7 @@ class Config {
depthFunc.setDirty();
blend.setDirty();
blendFunc.setDirty();
blendColor.setDirty();
colorMask.setDirty();
clearDepth.setDirty();
clearColor.setDirty();
Expand All @@ -103,6 +105,7 @@ class Config {
Value<DepthFunc> depthFunc;
Value<Blend> blend;
Value<BlendFunc> blendFunc;
Value<BlendColor> blendColor;
Value<ColorMask> colorMask;
Value<ClearDepth> clearDepth;
Value<ClearColor> clearColor;
Expand Down
6 changes: 3 additions & 3 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,14 +787,14 @@ void Map::cycleDebugOptions() {
#ifndef GL_ES_VERSION_2_0
if (impl->debugOptions & MapDebugOptions::StencilClip)
impl->debugOptions = MapDebugOptions::NoDebug;
else if (impl->debugOptions & MapDebugOptions::Wireframe)
else if (impl->debugOptions & MapDebugOptions::Overdraw)
impl->debugOptions = MapDebugOptions::StencilClip;
#else
if (impl->debugOptions & MapDebugOptions::Wireframe)
if (impl->debugOptions & MapDebugOptions::Overdraw)
impl->debugOptions = MapDebugOptions::NoDebug;
#endif // GL_ES_VERSION_2_0
else if (impl->debugOptions & MapDebugOptions::Collision)
impl->debugOptions = MapDebugOptions::Collision | MapDebugOptions::Wireframe;
impl->debugOptions = MapDebugOptions::Overdraw;
else if (impl->debugOptions & MapDebugOptions::Timestamps)
impl->debugOptions = impl->debugOptions | MapDebugOptions::Collision;
else if (impl->debugOptions & MapDebugOptions::ParseStatus)
Expand Down
13 changes: 10 additions & 3 deletions src/mbgl/renderer/painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a
spriteAtlas = style.spriteAtlas.get();
lineAtlas = style.lineAtlas.get();

RenderData renderData = style.getRenderData();
RenderData renderData = style.getRenderData(frame.debugOptions);
const std::vector<RenderItem>& order = renderData.order;
const std::set<Source*>& sources = renderData.sources;
const Color& background = renderData.backgroundColor;
Expand Down Expand Up @@ -144,7 +144,12 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a
config.depthTest = GL_FALSE;
config.depthMask = GL_TRUE;
config.colorMask = { GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE };
if (frame.debugOptions & MapDebugOptions::Wireframe) {

if (isOverdraw()) {
config.blend = GL_TRUE;
config.blendFunc = { GL_CONSTANT_COLOR, GL_ONE };
const float overdraw = 1.0f / 8.0f;
config.blendColor = { overdraw, overdraw, overdraw, 0.0f };
config.clearColor = Color::black();
} else {
config.clearColor = background;
Expand Down Expand Up @@ -243,7 +248,9 @@ void Painter::renderPass(RenderPass pass_,
if (!layer.baseImpl->hasRenderPass(pass))
continue;

if (pass == RenderPass::Translucent) {
if (isOverdraw()) {
config.blend = GL_TRUE;
} else if (pass == RenderPass::Translucent) {
config.blendFunc.reset();
config.blend = GL_TRUE;
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/mbgl/renderer/painter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ class Painter : private util::noncopyable {

void setDepthSublayer(int n);

bool isOverdraw() const { return frame.debugOptions & MapDebugOptions::Overdraw; }

mat4 projMatrix;
mat4 nativeMatrix;

Expand Down
Loading