Nebula
Toggle main menu visibility
Loading...
Searching...
No Matches
materialvariant.h
Go to the documentation of this file.
1
#pragma once
2
//------------------------------------------------------------------------------
9
//------------------------------------------------------------------------------
10
#include "
coregraphics/config.h
"
11
namespace
Materials
12
{
13
14
struct
MaterialVariant
15
{
16
struct
TextureHandleTuple;
17
19
MaterialVariant
()
20
:
needsDeref
(false)
21
,
mem
(nullptr)
22
,
size
(0)
23
{};
24
26
MaterialVariant
(
const
MaterialVariant
& rhs)
27
:
needsDeref
(rhs.
needsDeref
)
28
,
mem
(rhs.
mem
)
29
,
size
(rhs.
size
)
30
{
31
}
32
34
void
operator=
(
const
MaterialVariant
& rhs)
35
{
36
this->
mem
= rhs.
mem
;
37
this->
needsDeref
= rhs.
needsDeref
;
38
this->
size
= rhs.
size
;
39
}
40
42
MaterialVariant
(
MaterialVariant
&& rhs)
43
:
needsDeref
(rhs.
needsDeref
)
44
,
mem
(rhs.
mem
)
45
,
size
(rhs.
size
)
46
{
47
rhs.mem =
nullptr
;
48
rhs.needsDeref =
false
;
49
rhs.size = 0;
50
}
51
53
void
operator=
(
MaterialVariant
&& rhs)
54
{
55
this->
mem
= rhs.mem;
56
this->
needsDeref
= rhs.needsDeref;
57
this->
size
= rhs.size;
58
59
rhs.mem =
nullptr
;
60
rhs.needsDeref =
false
;
61
rhs.size = 0;
62
}
63
65
MaterialVariant
(std::nullptr_t)
66
:
needsDeref
(false)
67
,
mem
(nullptr)
68
,
size
(0)
69
{}
70
71
bool
needsDeref
;
72
void
*
mem
;
73
SizeT
size
;
74
76
const
void
*
Get
()
const
77
{
78
// If the data is stored in a pointer, and not the pointer value it self, we need to deref the pointer
79
return
this->needsDeref ? this->mem :
reinterpret_cast<
const
void
*
>
(&this->mem);
80
}
81
83
template
<
typename
T>
const
T&
ConstGet
()
const
84
{
85
return
this->needsDeref ? *
reinterpret_cast<
T*
>
(this->mem) :
reinterpret_cast<
const
T&
>
(this->mem);
86
}
87
89
template
<
typename
T> T&
Get
()
90
{
91
return
this->needsDeref ? *
reinterpret_cast<
T*
>
(this->mem) :
reinterpret_cast<
T&
>
(this->mem);
92
}
93
95
template
<
typename
T>
void
Set
(
const
T& data,
void
*
mem
)
96
{
97
this->size =
sizeof
(T);
98
this->mem =
mem
;
99
this->needsDeref = this->size >
sizeof
(
void
*);
100
memcpy(this->needsDeref ? this->mem :
reinterpret_cast<
void
*
>
(&this->mem), &data, this->size);
101
}
102
104
template
<
typename
T>
void
Set
(
void
*
mem
)
105
{
106
this->size =
sizeof
(T);
107
this->mem =
mem
;
108
this->needsDeref =
true
;
109
}
110
};
111
112
}
// namespace Materials
Materials
Material special version of variant.
Definition
material.cc:12
config.h
Compile time configuration options for the CoreGraphics subsystem.
Materials::MaterialVariant::size
SizeT size
Definition
materialvariant.h:73
Materials::MaterialVariant::Set
void Set(const T &data, void *mem)
Set.
Definition
materialvariant.h:95
Materials::MaterialVariant::ConstGet
const T & ConstGet() const
Const get.
Definition
materialvariant.h:83
Materials::MaterialVariant::MaterialVariant
MaterialVariant()
Nullptr constructor.
Definition
materialvariant.h:19
Materials::MaterialVariant::MaterialVariant
MaterialVariant(const MaterialVariant &rhs)
Copy constructor.
Definition
materialvariant.h:26
Materials::MaterialVariant::mem
void * mem
Definition
materialvariant.h:72
Materials::MaterialVariant::operator=
void operator=(MaterialVariant &&rhs)
Move operator.
Definition
materialvariant.h:53
Materials::MaterialVariant::MaterialVariant
MaterialVariant(MaterialVariant &&rhs)
Move constructor.
Definition
materialvariant.h:42
Materials::MaterialVariant::needsDeref
bool needsDeref
Definition
materialvariant.h:71
Materials::MaterialVariant::Get
T & Get()
Mutable get.
Definition
materialvariant.h:89
Materials::MaterialVariant::operator=
void operator=(const MaterialVariant &rhs)
Assign operator.
Definition
materialvariant.h:34
Materials::MaterialVariant::Get
const void * Get() const
Get pointer.
Definition
materialvariant.h:76
Materials::MaterialVariant::Set
void Set(void *mem)
Set from raw memory.
Definition
materialvariant.h:104
Materials::MaterialVariant::MaterialVariant
MaterialVariant(std::nullptr_t)
Nullptr constructor.
Definition
materialvariant.h:65
SizeT
int SizeT
Definition
types.h:42
code
render
materials
materialvariant.h
Generated on
for Nebula. Dark theme by
Tilen Majerle
. All rights reserved.