diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-10-10 17:16:37 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-10-25 13:52:36 -0700 |
commit | a4d259c33f9bb890bba97fd89552720e3e0ec09b (patch) | |
tree | 342ecc27a6993c48f3a2e1d739fce890350bc44d /src/mbgl/renderer | |
parent | 5cc390d694fc7510d445310d8eb9e32429a5e67b (diff) | |
download | qtlocation-mapboxgl-a4d259c33f9bb890bba97fd89552720e3e0ec09b.tar.gz |
[core] move gl::Context to Backend and refactor View
Diffstat (limited to 'src/mbgl/renderer')
-rw-r--r-- | src/mbgl/renderer/painter.cpp | 35 | ||||
-rw-r--r-- | src/mbgl/renderer/painter.hpp | 7 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_debug.cpp | 44 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_fill.cpp | 4 |
4 files changed, 46 insertions, 44 deletions
diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index ee7ef6d212..fc61d6e0a0 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -31,6 +31,8 @@ #include <mbgl/util/mat3.hpp> #include <mbgl/util/string.hpp> +#include <mbgl/util/offscreen_texture.hpp> + #include <cassert> #include <algorithm> #include <iostream> @@ -40,8 +42,9 @@ namespace mbgl { using namespace style; -Painter::Painter(const TransformState& state_) - : state(state_), +Painter::Painter(gl::Context& context_, const TransformState& state_) + : context(context_), + state(state_), tileTriangleVertexBuffer(context.createVertexBuffer(std::vector<FillVertex> {{ { 0, 0 }, { util::EXTENT, 0 }, @@ -71,9 +74,6 @@ Painter::Painter(const TransformState& state_) #ifndef NDEBUG overdrawShaders = std::make_unique<Shaders>(context, gl::Shader::Overdraw); #endif - - // Reset GL values - context.setDirtyState(); } Painter::~Painter() = default; @@ -93,9 +93,10 @@ void Painter::cleanup() { } void Painter::render(const Style& style, const FrameData& frame_, View& view, SpriteAtlas& annotationSpriteAtlas) { - context.viewport.setDefaultValue( - { 0, 0, view.getFramebufferSize()[0], view.getFramebufferSize()[1] }); frame = frame_; + if (frame.contextMode == GLContextMode::Shared) { + context.setDirtyState(); + } PaintParameters parameters { #ifndef NDEBUG @@ -126,12 +127,14 @@ void Painter::render(const Style& style, const FrameData& frame_, View& view, Sp frameHistory.record(frame.timePoint, state.getZoom(), frame.mapMode == MapMode::Continuous ? util::DEFAULT_FADE_DURATION : Milliseconds(0)); + // - UPLOAD PASS ------------------------------------------------------------------------------- // Uploads all required buffers and images before we do any actual rendering. { MBGL_DEBUG_GROUP("upload"); spriteAtlas->upload(context, 0); + lineAtlas->upload(context, 0); glyphAtlas->upload(context, 0); frameHistory.upload(context, 0); @@ -149,10 +152,8 @@ void Painter::render(const Style& style, const FrameData& frame_, View& view, Sp // tiles whatsoever. { MBGL_DEBUG_GROUP("clear"); - context.bindFramebuffer.setDirty(); view.bind(); - context.viewport.reset(); - context.stencilFunc.reset(); + context.stencilFunc = { gl::StencilTestFunction::Always, 0, ~0u }; context.stencilTest = true; context.stencilMask = 0xFF; context.depthTest = false; @@ -249,10 +250,6 @@ void Painter::render(const Style& style, const FrameData& frame_, View& view, Sp context.vertexArrayObject = 0; } - - if (frame.contextMode == GLContextMode::Shared) { - context.setDirtyState(); - } } template <class Iterator> @@ -296,17 +293,21 @@ void Painter::renderPass(PaintParameters& parameters, renderBackground(parameters, *layer.as<BackgroundLayer>()); } else if (layer.is<CustomLayer>()) { MBGL_DEBUG_GROUP(layer.baseImpl->id + " - custom"); + + // Reset GL state to a known state so the CustomLayer always has a clean slate. context.vertexArrayObject = 0; context.depthFunc = gl::DepthTestFunction::LessEqual; context.depthTest = true; context.depthMask = false; context.stencilTest = false; setDepthSublayer(0); + layer.as<CustomLayer>()->impl->render(state); - context.setDirtyState(); - context.bindFramebuffer.setDirty(); + + // Reset the view back to our original one, just in case the CustomLayer changed + // the viewport or Framebuffer. parameters.view.bind(); - context.viewport.reset(); + context.setDirtyState(); } else { MBGL_DEBUG_GROUP(layer.baseImpl->id + " - " + util::toString(item.tile->id)); if (item.bucket->needsClipping()) { diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp index d2c89c04a9..f339ed1aed 100644 --- a/src/mbgl/renderer/painter.hpp +++ b/src/mbgl/renderer/painter.hpp @@ -68,7 +68,7 @@ struct FrameData { class Painter : private util::noncopyable { public: - Painter(const TransformState&); + Painter(gl::Context&, const TransformState&); ~Painter(); void render(const style::Style&, @@ -153,6 +153,9 @@ private: } #endif +private: + gl::Context& context; + mat4 projMatrix; std::array<float, 2> pixelsToGLUnits; @@ -169,8 +172,6 @@ private: int indent = 0; - gl::Context context; - RenderPass pass = RenderPass::Opaque; int numSublayers = 3; diff --git a/src/mbgl/renderer/painter_debug.cpp b/src/mbgl/renderer/painter_debug.cpp index ca961f84e7..e57bb2205e 100644 --- a/src/mbgl/renderer/painter_debug.cpp +++ b/src/mbgl/renderer/painter_debug.cpp @@ -89,7 +89,7 @@ void Painter::renderDebugFrame(const mat4 &matrix) { } #ifndef NDEBUG -void Painter::renderClipMasks(PaintParameters& parameters) { +void Painter::renderClipMasks(PaintParameters&) { context.stencilTest = false; context.depthTest = false; context.program = 0; @@ -100,13 +100,13 @@ void Painter::renderClipMasks(PaintParameters& parameters) { context.rasterPos = { -1, -1, 0, 0 }; // Read the stencil buffer - const auto& fbSize = parameters.view.getFramebufferSize(); - auto pixels = std::make_unique<uint8_t[]>(fbSize[0] * fbSize[1]); + const auto viewport = context.viewport.getCurrentValue(); + auto pixels = std::make_unique<uint8_t[]>(viewport.width * viewport.height); MBGL_CHECK_ERROR(glReadPixels( - 0, // GLint x - 0, // GLint y - fbSize[0], // GLsizei width - fbSize[1], // GLsizei height + viewport.x, // GLint x + viewport.y, // GLint y + viewport.width, // GLsizei width + viewport.height, // GLsizei height GL_STENCIL_INDEX, // GLenum format GL_UNSIGNED_BYTE, // GLenum type pixels.get() // GLvoid * data @@ -114,22 +114,21 @@ void Painter::renderClipMasks(PaintParameters& parameters) { // Scale the Stencil buffer to cover the entire color space. auto it = pixels.get(); - auto end = it + fbSize[0] * fbSize[1]; + auto end = it + viewport.width * viewport.height; 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())); -#else - (void)parameters; + MBGL_CHECK_ERROR(glWindowPos2i(viewport.x, viewport.y)); + MBGL_CHECK_ERROR(glDrawPixels(viewport.width, viewport.height, GL_LUMINANCE, GL_UNSIGNED_BYTE, + pixels.get())); #endif // MBGL_USE_GLES2 } #endif // NDEBUG #ifndef NDEBUG -void Painter::renderDepthBuffer(PaintParameters& parameters) { +void Painter::renderDepthBuffer(PaintParameters&) { context.stencilTest = false; context.depthTest = false; context.program = 0; @@ -140,27 +139,26 @@ void Painter::renderDepthBuffer(PaintParameters& parameters) { context.rasterPos = { -1, -1, 0, 0 }; // Read the stencil buffer - const auto& fbSize = parameters.view.getFramebufferSize(); - auto pixels = std::make_unique<GLubyte[]>(fbSize[0] * fbSize[1]); + const auto viewport = context.viewport.getCurrentValue(); + auto pixels = std::make_unique<uint8_t[]>(viewport.width * viewport.height); 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 + viewport.x, // GLint x + viewport.y, // GLint y + viewport.width, // GLsizei width + viewport.height, // 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())); -#else - (void)parameters; + MBGL_CHECK_ERROR(glWindowPos2i(viewport.x, viewport.y)); + MBGL_CHECK_ERROR(glDrawPixels(viewport.width, viewport.height, GL_LUMINANCE, GL_UNSIGNED_BYTE, + pixels.get())); #endif // MBGL_USE_GLES2 } #endif // NDEBUG diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp index 1fc5f11079..b6606ca40b 100644 --- a/src/mbgl/renderer/painter_fill.cpp +++ b/src/mbgl/renderer/painter_fill.cpp @@ -30,7 +30,9 @@ void Painter::renderFill(PaintParameters& parameters, const bool isOutlineColorDefined = !properties.fillOutlineColor.isUndefined(); Color strokeColor = isOutlineColorDefined? properties.fillOutlineColor : fillColor; - auto worldSize = util::convert<GLfloat>(parameters.view.getFramebufferSize()); + const auto viewport = context.viewport.getCurrentValue(); + const std::array<GLfloat, 2> worldSize{ { static_cast<GLfloat>(viewport.width), + static_cast<GLfloat>(viewport.height) } }; bool pattern = !properties.fillPattern.value.from.empty(); bool outline = properties.fillAntialias && !pattern && isOutlineColorDefined; |