diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core-files.json | 3 | ||||
-rw-r--r-- | src/mbgl/geometry/line_atlas.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/geometry/line_atlas.hpp | 8 | ||||
-rw-r--r-- | src/mbgl/gfx/context.hpp | 43 | ||||
-rw-r--r-- | src/mbgl/gfx/texture.hpp | 33 | ||||
-rw-r--r-- | src/mbgl/gl/context.cpp | 69 | ||||
-rw-r--r-- | src/mbgl/gl/context.hpp | 55 | ||||
-rw-r--r-- | src/mbgl/gl/texture.hpp | 33 | ||||
-rw-r--r-- | src/mbgl/gl/texture_resource.hpp | 18 | ||||
-rw-r--r-- | src/mbgl/gl/types.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/gl/value.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/buckets/hillshade_bucket.hpp | 6 | ||||
-rw-r--r-- | src/mbgl/renderer/buckets/raster_bucket.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/renderer/image_manager.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/renderer/image_manager.hpp | 8 | ||||
-rw-r--r-- | src/mbgl/renderer/layers/render_heatmap_layer.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/renderer/layers/render_line_layer.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/tile/geometry_tile.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/util/offscreen_texture.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/util/offscreen_texture.hpp | 7 |
20 files changed, 181 insertions, 136 deletions
diff --git a/src/core-files.json b/src/core-files.json index 4521457bb1..40a7aab20d 100644 --- a/src/core-files.json +++ b/src/core-files.json @@ -508,6 +508,7 @@ "mbgl/gfx/index_vector.hpp": "src/mbgl/gfx/index_vector.hpp", "mbgl/gfx/primitives.hpp": "src/mbgl/gfx/primitives.hpp", "mbgl/gfx/stencil_mode.hpp": "src/mbgl/gfx/stencil_mode.hpp", + "mbgl/gfx/texture.hpp": "src/mbgl/gfx/texture.hpp", "mbgl/gfx/types.hpp": "src/mbgl/gfx/types.hpp", "mbgl/gfx/uniform.hpp": "src/mbgl/gfx/uniform.hpp", "mbgl/gfx/vertex_buffer.hpp": "src/mbgl/gfx/vertex_buffer.hpp", @@ -527,7 +528,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", "mbgl/gl/value.hpp": "src/mbgl/gl/value.hpp", diff --git a/src/mbgl/geometry/line_atlas.cpp b/src/mbgl/geometry/line_atlas.cpp index e0114befcb..0e82b4ffc7 100644 --- a/src/mbgl/geometry/line_atlas.cpp +++ b/src/mbgl/geometry/line_atlas.cpp @@ -126,7 +126,7 @@ Size LineAtlas::getSize() const { return image.size; } -void LineAtlas::upload(gl::Context& context, gl::TextureUnit unit) { +void LineAtlas::upload(gl::Context& context, uint8_t unit) { if (!texture) { texture = context.createTexture(image, unit); } else if (dirty) { @@ -136,7 +136,7 @@ void LineAtlas::upload(gl::Context& context, gl::TextureUnit unit) { dirty = false; } -void LineAtlas::bind(gl::Context& context, gl::TextureUnit unit) { +void LineAtlas::bind(gl::Context& context, uint8_t unit) { upload(context, unit); context.bindTexture(*texture, unit, gfx::TextureFilterType::Linear, gfx::TextureMipMapType::No, gfx::TextureWrapType::Repeat, gfx::TextureWrapType::Clamp); diff --git a/src/mbgl/geometry/line_atlas.hpp b/src/mbgl/geometry/line_atlas.hpp index b1e7a670c1..f262232872 100644 --- a/src/mbgl/geometry/line_atlas.hpp +++ b/src/mbgl/geometry/line_atlas.hpp @@ -1,6 +1,6 @@ #pragma once -#include <mbgl/gl/texture.hpp> +#include <mbgl/gfx/texture.hpp> #include <mbgl/gl/object.hpp> #include <mbgl/util/image.hpp> #include <mbgl/util/optional.hpp> @@ -33,11 +33,11 @@ public: ~LineAtlas(); // Binds the atlas texture to the GPU, and uploads data if it is out of date. - void bind(gl::Context&, gl::TextureUnit unit); + void bind(gl::Context&, uint8_t unit); // 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(gl::Context&, gl::TextureUnit unit); + void upload(gl::Context&, uint8_t unit); LinePatternPos getDashPosition(const std::vector<float>&, LinePatternCap); LinePatternPos addDash(const std::vector<float>& dasharray, LinePatternCap); @@ -47,7 +47,7 @@ public: private: const AlphaImage image; bool dirty; - mbgl::optional<gl::Texture> texture; + mbgl::optional<gfx::Texture> texture; uint32_t nextRow = 0; std::unordered_map<size_t, LinePatternPos> positions; }; diff --git a/src/mbgl/gfx/context.hpp b/src/mbgl/gfx/context.hpp index b57cfcb65c..05a87eeeac 100644 --- a/src/mbgl/gfx/context.hpp +++ b/src/mbgl/gfx/context.hpp @@ -4,6 +4,7 @@ #include <mbgl/gfx/vertex_buffer.hpp> #include <mbgl/gfx/index_vector.hpp> #include <mbgl/gfx/index_buffer.hpp> +#include <mbgl/gfx/texture.hpp> #include <mbgl/gfx/types.hpp> namespace mbgl { @@ -56,6 +57,48 @@ protected: createIndexBufferResource(const void* data, std::size_t size, const BufferUsageType) = 0; virtual void updateIndexBufferResource(const IndexBufferResource&, const void* data, std::size_t size) = 0; + +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) }; + } + + // 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) }; + } + + 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); + 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 void updateTextureResource(const TextureResource&, Size, const void* data, + TexturePixelType, uint8_t unit, TextureChannelDataType) = 0; }; } // namespace gfx diff --git a/src/mbgl/gfx/texture.hpp b/src/mbgl/gfx/texture.hpp new file mode 100644 index 0000000000..ca5ab5d5d5 --- /dev/null +++ b/src/mbgl/gfx/texture.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include <mbgl/gfx/types.hpp> +#include <mbgl/util/size.hpp> + +#include <memory> + +namespace mbgl { +namespace gfx { + +class TextureResource { +protected: + TextureResource() = default; +public: + virtual ~TextureResource() = default; +}; + +class Texture { +public: + Texture(Size size_, std::unique_ptr<const 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; +}; + +} // namespace gfx +} // namespace mbgl diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index c8236e0b0a..2758e236e4 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -2,6 +2,7 @@ #include <mbgl/gl/enum.hpp> #include <mbgl/gl/vertex_buffer_resource.hpp> #include <mbgl/gl/index_buffer_resource.hpp> +#include <mbgl/gl/texture_resource.hpp> #include <mbgl/gl/debugging_extension.hpp> #include <mbgl/gl/vertex_array_extension.hpp> #include <mbgl/gl/program_binary_extension.hpp> @@ -266,7 +267,7 @@ void Context::updateIndexBufferResource(const gfx::IndexBufferResource& resource } -UniqueTexture Context::createTexture() { +UniqueTexture Context::createUniqueTexture() { if (pooledTextures.empty()) { pooledTextures.resize(TextureMax); MBGL_CHECK_ERROR(glGenTextures(TextureMax, pooledTextures.data())); @@ -468,83 +469,91 @@ Framebuffer Context::createFramebuffer(const Renderbuffer<RenderbufferType::RGBA } Framebuffer -Context::createFramebuffer(const Texture& color, +Context::createFramebuffer(const gfx::Texture& color, const Renderbuffer<RenderbufferType::DepthStencil>& depthStencil) { if (color.size != depthStencil.size) { throw std::runtime_error("Renderbuffer size mismatch"); } auto fbo = createFramebuffer(); bindFramebuffer = fbo; - MBGL_CHECK_ERROR(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, - color.texture, 0)); + MBGL_CHECK_ERROR(glFramebufferTexture2D( + GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, + reinterpret_cast<const gl::TextureResource&>(*color.resource).texture, 0)); bindDepthStencilRenderbuffer(depthStencil); checkFramebuffer(); return { color.size, std::move(fbo) }; } -Framebuffer Context::createFramebuffer(const Texture& color) { +Framebuffer Context::createFramebuffer(const gfx::Texture& color) { auto fbo = createFramebuffer(); bindFramebuffer = fbo; - MBGL_CHECK_ERROR(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, - color.texture, 0)); + MBGL_CHECK_ERROR(glFramebufferTexture2D( + GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, + reinterpret_cast<const gl::TextureResource&>(*color.resource).texture, 0)); checkFramebuffer(); return { color.size, std::move(fbo) }; } Framebuffer -Context::createFramebuffer(const Texture& color, +Context::createFramebuffer(const gfx::Texture& color, const Renderbuffer<RenderbufferType::DepthComponent>& depthTarget) { if (color.size != depthTarget.size) { throw std::runtime_error("Renderbuffer size mismatch"); } auto fbo = createFramebuffer(); bindFramebuffer = fbo; - MBGL_CHECK_ERROR(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color.texture, 0)); - MBGL_CHECK_ERROR(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthTarget.renderbuffer)); + MBGL_CHECK_ERROR(glFramebufferTexture2D( + GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, + reinterpret_cast<const gl::TextureResource&>(*color.resource).texture, 0)); + MBGL_CHECK_ERROR(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, + depthTarget.renderbuffer)); checkFramebuffer(); return { depthTarget.size, std::move(fbo) }; } -UniqueTexture Context::createTexture(const Size size, - const void* data, - gfx::TexturePixelType format, - TextureUnit unit, - gfx::TextureChannelDataType type) { - auto obj = createTexture(); +std::unique_ptr<const 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)); pixelStoreUnpack = { 1 }; - updateTexture(obj, size, data, format, unit, type); + updateTextureResource(*resource, size, data, format, unit, 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)); MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); - return obj; + return resource; } -void Context::updateTexture(TextureID id, - const Size size, - const void* data, - gfx::TexturePixelType format, - TextureUnit unit, - gfx::TextureChannelDataType type) { +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] = id; + texture[unit] = 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(Texture& obj, - TextureUnit unit, +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] = obj.texture; + texture[unit] = id; if (filter != obj.filter || mipmap != obj.mipmap) { MBGL_CHECK_ERROR(glTexParameteri( @@ -571,11 +580,11 @@ void Context::bindTexture(Texture& obj, wrapY == gfx::TextureWrapType::Clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT)); obj.wrapY = wrapY; } - } else if (texture[unit] != obj.texture) { + } else if (texture[unit] != id) { // We are checking first to avoid setting the active texture without a subsequent // texture bind. activeTextureUnit = unit; - texture[unit] = obj.texture; + texture[unit] = id; } } diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index 8b7b9346b3..1200e3b49a 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -5,7 +5,6 @@ #include <mbgl/gl/object.hpp> #include <mbgl/gl/state.hpp> #include <mbgl/gl/value.hpp> -#include <mbgl/gl/texture.hpp> #include <mbgl/gl/renderbuffer.hpp> #include <mbgl/gl/framebuffer.hpp> #include <mbgl/gl/vertex_array.hpp> @@ -52,7 +51,7 @@ public: UniqueProgram createProgram(BinaryProgramFormat binaryFormat, const std::string& binaryProgram); void verifyProgramLinkage(ProgramID); void linkProgram(ProgramID); - UniqueTexture createTexture(); + UniqueTexture createUniqueTexture(); VertexArray createVertexArray(); #if MBGL_HAS_BINARY_PROGRAMS @@ -74,10 +73,10 @@ public: Framebuffer createFramebuffer(const Renderbuffer<RenderbufferType::RGBA>&, const Renderbuffer<RenderbufferType::DepthStencil>&); Framebuffer createFramebuffer(const Renderbuffer<RenderbufferType::RGBA>&); - Framebuffer createFramebuffer(const Texture&, + Framebuffer createFramebuffer(const gfx::Texture&, const Renderbuffer<RenderbufferType::DepthStencil>&); - Framebuffer createFramebuffer(const Texture&); - Framebuffer createFramebuffer(const Texture&, + Framebuffer createFramebuffer(const gfx::Texture&); + Framebuffer createFramebuffer(const gfx::Texture&, const Renderbuffer<RenderbufferType::DepthComponent>&); template <typename Image, @@ -89,6 +88,13 @@ 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) { @@ -97,40 +103,6 @@ public: } #endif // MBGL_USE_GLES2 - // Create a texture from an image with data. - template <typename Image> - Texture createTexture(const Image& image, - TextureUnit unit = 0, - gfx::TextureChannelDataType type = gfx::TextureChannelDataType::UnsignedByte) { - auto format = image.channels == 4 ? gfx::TexturePixelType::RGBA : gfx::TexturePixelType::Alpha; - return { image.size, createTexture(image.size, image.data.get(), format, unit, type) }; - } - - template <typename Image> - void updateTexture(Texture& obj, - const Image& image, - TextureUnit unit = 0, - gfx::TextureChannelDataType type = gfx::TextureChannelDataType::UnsignedByte) { - auto format = image.channels == 4 ? gfx::TexturePixelType::RGBA : gfx::TexturePixelType::Alpha; - updateTexture(obj.texture.get(), image.size, image.data.get(), format, unit, type); - obj.size = image.size; - } - - // Creates an empty texture with the specified dimensions. - Texture createTexture(const Size size, - gfx::TexturePixelType format = gfx::TexturePixelType::RGBA, - TextureUnit unit = 0, - gfx::TextureChannelDataType type = gfx::TextureChannelDataType::UnsignedByte) { - return { size, createTexture(size, nullptr, format, unit, type) }; - } - - void bindTexture(Texture&, - TextureUnit = 0, - gfx::TextureFilterType = gfx::TextureFilterType::Nearest, - gfx::TextureMipMapType = gfx::TextureMipMapType::No, - gfx::TextureWrapType wrapX = gfx::TextureWrapType::Clamp, - gfx::TextureWrapType wrapY = gfx::TextureWrapType::Clamp); - void clear(optional<mbgl::Color> color, optional<float> depth, optional<int32_t> stencil); @@ -248,8 +220,9 @@ 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; - UniqueTexture createTexture(Size size, const void* data, gfx::TexturePixelType, TextureUnit, gfx::TextureChannelDataType); - void updateTexture(TextureID, Size size, const void* data, gfx::TexturePixelType, TextureUnit, gfx::TextureChannelDataType); + 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; + UniqueFramebuffer createFramebuffer(); UniqueRenderbuffer createRenderbuffer(RenderbufferType, Size size); std::unique_ptr<uint8_t[]> readFramebuffer(Size, gfx::TexturePixelType, bool flip); diff --git a/src/mbgl/gl/texture.hpp b/src/mbgl/gl/texture.hpp deleted file mode 100644 index 1b85ac6ebc..0000000000 --- a/src/mbgl/gl/texture.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include <mbgl/gfx/types.hpp> -#include <mbgl/gl/object.hpp> -#include <mbgl/util/size.hpp> - -namespace mbgl { -namespace gl { - -class Texture { -public: - Texture(Size size_, 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) - : size(std::move(size_)), - texture(std::move(texture_)), - filter(filter_), - mipmap(mipmap_), - wrapX(wrapX_), - wrapY(wrapY_) {} - - Size size; - UniqueTexture texture; - gfx::TextureFilterType filter; - gfx::TextureMipMapType mipmap; - gfx::TextureWrapType wrapX; - gfx::TextureWrapType wrapY; -}; - -} // namespace gl -} // namespace mbgl diff --git a/src/mbgl/gl/texture_resource.hpp b/src/mbgl/gl/texture_resource.hpp new file mode 100644 index 0000000000..4803f9b7f4 --- /dev/null +++ b/src/mbgl/gl/texture_resource.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include <mbgl/gfx/texture.hpp> +#include <mbgl/gl/object.hpp> + +namespace mbgl { +namespace gl { + +class TextureResource : public gfx::TextureResource { +public: + TextureResource(UniqueTexture&& texture_) : texture(std::move(texture_)) { + } + + UniqueTexture texture; +}; + +} // namespace gl +} // namespace mbgl diff --git a/src/mbgl/gl/types.hpp b/src/mbgl/gl/types.hpp index ab6b72656b..5cb486f0c9 100644 --- a/src/mbgl/gl/types.hpp +++ b/src/mbgl/gl/types.hpp @@ -25,8 +25,6 @@ using AttributeLocation = uint32_t; // "silently ignored". using UniformLocation = int32_t; -using TextureUnit = uint8_t; - enum class ShaderType : uint32_t { Vertex = 0x8B31, Fragment = 0x8B30 diff --git a/src/mbgl/gl/value.hpp b/src/mbgl/gl/value.hpp index 9c01039b99..15812a49bd 100644 --- a/src/mbgl/gl/value.hpp +++ b/src/mbgl/gl/value.hpp @@ -168,7 +168,7 @@ struct LineWidth { }; struct ActiveTextureUnit { - using Type = TextureUnit; + using Type = uint8_t; static const constexpr Type Default = 0; static void Set(const Type&); static Type Get(); diff --git a/src/mbgl/renderer/buckets/hillshade_bucket.hpp b/src/mbgl/renderer/buckets/hillshade_bucket.hpp index 50b05aaeef..906eac7e58 100644 --- a/src/mbgl/renderer/buckets/hillshade_bucket.hpp +++ b/src/mbgl/renderer/buckets/hillshade_bucket.hpp @@ -1,7 +1,7 @@ #pragma once #include <mbgl/gfx/index_buffer.hpp> -#include <mbgl/gl/texture.hpp> +#include <mbgl/gfx/texture.hpp> #include <mbgl/gfx/vertex_buffer.hpp> #include <mbgl/programs/hillshade_program.hpp> #include <mbgl/programs/hillshade_prepare_program.hpp> @@ -29,8 +29,8 @@ public: void clear(); void setMask(TileMask&&); - optional<gl::Texture> dem; - optional<gl::Texture> texture; + optional<gfx::Texture> dem; + optional<gfx::Texture> texture; TileMask mask{ { 0, 0, 0 } }; diff --git a/src/mbgl/renderer/buckets/raster_bucket.hpp b/src/mbgl/renderer/buckets/raster_bucket.hpp index ea48a0c235..4c4ca50320 100644 --- a/src/mbgl/renderer/buckets/raster_bucket.hpp +++ b/src/mbgl/renderer/buckets/raster_bucket.hpp @@ -1,7 +1,7 @@ #pragma once #include <mbgl/gfx/index_buffer.hpp> -#include <mbgl/gl/texture.hpp> +#include <mbgl/gfx/texture.hpp> #include <mbgl/gfx/vertex_buffer.hpp> #include <mbgl/programs/raster_program.hpp> #include <mbgl/renderer/bucket.hpp> @@ -27,7 +27,7 @@ public: void setMask(TileMask&&); std::shared_ptr<PremultipliedImage> image; - optional<gl::Texture> texture; + optional<gfx::Texture> texture; TileMask mask{ { 0, 0, 0 } }; // Bucket specific vertices are used for Image Sources only diff --git a/src/mbgl/renderer/image_manager.cpp b/src/mbgl/renderer/image_manager.cpp index 594d79b5cb..4d0f010e49 100644 --- a/src/mbgl/renderer/image_manager.cpp +++ b/src/mbgl/renderer/image_manager.cpp @@ -167,7 +167,7 @@ Size ImageManager::getPixelSize() const { }; } -void ImageManager::upload(gl::Context& context, gl::TextureUnit unit) { +void ImageManager::upload(gl::Context& context, uint8_t unit) { if (!atlasTexture) { atlasTexture = context.createTexture(atlasImage, unit); } else if (dirty) { @@ -177,7 +177,7 @@ void ImageManager::upload(gl::Context& context, gl::TextureUnit unit) { dirty = false; } -void ImageManager::bind(gl::Context& context, gl::TextureUnit unit) { +void ImageManager::bind(gl::Context& context, uint8_t unit) { upload(context, unit); context.bindTexture(*atlasTexture, unit, gfx::TextureFilterType::Linear); } diff --git a/src/mbgl/renderer/image_manager.hpp b/src/mbgl/renderer/image_manager.hpp index 103491c58b..e4b251e92b 100644 --- a/src/mbgl/renderer/image_manager.hpp +++ b/src/mbgl/renderer/image_manager.hpp @@ -5,7 +5,7 @@ #include <mbgl/util/noncopyable.hpp> #include <mbgl/util/immutable.hpp> #include <mbgl/util/optional.hpp> -#include <mbgl/gl/texture.hpp> +#include <mbgl/gfx/texture.hpp> #include <mapbox/shelf-pack.hpp> @@ -65,8 +65,8 @@ private: public: optional<ImagePosition> getPattern(const std::string& name); - void bind(gl::Context&, gl::TextureUnit unit); - void upload(gl::Context&, gl::TextureUnit unit); + void bind(gl::Context&, uint8_t unit); + void upload(gl::Context&, uint8_t unit); Size getPixelSize() const; @@ -84,7 +84,7 @@ private: mapbox::ShelfPack shelfPack; std::unordered_map<std::string, Pattern> patterns; PremultipliedImage atlasImage; - mbgl::optional<gl::Texture> atlasTexture; + mbgl::optional<gfx::Texture> atlasTexture; bool dirty = true; }; diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.hpp b/src/mbgl/renderer/layers/render_heatmap_layer.hpp index d63c30dcca..364628a2b2 100644 --- a/src/mbgl/renderer/layers/render_heatmap_layer.hpp +++ b/src/mbgl/renderer/layers/render_heatmap_layer.hpp @@ -3,7 +3,7 @@ #include <mbgl/renderer/render_layer.hpp> #include <mbgl/style/layers/heatmap_layer_impl.hpp> #include <mbgl/style/layers/heatmap_layer_properties.hpp> -#include <mbgl/gl/texture.hpp> +#include <mbgl/gfx/texture.hpp> #include <mbgl/util/optional.hpp> #include <mbgl/util/offscreen_texture.hpp> @@ -37,7 +37,7 @@ public: PremultipliedImage colorRamp; optional<OffscreenTexture> renderTexture; - optional<gl::Texture> colorRampTexture; + optional<gfx::Texture> colorRampTexture; private: void updateColorRamp(); diff --git a/src/mbgl/renderer/layers/render_line_layer.hpp b/src/mbgl/renderer/layers/render_line_layer.hpp index af2a5a26e2..186b740234 100644 --- a/src/mbgl/renderer/layers/render_line_layer.hpp +++ b/src/mbgl/renderer/layers/render_line_layer.hpp @@ -6,7 +6,7 @@ #include <mbgl/programs/uniforms.hpp> #include <mbgl/style/image_impl.hpp> #include <mbgl/layout/pattern_layout.hpp> -#include <mbgl/gl/texture.hpp> +#include <mbgl/gfx/texture.hpp> namespace mbgl { @@ -53,7 +53,7 @@ private: void updateColorRamp(); CrossfadeParameters crossfade; PremultipliedImage colorRamp; - optional<gl::Texture> colorRampTexture; + optional<gfx::Texture> colorRampTexture; }; inline const RenderLineLayer* toRenderLineLayer(const RenderLayer* layer) { diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp index c5c7cb6623..3f6f07e26e 100644 --- a/src/mbgl/tile/geometry_tile.hpp +++ b/src/mbgl/tile/geometry_tile.hpp @@ -132,8 +132,8 @@ private: FadeState fadeState = FadeState::Loaded; public: - optional<gl::Texture> glyphAtlasTexture; - optional<gl::Texture> iconAtlasTexture; + optional<gfx::Texture> glyphAtlasTexture; + optional<gfx::Texture> iconAtlasTexture; }; } // namespace mbgl diff --git a/src/mbgl/util/offscreen_texture.cpp b/src/mbgl/util/offscreen_texture.cpp index bf42f98ceb..6897732dc4 100644 --- a/src/mbgl/util/offscreen_texture.cpp +++ b/src/mbgl/util/offscreen_texture.cpp @@ -44,7 +44,7 @@ public: return context.readFramebuffer<PremultipliedImage>(size); } - gl::Texture& getTexture() { + gfx::Texture& getTexture() { assert(texture); return *texture; } @@ -57,7 +57,7 @@ private: gl::Context& context; const Size size; optional<gl::Framebuffer> framebuffer; - optional<gl::Texture> texture; + optional<gfx::Texture> texture; gl::Renderbuffer<gl::RenderbufferType::DepthComponent>* depth = nullptr; const gfx::TextureChannelDataType type; }; @@ -87,7 +87,7 @@ PremultipliedImage OffscreenTexture::readStillImage() { return impl->readStillImage(); } -gl::Texture& OffscreenTexture::getTexture() { +gfx::Texture& OffscreenTexture::getTexture() { return impl->getTexture(); } diff --git a/src/mbgl/util/offscreen_texture.hpp b/src/mbgl/util/offscreen_texture.hpp index 5dc1ad0c56..9446fabecf 100644 --- a/src/mbgl/util/offscreen_texture.hpp +++ b/src/mbgl/util/offscreen_texture.hpp @@ -8,9 +8,12 @@ namespace mbgl { namespace gl { class Context; -class Texture; } // namespace gl +namespace gfx { +class Texture; +} // namespace gfx + class OffscreenTexture { public: OffscreenTexture(gl::Context&, @@ -28,7 +31,7 @@ public: PremultipliedImage readStillImage(); - gl::Texture& getTexture(); + gfx::Texture& getTexture(); const Size& getSize() const; |