summaryrefslogtreecommitdiff
path: root/src/mbgl/gl
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2019-03-06 17:27:00 +0100
committerKonstantin Käfer <mail@kkaefer.com>2019-03-12 11:03:54 +0100
commit2a25270298f358f815b22c87ece74fd3f37a42b5 (patch)
tree37e8e3c08f2531c98c962aba6fdb227ed6212e2c /src/mbgl/gl
parent60ceac5efc3d77199f773f08400fe1d53d5a1b90 (diff)
downloadqtlocation-mapboxgl-2a25270298f358f815b22c87ece74fd3f37a42b5.tar.gz
[core] move Texture related enums to gfx namespace
Diffstat (limited to 'src/mbgl/gl')
-rw-r--r--src/mbgl/gl/context.cpp74
-rw-r--r--src/mbgl/gl/context.hpp36
-rw-r--r--src/mbgl/gl/defines.hpp10
-rw-r--r--src/mbgl/gl/enum.cpp42
-rw-r--r--src/mbgl/gl/texture.hpp17
-rw-r--r--src/mbgl/gl/types.hpp21
6 files changed, 111 insertions, 89 deletions
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp
index df304eb7d4..c8236e0b0a 100644
--- a/src/mbgl/gl/context.cpp
+++ b/src/mbgl/gl/context.cpp
@@ -43,20 +43,6 @@ static_assert(std::is_same<VertexArrayID, GLuint>::value, "OpenGL type mismatch"
static_assert(std::is_same<FramebufferID, GLuint>::value, "OpenGL type mismatch");
static_assert(std::is_same<RenderbufferID, GLuint>::value, "OpenGL type mismatch");
-static_assert(std::is_same<std::underlying_type_t<TextureFormat>, GLenum>::value, "OpenGL type mismatch");
-static_assert(underlying_type(TextureFormat::RGBA) == GL_RGBA, "OpenGL type mismatch");
-static_assert(underlying_type(TextureFormat::Alpha) == GL_ALPHA, "OpenGL type mismatch");
-
-static_assert(std::is_same<std::underlying_type_t<TextureType>, GLenum>::value, "OpenGL type mismatch");
-static_assert(underlying_type(TextureType::UnsignedByte) == GL_UNSIGNED_BYTE, "OpenGL type mismatch");
-
-#if MBGL_USE_GLES2 && GL_HALF_FLOAT_OES
-static_assert(underlying_type(TextureType::HalfFloat) == GL_HALF_FLOAT_OES, "OpenGL type mismatch");
-#endif
-#if !MBGL_USE_GLES2 && GL_HALF_FLOAT_ARB
-static_assert(underlying_type(TextureType::HalfFloat) == GL_HALF_FLOAT_ARB, "OpenGL type mismatch");
-#endif
-
static_assert(underlying_type(UniformDataType::Float) == GL_FLOAT, "OpenGL type mismatch");
static_assert(underlying_type(UniformDataType::FloatVec2) == GL_FLOAT_VEC2, "OpenGL type mismatch");
static_assert(underlying_type(UniformDataType::FloatVec3) == GL_FLOAT_VEC3, "OpenGL type mismatch");
@@ -374,16 +360,17 @@ UniqueRenderbuffer Context::createRenderbuffer(const RenderbufferType type, cons
return renderbuffer;
}
-std::unique_ptr<uint8_t[]> Context::readFramebuffer(const Size size, const TextureFormat format, const bool flip) {
- const size_t stride = size.width * (format == TextureFormat::RGBA ? 4 : 1);
+std::unique_ptr<uint8_t[]> Context::readFramebuffer(const Size size, const gfx::TexturePixelType format, const bool flip) {
+ const size_t stride = size.width * (format == gfx::TexturePixelType::RGBA ? 4 : 1);
auto data = std::make_unique<uint8_t[]>(stride * size.height);
// When reading data from the framebuffer, make sure that we are storing the values
// tightly packed into the buffer to avoid buffer overruns.
pixelStorePack = { 1 };
- MBGL_CHECK_ERROR(glReadPixels(0, 0, size.width, size.height, static_cast<GLenum>(format),
- GL_UNSIGNED_BYTE, data.get()));
+ MBGL_CHECK_ERROR(glReadPixels(0, 0, size.width, size.height,
+ Enum<gfx::TexturePixelType>::to(format), GL_UNSIGNED_BYTE,
+ data.get()));
if (flip) {
auto tmp = std::make_unique<uint8_t[]>(stride);
@@ -399,12 +386,13 @@ std::unique_ptr<uint8_t[]> Context::readFramebuffer(const Size size, const Textu
}
#if not MBGL_USE_GLES2
-void Context::drawPixels(const Size size, const void* data, TextureFormat format) {
+void Context::drawPixels(const Size size, const void* data, gfx::TexturePixelType format) {
pixelStoreUnpack = { 1 };
- if (format != TextureFormat::RGBA) {
- format = static_cast<TextureFormat>(GL_LUMINANCE);
+ // TODO
+ if (format != gfx::TexturePixelType::RGBA) {
+ format = gfx::TexturePixelType::Luminance;
}
- MBGL_CHECK_ERROR(glDrawPixels(size.width, size.height, static_cast<GLenum>(format),
+ MBGL_CHECK_ERROR(glDrawPixels(size.width, size.height, Enum<gfx::TexturePixelType>::to(format),
GL_UNSIGNED_BYTE, data));
}
#endif // MBGL_USE_GLES2
@@ -517,8 +505,11 @@ Context::createFramebuffer(const Texture& color,
return { depthTarget.size, std::move(fbo) };
}
-UniqueTexture
-Context::createTexture(const Size size, const void* data, TextureFormat format, TextureUnit unit, TextureType type) {
+UniqueTexture Context::createTexture(const Size size,
+ const void* data,
+ gfx::TexturePixelType format,
+ TextureUnit unit,
+ gfx::TextureChannelDataType type) {
auto obj = createTexture();
pixelStoreUnpack = { 1 };
updateTexture(obj, size, data, format, unit, type);
@@ -531,21 +522,26 @@ Context::createTexture(const Size size, const void* data, TextureFormat format,
return obj;
}
-void Context::updateTexture(
- TextureID id, const Size size, const void* data, TextureFormat format, TextureUnit unit, TextureType type) {
+void Context::updateTexture(TextureID id,
+ const Size size,
+ const void* data,
+ gfx::TexturePixelType format,
+ TextureUnit unit,
+ gfx::TextureChannelDataType type) {
activeTextureUnit = unit;
texture[unit] = id;
- MBGL_CHECK_ERROR(glTexImage2D(GL_TEXTURE_2D, 0, static_cast<GLenum>(format), size.width,
- size.height, 0, static_cast<GLenum>(format), static_cast<GLenum>(type),
- data));
+ 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,
- TextureFilter filter,
- TextureMipMap mipmap,
- TextureWrap wrapX,
- TextureWrap wrapY) {
+ gfx::TextureFilterType filter,
+ gfx::TextureMipMapType mipmap,
+ gfx::TextureWrapType wrapX,
+ gfx::TextureWrapType wrapY) {
if (filter != obj.filter || mipmap != obj.mipmap || wrapX != obj.wrapX || wrapY != obj.wrapY) {
activeTextureUnit = unit;
texture[unit] = obj.texture;
@@ -553,12 +549,12 @@ void Context::bindTexture(Texture& obj,
if (filter != obj.filter || mipmap != obj.mipmap) {
MBGL_CHECK_ERROR(glTexParameteri(
GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
- filter == TextureFilter::Linear
- ? (mipmap == TextureMipMap::Yes ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR)
- : (mipmap == TextureMipMap::Yes ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST)));
+ filter == gfx::TextureFilterType::Linear
+ ? (mipmap == gfx::TextureMipMapType::Yes ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR)
+ : (mipmap == gfx::TextureMipMapType::Yes ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST)));
MBGL_CHECK_ERROR(
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
- filter == TextureFilter::Linear ? GL_LINEAR : GL_NEAREST));
+ filter == gfx::TextureFilterType::Linear ? GL_LINEAR : GL_NEAREST));
obj.filter = filter;
obj.mipmap = mipmap;
}
@@ -566,13 +562,13 @@ void Context::bindTexture(Texture& obj,
MBGL_CHECK_ERROR(
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
- wrapX == TextureWrap::Clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT));
+ wrapX == gfx::TextureWrapType::Clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT));
obj.wrapX = wrapX;
}
if (wrapY != obj.wrapY) {
MBGL_CHECK_ERROR(
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
- wrapY == TextureWrap::Clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT));
+ wrapY == gfx::TextureWrapType::Clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT));
obj.wrapY = wrapY;
}
} else if (texture[unit] != obj.texture) {
diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp
index 70ba1ec107..8b7b9346b3 100644
--- a/src/mbgl/gl/context.hpp
+++ b/src/mbgl/gl/context.hpp
@@ -81,10 +81,10 @@ public:
const Renderbuffer<RenderbufferType::DepthComponent>&);
template <typename Image,
- TextureFormat format = Image::channels == 4 ? TextureFormat::RGBA
- : TextureFormat::Alpha>
+ gfx::TexturePixelType format = Image::channels == 4 ? gfx::TexturePixelType::RGBA
+ : gfx::TexturePixelType::Alpha>
Image readFramebuffer(const Size size, bool flip = true) {
- static_assert(Image::channels == (format == TextureFormat::RGBA ? 4 : 1),
+ static_assert(Image::channels == (format == gfx::TexturePixelType::RGBA ? 4 : 1),
"image format mismatch");
return { size, readFramebuffer(size, format, flip) };
}
@@ -92,7 +92,7 @@ public:
#if not MBGL_USE_GLES2
template <typename Image>
void drawPixels(const Image& image) {
- auto format = image.channels == 4 ? TextureFormat::RGBA : TextureFormat::Alpha;
+ auto format = image.channels == 4 ? gfx::TexturePixelType::RGBA : gfx::TexturePixelType::Alpha;
drawPixels(image.size, image.data.get(), format);
}
#endif // MBGL_USE_GLES2
@@ -101,8 +101,8 @@ public:
template <typename Image>
Texture createTexture(const Image& image,
TextureUnit unit = 0,
- TextureType type = TextureType::UnsignedByte) {
- auto format = image.channels == 4 ? TextureFormat::RGBA : TextureFormat::Alpha;
+ 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) };
}
@@ -110,26 +110,26 @@ public:
void updateTexture(Texture& obj,
const Image& image,
TextureUnit unit = 0,
- TextureType type = TextureType::UnsignedByte) {
- auto format = image.channels == 4 ? TextureFormat::RGBA : TextureFormat::Alpha;
+ 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,
- TextureFormat format = TextureFormat::RGBA,
+ gfx::TexturePixelType format = gfx::TexturePixelType::RGBA,
TextureUnit unit = 0,
- TextureType type = TextureType::UnsignedByte) {
+ gfx::TextureChannelDataType type = gfx::TextureChannelDataType::UnsignedByte) {
return { size, createTexture(size, nullptr, format, unit, type) };
}
void bindTexture(Texture&,
TextureUnit = 0,
- TextureFilter = TextureFilter::Nearest,
- TextureMipMap = TextureMipMap::No,
- TextureWrap wrapX = TextureWrap::Clamp,
- TextureWrap wrapY = TextureWrap::Clamp);
+ 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,
@@ -248,13 +248,13 @@ 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, TextureFormat, TextureUnit, TextureType);
- void updateTexture(TextureID, Size size, const void* data, TextureFormat, TextureUnit, TextureType);
+ 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);
UniqueFramebuffer createFramebuffer();
UniqueRenderbuffer createRenderbuffer(RenderbufferType, Size size);
- std::unique_ptr<uint8_t[]> readFramebuffer(Size, TextureFormat, bool flip);
+ std::unique_ptr<uint8_t[]> readFramebuffer(Size, gfx::TexturePixelType, bool flip);
#if not MBGL_USE_GLES2
- void drawPixels(Size size, const void* data, TextureFormat);
+ void drawPixels(Size size, const void* data, gfx::TexturePixelType);
#endif // MBGL_USE_GLES2
bool supportsVertexArrays() const;
diff --git a/src/mbgl/gl/defines.hpp b/src/mbgl/gl/defines.hpp
index 41c4cb07d6..75325dfb75 100644
--- a/src/mbgl/gl/defines.hpp
+++ b/src/mbgl/gl/defines.hpp
@@ -39,6 +39,7 @@
#define GL_DEPTH_ATTACHMENT 0x8D00
#define GL_DEPTH_BUFFER_BIT 0x00000100
#define GL_DEPTH_CLEAR_VALUE 0x0B73
+#define GL_DEPTH_COMPONENT 0x1902
#define GL_DEPTH_COMPONENT16 0x81A5
#define GL_DEPTH_FUNC 0x0B74
#define GL_DEPTH_RANGE 0x0B70
@@ -97,6 +98,7 @@
#define GL_LINE_STRIP 0x0003
#define GL_LINE_WIDTH 0x0B21
#define GL_LINK_STATUS 0x8B82
+#define GL_LUMINANCE 0x1909
#define GL_MAX_VERTEX_ATTRIBS 0x8869
#define GL_NEAREST 0x2600
#define GL_NEAREST_MIPMAP_NEAREST 0x2700
@@ -133,6 +135,7 @@
#define GL_STENCIL_CLEAR_VALUE 0x0B91
#define GL_STENCIL_FAIL 0x0B94
#define GL_STENCIL_FUNC 0x0B92
+#define GL_STENCIL_INDEX 0x1901
#define GL_STENCIL_PASS_DEPTH_FAIL 0x0B95
#define GL_STENCIL_PASS_DEPTH_PASS 0x0B96
#define GL_STENCIL_REF 0x0B97
@@ -159,15 +162,16 @@
#define GL_VIEWPORT 0x0BA2
#define GL_ZERO 0
-#ifndef MBGL_USE_GLES2
+#ifdef MBGL_USE_GLES2
+#define GL_HALF_FLOAT 0x8D61
+#else
#define GL_CURRENT_RASTER_POSITION 0x0B07
#define GL_DEPTH24_STENCIL8 0x88F0
#define GL_DEPTH_BIAS 0x0D1F
-#define GL_DEPTH_COMPONENT 0x1902
#define GL_DEPTH_SCALE 0x0D1E
+#define GL_HALF_FLOAT 0x140B
#define GL_INDEX_OFFSET 0x0D13
#define GL_INDEX_SHIFT 0x0D12
-#define GL_LUMINANCE 0x1909
#define GL_POINT_SIZE 0x0B11
#define GL_RGBA8 0x8058
#define GL_ZOOM_X 0x0D16
diff --git a/src/mbgl/gl/enum.cpp b/src/mbgl/gl/enum.cpp
index 81561360e9..c1a51944de 100644
--- a/src/mbgl/gl/enum.cpp
+++ b/src/mbgl/gl/enum.cpp
@@ -241,5 +241,47 @@ platform::GLenum Enum<gfx::BufferUsageType>::to(const gfx::BufferUsageType value
return GL_INVALID_ENUM;
}
+template <>
+gfx::TexturePixelType Enum<gfx::TexturePixelType>::from(const platform::GLint value) {
+ switch (value) {
+ case GL_RGBA: return gfx::TexturePixelType::RGBA;
+ case GL_ALPHA: return gfx::TexturePixelType::Alpha;
+ case GL_STENCIL_INDEX: return gfx::TexturePixelType::Stencil;
+ case GL_DEPTH_COMPONENT: return gfx::TexturePixelType::Depth;
+ case GL_LUMINANCE: return gfx::TexturePixelType::Luminance;
+ }
+ return {};
+}
+
+template <>
+platform::GLenum Enum<gfx::TexturePixelType>::to(const gfx::TexturePixelType value) {
+ switch (value) {
+ case gfx::TexturePixelType::RGBA: return GL_RGBA;
+ case gfx::TexturePixelType::Alpha: return GL_ALPHA;
+ case gfx::TexturePixelType::Stencil: return GL_STENCIL_INDEX;
+ case gfx::TexturePixelType::Depth: return GL_DEPTH_COMPONENT;
+ case gfx::TexturePixelType::Luminance: return GL_LUMINANCE;
+ }
+ return GL_INVALID_ENUM;
+}
+
+template <>
+gfx::TextureChannelDataType Enum<gfx::TextureChannelDataType>::from(const platform::GLint value) {
+ switch (value) {
+ case GL_UNSIGNED_BYTE: return gfx::TextureChannelDataType::UnsignedByte;
+ case GL_HALF_FLOAT: return gfx::TextureChannelDataType::HalfFloat;
+ }
+ return {};
+}
+
+template <>
+platform::GLenum Enum<gfx::TextureChannelDataType>::to(const gfx::TextureChannelDataType value) {
+ switch (value) {
+ case gfx::TextureChannelDataType::UnsignedByte: return GL_UNSIGNED_BYTE;
+ case gfx::TextureChannelDataType::HalfFloat: return GL_HALF_FLOAT;
+ }
+ return GL_INVALID_ENUM;
+}
+
} // namespace gl
} // namespace mbgl
diff --git a/src/mbgl/gl/texture.hpp b/src/mbgl/gl/texture.hpp
index 625e69233a..1b85ac6ebc 100644
--- a/src/mbgl/gl/texture.hpp
+++ b/src/mbgl/gl/texture.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <mbgl/gfx/types.hpp>
#include <mbgl/gl/object.hpp>
#include <mbgl/util/size.hpp>
@@ -9,10 +10,10 @@ namespace gl {
class Texture {
public:
Texture(Size size_, UniqueTexture texture_,
- TextureFilter filter_ = TextureFilter::Nearest,
- TextureMipMap mipmap_ = TextureMipMap::No,
- TextureWrap wrapX_ = TextureWrap::Clamp,
- TextureWrap wrapY_ = TextureWrap::Clamp)
+ 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_),
@@ -22,10 +23,10 @@ public:
Size size;
UniqueTexture texture;
- TextureFilter filter;
- TextureMipMap mipmap;
- TextureWrap wrapX;
- TextureWrap wrapY;
+ gfx::TextureFilterType filter;
+ gfx::TextureMipMapType mipmap;
+ gfx::TextureWrapType wrapX;
+ gfx::TextureWrapType wrapY;
};
} // namespace gl
diff --git a/src/mbgl/gl/types.hpp b/src/mbgl/gl/types.hpp
index 310960b970..ab6b72656b 100644
--- a/src/mbgl/gl/types.hpp
+++ b/src/mbgl/gl/types.hpp
@@ -42,27 +42,6 @@ enum class RenderbufferType : uint32_t {
#endif // MBGL_USE_GLES2
};
-enum class TextureMipMap : bool { No = false, Yes = true };
-enum class TextureFilter : bool { Nearest = false, Linear = true };
-enum class TextureWrap : bool { Clamp, Repeat };
-enum class TextureFormat : uint32_t {
- RGBA = 0x1908,
- Alpha = 0x1906,
-#if not MBGL_USE_GLES2
- Stencil = 0x1901,
- Depth = 0x1902,
-#endif // MBGL_USE_GLES2
-};
-
-enum class TextureType : uint32_t {
- UnsignedByte = 0x1401,
-#if MBGL_USE_GLES2
- HalfFloat = 0x8D61,
-#else
- HalfFloat = 0x140B,
-#endif // MBGL_USE_GLES2
-};
-
struct PixelStorageType {
int32_t alignment;
};