Add flags to ResourceFormat to replace bgraOrder/srgbCorrected

* Allows for future expansion as well
This commit is contained in:
baldurk
2018-12-11 19:57:20 +00:00
parent 2db56c2a86
commit 2411ce70ea
25 changed files with 192 additions and 152 deletions
+53 -13
View File
@@ -133,15 +133,14 @@ struct ResourceFormat
compCount = compByteWidth = 0;
compType = CompType::Typeless;
bgraOrder = false;
srgbCorrected = false;
flags = 0;
}
ResourceFormat(const ResourceFormat &) = default;
bool operator==(const ResourceFormat &r) const
{
return type == r.type && compCount == r.compCount && compByteWidth == r.compByteWidth &&
compType == r.compType && bgraOrder == r.bgraOrder && srgbCorrected == r.srgbCorrected;
compType == r.compType && flags == r.flags;
}
bool operator<(const ResourceFormat &r) const
{
@@ -153,10 +152,8 @@ struct ResourceFormat
return compByteWidth < r.compByteWidth;
if(compType != r.compType)
return compType < r.compType;
if(bgraOrder != r.bgraOrder)
return bgraOrder < r.bgraOrder;
if(srgbCorrected != r.srgbCorrected)
return srgbCorrected < r.srgbCorrected;
if(flags != r.flags)
return flags < r.flags;
return false;
}
@@ -172,12 +169,45 @@ struct ResourceFormat
}
DOCUMENT(R"(:return: ``True`` if the ``ResourceFormat`` is a 'special' non-regular type.
:type: ``bool``
:rtype: ``bool``
)");
bool Special() const { return type != ResourceFormatType::Regular; }
DOCUMENT(R"(The :class:`ResourceFormatType` of this format. If the value is not
:attr:`ResourceFormatType.Regular` then it's a non-uniform layout like block-compressed.
)");
DOCUMENT(R"(:return: ``True`` if the components are to be read in ``BGRA`` order.
:rtype: ``bool``
)");
bool bgraOrder() const { return (flags & ResourceFormat_BGRA) != 0; }
DOCUMENT(R"(:return: ``True`` if the components are SRGB corrected on read and write.
:rtype: ``bool``
)");
bool srgbCorrected() const { return (flags & ResourceFormat_SRGB) != 0; }
DOCUMENT(R"(Set BGRA order flag. See :meth:`bgraOrder`.
:param bool flag: The new flag value.
)");
void setBgraOrder(bool flag)
{
if(flag)
flags |= ResourceFormat_BGRA;
else
flags &= ~ResourceFormat_BGRA;
}
DOCUMENT(R"(Set SRGB correction flag. See :meth:`srgbCorrected`.
:param bool flag: The new flag value.
)");
void setSrgbCorrected(bool flag)
{
if(flag)
flags |= ResourceFormat_SRGB;
else
flags &= ~ResourceFormat_SRGB;
}
ResourceFormatType type;
DOCUMENT("The :class:`type <CompType>` of each component.");
@@ -187,10 +217,17 @@ struct ResourceFormat
DOCUMENT("The width in bytes of each component.");
uint8_t compByteWidth;
DOCUMENT("``True`` if the components are to be read in ``BGRA`` order.");
bool bgraOrder;
DOCUMENT("``True`` if the components are SRGB corrected on read and write.");
bool srgbCorrected;
private:
enum
{
ResourceFormat_BGRA = 0x001,
ResourceFormat_SRGB = 0x002,
};
uint16_t flags;
// make DoSerialise a friend so it can serialise flags
template <typename SerialiserType>
friend void DoSerialise(SerialiserType &ser, ResourceFormat &el);
};
DECLARE_REFLECTION_STRUCT(ResourceFormat);
@@ -277,7 +314,10 @@ typically it is one parent to many derived.
)");
rdcarray<ResourceId> parentResources;
DOCUMENT("Utility function for setting up a custom name to overwrite the auto-generated one.");
DOCUMENT(R"(Utility function for setting up a custom name to overwrite the auto-generated one.
:param str givenName: The custom name to use.
)");
inline void SetCustomName(const rdcstr &givenName)
{
autogeneratedName = false;
+1 -1
View File
@@ -821,7 +821,7 @@ rdcarray<VertexInputAttribute> PipeState::GetVertexInputs() const
ret[a].format.compCount = (uint8_t)compCount;
ret[a].format.compType = compType;
ret[a].format.type = ResourceFormatType::Regular;
ret[a].format.srgbCorrected = false;
ret[a].format.setSrgbCorrected(false);
}
}