summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-07-18 10:41:07 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-07-19 09:31:07 -0700
commit3787d3a048b4c9c1d9664e62e7a26dca9c26da6b (patch)
tree0c7ea33e7e927ff8b785ae627e9920e18130efe5 /src
parent0d951f39b6ca815780605d973e744e5aab3b1129 (diff)
downloadqtlocation-mapboxgl-3787d3a048b4c9c1d9664e62e7a26dca9c26da6b.tar.gz
[core] Inline Painter::renderLine and RenderImageSource::render
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/renderer/layers/render_raster_layer.cpp110
-rw-r--r--src/mbgl/renderer/painter.hpp3
-rw-r--r--src/mbgl/renderer/painters/painter_raster.cpp90
-rw-r--r--src/mbgl/renderer/sources/render_image_source.cpp10
-rw-r--r--src/mbgl/renderer/sources/render_image_source.hpp5
5 files changed, 102 insertions, 116 deletions
diff --git a/src/mbgl/renderer/layers/render_raster_layer.cpp b/src/mbgl/renderer/layers/render_raster_layer.cpp
index b678398eca..349646c281 100644
--- a/src/mbgl/renderer/layers/render_raster_layer.cpp
+++ b/src/mbgl/renderer/layers/render_raster_layer.cpp
@@ -2,12 +2,17 @@
#include <mbgl/renderer/buckets/raster_bucket.hpp>
#include <mbgl/renderer/painter.hpp>
#include <mbgl/renderer/render_tile.hpp>
-#include <mbgl/tile/tile.hpp>
+#include <mbgl/renderer/paint_parameters.hpp>
#include <mbgl/renderer/sources/render_image_source.hpp>
+#include <mbgl/programs/programs.hpp>
+#include <mbgl/programs/raster_program.hpp>
+#include <mbgl/tile/tile.hpp>
#include <mbgl/style/layers/raster_layer_impl.hpp>
namespace mbgl {
+using namespace style;
+
RenderRasterLayer::RenderRasterLayer(Immutable<style::RasterLayer::Impl> _impl)
: RenderLayer(style::LayerType::Raster, _impl),
unevaluated(impl().paint.untransitioned()) {
@@ -36,19 +41,104 @@ bool RenderRasterLayer::hasTransition() const {
return unevaluated.hasTransition();
}
+static float saturationFactor(float saturation) {
+ if (saturation > 0) {
+ return 1 - 1 / (1.001 - saturation);
+ } else {
+ return -saturation;
+ }
+}
+
+static float contrastFactor(float contrast) {
+ if (contrast > 0) {
+ return 1 / (1 - contrast);
+ } else {
+ return 1 + contrast;
+ }
+}
+
+static std::array<float, 3> spinWeights(float spin) {
+ spin *= util::DEG2RAD;
+ float s = std::sin(spin);
+ float c = std::cos(spin);
+ std::array<float, 3> spin_weights = {{
+ (2 * c + 1) / 3,
+ (-std::sqrt(3.0f) * s - c + 1) / 3,
+ (std::sqrt(3.0f) * s - c + 1) / 3
+ }};
+ return spin_weights;
+}
+
void RenderRasterLayer::render(Painter& painter, PaintParameters& parameters, RenderSource* source) {
+ if (painter.pass != RenderPass::Translucent)
+ return;
+
+ auto draw = [&] (const mat4& matrix,
+ const auto& vertexBuffer,
+ const auto& indexBuffer,
+ const auto& segments) {
+ parameters.programs.raster.draw(
+ painter.context,
+ gl::Triangles(),
+ painter.depthModeForSublayer(0, gl::DepthMode::ReadOnly),
+ gl::StencilMode::disabled(),
+ painter.colorModeForRenderPass(),
+ RasterProgram::UniformValues {
+ uniforms::u_matrix::Value{ matrix },
+ uniforms::u_image0::Value{ 0 },
+ uniforms::u_image1::Value{ 1 },
+ uniforms::u_opacity::Value{ evaluated.get<RasterOpacity>() },
+ uniforms::u_fade_t::Value{ 1 },
+ uniforms::u_brightness_low::Value{ evaluated.get<RasterBrightnessMin>() },
+ uniforms::u_brightness_high::Value{ evaluated.get<RasterBrightnessMax>() },
+ uniforms::u_saturation_factor::Value{ saturationFactor(evaluated.get<RasterSaturation>()) },
+ uniforms::u_contrast_factor::Value{ contrastFactor(evaluated.get<RasterContrast>()) },
+ uniforms::u_spin_weights::Value{ spinWeights(evaluated.get<RasterHueRotate>()) },
+ uniforms::u_buffer_scale::Value{ 1.0f },
+ uniforms::u_scale_parent::Value{ 1.0f },
+ uniforms::u_tl_parent::Value{ std::array<float, 2> {{ 0.0f, 0.0f }} },
+ },
+ vertexBuffer,
+ indexBuffer,
+ segments,
+ RasterProgram::PaintPropertyBinders { evaluated, 0 },
+ evaluated,
+ painter.state.getZoom(),
+ getID()
+ );
+ };
+
if (RenderImageSource* imageSource = source->as<RenderImageSource>()) {
- imageSource->render(painter, parameters, *this);
+ if (imageSource->isEnabled() && imageSource->isLoaded() && !imageSource->bucket->needsUpload()) {
+ RasterBucket& bucket = *imageSource->bucket;
+
+ assert(bucket.texture);
+ painter.context.bindTexture(*bucket.texture, 0, gl::TextureFilter::Linear);
+ painter.context.bindTexture(*bucket.texture, 1, gl::TextureFilter::Linear);
+
+ for (auto matrix_ : imageSource->matrices) {
+ draw(matrix_,
+ *bucket.vertexBuffer,
+ *bucket.indexBuffer,
+ bucket.segments);
+ }
+ }
} else {
for (const RenderTile& tile : renderTiles) {
- Bucket* bucket = tile.tile.getBucket(*baseImpl);
- assert(dynamic_cast<RasterBucket*>(bucket));
- painter.renderRaster(
- parameters,
- *reinterpret_cast<RasterBucket*>(bucket),
- *this,
- tile.matrix,
- false);
+ assert(dynamic_cast<RasterBucket*>(tile.tile.getBucket(*baseImpl)));
+ RasterBucket& bucket = *reinterpret_cast<RasterBucket*>(tile.tile.getBucket(*baseImpl));
+
+ if (!bucket.hasData())
+ continue;
+
+ assert(bucket.texture);
+ painter.context.bindTexture(*bucket.texture, 0, gl::TextureFilter::Linear);
+ painter.context.bindTexture(*bucket.texture, 1, gl::TextureFilter::Linear);
+
+ draw(tile.matrix,
+ painter.rasterVertexBuffer,
+ painter.quadTriangleIndexBuffer,
+ painter.rasterSegments);
}
}
}
diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp
index 60b03a16a9..d210ce58d1 100644
--- a/src/mbgl/renderer/painter.hpp
+++ b/src/mbgl/renderer/painter.hpp
@@ -40,10 +40,8 @@ class Tile;
class DebugBucket;
class SymbolBucket;
-class RasterBucket;
class RenderSymbolLayer;
-class RenderRasterLayer;
class Programs;
class PaintParameters;
@@ -74,7 +72,6 @@ public:
void renderTileDebug(const RenderTile&);
void renderTileDebug(const mat4& matrix);
void renderSymbol(PaintParameters&, SymbolBucket&, const RenderSymbolLayer&, const RenderTile&);
- void renderRaster(PaintParameters&, RasterBucket&, const RenderRasterLayer&, const mat4&, bool useBucketBuffers /* = false */);
void renderItem(PaintParameters&, const RenderItem&);
diff --git a/src/mbgl/renderer/painters/painter_raster.cpp b/src/mbgl/renderer/painters/painter_raster.cpp
deleted file mode 100644
index d0ab480616..0000000000
--- a/src/mbgl/renderer/painters/painter_raster.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-#include <mbgl/renderer/painter.hpp>
-#include <mbgl/renderer/paint_parameters.hpp>
-#include <mbgl/renderer/render_tile.hpp>
-#include <mbgl/renderer/buckets/raster_bucket.hpp>
-#include <mbgl/renderer/layers/render_raster_layer.hpp>
-#include <mbgl/style/layers/raster_layer_impl.hpp>
-#include <mbgl/programs/programs.hpp>
-#include <mbgl/programs/raster_program.hpp>
-
-namespace mbgl {
-
-using namespace style;
-
-static float saturationFactor(float saturation) {
- if (saturation > 0) {
- return 1 - 1 / (1.001 - saturation);
- } else {
- return -saturation;
- }
-}
-
-static float contrastFactor(float contrast) {
- if (contrast > 0) {
- return 1 / (1 - contrast);
- } else {
- return 1 + contrast;
- }
-}
-
-static std::array<float, 3> spinWeights(float spin) {
- spin *= util::DEG2RAD;
- float s = std::sin(spin);
- float c = std::cos(spin);
- std::array<float, 3> spin_weights = {{
- (2 * c + 1) / 3,
- (-std::sqrt(3.0f) * s - c + 1) / 3,
- (std::sqrt(3.0f) * s - c + 1) / 3
- }};
- return spin_weights;
-}
-
-void Painter::renderRaster(PaintParameters& parameters,
- RasterBucket& bucket,
- const RenderRasterLayer& layer,
- const mat4& matrix,
- bool useBucketBuffers = false) {
- if (pass != RenderPass::Translucent)
- return;
- if (!bucket.hasData())
- return;
-
- const RasterPaintProperties::PossiblyEvaluated& properties = layer.evaluated;
- const RasterProgram::PaintPropertyBinders paintAttributeData(properties, 0);
-
- assert(bucket.texture);
- context.bindTexture(*bucket.texture, 0, gl::TextureFilter::Linear);
- context.bindTexture(*bucket.texture, 1, gl::TextureFilter::Linear);
-
- parameters.programs.raster.draw(
- context,
- gl::Triangles(),
- depthModeForSublayer(0, gl::DepthMode::ReadOnly),
- gl::StencilMode::disabled(),
- colorModeForRenderPass(),
- RasterProgram::UniformValues {
- uniforms::u_matrix::Value{ matrix },
- uniforms::u_image0::Value{ 0 },
- uniforms::u_image1::Value{ 1 },
- uniforms::u_opacity::Value{ properties.get<RasterOpacity>() },
- uniforms::u_fade_t::Value{ 1 },
- uniforms::u_brightness_low::Value{ properties.get<RasterBrightnessMin>() },
- uniforms::u_brightness_high::Value{ properties.get<RasterBrightnessMax>() },
- uniforms::u_saturation_factor::Value{ saturationFactor(properties.get<RasterSaturation>()) },
- uniforms::u_contrast_factor::Value{ contrastFactor(properties.get<RasterContrast>()) },
- uniforms::u_spin_weights::Value{ spinWeights(properties.get<RasterHueRotate>()) },
- uniforms::u_buffer_scale::Value{ 1.0f },
- uniforms::u_scale_parent::Value{ 1.0f },
- uniforms::u_tl_parent::Value{ std::array<float, 2> {{ 0.0f, 0.0f }} },
- },
- useBucketBuffers ? *bucket.vertexBuffer : rasterVertexBuffer,
- useBucketBuffers ? *bucket.indexBuffer : quadTriangleIndexBuffer,
- useBucketBuffers ? bucket.segments : rasterSegments,
- paintAttributeData,
- properties,
- state.getZoom(),
- layer.getID()
- );
-}
-
-} // namespace mbgl
diff --git a/src/mbgl/renderer/sources/render_image_source.cpp b/src/mbgl/renderer/sources/render_image_source.cpp
index f654b83884..1cb3d9d1ba 100644
--- a/src/mbgl/renderer/sources/render_image_source.cpp
+++ b/src/mbgl/renderer/sources/render_image_source.cpp
@@ -182,16 +182,6 @@ void RenderImageSource::update(Immutable<style::Source::Impl> baseImpl_,
bucket->segments.emplace_back(0, 0, 4, 6);
}
-void RenderImageSource::render(Painter& painter,
- PaintParameters& parameters,
- const RenderRasterLayer& layer) {
- if (isEnabled() && isLoaded() && !bucket->needsUpload()) {
- for (auto matrix : matrices) {
- painter.renderRaster(parameters, *bucket, layer, matrix, true);
- }
- }
-}
-
void RenderImageSource::dumpDebugLogs() const {
Log::Info(Event::General, "RenderImageSource::id: %s", impl().id.c_str());
Log::Info(Event::General, "RenderImageSource::loaded: %s", isLoaded() ? "yes" : "no");
diff --git a/src/mbgl/renderer/sources/render_image_source.hpp b/src/mbgl/renderer/sources/render_image_source.hpp
index 6deffca046..14e4696f5a 100644
--- a/src/mbgl/renderer/sources/render_image_source.hpp
+++ b/src/mbgl/renderer/sources/render_image_source.hpp
@@ -6,8 +6,6 @@
namespace mbgl {
-class RenderRasterLayer;
-class PaintParameters;
class RasterBucket;
class RenderImageSource : public RenderSource {
@@ -18,7 +16,6 @@ public:
bool isLoaded() const final;
void startRender(Painter&) final;
- void render(Painter&, PaintParameters&, const RenderRasterLayer&);
void finishRender(Painter&) final;
void update(Immutable<style::Source::Impl>,
@@ -44,6 +41,8 @@ public:
void dumpDebugLogs() const final;
private:
+ friend class RenderRasterLayer;
+
const style::ImageSource::Impl& impl() const;
std::vector<UnwrappedTileID> tileIds;