Cogs.Core
ColorRasterSource.cpp
1#include "ColorRasterSource.h"
2
3#include "Foundation/Logging/Logger.h"
4
5namespace {
6 Cogs::Logging::Log logger = Cogs::Logging::getLogger("FloatRasterSource");
7}
8
9Cogs::Core::TerrainProvider::ColorRasterSource::~ColorRasterSource()
10{
11
12}
13
14bool Cogs::Core::TerrainProvider::ColorRasterSource::init(const ColorConfig& conf, std::unique_ptr<ICache>&& icache)
15{
16 colors = conf.colors;
17 if (colors.size() == 0) {
18 LOG_ERROR(logger, "No colors defined");
19 return false;
20 }
21
22 BaseConfig base = conf;
23 if (base.textureFormat == Cogs::TextureFormat::Unknown) {
24 base.textureFormat = Cogs::TextureFormat::R8G8B8A8_UNORM_SRGB;
25 }
26 else if (base.textureFormat != Cogs::TextureFormat::R8G8B8A8_UNORM_SRGB && base.textureFormat != Cogs::TextureFormat::R8G8B8A8_UNORM) {
27 LOG_ERROR(logger, "Illegal texture format");
28 return false;
29 }
30 return BaseRasterSource::init(base, std::move(icache));
31}
32
33void Cogs::Core::TerrainProvider::ColorRasterSource::getConfig(ColorConfig& conf) const
34{
35 BaseRasterSource::getConfig(conf);
36 conf.colors = colors;
37}
38
39void Cogs::Core::TerrainProvider::ColorRasterSource::requestTile(Request* req)
40{
41 size_t N = size_t(tiling.width) * size_t(tiling.height);
42 Cogs::Memory::MemoryBuffer contents(N * sizeof(uint32_t));
43
44 assert(colors.size() != 0);
45 //assert(req->id.level == 0);
46 auto l = std::min(size_t(req->id.level), colors.size() - 1);
47 uint8_t color[4] = {
48 uint8_t(255.0 * colors[l].r),
49 uint8_t(255.0 * colors[l].g),
50 uint8_t(255.0 * colors[l].b),
51 uint8_t(255.0 * colors[l].a)
52 };
53 auto* ptr = static_cast<uint8_t*>(contents.data());
54 for (size_t i = 0; i < N; i++) {
55 for (size_t k = 0; k < 4; k++) {
56 ptr[4 * i + k] = color[k];
57 }
58 }
59 addTile(contents, MimeType::RGBA8, req, StringView());
60}
Log implementation class.
Definition: LogManager.h:139
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Definition: LogManager.h:180