Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
karimnaaji committed Jun 4, 2020
1 parent 6bd46c1 commit cb51b7c
Show file tree
Hide file tree
Showing 32 changed files with 294 additions and 106 deletions.
34 changes: 34 additions & 0 deletions platform/glfw/glfw_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <mbgl/util/logging.hpp>
#include <mbgl/util/platform.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/style/conversion/color_ramp_property_value.hpp>
#include <mbgl/style/conversion/json.hpp>

#include <mapbox/cheap_ruler.hpp>
#include <mapbox/geometry.hpp>
Expand Down Expand Up @@ -408,6 +410,38 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action,
case GLFW_KEY_T:
view->toggleCustomSource();
break;
case GLFW_KEY_V: {
using namespace mbgl;
using namespace mbgl::style;
auto &style = view->map->getStyle();
if (!style.getSource("line-gradient-source")) {
std::string url = "https://gist.githubusercontent.com/karimnaaji/0ea3016a825a4c2883fce309183f0c20/raw/9f67d55c3c797b8b1183dc27a26ec705ac619198/polylines.geojson";
GeoJSONOptions options;
options.lineMetrics = true;
auto source = std::make_unique<GeoJSONSource>("line-gradient-source", Immutable<GeoJSONOptions>(makeMutable<GeoJSONOptions>(options)));
source->setURL(url);
style.addSource(std::move(source));

mbgl::CameraOptions cameraOptions;
cameraOptions.center = mbgl::LatLng{38.888, -77.01866};
cameraOptions.zoom = 12.5;
cameraOptions.pitch = 0;
cameraOptions.bearing = 0;
view->map->jumpTo(cameraOptions);
}

if (!style.getLayer("line-gradient")) {
auto lineLayer = std::make_unique<LineLayer>("line-gradient", "line-gradient-source");
lineLayer->setLineWidth(PropertyValue<float>(14.0f));
std::string rawValue = R"JSON(["step",["line-progress"],"rgba(0, 0, 255, 0.1)",0.25,"red",0.6,"yellow"])JSON";
//std::string rawValue = R"JSON(["interpolate",["linear"],["line-progress"],0,"rgba(0, 0, 255, 0)",0.1,"royalblue",0.3,"cyan",0.5,"lime",0.7,"yellow",1,"red"])JSON";
conversion::Error error;
auto ramp = conversion::convertJSON<ColorRampPropertyValue>(rawValue, error);
lineLayer->setLineGradient(ramp.value());
style.addLayer(std::move(lineLayer));
}
}
break;
case GLFW_KEY_F: {
using namespace mbgl;
using namespace mbgl::style;
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/gfx/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Context {
static constexpr const uint32_t minimumRequiredVertexBindingCount = 8;
const uint32_t maximumVertexBindingCount;
bool supportsHalfFloatTextures = false;
static int32_t maxTextureSize;

public:
Context(Context&&) = delete;
Expand Down
9 changes: 8 additions & 1 deletion src/mbgl/gl/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
#include <cstring>

namespace mbgl {

namespace gfx {
int32_t Context::maxTextureSize;
} // namespace gfx

namespace gl {

using namespace platform;
Expand Down Expand Up @@ -65,7 +70,7 @@ Context::~Context() {
}
}

void Context::initializeExtensions(const std::function<gl::ProcAddress(const char*)>& getProcAddress) {
void Context::initialize(const std::function<gl::ProcAddress(const char*)>& getProcAddress) {
if (const auto* extensions =
reinterpret_cast<const char*>(MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS)))) {

Expand Down Expand Up @@ -123,6 +128,8 @@ void Context::initializeExtensions(const std::function<gl::ProcAddress(const cha
Log::Warning(Event::OpenGL, "Not using Vertex Array Objects");
}
}

MBGL_CHECK_ERROR(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &Context::maxTextureSize));
}

void Context::enableDebugging() {
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/gl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Context final : public gfx::Context {
gfx::RenderingStats& renderingStats();
const gfx::RenderingStats& renderingStats() const override;

void initializeExtensions(const std::function<gl::ProcAddress(const char*)>&);
void initialize(const std::function<gl::ProcAddress(const char*)>&);

void enableDebugging();

Expand Down
1 change: 1 addition & 0 deletions src/mbgl/gl/defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
#define GL_VERTEX_SHADER 0x8B31
#define GL_VIEWPORT 0x0BA2
#define GL_ZERO 0
#define GL_MAX_TEXTURE_SIZE 0x0D33
#ifdef MBGL_USE_GLES2
#define GL_HALF_FLOAT 0x8D61
#else
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/gl/renderer_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RendererBackend::RendererBackend(const gfx::ContextMode contextMode_)
std::unique_ptr<gfx::Context> RendererBackend::createContext() {
auto result = std::make_unique<gl::Context>(*this);
result->enableDebugging();
result->initializeExtensions(
result->initialize(
std::bind(&RendererBackend::getExtensionFunctionPointer, this, std::placeholders::_1));
return result;
}
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/programs/collision_box_program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CollisionBoxProgram : public Program<
const gfx::VertexBuffer<gfx::Vertex<CollisionBoxLayoutAttributes>>& layoutVertexBuffer,
const gfx::VertexBuffer<gfx::Vertex<CollisionBoxDynamicAttributes>>& dynamicVertexBuffer,
const gfx::IndexBuffer& indexBuffer,
const SegmentVector<AttributeList>& segments,
const SegmentVector& segments,
const Binders& paintPropertyBinders,
const typename PaintProperties::PossiblyEvaluated& currentProperties,
const TextureBindings& textureBindings,
Expand Down Expand Up @@ -152,7 +152,7 @@ class CollisionCircleProgram : public Program<
const gfx::VertexBuffer<gfx::Vertex<CollisionBoxLayoutAttributes>>& layoutVertexBuffer,
const gfx::VertexBuffer<gfx::Vertex<CollisionBoxDynamicAttributes>>& dynamicVertexBuffer,
const gfx::IndexBuffer& indexBuffer,
const SegmentVector<AttributeList>& segments,
const SegmentVector& segments,
const Binders& paintPropertyBinders,
const typename PaintProperties::PossiblyEvaluated& currentProperties,
const TextureBindings& textureBindings,
Expand Down
6 changes: 4 additions & 2 deletions src/mbgl/programs/line_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,15 @@ LineGradientProgram::LayoutUniformValues LineGradientProgram::layoutUniformValue
const RenderTile& tile,
const TransformState& state,
const std::array<float, 2>& pixelsToGLUnits,
const float pixelRatio) {
const float pixelRatio,
const float imageHeight) {
return makeValues<LineGradientProgram::LayoutUniformValues>(
properties,
tile,
state,
pixelsToGLUnits,
pixelRatio
pixelRatio,
imageHeight
);
}

Expand Down
38 changes: 32 additions & 6 deletions src/mbgl/programs/line_program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,24 @@ MBGL_DEFINE_UNIFORM_SCALAR(float, sdfgamma);
MBGL_DEFINE_UNIFORM_VECTOR(float, 2, patternscale_a);
MBGL_DEFINE_UNIFORM_VECTOR(float, 2, patternscale_b);
MBGL_DEFINE_UNIFORM_VECTOR(float, 2, units_to_pixels);
MBGL_DEFINE_UNIFORM_SCALAR(float, image_height);
} // namespace uniforms

namespace attributes {
MBGL_DEFINE_ATTRIBUTE(float, 1, line_progress);
MBGL_DEFINE_ATTRIBUTE(float, 1, line_clip);
MBGL_DEFINE_ATTRIBUTE(uint32_t, 1, split_index);
} // namespace attributes

using LineLayoutAttributes = TypeList<
attributes::pos_normal,
attributes::data<uint8_t, 4>>;

using LineLayoutAttributesExt = TypeList<
attributes::line_progress,
attributes::line_clip,
attributes::split_index>;

class LineProgram : public Program<
LineProgram,
gfx::PrimitiveType::Triangle,
Expand Down Expand Up @@ -157,6 +169,10 @@ class LineSDFProgram : public Program<
float atlasWidth);
};

using LineLayoutVertex = LineProgram::LayoutVertex;
using LineAttributes = LineProgram::AttributeList;
using LineLayoutVertexExt = gfx::Vertex<LineLayoutAttributesExt>;

class LineGradientProgram : public Program<
LineGradientProgram,
gfx::PrimitiveType::Triangle,
Expand All @@ -165,10 +181,12 @@ class LineGradientProgram : public Program<
uniforms::matrix,
uniforms::ratio,
uniforms::units_to_pixels,
uniforms::device_pixel_ratio>,
uniforms::device_pixel_ratio,
uniforms::image_height>,
TypeList<
textures::image>,
style::LinePaintProperties>
style::LinePaintProperties,
LineLayoutAttributesExt>
{
public:
using Program::Program;
Expand All @@ -177,12 +195,20 @@ class LineGradientProgram : public Program<
const RenderTile&,
const TransformState&,
const std::array<float, 2>& pixelsToGLUnits,
float pixelRatio);
float pixelRatio,
float imageHeight);

static AttributeBindings computeAllAttributeBindings(
const gfx::VertexBuffer<LineProgram::LayoutVertex>& layoutVertexBuffer,
const gfx::VertexBuffer<gfx::Vertex<LineLayoutAttributesExt>>& layoutVertexBufferExt,
const Binders& paintPropertyBinders,
const typename PaintProperties::PossiblyEvaluated& currentProperties) {
return gfx::AttributeBindings<LineLayoutAttributes>(layoutVertexBuffer)
.concat(paintPropertyBinders.attributeBindings(currentProperties))
.concat(gfx::AttributeBindings<LineLayoutAttributesExt>(layoutVertexBufferExt));
}
};

using LineLayoutVertex = LineProgram::LayoutVertex;
using LineAttributes = LineProgram::AttributeList;

class LineLayerPrograms final : public LayerTypePrograms {
public:
LineLayerPrograms(gfx::Context& context, const ProgramParameters& programParameters)
Expand Down
9 changes: 5 additions & 4 deletions src/mbgl/programs/program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ template <class Name,
class LayoutAttributeList,
class LayoutUniformList,
class Textures,
class PaintProps>
class PaintProps,
class LayoutAttributeListExt = TypeList<>>
class Program {
public:
using LayoutVertex = gfx::Vertex<LayoutAttributeList>;
Expand All @@ -32,7 +33,7 @@ class Program {
using Binders = PaintPropertyBinders<typename PaintProperties::DataDrivenProperties>;

using PaintAttributeList = typename Binders::AttributeList;
using AttributeList = TypeListConcat<LayoutAttributeList, PaintAttributeList>;
using AttributeList = TypeListConcat<LayoutAttributeList, PaintAttributeList, LayoutAttributeListExt>;
using AttributeBindings = gfx::AttributeBindings<AttributeList>;

using PaintUniformList = typename Binders::UniformList;
Expand Down Expand Up @@ -79,7 +80,7 @@ class Program {
const gfx::ColorMode& colorMode,
const gfx::CullFaceMode& cullFaceMode,
const gfx::IndexBuffer& indexBuffer,
const Segment<AttributeList>& segment,
const Segment& segment,
const UniformValues& uniformValues,
const AttributeBindings& allAttributeBindings,
const TextureBindings& textureBindings,
Expand Down Expand Up @@ -120,7 +121,7 @@ class Program {
const gfx::ColorMode& colorMode,
const gfx::CullFaceMode& cullFaceMode,
const gfx::IndexBuffer& indexBuffer,
const SegmentVector<AttributeList>& segments,
const SegmentVector& segments,
const UniformValues& uniformValues,
const AttributeBindings& allAttributeBindings,
const TextureBindings& textureBindings,
Expand Down
4 changes: 1 addition & 3 deletions src/mbgl/programs/segment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace mbgl {

template <class AttributeList>
class Segment {
public:
Segment(std::size_t vertexOffset_,
Expand Down Expand Up @@ -47,7 +46,6 @@ class Segment {
float sortKey;
};

template <class AttributeList>
using SegmentVector = std::vector<Segment<AttributeList>>;
using SegmentVector = std::vector<Segment>;

} // namespace mbgl
4 changes: 2 additions & 2 deletions src/mbgl/programs/symbol_program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ class SymbolProgram : public SymbolProgramBase {
const gfx::ColorMode& colorMode,
const gfx::CullFaceMode& cullFaceMode,
const gfx::IndexBuffer& indexBuffer,
const Segment<AttributeList>& segment,
const Segment& segment,
const UniformValues& uniformValues,
const AttributeBindings& allAttributeBindings,
const TextureBindings& textureBindings,
Expand Down Expand Up @@ -353,7 +353,7 @@ class SymbolProgram : public SymbolProgramBase {
const gfx::ColorMode& colorMode,
const gfx::CullFaceMode& cullFaceMode,
const gfx::IndexBuffer& indexBuffer,
const SegmentVector<AttributeList>& segments,
const SegmentVector& segments,
const UniformValues& uniformValues,
const AttributeBindings& allAttributeBindings,
const TextureBindings& textureBindings,
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/buckets/circle_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CircleBucket final : public Bucket {

gfx::VertexVector<CircleLayoutVertex> vertices;
gfx::IndexVector<gfx::Triangles> triangles;
SegmentVector<CircleAttributes> segments;
SegmentVector segments;

optional<gfx::VertexBuffer<CircleLayoutVertex>> vertexBuffer;
optional<gfx::IndexBuffer> indexBuffer;
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/renderer/buckets/debug_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class DebugBucket : private util::noncopyable {
gfx::VertexVector<FillLayoutVertex> vertices;
gfx::IndexVector<gfx::Lines> indices;

SegmentVector<DebugAttributes> segments;
SegmentVector<DebugAttributes> tileBorderSegments;
SegmentVector segments;
SegmentVector tileBorderSegments;
optional<gfx::VertexBuffer<DebugLayoutVertex>> vertexBuffer;
optional<gfx::IndexBuffer> indexBuffer;
optional<gfx::Texture> texture;
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/renderer/buckets/fill_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class FillBucket final : public Bucket {
gfx::VertexVector<FillLayoutVertex> vertices;
gfx::IndexVector<gfx::Lines> lines;
gfx::IndexVector<gfx::Triangles> triangles;
SegmentVector<FillAttributes> lineSegments;
SegmentVector<FillAttributes> triangleSegments;
SegmentVector lineSegments;
SegmentVector triangleSegments;

optional<gfx::VertexBuffer<FillLayoutVertex>> vertexBuffer;
optional<gfx::IndexBuffer> lineIndexBuffer;
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class FillExtrusionBucket final : public Bucket {

gfx::VertexVector<FillExtrusionLayoutVertex> vertices;
gfx::IndexVector<gfx::Triangles> triangles;
SegmentVector<FillExtrusionAttributes> triangleSegments;
SegmentVector triangleSegments;

optional<gfx::VertexBuffer<FillExtrusionLayoutVertex>> vertexBuffer;
optional<gfx::IndexBuffer> indexBuffer;
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/buckets/heatmap_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class HeatmapBucket final : public Bucket {

gfx::VertexVector<HeatmapLayoutVertex> vertices;
gfx::IndexVector<gfx::Triangles> triangles;
SegmentVector<HeatmapAttributes> segments;
SegmentVector segments;

optional<gfx::VertexBuffer<HeatmapLayoutVertex>> vertexBuffer;
optional<gfx::IndexBuffer> indexBuffer;
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/buckets/hillshade_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class HillshadeBucket final : public Bucket {
// Raster-DEM Tile Sources use the default buffers from Painter
gfx::VertexVector<HillshadeLayoutVertex> vertices;
gfx::IndexVector<gfx::Triangles> indices;
SegmentVector<HillshadeAttributes> segments;
SegmentVector segments;

optional<gfx::VertexBuffer<HillshadeLayoutVertex>> vertexBuffer;
optional<gfx::IndexBuffer> indexBuffer;
Expand Down
Loading

0 comments on commit cb51b7c

Please sign in to comment.