mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
Added vertex attrib Uint10.
This commit is contained in:
parent
d0b4657e15
commit
8da579ff99
9 changed files with 92 additions and 56 deletions
|
@ -66,6 +66,7 @@ typedef enum bgfx_attrib
|
|||
typedef enum bgfx_attrib_type
|
||||
{
|
||||
BGFX_ATTRIB_TYPE_UINT8,
|
||||
BGFX_ATTRIB_TYPE_UINT10,
|
||||
BGFX_ATTRIB_TYPE_INT16,
|
||||
BGFX_ATTRIB_TYPE_HALF,
|
||||
BGFX_ATTRIB_TYPE_FLOAT,
|
||||
|
@ -236,7 +237,7 @@ typedef struct bgfx_vertex_decl
|
|||
uint32_t hash;
|
||||
uint16_t stride;
|
||||
uint16_t offset[BGFX_ATTRIB_COUNT];
|
||||
uint8_t attributes[BGFX_ATTRIB_COUNT];
|
||||
uint16_t attributes[BGFX_ATTRIB_COUNT];
|
||||
|
||||
} bgfx_vertex_decl_t;
|
||||
|
||||
|
|
|
@ -120,8 +120,9 @@ namespace bgfx
|
|||
enum Enum
|
||||
{
|
||||
Uint8,
|
||||
Uint10, //!< Availability depends on: `BGFX_CAPS_VERTEX_ATTRIB_UINT10`.
|
||||
Int16,
|
||||
Half, // Availability depends on: `BGFX_CAPS_VERTEX_ATTRIB_HALF`.
|
||||
Half, //!< Availability depends on: `BGFX_CAPS_VERTEX_ATTRIB_HALF`.
|
||||
Float,
|
||||
|
||||
Count
|
||||
|
@ -607,7 +608,7 @@ namespace bgfx
|
|||
uint32_t m_hash;
|
||||
uint16_t m_stride;
|
||||
uint16_t m_offset[Attrib::Count];
|
||||
uint8_t m_attributes[Attrib::Count];
|
||||
uint16_t m_attributes[Attrib::Count];
|
||||
};
|
||||
|
||||
/// Pack vec4 into vertex stream format.
|
||||
|
|
|
@ -344,16 +344,17 @@
|
|||
#define BGFX_CAPS_TEXTURE_COMPARE_ALL UINT64_C(0x0000000000000003) //!< All texture compare modes are supported.
|
||||
#define BGFX_CAPS_TEXTURE_3D UINT64_C(0x0000000000000004) //!< 3D textures are supported.
|
||||
#define BGFX_CAPS_VERTEX_ATTRIB_HALF UINT64_C(0x0000000000000008) //!< Vertex attribute half-float is supported.
|
||||
#define BGFX_CAPS_INSTANCING UINT64_C(0x0000000000000010) //!< Instancing is supported.
|
||||
#define BGFX_CAPS_RENDERER_MULTITHREADED UINT64_C(0x0000000000000020) //!< Renderer is on separate thread.
|
||||
#define BGFX_CAPS_FRAGMENT_DEPTH UINT64_C(0x0000000000000040) //!< Fragment depth is accessible in fragment shader.
|
||||
#define BGFX_CAPS_BLEND_INDEPENDENT UINT64_C(0x0000000000000080) //!< Blend independent is supported.
|
||||
#define BGFX_CAPS_COMPUTE UINT64_C(0x0000000000000100) //!< Compute shaders are supported.
|
||||
#define BGFX_CAPS_FRAGMENT_ORDERING UINT64_C(0x0000000000000200) //!< Fragment ordering is available in fragment shader.
|
||||
#define BGFX_CAPS_SWAP_CHAIN UINT64_C(0x0000000000000400) //!< Multiple windows are supported.
|
||||
#define BGFX_CAPS_HMD UINT64_C(0x0000000000000800) //!< Head Mounted Display is available.
|
||||
#define BGFX_CAPS_INDEX32 UINT64_C(0x0000000000001000) //!< 32-bit indices are supported.
|
||||
#define BGFX_CAPS_DRAW_INDIRECT UINT64_C(0x0000000000002000) //!< Draw indirect is supported.
|
||||
#define BGFX_CAPS_VERTEX_ATTRIB_UINT10 UINT64_C(0x0000000000000010) //!< Vertex attribute 10_10_10_2 is supported.
|
||||
#define BGFX_CAPS_INSTANCING UINT64_C(0x0000000000000020) //!< Instancing is supported.
|
||||
#define BGFX_CAPS_RENDERER_MULTITHREADED UINT64_C(0x0000000000000040) //!< Renderer is on separate thread.
|
||||
#define BGFX_CAPS_FRAGMENT_DEPTH UINT64_C(0x0000000000000080) //!< Fragment depth is accessible in fragment shader.
|
||||
#define BGFX_CAPS_BLEND_INDEPENDENT UINT64_C(0x0000000000000100) //!< Blend independent is supported.
|
||||
#define BGFX_CAPS_COMPUTE UINT64_C(0x0000000000000200) //!< Compute shaders are supported.
|
||||
#define BGFX_CAPS_FRAGMENT_ORDERING UINT64_C(0x0000000000000400) //!< Fragment ordering is available in fragment shader.
|
||||
#define BGFX_CAPS_SWAP_CHAIN UINT64_C(0x0000000000000800) //!< Multiple windows are supported.
|
||||
#define BGFX_CAPS_HMD UINT64_C(0x0000000000001000) //!< Head Mounted Display is available.
|
||||
#define BGFX_CAPS_INDEX32 UINT64_C(0x0000000000002000) //!< 32-bit indices are supported.
|
||||
#define BGFX_CAPS_DRAW_INDIRECT UINT64_C(0x0000000000004000) //!< Draw indirect is supported.
|
||||
|
||||
///
|
||||
#define BGFX_CAPS_FORMAT_TEXTURE_NONE UINT8_C(0x00) //!<
|
||||
|
|
|
@ -842,6 +842,7 @@ namespace bgfx
|
|||
CAPS_FLAGS(BGFX_CAPS_TEXTURE_COMPARE_ALL),
|
||||
CAPS_FLAGS(BGFX_CAPS_TEXTURE_3D),
|
||||
CAPS_FLAGS(BGFX_CAPS_VERTEX_ATTRIB_HALF),
|
||||
CAPS_FLAGS(BGFX_CAPS_VERTEX_ATTRIB_UINT10),
|
||||
CAPS_FLAGS(BGFX_CAPS_INSTANCING),
|
||||
CAPS_FLAGS(BGFX_CAPS_RENDERER_MULTITHREADED),
|
||||
CAPS_FLAGS(BGFX_CAPS_FRAGMENT_DEPTH),
|
||||
|
|
|
@ -267,25 +267,31 @@ namespace bgfx { namespace d3d11
|
|||
|
||||
static const DXGI_FORMAT s_attribType[][4][2] =
|
||||
{
|
||||
{
|
||||
{ // Uint8
|
||||
{ DXGI_FORMAT_R8_UINT, DXGI_FORMAT_R8_UNORM },
|
||||
{ DXGI_FORMAT_R8G8_UINT, DXGI_FORMAT_R8G8_UNORM },
|
||||
{ DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UNORM },
|
||||
{ DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UNORM },
|
||||
},
|
||||
{
|
||||
{ // Uint10
|
||||
{ DXGI_FORMAT_R10G10B10A2_UINT, DXGI_FORMAT_R10G10B10A2_UNORM },
|
||||
{ DXGI_FORMAT_R10G10B10A2_UINT, DXGI_FORMAT_R10G10B10A2_UNORM },
|
||||
{ DXGI_FORMAT_R10G10B10A2_UINT, DXGI_FORMAT_R10G10B10A2_UNORM },
|
||||
{ DXGI_FORMAT_R10G10B10A2_UINT, DXGI_FORMAT_R10G10B10A2_UNORM },
|
||||
},
|
||||
{ // Int16
|
||||
{ DXGI_FORMAT_R16_SINT, DXGI_FORMAT_R16_SNORM },
|
||||
{ DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_SNORM },
|
||||
{ DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SNORM },
|
||||
{ DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SNORM },
|
||||
},
|
||||
{
|
||||
{ // Half
|
||||
{ DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_R16_FLOAT },
|
||||
{ DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_FLOAT },
|
||||
{ DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT },
|
||||
{ DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT },
|
||||
},
|
||||
{
|
||||
{ // Float
|
||||
{ DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_R32_FLOAT },
|
||||
{ DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_FLOAT },
|
||||
{ DXGI_FORMAT_R32G32B32_FLOAT, DXGI_FORMAT_R32G32B32_FLOAT },
|
||||
|
@ -933,6 +939,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
|||
g_caps.supported |= (0
|
||||
| BGFX_CAPS_TEXTURE_3D
|
||||
| BGFX_CAPS_VERTEX_ATTRIB_HALF
|
||||
| BGFX_CAPS_VERTEX_ATTRIB_UINT10
|
||||
| BGFX_CAPS_FRAGMENT_DEPTH
|
||||
| (getIntelExtensions(m_device) ? BGFX_CAPS_FRAGMENT_ORDERING : 0)
|
||||
| BGFX_CAPS_SWAP_CHAIN
|
||||
|
|
|
@ -250,25 +250,31 @@ namespace bgfx { namespace d3d12
|
|||
|
||||
static const DXGI_FORMAT s_attribType[][4][2] =
|
||||
{
|
||||
{
|
||||
{ // Uint8
|
||||
{ DXGI_FORMAT_R8_UINT, DXGI_FORMAT_R8_UNORM },
|
||||
{ DXGI_FORMAT_R8G8_UINT, DXGI_FORMAT_R8G8_UNORM },
|
||||
{ DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UNORM },
|
||||
{ DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UNORM },
|
||||
},
|
||||
{
|
||||
{ // Uint10
|
||||
{ DXGI_FORMAT_R10G10B10A2_UINT, DXGI_FORMAT_R10G10B10A2_UNORM },
|
||||
{ DXGI_FORMAT_R10G10B10A2_UINT, DXGI_FORMAT_R10G10B10A2_UNORM },
|
||||
{ DXGI_FORMAT_R10G10B10A2_UINT, DXGI_FORMAT_R10G10B10A2_UNORM },
|
||||
{ DXGI_FORMAT_R10G10B10A2_UINT, DXGI_FORMAT_R10G10B10A2_UNORM },
|
||||
},
|
||||
{ // Int16
|
||||
{ DXGI_FORMAT_R16_SINT, DXGI_FORMAT_R16_SNORM },
|
||||
{ DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_SNORM },
|
||||
{ DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SNORM },
|
||||
{ DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SNORM },
|
||||
},
|
||||
{
|
||||
{ // Half
|
||||
{ DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_R16_FLOAT },
|
||||
{ DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_FLOAT },
|
||||
{ DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT },
|
||||
{ DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT },
|
||||
},
|
||||
{
|
||||
{ // Float
|
||||
{ DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_R32_FLOAT },
|
||||
{ DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_FLOAT },
|
||||
{ DXGI_FORMAT_R32G32B32_FLOAT, DXGI_FORMAT_R32G32B32_FLOAT },
|
||||
|
@ -757,6 +763,7 @@ namespace bgfx { namespace d3d12
|
|||
| BGFX_CAPS_TEXTURE_COMPARE_ALL
|
||||
| BGFX_CAPS_INSTANCING
|
||||
| BGFX_CAPS_VERTEX_ATTRIB_HALF
|
||||
| BGFX_CAPS_VERTEX_ATTRIB_UINT10
|
||||
| BGFX_CAPS_FRAGMENT_DEPTH
|
||||
| BGFX_CAPS_BLEND_INDEPENDENT
|
||||
| BGFX_CAPS_COMPUTE
|
||||
|
|
|
@ -515,6 +515,7 @@ namespace bgfx { namespace d3d9
|
|||
| BGFX_CAPS_TEXTURE_3D
|
||||
| BGFX_CAPS_TEXTURE_COMPARE_LEQUAL
|
||||
| BGFX_CAPS_VERTEX_ATTRIB_HALF
|
||||
| BGFX_CAPS_VERTEX_ATTRIB_UINT10
|
||||
| BGFX_CAPS_FRAGMENT_DEPTH
|
||||
| BGFX_CAPS_SWAP_CHAIN
|
||||
| ( (UINT16_MAX < m_caps.MaxVertexIndex) ? BGFX_CAPS_INDEX32 : 0)
|
||||
|
@ -2036,25 +2037,31 @@ namespace bgfx { namespace d3d9
|
|||
|
||||
static const uint8_t s_attribType[][4][2] =
|
||||
{
|
||||
{
|
||||
{ // Uint8
|
||||
{ D3DDECLTYPE_UBYTE4, D3DDECLTYPE_UBYTE4N },
|
||||
{ D3DDECLTYPE_UBYTE4, D3DDECLTYPE_UBYTE4N },
|
||||
{ D3DDECLTYPE_UBYTE4, D3DDECLTYPE_UBYTE4N },
|
||||
{ D3DDECLTYPE_UBYTE4, D3DDECLTYPE_UBYTE4N },
|
||||
},
|
||||
{
|
||||
{ // Uint10
|
||||
{ D3DDECLTYPE_UDEC3, D3DDECLTYPE_DEC3N },
|
||||
{ D3DDECLTYPE_UDEC3, D3DDECLTYPE_DEC3N },
|
||||
{ D3DDECLTYPE_UDEC3, D3DDECLTYPE_DEC3N },
|
||||
{ D3DDECLTYPE_UDEC3, D3DDECLTYPE_DEC3N },
|
||||
},
|
||||
{ // Int16
|
||||
{ D3DDECLTYPE_SHORT2, D3DDECLTYPE_SHORT2N },
|
||||
{ D3DDECLTYPE_SHORT2, D3DDECLTYPE_SHORT2N },
|
||||
{ D3DDECLTYPE_SHORT4, D3DDECLTYPE_SHORT4N },
|
||||
{ D3DDECLTYPE_SHORT4, D3DDECLTYPE_SHORT4N },
|
||||
},
|
||||
{
|
||||
{ // Half
|
||||
{ D3DDECLTYPE_FLOAT16_2, D3DDECLTYPE_FLOAT16_2 },
|
||||
{ D3DDECLTYPE_FLOAT16_2, D3DDECLTYPE_FLOAT16_2 },
|
||||
{ D3DDECLTYPE_FLOAT16_4, D3DDECLTYPE_FLOAT16_4 },
|
||||
{ D3DDECLTYPE_FLOAT16_4, D3DDECLTYPE_FLOAT16_4 },
|
||||
},
|
||||
{
|
||||
{ // Float
|
||||
{ D3DDECLTYPE_FLOAT1, D3DDECLTYPE_FLOAT1 },
|
||||
{ D3DDECLTYPE_FLOAT2, D3DDECLTYPE_FLOAT2 },
|
||||
{ D3DDECLTYPE_FLOAT3, D3DDECLTYPE_FLOAT3 },
|
||||
|
@ -2069,7 +2076,7 @@ namespace bgfx { namespace d3d9
|
|||
|
||||
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;
|
||||
|
|
|
@ -81,10 +81,11 @@ namespace bgfx { namespace gl
|
|||
|
||||
static const GLenum s_attribType[] =
|
||||
{
|
||||
GL_UNSIGNED_BYTE,
|
||||
GL_SHORT,
|
||||
GL_HALF_FLOAT,
|
||||
GL_FLOAT,
|
||||
GL_UNSIGNED_BYTE, // Uint8
|
||||
GL_UNSIGNED_INT_10_10_10_2, // Uint10
|
||||
GL_SHORT, // Int16
|
||||
GL_HALF_FLOAT, // Half
|
||||
GL_FLOAT, // Float
|
||||
};
|
||||
BX_STATIC_ASSERT(AttribType::Count == BX_COUNTOF(s_attribType) );
|
||||
|
||||
|
@ -1522,6 +1523,12 @@ namespace bgfx { namespace gl
|
|||
? BGFX_CAPS_VERTEX_ATTRIB_HALF
|
||||
: 0
|
||||
;
|
||||
g_caps.supported |= false
|
||||
|| s_extension[Extension::ARB_vertex_type_2_10_10_10_rev].m_supported
|
||||
|| s_extension[Extension::OES_vertex_type_10_10_10_2].m_supported
|
||||
? BGFX_CAPS_VERTEX_ATTRIB_UINT10
|
||||
: 0
|
||||
;
|
||||
g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 30)
|
||||
|| s_extension[Extension::EXT_frag_depth].m_supported
|
||||
? BGFX_CAPS_FRAGMENT_DEPTH
|
||||
|
|
|
@ -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] =
|
||||
|
@ -108,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 encodedNorm = (_normalized&1)<<7;
|
||||
const uint8_t encodedType = (_type&7)<<3;
|
||||
const uint8_t encodedNum = (_num-1)&3;
|
||||
const uint8_t encodeAsInt = (_asInt&(!!"\x1\x1\x0\x0"[_type]) )<<7;
|
||||
const uint8_t encodeAsInt = (_asInt&(!!"\x1\x1\x0\x0"[_type]) )<<8;
|
||||
m_attributes[_attrib] = encodedNorm|encodedType|encodedNum|encodeAsInt;
|
||||
|
||||
m_offset[_attrib] = m_stride;
|
||||
|
@ -129,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[] =
|
||||
|
@ -257,6 +260,7 @@ namespace bgfx
|
|||
// id is unique and should not be changed if new AttribTypes are
|
||||
// added.
|
||||
{ AttribType::Uint8, 0x0001 },
|
||||
{ AttribType::Uint10, 0x0005 },
|
||||
{ AttribType::Int16, 0x0002 },
|
||||
{ AttribType::Half, 0x0003 },
|
||||
{ AttribType::Float, 0x0004 },
|
||||
|
@ -288,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);
|
||||
|
@ -296,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;
|
||||
|
|
Loading…
Reference in a new issue