diff --git a/CMakeLists.txt b/CMakeLists.txt index ad989ba8386..2e6899bf61f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,11 @@ option(MBGL_WITH_SANITIZER "Use [address|thread|undefined] here" OFF) option(MBGL_WITH_RTTI "Compile with runtime type information" OFF) option(MBGL_WITH_OPENGL "Build with OpenGL renderer" ON) option(MBGL_WITH_WERROR "Make all compilation warnings errors" ON) +option(MBGL_WITH_GLES2 "Build with GLES2" OFF) + +if(MBGL_WITH_GLES2) + add_compile_definitions(MBGL_USE_GLES2) +endif() add_library( mbgl-compiler-options INTERFACE @@ -57,6 +62,7 @@ target_compile_options( $<$:-Wno-error=maybe-uninitialized> $<$:-Wno-error=return-type> $<$:-Wno-error=unknown-pragmas> + $<$:-Wno-error=type-limits> $<$:-Wno-error=deprecated-declarations> $<$:-Wno-error=unused-parameter> $<$:-Wno-error=unused-property-ivar> diff --git a/platform/glfw/CMakeLists.txt b/platform/glfw/CMakeLists.txt index 986d3b01313..e8b0b0f96b1 100644 --- a/platform/glfw/CMakeLists.txt +++ b/platform/glfw/CMakeLists.txt @@ -3,6 +3,15 @@ find_package(PkgConfig REQUIRED) pkg_search_module(GLFW glfw3 REQUIRED) +# build glfw3 with GLFW_USE_WAYLAND=ON +if(CMAKE_SYSTEM_NAME STREQUAL Linux) + pkg_check_modules(WAYLAND + wayland-client>=0.2.7 + wayland-cursor>=0.2.7 + wayland-egl>=0.2.7 + xkbcommon) +endif() + add_executable( mbgl-glfw ${PROJECT_SOURCE_DIR}/platform/glfw/main.cpp @@ -53,6 +62,7 @@ target_link_libraries( Mapbox::Map mbgl-compiler-options Mapbox::Base::cheap-ruler-cpp + ${WAYLAND_LINK_LIBRARIES} ) if(MBGL_WITH_OPENGL) @@ -62,6 +72,20 @@ if(MBGL_WITH_OPENGL) ) endif() +if(MBGL_WITH_GLES2) + target_compile_definitions( + mbgl-glfw + PRIVATE MBGL_WITH_EGL + ) +endif() + +if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") + target_compile_definitions( + mbgl-glfw + PRIVATE DEBUG + ) +endif() + set_property(TARGET mbgl-glfw PROPERTY FOLDER Executables) install(TARGETS mbgl-glfw RUNTIME DESTINATION bin) diff --git a/platform/glfw/glfw_backend.hpp b/platform/glfw/glfw_backend.hpp index 867e60d79e7..9456222108e 100644 --- a/platform/glfw/glfw_backend.hpp +++ b/platform/glfw/glfw_backend.hpp @@ -15,14 +15,14 @@ class GLFWBackend { public: explicit GLFWBackend() = default; GLFWBackend(const GLFWBackend&) = delete; - GLFWBackend& operator=(const GLFWBackend&) = delete; + auto operator=(const GLFWBackend&) -> GLFWBackend& = delete; virtual ~GLFWBackend() = default; - static std::unique_ptr Create(GLFWwindow* window, bool capFrameRate) { + static auto Create(GLFWwindow* window, bool capFrameRate) -> std::unique_ptr { return mbgl::gfx::Backend::Create(window, capFrameRate); } - virtual mbgl::gfx::RendererBackend& getRendererBackend() = 0; - virtual mbgl::Size getSize() const = 0; + virtual auto getRendererBackend() -> mbgl::gfx::RendererBackend& = 0; + virtual auto getSize() const -> mbgl::Size = 0; virtual void setSize(mbgl::Size) = 0; }; diff --git a/platform/glfw/glfw_gl_backend.cpp b/platform/glfw/glfw_gl_backend.cpp index 6af68d83d66..6daca3dc4d0 100644 --- a/platform/glfw/glfw_gl_backend.cpp +++ b/platform/glfw/glfw_gl_backend.cpp @@ -52,7 +52,7 @@ void GLFWGLBackend::deactivate() { glfwMakeContextCurrent(nullptr); } -mbgl::gl::ProcAddress GLFWGLBackend::getExtensionFunctionPointer(const char* name) { +auto GLFWGLBackend::getExtensionFunctionPointer(const char* name) -> mbgl::gl::ProcAddress { return glfwGetProcAddress(name); } @@ -61,7 +61,7 @@ void GLFWGLBackend::updateAssumedState() { setViewport(0, 0, size); } -mbgl::Size GLFWGLBackend::getSize() const { +auto GLFWGLBackend::getSize() const -> mbgl::Size { return size; } @@ -77,8 +77,8 @@ namespace mbgl { namespace gfx { template <> -std::unique_ptr -Backend::Create(GLFWwindow* window, bool capFrameRate) { +auto +Backend::Create(GLFWwindow* window, bool capFrameRate) -> std::unique_ptr { return std::make_unique(window, capFrameRate); } diff --git a/platform/glfw/glfw_gl_backend.hpp b/platform/glfw/glfw_gl_backend.hpp index 5971bbd0c50..f2ec0d1559f 100644 --- a/platform/glfw/glfw_gl_backend.hpp +++ b/platform/glfw/glfw_gl_backend.hpp @@ -17,16 +17,14 @@ class GLFWGLBackend final : public GLFWBackend, void swap(); // GLFWRendererBackend implementation -public: - mbgl::gfx::RendererBackend& getRendererBackend() override { + auto getRendererBackend() -> mbgl::gfx::RendererBackend& override { return *this; } - mbgl::Size getSize() const override; + auto getSize() const -> mbgl::Size override; void setSize(mbgl::Size) override; // mbgl::gfx::RendererBackend implementation -public: - mbgl::gfx::Renderable& getDefaultRenderable() override { + auto getDefaultRenderable() -> mbgl::gfx::Renderable& override { return *this; } @@ -35,8 +33,7 @@ class GLFWGLBackend final : public GLFWBackend, void deactivate() override; // mbgl::gl::RendererBackend implementation -protected: - mbgl::gl::ProcAddress getExtensionFunctionPointer(const char*) override; + auto getExtensionFunctionPointer(const char*) -> mbgl::gl::ProcAddress override; void updateAssumedState() override; private: diff --git a/platform/glfw/glfw_renderer_frontend.cpp b/platform/glfw/glfw_renderer_frontend.cpp index 46f13099015..fbdaae6441a 100644 --- a/platform/glfw/glfw_renderer_frontend.cpp +++ b/platform/glfw/glfw_renderer_frontend.cpp @@ -41,7 +41,7 @@ void GLFWRendererFrontend::render() { renderer->render(updateParameters_); } -mbgl::Renderer* GLFWRendererFrontend::getRenderer() { +auto GLFWRendererFrontend::getRenderer() -> mbgl::Renderer* { assert(renderer); return renderer.get(); } diff --git a/platform/glfw/glfw_renderer_frontend.hpp b/platform/glfw/glfw_renderer_frontend.hpp index c992fe20fe9..fdbb2ccde13 100644 --- a/platform/glfw/glfw_renderer_frontend.hpp +++ b/platform/glfw/glfw_renderer_frontend.hpp @@ -20,7 +20,7 @@ class GLFWRendererFrontend : public mbgl::RendererFrontend { void update(std::shared_ptr) override; void render(); - mbgl::Renderer* getRenderer(); + auto getRenderer() -> mbgl::Renderer*; private: GLFWView& glfwView; diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp index 2eb98b113df..c8f7dce021b 100644 --- a/platform/glfw/glfw_view.cpp +++ b/platform/glfw/glfw_view.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -31,16 +30,14 @@ #include #if MBGL_USE_GLES2 -#define GLFW_INCLUDE_ES2 +#define GLFW_INCLUDE_ES3 #endif // MBGL_USE_GLES2 #define GL_GLEXT_PROTOTYPES #include -#include #include #include -#include #include #if defined(MBGL_RENDER_BACKEND_OPENGL) && !defined(MBGL_LAYER_LOCATION_INDICATOR_DISABLE_ALL) @@ -49,14 +46,14 @@ namespace { const std::string mbglPuckAssetsPath{MAPBOX_PUCK_ASSETS_PATH}; -mbgl::Color premultiply(mbgl::Color c) { +auto premultiply(mbgl::Color c) -> mbgl::Color { c.r *= c.a; c.g *= c.a; c.b *= c.a; return c; } -std::array toArray(const mbgl::LatLng &crd) { +auto toArray(const mbgl::LatLng &crd) -> std::array { return {crd.latitude(), crd.longitude(), 0}; } } // namespace @@ -83,24 +80,24 @@ void addFillExtrusionLayer(mbgl::style::Style &style, bool visible) { return; } - if (auto layer = style.getLayer("3d-buildings")) { + if (auto *layer = style.getLayer("3d-buildings")) { layer->setVisibility(VisibilityType(!visible)); return; } auto extrusionLayer = std::make_unique("3d-buildings", "composite"); extrusionLayer->setSourceLayer("building"); - extrusionLayer->setMinZoom(15.0f); + extrusionLayer->setMinZoom(15.0F); extrusionLayer->setFilter(Filter(eq(get("extrude"), literal("true")))); extrusionLayer->setFillExtrusionColor(PropertyExpression(interpolate(linear(), number(get("height")), - 0.f, + 0.F, toColor(literal("#160e23")), - 50.f, + 50.F, toColor(literal("#00615f")), - 100.f, + 100.F, toColor(literal("#55e9ff"))))); - extrusionLayer->setFillExtrusionOpacity(0.6f); + extrusionLayer->setFillExtrusionOpacity(0.6F); extrusionLayer->setFillExtrusionHeight(PropertyExpression(get("height"))); extrusionLayer->setFillExtrusionBase(PropertyExpression(get("min_height"))); style.addLayer(std::move(extrusionLayer)); @@ -109,7 +106,7 @@ void addFillExtrusionLayer(mbgl::style::Style &style, bool visible) { void glfwError(int error, const char *description) { mbgl::Log::Error(mbgl::Event::OpenGL, "GLFW error (%i): %s", error, description); - assert(false); +// assert(false); } GLFWView::GLFWView(bool fullscreen_, bool benchmark_, const mbgl::ResourceOptions &options) @@ -119,7 +116,7 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_, const mbgl::ResourceOption mapResourceOptions(options.clone()) { glfwSetErrorCallback(glfwError); - std::srand(static_cast(std::time(nullptr))); + std::srand(std::clock()); if (!glfwInit()) { mbgl::Log::Error(mbgl::Event::OpenGL, "failed to initialize glfw"); @@ -129,7 +126,7 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_, const mbgl::ResourceOption GLFWmonitor *monitor = nullptr; if (fullscreen) { monitor = glfwGetPrimaryMonitor(); - auto videoMode = glfwGetVideoMode(monitor); + const auto *videoMode = glfwGetVideoMode(monitor); width = videoMode->width; height = videoMode->height; } @@ -148,8 +145,7 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_, const mbgl::ResourceOption #if MBGL_USE_GLES2 glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); #endif if (mbgl::gfx::Backend::GetType() != mbgl::gfx::Backend::Type::OpenGL) { @@ -200,7 +196,9 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_, const mbgl::ResourceOption printf("- Press `X` to cycle through the viewport modes\n"); printf("- Press `I` to delete existing database and re-initialize\n"); printf("- Press `A` to cycle through Mapbox offices in the world + dateline monument\n"); +#ifndef MBGL_USE_GLES2 printf("- Press `B` to cycle through the color, stencil, and depth buffer\n"); +#endif printf("- Press `D` to cycle through camera bounds: inside, crossing IDL at left, crossing IDL at right, and disabled\n"); printf("- Press `T` to add custom geometry source\n"); printf("- Press `F` to enable feature-state demo\n"); @@ -244,7 +242,7 @@ void GLFWView::setRenderFrontend(GLFWRendererFrontend* rendererFrontend_) { rendererFrontend = rendererFrontend_; } -mbgl::gfx::RendererBackend &GLFWView::getRendererBackend() { +auto GLFWView::getRendererBackend() -> mbgl::gfx::RendererBackend & { return backend->getRendererBackend(); } @@ -376,7 +374,7 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, mbgl::LatLngBounds::hull(mbgl::LatLng{-45.0, -200.0}, mbgl::LatLng{45.0, -160.0}), // left IDL mbgl::LatLngBounds::hull(mbgl::LatLng{-45.0, 160.0}, mbgl::LatLng{45.0, 200.0}), // right IDL mbgl::LatLngBounds()}; - static size_t nextBound = 0u; + static size_t nextBound = 0U; static mbgl::AnnotationID boundAnnotationID = std::numeric_limits::max(); mbgl::LatLngBounds bound = bounds[nextBound++]; @@ -396,7 +394,7 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, mbgl::Point{ bound.west(), bound.south() }, }); - auto boundAnnotation = mbgl::FillAnnotation { rect, 0.5f, { view->makeRandomColor() }, { view->makeRandomColor() } }; + auto boundAnnotation = mbgl::FillAnnotation { rect, 0.5F, { GLFWView::makeRandomColor() }, { GLFWView::makeRandomColor() } }; if (boundAnnotationID == std::numeric_limits::max()) { boundAnnotationID = view->map->addAnnotation(boundAnnotation); @@ -428,7 +426,7 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, view->map->jumpTo(cameraOptions); } - auto layer = style.getLayer("state-fills"); + auto *layer = style.getLayer("state-fills"); if (!layer) { auto fillLayer = std::make_unique("state-fills", "states"); fillLayer->setFillColor(mbgl::Color{0.0, 0.0, 1.0, 0.5}); @@ -520,7 +518,7 @@ namespace util { template <> struct Interpolator { - mbgl::LatLng operator()(const mbgl::LatLng &a, const mbgl::LatLng &b, const double t) { + auto operator()(const mbgl::LatLng &a, const mbgl::LatLng &b, const double t) -> mbgl::LatLng { return { interpolate(a.latitude(), b.latitude(), t), interpolate(a.longitude(), b.longitude(), t), @@ -561,22 +559,22 @@ void GLFWView::updateFreeCameraDemo() { } } -mbgl::Color GLFWView::makeRandomColor() const { - const float r = 1.0f * float(std::rand()) / float(RAND_MAX); - const float g = 1.0f * float(std::rand()) / float(RAND_MAX); - const float b = 1.0f * float(std::rand()) / float(RAND_MAX); - return { r, g, b, 1.0f }; +auto GLFWView::makeRandomColor() -> mbgl::Color { + const float r = 1.0F * float(std::rand()) / float(RAND_MAX); + const float g = 1.0F * float(std::rand()) / float(RAND_MAX); + const float b = 1.0F * float(std::rand()) / float(RAND_MAX); + return { r, g, b, 1.0F }; } -mbgl::Point GLFWView::makeRandomPoint() const { +auto GLFWView::makeRandomPoint() const -> mbgl::Point { const double x = width * double(std::rand()) / RAND_MAX; const double y = height * double(std::rand()) / RAND_MAX; mbgl::LatLng latLng = map->latLngForPixel({ x, y }); return { latLng.longitude(), latLng.latitude() }; } -std::unique_ptr -GLFWView::makeImage(const std::string& id, int width, int height, float pixelRatio) { +auto +GLFWView::makeImage(const std::string& id, int width, int height, float pixelRatio) -> std::unique_ptr { const int r = 255 * (double(std::rand()) / RAND_MAX); const int g = 255 * (double(std::rand()) / RAND_MAX); const int b = 255 * (double(std::rand()) / RAND_MAX); @@ -585,7 +583,7 @@ GLFWView::makeImage(const std::string& id, int width, int height, float pixelRat const int h = std::ceil(pixelRatio * height); mbgl::PremultipliedImage image({ static_cast(w), static_cast(h) }); - auto data = reinterpret_cast(image.data.get()); + auto *data = reinterpret_cast(image.data.get()); const int dist = (w / 2) * (w / 2); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { @@ -636,7 +634,7 @@ void GLFWView::addRandomLineAnnotations(int count) { for (int j = 0; j < 3; ++j) { lineString.push_back(makeRandomPoint()); } - annotationIDs.push_back(map->addAnnotation(mbgl::LineAnnotation { lineString, 1.0f, 2.0f, { makeRandomColor() } })); + annotationIDs.push_back(map->addAnnotation(mbgl::LineAnnotation { lineString, 1.0F, 2.0F, { makeRandomColor() } })); } } @@ -644,7 +642,7 @@ void GLFWView::addRandomShapeAnnotations(int count) { for (int i = 0; i < count; ++i) { mbgl::Polygon triangle; triangle.push_back({ makeRandomPoint(), makeRandomPoint(), makeRandomPoint() }); - annotationIDs.push_back(map->addAnnotation(mbgl::FillAnnotation { triangle, 0.5f, { makeRandomColor() }, { makeRandomColor() } })); + annotationIDs.push_back(map->addAnnotation(mbgl::FillAnnotation { triangle, 0.5F, { makeRandomColor() }, { makeRandomColor() } })); } } @@ -932,11 +930,11 @@ void GLFWView::run() { #endif } -float GLFWView::getPixelRatio() const { +auto GLFWView::getPixelRatio() const -> float { return pixelRatio; } -mbgl::Size GLFWView::getSize() const { +auto GLFWView::getSize() const -> mbgl::Size { return { static_cast(width), static_cast(height) }; } @@ -1012,7 +1010,7 @@ void GLFWView::toggleCustomSource() { features.emplace_back(gridLine); } - auto source = static_cast(map->getStyle().getSource("custom")); + auto *source = static_cast(map->getStyle().getSource("custom")); if (source) { source->setTileData(tileID, features); source->invalidateTile(tileID); @@ -1055,7 +1053,7 @@ void GLFWView::toggleLocationIndicatorLayer() { puckLayer->setTopImageSize(0.18); puckLayer->setBearingImageSize(0.26); puckLayer->setShadowImageSize(0.2); - puckLayer->setImageTiltDisplacement(7.0f); // set to 0 for a "flat" puck + puckLayer->setImageTiltDisplacement(7.0F); // set to 0 for a "flat" puck puckLayer->setPerspectiveCompensation(0.9); map->getStyle().addImage(std::make_unique( @@ -1093,8 +1091,6 @@ void GLFWView::toggleLocationIndicatorLayer() { #endif } -using Nanoseconds = std::chrono::nanoseconds; - void GLFWView::onWillStartRenderingFrame() { #if defined(MBGL_RENDER_BACKEND_OPENGL) && !defined(MBGL_LAYER_LOCATION_INDICATOR_DISABLE_ALL) puck = static_cast(map->getStyle().getLayer("puck")); diff --git a/platform/glfw/glfw_view.hpp b/platform/glfw/glfw_view.hpp index 918f5fb5131..e98e0618bcf 100644 --- a/platform/glfw/glfw_view.hpp +++ b/platform/glfw/glfw_view.hpp @@ -28,13 +28,13 @@ class GLFWView : public mbgl::MapObserver { GLFWView(bool fullscreen, bool benchmark, const mbgl::ResourceOptions &options); ~GLFWView() override; - float getPixelRatio() const; + auto getPixelRatio() const -> float; void setMap(mbgl::Map*); void setRenderFrontend(GLFWRendererFrontend*); - mbgl::gfx::RendererBackend& getRendererBackend(); + auto getRendererBackend() -> mbgl::gfx::RendererBackend&; void setTestDirectory(std::string dir) { testDirectory = std::move(dir); }; @@ -56,7 +56,7 @@ class GLFWView : public mbgl::MapObserver { void invalidate(); - mbgl::Size getSize() const; + auto getSize() const -> mbgl::Size; // mbgl::MapObserver implementation void onDidFinishLoadingStyle() override; @@ -78,9 +78,9 @@ class GLFWView : public mbgl::MapObserver { // Internal void report(float duration); - mbgl::Color makeRandomColor() const; - mbgl::Point makeRandomPoint() const; - static std::unique_ptr makeImage(const std::string& id, int width, int height, float pixelRatio); + static auto makeRandomColor() -> mbgl::Color ; + auto makeRandomPoint() const -> mbgl::Point; + static auto makeImage(const std::string& id, int width, int height, float pixelRatio) -> std::unique_ptr; void nextOrientation(); @@ -106,7 +106,6 @@ class GLFWView : public mbgl::MapObserver { mbgl::AnnotationIDs animatedAnnotationIDs; std::vector animatedAnnotationAddedTimes; -private: void toggle3DExtrusions(bool visible); mbgl::Map* map = nullptr; diff --git a/platform/glfw/main.cpp b/platform/glfw/main.cpp index 3b45c4482fe..e2f72201011 100644 --- a/platform/glfw/main.cpp +++ b/platform/glfw/main.cpp @@ -9,17 +9,13 @@ #include #include #include -#include #include #include #include -#include #include #include -#include -#include namespace { @@ -36,7 +32,7 @@ void quit_handler(int) { } } -int main(int argc, char *argv[]) { +auto main(int argc, char *argv[]) -> int { args::ArgumentParser argumentParser("Mapbox GL GLFW example"); args::HelpFlag helpFlag(argumentParser, "help", "Display this help menu", {'h', "help"}); @@ -79,8 +75,8 @@ int main(int argc, char *argv[]) { if (bearingValue) settings.bearing = args::get(bearingValue); if (pitchValue) settings.pitch = args::get(pitchValue); - const bool fullscreen = fullscreenFlag ? args::get(fullscreenFlag) : false; - const bool benchmark = benchmarkFlag ? args::get(benchmarkFlag) : false; + const bool fullscreen = fullscreenFlag && args::get(fullscreenFlag); + const bool benchmark = benchmarkFlag && args::get(benchmarkFlag); std::string style = styleValue ? args::get(styleValue) : ""; const std::string cacheDB = cacheDBValue ? args::get(cacheDBValue) : "/tmp/mbgl-cache.db"; diff --git a/platform/glfw/settings_json.cpp b/platform/glfw/settings_json.cpp index 5b6aa4e0da1..0a77ae72153 100644 --- a/platform/glfw/settings_json.cpp +++ b/platform/glfw/settings_json.cpp @@ -18,7 +18,7 @@ void Settings_JSON::load() { } } -void Settings_JSON::save() { +void Settings_JSON::save() const { std::ofstream file("/tmp/mbgl-native.cfg"); if (file) { file << longitude << std::endl; diff --git a/platform/glfw/settings_json.hpp b/platform/glfw/settings_json.hpp index c89accb8aff..4290fc4e844 100644 --- a/platform/glfw/settings_json.hpp +++ b/platform/glfw/settings_json.hpp @@ -8,18 +8,14 @@ class Settings_JSON { public: Settings_JSON(); void load(); - void save(); + void save() const; void clear(); -public: double longitude = 0; double latitude = 0; double zoom = 0; double bearing = 0; double pitch = 0; - bool axonometric = false; - double xSkew = 0.0; - double ySkew = 1.0; EnumType debug = 0; bool online = true; diff --git a/platform/glfw/test_writer.cpp b/platform/glfw/test_writer.cpp index 71dae3ef5d4..cda385bdad0 100644 --- a/platform/glfw/test_writer.cpp +++ b/platform/glfw/test_writer.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include @@ -93,26 +92,26 @@ TestWriter::TestWriter() = default; TestWriter::~TestWriter() = default; -TestWriter& TestWriter::withCameraOptions(const mbgl::CameraOptions& camera) { +auto TestWriter::withCameraOptions(const mbgl::CameraOptions& camera) -> TestWriter& { operations.emplace_back(std::make_unique(camera)); return *this; } -TestWriter& TestWriter::withStyle(const mbgl::style::Style& style) { +auto TestWriter::withStyle(const mbgl::style::Style& style) -> TestWriter& { operations.emplace_back(std::make_unique(style)); return *this; } -TestWriter& TestWriter::withInitialSize(const mbgl::Size& size) { +auto TestWriter::withInitialSize(const mbgl::Size& size) -> TestWriter& { assert(initialSize == nullptr); initialSize = std::make_unique(size); return *this; } -bool TestWriter::write(const std::string& dir) const { +auto TestWriter::write(const std::string& dir) const -> bool { namespace fs = ghc::filesystem; fs::path rootDir(dir); @@ -144,7 +143,7 @@ bool TestWriter::write(const std::string& dir) const { return out.is_open() && out.good(); } -std::string TestWriter::serialize() const { +auto TestWriter::serialize() const -> std::string { rapidjson::StringBuffer s; Writer writer(s); diff --git a/platform/glfw/test_writer.hpp b/platform/glfw/test_writer.hpp index 881b0d16fa1..e1e3c7f58ae 100644 --- a/platform/glfw/test_writer.hpp +++ b/platform/glfw/test_writer.hpp @@ -15,14 +15,14 @@ class TestWriter final { TestWriter(); ~TestWriter(); - TestWriter& withCameraOptions(const mbgl::CameraOptions&); - TestWriter& withStyle(const mbgl::style::Style&); - TestWriter& withInitialSize(const mbgl::Size&); + auto withCameraOptions(const mbgl::CameraOptions&) -> TestWriter&; + auto withStyle(const mbgl::style::Style&) -> TestWriter&; + auto withInitialSize(const mbgl::Size&) -> TestWriter&; - bool write(const std::string& dir) const; + auto write(const std::string& dir) const -> bool; private: - std::string serialize() const; + auto serialize() const -> std::string; std::vector> operations; std::unique_ptr initialSize; diff --git a/platform/linux/linux.cmake b/platform/linux/linux.cmake index a9a6e73e266..d0c999efe6b 100644 --- a/platform/linux/linux.cmake +++ b/platform/linux/linux.cmake @@ -1,3 +1,6 @@ + +option(MBGL_WITH_GLX "Build with OpenGLX" OFF) + find_package(CURL REQUIRED) find_package(ICU OPTIONAL_COMPONENTS i18n) find_package(ICU OPTIONAL_COMPONENTS uc) @@ -5,7 +8,7 @@ find_package(JPEG REQUIRED) find_package(OpenGL REQUIRED GLX) find_package(PNG REQUIRED) find_package(PkgConfig REQUIRED) -find_package(X11 REQUIRED) +find_package(Threads REQUIRED) pkg_search_module(LIBUV libuv REQUIRED) @@ -49,9 +52,25 @@ target_sources( ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/util/timer.cpp ${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/util/utf.cpp ${PROJECT_SOURCE_DIR}/platform/linux/src/gl_functions.cpp - ${PROJECT_SOURCE_DIR}/platform/linux/src/headless_backend_glx.cpp ) +if (MBGL_WITH_GLX) + find_package(OpenGL REQUIRED GLX) + find_package(X11 REQUIRED) + target_sources( + mbgl-core + PRIVATE + ${PROJECT_SOURCE_DIR}/platform/linux/src/headless_backend_glx.cpp + ) +elseif (MBGL_WITH_GLES2) + pkg_check_modules(EGL REQUIRED egl glesv2) + target_sources( + mbgl-core + PRIVATE + ${PROJECT_SOURCE_DIR}/platform/linux/src/headless_backend_egl.cpp + ) +endif () + # FIXME: Should not be needed, but now needed by node because of the headless frontend. target_include_directories( mbgl-core @@ -60,6 +79,7 @@ target_include_directories( ${CURL_INCLUDE_DIRS} ${JPEG_INCLUDE_DIRS} ${LIBUV_INCLUDE_DIRS} + ${EGL_INCLUDE_DIRS} ${X11_INCLUDE_DIRS} ) @@ -87,14 +107,22 @@ target_link_libraries( ${JPEG_LIBRARIES} ${LIBUV_LIBRARIES} ${X11_LIBRARIES} + ${EGL_LIBRARIES} $<$>:ICU::i18n> $<$>:ICU::uc> $<$:mbgl-vendor-icu> - OpenGL::GLX + Threads::Threads PNG::PNG mbgl-vendor-nunicode mbgl-vendor-sqlite ) +if(MBGL_WITH_GLX) + target_link_libraries( + mbgl-core + PRIVATE + OpenGL::GLX + ) +endif() add_subdirectory(${PROJECT_SOURCE_DIR}/bin) add_subdirectory(${PROJECT_SOURCE_DIR}/expression-test) diff --git a/platform/linux/src/gl_functions.cpp b/platform/linux/src/gl_functions.cpp index a5c7527935f..92400a8ec52 100644 --- a/platform/linux/src/gl_functions.cpp +++ b/platform/linux/src/gl_functions.cpp @@ -7,7 +7,6 @@ #include #else #include -#include #endif namespace mbgl { diff --git a/platform/linux/src/headless_backend_egl.cpp b/platform/linux/src/headless_backend_egl.cpp index 21db012510f..0d92521b8e2 100644 --- a/platform/linux/src/headless_backend_egl.cpp +++ b/platform/linux/src/headless_backend_egl.cpp @@ -24,7 +24,9 @@ class EGLDisplayConfig { throw std::runtime_error("Failed to obtain a valid EGL display.\n"); } - EGLint major, minor, numConfigs; + EGLint major; + EGLint minor; + EGLint numConfigs; if (!eglInitialize(display, &major, &minor)) { throw std::runtime_error("eglInitialize() failed.\n"); } @@ -54,7 +56,7 @@ class EGLDisplayConfig { eglTerminate(display); } - static std::shared_ptr create() { + static auto create() -> std::shared_ptr { static std::weak_ptr instance; auto shared = instance.lock(); if (!shared) { @@ -63,9 +65,8 @@ class EGLDisplayConfig { return shared; } -public: EGLDisplay display = EGL_NO_DISPLAY; - EGLConfig config = 0; + EGLConfig config = nullptr; }; class EGLBackendImpl : public HeadlessBackend::Impl { @@ -116,9 +117,7 @@ class EGLBackendImpl : public HeadlessBackend::Impl { } } - gl::ProcAddress getExtensionFunctionPointer(const char* name) final { - return eglGetProcAddress(name); - } + auto getExtensionFunctionPointer(const char* name) -> gl::ProcAddress final; void activateContext() final { if (!eglMakeCurrent(eglDisplay->display, eglSurface, eglSurface, eglContext)) { @@ -138,6 +137,10 @@ class EGLBackendImpl : public HeadlessBackend::Impl { EGLSurface eglSurface = EGL_NO_SURFACE; }; +auto EGLBackendImpl::getExtensionFunctionPointer(const char* name) -> gl::ProcAddress { + return eglGetProcAddress(name); +} + void HeadlessBackend::createImpl() { assert(!impl); impl = std::make_unique();