[core] move IndexBuffer to gfx namespace

This commit is contained in:
Konstantin Käfer
2019-03-05 16:07:58 +01:00
parent f13c2b86e4
commit 4737a45383
21 changed files with 85 additions and 49 deletions

View File

@@ -500,6 +500,7 @@
"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",
"mbgl/gfx/index_buffer.hpp": "src/mbgl/gfx/index_buffer.hpp",
"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",

View File

@@ -0,0 +1,22 @@
#pragma once
#include <memory>
namespace mbgl {
namespace gfx {
class IndexBufferResource {
protected:
IndexBufferResource() = default;
public:
virtual ~IndexBufferResource() = default;
};
class IndexBuffer {
public:
std::size_t elements;
std::unique_ptr<const IndexBufferResource> resource;
};
} // namespace gfx
} // namespace mbgl

View File

@@ -1,5 +1,6 @@
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/enum.hpp>
#include <mbgl/gl/index_buffer.hpp>
#include <mbgl/gl/debugging_extension.hpp>
#include <mbgl/gl/vertex_array_extension.hpp>
#include <mbgl/gl/program_binary_extension.hpp>
@@ -261,21 +262,22 @@ void Context::updateVertexBuffer(UniqueBuffer& buffer, const void* data, std::si
MBGL_CHECK_ERROR(glBufferSubData(GL_ARRAY_BUFFER, 0, size, data));
}
UniqueBuffer Context::createIndexBuffer(const void* data, std::size_t size, const BufferUsage usage) {
std::unique_ptr<const gfx::IndexBufferResource>
Context::createIndexBuffer(const void* data, std::size_t size, const BufferUsage usage) {
BufferID id = 0;
MBGL_CHECK_ERROR(glGenBuffers(1, &id));
UniqueBuffer result { std::move(id), { this } };
bindVertexArray = 0;
globalVertexArrayState.indexBuffer = result;
MBGL_CHECK_ERROR(glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, data, static_cast<GLenum>(usage)));
return result;
return std::make_unique<gl::IndexBufferResource>(std::move(result));
}
void Context::updateIndexBuffer(UniqueBuffer& buffer, const void* data, std::size_t size) {
void Context::updateIndexBuffer(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;
globalVertexArrayState.indexBuffer = buffer;
globalVertexArrayState.indexBuffer = reinterpret_cast<const gl::IndexBufferResource&>(resource).buffer;
MBGL_CHECK_ERROR(glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, size, data));
}

View File

@@ -8,7 +8,7 @@
#include <mbgl/gl/renderbuffer.hpp>
#include <mbgl/gl/framebuffer.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/gl/index_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>
@@ -80,17 +80,17 @@ public:
}
template <class DrawMode>
IndexBuffer createIndexBuffer(gfx::IndexVector<DrawMode>&& v, const BufferUsage usage = BufferUsage::StaticDraw) {
return IndexBuffer {
gfx::IndexBuffer createIndexBuffer(gfx::IndexVector<DrawMode>&& v, const BufferUsage usage = BufferUsage::StaticDraw) {
return {
v.elements(),
createIndexBuffer(v.data(), v.bytes(), usage)
};
}
template <class DrawMode>
void updateIndexBuffer(IndexBuffer& buffer, gfx::IndexVector<DrawMode>&& v) {
void updateIndexBuffer(gfx::IndexBuffer& buffer, gfx::IndexVector<DrawMode>&& v) {
assert(v.elements() == buffer.elements);
updateIndexBuffer(buffer.buffer, v.data(), v.bytes());
updateIndexBuffer(*buffer.resource, v.data(), v.bytes());
}
template <RenderbufferType type>
@@ -276,8 +276,8 @@ private:
UniqueBuffer createVertexBuffer(const void* data, std::size_t size, const BufferUsage usage);
void updateVertexBuffer(UniqueBuffer& buffer, const void* data, std::size_t size);
UniqueBuffer createIndexBuffer(const void* data, std::size_t size, const BufferUsage usage);
void updateIndexBuffer(UniqueBuffer& buffer, const void* data, std::size_t size);
std::unique_ptr<const gfx::IndexBufferResource> createIndexBuffer(const void* data, std::size_t size, const BufferUsage usage);
void updateIndexBuffer(const gfx::IndexBufferResource&, const void* data, std::size_t size);
UniqueTexture createTexture(Size size, const void* data, TextureFormat, TextureUnit, TextureType);
void updateTexture(TextureID, Size size, const void* data, TextureFormat, TextureUnit, TextureType);
UniqueFramebuffer createFramebuffer();

View File

@@ -1,13 +1,16 @@
#pragma once
#include <mbgl/gfx/index_buffer.hpp>
#include <mbgl/gl/object.hpp>
namespace mbgl {
namespace gl {
class IndexBuffer {
class IndexBufferResource : public gfx::IndexBufferResource {
public:
std::size_t elements;
IndexBufferResource(UniqueBuffer&& buffer_) : buffer(std::move(buffer_)) {
}
UniqueBuffer buffer;
};

View File

@@ -4,7 +4,7 @@
#include <mbgl/gl/object.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/gl/index_buffer.hpp>
#include <mbgl/gfx/index_buffer.hpp>
#include <mbgl/gl/vertex_array.hpp>
#include <mbgl/gl/attribute.hpp>
#include <mbgl/gl/uniform.hpp>
@@ -120,9 +120,9 @@ public:
gfx::ColorMode colorMode,
gfx::CullFaceMode cullFaceMode,
const UniformValues& uniformValues,
VertexArray& vertexArray,
gl::VertexArray& vertexArray,
const AttributeBindings& attributeBindings,
const IndexBuffer& indexBuffer,
const gfx::IndexBuffer& indexBuffer,
std::size_t indexOffset,
std::size_t indexLength) {
static_assert(std::is_same<Primitive, typename DrawMode::Primitive>::value, "incompatible draw mode");
@@ -138,7 +138,7 @@ public:
Uniforms::bind(uniformsState, uniformValues);
vertexArray.bind(context,
indexBuffer.buffer,
indexBuffer,
Attributes::toBindingArray(attributeLocations, attributeBindings));
context.draw(drawMode.primitiveType,

View File

@@ -1,12 +1,15 @@
#include <mbgl/gl/vertex_array.hpp>
#include <mbgl/gl/index_buffer.hpp>
#include <mbgl/gl/context.hpp>
namespace mbgl {
namespace gl {
void VertexArray::bind(Context& context, BufferID indexBuffer, const AttributeBindingArray& bindings) {
void VertexArray::bind(Context& context,
const gfx::IndexBuffer& indexBuffer,
const AttributeBindingArray& bindings) {
context.bindVertexArray = state->vertexArray;
state->indexBuffer = indexBuffer;
state->indexBuffer = reinterpret_cast<const gl::IndexBufferResource&>(*indexBuffer.resource).buffer;
state->bindings.reserve(bindings.size());
for (AttributeLocation location = 0; location < bindings.size(); ++location) {

View File

@@ -9,6 +9,11 @@
#include <memory>
namespace mbgl {
namespace gfx {
class IndexBuffer;
} // namespace gfx
namespace gl {
class Context;
@@ -56,7 +61,7 @@ public:
: state(std::move(state_)) {
}
void bind(Context&, BufferID indexBuffer, const AttributeBindingArray&);
void bind(Context&, const gfx::IndexBuffer&, const AttributeBindingArray&);
private:
UniqueVertexArrayState state;

View File

@@ -65,7 +65,7 @@ public:
const UniformValues& uniformValues,
const gl::VertexBuffer<gfx::Vertex<CollisionBoxLayoutAttributes>>& layoutVertexBuffer,
const gl::VertexBuffer<gfx::Vertex<CollisionBoxDynamicAttributes>>& dynamicVertexBuffer,
const gl::IndexBuffer& indexBuffer,
const gfx::IndexBuffer& indexBuffer,
const SegmentVector<Attributes>& segments,
const Binders& paintPropertyBinders,
const typename PaintProperties::PossiblyEvaluated& currentProperties,
@@ -146,7 +146,7 @@ public:
const UniformValues& uniformValues,
const gl::VertexBuffer<gfx::Vertex<CollisionBoxLayoutAttributes>>& layoutVertexBuffer,
const gl::VertexBuffer<gfx::Vertex<CollisionBoxDynamicAttributes>>& dynamicVertexBuffer,
const gl::IndexBuffer& indexBuffer,
const gfx::IndexBuffer& indexBuffer,
const SegmentVector<Attributes>& segments,
const Binders& paintPropertyBinders,
const typename PaintProperties::PossiblyEvaluated& currentProperties,

View File

@@ -75,7 +75,7 @@ public:
gfx::StencilMode stencilMode,
gfx::ColorMode colorMode,
gfx::CullFaceMode cullFaceMode,
const gl::IndexBuffer& indexBuffer,
const gfx::IndexBuffer& indexBuffer,
const SegmentVector<Attributes>& segments,
const typename AllUniforms::Values& allUniformValues,
const typename Attributes::Bindings& allAttributeBindings,

View File

@@ -310,7 +310,7 @@ public:
gfx::StencilMode stencilMode,
gfx::ColorMode colorMode,
gfx::CullFaceMode cullFaceMode,
const gl::IndexBuffer& indexBuffer,
const gfx::IndexBuffer& indexBuffer,
const SegmentVector<Attributes>& segments,
const typename AllUniforms::Values& allUniformValues,
const typename Attributes::Bindings& allAttributeBindings,

View File

@@ -4,7 +4,7 @@
#include <mbgl/map/mode.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/gl/index_buffer.hpp>
#include <mbgl/gfx/index_buffer.hpp>
#include <mbgl/programs/segment.hpp>
#include <mbgl/programs/circle_program.hpp>
#include <mbgl/style/layers/circle_layer_properties.hpp>
@@ -35,7 +35,7 @@ public:
SegmentVector<CircleAttributes> segments;
optional<gl::VertexBuffer<CircleLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer> indexBuffer;
optional<gfx::IndexBuffer> indexBuffer;
std::map<std::string, CircleProgram::Binders> paintPropertyBinders;

View File

@@ -6,7 +6,7 @@
#include <mbgl/util/optional.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/gl/index_buffer.hpp>
#include <mbgl/gfx/index_buffer.hpp>
#include <mbgl/programs/debug_program.hpp>
namespace mbgl {
@@ -35,7 +35,7 @@ public:
SegmentVector<DebugAttributes> segments;
optional<gl::VertexBuffer<DebugLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer> indexBuffer;
optional<gfx::IndexBuffer> indexBuffer;
};
} // namespace mbgl

View File

@@ -3,7 +3,7 @@
#include <mbgl/renderer/bucket.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/gl/index_buffer.hpp>
#include <mbgl/gfx/index_buffer.hpp>
#include <mbgl/programs/segment.hpp>
#include <mbgl/programs/fill_program.hpp>
#include <mbgl/style/layers/fill_layer_properties.hpp>
@@ -47,8 +47,8 @@ public:
SegmentVector<FillAttributes> triangleSegments;
optional<gl::VertexBuffer<FillLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer> lineIndexBuffer;
optional<gl::IndexBuffer> triangleIndexBuffer;
optional<gfx::IndexBuffer> lineIndexBuffer;
optional<gfx::IndexBuffer> triangleIndexBuffer;
std::map<std::string, FillProgram::Binders> paintPropertyBinders;
};

View File

@@ -3,7 +3,7 @@
#include <mbgl/renderer/bucket.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/gl/index_buffer.hpp>
#include <mbgl/gfx/index_buffer.hpp>
#include <mbgl/programs/segment.hpp>
#include <mbgl/programs/fill_extrusion_program.hpp>
#include <mbgl/style/layers/fill_extrusion_layer_properties.hpp>
@@ -44,7 +44,7 @@ public:
SegmentVector<FillExtrusionAttributes> triangleSegments;
optional<gl::VertexBuffer<FillExtrusionLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer> indexBuffer;
optional<gfx::IndexBuffer> indexBuffer;
std::unordered_map<std::string, FillExtrusionProgram::Binders> paintPropertyBinders;
};

View File

@@ -4,7 +4,7 @@
#include <mbgl/map/mode.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/gl/index_buffer.hpp>
#include <mbgl/gfx/index_buffer.hpp>
#include <mbgl/programs/segment.hpp>
#include <mbgl/programs/heatmap_program.hpp>
#include <mbgl/style/layers/heatmap_layer_properties.hpp>
@@ -34,7 +34,7 @@ public:
SegmentVector<HeatmapAttributes> segments;
optional<gl::VertexBuffer<HeatmapLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer> indexBuffer;
optional<gfx::IndexBuffer> indexBuffer;
std::map<std::string, HeatmapProgram::Binders> paintPropertyBinders;

View File

@@ -1,6 +1,6 @@
#pragma once
#include <mbgl/gl/index_buffer.hpp>
#include <mbgl/gfx/index_buffer.hpp>
#include <mbgl/gl/texture.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/programs/hillshade_program.hpp>
@@ -51,7 +51,7 @@ public:
SegmentVector<HillshadeAttributes> segments;
optional<gl::VertexBuffer<HillshadeLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer> indexBuffer;
optional<gfx::IndexBuffer> indexBuffer;
private:
DEMData demdata;
bool prepared = false;

View File

@@ -2,7 +2,7 @@
#include <mbgl/renderer/bucket.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/gl/index_buffer.hpp>
#include <mbgl/gfx/index_buffer.hpp>
#include <mbgl/programs/segment.hpp>
#include <mbgl/programs/line_program.hpp>
#include <mbgl/style/layers/line_layer_properties.hpp>
@@ -48,7 +48,7 @@ public:
SegmentVector<LineAttributes> segments;
optional<gl::VertexBuffer<LineLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer> indexBuffer;
optional<gfx::IndexBuffer> indexBuffer;
std::map<std::string, LineProgram::Binders> paintPropertyBinders;

View File

@@ -1,6 +1,6 @@
#pragma once
#include <mbgl/gl/index_buffer.hpp>
#include <mbgl/gfx/index_buffer.hpp>
#include <mbgl/gl/texture.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/programs/raster_program.hpp>
@@ -37,7 +37,7 @@ public:
SegmentVector<RasterAttributes> segments;
optional<gl::VertexBuffer<RasterLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer> indexBuffer;
optional<gfx::IndexBuffer> indexBuffer;
};
} // namespace mbgl

View File

@@ -3,7 +3,7 @@
#include <mbgl/renderer/bucket.hpp>
#include <mbgl/map/mode.hpp>
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/gl/index_buffer.hpp>
#include <mbgl/gfx/index_buffer.hpp>
#include <mbgl/programs/segment.hpp>
#include <mbgl/programs/symbol_program.hpp>
#include <mbgl/programs/collision_box_program.hpp>
@@ -98,7 +98,7 @@ public:
optional<gl::VertexBuffer<SymbolLayoutVertex>> vertexBuffer;
optional<gl::VertexBuffer<gfx::Vertex<SymbolDynamicLayoutAttributes>>> dynamicVertexBuffer;
optional<gl::VertexBuffer<gfx::Vertex<SymbolOpacityAttributes>>> opacityVertexBuffer;
optional<gl::IndexBuffer> indexBuffer;
optional<gfx::IndexBuffer> indexBuffer;
} text;
std::unique_ptr<SymbolSizeBinder> iconSizeBinder;
@@ -115,7 +115,7 @@ public:
optional<gl::VertexBuffer<SymbolLayoutVertex>> vertexBuffer;
optional<gl::VertexBuffer<gfx::Vertex<SymbolDynamicLayoutAttributes>>> dynamicVertexBuffer;
optional<gl::VertexBuffer<gfx::Vertex<SymbolOpacityAttributes>>> opacityVertexBuffer;
optional<gl::IndexBuffer> indexBuffer;
optional<gfx::IndexBuffer> indexBuffer;
} icon;
struct CollisionBuffer {
@@ -129,12 +129,12 @@ public:
struct CollisionBoxBuffer : public CollisionBuffer {
gfx::IndexVector<gfx::Lines> lines;
optional<gl::IndexBuffer> indexBuffer;
optional<gfx::IndexBuffer> indexBuffer;
} collisionBox;
struct CollisionCircleBuffer : public CollisionBuffer {
gfx::IndexVector<gfx::Triangles> triangles;
optional<gl::IndexBuffer> indexBuffer;
optional<gfx::IndexBuffer> indexBuffer;
} collisionCircle;
uint32_t bucketInstanceId = 0;

View File

@@ -1,7 +1,7 @@
#pragma once
#include <mbgl/gl/vertex_buffer.hpp>
#include <mbgl/gl/index_buffer.hpp>
#include <mbgl/gfx/index_buffer.hpp>
#include <mbgl/programs/background_program.hpp>
#include <mbgl/programs/extrusion_texture_program.hpp>
#include <mbgl/programs/programs.hpp>
@@ -20,8 +20,8 @@ public:
gl::VertexBuffer<RasterLayoutVertex> rasterVertexBuffer;
gl::VertexBuffer<ExtrusionTextureLayoutVertex> extrusionTextureVertexBuffer;
gl::IndexBuffer quadTriangleIndexBuffer;
gl::IndexBuffer tileBorderIndexBuffer;
gfx::IndexBuffer quadTriangleIndexBuffer;
gfx::IndexBuffer tileBorderIndexBuffer;
SegmentVector<BackgroundAttributes> tileTriangleSegments;
SegmentVector<DebugAttributes> tileBorderSegments;