[core] add texture bindings to draw call instead of Context member fn
This commit is contained in:
@@ -15,4 +15,5 @@ message binary_program {
|
||||
repeated binding attribute = 3;
|
||||
repeated binding uniform = 4;
|
||||
optional string identifier = 5;
|
||||
repeated binding texture = 6;
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
54
src/mbgl/gl/texture.cpp
Normal file
54
src/mbgl/gl/texture.cpp
Normal file
@@ -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
|
||||
52
src/mbgl/gl/texture.hpp
Normal file
52
src/mbgl/gl/texture.hpp
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -67,6 +67,11 @@ void bindUniform<uint32_t>(UniformLocation location, const uint32_t& t) {
|
||||
bindUniform(location, int32_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 }});
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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()) ),
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 ),
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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) }} )
|
||||
};
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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() ),
|
||||
|
||||
@@ -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;
|
||||
|
||||
15
src/mbgl/programs/textures.hpp
Normal file
15
src/mbgl/programs/textures.hpp
Normal file
@@ -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
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 },
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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 },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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 },
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 = {};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user