diff options
author | Lauren Budorick <lauren@mapbox.com> | 2017-04-27 15:56:55 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-27 15:56:55 -0700 |
commit | f6e79d70735361438655f279c8699a786d25458c (patch) | |
tree | cc01ae7aba097bae4aa84beb12ac6b8f34f4d51a /src/mbgl/util | |
parent | 839ad87f37a4880804fb4c79157d998ac59954b5 (diff) | |
download | qtlocation-mapboxgl-f6e79d70735361438655f279c8699a786d25458c.tar.gz |
[core] Render fill-extrusion layers (#8431)
Diffstat (limited to 'src/mbgl/util')
-rw-r--r-- | src/mbgl/util/indexed_tuple.hpp | 56 | ||||
-rw-r--r-- | src/mbgl/util/mat3.cpp | 16 | ||||
-rw-r--r-- | src/mbgl/util/mat3.hpp | 6 | ||||
-rw-r--r-- | src/mbgl/util/offscreen_texture.cpp | 21 | ||||
-rw-r--r-- | src/mbgl/util/offscreen_texture.hpp | 1 | ||||
-rw-r--r-- | src/mbgl/util/type_list.hpp | 40 |
6 files changed, 38 insertions, 102 deletions
diff --git a/src/mbgl/util/indexed_tuple.hpp b/src/mbgl/util/indexed_tuple.hpp deleted file mode 100644 index a414639530..0000000000 --- a/src/mbgl/util/indexed_tuple.hpp +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once - -#include <mbgl/util/type_list.hpp> - -#include <type_traits> -#include <tuple> - -namespace mbgl { - -template <class T, class... Ts> -struct TypeIndex; - -template <class T, class... Ts> -struct TypeIndex<T, T, Ts...> : std::integral_constant<std::size_t, 0> {}; - -template <class T, class U, class... Ts> -struct TypeIndex<T, U, Ts...> : std::integral_constant<std::size_t, 1 + TypeIndex<T, Ts...>::value> {}; - -template <class...> class IndexedTuple; - -// A tuple of Ts, where individual members can be accessed via `t.get<I>()` for I ∈ Is. -// -// See https://github.com/mapbox/cpp/blob/master/C%2B%2B%20Structural%20Metaprogramming.md -// for motivation. -// -template <class... Is, class... Ts> -class IndexedTuple<TypeList<Is...>, TypeList<Ts...>> : public std::tuple<Ts...> { -public: - static_assert(sizeof...(Is) == sizeof...(Ts), "IndexedTuple size mismatch"); - - using std::tuple<Ts...>::tuple; - - template <class I> - static constexpr std::size_t Index = TypeIndex<I, Is...>::value; - - template <class I> - auto& get() { - return std::get<Index<I>>(*this); - } - - template <class I> - const auto& get() const { - return std::get<Index<I>>(*this); - } - - template <class... Js, class... Us> - IndexedTuple<TypeList<Is..., Js...>, TypeList<Ts..., Us...>> - concat(const IndexedTuple<TypeList<Js...>, TypeList<Us...>>& other) const { - return IndexedTuple<TypeList<Is..., Js...>, TypeList<Ts..., Us...>> { - get<Is>()..., - other.template get<Js>()... - }; - } -}; - -} // namespace mbgl diff --git a/src/mbgl/util/mat3.cpp b/src/mbgl/util/mat3.cpp index e2200867ce..107be81985 100644 --- a/src/mbgl/util/mat3.cpp +++ b/src/mbgl/util/mat3.cpp @@ -25,8 +25,9 @@ #include <cmath> namespace mbgl { +namespace matrix { -void matrix::identity(mat3& out) { +void identity(mat3& out) { out[0] = 1.0f; out[1] = 0.0f; out[2] = 0.0f; @@ -38,7 +39,7 @@ void matrix::identity(mat3& out) { out[8] = 1.0f; } -void matrix::translate(mat3& out, const mat3& a, double x, double y) { +void translate(mat3& out, const mat3& a, double x, double y) { double a00 = a[0], a01 = a[1], a02 = a[2], a10 = a[3], a11 = a[4], a12 = a[5], a20 = a[6], a21 = a[7], a22 = a[8]; @@ -56,7 +57,7 @@ void matrix::translate(mat3& out, const mat3& a, double x, double y) { out[8] = x * a02 + y * a12 + a22; } -void matrix::rotate(mat3& out, const mat3& a, double rad) { +void rotate(mat3& out, const mat3& a, double rad) { double s = std::sin(rad), c = std::cos(rad), a00 = a[0], @@ -82,7 +83,7 @@ void matrix::rotate(mat3& out, const mat3& a, double rad) { out[8] = a22; } -void matrix::scale(mat3& out, const mat3& a, double x, double y) { +void scale(mat3& out, const mat3& a, double x, double y) { out[0] = x * a[0]; out[1] = x * a[1]; out[2] = x * a[2]; @@ -94,4 +95,11 @@ void matrix::scale(mat3& out, const mat3& a, double x, double y) { out[8] = a[8]; } +void transformMat3f(vec3f& out, const vec3f& a, const mat3& m) { + out[0] = m[0] * a[0] + m[3] * a[1] + m[6] * a[2]; + out[1] = m[1] * a[0] + m[4] * a[1] + m[7] * a[2]; + out[2] = m[2] * a[0] + m[5] * a[1] + m[8] * a[2]; +} + +} // namespace matrix } // namespace mbgl diff --git a/src/mbgl/util/mat3.hpp b/src/mbgl/util/mat3.hpp index ca4955fe5f..c4203c940b 100644 --- a/src/mbgl/util/mat3.hpp +++ b/src/mbgl/util/mat3.hpp @@ -26,7 +26,9 @@ namespace mbgl { -typedef std::array<double, 9> mat3; +using vec3 = std::array<double, 3>; +using vec3f = std::array<float, 3>; +using mat3 = std::array<double, 9>; namespace matrix { @@ -35,5 +37,7 @@ void translate(mat3& out, const mat3& a, double x, double y); void rotate(mat3& out, const mat3& a, double rad); void scale(mat3& out, const mat3& a, double x, double y); +void transformMat3f(vec3f& out, const vec3f& a, const mat3& m); + } // namespace matrix } // namespace mbgl diff --git a/src/mbgl/util/offscreen_texture.cpp b/src/mbgl/util/offscreen_texture.cpp index 56ef60b15c..e719ac566e 100644 --- a/src/mbgl/util/offscreen_texture.cpp +++ b/src/mbgl/util/offscreen_texture.cpp @@ -14,12 +14,13 @@ public: void bind() { if (!framebuffer) { - texture = context.createTexture(size); + texture = context.createTexture(size, gl::TextureFormat::RGBA); framebuffer = context.createFramebuffer(*texture); } else { context.bindFramebuffer = framebuffer->framebuffer; } + context.activeTexture = 0; context.viewport = { 0, 0, size }; } @@ -36,6 +37,20 @@ public: return size; } + void bindRenderbuffers(gl::TextureUnit unit) { + if (!framebuffer) { + texture = context.createTexture(size, gl::TextureFormat::RGBA, unit); + gl::Renderbuffer<gl::RenderbufferType::DepthComponent> depthTarget = context.createRenderbuffer<gl::RenderbufferType::DepthComponent>(size); + framebuffer = context.createFramebuffer(*texture, depthTarget); + + } else { + context.bindFramebuffer = framebuffer->framebuffer; + } + + context.activeTexture = unit; + context.viewport = { 0, 0, size }; + } + private: gl::Context& context; const Size size; @@ -66,4 +81,8 @@ const Size& OffscreenTexture::getSize() const { return impl->getSize(); } +void OffscreenTexture::bindRenderbuffers(gl::TextureUnit unit) { + impl->bindRenderbuffers(unit); +} + } // namespace mbgl diff --git a/src/mbgl/util/offscreen_texture.hpp b/src/mbgl/util/offscreen_texture.hpp index b8bfabf7d3..4e9e936114 100644 --- a/src/mbgl/util/offscreen_texture.hpp +++ b/src/mbgl/util/offscreen_texture.hpp @@ -16,6 +16,7 @@ public: ~OffscreenTexture(); void bind() override; + void bindRenderbuffers(gl::TextureUnit unit = 0); PremultipliedImage readStillImage(); diff --git a/src/mbgl/util/type_list.hpp b/src/mbgl/util/type_list.hpp deleted file mode 100644 index 4a5e95c8a4..0000000000 --- a/src/mbgl/util/type_list.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include <type_traits> -#include <tuple> - -namespace mbgl { - -template <class...> -class TypeList {}; - -namespace detail { - -template <class, class> -struct TypeCons; - -template <class T, class... Ts> -struct TypeCons<T, TypeList<Ts...>> { - using Type = TypeList<T, Ts...>; -}; - -template <class, template <class> class> -struct TypeFilter; - -template <template <class> class Predicate> -struct TypeFilter<TypeList<>, Predicate> { - using Type = TypeList<>; -}; - -template <template <class> class Predicate, class T, class... Ts> -struct TypeFilter<TypeList<T, Ts...>, Predicate> { - using Tail = typename TypeFilter<TypeList<Ts...>, Predicate>::Type; - using Type = std::conditional_t<Predicate<T>::value, typename TypeCons<T, Tail>::Type, Tail>; -}; - -} // namespace detail - -template <class TypeList, template <class> class Predicate> -using FilteredTypeList = typename detail::TypeFilter<TypeList, Predicate>::Type; - -} // namespace mbgl |