diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2019-02-27 12:47:34 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2019-03-01 09:33:37 +0100 |
commit | 55c7b86053816e74c3fd3c0595c1fa053970f959 (patch) | |
tree | c34be5d76008fad4f28d39e9c39cc85ad31b72fe /src | |
parent | 7f1428ed3b90b54f503760471869ac83def32a59 (diff) | |
download | qtlocation-mapboxgl-55c7b86053816e74c3fd3c0595c1fa053970f959.tar.gz |
[core] extract uniform type lists from gl namespace
Diffstat (limited to 'src')
28 files changed, 179 insertions, 150 deletions
diff --git a/src/core-files.json b/src/core-files.json index 30b12075ed..590cd3c620 100644 --- a/src/core-files.json +++ b/src/core-files.json @@ -498,6 +498,7 @@ "mbgl/geometry/dem_data.hpp": "src/mbgl/geometry/dem_data.hpp", "mbgl/geometry/feature_index.hpp": "src/mbgl/geometry/feature_index.hpp", "mbgl/geometry/line_atlas.hpp": "src/mbgl/geometry/line_atlas.hpp", + "mbgl/gfx/uniform.hpp": "src/mbgl/gfx/uniform.hpp", "mbgl/gl/attribute.hpp": "src/mbgl/gl/attribute.hpp", "mbgl/gl/color_mode.hpp": "src/mbgl/gl/color_mode.hpp", "mbgl/gl/context.hpp": "src/mbgl/gl/context.hpp", diff --git a/src/mbgl/gfx/uniform.hpp b/src/mbgl/gfx/uniform.hpp new file mode 100644 index 0000000000..bc6e7c1866 --- /dev/null +++ b/src/mbgl/gfx/uniform.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include <mbgl/util/type_list.hpp> +#include <mbgl/util/indexed_tuple.hpp> + +#include <array> + +#define MBGL_DEFINE_UNIFORM_SCALAR(type_, name_) \ + struct name_ { \ + using Value = type_; \ + static constexpr auto name() { \ + return #name_; \ + } \ + } + +#define MBGL_DEFINE_UNIFORM_VECTOR(type_, n_, name_) \ + struct name_ { \ + using Value = std::array<type_, n_>; \ + static constexpr auto name() { \ + return #name_; \ + } \ + } + +#define MBGL_DEFINE_UNIFORM_MATRIX(type_, n_, name_) \ + struct name_ { \ + using Value = std::array<type_, n_ * n_>; \ + static constexpr auto name() { \ + return #name_; \ + } \ + } + +namespace mbgl { +namespace gfx { +namespace detail { + +template <class> +class UniformValues; + +template <class... Us> +class UniformValues<TypeList<Us...>> { +public: + using Type = IndexedTuple<TypeList<Us...>, TypeList<typename Us::Value...>>; +}; + +} // namespace detail + +template <class UniformTypeList> +using UniformValues = typename detail::UniformValues<UniformTypeList>::Type; + +} // namespace gfx +} // namespace mbgl diff --git a/src/mbgl/gl/uniform.cpp b/src/mbgl/gl/uniform.cpp index e6c77be50b..21017d6436 100644 --- a/src/mbgl/gl/uniform.cpp +++ b/src/mbgl/gl/uniform.cpp @@ -63,7 +63,7 @@ void bindUniform<bool>(UniformLocation location, const bool& t) { } template <> -void bindUniform<uint8_t>(UniformLocation location, const uint8_t& t) { +void bindUniform<uint32_t>(UniformLocation location, const uint32_t& t) { bindUniform(location, int32_t(t)); } @@ -153,7 +153,7 @@ bool verifyUniform<bool>(const ActiveUniform& uniform) { } template <> -bool verifyUniform<uint8_t>(const ActiveUniform& uniform) { +bool verifyUniform<uint32_t>(const ActiveUniform& uniform) { assert(uniform.size == 1 && (uniform.type == UniformDataType::Int || uniform.type == UniformDataType::Float || diff --git a/src/mbgl/gl/uniform.hpp b/src/mbgl/gl/uniform.hpp index 9e841c3c15..38a0a759b3 100644 --- a/src/mbgl/gl/uniform.hpp +++ b/src/mbgl/gl/uniform.hpp @@ -32,52 +32,30 @@ ActiveUniforms activeUniforms(ProgramID); #endif -template <class T> -class Uniform { +template <class Value> +class UniformState { public: - using Value = T; - - class State { - public: - State(UniformLocation location_) : location(std::move(location_)) {} + UniformState(UniformLocation location_) : location(std::move(location_)) { + } - void operator=(const Value& value) { - if (location >= 0 && (!current || *current != value)) { - current = value; - bindUniform(location, value); - } + void operator=(const Value& value) { + if (location >= 0 && (!current || *current != value)) { + current = value; + bindUniform(location, value); } + } - UniformLocation location; - optional<T> current = {}; - }; + UniformLocation location; + optional<Value> current = {}; }; -template <class T> -using UniformScalar = Uniform<T>; - -template <class T, size_t N> -using UniformVector = Uniform<std::array<T, N>>; - -template <class T, size_t N> -using UniformMatrix = Uniform<std::array<T, N*N>>; - -#define MBGL_DEFINE_UNIFORM_SCALAR(type_, name_) \ - struct name_ : ::mbgl::gl::UniformScalar<type_> { static auto name() { return #name_; } } - -#define MBGL_DEFINE_UNIFORM_VECTOR(type_, n_, name_) \ - struct name_ : ::mbgl::gl::UniformVector<type_, n_> { static auto name() { return #name_; } } - -#define MBGL_DEFINE_UNIFORM_MATRIX(type_, n_, name_) \ - struct name_ : ::mbgl::gl::UniformMatrix<type_, n_> { static auto name() { return #name_; } } - UniformLocation uniformLocation(ProgramID, const char * name); template <class... Us> class Uniforms { public: using Types = TypeList<Us...>; - using State = IndexedTuple<TypeList<Us...>, TypeList<typename Us::State...>>; + using State = IndexedTuple<TypeList<Us...>, TypeList<UniformState<typename Us::Value>...>>; using Values = IndexedTuple<TypeList<Us...>, TypeList<typename Us::Value...>>; using NamedLocations = std::vector<std::pair<const std::string, UniformLocation>>; diff --git a/src/mbgl/programs/background_program.cpp b/src/mbgl/programs/background_program.cpp index 94d7aab2c8..eeaa3e8ca6 100644 --- a/src/mbgl/programs/background_program.cpp +++ b/src/mbgl/programs/background_program.cpp @@ -10,8 +10,8 @@ using namespace style; static_assert(sizeof(BackgroundLayoutVertex) == 4, "expected BackgroundLayoutVertex size"); -BackgroundPatternUniforms::Values -BackgroundPatternUniforms::values(mat4 matrix, +BackgroundPatternProgram::UniformValues +BackgroundPatternProgram::uniformValues(mat4 matrix, float opacity, Size atlasSize, const ImagePosition& a, @@ -24,7 +24,7 @@ BackgroundPatternUniforms::values(mat4 matrix, int32_t pixelX = tileSizeAtNearestZoom * (tileID.canonical.x + tileID.wrap * state.zoomScale(tileID.canonical.z)); int32_t pixelY = tileSizeAtNearestZoom * tileID.canonical.y; - return BackgroundPatternUniforms::Values { + return { uniforms::u_matrix::Value( matrix ), uniforms::u_opacity::Value( opacity ), uniforms::u_texsize::Value( atlasSize ), diff --git a/src/mbgl/programs/background_program.hpp b/src/mbgl/programs/background_program.hpp index 6f9ab2a200..1cdc99e0ca 100644 --- a/src/mbgl/programs/background_program.hpp +++ b/src/mbgl/programs/background_program.hpp @@ -21,13 +21,12 @@ template <class> class Faded; using BackgroundLayoutAttributes = PositionOnlyLayoutAttributes; -struct BackgroundUniforms : gl::Uniforms< +using BackgroundUniforms = TypeList< uniforms::u_matrix, uniforms::u_color, - uniforms::u_opacity> -{}; + uniforms::u_opacity>; -struct BackgroundPatternUniforms : gl::Uniforms< +using BackgroundPatternUniforms = TypeList< uniforms::u_matrix, uniforms::u_opacity, uniforms::u_texsize, @@ -43,17 +42,7 @@ struct BackgroundPatternUniforms : gl::Uniforms< uniforms::u_image, uniforms::u_pixel_coord_upper, uniforms::u_pixel_coord_lower, - uniforms::u_tile_units_to_pixels> -{ - static Values values(mat4 matrix, - float opacity, - Size atlasSize, - const ImagePosition&, - const ImagePosition&, - const CrossfadeParameters&, - const UnwrappedTileID&, - const TransformState&); -}; + uniforms::u_tile_units_to_pixels>; class BackgroundProgram : public Program< shaders::background, @@ -75,6 +64,15 @@ class BackgroundPatternProgram : public Program< { public: using Program::Program; + + static UniformValues uniformValues(mat4 matrix, + float opacity, + Size atlasSize, + const ImagePosition&, + const ImagePosition&, + const CrossfadeParameters&, + const UnwrappedTileID&, + const TransformState&); }; using BackgroundLayoutVertex = BackgroundProgram::LayoutVertex; diff --git a/src/mbgl/programs/circle_program.hpp b/src/mbgl/programs/circle_program.hpp index b75dd18c5e..debf7a81c2 100644 --- a/src/mbgl/programs/circle_program.hpp +++ b/src/mbgl/programs/circle_program.hpp @@ -18,7 +18,7 @@ class CircleProgram : public Program< gl::Triangle, gl::Attributes< attributes::a_pos>, - gl::Uniforms< + TypeList< uniforms::u_matrix, uniforms::u_scale_with_map, uniforms::u_extrude_scale, diff --git a/src/mbgl/programs/clipping_mask_program.hpp b/src/mbgl/programs/clipping_mask_program.hpp index 5dff4849fe..87111b0da9 100644 --- a/src/mbgl/programs/clipping_mask_program.hpp +++ b/src/mbgl/programs/clipping_mask_program.hpp @@ -12,7 +12,7 @@ class ClippingMaskProgram : public Program< shaders::clipping_mask, gl::Triangle, PositionOnlyLayoutAttributes, - gl::Uniforms< + TypeList< uniforms::u_matrix>, style::Properties<>> { diff --git a/src/mbgl/programs/collision_box_program.hpp b/src/mbgl/programs/collision_box_program.hpp index 0b1abf97c7..9b3d82cd16 100644 --- a/src/mbgl/programs/collision_box_program.hpp +++ b/src/mbgl/programs/collision_box_program.hpp @@ -29,7 +29,7 @@ class CollisionBoxProgram : public Program< shaders::collision_box, gl::Line, gl::ConcatenateAttributes<CollisionBoxLayoutAttributes, CollisionBoxDynamicAttributes>, - gl::Uniforms< + TypeList< uniforms::u_matrix, uniforms::u_extrude_scale, uniforms::u_camera_to_center_distance>, @@ -109,7 +109,7 @@ class CollisionCircleProgram : public Program< shaders::collision_circle, gl::Triangle, gl::ConcatenateAttributes<CollisionBoxLayoutAttributes, CollisionBoxDynamicAttributes>, - gl::Uniforms< + TypeList< uniforms::u_matrix, uniforms::u_extrude_scale, uniforms::u_overscale_factor, diff --git a/src/mbgl/programs/debug_program.hpp b/src/mbgl/programs/debug_program.hpp index 7a6d075cdb..0accd490ab 100644 --- a/src/mbgl/programs/debug_program.hpp +++ b/src/mbgl/programs/debug_program.hpp @@ -13,7 +13,7 @@ class DebugProgram : public Program< gl::Line, gl::Attributes< attributes::a_pos>, - gl::Uniforms< + TypeList< uniforms::u_matrix, uniforms::u_color>, style::Properties<>> diff --git a/src/mbgl/programs/extrusion_texture_program.hpp b/src/mbgl/programs/extrusion_texture_program.hpp index bd82208885..fc53563e74 100644 --- a/src/mbgl/programs/extrusion_texture_program.hpp +++ b/src/mbgl/programs/extrusion_texture_program.hpp @@ -13,7 +13,7 @@ class ExtrusionTextureProgram : public Program< shaders::extrusion_texture, gl::Triangle, gl::Attributes<attributes::a_pos>, - gl::Uniforms< + TypeList< uniforms::u_matrix, uniforms::u_world, uniforms::u_image, diff --git a/src/mbgl/programs/fill_extrusion_program.cpp b/src/mbgl/programs/fill_extrusion_program.cpp index 2bdd0604d7..b262485b35 100644 --- a/src/mbgl/programs/fill_extrusion_program.cpp +++ b/src/mbgl/programs/fill_extrusion_program.cpp @@ -31,11 +31,11 @@ float lightIntensity(const EvaluatedLight& light) { return light.get<LightIntensity>(); } -FillExtrusionUniforms::Values -FillExtrusionUniforms::values(mat4 matrix, - const TransformState& state, - const EvaluatedLight& light) { - return FillExtrusionUniforms::Values{ +FillExtrusionProgram::UniformValues +FillExtrusionProgram::uniformValues(mat4 matrix, + const TransformState& state, + const EvaluatedLight& light) { + return { uniforms::u_matrix::Value( matrix ), uniforms::u_lightcolor::Value( lightColor(light) ), uniforms::u_lightpos::Value( lightPosition(light, state) ), @@ -43,21 +43,21 @@ FillExtrusionUniforms::values(mat4 matrix, }; } -FillExtrusionPatternUniforms::Values -FillExtrusionPatternUniforms::values(mat4 matrix, - Size atlasSize, - const CrossfadeParameters& crossfade, - const UnwrappedTileID& tileID, - const TransformState& state, - const float heightFactor, - const float pixelRatio, - const EvaluatedLight& light) { +FillExtrusionPatternProgram::UniformValues +FillExtrusionPatternProgram::uniformValues(mat4 matrix, + Size atlasSize, + const CrossfadeParameters& crossfade, + const UnwrappedTileID& tileID, + const TransformState& state, + const float heightFactor, + const float pixelRatio, + const EvaluatedLight& light) { const auto tileRatio = 1 / tileID.pixelsToTileUnits(1, state.getIntegerZoom()); int32_t tileSizeAtNearestZoom = util::tileSize * state.zoomScale(state.getIntegerZoom() - tileID.canonical.z); int32_t pixelX = tileSizeAtNearestZoom * (tileID.canonical.x + tileID.wrap * state.zoomScale(tileID.canonical.z)); int32_t pixelY = tileSizeAtNearestZoom * tileID.canonical.y; - return FillExtrusionPatternUniforms::Values{ + return { uniforms::u_matrix::Value( matrix ), uniforms::u_scale::Value( {{pixelRatio, tileRatio, crossfade.fromScale, crossfade.toScale}} ), uniforms::u_texsize::Value( atlasSize ), diff --git a/src/mbgl/programs/fill_extrusion_program.hpp b/src/mbgl/programs/fill_extrusion_program.hpp index 4573119e70..d8f07aec4c 100644 --- a/src/mbgl/programs/fill_extrusion_program.hpp +++ b/src/mbgl/programs/fill_extrusion_program.hpp @@ -34,18 +34,13 @@ struct FillExtrusionLayoutAttributes : gl::Attributes< attributes::a_normal_ed> {}; -struct FillExtrusionUniforms : gl::Uniforms< +using FillExtrusionUniforms = TypeList< uniforms::u_matrix, uniforms::u_lightcolor, uniforms::u_lightpos, - uniforms::u_lightintensity> -{ - static Values values(mat4, - const TransformState&, - const EvaluatedLight&); -}; + uniforms::u_lightintensity>; -struct FillExtrusionPatternUniforms : gl::Uniforms< +using FillExtrusionPatternUniforms = TypeList< uniforms::u_matrix, uniforms::u_scale, uniforms::u_texsize, @@ -56,17 +51,7 @@ struct FillExtrusionPatternUniforms : gl::Uniforms< uniforms::u_height_factor, uniforms::u_lightcolor, uniforms::u_lightpos, - uniforms::u_lightintensity> -{ - static Values values(mat4, - Size atlasSize, - const CrossfadeParameters&, - const UnwrappedTileID&, - const TransformState&, - const float heightFactor, - const float pixelRatio, - const EvaluatedLight&); -}; + uniforms::u_lightintensity>; class FillExtrusionProgram : public Program< shaders::fill_extrusion, @@ -97,6 +82,11 @@ public: }} }; } + + static UniformValues uniformValues(mat4, + const TransformState&, + const EvaluatedLight&); + }; class FillExtrusionPatternProgram : public Program< @@ -108,6 +98,15 @@ class FillExtrusionPatternProgram : public Program< { public: using Program::Program; + + static UniformValues uniformValues(mat4, + Size atlasSize, + const CrossfadeParameters&, + const UnwrappedTileID&, + const TransformState&, + const float heightFactor, + const float pixelRatio, + const EvaluatedLight&); }; using FillExtrusionLayoutVertex = FillExtrusionProgram::LayoutVertex; diff --git a/src/mbgl/programs/fill_program.cpp b/src/mbgl/programs/fill_program.cpp index b072343e7a..9bf1257e89 100644 --- a/src/mbgl/programs/fill_program.cpp +++ b/src/mbgl/programs/fill_program.cpp @@ -10,8 +10,8 @@ using namespace style; static_assert(sizeof(FillLayoutVertex) == 4, "expected FillLayoutVertex size"); -FillPatternUniforms::Values -FillPatternUniforms::values(mat4 matrix, +FillPatternProgram::UniformValues +FillPatternProgram::uniformValues(mat4 matrix, Size framebufferSize, Size atlasSize, const CrossfadeParameters& crossfade, @@ -24,7 +24,7 @@ FillPatternUniforms::values(mat4 matrix, int32_t pixelX = tileSizeAtNearestZoom * (tileID.canonical.x + tileID.wrap * state.zoomScale(tileID.canonical.z)); int32_t pixelY = tileSizeAtNearestZoom * tileID.canonical.y; - return FillPatternUniforms::Values { + return { uniforms::u_matrix::Value( matrix ), uniforms::u_world::Value( framebufferSize ), uniforms::u_texsize::Value( atlasSize ), diff --git a/src/mbgl/programs/fill_program.hpp b/src/mbgl/programs/fill_program.hpp index 12544ec073..b0037ca7f9 100644 --- a/src/mbgl/programs/fill_program.hpp +++ b/src/mbgl/programs/fill_program.hpp @@ -23,12 +23,11 @@ template <class> class Faded; using FillLayoutAttributes = PositionOnlyLayoutAttributes; -struct FillUniforms : gl::Uniforms< +using FillUniforms = TypeList< uniforms::u_matrix, - uniforms::u_world> -{}; + uniforms::u_world>; -struct FillPatternUniforms : gl::Uniforms< +using FillPatternUniforms = TypeList< uniforms::u_matrix, uniforms::u_world, uniforms::u_texsize, @@ -36,16 +35,7 @@ struct FillPatternUniforms : gl::Uniforms< uniforms::u_fade, uniforms::u_image, uniforms::u_pixel_coord_upper, - uniforms::u_pixel_coord_lower> -{ - static Values values(mat4 matrix, - Size framebufferSize, - Size atlasSize, - const CrossfadeParameters& crossfade, - const UnwrappedTileID&, - const TransformState&, - const float pixelRatio); -}; + uniforms::u_pixel_coord_lower>; class FillProgram : public Program< shaders::fill, @@ -76,6 +66,14 @@ class FillPatternProgram : public Program< { public: using Program::Program; + + static UniformValues uniformValues(mat4 matrix, + Size framebufferSize, + Size atlasSize, + const CrossfadeParameters& crossfade, + const UnwrappedTileID&, + const TransformState&, + const float pixelRatio); }; class FillOutlineProgram : public Program< diff --git a/src/mbgl/programs/heatmap_program.hpp b/src/mbgl/programs/heatmap_program.hpp index f558dc4eaa..98208c02c8 100644 --- a/src/mbgl/programs/heatmap_program.hpp +++ b/src/mbgl/programs/heatmap_program.hpp @@ -19,7 +19,7 @@ class HeatmapProgram : public Program< gl::Triangle, gl::Attributes< attributes::a_pos>, - gl::Uniforms< + TypeList< uniforms::u_intensity, uniforms::u_matrix, uniforms::heatmap::u_extrude_scale>, diff --git a/src/mbgl/programs/heatmap_texture_program.hpp b/src/mbgl/programs/heatmap_texture_program.hpp index 7afe8060d0..060e0cc397 100644 --- a/src/mbgl/programs/heatmap_texture_program.hpp +++ b/src/mbgl/programs/heatmap_texture_program.hpp @@ -10,14 +10,14 @@ namespace mbgl { namespace uniforms { -MBGL_DEFINE_UNIFORM_SCALAR(gl::TextureUnit, u_color_ramp); +MBGL_DEFINE_UNIFORM_SCALAR(uint32_t, u_color_ramp); } // namespace uniforms class HeatmapTextureProgram : public Program< shaders::heatmap_texture, gl::Triangle, gl::Attributes<attributes::a_pos>, - gl::Uniforms< + TypeList< uniforms::u_matrix, uniforms::u_world, uniforms::u_image, diff --git a/src/mbgl/programs/hillshade_prepare_program.hpp b/src/mbgl/programs/hillshade_prepare_program.hpp index 76638afddd..fe077611f8 100644 --- a/src/mbgl/programs/hillshade_prepare_program.hpp +++ b/src/mbgl/programs/hillshade_prepare_program.hpp @@ -19,7 +19,7 @@ class HillshadePrepareProgram : public Program< gl::Attributes< attributes::a_pos, attributes::a_texture_pos>, - gl::Uniforms< + TypeList< uniforms::u_matrix, uniforms::u_dimension, uniforms::u_zoom, diff --git a/src/mbgl/programs/hillshade_program.hpp b/src/mbgl/programs/hillshade_program.hpp index aaef884b80..10143146de 100644 --- a/src/mbgl/programs/hillshade_program.hpp +++ b/src/mbgl/programs/hillshade_program.hpp @@ -24,7 +24,7 @@ class HillshadeProgram : public Program< gl::Attributes< attributes::a_pos, attributes::a_texture_pos>, - gl::Uniforms< + TypeList< uniforms::u_matrix, uniforms::u_image, uniforms::u_highlight, diff --git a/src/mbgl/programs/line_program.hpp b/src/mbgl/programs/line_program.hpp index e43fa171c6..54553e29e7 100644 --- a/src/mbgl/programs/line_program.hpp +++ b/src/mbgl/programs/line_program.hpp @@ -38,7 +38,7 @@ class LineProgram : public Program< shaders::line, gl::Triangle, LineLayoutAttributes, - gl::Uniforms< + TypeList< uniforms::u_matrix, uniforms::u_ratio, uniforms::u_gl_units_to_pixels>, @@ -102,7 +102,7 @@ class LinePatternProgram : public Program< shaders::line_pattern, gl::Triangle, LineLayoutAttributes, - gl::Uniforms< + TypeList< uniforms::u_matrix, uniforms::u_ratio, uniforms::u_gl_units_to_pixels, @@ -128,7 +128,7 @@ class LineSDFProgram : public Program< shaders::line_sdf, gl::Triangle, LineLayoutAttributes, - gl::Uniforms< + TypeList< uniforms::u_matrix, uniforms::u_ratio, uniforms::u_gl_units_to_pixels, @@ -159,7 +159,7 @@ class LineGradientProgram : public Program< shaders::line_gradient, gl::Triangle, LineLayoutAttributes, - gl::Uniforms< + TypeList< uniforms::u_matrix, uniforms::u_ratio, uniforms::u_gl_units_to_pixels, diff --git a/src/mbgl/programs/program.hpp b/src/mbgl/programs/program.hpp index 7c97727d89..30d226854f 100644 --- a/src/mbgl/programs/program.hpp +++ b/src/mbgl/programs/program.hpp @@ -17,7 +17,7 @@ namespace mbgl { template <class Shaders, class Primitive, class LayoutAttrs, - class Uniforms, + class UniformTypeList, class PaintProps> class Program { public: @@ -29,9 +29,9 @@ public: using PaintAttributes = typename PaintPropertyBinders::Attributes; using Attributes = gl::ConcatenateAttributes<LayoutAttributes, PaintAttributes>; - using UniformValues = typename Uniforms::Values; - using PaintUniforms = typename PaintPropertyBinders::Uniforms; - using AllUniforms = gl::ConcatenateUniforms<Uniforms, PaintUniforms>; + using UniformValues = gfx::UniformValues<UniformTypeList>; + using PaintUniformTypeList = typename PaintPropertyBinders::UniformTypeList; + using AllUniforms = typename TypeListConcat<UniformTypeList, PaintUniformTypeList>::template ExpandInto<gl::Uniforms>; using ProgramType = gl::Program<Primitive, Attributes, AllUniforms>; diff --git a/src/mbgl/programs/raster_program.hpp b/src/mbgl/programs/raster_program.hpp index a07e5c3870..b470ff6841 100644 --- a/src/mbgl/programs/raster_program.hpp +++ b/src/mbgl/programs/raster_program.hpp @@ -10,8 +10,8 @@ namespace mbgl { namespace uniforms { -MBGL_DEFINE_UNIFORM_SCALAR(gl::TextureUnit, u_image0); -MBGL_DEFINE_UNIFORM_SCALAR(gl::TextureUnit, u_image1); +MBGL_DEFINE_UNIFORM_SCALAR(uint32_t, u_image0); +MBGL_DEFINE_UNIFORM_SCALAR(uint32_t, u_image1); MBGL_DEFINE_UNIFORM_SCALAR(float, u_fade_t); MBGL_DEFINE_UNIFORM_SCALAR(float, u_buffer_scale); MBGL_DEFINE_UNIFORM_SCALAR(float, u_brightness_low); @@ -29,7 +29,7 @@ class RasterProgram : public Program< gl::Attributes< attributes::a_pos, attributes::a_texture_pos>, - gl::Uniforms< + TypeList< uniforms::u_matrix, uniforms::u_image0, uniforms::u_image1, diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp index 8f64225679..820173f7b7 100644 --- a/src/mbgl/programs/symbol_program.hpp +++ b/src/mbgl/programs/symbol_program.hpp @@ -33,7 +33,7 @@ class TransformState; namespace uniforms { MBGL_DEFINE_UNIFORM_MATRIX(double, 4, u_gl_coord_matrix); MBGL_DEFINE_UNIFORM_MATRIX(double, 4, u_label_plane_matrix); -MBGL_DEFINE_UNIFORM_SCALAR(gl::TextureUnit, u_texture); +MBGL_DEFINE_UNIFORM_SCALAR(uint32_t, u_texture); MBGL_DEFINE_UNIFORM_SCALAR(bool, u_is_halo); MBGL_DEFINE_UNIFORM_SCALAR(float, u_gamma_scale); @@ -109,12 +109,12 @@ class SymbolSizeBinder { public: virtual ~SymbolSizeBinder() = default; - using Uniforms = gl::Uniforms< + using UniformTypeList = TypeList< uniforms::u_is_size_zoom_constant, uniforms::u_is_size_feature_constant, uniforms::u_size_t, uniforms::u_size>; - using UniformValues = Uniforms::Values; + using UniformValues = gfx::UniformValues<UniformTypeList>; static std::unique_ptr<SymbolSizeBinder> create(const float tileZoom, const style::PropertyValue<float>& sizeProperty, @@ -246,7 +246,7 @@ public: template <class Shaders, class Primitive, class LayoutAttrs, - class Uniforms, + class UniformTypeList, class PaintProps> class SymbolProgram { public: @@ -260,10 +260,10 @@ public: using PaintAttributes = typename PaintPropertyBinders::Attributes; using Attributes = gl::ConcatenateAttributes<LayoutAndSizeAttributes, PaintAttributes>; - using UniformValues = typename Uniforms::Values; - using SizeUniforms = typename SymbolSizeBinder::Uniforms; - using PaintUniforms = typename PaintPropertyBinders::Uniforms; - using AllUniforms = gl::ConcatenateUniforms<Uniforms, SizeUniforms, PaintUniforms>; + using UniformValues = gfx::UniformValues<UniformTypeList>; + using SizeUniformTypeList = typename SymbolSizeBinder::UniformTypeList; + using PaintUniformTypeList = typename PaintPropertyBinders::UniformTypeList; + using AllUniforms = typename TypeListConcat<UniformTypeList, SizeUniformTypeList, PaintUniformTypeList>::template ExpandInto<gl::Uniforms>; using ProgramType = gl::Program<Primitive, Attributes, AllUniforms>; @@ -346,7 +346,7 @@ class SymbolIconProgram : public SymbolProgram< shaders::symbol_icon, gl::Triangle, SymbolLayoutAttributes, - gl::Uniforms< + TypeList< uniforms::u_matrix, uniforms::u_label_plane_matrix, uniforms::u_gl_coord_matrix, @@ -385,7 +385,7 @@ class SymbolSDFProgram : public SymbolProgram< shaders::symbol_sdf, gl::Triangle, SymbolLayoutAttributes, - gl::Uniforms< + TypeList< uniforms::u_matrix, uniforms::u_label_plane_matrix, uniforms::u_gl_coord_matrix, @@ -407,7 +407,7 @@ public: using BaseProgram = SymbolProgram<shaders::symbol_sdf, gl::Triangle, SymbolLayoutAttributes, - gl::Uniforms< + TypeList< uniforms::u_matrix, uniforms::u_label_plane_matrix, uniforms::u_gl_coord_matrix, diff --git a/src/mbgl/programs/uniforms.hpp b/src/mbgl/programs/uniforms.hpp index ab68e43c87..f634122181 100644 --- a/src/mbgl/programs/uniforms.hpp +++ b/src/mbgl/programs/uniforms.hpp @@ -1,6 +1,7 @@ #pragma once -#include <mbgl/gl/uniform.hpp> +#include <mbgl/gfx/uniform.hpp> +#include <mbgl/util/size.hpp> #include <mbgl/util/color.hpp> namespace mbgl { @@ -59,8 +60,8 @@ MBGL_DEFINE_UNIFORM_VECTOR(float, 2, u_pixel_coord_upper); MBGL_DEFINE_UNIFORM_VECTOR(float, 2, u_pixel_coord_lower); MBGL_DEFINE_UNIFORM_SCALAR(float, u_mix); -MBGL_DEFINE_UNIFORM_SCALAR(gl::TextureUnit, u_image); -MBGL_DEFINE_UNIFORM_SCALAR(gl::TextureUnit, u_fadetexture); +MBGL_DEFINE_UNIFORM_SCALAR(uint32_t, u_image); +MBGL_DEFINE_UNIFORM_SCALAR(uint32_t, u_fadetexture); MBGL_DEFINE_UNIFORM_SCALAR(float, u_scale_a); MBGL_DEFINE_UNIFORM_SCALAR(float, u_scale_b); MBGL_DEFINE_UNIFORM_SCALAR(float, u_tile_units_to_pixels); diff --git a/src/mbgl/renderer/layers/render_background_layer.cpp b/src/mbgl/renderer/layers/render_background_layer.cpp index a563d49611..4171e3a670 100644 --- a/src/mbgl/renderer/layers/render_background_layer.cpp +++ b/src/mbgl/renderer/layers/render_background_layer.cpp @@ -91,7 +91,7 @@ void RenderBackgroundLayer::render(PaintParameters& parameters, RenderSource*) { for (const auto& tileID : util::tileCover(parameters.state, parameters.state.getIntegerZoom())) { draw( parameters.programs.getBackgroundLayerPrograms().backgroundPattern, - BackgroundPatternUniforms::values( + BackgroundPatternProgram::uniformValues( parameters.matrixForTile(tileID), evaluated.get<BackgroundOpacity>(), parameters.imageManager.getPixelSize(), diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp index 0a22f89341..fe1641a092 100644 --- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp @@ -114,7 +114,7 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource* draw( parameters.programs.getFillExtrusionLayerPrograms().fillExtrusion.get(evaluated), bucket, - FillExtrusionUniforms::values( + FillExtrusionProgram::uniformValues( tile.translatedClipMatrix(evaluated.get<FillExtrusionTranslate>(), evaluated.get<FillExtrusionTranslateAnchor>(), parameters.state), @@ -141,7 +141,7 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource* draw( parameters.programs.getFillExtrusionLayerPrograms().fillExtrusionPattern.get(evaluated), bucket, - FillExtrusionPatternUniforms::values( + FillExtrusionPatternProgram::uniformValues( tile.translatedClipMatrix(evaluated.get<FillExtrusionTranslate>(), evaluated.get<FillExtrusionTranslateAnchor>(), parameters.state), diff --git a/src/mbgl/renderer/layers/render_fill_layer.cpp b/src/mbgl/renderer/layers/render_fill_layer.cpp index c2e62acae2..9b4a5c6361 100644 --- a/src/mbgl/renderer/layers/render_fill_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_layer.cpp @@ -166,7 +166,7 @@ void RenderFillLayer::render(PaintParameters& parameters, RenderSource*) { paintPropertyBinders.setPatternParameters(patternPosA, patternPosB, crossfade); const auto allUniformValues = programInstance.computeAllUniformValues( - FillPatternUniforms::values( + FillPatternProgram::uniformValues( tile.translatedMatrix(evaluated.get<FillTranslate>(), evaluated.get<FillTranslateAnchor>(), parameters.state), diff --git a/src/mbgl/renderer/paint_property_binder.hpp b/src/mbgl/renderer/paint_property_binder.hpp index a382597995..9449ca5823 100644 --- a/src/mbgl/renderer/paint_property_binder.hpp +++ b/src/mbgl/renderer/paint_property_binder.hpp @@ -1,5 +1,6 @@ #pragma once +#include <mbgl/gfx/uniform.hpp> #include <mbgl/programs/attributes.hpp> #include <mbgl/gl/attribute.hpp> #include <mbgl/gl/uniform.hpp> @@ -419,7 +420,8 @@ struct ZoomInterpolatedAttribute { }; template <class Attr> -struct InterpolationUniform : gl::UniformScalar<float> { +struct InterpolationUniformType { + using Value = float; static auto name() { static const std::string name = Attr::name() + std::string("_t"); return name.c_str(); @@ -439,7 +441,7 @@ private: struct Detail<T, UniformValueType, PossiblyEvaluatedType, TypeList<As...>> { using Binder = PaintPropertyBinder<T, UniformValueType, PossiblyEvaluatedType, typename As::Type...>; using ZoomInterpolatedAttributeList = TypeList<ZoomInterpolatedAttribute<As>...>; - using InterpolationUniformList = TypeList<InterpolationUniform<As>...>; + using InterpolationUniformTypeList = TypeList<InterpolationUniformType<As>...>; }; template <class P> @@ -483,7 +485,7 @@ public: template <class P> using ZoomInterpolatedAttributeList = typename Property<P>::ZoomInterpolatedAttributeList; template <class P> - using InterpolationUniformList = typename Property<P>::InterpolationUniformList; + using InterpolationUniformTypeList = typename Property<P>::InterpolationUniformTypeList; using Attributes = typename TypeListConcat<ZoomInterpolatedAttributeList<Ps>...>::template ExpandInto<gl::Attributes>; using AttributeBindings = typename Attributes::Bindings; @@ -495,8 +497,9 @@ public: ) }; } - using Uniforms = typename TypeListConcat<InterpolationUniformList<Ps>..., typename Ps::Uniforms...>::template ExpandInto<gl::Uniforms>; - using UniformValues = typename Uniforms::Values; + using UniformTypeList = TypeListConcat<InterpolationUniformTypeList<Ps>..., typename Ps::Uniforms...>; + using UniformValues = gfx::UniformValues<UniformTypeList>; + using Uniforms = typename UniformTypeList::template ExpandInto<gl::Uniforms>; template <class EvaluatedProperties> UniformValues uniformValues(float currentZoom, EvaluatedProperties& currentProperties) const { |