summaryrefslogtreecommitdiff
path: root/src/mbgl/gl/texture_resource.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/gl/texture_resource.cpp')
-rw-r--r--src/mbgl/gl/texture_resource.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/mbgl/gl/texture_resource.cpp b/src/mbgl/gl/texture_resource.cpp
new file mode 100644
index 0000000000..b9bf620eea
--- /dev/null
+++ b/src/mbgl/gl/texture_resource.cpp
@@ -0,0 +1,45 @@
+#include <mbgl/gl/context.hpp>
+#include <mbgl/gl/texture_resource.hpp>
+
+namespace mbgl {
+namespace gl {
+
+static int channelCount(gfx::TexturePixelType format) {
+ switch (format) {
+ case gfx::TexturePixelType::Alpha:
+ case gfx::TexturePixelType::Depth:
+ case gfx::TexturePixelType::Luminance:
+ case gfx::TexturePixelType::Stencil:
+ return 1;
+ case gfx::TexturePixelType::RGBA:
+ return 4;
+ default:
+ assert(!"Unknown texture pixel type");
+ return 0;
+ }
+}
+
+static int channelStorageSize(gfx::TextureChannelDataType type) {
+ switch (type) {
+ case gfx::TextureChannelDataType::HalfFloat:
+ return 2;
+ case gfx::TextureChannelDataType::UnsignedByte:
+ return 1;
+ default:
+ assert(!"Unknown texture channel data type");
+ return 0;
+ }
+}
+
+TextureResource::~TextureResource() {
+ auto& stats = texture.get_deleter().context->renderingStats();
+ stats.memTextures -= byteSize;
+ assert(stats.memTextures >= 0);
+}
+
+int TextureResource::getStorageSize(const Size& size, gfx::TexturePixelType format, gfx::TextureChannelDataType type) {
+ return size.width * size.height * channelCount(format) * channelStorageSize(type);
+}
+
+} // namespace gl
+} // namespace mbgl \ No newline at end of file