diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | include/mbgl/style/expression/expression.hpp | 446 | ||||
-rw-r--r-- | include/mbgl/style/expression/value.hpp | 127 | ||||
-rw-r--r-- | include/mbgl/util/chrono.hpp | 7 | ||||
-rw-r--r-- | include/mbgl/util/enum.hpp | 37 | ||||
m--------- | mapbox-gl-js | 0 | ||||
-rw-r--r-- | scripts/windows-build-appveyor.bat | 64 | ||||
-rw-r--r-- | scripts/windows-build-local.bat | 31 | ||||
-rw-r--r-- | src/mbgl/gl/context.hpp | 88 | ||||
-rw-r--r-- | src/mbgl/gl/vertex_array.hpp | 13 |
10 files changed, 503 insertions, 311 deletions
diff --git a/.gitignore b/.gitignore index 48f3c06f3..9459cafd5 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ test/fixtures/api/assets.zip test/fixtures/storage/assets.zip /.circle-week /vendor/.cache +/cmake.zip # Generated list files from code generation /scripts/generate-cmake-files.list diff --git a/include/mbgl/style/expression/expression.hpp b/include/mbgl/style/expression/expression.hpp index bfd1e08ee..e817a642a 100644 --- a/include/mbgl/style/expression/expression.hpp +++ b/include/mbgl/style/expression/expression.hpp @@ -1,215 +1,231 @@ -#pragma once - -#include <mbgl/util/optional.hpp> -#include <mbgl/util/variant.hpp> -#include <mbgl/util/color.hpp> -#include <mbgl/style/expression/type.hpp> -#include <mbgl/style/expression/value.hpp> -#include <mbgl/style/expression/parsing_context.hpp> - -#include <array> -#include <vector> -#include <memory> - -namespace mbgl { - -class GeometryTileFeature; - -namespace style { -namespace expression { - -class EvaluationError { -public: - std::string message; -}; - -class EvaluationContext { -public: - EvaluationContext(float zoom_) : zoom(zoom_), feature(nullptr) {} - EvaluationContext(GeometryTileFeature const * feature_) : zoom(optional<float>()), feature(feature_) {} - EvaluationContext(float zoom_, GeometryTileFeature const * feature_) : - zoom(zoom_), feature(feature_) - {} - EvaluationContext(optional<float> zoom_, GeometryTileFeature const * feature_, optional<double> colorRampParameter_) : - zoom(std::move(zoom_)), feature(feature_), colorRampParameter(std::move(colorRampParameter_)) - {} - - optional<float> zoom; - GeometryTileFeature const * feature; - optional<double> colorRampParameter; -}; - -template <typename T> -class Result : private variant<EvaluationError, T> { -public: - using variant<EvaluationError, T>::variant; - using Value = T; - - Result() = default; - - explicit operator bool () const { - return this->template is<T>(); - } - - // optional does some type trait magic for this one, so this might - // be problematic as is. - const T* operator->() const { - assert(this->template is<T>()); - return std::addressof(this->template get<T>()); - } - - T* operator->() { - assert(this->template is<T>()); - return std::addressof(this->template get<T>()); - } - - T& operator*() { - assert(this->template is<T>()); - return this->template get<T>(); - } - - const T& operator*() const { - assert(this->template is<T>()); - return this->template get<T>(); - } - - const EvaluationError& error() const { - assert(this->template is<EvaluationError>()); - return this->template get<EvaluationError>(); - } -}; - -class EvaluationResult : public Result<Value> { -public: - using Result::Result; // NOLINT - - EvaluationResult() = default; - - EvaluationResult(const std::array<double, 4>& arr) : - Result(toExpressionValue(arr)) - {} - - // used only for the special (private) "error" expression - EvaluationResult(const type::ErrorType&) { - assert(false); - } -}; - -/* - Expression is an abstract class that serves as an interface and base class - for particular expression implementations. - - CompoundExpression implements the majority of expressions in the spec by - inferring the argument and output from a simple function (const T0& arg0, - const T1& arg1, ...) -> Result<U> where T0, T1, ..., U are member types of - mbgl::style::expression::Value. - - The other Expression subclasses (Let, Curve, Match, etc.) exist in order to - implement expressions that need specialized parsing, type checking, or - evaluation logic that can't be handled by CompoundExpression's inference - mechanism. - - Each Expression subclass also provides a static - ParseResult ExpressionClass::parse(const V&, ParsingContext), - which handles parsing a style-spec JSON representation of the expression. -*/ - -enum class Kind : int32_t { - Coalesce, - CompoundExpression, - Literal, - ArrayAssertion, - At, - Interpolate, - Assertion, - Length, - Step, - Let, - Var, - CollatorExpression, - Coercion, - Match, - Error, - Case, - Any, - All, - Comparison, -}; - -class Expression { -public: - Expression(Kind kind_, type::Type type_) : kind(kind_), type(std::move(type_)) {} - virtual ~Expression() = default; - - virtual EvaluationResult evaluate(const EvaluationContext& params) const = 0; - virtual void eachChild(const std::function<void(const Expression&)>&) const = 0; - virtual bool operator==(const Expression&) const = 0; - bool operator!=(const Expression& rhs) const { - return !operator==(rhs); - } - - Kind getKind() const { return kind; }; - type::Type getType() const { return type; }; - - EvaluationResult evaluate(optional<float> zoom, const Feature& feature, optional<double> colorRampParameter) const; - - /** - * Statically analyze the expression, attempting to enumerate possible outputs. Returns - * an array of values plus the sentinel null optional value, used to indicate that the - * complete set of outputs is statically undecidable. - */ - virtual std::vector<optional<Value>> possibleOutputs() const = 0; - - virtual mbgl::Value serialize() const { - std::vector<mbgl::Value> serialized; - serialized.emplace_back(getOperator()); - eachChild([&](const Expression &child) { - serialized.emplace_back(child.serialize()); - }); - return serialized; - }; - - virtual std::string getOperator() const = 0; - -protected: - template <typename T> - static bool childrenEqual(const T& lhs, const T& rhs) { - if (lhs.size() != rhs.size()) return false; - for (auto leftChild = lhs.begin(), rightChild = rhs.begin(); - leftChild != lhs.end(); - leftChild++, rightChild++) - { - if (!Expression::childEqual(*leftChild, *rightChild)) return false; - } - return true; - } - - static bool childEqual(const std::unique_ptr<Expression>& lhs, const std::unique_ptr<Expression>& rhs) { - return *lhs == *rhs; - } - - template <typename T> - static bool childEqual(const std::pair<T, std::unique_ptr<Expression>>& lhs, - const std::pair<T, std::unique_ptr<Expression>>& rhs) { - return lhs.first == rhs.first && *(lhs.second) == *(rhs.second); - } - - template <typename T> - static bool childEqual(const std::pair<T, std::shared_ptr<Expression>>& lhs, - const std::pair<T, std::shared_ptr<Expression>>& rhs) { - return lhs.first == rhs.first && *(lhs.second) == *(rhs.second); - } - - static bool childEqual(const std::pair<std::unique_ptr<Expression>, std::unique_ptr<Expression>>& lhs, - const std::pair<std::unique_ptr<Expression>, std::unique_ptr<Expression>>& rhs) { - return *(lhs.first) == *(rhs.first) && *(lhs.second) == *(rhs.second); - } - -private: - Kind kind; - type::Type type; -}; - -} // namespace expression -} // namespace style -} // namespace mbgl +#pragma once
+
+#include <mbgl/style/expression/parsing_context.hpp>
+#include <mbgl/style/expression/type.hpp>
+#include <mbgl/style/expression/value.hpp>
+#include <mbgl/util/color.hpp>
+#include <mbgl/util/optional.hpp>
+#include <mbgl/util/variant.hpp>
+
+#include <array>
+#include <memory>
+#include <vector>
+
+namespace mbgl {
+
+class GeometryTileFeature;
+
+namespace style {
+namespace expression {
+
+class EvaluationError {
+public:
+ std::string message;
+};
+
+class EvaluationContext {
+public:
+ EvaluationContext(float zoom_) : zoom(zoom_), feature(nullptr) {
+ }
+ EvaluationContext(GeometryTileFeature const* feature_)
+ : zoom(optional<float>()), feature(feature_) {
+ }
+ EvaluationContext(float zoom_, GeometryTileFeature const* feature_)
+ : zoom(zoom_), feature(feature_) {
+ }
+ EvaluationContext(optional<float> zoom_,
+ GeometryTileFeature const* feature_,
+ optional<double> colorRampParameter_)
+ : zoom(std::move(zoom_)),
+ feature(feature_),
+ colorRampParameter(std::move(colorRampParameter_)) {
+ }
+
+ optional<float> zoom;
+ GeometryTileFeature const* feature;
+ optional<double> colorRampParameter;
+};
+
+template <typename T>
+class Result : private variant<EvaluationError, T> {
+public:
+ // using variant<EvaluationError, T>::variant;
+ template <class... Args>
+ Result(Args&&... args) : variant<EvaluationError, T>(std::forward<Args>(args)...) {
+ }
+ using Value = T;
+
+ Result() = default;
+
+ explicit operator bool() const {
+ return this->template is<T>();
+ }
+
+ // optional does some type trait magic for this one, so this might
+ // be problematic as is.
+ const T* operator->() const {
+ assert(this->template is<T>());
+ return std::addressof(this->template get<T>());
+ }
+
+ T* operator->() {
+ assert(this->template is<T>());
+ return std::addressof(this->template get<T>());
+ }
+
+ T& operator*() {
+ assert(this->template is<T>());
+ return this->template get<T>();
+ }
+
+ const T& operator*() const {
+ assert(this->template is<T>());
+ return this->template get<T>();
+ }
+
+ const EvaluationError& error() const {
+ assert(this->template is<EvaluationError>());
+ return this->template get<EvaluationError>();
+ }
+};
+
+class EvaluationResult : public Result<Value> {
+public:
+ using Result::Result; // NOLINT
+
+ EvaluationResult() = default;
+
+ EvaluationResult(const std::array<double, 4>& arr) : Result(toExpressionValue(arr)) {
+ }
+
+ // used only for the special (private) "error" expression
+ EvaluationResult(const type::ErrorType&) {
+ assert(false);
+ }
+};
+
+/*
+ Expression is an abstract class that serves as an interface and base class
+ for particular expression implementations.
+
+ CompoundExpression implements the majority of expressions in the spec by
+ inferring the argument and output from a simple function (const T0& arg0,
+ const T1& arg1, ...) -> Result<U> where T0, T1, ..., U are member types of
+ mbgl::style::expression::Value.
+
+ The other Expression subclasses (Let, Curve, Match, etc.) exist in order to
+ implement expressions that need specialized parsing, type checking, or
+ evaluation logic that can't be handled by CompoundExpression's inference
+ mechanism.
+
+ Each Expression subclass also provides a static
+ ParseResult ExpressionClass::parse(const V&, ParsingContext),
+ which handles parsing a style-spec JSON representation of the expression.
+*/
+
+enum class Kind : int32_t {
+ Coalesce,
+ CompoundExpression,
+ Literal,
+ ArrayAssertion,
+ At,
+ Interpolate,
+ Assertion,
+ Length,
+ Step,
+ Let,
+ Var,
+ CollatorExpression,
+ Coercion,
+ Match,
+ Error,
+ Case,
+ Any,
+ All,
+ Comparison,
+};
+
+class Expression {
+public:
+ Expression(Kind kind_, type::Type type_) : kind(kind_), type(std::move(type_)) {
+ }
+ virtual ~Expression() = default;
+
+ virtual EvaluationResult evaluate(const EvaluationContext& params) const = 0;
+ virtual void eachChild(const std::function<void(const Expression&)>&) const = 0;
+ virtual bool operator==(const Expression&) const = 0;
+ bool operator!=(const Expression& rhs) const {
+ return !operator==(rhs);
+ }
+
+ Kind getKind() const {
+ return kind;
+ };
+ type::Type getType() const {
+ return type;
+ };
+
+ EvaluationResult evaluate(optional<float> zoom,
+ const Feature& feature,
+ optional<double> colorRampParameter) const;
+
+ /**
+ * Statically analyze the expression, attempting to enumerate possible outputs. Returns
+ * an array of values plus the sentinel null optional value, used to indicate that the
+ * complete set of outputs is statically undecidable.
+ */
+ virtual std::vector<optional<Value>> possibleOutputs() const = 0;
+
+ virtual mbgl::Value serialize() const {
+ std::vector<mbgl::Value> serialized;
+ serialized.emplace_back(getOperator());
+ eachChild([&](const Expression& child) { serialized.emplace_back(child.serialize()); });
+ return serialized;
+ };
+
+ virtual std::string getOperator() const = 0;
+
+protected:
+ template <typename T>
+ static bool childrenEqual(const T& lhs, const T& rhs) {
+ if (lhs.size() != rhs.size())
+ return false;
+ for (auto leftChild = lhs.begin(), rightChild = rhs.begin(); leftChild != lhs.end();
+ leftChild++, rightChild++) {
+ if (!Expression::childEqual(*leftChild, *rightChild))
+ return false;
+ }
+ return true;
+ }
+
+ static bool childEqual(const std::unique_ptr<Expression>& lhs,
+ const std::unique_ptr<Expression>& rhs) {
+ return *lhs == *rhs;
+ }
+
+ template <typename T>
+ static bool childEqual(const std::pair<T, std::unique_ptr<Expression>>& lhs,
+ const std::pair<T, std::unique_ptr<Expression>>& rhs) {
+ return lhs.first == rhs.first && *(lhs.second) == *(rhs.second);
+ }
+
+ template <typename T>
+ static bool childEqual(const std::pair<T, std::shared_ptr<Expression>>& lhs,
+ const std::pair<T, std::shared_ptr<Expression>>& rhs) {
+ return lhs.first == rhs.first && *(lhs.second) == *(rhs.second);
+ }
+
+ static bool
+ childEqual(const std::pair<std::unique_ptr<Expression>, std::unique_ptr<Expression>>& lhs,
+ const std::pair<std::unique_ptr<Expression>, std::unique_ptr<Expression>>& rhs) {
+ return *(lhs.first) == *(rhs.first) && *(lhs.second) == *(rhs.second);
+ }
+
+private:
+ Kind kind;
+ type::Type type;
+};
+
+} // namespace expression
+} // namespace style
+} // namespace mbgl
diff --git a/include/mbgl/style/expression/value.hpp b/include/mbgl/style/expression/value.hpp index b1126118a..6170ac46e 100644 --- a/include/mbgl/style/expression/value.hpp +++ b/include/mbgl/style/expression/value.hpp @@ -18,29 +18,102 @@ namespace expression { struct Value; -using ValueBase = variant< - NullValue, - bool, - double, - std::string, - Color, - Collator, - mapbox::util::recursive_wrapper<std::vector<Value>>, - mapbox::util::recursive_wrapper<std::unordered_map<std::string, Value>>>; +using ValueBase = variant<NullValue, + bool, + double, + std::string, + Color, + Collator, + mapbox::util::recursive_wrapper<std::vector<Value>>, + mapbox::util::recursive_wrapper<std::unordered_map<std::string, Value>>>; struct Value : ValueBase { using ValueBase::ValueBase; - + + template <typename T> + bool is(T*) const { + return ValueBase::is<T>(); + } + + template <> + bool is(float*) const { + return ValueBase::is<double>(); + } + + template <typename T> + bool is() const { + return ValueBase::is<T>(); + } + template <typename T> + T& get(T*) { + return ValueBase::get<T>(); + } + template <typename T> + T const& get(T*) const { + return ValueBase::get<T>(); + } + template <> + float const& get(float*) const { + return ValueBase::get<double>(); + } + + template <typename T> + T& get() { + return ValueBase::get<T>(); + } + template <typename T> + T const& get() const { + return ValueBase::get<T>(); + } + + Value(NullValue&& args) : ValueBase(std::move(args)) { + } + Value(bool&& args) : ValueBase(std::forward<bool>(args)) { + } + Value(double&& args) : ValueBase(std::forward<double>(args)) { + } + Value(std::string&& args) : ValueBase(std::move(args)) { + } + Value(Color&& args) : ValueBase(std::forward<Color>(args)) { + } + Value(std::vector<Value>&& args) + : ValueBase(mapbox::util::recursive_wrapper<std::vector<Value>>(args)) { + } + typedef mapbox::util::recursive_wrapper<std::unordered_map<std::string, Value>> rec_map; + Value(std::unordered_map<std::string, Value>&& args) : ValueBase(rec_map(args)) { + } + + Value(const NullValue& args) : ValueBase(args) { + } + Value(const bool& args) : ValueBase(args) { + } + Value(const double& args) : ValueBase(args) { + } + Value(const std::string& args) : ValueBase(args) { + } + Value(const Color& args) : ValueBase(args) { + } + Value(const std::vector<Value>& args) + : ValueBase(mapbox::util::recursive_wrapper<std::vector<Value>>(args)) { + } + Value(const std::unordered_map<std::string, Value>& args) : ValueBase(rec_map(args)) { + } + + Value(const Value&) = default; + // Javascript's Number.MAX_SAFE_INTEGER - static uint64_t maxSafeInteger() { return 9007199254740991ULL; } - - static bool isSafeInteger(uint64_t x) { return x <= maxSafeInteger(); }; + static uint64_t maxSafeInteger() { + return 9007199254740991ULL; + } + + static bool isSafeInteger(uint64_t x) { + return x <= maxSafeInteger(); + }; static bool isSafeInteger(int64_t x) { return static_cast<uint64_t>(x > 0 ? x : -x) <= maxSafeInteger(); } static bool isSafeInteger(double x) { return static_cast<uint64_t>(x > 0 ? x : -x) <= maxSafeInteger(); } - }; constexpr NullValue Null = NullValue(); @@ -73,9 +146,15 @@ struct ValueConverter { template <> struct ValueConverter<Value> { - static type::Type expressionType() { return type::Value; } - static Value toExpressionValue(const Value& value) { return value; } - static optional<Value> fromExpressionValue(const Value& value) { return value; } + static type::Type expressionType() { + return type::Value; + } + static Value toExpressionValue(const Value& value) { + return value; + } + static optional<Value> fromExpressionValue(const Value& value) { + return value; + } }; template <> @@ -86,7 +165,9 @@ struct ValueConverter<mbgl::Value> { template <> struct ValueConverter<float> { - static type::Type expressionType() { return type::Number; } + static type::Type expressionType() { + return type::Number; + } static Value toExpressionValue(const float value); static optional<float> fromExpressionValue(const Value& value); }; @@ -111,14 +192,18 @@ struct ValueConverter<std::vector<T>> { template <> struct ValueConverter<Position> { - static type::Type expressionType() { return type::Array(type::Number, 3); } + static type::Type expressionType() { + return type::Array(type::Number, 3); + } static Value toExpressionValue(const mbgl::style::Position& value); static optional<Position> fromExpressionValue(const Value& v); }; template <typename T> -struct ValueConverter<T, std::enable_if_t< std::is_enum<T>::value >> { - static type::Type expressionType() { return type::String; } +struct ValueConverter<T, std::enable_if_t<std::is_enum<T>::value>> { + static type::Type expressionType() { + return type::String; + } static Value toExpressionValue(const T& value); static optional<T> fromExpressionValue(const Value& value); }; diff --git a/include/mbgl/util/chrono.hpp b/include/mbgl/util/chrono.hpp index 723cd131e..7384f5437 100644 --- a/include/mbgl/util/chrono.hpp +++ b/include/mbgl/util/chrono.hpp @@ -11,7 +11,7 @@ using Seconds = std::chrono::seconds; using Milliseconds = std::chrono::milliseconds; using TimePoint = Clock::time_point; -using Duration = Clock::duration; +using Duration = Clock::duration; // Used to measure second-precision times, such as times gathered from HTTP responses. using Timestamp = std::chrono::time_point<std::chrono::system_clock, Seconds>; @@ -28,18 +28,19 @@ std::string rfc1123(Timestamp); // YYYY-mm-dd HH:MM:SS e.g. "2015-11-26 16:11:23" std::string iso8601(Timestamp); -Timestamp parseTimestamp(const char *); +Timestamp parseTimestamp(const char*); Timestamp parseTimestamp(const int32_t timestamp); // C++17 polyfill +/* template <class Rep, class Period, class = std::enable_if_t< std::chrono::duration<Rep, Period>::min() < std::chrono::duration<Rep, Period>::zero()>> constexpr std::chrono::duration<Rep, Period> abs(std::chrono::duration<Rep, Period> d) { return d >= d.zero() ? d : -d; } - +*/ } // namespace util } // namespace mbgl diff --git a/include/mbgl/util/enum.hpp b/include/mbgl/util/enum.hpp index 608befd3c..5d67e394b 100644 --- a/include/mbgl/util/enum.hpp +++ b/include/mbgl/util/enum.hpp @@ -12,26 +12,27 @@ template <typename T> class Enum { public: using Type = T; - static const char * toString(T); + static const char* toString(T); static optional<T> toEnum(const std::string&); }; -#define MBGL_DEFINE_ENUM(T, values...) \ - \ -static const constexpr std::pair<const T, const char *> T##_names[] = values; \ - \ -template <> \ -const char * Enum<T>::toString(T t) { \ - auto it = std::find_if(std::begin(T##_names), std::end(T##_names), \ - [&] (const auto& v) { return t == v.first; }); \ - assert(it != std::end(T##_names)); return it->second; \ -} \ - \ -template <> \ -optional<T> Enum<T>::toEnum(const std::string& s) { \ - auto it = std::find_if(std::begin(T##_names), std::end(T##_names), \ - [&] (const auto& v) { return s == v.second; }); \ - return it == std::end(T##_names) ? optional<T>() : it->first; \ -} +#define MBGL_DEFINE_ENUM(T, ...) \ + \ + static const constexpr std::pair<const T, const char*> T##_names[] = values; \ + \ + template <> \ + const char* Enum<T>::toString(T t) { \ + auto it = std::find_if(std::begin(T##_names), std::end(T##_names), \ + [&](const auto& v) { return t == v.first; }); \ + assert(it != std::end(T##_names)); \ + return it->second; \ + } \ + \ + template <> \ + optional<T> Enum<T>::toEnum(const std::string& s) { \ + auto it = std::find_if(std::begin(T##_names), std::end(T##_names), \ + [&](const auto& v) { return s == v.second; }); \ + return it == std::end(T##_names) ? optional<T>() : it->first; \ + } } // namespace mbgl diff --git a/mapbox-gl-js b/mapbox-gl-js -Subproject e8fd41abae382f39f17a561a1461db90bd2204f +Subproject 53e622b475b7c9cb26b98d18e3fbd61d27b183a diff --git a/scripts/windows-build-appveyor.bat b/scripts/windows-build-appveyor.bat new file mode 100644 index 000000000..279ce5819 --- /dev/null +++ b/scripts/windows-build-appveyor.bat @@ -0,0 +1,64 @@ +@ECHO OFF +SETLOCAL +SET EL=0 + +7z > NUL +IF %ERRORLEVEL% NEQ 0 ECHO 7z not availabe && GOTO ERROR + +ECHO Powershell version^: +powershell $PSVersionTable.PSVersion +IF %ERRORLEVEL% NEQ 0 ECHO powershell not availabe && GOTO ERROR + +FOR /F "tokens=*" %%i in ('powershell Get-ExecutionPolicy') do SET PSPOLICY=%%i +ECHO Powershell execution policy^: %PSPOLICY% +IF NOT "%PSPOLICY%"=="Unrestricted" powershell Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force +IF %ERRORLEVEL% NEQ 0 GOTO ERROR +FOR /F "tokens=*" %%i in ('powershell Get-ExecutionPolicy') do SET PSPOLICY=%%i +ECHO Powershell execution policy now is^: %PSPOLICY% + +IF NOT EXIST cmake.zip powershell Invoke-WebRequest $env:CMAKE_URL -OutFile $env:APPVEYOR_BUILD_FOLDER\\cmake.zip +IF %ERRORLEVEL% NEQ 0 GOTO ERROR + +IF NOT EXIST C:\%CMAKE_VERSION% 7z -y x cmake.zip -oC:\ | %windir%\system32\FIND "ing archive" +IF %ERRORLEVEL% NEQ 0 GOTO ERROR + +SET PATH=C:\%CMAKE_VERSION%\bin;%PATH% + +IF EXIST %APPVEYOR_BUILD_FOLDER%\build RMDIR /Q /S %APPVEYOR_BUILD_FOLDER%\build +IF %ERRORLEVEL% NEQ 0 GOTO ERROR +MKDIR %APPVEYOR_BUILD_FOLDER%\build +IF %ERRORLEVEL% NEQ 0 GOTO ERROR +CD %APPVEYOR_BUILD_FOLDER%\build +IF %ERRORLEVEL% NEQ 0 GOTO ERROR + +SET VSCMD=C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\VC\Auxiliary\Build\vcvarsall.bat +IF "%APPVEYOR%"=="True" SET VSCMD=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat +CALL "%VSCMD%" amd64 +IF %ERRORLEVEL% NEQ 0 GOTO ERROR + +REM -T v141_clang_c2 ^ +cmake -G "Visual Studio 15 2017 Win64" ^ +-DCMAKE_BUILD_TYPE=%configuration% ^ +-DMBGL_PLATFORM=qt ^ +-DWITH_QT_DECODERS=ON ^ +-DWITH_QT_I18N=ON ^ +-DWITH_NODEJS=OFF ^ +-DCMAKE_BUILD_TYPE=Release ^ +-DCMAKE_PREFIX_PATH=C:\Qt\5.11.1\msvc2017_64\lib\cmake .. +IF %ERRORLEVEL% NEQ 0 GOTO ERROR + +REM cmake --build . -- -j %NUMBER_OF_PROCESSORS% +REM IF %ERRORLEVEL% NEQ 0 GOTO ERROR + +GOTO DONE + +:ERROR +SET EL=%ERRORLEVEL% +ECHO ~~~~~~~~~~~~~~~~~~~ ERROR %~f0 ~~~~~~~~~~~~~~~~~~~ +ECHO ERRORLEVEL^: %EL% + +:DONE + +ECHO ~~~~~~~~~~~~~~~~~~~ DONE %~f0 ~~~~~~~~~~~~~~~~~~~ + +EXIT /b %EL% diff --git a/scripts/windows-build-local.bat b/scripts/windows-build-local.bat new file mode 100644 index 000000000..07ca620fc --- /dev/null +++ b/scripts/windows-build-local.bat @@ -0,0 +1,31 @@ +@ECHO OFF +SETLOCAL +SET EL=0 + +REM this file is supposed to be called from the root of the repository +REM otherwise path references will not work + +IF NOT EXIST C:\Qt\5.11.1\msvc2017_64\lib SET EL=1 && ECHO QT not found && GOTO ERROR +SET PATH=C:\Program Files\7-Zip;%PATH% + +REM set env vars normally set by AppVeyor +SET configuration=Release +SET APPVEYOR_BUILD_FOLDER=%CD% +SET CMAKE_VERSION=cmake-3.10.1-win64-x64 +SET CMAKE_URL=https://cmake.org/files/v3.10/%CMAKE_VERSION%.zip + +CALL scripts\windows-build-appveyor.bat +IF %ERRORLEVEL% NEQ 0 GOTO ERROR + +GOTO DONE + +:ERROR +SET EL=%ERRORLEVEL% +ECHO ~~~~~~~~~~~~~~~~~~~ ERROR %~f0 ~~~~~~~~~~~~~~~~~~~ +ECHO ERRORLEVEL^: %EL% + +:DONE + +ECHO ~~~~~~~~~~~~~~~~~~~ DONE %~f0 ~~~~~~~~~~~~~~~~~~~ + +EXIT /b %EL% diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index c8181d7e8..f53690f42 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -1,28 +1,27 @@ #pragma once +#include <mbgl/gl/color_mode.hpp> +#include <mbgl/gl/depth_mode.hpp> +#include <mbgl/gl/draw_mode.hpp> #include <mbgl/gl/features.hpp> +#include <mbgl/gl/framebuffer.hpp> +#include <mbgl/gl/index_buffer.hpp> #include <mbgl/gl/object.hpp> +#include <mbgl/gl/renderbuffer.hpp> #include <mbgl/gl/state.hpp> -#include <mbgl/gl/value.hpp> +#include <mbgl/gl/stencil_mode.hpp> #include <mbgl/gl/texture.hpp> -#include <mbgl/gl/renderbuffer.hpp> -#include <mbgl/gl/framebuffer.hpp> -#include <mbgl/gl/vertex_buffer.hpp> -#include <mbgl/gl/index_buffer.hpp> -#include <mbgl/gl/vertex_array.hpp> #include <mbgl/gl/types.hpp> -#include <mbgl/gl/draw_mode.hpp> -#include <mbgl/gl/depth_mode.hpp> -#include <mbgl/gl/stencil_mode.hpp> -#include <mbgl/gl/color_mode.hpp> +#include <mbgl/gl/value.hpp> +#include <mbgl/gl/vertex_array.hpp> +#include <mbgl/gl/vertex_buffer.hpp> #include <mbgl/util/noncopyable.hpp> - +#include <array> #include <functional> #include <memory> -#include <vector> -#include <array> #include <string> +#include <vector> namespace mbgl { namespace gl { @@ -58,32 +57,34 @@ public: #if MBGL_HAS_BINARY_PROGRAMS bool supportsProgramBinaries() const; #else - constexpr bool supportsProgramBinaries() const { return false; } + constexpr bool supportsProgramBinaries() const { + return false; + } #endif optional<std::pair<BinaryProgramFormat, std::string>> getBinaryProgram(ProgramID) const; template <class Vertex, class DrawMode> - VertexBuffer<Vertex, DrawMode> createVertexBuffer(VertexVector<Vertex, DrawMode>&& v, const BufferUsage usage = BufferUsage::StaticDraw) { - return VertexBuffer<Vertex, DrawMode> { - v.vertexSize(), - createVertexBuffer(v.data(), v.byteSize(), usage) - }; + VertexBuffer<Vertex, DrawMode> + createVertexBuffer(VertexVector<Vertex, DrawMode>&& v, + const BufferUsage usage = BufferUsage::StaticDraw) { + return VertexBuffer<Vertex, DrawMode>{ v.vertexSize(), + createVertexBuffer(v.data(), v.byteSize(), usage) }; } template <class Vertex, class DrawMode> - void updateVertexBuffer(VertexBuffer<Vertex, DrawMode>& buffer, VertexVector<Vertex, DrawMode>&& v) { + void updateVertexBuffer(VertexBuffer<Vertex, DrawMode>& buffer, + VertexVector<Vertex, DrawMode>&& v) { assert(v.vertexSize() == buffer.vertexCount); updateVertexBuffer(buffer.buffer, v.data(), v.byteSize()); } template <class DrawMode> - IndexBuffer<DrawMode> createIndexBuffer(IndexVector<DrawMode>&& v, const BufferUsage usage = BufferUsage::StaticDraw) { - return IndexBuffer<DrawMode> { - v.indexSize(), - createIndexBuffer(v.data(), v.byteSize(), usage) - }; + IndexBuffer<DrawMode> createIndexBuffer(IndexVector<DrawMode>&& v, + const BufferUsage usage = BufferUsage::StaticDraw) { + return IndexBuffer<DrawMode>{ v.indexSize(), + createIndexBuffer(v.data(), v.byteSize(), usage) }; } - + template <class DrawMode> void updateIndexBuffer(IndexBuffer<DrawMode>& buffer, IndexVector<DrawMode>&& v) { assert(v.indexSize() == buffer.indexCount); @@ -92,9 +93,8 @@ public: template <RenderbufferType type> Renderbuffer<type> createRenderbuffer(const Size size) { - static_assert(type == RenderbufferType::RGBA || - type == RenderbufferType::DepthStencil || - type == RenderbufferType::DepthComponent, + static_assert(type == RenderbufferType::RGBA || type == RenderbufferType::DepthStencil || + type == RenderbufferType::DepthComponent, "invalid renderbuffer type"); return { size, createRenderbuffer(type, size) }; } @@ -159,9 +159,7 @@ public: TextureWrap wrapX = TextureWrap::Clamp, TextureWrap wrapY = TextureWrap::Clamp); - void clear(optional<mbgl::Color> color, - optional<float> depth, - optional<int32_t> stencil); + void clear(optional<mbgl::Color> color, optional<float> depth, optional<int32_t> stencil); void setDrawMode(const Points&); void setDrawMode(const Lines&); @@ -173,9 +171,7 @@ public: void setStencilMode(const StencilMode&); void setColorMode(const ColorMode&); - void draw(PrimitiveType, - std::size_t indexOffset, - std::size_t indexLength); + void draw(PrimitiveType, std::size_t indexOffset, std::size_t indexLength); // Actually remove the objects we marked as abandoned with the above methods. // Only call this while the OpenGL context is exclusive to this thread. @@ -186,13 +182,9 @@ public: void reset(); bool empty() const { - return pooledTextures.empty() - && abandonedPrograms.empty() - && abandonedShaders.empty() - && abandonedBuffers.empty() - && abandonedTextures.empty() - && abandonedVertexArrays.empty() - && abandonedFramebuffers.empty(); + return pooledTextures.empty() && abandonedPrograms.empty() && abandonedShaders.empty() && + abandonedBuffers.empty() && abandonedTextures.empty() && + abandonedVertexArrays.empty() && abandonedFramebuffers.empty(); } void setDirtyState(); @@ -227,8 +219,8 @@ public: State<value::Program> program; State<value::BindVertexBuffer> vertexBuffer; - State<value::BindVertexArray, const Context&> bindVertexArray { *this }; - VertexArrayState globalVertexArrayState { UniqueVertexArray(0, { this }) }; + State<value::BindVertexArray, const Context&> bindVertexArray{ *this }; + VertexArrayState globalVertexArrayState{ UniqueVertexArray(0, { const_cast<Context*>(this) }) }; State<value::PixelStorePack> pixelStorePack; State<value::PixelStoreUnpack> pixelStoreUnpack; @@ -243,7 +235,7 @@ public: bool supportsHalfFloatTextures = false; const uint32_t maximumVertexBindingCount; static constexpr const uint32_t minimumRequiredVertexBindingCount = 8; - + private: State<value::StencilFunc> stencilFunc; State<value::StencilMask> stencilMask; @@ -271,8 +263,10 @@ private: void updateVertexBuffer(UniqueBuffer& buffer, const void* data, std::size_t size); UniqueBuffer createIndexBuffer(const void* data, std::size_t size, const BufferUsage usage); void updateIndexBuffer(UniqueBuffer& buffer, const void* data, std::size_t size); - UniqueTexture createTexture(Size size, const void* data, TextureFormat, TextureUnit, TextureType); - void updateTexture(TextureID, Size size, const void* data, TextureFormat, TextureUnit, TextureType); + UniqueTexture + createTexture(Size size, const void* data, TextureFormat, TextureUnit, TextureType); + void + updateTexture(TextureID, Size size, const void* data, TextureFormat, TextureUnit, TextureType); UniqueFramebuffer createFramebuffer(); UniqueRenderbuffer createRenderbuffer(RenderbufferType, Size size); std::unique_ptr<uint8_t[]> readFramebuffer(Size, TextureFormat, bool flip); diff --git a/src/mbgl/gl/vertex_array.hpp b/src/mbgl/gl/vertex_array.hpp index 604754f67..e64174e1a 100644 --- a/src/mbgl/gl/vertex_array.hpp +++ b/src/mbgl/gl/vertex_array.hpp @@ -1,7 +1,7 @@ #pragma once -#include <mbgl/gl/object.hpp> #include <mbgl/gl/attribute.hpp> +#include <mbgl/gl/object.hpp> #include <mbgl/gl/state.hpp> #include <mbgl/gl/value.hpp> @@ -15,8 +15,7 @@ class Context; class VertexArrayState { public: - VertexArrayState(UniqueVertexArray vertexArray_) - : vertexArray(std::move(vertexArray_)) { + VertexArrayState(UniqueVertexArray vertexArray_) : vertexArray(std::move(vertexArray_)) { } void setDirty() { @@ -35,8 +34,8 @@ public: class VertexArrayStateDeleter { public: - VertexArrayStateDeleter(bool destroy_) - : destroy(destroy_) {} + VertexArrayStateDeleter(bool destroy_) : destroy(destroy_) { + } void operator()(VertexArrayState* ptr) const { if (destroy) { @@ -52,9 +51,9 @@ using UniqueVertexArrayState = std::unique_ptr<VertexArrayState, VertexArrayStat class VertexArray { public: - VertexArray(UniqueVertexArrayState state_) - : state(std::move(state_)) { + VertexArray(UniqueVertexArrayState state_) : state(std::move(state_)) { } + VertexArray(VertexArray&& other) = default; void bind(Context&, BufferID indexBuffer, const AttributeBindingArray&); |