#ifndef MBGL_RENDERER_PAINTER #define MBGL_RENDERER_PAINTER #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace mbgl { class Style; class StyleLayer; class Tile; class SpriteAtlas; class GlyphAtlas; class LineAtlas; class Source; struct FrameData; class DebugBucket; class FillBucket; class FillLayer; class LineBucket; class LineLayer; class CircleBucket; class CircleLayer; class SymbolBucket; class SymbolLayer; class RasterBucket; class RasterLayer; class BackgroundLayer; struct RasterProperties; class SDFShader; class PlainShader; class OutlineShader; class LineShader; class LinejoinShader; class LineSDFShader; class LinepatternShader; class CircleShader; class PatternShader; class IconShader; class RasterShader; class SDFGlyphShader; class SDFIconShader; class DotShader; class CollisionBoxShader; struct ClipID; class Painter : private util::noncopyable { 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); // Renders debug information for a tile. void renderTileDebug(const Tile& tile); // Renders the red debug frame around a tile, visualizing its perimeter. void renderDebugFrame(const mat4 &matrix); void renderDebugText(TileData&, const mat4&); void renderFill(FillBucket&, const FillLayer&, const TileID&, const mat4&); void renderLine(LineBucket&, const LineLayer&, const TileID&, const mat4&); void renderCircle(CircleBucket&, const CircleLayer&, const TileID&, const mat4&); void renderSymbol(SymbolBucket&, const SymbolLayer&, const TileID&, const mat4&); void renderRaster(RasterBucket&, const RasterLayer&, const TileID&, const mat4&); void renderBackground(const BackgroundLayer&); float saturationFactor(float saturation); 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); template void renderPass(RenderPass, Iterator it, Iterator end, GLsizei i, int8_t increment); void prepareTile(const Tile& tile); template void renderSDF(SymbolBucket &bucket, const TileID &id, const mat4 &matrixSymbol, const BucketProperties& bucketProperties, const StyleProperties& styleProperties, float scaleDivisor, std::array texsize, SDFShader& sdfShader, void (SymbolBucket::*drawSDF)(SDFShader&)); void setDepthSublayer(int n); public: mat4 projMatrix; mat4 nativeMatrix; mat4 extrudeMatrix; // used to composite images and flips the geometry upside down const mat4 flipMatrix = []{ mat4 flip; matrix::ortho(flip, 0, 4096, -4096, 0, 0, 1); matrix::translate(flip, flip, 0, -4096, 0); return flip; }(); const mat4 identityMatrix = []{ mat4 identity; matrix::identity(identity); return identity; }(); private: MapData& data; TransformState& state; FrameData frame; int indent = 0; gl::Config config; RenderPass pass = RenderPass::Opaque; int numSublayers = 3; GLsizei currentLayer; float depthRangeSize; const float depthEpsilon = 1.0f / (1 << 16); public: FrameHistory frameHistory; SpriteAtlas* spriteAtlas; GlyphAtlas* glyphAtlas; LineAtlas* lineAtlas; std::unique_ptr plainShader; std::unique_ptr outlineShader; std::unique_ptr lineShader; std::unique_ptr linesdfShader; std::unique_ptr linepatternShader; std::unique_ptr patternShader; std::unique_ptr iconShader; std::unique_ptr rasterShader; std::unique_ptr sdfGlyphShader; std::unique_ptr sdfIconShader; std::unique_ptr dotShader; std::unique_ptr collisionBoxShader; std::unique_ptr circleShader; StaticVertexBuffer backgroundBuffer = { { -1, -1 }, { 1, -1 }, { -1, 1 }, { 1, 1 } }; VertexArrayObject backgroundArray; // Set up the stencil quad we're using to generate the stencil mask. StaticVertexBuffer tileStencilBuffer = { // top left triangle { 0, 0 }, { 4096, 0 }, { 0, 4096 }, // bottom right triangle { 4096, 0 }, { 0, 4096 }, { 4096, 4096 }, }; VertexArrayObject coveringPlainArray; VertexArrayObject coveringRasterArray; // Set up the tile boundary lines we're using to draw the tile outlines. StaticVertexBuffer tileBorderBuffer = { { 0, 0 }, { 4096, 0 }, { 4096, 4096 }, { 0, 4096 }, { 0, 0 }, }; VertexArrayObject tileBorderArray; }; } #endif