Cogs.Core
TextureGeneratorSystem.cpp
1#include "TextureGeneratorSystem.h"
2
3#include "Foundation/Logging/Logger.h"
4
5#include "Context.h"
6
7#include "Components/Appearance/MaterialComponent.h"
8
9#include "Resources/TextureManager.h"
10#include "Resources/MaterialManager.h"
11
12#include "Services/Services.h"
13
14#include "Generators/TextureGenerator.h"
15
17{
18 auto textureGenerator = context->services->getService<TextureGenerator>();
19
20 for (const auto & component : pool) {
21 if (component.diffuseMap == ImageType::None) continue;
22
23 auto materialComponent = component.getComponent<MaterialComponent>();
24
25 auto texture = textureGenerator->getTexture(component.diffuseMap);
26
27 if (materialComponent && materialComponent->diffuseMap != texture) {
28 materialComponent->diffuseMap = texture;
29 materialComponent->setChanged();
30 } else if (component.material) {
31 auto key = component.material->material->getTextureKey("diffuseMap");
32
33 component.material->setTextureProperty(key, texture);
34 }
35 }
36}
37
void setChanged()
Sets the component to the ComponentFlags::Changed state with carry.
Definition: Component.h:202
Context * context
Pointer to the Context instance the system lives in.
void update()
Updates the system state to that of the current frame.
ComponentPool< TextureGeneratorComponent > pool
Pool of components managed by the system.
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
std::unique_ptr< class Services > services
Services.
Definition: Context.h:174
Exposes material properties for legacy entities and code.