Added AttribType::Uint10 encoding/decoding.

This commit is contained in:
Branimir Karadžić
2015-08-04 21:55:47 -07:00
parent f54ffcca42
commit 4ce0c5703e
2 changed files with 90 additions and 7 deletions

View File

@@ -425,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;
@@ -529,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;