[core] Clean up Painter
This commit is contained in:
@@ -45,7 +45,24 @@ using namespace mbgl;
|
||||
|
||||
Painter::Painter(MapData& data_, TransformState& state_)
|
||||
: data(data_), state(state_) {
|
||||
setup();
|
||||
gl::debugging::enable();
|
||||
|
||||
plainShader = std::make_unique<PlainShader>();
|
||||
outlineShader = std::make_unique<OutlineShader>();
|
||||
lineShader = std::make_unique<LineShader>();
|
||||
linesdfShader = std::make_unique<LineSDFShader>();
|
||||
linepatternShader = std::make_unique<LinepatternShader>();
|
||||
patternShader = std::make_unique<PatternShader>();
|
||||
iconShader = std::make_unique<IconShader>();
|
||||
rasterShader = std::make_unique<RasterShader>();
|
||||
sdfGlyphShader = std::make_unique<SDFGlyphShader>();
|
||||
sdfIconShader = std::make_unique<SDFIconShader>();
|
||||
dotShader = std::make_unique<DotShader>();
|
||||
collisionBoxShader = std::make_unique<CollisionBoxShader>();
|
||||
circleShader = std::make_unique<CircleShader>();
|
||||
|
||||
// Reset GL values
|
||||
config.reset();
|
||||
}
|
||||
|
||||
Painter::~Painter() = default;
|
||||
@@ -54,60 +71,6 @@ 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);
|
||||
|
||||
// Reset GL values
|
||||
config.reset();
|
||||
}
|
||||
|
||||
void Painter::setupShaders() {
|
||||
if (!plainShader) plainShader = std::make_unique<PlainShader>();
|
||||
if (!outlineShader) outlineShader = std::make_unique<OutlineShader>();
|
||||
if (!lineShader) lineShader = std::make_unique<LineShader>();
|
||||
if (!linesdfShader) linesdfShader = std::make_unique<LineSDFShader>();
|
||||
if (!linepatternShader) linepatternShader = std::make_unique<LinepatternShader>();
|
||||
if (!patternShader) patternShader = std::make_unique<PatternShader>();
|
||||
if (!iconShader) iconShader = std::make_unique<IconShader>();
|
||||
if (!rasterShader) rasterShader = std::make_unique<RasterShader>();
|
||||
if (!sdfGlyphShader) sdfGlyphShader = std::make_unique<SDFGlyphShader>();
|
||||
if (!sdfIconShader) sdfIconShader = std::make_unique<SDFIconShader>();
|
||||
if (!dotShader) dotShader = std::make_unique<DotShader>();
|
||||
if (!collisionBoxShader) collisionBoxShader = std::make_unique<CollisionBoxShader>();
|
||||
if (!circleShader) circleShader = std::make_unique<CircleShader>();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
void Painter::prepareTile(const Tile& tile) {
|
||||
const GLint ref = (GLint)tile.clip.reference.to_ulong();
|
||||
const GLuint mask = (GLuint)tile.clip.mask.to_ulong();
|
||||
@@ -126,8 +89,18 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a
|
||||
const std::set<Source*>& 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.
|
||||
|
||||
@@ -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<float, 3> 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<Source*>&);
|
||||
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<float, 2> &translation, const TileID &id, TranslateAnchorType anchor);
|
||||
|
||||
std::vector<RenderItem> 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> plainShader;
|
||||
std::unique_ptr<OutlineShader> outlineShader;
|
||||
std::unique_ptr<LineShader> lineShader;
|
||||
|
||||
Reference in New Issue
Block a user