From e27f33062994a1b0155b44b9d471e48e93b09f8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 7 Mar 2019 17:50:02 +0100 Subject: [core] add texture bindings to draw call instead of Context member fn --- src/mbgl/programs/background_program.cpp | 1 - src/mbgl/programs/background_program.hpp | 5 +++-- src/mbgl/programs/binary_program.cpp | 27 ++++++++++++++++++++++--- src/mbgl/programs/binary_program.hpp | 3 +++ src/mbgl/programs/extrusion_texture_program.hpp | 5 +++-- src/mbgl/programs/fill_extrusion_program.cpp | 1 - src/mbgl/programs/fill_extrusion_program.hpp | 5 +++-- src/mbgl/programs/fill_program.cpp | 1 - src/mbgl/programs/fill_program.hpp | 8 +++++--- src/mbgl/programs/heatmap_texture_program.hpp | 11 ++++------ src/mbgl/programs/hillshade_prepare_program.hpp | 7 ++++--- src/mbgl/programs/hillshade_program.hpp | 5 +++-- src/mbgl/programs/line_program.cpp | 9 +++------ src/mbgl/programs/line_program.hpp | 19 ++++++++--------- src/mbgl/programs/program.hpp | 2 +- src/mbgl/programs/raster_program.hpp | 9 ++++----- src/mbgl/programs/symbol_program.cpp | 1 - src/mbgl/programs/symbol_program.hpp | 16 +++++++-------- src/mbgl/programs/textures.hpp | 15 ++++++++++++++ src/mbgl/programs/uniforms.hpp | 2 -- 20 files changed, 93 insertions(+), 59 deletions(-) create mode 100644 src/mbgl/programs/textures.hpp (limited to 'src/mbgl/programs') diff --git a/src/mbgl/programs/background_program.cpp b/src/mbgl/programs/background_program.cpp index eeaa3e8ca6..99c9c55e84 100644 --- a/src/mbgl/programs/background_program.cpp +++ b/src/mbgl/programs/background_program.cpp @@ -37,7 +37,6 @@ BackgroundPatternProgram::uniformValues(mat4 matrix, uniforms::u_scale_a::Value( fading.fromScale ), uniforms::u_scale_b::Value( fading.toScale ), uniforms::u_mix::Value( fading.t ), - uniforms::u_image::Value( 0 ), uniforms::u_pixel_coord_upper::Value( std::array {{ float(pixelX >> 16), float(pixelY >> 16) }}), uniforms::u_pixel_coord_lower::Value( std::array {{ float(pixelX & 0xFFFF), float(pixelY & 0xFFFF)}}), uniforms::u_tile_units_to_pixels::Value( 1.0f / tileID.pixelsToTileUnits(1.0f, state.getIntegerZoom()) ), diff --git a/src/mbgl/programs/background_program.hpp b/src/mbgl/programs/background_program.hpp index 4f94ed16f4..9899fb695a 100644 --- a/src/mbgl/programs/background_program.hpp +++ b/src/mbgl/programs/background_program.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -39,7 +40,6 @@ using BackgroundPatternUniforms = TypeList< uniforms::u_scale_a, uniforms::u_scale_b, uniforms::u_mix, - uniforms::u_image, uniforms::u_pixel_coord_upper, uniforms::u_pixel_coord_lower, uniforms::u_tile_units_to_pixels>; @@ -61,7 +61,8 @@ class BackgroundPatternProgram : public Program< gfx::Triangle, BackgroundLayoutAttributes, BackgroundPatternUniforms, - TypeList<>, + TypeList< + textures::u_image>, style::Properties<>> { public: diff --git a/src/mbgl/programs/binary_program.cpp b/src/mbgl/programs/binary_program.cpp index da629194b4..598a547252 100644 --- a/src/mbgl/programs/binary_program.cpp +++ b/src/mbgl/programs/binary_program.cpp @@ -52,9 +52,14 @@ BinaryProgram::BinaryProgram(std::string&& data) { uniforms.emplace_back(parseBinding(pbf.get_message())); break; case 5: // identifier - default: binaryIdentifier = pbf.get_string(); break; + case 6: // uniform + textures.emplace_back(parseBinding(pbf.get_message())); + break; + default: + pbf.skip(); + break; } } @@ -68,12 +73,14 @@ BinaryProgram::BinaryProgram( std::string&& binaryCode_, std::string binaryIdentifier_, std::vector>&& attributes_, - std::vector>&& uniforms_) + std::vector>&& uniforms_, + std::vector>&& textures_) : binaryFormat(binaryFormat_), binaryCode(std::move(binaryCode_)), binaryIdentifier(std::move(binaryIdentifier_)), attributes(std::move(attributes_)), - uniforms(std::move(uniforms_)) { + uniforms(std::move(uniforms_)), + textures(std::move(textures_)) { } std::string BinaryProgram::serialize() const { @@ -92,6 +99,11 @@ std::string BinaryProgram::serialize() const { pbf_binding.add_string(1 /* name */, binding.first); pbf_binding.add_uint32(2 /* value */, binding.second); } + for (const auto& binding : textures) { + protozero::pbf_writer pbf_binding(pbf, 6 /* texture */); + pbf_binding.add_string(1 /* name */, binding.first); + pbf_binding.add_uint32(2 /* value */, binding.second); + } if (!binaryIdentifier.empty()) { pbf.add_string(5 /* identifier */, binaryIdentifier); } @@ -116,4 +128,13 @@ gl::UniformLocation BinaryProgram::uniformLocation(const std::string& name) cons return -1; } +gl::UniformLocation BinaryProgram::textureLocation(const std::string& name) const { + for (const auto& pair : textures) { + if (pair.first == name) { + return pair.second; + } + } + return -1; +} + } // namespace mbgl diff --git a/src/mbgl/programs/binary_program.hpp b/src/mbgl/programs/binary_program.hpp index 8690f3fd6f..1ae874800b 100644 --- a/src/mbgl/programs/binary_program.hpp +++ b/src/mbgl/programs/binary_program.hpp @@ -17,6 +17,7 @@ public: std::string&& binaryCode, std::string binaryIdentifier, std::vector>&&, + std::vector>&&, std::vector>&&); std::string serialize() const; @@ -33,6 +34,7 @@ public: optional attributeLocation(const std::string& name) const; gl::UniformLocation uniformLocation(const std::string& name) const; + gl::UniformLocation textureLocation(const std::string& name) const; private: gl::BinaryProgramFormat binaryFormat = 0; @@ -40,6 +42,7 @@ private: std::string binaryIdentifier; std::vector> attributes; std::vector> uniforms; + std::vector> textures; }; } // namespace mbgl diff --git a/src/mbgl/programs/extrusion_texture_program.hpp b/src/mbgl/programs/extrusion_texture_program.hpp index ccbb0398cf..8281037b2a 100644 --- a/src/mbgl/programs/extrusion_texture_program.hpp +++ b/src/mbgl/programs/extrusion_texture_program.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -16,9 +17,9 @@ class ExtrusionTextureProgram : public Program< TypeList< uniforms::u_matrix, uniforms::u_world, - uniforms::u_image, uniforms::u_opacity>, - TypeList<>, + TypeList< + textures::u_image>, style::Properties<>> { public: using Program::Program; diff --git a/src/mbgl/programs/fill_extrusion_program.cpp b/src/mbgl/programs/fill_extrusion_program.cpp index 92916a61ab..fb9c9f7b4a 100644 --- a/src/mbgl/programs/fill_extrusion_program.cpp +++ b/src/mbgl/programs/fill_extrusion_program.cpp @@ -62,7 +62,6 @@ FillExtrusionPatternProgram::uniformValues(mat4 matrix, uniforms::u_scale::Value( {{pixelRatio, tileRatio, crossfade.fromScale, crossfade.toScale}} ), uniforms::u_texsize::Value( atlasSize ), uniforms::u_fade::Value( crossfade.t ), - uniforms::u_image::Value( 0 ), uniforms::u_pixel_coord_upper::Value( std::array{{ float(pixelX >> 16), float(pixelY >> 16) }} ), uniforms::u_pixel_coord_lower::Value( std::array{{ float(pixelX & 0xFFFF), float(pixelY & 0xFFFF) }} ), uniforms::u_height_factor::Value( heightFactor ), diff --git a/src/mbgl/programs/fill_extrusion_program.hpp b/src/mbgl/programs/fill_extrusion_program.hpp index 83a2fd1f60..0723770143 100644 --- a/src/mbgl/programs/fill_extrusion_program.hpp +++ b/src/mbgl/programs/fill_extrusion_program.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -44,7 +45,6 @@ using FillExtrusionPatternUniforms = TypeList< uniforms::u_scale, uniforms::u_texsize, uniforms::u_fade, - uniforms::u_image, uniforms::u_pixel_coord_upper, uniforms::u_pixel_coord_lower, uniforms::u_height_factor, @@ -94,7 +94,8 @@ class FillExtrusionPatternProgram : public Program< gfx::Triangle, FillExtrusionLayoutAttributes, FillExtrusionPatternUniforms, - TypeList<>, + TypeList< + textures::u_image>, style::FillExtrusionPaintProperties> { public: diff --git a/src/mbgl/programs/fill_program.cpp b/src/mbgl/programs/fill_program.cpp index 9bf1257e89..2c290dd15d 100644 --- a/src/mbgl/programs/fill_program.cpp +++ b/src/mbgl/programs/fill_program.cpp @@ -30,7 +30,6 @@ FillPatternProgram::uniformValues(mat4 matrix, uniforms::u_texsize::Value( atlasSize ), uniforms::u_scale::Value({ {pixelRatio, tileRatio, crossfade.fromScale, crossfade.toScale} } ), uniforms::u_fade::Value( crossfade.t ), - uniforms::u_image::Value( 0 ), uniforms::u_pixel_coord_upper::Value( std::array {{ float(pixelX >> 16), float(pixelY >> 16) }}), uniforms::u_pixel_coord_lower::Value( std::array {{ float(pixelX & 0xFFFF), float(pixelY & 0xFFFF) }} ) }; diff --git a/src/mbgl/programs/fill_program.hpp b/src/mbgl/programs/fill_program.hpp index 47d09912ad..5c0fbdcb62 100644 --- a/src/mbgl/programs/fill_program.hpp +++ b/src/mbgl/programs/fill_program.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -33,7 +34,6 @@ using FillPatternUniforms = TypeList< uniforms::u_texsize, uniforms::u_scale, uniforms::u_fade, - uniforms::u_image, uniforms::u_pixel_coord_upper, uniforms::u_pixel_coord_lower>; @@ -63,7 +63,8 @@ class FillPatternProgram : public Program< gfx::Triangle, FillLayoutAttributes, FillPatternUniforms, - TypeList<>, + TypeList< + textures::u_image>, style::FillPaintProperties> { public: @@ -95,7 +96,8 @@ class FillOutlinePatternProgram : public Program< gfx::Line, FillLayoutAttributes, FillPatternUniforms, - TypeList<>, + TypeList< + textures::u_image>, style::FillPaintProperties> { public: diff --git a/src/mbgl/programs/heatmap_texture_program.hpp b/src/mbgl/programs/heatmap_texture_program.hpp index e193c09180..a1d3835821 100644 --- a/src/mbgl/programs/heatmap_texture_program.hpp +++ b/src/mbgl/programs/heatmap_texture_program.hpp @@ -3,16 +3,13 @@ #include #include #include +#include #include #include #include namespace mbgl { -namespace uniforms { -MBGL_DEFINE_UNIFORM_SCALAR(uint32_t, u_color_ramp); -} // namespace uniforms - class HeatmapTextureProgram : public Program< shaders::heatmap_texture, gfx::Triangle, @@ -20,10 +17,10 @@ class HeatmapTextureProgram : public Program< TypeList< uniforms::u_matrix, uniforms::u_world, - uniforms::u_image, - uniforms::u_color_ramp, uniforms::u_opacity>, - TypeList<>, + TypeList< + textures::u_image, + textures::u_color_ramp>, style::Properties<>> { public: using Program::Program; diff --git a/src/mbgl/programs/hillshade_prepare_program.hpp b/src/mbgl/programs/hillshade_prepare_program.hpp index 44c8ca92be..b58525bbfd 100644 --- a/src/mbgl/programs/hillshade_prepare_program.hpp +++ b/src/mbgl/programs/hillshade_prepare_program.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -23,9 +24,9 @@ class HillshadePrepareProgram : public Program< uniforms::u_matrix, uniforms::u_dimension, uniforms::u_zoom, - uniforms::u_maxzoom, - uniforms::u_image>, - TypeList<>, + uniforms::u_maxzoom>, + TypeList< + textures::u_image>, style::Properties<>> { public: using Program::Program; diff --git a/src/mbgl/programs/hillshade_program.hpp b/src/mbgl/programs/hillshade_program.hpp index 37b5024b76..2a67338c7c 100644 --- a/src/mbgl/programs/hillshade_program.hpp +++ b/src/mbgl/programs/hillshade_program.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -26,13 +27,13 @@ class HillshadeProgram : public Program< attributes::a_texture_pos>, TypeList< uniforms::u_matrix, - uniforms::u_image, uniforms::u_highlight, uniforms::u_shadow, uniforms::u_accent, uniforms::u_light, uniforms::u_latrange>, - TypeList<>, + TypeList< + textures::u_image>, style::HillshadePaintProperties>{ public: using Program::Program; diff --git a/src/mbgl/programs/line_program.cpp b/src/mbgl/programs/line_program.cpp index 55362ad6fe..e5b4cc2ad5 100644 --- a/src/mbgl/programs/line_program.cpp +++ b/src/mbgl/programs/line_program.cpp @@ -77,8 +77,7 @@ LineSDFProgram::uniformValues(const RenderLinePaintProperties::PossiblyEvaluated uniforms::u_tex_y_a::Value( posA.y ), uniforms::u_tex_y_b::Value( posB.y ), uniforms::u_mix::Value( crossfade.t ), - uniforms::u_sdfgamma::Value( atlasWidth / (std::min(widthA, widthB) * 256.0f * pixelRatio) / 2.0f ), - uniforms::u_image::Value( 0 ) + uniforms::u_sdfgamma::Value( atlasWidth / (std::min(widthA, widthB) * 256.0f * pixelRatio) / 2.0f ) ); } @@ -100,8 +99,7 @@ LinePatternProgram::uniformValues(const RenderLinePaintProperties::PossiblyEvalu pixelsToGLUnits, uniforms::u_scale::Value ({ {pixelRatio, tileRatio, crossfade.fromScale, crossfade.toScale} }), uniforms::u_texsize::Value( atlasSize ), - uniforms::u_fade::Value( crossfade.t ), - uniforms::u_image::Value( 0 ) + uniforms::u_fade::Value( crossfade.t ) ); } @@ -114,8 +112,7 @@ LineGradientProgram::uniformValues(const RenderLinePaintProperties::PossiblyEval properties, tile, state, - pixelsToGLUnits, - uniforms::u_image::Value{ 0 } + pixelsToGLUnits ); } diff --git a/src/mbgl/programs/line_program.hpp b/src/mbgl/programs/line_program.hpp index 6f9eefbc67..0e4055bded 100644 --- a/src/mbgl/programs/line_program.hpp +++ b/src/mbgl/programs/line_program.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -108,9 +109,9 @@ class LinePatternProgram : public Program< uniforms::u_gl_units_to_pixels, uniforms::u_scale, uniforms::u_texsize, - uniforms::u_fade, - uniforms::u_image>, - TypeList<>, + uniforms::u_fade>, + TypeList< + textures::u_image>, RenderLinePaintProperties> { public: @@ -138,9 +139,9 @@ class LineSDFProgram : public Program< uniforms::u_tex_y_a, uniforms::u_tex_y_b, uniforms::u_mix, - uniforms::u_sdfgamma, - uniforms::u_image>, - TypeList<>, + uniforms::u_sdfgamma>, + TypeList< + textures::u_image>, RenderLinePaintProperties> { public: @@ -164,9 +165,9 @@ class LineGradientProgram : public Program< TypeList< uniforms::u_matrix, uniforms::u_ratio, - uniforms::u_gl_units_to_pixels, - uniforms::u_image>, - TypeList<>, + uniforms::u_gl_units_to_pixels>, + TypeList< + textures::u_image>, RenderLinePaintProperties> { public: diff --git a/src/mbgl/programs/program.hpp b/src/mbgl/programs/program.hpp index e09fdb32d2..379cc6b842 100644 --- a/src/mbgl/programs/program.hpp +++ b/src/mbgl/programs/program.hpp @@ -37,7 +37,7 @@ public: using TextureBindings = gfx::TextureBindings; - using ProgramType = gl::Program; + using ProgramType = gl::Program; ProgramType program; diff --git a/src/mbgl/programs/raster_program.hpp b/src/mbgl/programs/raster_program.hpp index 618081ab12..a5b4ee36ba 100644 --- a/src/mbgl/programs/raster_program.hpp +++ b/src/mbgl/programs/raster_program.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -10,8 +11,6 @@ namespace mbgl { namespace uniforms { -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); @@ -31,8 +30,6 @@ class RasterProgram : public Program< attributes::a_texture_pos>, TypeList< uniforms::u_matrix, - uniforms::u_image0, - uniforms::u_image1, uniforms::u_opacity, uniforms::u_fade_t, uniforms::u_brightness_low, @@ -43,7 +40,9 @@ class RasterProgram : public Program< uniforms::u_buffer_scale, uniforms::u_scale_parent, uniforms::u_tl_parent>, - TypeList<>, + TypeList< + textures::u_image0, + textures::u_image1>, style::RasterPaintProperties> { public: diff --git a/src/mbgl/programs/symbol_program.cpp b/src/mbgl/programs/symbol_program.cpp index 0c195e4d37..03643d6422 100644 --- a/src/mbgl/programs/symbol_program.cpp +++ b/src/mbgl/programs/symbol_program.cpp @@ -88,7 +88,6 @@ Values makeValues(const bool isText, true) ), uniforms::u_extrude_scale::Value( extrudeScale ), uniforms::u_texsize::Value( texsize ), - uniforms::u_texture::Value( 0 ), uniforms::u_fade_change::Value( symbolFadeChange ), uniforms::u_is_text::Value( isText ), uniforms::u_camera_to_center_distance::Value( state.getCameraToCenterDistance() ), diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp index 9c5bd01ef8..7b8a2c1330 100644 --- a/src/mbgl/programs/symbol_program.hpp +++ b/src/mbgl/programs/symbol_program.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -33,7 +34,6 @@ 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(uint32_t, u_texture); MBGL_DEFINE_UNIFORM_SCALAR(bool, u_is_halo); MBGL_DEFINE_UNIFORM_SCALAR(float, u_gamma_scale); @@ -265,7 +265,7 @@ public: using TextureBindings = gfx::TextureBindings; - using ProgramType = gl::Program; + using ProgramType = gl::Program; ProgramType program; @@ -354,7 +354,6 @@ class SymbolIconProgram : public SymbolProgram< uniforms::u_gl_coord_matrix, uniforms::u_extrude_scale, uniforms::u_texsize, - uniforms::u_texture, uniforms::u_fade_change, uniforms::u_is_text, uniforms::u_camera_to_center_distance, @@ -362,7 +361,8 @@ class SymbolIconProgram : public SymbolProgram< uniforms::u_pitch_with_map, uniforms::u_rotate_symbol, uniforms::u_aspect_ratio>, - TypeList<>, + TypeList< + textures::u_texture>, style::IconPaintProperties> { public: @@ -394,7 +394,6 @@ class SymbolSDFProgram : public SymbolProgram< uniforms::u_gl_coord_matrix, uniforms::u_extrude_scale, uniforms::u_texsize, - uniforms::u_texture, uniforms::u_fade_change, uniforms::u_is_text, uniforms::u_camera_to_center_distance, @@ -404,7 +403,8 @@ class SymbolSDFProgram : public SymbolProgram< uniforms::u_aspect_ratio, uniforms::u_gamma_scale, uniforms::u_is_halo>, - TypeList<>, + TypeList< + textures::u_texture>, PaintProperties> { public: @@ -417,7 +417,6 @@ public: uniforms::u_gl_coord_matrix, uniforms::u_extrude_scale, uniforms::u_texsize, - uniforms::u_texture, uniforms::u_fade_change, uniforms::u_is_text, uniforms::u_camera_to_center_distance, @@ -427,7 +426,8 @@ public: uniforms::u_aspect_ratio, uniforms::u_gamma_scale, uniforms::u_is_halo>, - TypeList<>, + TypeList< + textures::u_texture>, PaintProperties>; using UniformValues = typename BaseProgram::UniformValues; diff --git a/src/mbgl/programs/textures.hpp b/src/mbgl/programs/textures.hpp new file mode 100644 index 0000000000..32bc4a4a35 --- /dev/null +++ b/src/mbgl/programs/textures.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include + +namespace mbgl { +namespace textures { + +MBGL_DEFINE_TEXTURE(u_image); +MBGL_DEFINE_TEXTURE(u_image0); +MBGL_DEFINE_TEXTURE(u_image1); +MBGL_DEFINE_TEXTURE(u_color_ramp); +MBGL_DEFINE_TEXTURE(u_texture); + +} // namespace textures +} // namespace mbgl diff --git a/src/mbgl/programs/uniforms.hpp b/src/mbgl/programs/uniforms.hpp index f634122181..79febf7f73 100644 --- a/src/mbgl/programs/uniforms.hpp +++ b/src/mbgl/programs/uniforms.hpp @@ -60,8 +60,6 @@ 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(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); -- cgit v1.2.1