Chira Engine
A customizable MIT-licensed game engine.
MaterialFactory.h
1
#pragma once
2
3
#include <functional>
4
#include <string>
5
#include <render/shader/Shader.h>
6
#include <resource/Resource.h>
7
#include <utility/AbstractFactory.h>
8
#include <utility/Serial.h>
9
10
namespace
chira {
11
12
class
IMaterial
:
public
Resource
{
13
public
:
14
explicit
IMaterial
(std::string identifier_);
15
void
compile(
const
byte
buffer[], std::size_t bufferLength)
override
;
16
virtual
void
use()
const
;
17
[[nodiscard]]
SharedPointer<Shader>
getShader()
const
;
18
19
protected
:
20
SharedPointer<Shader>
shader;
21
std::string shaderPath{
"file://shaders/unlitTextured.json"
};
22
23
public
:
24
template
<
typename
Archive>
25
void
serialize(Archive& ar) {
26
ar(
27
cereal::make_nvp(
"shader"
, this->shaderPath)
28
);
29
}
30
};
31
32
using
MaterialFactory
=
AbstractFactory<SharedPointer<IMaterial>
>;
33
34
}
// namespace chira
35
36
#define CHIRA_REGISTER_MATERIAL_TYPE(ResourceClassName) \
37
static inline const bool ResourceClassName##FactoryRegistryHelper = \
38
chira::MaterialFactory::registerTypeFactory( \
39
#ResourceClassName, \
40
[](const std::string& materialId) -> chira::SharedPointer<chira::IMaterial> { \
41
return chira::Resource::getResource<ResourceClassName>(materialId) \
42
.cast<chira::IMaterial>(); \
43
} \
44
)
45
46
#define CHIRA_GET_MATERIAL(type, identifier) \
47
chira::MaterialFactory::getTypeFactory(type)(identifier)
chira::AbstractFactory
Definition:
AbstractFactory.h:12
chira::IMaterial
Definition:
MaterialFactory.h:12
chira::Resource
A chunk of data, usually a file. Is typically cached and shared.
Definition:
Resource.h:19
chira::SharedPointer
Definition:
SharedPointer.h:31
engine
render
material
MaterialFactory.h
Generated by
1.9.1