-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMaterialInstance.h
64 lines (47 loc) · 1.85 KB
/
MaterialInstance.h
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once
#include <filament/Material.h>
#include <filament/MaterialInstance.h>
#include <memory>
#include <spatial/graphics/Resources.h>
#include <unordered_map>
namespace spatial::graphics
{
class MaterialInstance
{
public:
using MaterialInstanceResource = EngineResource<filament::MaterialInstance>;
MaterialInstance(filament::Engine& engine, SharedMaterial material, filament::MaterialInstance* materialInstance);
~MaterialInstance();
MaterialInstance(MaterialInstance&& other) noexcept;
MaterialInstance& operator=(MaterialInstance&& other) noexcept;
MaterialInstance(const MaterialInstance& other) = delete;
MaterialInstance& operator=(const MaterialInstance& other) = delete;
const SharedMaterial& getMaterial() const
{
return mMaterial;
}
const filament::MaterialInstance* getInstance() const noexcept
{
return mInstance.get();
}
void setScissor(uint32_t left, uint32_t bottom, uint32_t width, uint32_t height);
void setParameter(std::string_view parameter, bool value);
void setParameter(std::string_view parameter, float value);
void setParameter(std::string_view parameter, math::vec2 value);
void setParameter(std::string_view parameter, math::vec3 value);
void setParameter(std::string_view parameter, math::vec4 value);
void setParameter(std::string_view parameter, filament::Texture* texture, filament::TextureSampler sampler);
private:
filament::Engine& mEngine;
SharedMaterial mMaterial;
MaterialInstanceResource mInstance;
filament::MaterialInstance* get() noexcept
{
return mInstance.get();
}
};
using SharedMaterialInstance = std::shared_ptr<graphics::MaterialInstance>;
SharedMaterialInstance toShared(MaterialInstance&& materialInstance);
MaterialInstance createMaterialInstance(filament::Engine& engine, const SharedMaterial& material,
std::string_view = {}) noexcept;
} // namespace spatial::graphics