summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core-files.json1
-rw-r--r--src/mbgl/gfx/context.hpp62
-rw-r--r--src/mbgl/gl/context.cpp8
-rw-r--r--src/mbgl/gl/context.hpp46
-rw-r--r--src/mbgl/renderer/paint_property_binder.hpp16
5 files changed, 83 insertions, 50 deletions
diff --git a/src/core-files.json b/src/core-files.json
index 928cb9c8aa..ab43e6b409 100644
--- a/src/core-files.json
+++ b/src/core-files.json
@@ -497,6 +497,7 @@
"mbgl/geometry/line_atlas.hpp": "src/mbgl/geometry/line_atlas.hpp",
"mbgl/gfx/attribute.hpp": "src/mbgl/gfx/attribute.hpp",
"mbgl/gfx/color_mode.hpp": "src/mbgl/gfx/color_mode.hpp",
+ "mbgl/gfx/context.hpp": "src/mbgl/gfx/context.hpp",
"mbgl/gfx/cull_face_mode.hpp": "src/mbgl/gfx/cull_face_mode.hpp",
"mbgl/gfx/depth_mode.hpp": "src/mbgl/gfx/depth_mode.hpp",
"mbgl/gfx/draw_mode.hpp": "src/mbgl/gfx/draw_mode.hpp",
diff --git a/src/mbgl/gfx/context.hpp b/src/mbgl/gfx/context.hpp
new file mode 100644
index 0000000000..b57cfcb65c
--- /dev/null
+++ b/src/mbgl/gfx/context.hpp
@@ -0,0 +1,62 @@
+#pragma once
+
+#include <mbgl/gfx/vertex_vector.hpp>
+#include <mbgl/gfx/vertex_buffer.hpp>
+#include <mbgl/gfx/index_vector.hpp>
+#include <mbgl/gfx/index_buffer.hpp>
+#include <mbgl/gfx/types.hpp>
+
+namespace mbgl {
+namespace gfx {
+
+class Context {
+protected:
+ Context() = default;
+
+public:
+ Context(Context&&) = delete;
+ Context(const Context&) = delete;
+ Context& operator=(Context&& other) = delete;
+ Context& operator=(const Context& other) = delete;
+ virtual ~Context() = default;
+
+public:
+ template <class Vertex>
+ VertexBuffer<Vertex>
+ createVertexBuffer(VertexVector<Vertex>&& v,
+ const BufferUsageType usage = BufferUsageType::StaticDraw) {
+ return { v.elements(), createVertexBufferResource(v.data(), v.bytes(), usage) };
+ }
+
+ template <class Vertex>
+ void updateVertexBuffer(VertexBuffer<Vertex>& buffer, VertexVector<Vertex>&& v) {
+ assert(v.elements() == buffer.elements);
+ updateVertexBufferResource(*buffer.resource, v.data(), v.bytes());
+ }
+
+ template <class DrawMode>
+ IndexBuffer createIndexBuffer(IndexVector<DrawMode>&& v,
+ const BufferUsageType usage = BufferUsageType::StaticDraw) {
+ return { v.elements(), createIndexBufferResource(v.data(), v.bytes(), usage) };
+ }
+
+ template <class DrawMode>
+ void updateIndexBuffer(IndexBuffer& buffer, IndexVector<DrawMode>&& v) {
+ assert(v.elements() == buffer.elements);
+ updateIndexBufferResource(*buffer.resource, v.data(), v.bytes());
+ }
+
+protected:
+ virtual std::unique_ptr<const VertexBufferResource>
+ createVertexBufferResource(const void* data, std::size_t size, const BufferUsageType) = 0;
+ virtual void
+ updateVertexBufferResource(const VertexBufferResource&, const void* data, std::size_t size) = 0;
+
+ virtual std::unique_ptr<const IndexBufferResource>
+ createIndexBufferResource(const void* data, std::size_t size, const BufferUsageType) = 0;
+ virtual void
+ updateIndexBufferResource(const IndexBufferResource&, const void* data, std::size_t size) = 0;
+};
+
+} // namespace gfx
+} // namespace mbgl
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp
index 514bc0115e..df304eb7d4 100644
--- a/src/mbgl/gl/context.cpp
+++ b/src/mbgl/gl/context.cpp
@@ -246,7 +246,7 @@ void Context::verifyProgramLinkage(ProgramID program_) {
}
std::unique_ptr<const gfx::VertexBufferResource>
-Context::createVertexBuffer(const void* data, std::size_t size, const gfx::BufferUsageType usage) {
+Context::createVertexBufferResource(const void* data, std::size_t size, const gfx::BufferUsageType usage) {
BufferID id = 0;
MBGL_CHECK_ERROR(glGenBuffers(1, &id));
UniqueBuffer result { std::move(id), { this } };
@@ -255,13 +255,13 @@ Context::createVertexBuffer(const void* data, std::size_t size, const gfx::Buffe
return std::make_unique<gl::VertexBufferResource>(std::move(result));
}
-void Context::updateVertexBuffer(const gfx::VertexBufferResource& resource, const void* data, std::size_t size) {
+void Context::updateVertexBufferResource(const gfx::VertexBufferResource& resource, const void* data, std::size_t size) {
vertexBuffer = reinterpret_cast<const gl::VertexBufferResource&>(resource).buffer;
MBGL_CHECK_ERROR(glBufferSubData(GL_ARRAY_BUFFER, 0, size, data));
}
std::unique_ptr<const gfx::IndexBufferResource>
-Context::createIndexBuffer(const void* data, std::size_t size, const gfx::BufferUsageType usage) {
+Context::createIndexBufferResource(const void* data, std::size_t size, const gfx::BufferUsageType usage) {
BufferID id = 0;
MBGL_CHECK_ERROR(glGenBuffers(1, &id));
UniqueBuffer result { std::move(id), { this } };
@@ -271,7 +271,7 @@ Context::createIndexBuffer(const void* data, std::size_t size, const gfx::Buffer
return std::make_unique<gl::IndexBufferResource>(std::move(result));
}
-void Context::updateIndexBuffer(const gfx::IndexBufferResource& resource, const void* data, std::size_t size) {
+void Context::updateIndexBufferResource(const gfx::IndexBufferResource& resource, const void* data, std::size_t size) {
// Be sure to unbind any existing vertex array object before binding the index buffer
// so that we don't mess up another VAO
bindVertexArray = 0;
diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp
index 585ee286c4..70ba1ec107 100644
--- a/src/mbgl/gl/context.hpp
+++ b/src/mbgl/gl/context.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <mbgl/gfx/context.hpp>
#include <mbgl/gl/features.hpp>
#include <mbgl/gl/object.hpp>
#include <mbgl/gl/state.hpp>
@@ -7,12 +8,8 @@
#include <mbgl/gl/texture.hpp>
#include <mbgl/gl/renderbuffer.hpp>
#include <mbgl/gl/framebuffer.hpp>
-#include <mbgl/gfx/vertex_buffer.hpp>
-#include <mbgl/gfx/index_buffer.hpp>
#include <mbgl/gl/vertex_array.hpp>
#include <mbgl/gl/types.hpp>
-#include <mbgl/gfx/vertex_vector.hpp>
-#include <mbgl/gfx/index_vector.hpp>
#include <mbgl/gfx/draw_mode.hpp>
#include <mbgl/gfx/depth_mode.hpp>
#include <mbgl/gfx/stencil_mode.hpp>
@@ -39,10 +36,10 @@ class Debugging;
class ProgramBinary;
} // namespace extension
-class Context {
+class Context final : public gfx::Context {
public:
Context();
- ~Context();
+ ~Context() override;
Context(const Context&) = delete;
Context& operator=(const Context& other) = delete;
@@ -65,34 +62,6 @@ public:
#endif
optional<std::pair<BinaryProgramFormat, std::string>> getBinaryProgram(ProgramID) const;
- template <class Vertex>
- gfx::VertexBuffer<Vertex> createVertexBuffer(gfx::VertexVector<Vertex>&& v, const gfx::BufferUsageType usage = gfx::BufferUsageType::StaticDraw) {
- return {
- v.elements(),
- createVertexBuffer(v.data(), v.bytes(), usage)
- };
- }
-
- template <class Vertex>
- void updateVertexBuffer(gfx::VertexBuffer<Vertex>& buffer, gfx::VertexVector<Vertex>&& v) {
- assert(v.elements() == buffer.elements);
- updateVertexBuffer(*buffer.resource, v.data(), v.bytes());
- }
-
- template <class DrawMode>
- gfx::IndexBuffer createIndexBuffer(gfx::IndexVector<DrawMode>&& v, const gfx::BufferUsageType usage = gfx::BufferUsageType::StaticDraw) {
- return {
- v.elements(),
- createIndexBuffer(v.data(), v.bytes(), usage)
- };
- }
-
- template <class DrawMode>
- void updateIndexBuffer(gfx::IndexBuffer& buffer, gfx::IndexVector<DrawMode>&& v) {
- assert(v.elements() == buffer.elements);
- updateIndexBuffer(*buffer.resource, v.data(), v.bytes());
- }
-
template <RenderbufferType type>
Renderbuffer<type> createRenderbuffer(const Size size) {
static_assert(type == RenderbufferType::RGBA ||
@@ -274,10 +243,11 @@ private:
State<value::PointSize> pointSize;
#endif // MBGL_USE_GLES2
- std::unique_ptr<const gfx::VertexBufferResource> createVertexBuffer(const void* data, std::size_t size, const gfx::BufferUsageType usage);
- void updateVertexBuffer(const gfx::VertexBufferResource&, const void* data, std::size_t size);
- std::unique_ptr<const gfx::IndexBufferResource> createIndexBuffer(const void* data, std::size_t size, const gfx::BufferUsageType usage);
- void updateIndexBuffer(const gfx::IndexBufferResource&, const void* data, std::size_t size);
+ std::unique_ptr<const gfx::VertexBufferResource> createVertexBufferResource(const void* data, std::size_t size, const gfx::BufferUsageType) override;
+ void updateVertexBufferResource(const gfx::VertexBufferResource&, const void* data, std::size_t size) override;
+ 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, TextureFormat, TextureUnit, TextureType);
void updateTexture(TextureID, Size size, const void* data, TextureFormat, TextureUnit, TextureType);
UniqueFramebuffer createFramebuffer();
diff --git a/src/mbgl/renderer/paint_property_binder.hpp b/src/mbgl/renderer/paint_property_binder.hpp
index da317f93e8..34600508af 100644
--- a/src/mbgl/renderer/paint_property_binder.hpp
+++ b/src/mbgl/renderer/paint_property_binder.hpp
@@ -1,10 +1,10 @@
#pragma once
+#include <mbgl/gfx/context.hpp>
#include <mbgl/gfx/uniform.hpp>
#include <mbgl/programs/attributes.hpp>
#include <mbgl/gl/attribute.hpp>
#include <mbgl/gl/uniform.hpp>
-#include <mbgl/gl/context.hpp>
#include <mbgl/util/type_list.hpp>
#include <mbgl/renderer/possibly_evaluated_property_value.hpp>
#include <mbgl/renderer/paint_property_statistics.hpp>
@@ -96,7 +96,7 @@ public:
virtual ~PaintPropertyBinder() = default;
virtual void populateVertexVector(const GeometryTileFeature& feature, std::size_t length, const ImagePositions&, const optional<PatternDependency>&) = 0;
- virtual void upload(gl::Context& context) = 0;
+ virtual void upload(gfx::Context& context) = 0;
virtual void setPatternParameters(const optional<ImagePosition>&, const optional<ImagePosition>&, CrossfadeParameters&) = 0;
virtual std::tuple<ExpandToType<As, optional<gl::AttributeBinding>>...> attributeBinding(const PossiblyEvaluatedType& currentValue) const = 0;
virtual std::tuple<ExpandToType<As, float>...> interpolationFactor(float currentZoom) const = 0;
@@ -115,7 +115,7 @@ public:
}
void populateVertexVector(const GeometryTileFeature&, std::size_t, const ImagePositions&, const optional<PatternDependency>&) override {}
- void upload(gl::Context&) override {}
+ void upload(gfx::Context&) override {}
void setPatternParameters(const optional<ImagePosition>&, const optional<ImagePosition>&, CrossfadeParameters&) override {};
std::tuple<optional<gl::AttributeBinding>> attributeBinding(const PossiblyEvaluatedPropertyValue<T>&) const override {
@@ -142,7 +142,7 @@ public:
}
void populateVertexVector(const GeometryTileFeature&, std::size_t, const ImagePositions&, const optional<PatternDependency>&) override {}
- void upload(gl::Context&) override {}
+ void upload(gfx::Context&) override {}
void setPatternParameters(const optional<ImagePosition>& posA, const optional<ImagePosition>& posB, CrossfadeParameters&) override {
if (!posA && !posB) {
@@ -192,7 +192,7 @@ public:
}
}
- void upload(gl::Context& context) override {
+ void upload(gfx::Context& context) override {
vertexBuffer = context.createVertexBuffer(std::move(vertexVector));
}
@@ -252,7 +252,7 @@ public:
}
}
- void upload(gl::Context& context) override {
+ void upload(gfx::Context& context) override {
vertexBuffer = context.createVertexBuffer(std::move(vertexVector));
}
@@ -344,7 +344,7 @@ public:
}
}
- void upload(gl::Context& context) override {
+ void upload(gfx::Context& context) override {
patternToVertexBuffer = context.createVertexBuffer(std::move(patternToVertexVector));
zoomInVertexBuffer = context.createVertexBuffer(std::move(zoomInVertexVector));
zoomOutVertexBuffer = context.createVertexBuffer(std::move(zoomOutVertexVector));
@@ -486,7 +486,7 @@ public:
});
}
- void upload(gl::Context& context) {
+ void upload(gfx::Context& context) {
util::ignore({
(binders.template get<Ps>()->upload(context), 0)...
});