summaryrefslogtreecommitdiff
path: root/src/mbgl/gfx
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/gfx')
-rw-r--r--src/mbgl/gfx/command_encoder.hpp2
-rw-r--r--src/mbgl/gfx/context.hpp96
-rw-r--r--src/mbgl/gfx/stencil_mode.hpp9
-rw-r--r--src/mbgl/gfx/upload_pass.hpp109
4 files changed, 131 insertions, 85 deletions
diff --git a/src/mbgl/gfx/command_encoder.hpp b/src/mbgl/gfx/command_encoder.hpp
index 46ae551982..5692615643 100644
--- a/src/mbgl/gfx/command_encoder.hpp
+++ b/src/mbgl/gfx/command_encoder.hpp
@@ -10,6 +10,7 @@ namespace gfx {
class RenderPassDescriptor;
class RenderPass;
class Renderable;
+class UploadPass;
class CommandEncoder {
protected:
@@ -28,6 +29,7 @@ public:
return { *this, name };
}
+ virtual std::unique_ptr<UploadPass> createUploadPass(const char* name) = 0;
virtual std::unique_ptr<RenderPass> createRenderPass(const char* name, const RenderPassDescriptor&) = 0;
virtual void present(Renderable&) = 0;
};
diff --git a/src/mbgl/gfx/context.hpp b/src/mbgl/gfx/context.hpp
index c56ace2252..118df30a26 100644
--- a/src/mbgl/gfx/context.hpp
+++ b/src/mbgl/gfx/context.hpp
@@ -1,15 +1,11 @@
#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/texture.hpp>
#include <mbgl/gfx/renderbuffer.hpp>
#include <mbgl/gfx/command_encoder.hpp>
#include <mbgl/gfx/draw_scope.hpp>
#include <mbgl/gfx/program.hpp>
#include <mbgl/gfx/types.hpp>
+#include <mbgl/gfx/texture.hpp>
namespace mbgl {
@@ -43,95 +39,25 @@ public:
virtual void performCleanup() = 0;
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.getResource(), 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.getResource(), v.data(), v.bytes());
- }
-
-protected:
- virtual std::unique_ptr<VertexBufferResource>
- createVertexBufferResource(const void* data, std::size_t size, const BufferUsageType) = 0;
- virtual void
- updateVertexBufferResource(VertexBufferResource&, const void* data, std::size_t size) = 0;
-
- virtual std::unique_ptr<IndexBufferResource>
- createIndexBufferResource(const void* data, std::size_t size, const BufferUsageType) = 0;
- virtual void
- updateIndexBufferResource(IndexBufferResource&, const void* data, std::size_t size) = 0;
+ virtual std::unique_ptr<OffscreenTexture>
+ createOffscreenTexture(Size,
+ TextureChannelDataType = TextureChannelDataType::UnsignedByte) = 0;
+ virtual std::unique_ptr<OffscreenTexture>
+ createOffscreenTexture(Size,
+ Renderbuffer<RenderbufferPixelType::Depth>&,
+ TextureChannelDataType = TextureChannelDataType::UnsignedByte) = 0;
public:
- // Create a texture from an image with data.
- template <typename Image>
- Texture createTexture(const Image& image,
- TextureChannelDataType type = TextureChannelDataType::UnsignedByte) {
- auto format = image.channels == 4 ? TexturePixelType::RGBA : TexturePixelType::Alpha;
- return { image.size,
- 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,
TextureChannelDataType type = TextureChannelDataType::UnsignedByte) {
- return { size, createTextureResource(size, nullptr, format, type) };
- }
-
- template <typename Image>
- void updateTexture(Texture& texture,
- const Image& image,
- TextureChannelDataType type = TextureChannelDataType::UnsignedByte) {
- auto format = image.channels == 4 ? TexturePixelType::RGBA : TexturePixelType::Alpha;
- updateTextureResource(texture.getResource(), image.size, image.data.get(), format, type);
- texture.size = image.size;
- }
-
- template <typename Image>
- void updateTextureSub(Texture& texture,
- const Image& image,
- const uint16_t offsetX,
- const uint16_t offsetY,
- TextureChannelDataType type = TextureChannelDataType::UnsignedByte) {
- assert(image.size.width + offsetX <= texture.size.width);
- assert(image.size.height + offsetY <= texture.size.height);
- auto format = image.channels == 4 ? TexturePixelType::RGBA : TexturePixelType::Alpha;
- updateTextureResourceSub(texture.getResource(), offsetX, offsetY, image.size, image.data.get(), format, type);
+ return { size, createTextureResource(size, format, type) };
}
protected:
- virtual std::unique_ptr<TextureResource> createTextureResource(
- Size, const void* data, TexturePixelType, TextureChannelDataType) = 0;
- virtual void updateTextureResource(TextureResource&, Size, const void* data,
- TexturePixelType, TextureChannelDataType) = 0;
- virtual void updateTextureResourceSub(TextureResource&, uint16_t xOffset, uint16_t yOffset, Size, const void* data,
- TexturePixelType, TextureChannelDataType) = 0;
-
-public:
- virtual std::unique_ptr<gfx::OffscreenTexture> createOffscreenTexture(
- Size, gfx::TextureChannelDataType = gfx::TextureChannelDataType::UnsignedByte) = 0;
- virtual std::unique_ptr<gfx::OffscreenTexture> createOffscreenTexture(
- Size,
- gfx::Renderbuffer<gfx::RenderbufferPixelType::Depth>&,
- gfx::TextureChannelDataType = gfx::TextureChannelDataType::UnsignedByte) = 0;
+ virtual std::unique_ptr<TextureResource>
+ createTextureResource(Size, TexturePixelType, TextureChannelDataType) = 0;
public:
template <RenderbufferPixelType pixelType>
diff --git a/src/mbgl/gfx/stencil_mode.hpp b/src/mbgl/gfx/stencil_mode.hpp
index 3ba2687b8c..aec403b59b 100644
--- a/src/mbgl/gfx/stencil_mode.hpp
+++ b/src/mbgl/gfx/stencil_mode.hpp
@@ -52,5 +52,14 @@ public:
}
};
+template <StencilFunctionType F>
+constexpr StencilFunctionType StencilMode::SimpleTest<F>::func;
+
+template <StencilFunctionType F>
+constexpr uint32_t StencilMode::SimpleTest<F>::mask;
+
+template <StencilFunctionType F>
+constexpr StencilFunctionType StencilMode::MaskedTest<F>::func;
+
} // namespace gfx
} // namespace mbgl
diff --git a/src/mbgl/gfx/upload_pass.hpp b/src/mbgl/gfx/upload_pass.hpp
new file mode 100644
index 0000000000..f0bf9d7e2d
--- /dev/null
+++ b/src/mbgl/gfx/upload_pass.hpp
@@ -0,0 +1,109 @@
+#pragma once
+
+#include <mbgl/gfx/debug_group.hpp>
+#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/texture.hpp>
+#include <mbgl/util/size.hpp>
+
+namespace mbgl {
+namespace gfx {
+
+class UploadPass {
+protected:
+ UploadPass() = default;
+
+ friend class DebugGroup<UploadPass>;
+ virtual void pushDebugGroup(const char* name) = 0;
+ virtual void popDebugGroup() = 0;
+
+public:
+ virtual ~UploadPass() = default;
+ UploadPass(const UploadPass&) = delete;
+ UploadPass& operator=(const UploadPass&) = delete;
+
+ DebugGroup<UploadPass> createDebugGroup(const char* name) {
+ return { *this, name };
+ }
+
+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.getResource(), 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.getResource(), v.data(), v.bytes());
+ }
+
+protected:
+ virtual std::unique_ptr<VertexBufferResource>
+ createVertexBufferResource(const void* data, std::size_t size, const BufferUsageType) = 0;
+ virtual void
+ updateVertexBufferResource(VertexBufferResource&, const void* data, std::size_t size) = 0;
+
+ virtual std::unique_ptr<IndexBufferResource>
+ createIndexBufferResource(const void* data, std::size_t size, const BufferUsageType) = 0;
+ virtual void
+ updateIndexBufferResource(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,
+ TextureChannelDataType type = TextureChannelDataType::UnsignedByte) {
+ auto format = image.channels == 4 ? TexturePixelType::RGBA : TexturePixelType::Alpha;
+ return { image.size,
+ createTextureResource(image.size, image.data.get(), format, type) };
+ }
+
+ template <typename Image>
+ void updateTexture(Texture& texture,
+ const Image& image,
+ TextureChannelDataType type = TextureChannelDataType::UnsignedByte) {
+ auto format = image.channels == 4 ? TexturePixelType::RGBA : TexturePixelType::Alpha;
+ updateTextureResource(texture.getResource(), image.size, image.data.get(), format, type);
+ texture.size = image.size;
+ }
+
+ template <typename Image>
+ void updateTextureSub(Texture& texture,
+ const Image& image,
+ const uint16_t offsetX,
+ const uint16_t offsetY,
+ TextureChannelDataType type = TextureChannelDataType::UnsignedByte) {
+ assert(image.size.width + offsetX <= texture.size.width);
+ assert(image.size.height + offsetY <= texture.size.height);
+ auto format = image.channels == 4 ? TexturePixelType::RGBA : TexturePixelType::Alpha;
+ updateTextureResourceSub(texture.getResource(), offsetX, offsetY, image.size, image.data.get(), format, type);
+ }
+
+protected:
+ virtual std::unique_ptr<TextureResource> createTextureResource(
+ Size, const void* data, TexturePixelType, TextureChannelDataType) = 0;
+ virtual void updateTextureResource(TextureResource&, Size, const void* data,
+ TexturePixelType, TextureChannelDataType) = 0;
+ virtual void updateTextureResourceSub(TextureResource&, uint16_t xOffset, uint16_t yOffset, Size, const void* data,
+ TexturePixelType, TextureChannelDataType) = 0;
+};
+
+} // namespace gfx
+} // namespace mbgl