[core] render light
This commit is contained in:
committed by
Ivo van Dongen
parent
1c9af3226f
commit
20810f988a
@@ -212,6 +212,7 @@ set(MBGL_CORE_FILES
|
||||
src/mbgl/renderer/render_item.hpp
|
||||
src/mbgl/renderer/render_layer.cpp
|
||||
src/mbgl/renderer/render_layer.hpp
|
||||
src/mbgl/renderer/render_light.cpp
|
||||
src/mbgl/renderer/render_light.hpp
|
||||
src/mbgl/renderer/render_line_layer.cpp
|
||||
src/mbgl/renderer/render_line_layer.hpp
|
||||
|
||||
@@ -967,7 +967,7 @@ void Map::setLight(std::unique_ptr<style::Light> light) {
|
||||
return;
|
||||
}
|
||||
|
||||
impl->style->light = std::move(light);
|
||||
impl->style->setLight(std::move(light));
|
||||
}
|
||||
|
||||
style::Light* Map::getLight() {
|
||||
@@ -975,7 +975,7 @@ style::Light* Map::getLight() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return impl->style->light.get();
|
||||
return impl->style->getLight();
|
||||
}
|
||||
|
||||
#pragma mark - Defaults
|
||||
|
||||
@@ -144,7 +144,7 @@ void Painter::render(const Style& style, const FrameData& frame_, View& view, Sp
|
||||
spriteAtlas = style.spriteAtlas.get();
|
||||
lineAtlas = style.lineAtlas.get();
|
||||
|
||||
evaluatedLight = style.evaluatedLight;
|
||||
evaluatedLight = style.getRenderLight()->getEvaluated();
|
||||
|
||||
RenderData renderData = style.getRenderData(frame.debugOptions, state.getAngle());
|
||||
const std::vector<RenderItem>& order = renderData.order;
|
||||
|
||||
25
src/mbgl/renderer/render_light.cpp
Normal file
25
src/mbgl/renderer/render_light.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <mbgl/renderer/render_light.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
RenderLight::RenderLight(const style::Light light_)
|
||||
: light(std::move(light_)) {
|
||||
}
|
||||
|
||||
void RenderLight::transition(const CascadeParameters& parameters) {
|
||||
transitioning = TransitioningLight(light, std::move(transitioning), parameters);
|
||||
}
|
||||
|
||||
void RenderLight::evaluate(const PropertyEvaluationParameters& parameters) {
|
||||
evaluated = EvaluatedLight(transitioning, parameters);
|
||||
}
|
||||
|
||||
bool RenderLight::hasTransition() const {
|
||||
return transitioning.hasTransition();
|
||||
}
|
||||
|
||||
const EvaluatedLight& RenderLight::getEvaluated() const {
|
||||
return evaluated;
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
@@ -69,4 +69,22 @@ public:
|
||||
using TransitioningLight = Transitioning<style::LightProperties>;
|
||||
using EvaluatedLight = Evaluated<style::LightProperties>;
|
||||
|
||||
class Painter;
|
||||
|
||||
class RenderLight {
|
||||
public:
|
||||
RenderLight(const style::Light);
|
||||
|
||||
void transition(const CascadeParameters&);
|
||||
void evaluate(const PropertyEvaluationParameters&);
|
||||
bool hasTransition() const;
|
||||
|
||||
const EvaluatedLight& getEvaluated() const;
|
||||
|
||||
private:
|
||||
TransitioningLight transitioning;
|
||||
EvaluatedLight evaluated;
|
||||
style::Light light;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -59,6 +59,7 @@ Style::Style(Scheduler& scheduler_, FileSource& fileSource_, float pixelRatio)
|
||||
spriteAtlas(std::make_unique<SpriteAtlas>(Size{ 1024, 1024 }, pixelRatio)),
|
||||
lineAtlas(std::make_unique<LineAtlas>(Size{ 256, 512 })),
|
||||
light(std::make_unique<Light>()),
|
||||
renderLight(std::make_unique<RenderLight>(*light)),
|
||||
observer(&nullObserver) {
|
||||
glyphAtlas->setObserver(this);
|
||||
spriteAtlas->setObserver(this);
|
||||
@@ -147,7 +148,7 @@ void Style::setJSON(const std::string& json) {
|
||||
defaultZoom = parser.zoom;
|
||||
defaultBearing = parser.bearing;
|
||||
defaultPitch = parser.pitch;
|
||||
light = std::make_unique<Light>(parser.light);
|
||||
setLight(std::make_unique<Light>(parser.light));
|
||||
|
||||
glyphAtlas->setURL(parser.glyphURL);
|
||||
spriteAtlas->load(parser.spriteURL, scheduler, fileSource);
|
||||
@@ -310,6 +311,19 @@ void Style::removeRenderLayer(const std::string& id) {
|
||||
}
|
||||
}
|
||||
|
||||
void Style::setLight(std::unique_ptr<Light> light_) {
|
||||
light = std::move(light_);
|
||||
renderLight = std::make_unique<RenderLight>(*light);
|
||||
}
|
||||
|
||||
Light* Style::getLight() const {
|
||||
return light.get();
|
||||
}
|
||||
|
||||
RenderLight* Style::getRenderLight() const {
|
||||
return renderLight.get();
|
||||
}
|
||||
|
||||
std::string Style::getName() const {
|
||||
return name;
|
||||
}
|
||||
@@ -364,11 +378,11 @@ void Style::update(const UpdateParameters& parameters) {
|
||||
const bool evaluate = cascade || zoomChanged || parameters.updateFlags & Update::RecalculateStyle;
|
||||
|
||||
if (cascade) {
|
||||
transitioningLight = TransitioningLight(*light, std::move(transitioningLight), cascadeParameters);
|
||||
renderLight->transition(cascadeParameters);
|
||||
}
|
||||
|
||||
if (evaluate || transitioningLight.hasTransition()) {
|
||||
evaluatedLight = EvaluatedLight(transitioningLight, evaluationParameters);
|
||||
if (evaluate || renderLight->hasTransition()) {
|
||||
renderLight->evaluate(evaluationParameters);
|
||||
}
|
||||
|
||||
for (const auto& renderSource : renderSources) {
|
||||
@@ -443,7 +457,7 @@ RenderSource* Style::getRenderSource(const std::string& id) const {
|
||||
}
|
||||
|
||||
bool Style::hasTransitions() const {
|
||||
if (transitioningLight.hasTransition()) {
|
||||
if (renderLight->hasTransition()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -101,6 +101,10 @@ public:
|
||||
bool hasClass(const std::string&) const;
|
||||
std::vector<std::string> getClasses() const;
|
||||
|
||||
void setLight(std::unique_ptr<Light>);
|
||||
Light* getLight() const;
|
||||
RenderLight* getRenderLight() const;
|
||||
|
||||
RenderData getRenderData(MapDebugOptions, float angle) const;
|
||||
|
||||
std::vector<Feature> queryRenderedFeatures(const ScreenLineString& geometry,
|
||||
@@ -118,10 +122,6 @@ public:
|
||||
std::unique_ptr<SpriteAtlas> spriteAtlas;
|
||||
std::unique_ptr<LineAtlas> lineAtlas;
|
||||
|
||||
std::unique_ptr<Light> light;
|
||||
TransitioningLight transitioningLight;
|
||||
EvaluatedLight evaluatedLight;
|
||||
|
||||
RenderSource* getRenderSource(const std::string& id) const;
|
||||
|
||||
private:
|
||||
@@ -133,6 +133,9 @@ private:
|
||||
std::vector<std::string> classes;
|
||||
TransitionOptions transitionOptions;
|
||||
|
||||
std::unique_ptr<Light> light;
|
||||
std::unique_ptr<RenderLight> renderLight;
|
||||
|
||||
// Defaults
|
||||
std::string name;
|
||||
LatLng defaultLatLng;
|
||||
|
||||
Reference in New Issue
Block a user