summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/src/vertexdecl.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/src/vertexdecl.cpp')
-rw-r--r--3rdparty/bgfx/src/vertexdecl.cpp127
1 files changed, 99 insertions, 28 deletions
diff --git a/3rdparty/bgfx/src/vertexdecl.cpp b/3rdparty/bgfx/src/vertexdecl.cpp
index 83435fa8cf2..470cb56755a 100644
--- a/3rdparty/bgfx/src/vertexdecl.cpp
+++ b/3rdparty/bgfx/src/vertexdecl.cpp
@@ -17,26 +17,29 @@ namespace bgfx
{
static const uint8_t s_attribTypeSizeDx9[AttribType::Count][4] =
{
- { 4, 4, 4, 4 },
- { 4, 4, 8, 8 },
- { 4, 4, 8, 8 },
- { 4, 8, 12, 16 },
+ { 4, 4, 4, 4 }, // Uint8
+ { 4, 4, 4, 4 }, // Uint10
+ { 4, 4, 8, 8 }, // Int16
+ { 4, 4, 8, 8 }, // Half
+ { 4, 8, 12, 16 }, // Float
};
static const uint8_t s_attribTypeSizeDx1x[AttribType::Count][4] =
{
- { 1, 2, 4, 4 },
- { 2, 4, 8, 8 },
- { 2, 4, 8, 8 },
- { 4, 8, 12, 16 },
+ { 1, 2, 4, 4 }, // Uint8
+ { 4, 4, 4, 4 }, // Uint10
+ { 2, 4, 8, 8 }, // Int16
+ { 2, 4, 8, 8 }, // Half
+ { 4, 8, 12, 16 }, // Float
};
static const uint8_t s_attribTypeSizeGl[AttribType::Count][4] =
{
- { 1, 2, 4, 4 },
- { 2, 4, 6, 8 },
- { 2, 4, 6, 8 },
- { 4, 8, 12, 16 },
+ { 1, 2, 4, 4 }, // Uint8
+ { 4, 4, 4, 4 }, // Uint10
+ { 2, 4, 6, 8 }, // Int16
+ { 2, 4, 6, 8 }, // Half
+ { 4, 8, 12, 16 }, // Float
};
static const uint8_t (*s_attribTypeSize[])[AttribType::Count][4] =
@@ -45,6 +48,7 @@ namespace bgfx
&s_attribTypeSizeDx9, // Direct3D9
&s_attribTypeSizeDx1x, // Direct3D11
&s_attribTypeSizeDx1x, // Direct3D12
+ &s_attribTypeSizeGl, // Metal
&s_attribTypeSizeGl, // OpenGLES
&s_attribTypeSizeGl, // OpenGL
&s_attribTypeSizeGl, // Vulkan
@@ -107,10 +111,10 @@ namespace bgfx
VertexDecl& VertexDecl::add(Attrib::Enum _attrib, uint8_t _num, AttribType::Enum _type, bool _normalized, bool _asInt)
{
- const uint8_t encodedNorm = (_normalized&1)<<6;
- const uint8_t encodedType = (_type&3)<<3;
- const uint8_t encodedNum = (_num-1)&3;
- const uint8_t encodeAsInt = (_asInt&(!!"\x1\x1\x0\x0"[_type]) )<<7;
+ const uint16_t encodedNorm = (_normalized&1)<<7;
+ const uint16_t encodedType = (_type&7)<<3;
+ const uint16_t encodedNum = (_num-1)&3;
+ const uint16_t encodeAsInt = (_asInt&(!!"\x1\x1\x1\x0\x0"[_type]) )<<8;
m_attributes[_attrib] = encodedNorm|encodedType|encodedNum|encodeAsInt;
m_offset[_attrib] = m_stride;
@@ -128,11 +132,11 @@ namespace bgfx
void VertexDecl::decode(Attrib::Enum _attrib, uint8_t& _num, AttribType::Enum& _type, bool& _normalized, bool& _asInt) const
{
- uint8_t val = m_attributes[_attrib];
+ uint16_t val = m_attributes[_attrib];
_num = (val&3)+1;
- _type = AttribType::Enum((val>>3)&3);
- _normalized = !!(val&(1<<6) );
- _asInt = !!(val&(1<<7) );
+ _type = AttribType::Enum( (val>>3)&7);
+ _normalized = !!(val&(1<<7) );
+ _asInt = !!(val&(1<<8) );
}
static const char* s_attrName[] =
@@ -173,7 +177,7 @@ namespace bgfx
for (uint32_t attr = 0; attr < Attrib::Count; ++attr)
{
- if (0xff != _decl.m_attributes[attr])
+ if (UINT16_MAX != _decl.m_attributes[attr])
{
uint8_t num;
AttribType::Enum type;
@@ -255,10 +259,11 @@ namespace bgfx
// AttribType must be in order how it appears in AttribType::Enum!
// id is unique and should not be changed if new AttribTypes are
// added.
- { AttribType::Uint8, 0x0001 },
- { AttribType::Int16, 0x0002 },
- { AttribType::Half, 0x0003 },
- { AttribType::Float, 0x0004 },
+ { AttribType::Uint8, 0x0001 },
+ { AttribType::Uint10, 0x0005 },
+ { AttribType::Int16, 0x0002 },
+ { AttribType::Half, 0x0003 },
+ { AttribType::Float, 0x0004 },
};
BX_STATIC_ASSERT(BX_COUNTOF(s_attribTypeToId) == AttribType::Count);
@@ -287,7 +292,7 @@ namespace bgfx
for (uint32_t attr = 0; attr < Attrib::Count; ++attr)
{
- numAttrs += 0xff == _decl.m_attributes[attr] ? 0 : 1;
+ numAttrs += UINT16_MAX == _decl.m_attributes[attr] ? 0 : 1;
}
total += bx::write(_writer, numAttrs);
@@ -295,7 +300,7 @@ namespace bgfx
for (uint32_t attr = 0; attr < Attrib::Count; ++attr)
{
- if (0xff != _decl.m_attributes[attr])
+ if (UINT16_MAX != _decl.m_attributes[attr])
{
uint8_t num;
AttribType::Enum type;
@@ -348,7 +353,7 @@ namespace bgfx
Attrib::Enum attr = idToAttrib(attribId);
AttribType::Enum type = idToAttribType(attribTypeId);
- if (Attrib::Count != attr
+ if (Attrib::Count != attr
&& AttribType::Count != type)
{
_decl.add(attr, num, type, normalized, asInt);
@@ -420,6 +425,46 @@ namespace bgfx
}
break;
+ case AttribType::Uint10:
+ {
+ uint32_t packed = 0;
+ if (_inputNormalized)
+ {
+ if (asInt)
+ {
+ switch (num)
+ {
+ default:
+ case 3: packed |= uint32_t(*_input++ * 511.0f + 512.0f);
+ case 2: packed <<= 10; packed |= uint32_t(*_input++ * 511.0f + 512.0f);
+ case 1: packed <<= 10; packed |= uint32_t(*_input++ * 511.0f + 512.0f);
+ }
+ }
+ else
+ {
+ switch (num)
+ {
+ default:
+ case 3: packed |= uint32_t(*_input++ * 1023.0f);
+ case 2: packed <<= 10; packed |= uint32_t(*_input++ * 1023.0f);
+ case 1: packed <<= 10; packed |= uint32_t(*_input++ * 1023.0f);
+ }
+ }
+ }
+ else
+ {
+ switch (num)
+ {
+ default:
+ case 3: packed |= uint32_t(*_input++);
+ case 2: packed <<= 10; packed |= uint32_t(*_input++);
+ case 1: packed <<= 10; packed |= uint32_t(*_input++);
+ }
+ }
+ *(uint32_t*)data = packed;
+ }
+ break;
+
case AttribType::Int16:
{
int16_t* packed = (int16_t*)data;
@@ -524,6 +569,32 @@ namespace bgfx
}
break;
+ case AttribType::Uint10:
+ {
+ uint32_t packed = *(uint32_t*)data;
+ if (asInt)
+ {
+ switch (num)
+ {
+ default:
+ case 3: *_output++ = (float(packed & 0x3ff) - 512.0f)*1.0f/511.0f; packed >>= 10;
+ case 2: *_output++ = (float(packed & 0x3ff) - 512.0f)*1.0f/511.0f; packed >>= 10;
+ case 1: *_output++ = (float(packed & 0x3ff) - 512.0f)*1.0f/511.0f;
+ }
+ }
+ else
+ {
+ switch (num)
+ {
+ default:
+ case 3: *_output++ = float(packed & 0x3ff)*1.0f/1023.0f; packed >>= 10;
+ case 2: *_output++ = float(packed & 0x3ff)*1.0f/1023.0f; packed >>= 10;
+ case 1: *_output++ = float(packed & 0x3ff)*1.0f/1023.0f;
+ }
+ }
+ }
+ break;
+
case AttribType::Int16:
{
int16_t* packed = (int16_t*)data;