[core] gl::RenderbufferType -> gfx::RenderbufferPixelType

This commit is contained in:
Konstantin Käfer
2019-03-20 13:48:14 +01:00
parent ca60095071
commit 839f4687aa
11 changed files with 69 additions and 56 deletions

View File

@@ -11,13 +11,13 @@ namespace mbgl {
class HeadlessBackend::View {
public:
View(gl::Context& context, Size size_)
: color(context.createRenderbuffer<gl::RenderbufferType::RGBA>(size_)),
depthStencil(context.createRenderbuffer<gl::RenderbufferType::DepthStencil>(size_)),
: color(context.createRenderbuffer<gfx::RenderbufferPixelType::RGBA>(size_)),
depthStencil(context.createRenderbuffer<gfx::RenderbufferPixelType::DepthStencil>(size_)),
framebuffer(context.createFramebuffer(color, depthStencil)) {
}
gl::Renderbuffer<gl::RenderbufferType::RGBA> color;
gl::Renderbuffer<gl::RenderbufferType::DepthStencil> depthStencil;
gl::Renderbuffer<gfx::RenderbufferPixelType::RGBA> color;
gl::Renderbuffer<gfx::RenderbufferPixelType::DepthStencil> depthStencil;
gl::Framebuffer framebuffer;
};

View File

@@ -171,5 +171,11 @@ enum class TextureWrapType : bool {
Repeat,
};
enum class RenderbufferPixelType : uint8_t {
RGBA,
Depth,
DepthStencil,
};
} // namespace gfx
} // namespace mbgl

View File

@@ -23,22 +23,6 @@ using namespace platform;
static_assert(underlying_type(ShaderType::Vertex) == GL_VERTEX_SHADER, "OpenGL type mismatch");
static_assert(underlying_type(ShaderType::Fragment) == GL_FRAGMENT_SHADER, "OpenGL type mismatch");
#if not MBGL_USE_GLES2
static_assert(underlying_type(RenderbufferType::RGBA) == GL_RGBA8, "OpenGL type mismatch");
#else
static_assert(underlying_type(RenderbufferType::RGBA) == GL_RGBA8_OES, "OpenGL type mismatch");
#endif // MBGL_USE_GLES2
#if not MBGL_USE_GLES2
static_assert(underlying_type(RenderbufferType::DepthStencil) == GL_DEPTH24_STENCIL8, "OpenGL type mismatch");
#else
static_assert(underlying_type(RenderbufferType::DepthStencil) == GL_DEPTH24_STENCIL8_OES, "OpenGL type mismatch");
#endif // MBGL_USE_GLES2
#if not MBGL_USE_GLES2
static_assert(underlying_type(RenderbufferType::DepthComponent) == GL_DEPTH_COMPONENT, "OpenGL type mismatch");
#else
static_assert(underlying_type(RenderbufferType::DepthComponent) == GL_DEPTH_COMPONENT16, "OpenGL type mismatch");
#endif // MBGL_USE_GLES2
static_assert(std::is_same<ProgramID, GLuint>::value, "OpenGL type mismatch");
static_assert(std::is_same<ShaderID, GLuint>::value, "OpenGL type mismatch");
static_assert(std::is_same<BufferID, GLuint>::value, "OpenGL type mismatch");
@@ -352,14 +336,14 @@ UniqueFramebuffer Context::createFramebuffer() {
return UniqueFramebuffer{ std::move(id), { this } };
}
UniqueRenderbuffer Context::createRenderbuffer(const RenderbufferType type, const Size size) {
UniqueRenderbuffer Context::createRenderbuffer(const gfx::RenderbufferPixelType type, const Size size) {
RenderbufferID id = 0;
MBGL_CHECK_ERROR(glGenRenderbuffers(1, &id));
UniqueRenderbuffer renderbuffer{ std::move(id), { this } };
bindRenderbuffer = renderbuffer;
MBGL_CHECK_ERROR(
glRenderbufferStorage(GL_RENDERBUFFER, static_cast<GLenum>(type), size.width, size.height));
glRenderbufferStorage(GL_RENDERBUFFER, Enum<gfx::RenderbufferPixelType>::to(type), size.width, size.height));
bindRenderbuffer = 0;
return renderbuffer;
}
@@ -433,7 +417,7 @@ void checkFramebuffer() {
}
void bindDepthStencilRenderbuffer(
const Renderbuffer<RenderbufferType::DepthStencil>& depthStencil) {
const Renderbuffer<gfx::RenderbufferPixelType::DepthStencil>& depthStencil) {
#ifdef GL_DEPTH_STENCIL_ATTACHMENT
MBGL_CHECK_ERROR(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
GL_RENDERBUFFER, depthStencil.renderbuffer));
@@ -448,8 +432,8 @@ void bindDepthStencilRenderbuffer(
} // namespace
Framebuffer
Context::createFramebuffer(const Renderbuffer<RenderbufferType::RGBA>& color,
const Renderbuffer<RenderbufferType::DepthStencil>& depthStencil) {
Context::createFramebuffer(const Renderbuffer<gfx::RenderbufferPixelType::RGBA>& color,
const Renderbuffer<gfx::RenderbufferPixelType::DepthStencil>& depthStencil) {
if (color.size != depthStencil.size) {
throw std::runtime_error("Renderbuffer size mismatch");
}
@@ -462,7 +446,7 @@ Context::createFramebuffer(const Renderbuffer<RenderbufferType::RGBA>& color,
return { color.size, std::move(fbo) };
}
Framebuffer Context::createFramebuffer(const Renderbuffer<RenderbufferType::RGBA>& color) {
Framebuffer Context::createFramebuffer(const Renderbuffer<gfx::RenderbufferPixelType::RGBA>& color) {
auto fbo = createFramebuffer();
bindFramebuffer = fbo;
MBGL_CHECK_ERROR(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
@@ -473,7 +457,7 @@ Framebuffer Context::createFramebuffer(const Renderbuffer<RenderbufferType::RGBA
Framebuffer
Context::createFramebuffer(const gfx::Texture& color,
const Renderbuffer<RenderbufferType::DepthStencil>& depthStencil) {
const Renderbuffer<gfx::RenderbufferPixelType::DepthStencil>& depthStencil) {
if (color.size != depthStencil.size) {
throw std::runtime_error("Renderbuffer size mismatch");
}
@@ -499,7 +483,7 @@ Framebuffer Context::createFramebuffer(const gfx::Texture& color) {
Framebuffer
Context::createFramebuffer(const gfx::Texture& color,
const Renderbuffer<RenderbufferType::DepthComponent>& depthTarget) {
const Renderbuffer<gfx::RenderbufferPixelType::Depth>& depthTarget) {
if (color.size != depthTarget.size) {
throw std::runtime_error("Renderbuffer size mismatch");
}

View File

@@ -60,23 +60,23 @@ public:
#endif
optional<std::pair<BinaryProgramFormat, std::string>> getBinaryProgram(ProgramID) const;
template <RenderbufferType type>
template <gfx::RenderbufferPixelType type>
Renderbuffer<type> createRenderbuffer(const Size size) {
static_assert(type == RenderbufferType::RGBA ||
type == RenderbufferType::DepthStencil ||
type == RenderbufferType::DepthComponent,
static_assert(type == gfx::RenderbufferPixelType::RGBA ||
type == gfx::RenderbufferPixelType::DepthStencil ||
type == gfx::RenderbufferPixelType::Depth,
"invalid renderbuffer type");
return { size, createRenderbuffer(type, size) };
}
Framebuffer createFramebuffer(const Renderbuffer<RenderbufferType::RGBA>&,
const Renderbuffer<RenderbufferType::DepthStencil>&);
Framebuffer createFramebuffer(const Renderbuffer<RenderbufferType::RGBA>&);
Framebuffer createFramebuffer(const Renderbuffer<gfx::RenderbufferPixelType::RGBA>&,
const Renderbuffer<gfx::RenderbufferPixelType::DepthStencil>&);
Framebuffer createFramebuffer(const Renderbuffer<gfx::RenderbufferPixelType::RGBA>&);
Framebuffer createFramebuffer(const gfx::Texture&,
const Renderbuffer<RenderbufferType::DepthStencil>&);
const Renderbuffer<gfx::RenderbufferPixelType::DepthStencil>&);
Framebuffer createFramebuffer(const gfx::Texture&);
Framebuffer createFramebuffer(const gfx::Texture&,
const Renderbuffer<RenderbufferType::DepthComponent>&);
const Renderbuffer<gfx::RenderbufferPixelType::Depth>&);
template <typename Image,
gfx::TexturePixelType format = Image::channels == 4 ? gfx::TexturePixelType::RGBA
@@ -216,7 +216,7 @@ private:
std::unique_ptr<gfx::DrawScopeResource> createDrawScopeResource() override;
UniqueFramebuffer createFramebuffer();
UniqueRenderbuffer createRenderbuffer(RenderbufferType, Size size);
UniqueRenderbuffer createRenderbuffer(gfx::RenderbufferPixelType, Size size);
std::unique_ptr<uint8_t[]> readFramebuffer(Size, gfx::TexturePixelType, bool flip);
#if not MBGL_USE_GLES2
void drawPixels(Size size, const void* data, gfx::TexturePixelType);

View File

@@ -283,5 +283,37 @@ platform::GLenum Enum<gfx::TextureChannelDataType>::to(const gfx::TextureChannel
return GL_INVALID_ENUM;
}
template <>
gfx::RenderbufferPixelType Enum<gfx::RenderbufferPixelType>::from(const platform::GLint value) {
switch (value) {
#if not MBGL_USE_GLES2
case GL_RGBA8: return gfx::RenderbufferPixelType::RGBA;
case GL_DEPTH_COMPONENT: return gfx::RenderbufferPixelType::Depth;
case GL_DEPTH24_STENCIL8: return gfx::RenderbufferPixelType::DepthStencil;
#else
case GL_RGBA8_OES: return gfx::RenderbufferPixelType::RGBA;
case GL_DEPTH_COMPONENT16: return gfx::RenderbufferPixelType::Depth;
case GL_DEPTH24_STENCIL8_OES: return gfx::RenderbufferPixelType::DepthStencil;
#endif
}
return {};
}
template <>
platform::GLenum Enum<gfx::RenderbufferPixelType>::to(const gfx::RenderbufferPixelType value) {
switch (value) {
#if not MBGL_USE_GLES2
case gfx::RenderbufferPixelType::RGBA: return GL_RGBA8;
case gfx::RenderbufferPixelType::Depth: return GL_DEPTH_COMPONENT;
case gfx::RenderbufferPixelType::DepthStencil: return GL_DEPTH24_STENCIL8;
#else
case gfx::RenderbufferPixelType::RGBA: return GL_RGBA8_OES;
case gfx::RenderbufferPixelType::Depth: return GL_DEPTH_COMPONENT16;
case gfx::RenderbufferPixelType::DepthStencil: return GL_DEPTH24_STENCIL8_OES;
#endif
}
return GL_INVALID_ENUM;
}
} // namespace gl
} // namespace mbgl

View File

@@ -1,19 +1,20 @@
#pragma once
#include <mbgl/gfx/types.hpp>
#include <mbgl/gl/object.hpp>
#include <mbgl/util/size.hpp>
namespace mbgl {
namespace gl {
template <RenderbufferType renderbufferType>
template <gfx::RenderbufferPixelType renderbufferType>
class Renderbuffer {
public:
Renderbuffer(Size size_, UniqueRenderbuffer renderbuffer_, bool dirty_ = false)
: size(std::move(size_)), renderbuffer(std::move(renderbuffer_)), dirty(dirty_) {
}
using type = std::integral_constant<RenderbufferType, renderbufferType>;
using type = std::integral_constant<gfx::RenderbufferPixelType, renderbufferType>;
Size size;
UniqueRenderbuffer renderbuffer;

View File

@@ -30,16 +30,6 @@ enum class ShaderType : uint32_t {
Fragment = 0x8B30
};
enum class RenderbufferType : uint32_t {
RGBA = 0x8058,
DepthStencil = 0x88F0,
#if not MBGL_USE_GLES2
DepthComponent = 0x1902, // GL_DEPTH_COMPONENT
#else
DepthComponent = 0x81A5, // GL_DEPTH_COMPONENT16
#endif // MBGL_USE_GLES2
};
struct PixelStorageType {
int32_t alignment;
};

View File

@@ -32,7 +32,7 @@ public:
SegmentVector<RasterAttributes> rasterSegments;
SegmentVector<ExtrusionTextureAttributes> extrusionTextureSegments;
optional<gl::Renderbuffer<gl::RenderbufferType::DepthComponent>> depthRenderbuffer;
optional<gl::Renderbuffer<gfx::RenderbufferPixelType::Depth>> depthRenderbuffer;
bool has3D = false;
Size backendSize;

View File

@@ -400,7 +400,7 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
if (!parameters.staticData.depthRenderbuffer ||
parameters.staticData.depthRenderbuffer->size != parameters.staticData.backendSize) {
parameters.staticData.depthRenderbuffer =
glContext.createRenderbuffer<gl::RenderbufferType::DepthComponent>(parameters.staticData.backendSize);
glContext.createRenderbuffer<gfx::RenderbufferPixelType::Depth>(parameters.staticData.backendSize);
}
parameters.staticData.depthRenderbuffer->shouldClear(true);

View File

@@ -17,7 +17,7 @@ public:
}
Impl(gl::Context& context_,
const Size size_,
gl::Renderbuffer<gl::RenderbufferType::DepthComponent>& depth_,
gl::Renderbuffer<gfx::RenderbufferPixelType::Depth>& depth_,
const gfx::TextureChannelDataType type_)
: context(context_), size(std::move(size_)), depth(&depth_), type(type_) {
assert(!size.isEmpty());
@@ -58,7 +58,7 @@ private:
const Size size;
optional<gl::Framebuffer> framebuffer;
optional<gfx::Texture> texture;
gl::Renderbuffer<gl::RenderbufferType::DepthComponent>* depth = nullptr;
gl::Renderbuffer<gfx::RenderbufferPixelType::Depth>* depth = nullptr;
const gfx::TextureChannelDataType type;
};
@@ -72,7 +72,7 @@ OffscreenTexture::OffscreenTexture(gfx::Context& context,
OffscreenTexture::OffscreenTexture(gfx::Context& context,
const Size size,
gl::Renderbuffer<gl::RenderbufferType::DepthComponent>& renderbuffer,
gl::Renderbuffer<gfx::RenderbufferPixelType::Depth>& renderbuffer,
const gfx::TextureChannelDataType type)
// TODO: remove cast
: impl(std::make_unique<Impl>(reinterpret_cast<gl::Context&>(context), std::move(size), renderbuffer, type)) {

View File

@@ -18,7 +18,7 @@ public:
gfx::TextureChannelDataType type = gfx::TextureChannelDataType::UnsignedByte);
OffscreenTexture(gfx::Context&,
Size size,
gl::Renderbuffer<gl::RenderbufferType::DepthComponent>&,
gl::Renderbuffer<gfx::RenderbufferPixelType::Depth>&,
gfx::TextureChannelDataType type = gfx::TextureChannelDataType::UnsignedByte);
~OffscreenTexture();
OffscreenTexture(OffscreenTexture&&);