1#include "BlueNoiseManager.h"
3#include "Resources/TextureManager.h"
5#include "Services/Random.h"
6#include "Services/Variables.h"
8#include "Foundation/Logging/Logger.h"
17 BlueNoiseManager::BlueNoiseManager(Context *context):
18 ResourceManager(context)
20 for(
auto &tmp : blueNoise) tmp = BlueNoiseHandle::NoHandle;
21 count = context->variables->get(
"renderer.blueNoiseTextures", 4);
22 assert(count <=
sizeof(blueNoise)/
sizeof(blueNoise[0]));
23 context->blueNoiseManager =
this;
25 BlueNoiseManager::~BlueNoiseManager()
27 reportLeaks(
"BlueNoise");
30 void BlueNoiseManager::initialize()
32 ResourceManager::initialize();
35 void BlueNoiseManager::handleEnable()
38 for (
size_t i = 0; i<count; i++) {
39 std::string name =
"Textures/LDR_RGBA_" + std::to_string(i) +
".png";
40 blueNoise[i] = loadBlueNoise(name.c_str(), getNextResourceId());
42 LOG_DEBUG(logger,
"Enabled blue noise manager.");
45 void BlueNoiseManager::clear()
47 for(
auto &tmp : blueNoise) tmp = BlueNoiseHandle::NoHandle;
48 ResourceManager::clear();
52 uint32_t BlueNoiseManager::RandIndex()
54 auto & random = context->random;
55 static std::uniform_int_distribution<uint32_t> dist(0, uint32_t(count)-1);
56 return dist(random->mt);
59 BlueNoiseHandle BlueNoiseManager::loadBlueNoise(
const std::string & name,
const ResourceId resourceId)
61 auto textureManager = context->textureManager;
63 BlueNoiseHandle handle = getOrCreate(resourceId);
65 auto texture = textureManager->loadTexture(name, textureManager->getNextResourceId(), TextureLoadFlags::None);
67 handle->texture = texture;
74 BlueNoiseHandle BlueNoiseManager::getBlueNoiseHandle(
bool stable) {
75 return blueNoise[stable ? 0 : RandIndex()];
Log implementation class.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
bool HandleIsValid(const ResourceHandle_t< T > &handle)
Check if the given resource is valid, that is not equal to NoHandle or InvalidHandle.
constexpr Log getLogger(const char(&name)[LEN]) noexcept