[core] Modern C++ bindings for OpenGL

This commit is contained in:
John Firebaugh
2016-09-26 12:53:32 -07:00
parent a4c82b8a3b
commit 0e57d10d77
97 changed files with 2233 additions and 1857 deletions

View File

@@ -5,6 +5,7 @@
#include <mbgl/map/view.hpp>
#include <mbgl/tile/tile.hpp>
#include <mbgl/shader/shaders.hpp>
#include <mbgl/shader/fill_uniforms.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/gl/debugging.hpp>
#include <mbgl/gl/gl.hpp>
@@ -12,89 +13,59 @@
namespace mbgl {
void Painter::renderTileDebug(const RenderTile& tile) {
MBGL_DEBUG_GROUP(std::string { "debug " } + util::toString(tile.id));
if (frame.debugOptions != MapDebugOptions::NoDebug) {
setClipping(tile.clip);
if (frame.debugOptions & (MapDebugOptions::Timestamps | MapDebugOptions::ParseStatus)) {
renderDebugText(tile.tile, tile.matrix);
void Painter::renderTileDebug(const RenderTile& renderTile) {
if (frame.debugOptions == MapDebugOptions::NoDebug)
return;
MBGL_DEBUG_GROUP(std::string { "debug " } + util::toString(renderTile.id));
auto draw = [&] (Color color, auto subject) {
context.draw({
gl::DepthMode::disabled(),
stencilModeForClipping(renderTile.clip),
gl::ColorMode::unblended(),
shaders->fill,
FillColorUniforms::values(
renderTile.matrix,
1.0f,
color,
color,
context.viewport.getCurrentValue().size
),
subject
});
};
if (frame.debugOptions & (MapDebugOptions::Timestamps | MapDebugOptions::ParseStatus)) {
Tile& tile = renderTile.tile;
if (!tile.debugBucket || tile.debugBucket->renderable != tile.isRenderable() ||
tile.debugBucket->complete != tile.isComplete() ||
!(tile.debugBucket->modified == tile.modified) ||
!(tile.debugBucket->expires == tile.expires) ||
tile.debugBucket->debugMode != frame.debugOptions) {
tile.debugBucket = std::make_unique<DebugBucket>(
tile.id, tile.isRenderable(), tile.isComplete(), tile.modified,
tile.expires, frame.debugOptions, context);
}
if (frame.debugOptions & MapDebugOptions::TileBorders) {
renderDebugFrame(tile.matrix);
}
}
}
void Painter::renderDebugText(Tile& tile, const mat4 &matrix) {
MBGL_DEBUG_GROUP("debug text");
const auto& vertexBuffer = tile.debugBucket->vertexBuffer;
context.depthTest = false;
if (!tile.debugBucket || tile.debugBucket->renderable != tile.isRenderable() ||
tile.debugBucket->complete != tile.isComplete() ||
!(tile.debugBucket->modified == tile.modified) ||
!(tile.debugBucket->expires == tile.expires) ||
tile.debugBucket->debugMode != frame.debugOptions) {
tile.debugBucket = std::make_unique<DebugBucket>(
tile.id, tile.isRenderable(), tile.isComplete(), tile.modified,
tile.expires, frame.debugOptions, context);
draw(Color::white(), gl::Unindexed<gl::Lines>(vertexBuffer, 4.0f * frame.pixelRatio));
draw(Color::black(), gl::Unindexed<gl::Points>(vertexBuffer, 2.0f));
draw(Color::black(), gl::Unindexed<gl::Lines>(vertexBuffer, 2.0f * frame.pixelRatio));
}
auto& plainShader = shaders->fill;
context.program = plainShader.getID();
plainShader.u_matrix = matrix;
plainShader.u_opacity = 1.0f;
// Draw white outline
plainShader.u_color = Color::white();
context.lineWidth = 4.0f * frame.pixelRatio;
tile.debugBucket->drawLines(plainShader, context);
#if not MBGL_USE_GLES2
// Draw line "end caps"
MBGL_CHECK_ERROR(glPointSize(2));
tile.debugBucket->drawPoints(plainShader, context);
#endif // MBGL_USE_GLES2
// Draw black text.
plainShader.u_color = Color::black();
context.lineWidth = 2.0f * frame.pixelRatio;
tile.debugBucket->drawLines(plainShader, context);
context.depthFunc = gl::DepthTestFunction::LessEqual;
context.depthTest = true;
}
void Painter::renderDebugFrame(const mat4 &matrix) {
MBGL_DEBUG_GROUP("debug frame");
// Disable depth test and don't count this towards the depth buffer,
// but *don't* disable stencil test, as we want to clip the red tile border
// to the tile viewport.
context.depthTest = false;
context.stencilOp = { gl::StencilTestOperation::Keep, gl::StencilTestOperation::Keep,
gl::StencilTestOperation::Replace };
context.stencilTest = true;
auto& plainShader = shaders->fill;
context.program = plainShader.getID();
plainShader.u_matrix = matrix;
plainShader.u_opacity = 1.0f;
// draw tile outline
tileBorderArray.bind(plainShader, tileLineStripVertexBuffer, BUFFER_OFFSET_0, context);
plainShader.u_color = { 1.0f, 0.0f, 0.0f, 1.0f };
context.lineWidth = 4.0f * frame.pixelRatio;
MBGL_CHECK_ERROR(glDrawArrays(GL_LINE_STRIP, 0,
static_cast<GLsizei>(tileLineStripVertexBuffer.vertexCount)));
if (frame.debugOptions & MapDebugOptions::TileBorders) {
draw(Color::red(), gl::Unindexed<gl::LineStrip>(tileLineStripVertexBuffer, 4.0f * frame.pixelRatio));
}
}
#ifndef NDEBUG
void Painter::renderClipMasks(PaintParameters&) {
context.stencilTest = false;
context.depthTest = false;
context.setStencilMode(gl::StencilMode::disabled());
context.setDepthMode(gl::DepthMode::disabled());
context.setColorMode(gl::ColorMode::unblended());
context.program = 0;
context.colorMask = { true, true, true, true };
#if not MBGL_USE_GLES2
context.pixelZoom = { 1, 1 };
@@ -126,14 +97,12 @@ void Painter::renderClipMasks(PaintParameters&) {
GL_UNSIGNED_BYTE, pixels.get()));
#endif // MBGL_USE_GLES2
}
#endif // NDEBUG
#ifndef NDEBUG
void Painter::renderDepthBuffer(PaintParameters&) {
context.stencilTest = false;
context.depthTest = false;
context.setStencilMode(gl::StencilMode::disabled());
context.setDepthMode(gl::DepthMode::disabled());
context.setColorMode(gl::ColorMode::unblended());
context.program = 0;
context.colorMask = { true, true, true, true };
#if not MBGL_USE_GLES2
context.pixelZoom = { 1, 1 };