blob: b9bf620eeab21423c8b372a3d143ab4b7ad03ac8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
|