summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2019-03-07 17:50:02 +0100
committerKonstantin Käfer <mail@kkaefer.com>2019-03-11 14:04:19 +0100
commitc83d9a6cc56b88b97ee1b455ed1d02b85fdd43e0 (patch)
tree4686cced26b195374c97f2c389dc39482309484c
parent0bb5e431621b45d29f812a25d8cf26cd26006067 (diff)
downloadqtlocation-mapboxgl-upstream/gfx-refactor-3.tar.gz
[core] add texture bindings to draw call instead of Context member fnupstream/gfx-refactor-3
-rw-r--r--misc/proto/binary_program.proto1
-rw-r--r--src/core-files.json3
-rw-r--r--src/mbgl/geometry/line_atlas.cpp14
-rw-r--r--src/mbgl/geometry/line_atlas.hpp4
-rw-r--r--src/mbgl/gfx/context.hpp22
-rw-r--r--src/mbgl/gfx/texture.hpp20
-rw-r--r--src/mbgl/gl/context.cpp58
-rw-r--r--src/mbgl/gl/context.hpp11
-rw-r--r--src/mbgl/gl/program.hpp18
-rw-r--r--src/mbgl/gl/texture.cpp54
-rw-r--r--src/mbgl/gl/texture.hpp52
-rw-r--r--src/mbgl/gl/texture_resource.hpp4
-rw-r--r--src/mbgl/gl/uniform.cpp5
-rw-r--r--src/mbgl/gl/uniform.hpp2
-rw-r--r--src/mbgl/programs/background_program.cpp1
-rw-r--r--src/mbgl/programs/background_program.hpp5
-rw-r--r--src/mbgl/programs/binary_program.cpp27
-rw-r--r--src/mbgl/programs/binary_program.hpp3
-rw-r--r--src/mbgl/programs/extrusion_texture_program.hpp5
-rw-r--r--src/mbgl/programs/fill_extrusion_program.cpp1
-rw-r--r--src/mbgl/programs/fill_extrusion_program.hpp5
-rw-r--r--src/mbgl/programs/fill_program.cpp1
-rw-r--r--src/mbgl/programs/fill_program.hpp8
-rw-r--r--src/mbgl/programs/heatmap_texture_program.hpp11
-rw-r--r--src/mbgl/programs/hillshade_prepare_program.hpp7
-rw-r--r--src/mbgl/programs/hillshade_program.hpp5
-rw-r--r--src/mbgl/programs/line_program.cpp9
-rw-r--r--src/mbgl/programs/line_program.hpp19
-rw-r--r--src/mbgl/programs/program.hpp2
-rw-r--r--src/mbgl/programs/raster_program.hpp9
-rw-r--r--src/mbgl/programs/symbol_program.cpp1
-rw-r--r--src/mbgl/programs/symbol_program.hpp16
-rw-r--r--src/mbgl/programs/textures.hpp15
-rw-r--r--src/mbgl/programs/uniforms.hpp2
-rw-r--r--src/mbgl/renderer/image_manager.cpp12
-rw-r--r--src/mbgl/renderer/image_manager.hpp4
-rw-r--r--src/mbgl/renderer/layers/render_background_layer.cpp10
-rw-r--r--src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp15
-rw-r--r--src/mbgl/renderer/layers/render_fill_layer.cpp9
-rw-r--r--src/mbgl/renderer/layers/render_heatmap_layer.cpp12
-rw-r--r--src/mbgl/renderer/layers/render_hillshade_layer.cpp26
-rw-r--r--src/mbgl/renderer/layers/render_line_layer.cpp18
-rw-r--r--src/mbgl/renderer/layers/render_raster_layer.cpp31
-rw-r--r--src/mbgl/renderer/layers/render_symbol_layer.cpp32
-rw-r--r--src/mbgl/renderer/renderer_impl.cpp4
-rw-r--r--src/mbgl/shaders/shaders.cpp2
-rw-r--r--src/mbgl/tile/geometry_tile.cpp4
-rw-r--r--src/mbgl/util/offscreen_texture.cpp2
-rw-r--r--test/programs/binary_program.test.cpp7
-rw-r--r--test/util/offscreen_texture.test.cpp3
50 files changed, 374 insertions, 237 deletions
diff --git a/misc/proto/binary_program.proto b/misc/proto/binary_program.proto
index 9d06a209c3..780664ef9c 100644
--- a/misc/proto/binary_program.proto
+++ b/misc/proto/binary_program.proto
@@ -15,4 +15,5 @@ message binary_program {
repeated binding attribute = 3;
repeated binding uniform = 4;
optional string identifier = 5;
+ repeated binding texture = 6;
}
diff --git a/src/core-files.json b/src/core-files.json
index 40a7aab20d..f745a409e5 100644
--- a/src/core-files.json
+++ b/src/core-files.json
@@ -22,6 +22,7 @@
"src/mbgl/gl/debugging_extension.cpp",
"src/mbgl/gl/enum.cpp",
"src/mbgl/gl/object.cpp",
+ "src/mbgl/gl/texture.cpp",
"src/mbgl/gl/uniform.cpp",
"src/mbgl/gl/value.cpp",
"src/mbgl/gl/vertex_array.cpp",
@@ -528,6 +529,7 @@
"mbgl/gl/program_binary_extension.hpp": "src/mbgl/gl/program_binary_extension.hpp",
"mbgl/gl/renderbuffer.hpp": "src/mbgl/gl/renderbuffer.hpp",
"mbgl/gl/state.hpp": "src/mbgl/gl/state.hpp",
+ "mbgl/gl/texture.hpp": "src/mbgl/gl/texture.hpp",
"mbgl/gl/texture_resource.hpp": "src/mbgl/gl/texture_resource.hpp",
"mbgl/gl/types.hpp": "src/mbgl/gl/types.hpp",
"mbgl/gl/uniform.hpp": "src/mbgl/gl/uniform.hpp",
@@ -568,6 +570,7 @@
"mbgl/programs/raster_program.hpp": "src/mbgl/programs/raster_program.hpp",
"mbgl/programs/segment.hpp": "src/mbgl/programs/segment.hpp",
"mbgl/programs/symbol_program.hpp": "src/mbgl/programs/symbol_program.hpp",
+ "mbgl/programs/textures.hpp": "src/mbgl/programs/textures.hpp",
"mbgl/programs/uniforms.hpp": "src/mbgl/programs/uniforms.hpp",
"mbgl/renderer/bucket.hpp": "src/mbgl/renderer/bucket.hpp",
"mbgl/renderer/bucket_parameters.hpp": "src/mbgl/renderer/bucket_parameters.hpp",
diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp
index e1443dc3ab..5f9acab0e8 100644
--- a/src/mbgl/geometry/line_atlas.cpp
+++ b/src/mbgl/geometry/line_atlas.cpp
@@ -126,20 +126,20 @@ Size LineAtlas::getSize() const {
return image.size;
}
-void LineAtlas::upload(gfx::Context& context, uint8_t unit) {
+void LineAtlas::upload(gfx::Context& context) {
if (!texture) {
- texture = context.createTexture(image, unit);
+ texture = context.createTexture(image);
} else if (dirty) {
- context.updateTexture(*texture, image, unit);
+ context.updateTexture(*texture, image);
}
dirty = false;
}
-void LineAtlas::bind(gfx::Context& context, uint8_t unit) {
- upload(context, unit);
- context.bindTexture(*texture, unit, gfx::TextureFilterType::Linear, gfx::TextureMipMapType::No,
- gfx::TextureWrapType::Repeat, gfx::TextureWrapType::Clamp);
+gfx::TextureBinding LineAtlas::textureBinding(gfx::Context& context) {
+ upload(context);
+ return { *texture->resource, gfx::TextureFilterType::Linear, gfx::TextureMipMapType::No,
+ gfx::TextureWrapType::Repeat, gfx::TextureWrapType::Clamp };
}
} // namespace mbgl
diff --git a/src/mbgl/geometry/line_atlas.hpp b/src/mbgl/geometry/line_atlas.hpp
index 96072c700c..3a238f8507 100644
--- a/src/mbgl/geometry/line_atlas.hpp
+++ b/src/mbgl/geometry/line_atlas.hpp
@@ -32,11 +32,11 @@ public:
~LineAtlas();
// Binds the atlas texture to the GPU, and uploads data if it is out of date.
- void bind(gfx::Context&, uint8_t unit);
+ gfx::TextureBinding textureBinding(gfx::Context&);
// Uploads the texture to the GPU to be available when we need it. This is a lazy operation;
// the texture is only bound when the data is out of date (=dirty).
- void upload(gfx::Context&, uint8_t unit);
+ void upload(gfx::Context&);
LinePatternPos getDashPosition(const std::vector<float>&, LinePatternCap);
LinePatternPos addDash(const std::vector<float>& dasharray, LinePatternCap);
diff --git a/src/mbgl/gfx/context.hpp b/src/mbgl/gfx/context.hpp
index 05a87eeeac..5ec73b8a41 100644
--- a/src/mbgl/gfx/context.hpp
+++ b/src/mbgl/gfx/context.hpp
@@ -62,43 +62,33 @@ public:
// Create a texture from an image with data.
template <typename Image>
Texture createTexture(const Image& image,
- uint8_t unit = 0,
TextureChannelDataType type = TextureChannelDataType::UnsignedByte) {
auto format = image.channels == 4 ? TexturePixelType::RGBA : TexturePixelType::Alpha;
return { image.size,
- createTextureResource(image.size, image.data.get(), format, unit, type) };
+ createTextureResource(image.size, image.data.get(), format, type) };
}
// Creates an empty texture with the specified dimensions.
Texture createTexture(const Size size,
TexturePixelType format = TexturePixelType::RGBA,
- uint8_t unit = 0,
TextureChannelDataType type = TextureChannelDataType::UnsignedByte) {
- return { size, createTextureResource(size, nullptr, format, unit, type) };
+ return { size, createTextureResource(size, nullptr, format, type) };
}
template <typename Image>
void updateTexture(Texture& texture,
const Image& image,
- uint8_t unit = 0,
TextureChannelDataType type = TextureChannelDataType::UnsignedByte) {
auto format = image.channels == 4 ? TexturePixelType::RGBA : TexturePixelType::Alpha;
- updateTextureResource(*texture.resource, image.size, image.data.get(), format, unit, type);
+ updateTextureResource(*texture.resource, image.size, image.data.get(), format, type);
texture.size = image.size;
}
- virtual void bindTexture(Texture&,
- uint8_t unit = 0,
- TextureFilterType = TextureFilterType::Nearest,
- TextureMipMapType = TextureMipMapType::No,
- TextureWrapType wrapX = TextureWrapType::Clamp,
- TextureWrapType wrapY = TextureWrapType::Clamp) = 0;
-
protected:
- virtual std::unique_ptr<const TextureResource> createTextureResource(
- Size, const void* data, TexturePixelType, uint8_t unit, TextureChannelDataType) = 0;
+ virtual std::unique_ptr<TextureResource> createTextureResource(
+ Size, const void* data, TexturePixelType, TextureChannelDataType) = 0;
virtual void updateTextureResource(const TextureResource&, Size, const void* data,
- TexturePixelType, uint8_t unit, TextureChannelDataType) = 0;
+ TexturePixelType, TextureChannelDataType) = 0;
};
} // namespace gfx
diff --git a/src/mbgl/gfx/texture.hpp b/src/mbgl/gfx/texture.hpp
index bbda44a8fb..758bdd1b09 100644
--- a/src/mbgl/gfx/texture.hpp
+++ b/src/mbgl/gfx/texture.hpp
@@ -7,6 +7,14 @@
#include <memory>
+#define MBGL_DEFINE_TEXTURE(name_) \
+ struct name_ { \
+ using Value = ::mbgl::gfx::TextureBinding; \
+ static constexpr auto name() { \
+ return #name_; \
+ } \
+ }
+
namespace mbgl {
namespace gfx {
@@ -19,21 +27,17 @@ public:
class Texture {
public:
- Texture(Size size_, std::unique_ptr<const TextureResource>&& resource_)
+ Texture(Size size_, std::unique_ptr<TextureResource>&& resource_)
: size(std::move(size_)), resource(std::move(resource_)) {
}
Size size;
- TextureFilterType filter = TextureFilterType::Nearest;
- TextureMipMapType mipmap = TextureMipMapType::No;
- TextureWrapType wrapX = TextureWrapType::Clamp;
- TextureWrapType wrapY = TextureWrapType::Clamp;
- std::unique_ptr<const TextureResource> resource;
+ std::unique_ptr<TextureResource> resource;
};
class TextureBinding {
public:
- TextureBinding(const TextureResource& resource_,
+ TextureBinding(TextureResource& resource_,
TextureFilterType filter_ = TextureFilterType::Nearest,
TextureMipMapType mipmap_ = TextureMipMapType::No,
TextureWrapType wrapX_ = TextureWrapType::Clamp,
@@ -41,7 +45,7 @@ public:
: resource(&resource_), filter(filter_), mipmap(mipmap_), wrapX(wrapX_), wrapY(wrapY_) {
}
- const TextureResource* resource;
+ TextureResource* resource;
TextureFilterType filter;
TextureMipMapType mipmap;
TextureWrapType wrapX;
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp
index 2758e236e4..ca06ab660d 100644
--- a/src/mbgl/gl/context.cpp
+++ b/src/mbgl/gl/context.cpp
@@ -3,6 +3,7 @@
#include <mbgl/gl/vertex_buffer_resource.hpp>
#include <mbgl/gl/index_buffer_resource.hpp>
#include <mbgl/gl/texture_resource.hpp>
+#include <mbgl/gl/texture.hpp>
#include <mbgl/gl/debugging_extension.hpp>
#include <mbgl/gl/vertex_array_extension.hpp>
#include <mbgl/gl/program_binary_extension.hpp>
@@ -511,16 +512,15 @@ Context::createFramebuffer(const gfx::Texture& color,
return { depthTarget.size, std::move(fbo) };
}
-std::unique_ptr<const gfx::TextureResource>
+std::unique_ptr<gfx::TextureResource>
Context::createTextureResource(const Size size,
const void* data,
gfx::TexturePixelType format,
- uint8_t unit,
gfx::TextureChannelDataType type) {
auto obj = createUniqueTexture();
- std::unique_ptr<const gfx::TextureResource> resource = std::make_unique<gl::TextureResource>(std::move(obj));
+ std::unique_ptr<gfx::TextureResource> resource = std::make_unique<gl::TextureResource>(std::move(obj));
pixelStoreUnpack = { 1 };
- updateTextureResource(*resource, size, data, format, unit, type);
+ updateTextureResource(*resource, size, data, format, type);
// We are using clamp to edge here since OpenGL ES doesn't allow GL_REPEAT on NPOT textures.
// We use those when the pixelRatio isn't a power of two, e.g. on iPhone 6 Plus.
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
@@ -534,60 +534,16 @@ void Context::updateTextureResource(const gfx::TextureResource& resource,
const Size size,
const void* data,
gfx::TexturePixelType format,
- uint8_t unit,
gfx::TextureChannelDataType type) {
- activeTextureUnit = unit;
- texture[unit] = reinterpret_cast<const gl::TextureResource&>(resource).texture;
+ // Always use texture unit 0 for manipulating it.
+ activeTextureUnit = 0;
+ texture[0] = reinterpret_cast<const gl::TextureResource&>(resource).texture;
MBGL_CHECK_ERROR(glTexImage2D(GL_TEXTURE_2D, 0, Enum<gfx::TexturePixelType>::to(format),
size.width, size.height, 0,
Enum<gfx::TexturePixelType>::to(format),
Enum<gfx::TextureChannelDataType>::to(type), data));
}
-void Context::bindTexture(gfx::Texture& obj,
- uint8_t unit,
- gfx::TextureFilterType filter,
- gfx::TextureMipMapType mipmap,
- gfx::TextureWrapType wrapX,
- gfx::TextureWrapType wrapY) {
- TextureID id = reinterpret_cast<const gl::TextureResource&>(*obj.resource).texture;
- if (filter != obj.filter || mipmap != obj.mipmap || wrapX != obj.wrapX || wrapY != obj.wrapY) {
- activeTextureUnit = unit;
- texture[unit] = id;
-
- if (filter != obj.filter || mipmap != obj.mipmap) {
- MBGL_CHECK_ERROR(glTexParameteri(
- GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
- filter == gfx::TextureFilterType::Linear
- ? (mipmap == gfx::TextureMipMapType::Yes ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR)
- : (mipmap == gfx::TextureMipMapType::Yes ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST)));
- MBGL_CHECK_ERROR(
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
- filter == gfx::TextureFilterType::Linear ? GL_LINEAR : GL_NEAREST));
- obj.filter = filter;
- obj.mipmap = mipmap;
- }
- if (wrapX != obj.wrapX) {
-
- MBGL_CHECK_ERROR(
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
- wrapX == gfx::TextureWrapType::Clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT));
- obj.wrapX = wrapX;
- }
- if (wrapY != obj.wrapY) {
- MBGL_CHECK_ERROR(
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
- wrapY == gfx::TextureWrapType::Clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT));
- obj.wrapY = wrapY;
- }
- } else if (texture[unit] != id) {
- // We are checking first to avoid setting the active texture without a subsequent
- // texture bind.
- activeTextureUnit = unit;
- texture[unit] = id;
- }
-}
-
void Context::reset() {
std::copy(pooledTextures.begin(), pooledTextures.end(), std::back_inserter(abandonedTextures));
pooledTextures.resize(0);
diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp
index 1200e3b49a..51b79200ba 100644
--- a/src/mbgl/gl/context.hpp
+++ b/src/mbgl/gl/context.hpp
@@ -88,13 +88,6 @@ public:
return { size, readFramebuffer(size, format, flip) };
}
- void bindTexture(gfx::Texture&,
- uint8_t unit = 0,
- gfx::TextureFilterType = gfx::TextureFilterType::Nearest,
- gfx::TextureMipMapType = gfx::TextureMipMapType::No,
- gfx::TextureWrapType wrapX = gfx::TextureWrapType::Clamp,
- gfx::TextureWrapType wrapY = gfx::TextureWrapType::Clamp) override;
-
#if not MBGL_USE_GLES2
template <typename Image>
void drawPixels(const Image& image) {
@@ -220,8 +213,8 @@ private:
std::unique_ptr<const gfx::IndexBufferResource> createIndexBufferResource(const void* data, std::size_t size, const gfx::BufferUsageType) override;
void updateIndexBufferResource(const gfx::IndexBufferResource&, const void* data, std::size_t size) override;
- std::unique_ptr<const gfx::TextureResource> createTextureResource(Size, const void* data, gfx::TexturePixelType, uint8_t, gfx::TextureChannelDataType) override;
- void updateTextureResource(const gfx::TextureResource&, Size, const void* data, gfx::TexturePixelType, uint8_t, gfx::TextureChannelDataType) override;
+ std::unique_ptr<gfx::TextureResource> createTextureResource(Size, const void* data, gfx::TexturePixelType, gfx::TextureChannelDataType) override;
+ void updateTextureResource(const gfx::TextureResource&, Size, const void* data, gfx::TexturePixelType, gfx::TextureChannelDataType) override;
UniqueFramebuffer createFramebuffer();
UniqueRenderbuffer createRenderbuffer(RenderbufferType, Size size);
diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp
index 050ec6c268..ffa3e07391 100644
--- a/src/mbgl/gl/program.hpp
+++ b/src/mbgl/gl/program.hpp
@@ -8,6 +8,7 @@
#include <mbgl/gl/vertex_array.hpp>
#include <mbgl/gl/attribute.hpp>
#include <mbgl/gl/uniform.hpp>
+#include <mbgl/gl/texture.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/logging.hpp>
@@ -20,7 +21,7 @@
namespace mbgl {
namespace gl {
-template <class P, class As, class Us, class TBs>
+template <class P, class As, class Us, class TextureList>
class Program {
public:
using Primitive = P;
@@ -29,7 +30,7 @@ public:
using UniformValues = typename Uniforms::Values;
using AttributeBindings = typename Attributes::Bindings;
- using TextureBindings = TBs;
+ using TextureBindings = gfx::TextureBindings<TextureList>;
Program(Context& context, const std::string& vertexSource, const std::string& fragmentSource)
: program(
@@ -37,13 +38,15 @@ public:
context.createShader(ShaderType::Fragment, fragmentSource))),
uniformsState((context.linkProgram(program), Uniforms::bindLocations(program))),
attributeLocations(Attributes::bindLocations(context, program)) {
-
// Re-link program after manually binding only active attributes in Attributes::bindLocations
context.linkProgram(program);
// We have to re-initialize the uniforms state from the bindings as the uniform locations
// get shifted on some implementations
uniformsState = Uniforms::bindLocations(program);
+
+ // Texture units are specified via uniforms as well, so we need query their locations
+ textures.queryLocations(program);
}
template <class BinaryProgram>
@@ -51,6 +54,7 @@ public:
: program(context.createProgram(binaryProgram.format(), binaryProgram.code())),
uniformsState(Uniforms::loadNamedLocations(binaryProgram)),
attributeLocations(Attributes::loadNamedLocations(binaryProgram)) {
+ textures.loadNamedLocations(binaryProgram);
}
static Program createProgram(gl::Context& context,
@@ -108,7 +112,8 @@ public:
if (auto binaryProgram = context.getBinaryProgram(program)) {
return BinaryProgram{ binaryProgram->first, std::move(binaryProgram->second),
identifier, Attributes::getNamedLocations(attributeLocations),
- Uniforms::getNamedLocations(uniformsState) };
+ Uniforms::getNamedLocations(uniformsState),
+ textures.getNamedLocations() };
}
return {};
}
@@ -129,8 +134,6 @@ public:
std::size_t indexLength) {
static_assert(std::is_same<Primitive, typename DrawMode::Primitive>::value, "incompatible draw mode");
- (void)textureBindings;
-
context.setDrawMode(drawMode);
context.setDepthMode(depthMode);
context.setStencilMode(stencilMode);
@@ -141,6 +144,8 @@ public:
Uniforms::bind(uniformsState, uniformValues);
+ textures.bind(context, textureBindings);
+
vertexArray.bind(context,
indexBuffer,
Attributes::toBindingArray(attributeLocations, attributeBindings));
@@ -155,6 +160,7 @@ private:
typename Uniforms::State uniformsState;
typename Attributes::Locations attributeLocations;
+ gl::Textures<TextureList> textures;
};
} // namespace gl
diff --git a/src/mbgl/gl/texture.cpp b/src/mbgl/gl/texture.cpp
new file mode 100644
index 0000000000..2b41e7ae8e
--- /dev/null
+++ b/src/mbgl/gl/texture.cpp
@@ -0,0 +1,54 @@
+#include <mbgl/gl/texture.hpp>
+#include <mbgl/gl/context.hpp>
+#include <mbgl/gl/texture_resource.hpp>
+#include <mbgl/gl/defines.hpp>
+
+namespace mbgl {
+namespace gl {
+
+using namespace platform;
+
+void bindTexture(gl::Context& context, const uint8_t unit, const gfx::TextureBinding& binding) {
+ auto& resource = reinterpret_cast<gl::TextureResource&>(*binding.resource);
+ if (binding.filter != resource.filter || binding.mipmap != resource.mipmap ||
+ binding.wrapX != resource.wrapX || binding.wrapY != resource.wrapY) {
+ context.activeTextureUnit = unit;
+ context.texture[unit] = resource.texture;
+
+ if (binding.filter != resource.filter || binding.mipmap != resource.mipmap) {
+ MBGL_CHECK_ERROR(glTexParameteri(
+ GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+ binding.filter == gfx::TextureFilterType::Linear
+ ? (binding.mipmap == gfx::TextureMipMapType::Yes ? GL_LINEAR_MIPMAP_NEAREST
+ : GL_LINEAR)
+ : (binding.mipmap == gfx::TextureMipMapType::Yes ? GL_NEAREST_MIPMAP_NEAREST
+ : GL_NEAREST)));
+ MBGL_CHECK_ERROR(glTexParameteri(
+ GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
+ binding.filter == gfx::TextureFilterType::Linear ? GL_LINEAR : GL_NEAREST));
+ resource.filter = binding.filter;
+ resource.mipmap = binding.mipmap;
+ }
+ if (binding.wrapX != resource.wrapX) {
+
+ MBGL_CHECK_ERROR(glTexParameteri(
+ GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
+ binding.wrapX == gfx::TextureWrapType::Clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT));
+ resource.wrapX = binding.wrapX;
+ }
+ if (binding.wrapY != resource.wrapY) {
+ MBGL_CHECK_ERROR(glTexParameteri(
+ GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
+ binding.wrapY == gfx::TextureWrapType::Clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT));
+ resource.wrapY = binding.wrapY;
+ }
+ } else if (context.texture[unit] != resource.texture) {
+ // We are checking first to avoid setting the active texture without a subsequent
+ // texture bind.
+ context.activeTextureUnit = unit;
+ context.texture[unit] = resource.texture;
+ }
+}
+
+} // namespace gl
+} // namespace mbgl
diff --git a/src/mbgl/gl/texture.hpp b/src/mbgl/gl/texture.hpp
new file mode 100644
index 0000000000..8230be1652
--- /dev/null
+++ b/src/mbgl/gl/texture.hpp
@@ -0,0 +1,52 @@
+#pragma once
+
+#include <mbgl/gfx/texture.hpp>
+#include <mbgl/gl/uniform.hpp>
+#include <mbgl/util/ignore.hpp>
+
+#include <vector>
+#include <string>
+
+namespace mbgl {
+namespace gl {
+
+class Context;
+
+void bindTexture(gl::Context&, uint8_t unit, const gfx::TextureBinding&);
+
+template <class>
+class Textures;
+
+template <class... Ts>
+class Textures<TypeList<Ts...>> {
+ using State =
+ IndexedTuple<TypeList<Ts...>, TypeList<ExpandToType<Ts, gl::UniformState<uint8_t>>...>>;
+ using NamedLocations = std::vector<std::pair<const std::string, gl::UniformLocation>>;
+
+public:
+ void queryLocations(const ProgramID& id) {
+ state = State{ gl::uniformLocation(id, Ts::name())... };
+ }
+
+ template <class BinaryProgram>
+ void loadNamedLocations(const BinaryProgram& program) {
+ state = State{ program.textureLocation(Ts::name())... };
+ }
+
+ NamedLocations getNamedLocations() const {
+ return NamedLocations{ { Ts::name(), state.template get<Ts>().location }... };
+ }
+
+ void bind(gl::Context& context, const gfx::TextureBindings<TypeList<Ts...>>& bindings) {
+ util::ignore(
+ { (state.template get<Ts>() = TypeIndex<Ts, Ts...>::value,
+ gl::bindTexture(context, TypeIndex<Ts, Ts...>::value, bindings.template get<Ts>()),
+ 0)... });
+ }
+
+private:
+ State state;
+};
+
+} // namespace gl
+} // namespace mbgl
diff --git a/src/mbgl/gl/texture_resource.hpp b/src/mbgl/gl/texture_resource.hpp
index 4803f9b7f4..ed742e75b7 100644
--- a/src/mbgl/gl/texture_resource.hpp
+++ b/src/mbgl/gl/texture_resource.hpp
@@ -12,6 +12,10 @@ public:
}
UniqueTexture texture;
+ gfx::TextureFilterType filter = gfx::TextureFilterType::Nearest;
+ gfx::TextureMipMapType mipmap = gfx::TextureMipMapType::No;
+ gfx::TextureWrapType wrapX = gfx::TextureWrapType::Clamp;
+ gfx::TextureWrapType wrapY = gfx::TextureWrapType::Clamp;
};
} // namespace gl
diff --git a/src/mbgl/gl/uniform.cpp b/src/mbgl/gl/uniform.cpp
index 21017d6436..8d99d4b467 100644
--- a/src/mbgl/gl/uniform.cpp
+++ b/src/mbgl/gl/uniform.cpp
@@ -68,6 +68,11 @@ void bindUniform<uint32_t>(UniformLocation location, const uint32_t& t) {
}
template <>
+void bindUniform<uint8_t>(UniformLocation location, const uint8_t& t) {
+ bindUniform(location, int32_t(t));
+}
+
+template <>
void bindUniform<Color>(UniformLocation location, const Color& t) {
bindUniform(location, std::array<float, 4> {{ t.r, t.g, t.b, t.a }});
}
diff --git a/src/mbgl/gl/uniform.hpp b/src/mbgl/gl/uniform.hpp
index c5aa2d6c39..3827015bb3 100644
--- a/src/mbgl/gl/uniform.hpp
+++ b/src/mbgl/gl/uniform.hpp
@@ -35,7 +35,7 @@ ActiveUniforms activeUniforms(ProgramID);
template <class Value>
class UniformState {
public:
- UniformState(UniformLocation location_) : location(std::move(location_)) {
+ UniformState(UniformLocation location_ = -1) : location(std::move(location_)) {
}
void operator=(const Value& value) {
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, 2> {{ float(pixelX >> 16), float(pixelY >> 16) }}),
uniforms::u_pixel_coord_lower::Value( std::array<float, 2> {{ 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 <mbgl/programs/program.hpp>
#include <mbgl/programs/attributes.hpp>
#include <mbgl/programs/uniforms.hpp>
+#include <mbgl/programs/textures.hpp>
#include <mbgl/shaders/background.hpp>
#include <mbgl/shaders/background_pattern.hpp>
#include <mbgl/util/geometry.hpp>
@@ -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<gl::UniformLocation>(pbf.get_message()));
break;
case 5: // identifier
- default:
binaryIdentifier = pbf.get_string();
break;
+ case 6: // uniform
+ textures.emplace_back(parseBinding<gl::UniformLocation>(pbf.get_message()));
+ break;
+ default:
+ pbf.skip();
+ break;
}
}
@@ -68,12 +73,14 @@ BinaryProgram::BinaryProgram(
std::string&& binaryCode_,
std::string binaryIdentifier_,
std::vector<std::pair<const std::string, gl::AttributeLocation>>&& attributes_,
- std::vector<std::pair<const std::string, gl::UniformLocation>>&& uniforms_)
+ std::vector<std::pair<const std::string, gl::UniformLocation>>&& uniforms_,
+ std::vector<std::pair<const std::string, gl::UniformLocation>>&& 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::pair<const std::string, gl::AttributeLocation>>&&,
+ std::vector<std::pair<const std::string, gl::UniformLocation>>&&,
std::vector<std::pair<const std::string, gl::UniformLocation>>&&);
std::string serialize() const;
@@ -33,6 +34,7 @@ public:
optional<gl::AttributeLocation> 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<std::pair<const std::string, gl::AttributeLocation>> attributes;
std::vector<std::pair<const std::string, gl::UniformLocation>> uniforms;
+ std::vector<std::pair<const std::string, gl::UniformLocation>> 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 <mbgl/programs/program.hpp>
#include <mbgl/programs/attributes.hpp>
#include <mbgl/programs/uniforms.hpp>
+#include <mbgl/programs/textures.hpp>
#include <mbgl/shaders/extrusion_texture.hpp>
#include <mbgl/style/properties.hpp>
#include <mbgl/util/geometry.hpp>
@@ -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, 2>{{ float(pixelX >> 16), float(pixelY >> 16) }} ),
uniforms::u_pixel_coord_lower::Value( std::array<float, 2>{{ 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 <mbgl/programs/attributes.hpp>
#include <mbgl/programs/extrusion_texture_program.hpp>
#include <mbgl/programs/uniforms.hpp>
+#include <mbgl/programs/textures.hpp>
#include <mbgl/shaders/fill_extrusion.hpp>
#include <mbgl/shaders/fill_extrusion_pattern.hpp>
#include <mbgl/util/geometry.hpp>
@@ -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, 2> {{ float(pixelX >> 16), float(pixelY >> 16) }}),
uniforms::u_pixel_coord_lower::Value( std::array<float, 2> {{ 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 <mbgl/programs/program.hpp>
#include <mbgl/programs/attributes.hpp>
#include <mbgl/programs/uniforms.hpp>
+#include <mbgl/programs/textures.hpp>
#include <mbgl/shaders/fill.hpp>
#include <mbgl/shaders/fill_pattern.hpp>
#include <mbgl/shaders/fill_outline.hpp>
@@ -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 <mbgl/programs/program.hpp>
#include <mbgl/programs/attributes.hpp>
#include <mbgl/programs/uniforms.hpp>
+#include <mbgl/programs/textures.hpp>
#include <mbgl/shaders/heatmap_texture.hpp>
#include <mbgl/style/properties.hpp>
#include <mbgl/util/geometry.hpp>
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 <mbgl/programs/program.hpp>
#include <mbgl/programs/attributes.hpp>
#include <mbgl/programs/uniforms.hpp>
+#include <mbgl/programs/textures.hpp>
#include <mbgl/shaders/hillshade_prepare.hpp>
#include <mbgl/util/geometry.hpp>
@@ -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 <mbgl/programs/attributes.hpp>
#include <mbgl/programs/hillshade_prepare_program.hpp>
#include <mbgl/programs/uniforms.hpp>
+#include <mbgl/programs/textures.hpp>
#include <mbgl/shaders/hillshade.hpp>
#include <mbgl/util/geometry.hpp>
#include <mbgl/style/layers/hillshade_layer_properties.hpp>
@@ -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 <mbgl/programs/program.hpp>
#include <mbgl/programs/attributes.hpp>
#include <mbgl/programs/uniforms.hpp>
+#include <mbgl/programs/textures.hpp>
#include <mbgl/shaders/line.hpp>
#include <mbgl/shaders/line_gradient.hpp>
#include <mbgl/shaders/line_pattern.hpp>
@@ -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<TextureList>;
- using ProgramType = gl::Program<Primitive, Attributes, AllUniforms, TextureBindings>;
+ using ProgramType = gl::Program<Primitive, Attributes, AllUniforms, TextureList>;
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 <mbgl/programs/program.hpp>
#include <mbgl/programs/attributes.hpp>
#include <mbgl/programs/uniforms.hpp>
+#include <mbgl/programs/textures.hpp>
#include <mbgl/shaders/raster.hpp>
#include <mbgl/util/geometry.hpp>
#include <mbgl/style/layers/raster_layer_properties.hpp>
@@ -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 <mbgl/programs/attributes.hpp>
#include <mbgl/programs/collision_box_program.hpp>
#include <mbgl/programs/uniforms.hpp>
+#include <mbgl/programs/textures.hpp>
#include <mbgl/programs/segment.hpp>
#include <mbgl/shaders/symbol_icon.hpp>
#include <mbgl/shaders/symbol_sdf.hpp>
@@ -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<TextureList>;
- using ProgramType = gl::Program<Primitive, Attributes, AllUniforms, TextureBindings>;
+ using ProgramType = gl::Program<Primitive, Attributes, AllUniforms, TextureList>;
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 <mbgl/gfx/texture.hpp>
+
+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);
diff --git a/src/mbgl/renderer/image_manager.cpp b/src/mbgl/renderer/image_manager.cpp
index d8f8cf615d..9c9f6c6e08 100644
--- a/src/mbgl/renderer/image_manager.cpp
+++ b/src/mbgl/renderer/image_manager.cpp
@@ -167,19 +167,19 @@ Size ImageManager::getPixelSize() const {
};
}
-void ImageManager::upload(gfx::Context& context, uint8_t unit) {
+void ImageManager::upload(gfx::Context& context) {
if (!atlasTexture) {
- atlasTexture = context.createTexture(atlasImage, unit);
+ atlasTexture = context.createTexture(atlasImage);
} else if (dirty) {
- context.updateTexture(*atlasTexture, atlasImage, unit);
+ context.updateTexture(*atlasTexture, atlasImage);
}
dirty = false;
}
-void ImageManager::bind(gfx::Context& context, uint8_t unit) {
- upload(context, unit);
- context.bindTexture(*atlasTexture, unit, gfx::TextureFilterType::Linear);
+gfx::TextureBinding ImageManager::textureBinding(gfx::Context& context) {
+ upload(context);
+ return { *atlasTexture->resource, gfx::TextureFilterType::Linear };
}
} // namespace mbgl
diff --git a/src/mbgl/renderer/image_manager.hpp b/src/mbgl/renderer/image_manager.hpp
index acc076965e..e56f30ac3f 100644
--- a/src/mbgl/renderer/image_manager.hpp
+++ b/src/mbgl/renderer/image_manager.hpp
@@ -65,8 +65,8 @@ private:
public:
optional<ImagePosition> getPattern(const std::string& name);
- void bind(gfx::Context&, uint8_t unit);
- void upload(gfx::Context&, uint8_t unit);
+ gfx::TextureBinding textureBinding(gfx::Context&);
+ void upload(gfx::Context&);
Size getPixelSize() const;
diff --git a/src/mbgl/renderer/layers/render_background_layer.cpp b/src/mbgl/renderer/layers/render_background_layer.cpp
index 61c8fa208e..ae89a08cac 100644
--- a/src/mbgl/renderer/layers/render_background_layer.cpp
+++ b/src/mbgl/renderer/layers/render_background_layer.cpp
@@ -50,7 +50,7 @@ void RenderBackgroundLayer::render(PaintParameters& parameters, RenderSource*) {
const Properties<>::PossiblyEvaluated properties;
const BackgroundProgram::Binders paintAttributeData(properties, 0);
- auto draw = [&](auto& program, auto&& uniformValues, auto&& textureBindings) {
+ auto draw = [&](auto& program, auto&& uniformValues, const auto& textureBindings) {
const auto allUniformValues = program.computeAllUniformValues(
std::move(uniformValues),
paintAttributeData,
@@ -76,7 +76,7 @@ void RenderBackgroundLayer::render(PaintParameters& parameters, RenderSource*) {
parameters.staticData.tileTriangleSegments,
allUniformValues,
allAttributeBindings,
- std::move(textureBindings),
+ textureBindings,
getID()
);
};
@@ -88,8 +88,6 @@ void RenderBackgroundLayer::render(PaintParameters& parameters, RenderSource*) {
if (!imagePosA || !imagePosB)
return;
- parameters.imageManager.bind(parameters.context, 0);
-
for (const auto& tileID : util::tileCover(parameters.state, parameters.state.getIntegerZoom())) {
draw(
parameters.programs.getBackgroundLayerPrograms().backgroundPattern,
@@ -103,7 +101,9 @@ void RenderBackgroundLayer::render(PaintParameters& parameters, RenderSource*) {
tileID,
parameters.state
),
- BackgroundPatternProgram::TextureBindings{}
+ BackgroundPatternProgram::TextureBindings{
+ textures::u_image::Value{ parameters.imageManager.textureBinding(parameters.context) },
+ }
);
}
} else {
diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp
index 5699bc5d4a..99bdc3a8c6 100644
--- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp
+++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp
@@ -140,7 +140,6 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource*
GeometryTile& geometryTile = static_cast<GeometryTile&>(tile.tile);
optional<ImagePosition> patternPosA = geometryTile.getPattern(fillPatternValue.from);
optional<ImagePosition> patternPosB = geometryTile.getPattern(fillPatternValue.to);
- parameters.context.bindTexture(*geometryTile.iconAtlasTexture, 0, gfx::TextureFilterType::Linear);
FillExtrusionBucket& bucket = *bucket_;
draw(
@@ -160,14 +159,14 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource*
),
patternPosA,
patternPosB,
- FillExtrusionPatternProgram::TextureBindings{}
+ FillExtrusionPatternProgram::TextureBindings{
+ textures::u_image::Value{ *geometryTile.iconAtlasTexture->resource, gfx::TextureFilterType::Linear },
+ }
);
}
}
} else if (parameters.pass == RenderPass::Translucent) {
- parameters.context.bindTexture(renderTexture->getTexture());
-
const auto& size = parameters.staticData.backendSize;
mat4 viewportMat;
@@ -180,8 +179,8 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource*
const auto allUniformValues = programInstance.computeAllUniformValues(
ExtrusionTextureProgram::UniformValues{
- uniforms::u_matrix::Value( viewportMat ), uniforms::u_world::Value( size ),
- uniforms::u_image::Value( 0 ),
+ uniforms::u_matrix::Value( viewportMat ),
+ uniforms::u_world::Value( size ),
uniforms::u_opacity::Value( evaluated.get<FillExtrusionOpacity>() )
},
paintAttributeData,
@@ -207,7 +206,9 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters, RenderSource*
parameters.staticData.extrusionTextureSegments,
allUniformValues,
allAttributeBindings,
- ExtrusionTextureProgram::TextureBindings{},
+ ExtrusionTextureProgram::TextureBindings{
+ textures::u_image::Value{ *renderTexture->getTexture().resource },
+ },
getID());
}
}
diff --git a/src/mbgl/renderer/layers/render_fill_layer.cpp b/src/mbgl/renderer/layers/render_fill_layer.cpp
index 798749711d..3e36561ffb 100644
--- a/src/mbgl/renderer/layers/render_fill_layer.cpp
+++ b/src/mbgl/renderer/layers/render_fill_layer.cpp
@@ -152,7 +152,6 @@ void RenderFillLayer::render(PaintParameters& parameters, RenderSource*) {
optional<ImagePosition> patternPosA = geometryTile.getPattern(fillPatternValue.from);
optional<ImagePosition> patternPosB = geometryTile.getPattern(fillPatternValue.to);
- parameters.context.bindTexture(*geometryTile.iconAtlasTexture, 0, gfx::TextureFilterType::Linear);
auto bucket_ = tile.tile.getBucket<FillBucket>(*baseImpl);
if (!bucket_) {
continue;
@@ -215,7 +214,9 @@ void RenderFillLayer::render(PaintParameters& parameters, RenderSource*) {
parameters.depthModeForSublayer(1, gfx::DepthMaskType::ReadWrite),
*bucket.triangleIndexBuffer,
bucket.triangleSegments,
- FillProgram::TextureBindings{});
+ FillPatternProgram::TextureBindings{
+ textures::u_image::Value{ *geometryTile.iconAtlasTexture->resource, gfx::TextureFilterType::Linear },
+ });
if (evaluated.get<FillAntialias>() && unevaluated.get<FillOutlineColor>().isUndefined()) {
draw(parameters.programs.getFillLayerPrograms().fillOutlinePattern,
@@ -223,7 +224,9 @@ void RenderFillLayer::render(PaintParameters& parameters, RenderSource*) {
parameters.depthModeForSublayer(2, gfx::DepthMaskType::ReadOnly),
*bucket.lineIndexBuffer,
bucket.lineSegments,
- FillOutlineProgram::TextureBindings{});
+ FillOutlinePatternProgram::TextureBindings{
+ textures::u_image::Value{ *geometryTile.iconAtlasTexture->resource, gfx::TextureFilterType::Linear },
+ });
}
}
}
diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.cpp b/src/mbgl/renderer/layers/render_heatmap_layer.cpp
index 9dd1ee6493..74b976658e 100644
--- a/src/mbgl/renderer/layers/render_heatmap_layer.cpp
+++ b/src/mbgl/renderer/layers/render_heatmap_layer.cpp
@@ -77,7 +77,7 @@ void RenderHeatmapLayer::render(PaintParameters& parameters, RenderSource*) {
}
if (!colorRampTexture) {
- colorRampTexture = parameters.context.createTexture(colorRamp, 1, gfx::TextureChannelDataType::UnsignedByte);
+ colorRampTexture = parameters.context.createTexture(colorRamp, gfx::TextureChannelDataType::UnsignedByte);
}
parameters.context.clear(Color{ 0.0f, 0.0f, 0.0f, 1.0f }, {}, {});
@@ -134,9 +134,6 @@ void RenderHeatmapLayer::render(PaintParameters& parameters, RenderSource*) {
}
} else if (parameters.pass == RenderPass::Translucent) {
- parameters.context.bindTexture(renderTexture->getTexture(), 0, gfx::TextureFilterType::Linear);
- parameters.context.bindTexture(*colorRampTexture, 1, gfx::TextureFilterType::Linear);
-
const auto& size = parameters.staticData.backendSize;
mat4 viewportMat;
@@ -150,8 +147,6 @@ void RenderHeatmapLayer::render(PaintParameters& parameters, RenderSource*) {
const auto allUniformValues = programInstance.computeAllUniformValues(
HeatmapTextureProgram::UniformValues{
uniforms::u_matrix::Value( viewportMat ), uniforms::u_world::Value( size ),
- uniforms::u_image::Value( 0 ),
- uniforms::u_color_ramp::Value( 1 ),
uniforms::u_opacity::Value( evaluated.get<HeatmapOpacity>() )
},
paintAttributeData,
@@ -177,7 +172,10 @@ void RenderHeatmapLayer::render(PaintParameters& parameters, RenderSource*) {
parameters.staticData.extrusionTextureSegments,
allUniformValues,
allAttributeBindings,
- HeatmapProgram::TextureBindings{},
+ HeatmapTextureProgram::TextureBindings{
+ textures::u_image::Value{ *renderTexture->getTexture().resource, gfx::TextureFilterType::Linear },
+ textures::u_color_ramp::Value{ *colorRampTexture->resource, gfx::TextureFilterType::Linear },
+ },
getID()
);
}
diff --git a/src/mbgl/renderer/layers/render_hillshade_layer.cpp b/src/mbgl/renderer/layers/render_hillshade_layer.cpp
index 70ff2379d4..b428e357e7 100644
--- a/src/mbgl/renderer/layers/render_hillshade_layer.cpp
+++ b/src/mbgl/renderer/layers/render_hillshade_layer.cpp
@@ -67,7 +67,8 @@ void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src
const auto& vertexBuffer,
const auto& indexBuffer,
const auto& segments,
- const UnwrappedTileID& id) {
+ const UnwrappedTileID& id,
+ const auto& textureBindings) {
auto& programInstance = parameters.programs.getHillshadeLayerPrograms().hillshade;
const HillshadeProgram::Binders paintAttributeData{ evaluated, 0 };
@@ -75,7 +76,6 @@ void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src
const auto allUniformValues = programInstance.computeAllUniformValues(
HillshadeProgram::UniformValues {
uniforms::u_matrix::Value( matrix ),
- uniforms::u_image::Value( 0 ),
uniforms::u_highlight::Value( evaluated.get<HillshadeHighlightColor>() ),
uniforms::u_shadow::Value( evaluated.get<HillshadeShadowColor>() ),
uniforms::u_accent::Value( evaluated.get<HillshadeAccentColor>() ),
@@ -105,7 +105,7 @@ void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src
segments,
allUniformValues,
allAttributeBindings,
- HillshadeProgram::TextureBindings{},
+ textureBindings,
getID()
);
};
@@ -126,12 +126,12 @@ void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src
}
if (!bucket.isPrepared() && parameters.pass == RenderPass::Pass3D) {
+ assert(bucket.dem);
const uint16_t stride = bucket.getDEMData().stride;
const uint16_t tilesize = bucket.getDEMData().dim;
OffscreenTexture view(parameters.context, { tilesize, tilesize });
view.bind();
-
- parameters.context.bindTexture(*bucket.dem, 0, gfx::TextureFilterType::Nearest, gfx::TextureMipMapType::No, gfx::TextureWrapType::Clamp, gfx::TextureWrapType::Clamp);
+
const Properties<>::PossiblyEvaluated properties;
const HillshadePrepareProgram::Binders paintAttributeData{ properties, 0 };
@@ -143,7 +143,6 @@ void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src
uniforms::u_dimension::Value( {{stride, stride}} ),
uniforms::u_zoom::Value( float(tile.id.canonical.z) ),
uniforms::u_maxzoom::Value( float(maxzoom) ),
- uniforms::u_image::Value( 0 )
},
paintAttributeData,
properties,
@@ -168,14 +167,15 @@ void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src
parameters.staticData.rasterSegments,
allUniformValues,
allAttributeBindings,
- HillshadePrepareProgram::TextureBindings{},
+ HillshadePrepareProgram::TextureBindings{
+ textures::u_image::Value{ *bucket.dem->resource },
+ },
getID()
);
bucket.texture = std::move(view.getTexture());
bucket.setPrepared(true);
} else if (parameters.pass == RenderPass::Translucent) {
assert(bucket.texture);
- parameters.context.bindTexture(*bucket.texture, 0, gfx::TextureFilterType::Linear, gfx::TextureMipMapType::No, gfx::TextureWrapType::Clamp, gfx::TextureWrapType::Clamp);
if (bucket.vertexBuffer && bucket.indexBuffer && !bucket.segments.empty()) {
// Draw only the parts of the tile that aren't drawn by another tile in the layer.
@@ -183,14 +183,20 @@ void RenderHillshadeLayer::render(PaintParameters& parameters, RenderSource* src
*bucket.vertexBuffer,
*bucket.indexBuffer,
bucket.segments,
- tile.id);
+ tile.id,
+ HillshadeProgram::TextureBindings{
+ textures::u_image::Value{ *bucket.texture->resource, gfx::TextureFilterType::Linear },
+ });
} else {
// Draw the full tile.
draw(parameters.matrixForTile(tile.id, true),
parameters.staticData.rasterVertexBuffer,
parameters.staticData.quadTriangleIndexBuffer,
parameters.staticData.rasterSegments,
- tile.id);
+ tile.id,
+ HillshadeProgram::TextureBindings{
+ textures::u_image::Value{ *bucket.texture->resource, gfx::TextureFilterType::Linear },
+ });
}
}
diff --git a/src/mbgl/renderer/layers/render_line_layer.cpp b/src/mbgl/renderer/layers/render_line_layer.cpp
index 9eb659f79f..f3947685fe 100644
--- a/src/mbgl/renderer/layers/render_line_layer.cpp
+++ b/src/mbgl/renderer/layers/render_line_layer.cpp
@@ -109,8 +109,6 @@ void RenderLineLayer::render(PaintParameters& parameters, RenderSource*) {
LinePatternPos posA = parameters.lineAtlas.getDashPosition(evaluated.get<LineDasharray>().from, cap);
LinePatternPos posB = parameters.lineAtlas.getDashPosition(evaluated.get<LineDasharray>().to, cap);
- parameters.lineAtlas.bind(parameters.context, 0);
-
draw(parameters.programs.getLineLayerPrograms().lineSDF,
LineSDFProgram::uniformValues(
evaluated,
@@ -124,13 +122,14 @@ void RenderLineLayer::render(PaintParameters& parameters, RenderSource*) {
parameters.lineAtlas.getSize().width),
{},
{},
- LineSDFProgram::TextureBindings{});
+ LineSDFProgram::TextureBindings{
+ parameters.lineAtlas.textureBinding(parameters.context),
+ });
} else if (!unevaluated.get<LinePattern>().isUndefined()) {
const auto linePatternValue = evaluated.get<LinePattern>().constantOr(Faded<std::basic_string<char>>{ "", ""});
assert(dynamic_cast<GeometryTile*>(&tile.tile));
- GeometryTile& geometryTile = static_cast<GeometryTile&>(tile.tile);
- parameters.context.bindTexture(*geometryTile.iconAtlasTexture, 0, gfx::TextureFilterType::Linear);
+ GeometryTile& geometryTile = static_cast<GeometryTile&>(tile.tile);
const Size texsize = geometryTile.iconAtlasTexture->size;
optional<ImagePosition> posA = geometryTile.getPattern(linePatternValue.from);
@@ -147,12 +146,13 @@ void RenderLineLayer::render(PaintParameters& parameters, RenderSource*) {
parameters.pixelRatio),
*posA,
*posB,
- LinePatternProgram::TextureBindings{});
+ LinePatternProgram::TextureBindings{
+ textures::u_image::Value{ *geometryTile.iconAtlasTexture->resource, gfx::TextureFilterType::Linear },
+ });
} else if (!unevaluated.get<LineGradient>().getValue().isUndefined()) {
if (!colorRampTexture) {
colorRampTexture = parameters.context.createTexture(colorRamp);
}
- parameters.context.bindTexture(*colorRampTexture, 0, gfx::TextureFilterType::Linear);
draw(parameters.programs.getLineLayerPrograms().lineGradient,
LineGradientProgram::uniformValues(
@@ -162,7 +162,9 @@ void RenderLineLayer::render(PaintParameters& parameters, RenderSource*) {
parameters.pixelsToGLUnits),
{},
{},
- LineGradientProgram::TextureBindings{});
+ LineGradientProgram::TextureBindings{
+ textures::u_image::Value{ *colorRampTexture->resource, gfx::TextureFilterType::Linear },
+ });
} else {
draw(parameters.programs.getLineLayerPrograms().line,
LineProgram::uniformValues(
diff --git a/src/mbgl/renderer/layers/render_raster_layer.cpp b/src/mbgl/renderer/layers/render_raster_layer.cpp
index a9fdcc0320..f68acd4061 100644
--- a/src/mbgl/renderer/layers/render_raster_layer.cpp
+++ b/src/mbgl/renderer/layers/render_raster_layer.cpp
@@ -77,14 +77,13 @@ void RenderRasterLayer::render(PaintParameters& parameters, RenderSource* source
auto draw = [&] (const mat4& matrix,
const auto& vertexBuffer,
const auto& indexBuffer,
- const auto& segments) {
+ const auto& segments,
+ const auto& textureBindings) {
auto& programInstance = parameters.programs.getRasterLayerPrograms().raster;
const auto allUniformValues = programInstance.computeAllUniformValues(
RasterProgram::UniformValues {
uniforms::u_matrix::Value( matrix ),
- uniforms::u_image0::Value( 0 ),
- uniforms::u_image1::Value( 1 ),
uniforms::u_opacity::Value( evaluated.get<RasterOpacity>() ),
uniforms::u_fade_t::Value( 1 ),
uniforms::u_brightness_low::Value( evaluated.get<RasterBrightnessMin>() ),
@@ -119,7 +118,7 @@ void RenderRasterLayer::render(PaintParameters& parameters, RenderSource* source
segments,
allUniformValues,
allAttributeBindings,
- RasterProgram::TextureBindings{},
+ textureBindings,
getID()
);
};
@@ -129,16 +128,17 @@ void RenderRasterLayer::render(PaintParameters& parameters, RenderSource* source
if (RenderImageSource* imageSource = source->as<RenderImageSource>()) {
if (imageSource->isEnabled() && imageSource->isLoaded() && !imageSource->bucket->needsUpload()) {
RasterBucket& bucket = *imageSource->bucket;
-
assert(bucket.texture);
- parameters.context.bindTexture(*bucket.texture, 0, filter);
- parameters.context.bindTexture(*bucket.texture, 1, filter);
for (auto matrix_ : imageSource->matrices) {
draw(matrix_,
*bucket.vertexBuffer,
*bucket.indexBuffer,
- bucket.segments);
+ bucket.segments,
+ RasterProgram::TextureBindings{
+ textures::u_image0::Value{ *bucket.texture->resource, filter },
+ textures::u_image1::Value{ *bucket.texture->resource, filter },
+ });
}
}
} else {
@@ -153,21 +153,26 @@ void RenderRasterLayer::render(PaintParameters& parameters, RenderSource* source
continue;
assert(bucket.texture);
- parameters.context.bindTexture(*bucket.texture, 0, filter);
- parameters.context.bindTexture(*bucket.texture, 1, filter);
-
if (bucket.vertexBuffer && bucket.indexBuffer && !bucket.segments.empty()) {
// Draw only the parts of the tile that aren't drawn by another tile in the layer.
draw(parameters.matrixForTile(tile.id, true),
*bucket.vertexBuffer,
*bucket.indexBuffer,
- bucket.segments);
+ bucket.segments,
+ RasterProgram::TextureBindings{
+ textures::u_image0::Value{ *bucket.texture->resource, filter },
+ textures::u_image1::Value{ *bucket.texture->resource, filter },
+ });
} else {
// Draw the full tile.
draw(parameters.matrixForTile(tile.id, true),
parameters.staticData.rasterVertexBuffer,
parameters.staticData.quadTriangleIndexBuffer,
- parameters.staticData.rasterSegments);
+ parameters.staticData.rasterSegments,
+ RasterProgram::TextureBindings{
+ textures::u_image0::Value{ *bucket.texture->resource, filter },
+ textures::u_image1::Value{ *bucket.texture->resource, filter },
+ });
}
}
}
diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp
index a5ac6ceeea..e523a869b2 100644
--- a/src/mbgl/renderer/layers/render_symbol_layer.cpp
+++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp
@@ -158,9 +158,12 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
const bool iconScaled = layout.get<IconSize>().constantOr(1.0) != 1.0 || bucket.iconsNeedLinear;
const bool iconTransformed = values.rotationAlignment == AlignmentType::Map || parameters.state.getPitch() != 0;
- parameters.context.bindTexture(*geometryTile.iconAtlasTexture, 0,
- bucket.sdfIcons || parameters.state.isChanging() || iconScaled || iconTransformed
- ? gfx::TextureFilterType::Linear : gfx::TextureFilterType::Nearest);
+ const gfx::TextureBinding textureBinding{ *geometryTile.iconAtlasTexture->resource,
+ bucket.sdfIcons ||
+ parameters.state.isChanging() ||
+ iconScaled || iconTransformed
+ ? gfx::TextureFilterType::Linear
+ : gfx::TextureFilterType::Nearest };
const Size texsize = geometryTile.iconAtlasTexture->size;
@@ -173,7 +176,9 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
values,
bucketPaintProperties.iconBinders,
paintPropertyValues,
- SymbolSDFIconProgram::TextureBindings{});
+ SymbolSDFIconProgram::TextureBindings{
+ textureBinding,
+ });
}
if (values.hasFill) {
@@ -184,7 +189,9 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
values,
bucketPaintProperties.iconBinders,
paintPropertyValues,
- SymbolSDFIconProgram::TextureBindings{});
+ SymbolSDFIconProgram::TextureBindings{
+ textureBinding,
+ });
}
} else {
draw(parameters.programs.getSymbolLayerPrograms().symbolIcon,
@@ -194,12 +201,15 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
values,
bucketPaintProperties.iconBinders,
paintPropertyValues,
- SymbolIconProgram::TextureBindings{});
+ SymbolIconProgram::TextureBindings{
+ textureBinding,
+ });
}
}
if (bucket.hasTextData()) {
- parameters.context.bindTexture(*geometryTile.glyphAtlasTexture, 0, gfx::TextureFilterType::Linear);
+ const gfx::TextureBinding textureBinding{ *geometryTile.glyphAtlasTexture->resource,
+ gfx::TextureFilterType::Linear };
auto values = textPropertyValues(evaluated_, layout);
const auto& paintPropertyValues = textPaintProperties(evaluated_);
@@ -229,7 +239,9 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
values,
bucketPaintProperties.textBinders,
paintPropertyValues,
- SymbolSDFTextProgram::TextureBindings{});
+ SymbolSDFTextProgram::TextureBindings{
+ textureBinding,
+ });
}
if (values.hasFill) {
@@ -240,7 +252,9 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
values,
bucketPaintProperties.textBinders,
paintPropertyValues,
- SymbolSDFTextProgram::TextureBindings{});
+ SymbolSDFTextProgram::TextureBindings{
+ textureBinding,
+ });
}
}
diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp
index d66ba1767e..e3346a39a5 100644
--- a/src/mbgl/renderer/renderer_impl.cpp
+++ b/src/mbgl/renderer/renderer_impl.cpp
@@ -375,8 +375,8 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
{
MBGL_DEBUG_GROUP(parameters.context, "upload");
- parameters.imageManager.upload(parameters.context, 0);
- parameters.lineAtlas.upload(parameters.context, 0);
+ parameters.imageManager.upload(parameters.context);
+ parameters.lineAtlas.upload(parameters.context);
// Update all clipping IDs + upload buckets.
for (const auto& entry : renderSources) {
diff --git a/src/mbgl/shaders/shaders.cpp b/src/mbgl/shaders/shaders.cpp
index c4f49a1a8c..578c2db624 100644
--- a/src/mbgl/shaders/shaders.cpp
+++ b/src/mbgl/shaders/shaders.cpp
@@ -21,7 +21,7 @@ std::string programIdentifier(const std::string& vertexSource, const std::string
result.reserve((sizeof(size_t) * 2) * 2 + 2); // 2 size_t hex values + "v2"
result += util::toHex(std::hash<std::string>()(vertexSource));
result += util::toHex(std::hash<std::string>()(fragmentSource));
- result += "v2";
+ result += "v3";
return result;
}
diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp
index a538e6e97c..c8498976b8 100644
--- a/src/mbgl/tile/geometry_tile.cpp
+++ b/src/mbgl/tile/geometry_tile.cpp
@@ -185,12 +185,12 @@ void GeometryTile::upload(gfx::Context& context) {
}
if (glyphAtlasImage) {
- glyphAtlasTexture = context.createTexture(*glyphAtlasImage, 0);
+ glyphAtlasTexture = context.createTexture(*glyphAtlasImage);
glyphAtlasImage = {};
}
if (iconAtlas.image.valid()) {
- iconAtlasTexture = context.createTexture(iconAtlas.image, 0);
+ iconAtlasTexture = context.createTexture(iconAtlas.image);
iconAtlas.image = {};
}
}
diff --git a/src/mbgl/util/offscreen_texture.cpp b/src/mbgl/util/offscreen_texture.cpp
index 6897732dc4..2a58ff86a3 100644
--- a/src/mbgl/util/offscreen_texture.cpp
+++ b/src/mbgl/util/offscreen_texture.cpp
@@ -25,7 +25,7 @@ public:
void bind() {
if (!framebuffer) {
- texture = context.createTexture(size, gfx::TexturePixelType::RGBA, 0, type);
+ texture = context.createTexture(size, gfx::TexturePixelType::RGBA, type);
if (depth) {
framebuffer = context.createFramebuffer(*texture, *depth);
} else {
diff --git a/test/programs/binary_program.test.cpp b/test/programs/binary_program.test.cpp
index a5cf7b6e39..c70539ea81 100644
--- a/test/programs/binary_program.test.cpp
+++ b/test/programs/binary_program.test.cpp
@@ -9,7 +9,8 @@ TEST(BinaryProgram, ObtainValues) {
"binary code",
"identifier",
{ { "a_pos", 1 }, { "a_data", 4 } },
- { { "u_world", 1 }, { "u_ratio", 3 } } };
+ { { "u_world", 1 }, { "u_ratio", 3 } },
+ { { "u_image", 0 } } };
EXPECT_EQ(42u, binaryProgram.format());
EXPECT_EQ("binary code", binaryProgram.code());
@@ -20,6 +21,8 @@ TEST(BinaryProgram, ObtainValues) {
EXPECT_EQ(1, binaryProgram.uniformLocation("u_world"));
EXPECT_EQ(3, binaryProgram.uniformLocation("u_ratio"));
EXPECT_EQ(-1, binaryProgram.uniformLocation("a_data"));
+ EXPECT_EQ(0, binaryProgram.textureLocation("u_image"));
+ EXPECT_EQ(-1, binaryProgram.textureLocation("u_image2"));
auto serialized = binaryProgram.serialize();
@@ -34,6 +37,8 @@ TEST(BinaryProgram, ObtainValues) {
EXPECT_EQ(1, binaryProgram2.uniformLocation("u_world"));
EXPECT_EQ(3, binaryProgram2.uniformLocation("u_ratio"));
EXPECT_EQ(-1, binaryProgram2.uniformLocation("a_data"));
+ EXPECT_EQ(0, binaryProgram.textureLocation("u_image"));
+ EXPECT_EQ(-1, binaryProgram.textureLocation("u_image2"));
EXPECT_THROW(BinaryProgram(""), std::runtime_error);
}
diff --git a/test/util/offscreen_texture.test.cpp b/test/util/offscreen_texture.test.cpp
index d0a78ec968..986ec39bc1 100644
--- a/test/util/offscreen_texture.test.cpp
+++ b/test/util/offscreen_texture.test.cpp
@@ -2,6 +2,7 @@
#include <mbgl/platform/gl_functions.hpp>
#include <mbgl/gl/context.hpp>
+#include <mbgl/gl/texture.hpp>
#include <mbgl/gl/defines.hpp>
#include <mbgl/gl/headless_backend.hpp>
#include <mbgl/renderer/backend_scope.hpp>
@@ -158,7 +159,7 @@ void main() {
test::checkImage("test/fixtures/offscreen_texture/render-to-fbo", image, 0, 0);
// Now, composite the Framebuffer texture we've rendered to onto the main FBO.
- context.bindTexture(texture.getTexture(), 0, gfx::TextureFilterType::Linear);
+ gl::bindTexture(context, 0, { *texture.getTexture().resource, gfx::TextureFilterType::Linear });
MBGL_CHECK_ERROR(glUseProgram(compositeShader.program));
MBGL_CHECK_ERROR(glUniform1i(u_texture, 0));
MBGL_CHECK_ERROR(glBindBuffer(GL_ARRAY_BUFFER, viewportBuffer.buffer));