Photon Engine 2.0.0-beta
A physically based renderer.
|
#include <SdlNativeData.h>
Public Types | |
template<typename Func > | |
using | TElementAccessor = TFunction<Func, 32> |
using | ElementGetter = TElementAccessor<SdlGetterVariant(std::size_t elementIdx)> |
using | ElementSetter = TElementAccessor<bool(std::size_t elementIdx, SdlSetterVariant input)> |
Public Member Functions | |
SdlNativeData () | |
Creates empty native data. | |
SdlNativeData (ElementGetter getter) | |
Creates read-only native data. | |
SdlNativeData (ElementGetter getter, ElementSetter setter) | |
Creates native data with both read and write capabilities. | |
SdlNativeData (ElementGetter getter, ElementSetter setter, AnyNonConstPtr directPtr) | |
Creates native data with custom capabilities. | |
template<typename T > requires std::is_arithmetic_v<T> || std::is_enum_v<T> | |
std::optional< T > | get (std::size_t elementIdx) const |
template<typename T > requires std::is_pointer_v<T> | |
T | get (std::size_t elementIdx) const |
template<typename T > requires std::is_arithmetic_v<T> || std::is_enum_v<T> | |
bool | set (std::size_t elementIdx, T value) const |
template<typename T > requires std::is_pointer_v<T> | |
bool | set (std::size_t elementIdx, T ptr) const |
template<typename T > requires std::is_null_pointer_v<T> | |
bool | set (std::size_t elementIdx, T nullPtr) const |
template<typename T > | |
T * | directAccess () const |
Directly access the underlying data. Use of direct accessor may invalidate getter and setter accessors (should reacquire native data from source for subsequent getter/setter access). Direct accessor never invalidate itself. | |
void | setDirectAccessor (AnyNonConstPtr accessor) |
bool | isIntegerElement () const |
bool | isFloatingPointElement () const |
operator bool () const | |
Static Public Member Functions | |
template<typename ElementType > | |
static SdlNativeData | fromSingleElement (ElementType *elementPtr, ESdlDataFormat elementContainer, ESdlDataType elementType, bool canSet=false, bool canDirectAccess=false) |
Creates native data for a single element pointer. | |
template<typename ElementType > | |
static auto | permissiveElementGetter (ElementType *elementPtr) -> SdlGetterVariant |
Given a valid target element, get its value in a permissive way (with auto conversions). | |
template<typename ElementType > | |
static auto | permissiveElementSetter (SdlSetterVariant input, ElementType *out_elementPtr) -> bool |
Given a valid target element, set its value in a permissive way (with auto conversions). | |
Public Attributes | |
std::size_t | numElements = 0 |
Hint for number of elements in this block of native data. For example, numElements would be 12 for an array of 12 int s; and 24 for an array of 12 vec2 s. | |
std::size_t | tupleSize = 0 |
Hint for number of elements that form a natural group. For an array of 10 vec3 s, tupleSize may have a value of 3 to indicate that for those 30 elements in the array every 3 elements can form a group. This information is not always provided. | |
ESdlDataFormat | elementContainer = ESdlDataFormat::None |
Hint for the type that encapsulates elements. | |
ESdlDataType | elementType = ESdlDataType::None |
Hint for the type of elements. | |
uint8 | isNullClearable: 1 = false |
Whether the data can be set as empty by assigning null to it. For example, if this flag is true and the data is with a ESdlDataFormat::Single format, you can use set(0, nullptr) to clear it (and use set(0, T{}) to set it). Other formats and types follow the same principle. | |
All public fields are only hints and may not always be available. They provide additional information for the underlying data, which can help to better interpret them. Implementation ensures there is no dynamic allocation and the size of the object should be reasonably small (independent of the data it is representing). This object can be cached if only getter and setter accessors are used.
Note on the implementation of getter & setter accessors: Implementation should guarantee that any calls to getter & setter accessors will not cause the accessors to be invalid (invalidated) in any way, so an instance of SdlNativeData
can be reused many times. Use of direct accessor may invalidate getter and setter accessors. See corresponding methods for more information.
Note on getting hints for interpreting native data: If the operation done on the native data would potentially alter the underlying data structure, it is advisable to retrieve a new instance of SdlNativeData
to see the updated hint.
using ph::SdlNativeData::ElementGetter = TElementAccessor<SdlGetterVariant(std::size_t elementIdx)> |
using ph::SdlNativeData::ElementSetter = TElementAccessor<bool(std::size_t elementIdx, SdlSetterVariant input)> |
using ph::SdlNativeData::TElementAccessor = TFunction<Func, 32> |
|
inline |
Creates empty native data.
|
inlineexplicit |
Creates read-only native data.
|
inline |
Creates native data with both read and write capabilities.
|
inline |
Creates native data with custom capabilities.
|
inline |
Directly access the underlying data. Use of direct accessor may invalidate getter and setter accessors (should reacquire native data from source for subsequent getter/setter access). Direct accessor never invalidate itself.
|
inlinestatic |
Creates native data for a single element pointer.
elementPtr | Pointer to the single element. If null, all native data access will be no-op. |
canSet | If true, elementPtr will also be used for ordinary setter. |
canDirectAccess | If true, elementPtr will also be used for direct access. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlinestatic |
Given a valid target element, get its value in a permissive way (with auto conversions).
elementPtr | Pointer to the target element. Cannot be null. |
|
inlinestatic |
Given a valid target element, set its value in a permissive way (with auto conversions).
out_elementPtr | Pointer to the target element. Cannot be null. |
bool ph::SdlNativeData::set | ( | std::size_t | elementIdx, |
T | nullPtr ) const |
bool ph::SdlNativeData::set | ( | std::size_t | elementIdx, |
T | ptr ) const |
|
inline |
|
inline |
ESdlDataFormat ph::SdlNativeData::elementContainer = ESdlDataFormat::None |
Hint for the type that encapsulates elements.
ESdlDataType ph::SdlNativeData::elementType = ESdlDataType::None |
Hint for the type of elements.
uint8 ph::SdlNativeData::isNullClearable |
Whether the data can be set as empty by assigning null to it. For example, if this flag is true
and the data is with a ESdlDataFormat::Single
format, you can use set(0, nullptr)
to clear it (and use set(0, T{})
to set it). Other formats and types follow the same principle.
std::size_t ph::SdlNativeData::numElements = 0 |
Hint for number of elements in this block of native data. For example, numElements
would be 12 for an array of 12 int
s; and 24 for an array of 12 vec2
s.
std::size_t ph::SdlNativeData::tupleSize = 0 |
Hint for number of elements that form a natural group. For an array of 10 vec3
s, tupleSize
may have a value of 3 to indicate that for those 30 elements in the array every 3 elements can form a group. This information is not always provided.