From 398ab663beec937d85c518c465770ffa0b8d38b4 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 9 Nov 2015 11:17:47 -0800 Subject: [core] Clean up Painter --- src/mbgl/renderer/painter.cpp | 83 +++++++++++++++---------------------------- src/mbgl/renderer/painter.hpp | 30 ++-------------- 2 files changed, 30 insertions(+), 83 deletions(-) (limited to 'src') diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index e4991b8086..f678414d0f 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -45,67 +45,30 @@ using namespace mbgl; Painter::Painter(MapData& data_, TransformState& state_) : data(data_), state(state_) { - setup(); -} - -Painter::~Painter() = default; - -bool Painter::needsAnimation() const { - return frameHistory.needsAnimation(data.getDefaultFadeDuration()); -} - -void Painter::setup() { gl::debugging::enable(); - setupShaders(); - - assert(iconShader); - assert(plainShader); - assert(outlineShader); - assert(lineShader); - assert(linepatternShader); - assert(patternShader); - assert(rasterShader); - assert(sdfGlyphShader); - assert(sdfIconShader); - assert(dotShader); - assert(circleShader); + plainShader = std::make_unique(); + outlineShader = std::make_unique(); + lineShader = std::make_unique(); + linesdfShader = std::make_unique(); + linepatternShader = std::make_unique(); + patternShader = std::make_unique(); + iconShader = std::make_unique(); + rasterShader = std::make_unique(); + sdfGlyphShader = std::make_unique(); + sdfIconShader = std::make_unique(); + dotShader = std::make_unique(); + collisionBoxShader = std::make_unique(); + circleShader = std::make_unique(); // Reset GL values config.reset(); } -void Painter::setupShaders() { - if (!plainShader) plainShader = std::make_unique(); - if (!outlineShader) outlineShader = std::make_unique(); - if (!lineShader) lineShader = std::make_unique(); - if (!linesdfShader) linesdfShader = std::make_unique(); - if (!linepatternShader) linepatternShader = std::make_unique(); - if (!patternShader) patternShader = std::make_unique(); - if (!iconShader) iconShader = std::make_unique(); - if (!rasterShader) rasterShader = std::make_unique(); - if (!sdfGlyphShader) sdfGlyphShader = std::make_unique(); - if (!sdfIconShader) sdfIconShader = std::make_unique(); - if (!dotShader) dotShader = std::make_unique(); - if (!collisionBoxShader) collisionBoxShader = std::make_unique(); - if (!circleShader) circleShader = std::make_unique(); -} - -void Painter::resize() { - config.viewport = { 0, 0, frame.framebufferSize[0], frame.framebufferSize[1] }; -} - -void Painter::changeMatrix() { - - state.getProjMatrix(projMatrix); - - // The extrusion matrix. - matrix::ortho(extrudeMatrix, 0, state.getWidth(), state.getHeight(), 0, 0, -1); +Painter::~Painter() = default; - // The native matrix is a 1:1 matrix that paints the coordinates at the - // same screen position as the vertex specifies. - matrix::identity(nativeMatrix); - matrix::multiply(nativeMatrix, projMatrix, nativeMatrix); +bool Painter::needsAnimation() const { + return frameHistory.needsAnimation(data.getDefaultFadeDuration()); } void Painter::prepareTile(const Tile& tile) { @@ -126,8 +89,18 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a const std::set& sources = renderData.sources; const Color& background = renderData.backgroundColor; - resize(); - changeMatrix(); + config.viewport = { 0, 0, frame.framebufferSize[0], frame.framebufferSize[1] }; + + // Update the default matrices to the current viewport dimensions. + state.getProjMatrix(projMatrix); + + // The extrusion matrix. + matrix::ortho(extrudeMatrix, 0, state.getWidth(), state.getHeight(), 0, 0, -1); + + // The native matrix is a 1:1 matrix that paints the coordinates at the + // same screen position as the vertex specifies. + matrix::identity(nativeMatrix); + matrix::multiply(nativeMatrix, projMatrix, nativeMatrix); // - UPLOAD PASS ------------------------------------------------------------------------------- // Uploads all required buffers and images before we do any actual rendering. diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp index 3a49b36183..7189bcc19b 100644 --- a/src/mbgl/renderer/painter.hpp +++ b/src/mbgl/renderer/painter.hpp @@ -34,7 +34,6 @@ class LineAtlas; class Source; struct FrameData; - class DebugBucket; class FillBucket; class FillLayer; @@ -48,8 +47,6 @@ class RasterBucket; class RasterLayer; class BackgroundLayer; -struct RasterProperties; - class SDFShader; class PlainShader; class OutlineShader; @@ -73,9 +70,6 @@ public: Painter(MapData&, TransformState&); ~Painter(); - // Updates the default matrices to the current viewport dimensions. - void changeMatrix(); - void render(const Style& style, const FrameData& frame, SpriteAtlas& annotationSpriteAtlas); @@ -98,29 +92,12 @@ public: float contrastFactor(float contrast); std::array spinWeights(float spin_value); - void preparePrerender(RasterBucket &bucket); - - void renderPrerenderedTexture(RasterBucket &bucket, const mat4 &matrix, const RasterProperties& properties); - - void createPrerendered(RasterBucket& bucket, const StyleLayer &layer_desc, const TileID& id); - - // Adjusts the dimensions of the OpenGL viewport - void resize(); - void drawClippingMasks(const std::set&); void drawClippingMask(const mat4& matrix, const ClipID& clip); - void resetFramebuffer(); - void bindFramebuffer(); - void pushFramebuffer(); - GLuint popFramebuffer(); - void discardFramebuffers(); - bool needsAnimation() const; private: - void setup(); - void setupShaders(); mat4 translatedMatrix(const mat4& matrix, const std::array &translation, const TileID &id, TranslateAnchorType anchor); std::vector determineRenderOrder(const Style& style); @@ -145,7 +122,6 @@ private: void setDepthSublayer(int n); -public: mat4 projMatrix; mat4 nativeMatrix; mat4 extrudeMatrix; @@ -164,7 +140,6 @@ public: return identity; }(); -private: MapData& data; TransformState& state; FrameData frame; @@ -180,13 +155,12 @@ private: float depthRangeSize; const float depthEpsilon = 1.0f / (1 << 16); -public: - FrameHistory frameHistory; - SpriteAtlas* spriteAtlas; GlyphAtlas* glyphAtlas; LineAtlas* lineAtlas; + FrameHistory frameHistory; + std::unique_ptr plainShader; std::unique_ptr outlineShader; std::unique_ptr lineShader; -- cgit v1.2.1