diff options
Diffstat (limited to '3rdparty/bgfx/src/vertexdecl.cpp')
-rw-r--r-- | 3rdparty/bgfx/src/vertexdecl.cpp | 99 |
1 files changed, 50 insertions, 49 deletions
diff --git a/3rdparty/bgfx/src/vertexdecl.cpp b/3rdparty/bgfx/src/vertexdecl.cpp index 6c6358626d1..099b4b03635 100644 --- a/3rdparty/bgfx/src/vertexdecl.cpp +++ b/3rdparty/bgfx/src/vertexdecl.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. + * Copyright 2011-2019 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ @@ -49,6 +49,7 @@ namespace bgfx &s_attribTypeSizeD3D1x, // Direct3D12 &s_attribTypeSizeD3D1x, // Gnm &s_attribTypeSizeGl, // Metal + &s_attribTypeSizeGl, // Nvn &s_attribTypeSizeGl, // OpenGLES &s_attribTypeSizeGl, // OpenGL &s_attribTypeSizeD3D1x, // Vulkan @@ -62,16 +63,16 @@ namespace bgfx s_attribTypeSize[RendererType::Count] = s_attribTypeSize[_type]; } - VertexDecl::VertexDecl() + VertexLayout::VertexLayout() : m_stride(0) { // BK - struct need to have ctor to qualify as non-POD data. // Need this to catch programming errors when serializing struct. } - VertexDecl& VertexDecl::begin(RendererType::Enum _renderer) + VertexLayout& VertexLayout::begin(RendererType::Enum _renderer) { - m_hash = _renderer; // use hash to store renderer type while building VertexDecl. + m_hash = _renderer; // use hash to store renderer type while building VertexLayout. m_stride = 0; bx::memSet(m_attributes, 0xff, sizeof(m_attributes) ); bx::memSet(m_offset, 0, sizeof(m_offset) ); @@ -79,7 +80,7 @@ namespace bgfx return *this; } - void VertexDecl::end() + void VertexLayout::end() { bx::HashMurmur2A murmur; murmur.begin(); @@ -89,7 +90,7 @@ namespace bgfx m_hash = murmur.end(); } - VertexDecl& VertexDecl::add(Attrib::Enum _attrib, uint8_t _num, AttribType::Enum _type, bool _normalized, bool _asInt) + VertexLayout& VertexLayout::add(Attrib::Enum _attrib, uint8_t _num, AttribType::Enum _type, bool _normalized, bool _asInt) { const uint16_t encodedNorm = (_normalized&1)<<7; const uint16_t encodedType = (_type&7)<<3; @@ -103,14 +104,14 @@ namespace bgfx return *this; } - VertexDecl& VertexDecl::skip(uint8_t _num) + VertexLayout& VertexLayout::skip(uint8_t _num) { m_stride += _num; return *this; } - void VertexDecl::decode(Attrib::Enum _attrib, uint8_t& _num, AttribType::Enum& _type, bool& _normalized, bool& _asInt) const + void VertexLayout::decode(Attrib::Enum _attrib, uint8_t& _num, AttribType::Enum& _type, bool& _normalized, bool& _asInt) const { uint16_t val = m_attributes[_attrib]; _num = (val&3)+1; @@ -240,7 +241,7 @@ namespace bgfx return s_attribTypeToId[_attr].id; } - int32_t write(bx::WriterI* _writer, const VertexDecl& _decl, bx::Error* _err) + int32_t write(bx::WriterI* _writer, const VertexLayout& _layout, bx::Error* _err) { BX_ERROR_SCOPE(_err); @@ -249,22 +250,22 @@ namespace bgfx for (uint32_t attr = 0; attr < Attrib::Count; ++attr) { - numAttrs += UINT16_MAX == _decl.m_attributes[attr] ? 0 : 1; + numAttrs += UINT16_MAX == _layout.m_attributes[attr] ? 0 : 1; } total += bx::write(_writer, numAttrs, _err); - total += bx::write(_writer, _decl.m_stride, _err); + total += bx::write(_writer, _layout.m_stride, _err); for (uint32_t attr = 0; attr < Attrib::Count; ++attr) { - if (UINT16_MAX != _decl.m_attributes[attr]) + if (UINT16_MAX != _layout.m_attributes[attr]) { uint8_t num; AttribType::Enum type; bool normalized; bool asInt; - _decl.decode(Attrib::Enum(attr), num, type, normalized, asInt); - total += bx::write(_writer, _decl.m_offset[attr], _err); + _layout.decode(Attrib::Enum(attr), num, type, normalized, asInt); + total += bx::write(_writer, _layout.m_offset[attr], _err); total += bx::write(_writer, s_attribToId[attr].id, _err); total += bx::write(_writer, num, _err); total += bx::write(_writer, s_attribTypeToId[type].id, _err); @@ -276,7 +277,7 @@ namespace bgfx return total; } - int32_t read(bx::ReaderI* _reader, VertexDecl& _decl, bx::Error* _err) + int32_t read(bx::ReaderI* _reader, VertexLayout& _layout, bx::Error* _err) { BX_ERROR_SCOPE(_err); @@ -293,7 +294,7 @@ namespace bgfx return total; } - _decl.begin(); + _layout.begin(); for (uint32_t ii = 0; ii < numAttrs; ++ii) { @@ -325,32 +326,32 @@ namespace bgfx if (Attrib::Count != attr && AttribType::Count != type) { - _decl.add(attr, num, type, normalized, asInt); - _decl.m_offset[attr] = offset; + _layout.add(attr, num, type, normalized, asInt); + _layout.m_offset[attr] = offset; } } - _decl.end(); - _decl.m_stride = stride; + _layout.end(); + _layout.m_stride = stride; return total; } - void vertexPack(const float _input[4], bool _inputNormalized, Attrib::Enum _attr, const VertexDecl& _decl, void* _data, uint32_t _index) + void vertexPack(const float _input[4], bool _inputNormalized, Attrib::Enum _attr, const VertexLayout& _layout, void* _data, uint32_t _index) { - if (!_decl.has(_attr) ) + if (!_layout.has(_attr) ) { return; } - uint32_t stride = _decl.getStride(); - uint8_t* data = (uint8_t*)_data + _index*stride + _decl.getOffset(_attr); + uint32_t stride = _layout.getStride(); + uint8_t* data = (uint8_t*)_data + _index*stride + _layout.getOffset(_attr); uint8_t num; AttribType::Enum type; bool normalized; bool asInt; - _decl.decode(_attr, num, type, normalized, asInt); + _layout.decode(_attr, num, type, normalized, asInt); switch (type) { @@ -492,22 +493,22 @@ namespace bgfx } } - void vertexUnpack(float _output[4], Attrib::Enum _attr, const VertexDecl& _decl, const void* _data, uint32_t _index) + void vertexUnpack(float _output[4], Attrib::Enum _attr, const VertexLayout& _layout, const void* _data, uint32_t _index) { - if (!_decl.has(_attr) ) + if (!_layout.has(_attr) ) { bx::memSet(_output, 0, 4*sizeof(float) ); return; } - uint32_t stride = _decl.getStride(); - uint8_t* data = (uint8_t*)_data + _index*stride + _decl.getOffset(_attr); + uint32_t stride = _layout.getStride(); + uint8_t* data = (uint8_t*)_data + _index*stride + _layout.getOffset(_attr); uint8_t num; AttribType::Enum type; bool normalized; bool asInt; - _decl.decode(_attr, num, type, normalized, asInt); + _layout.decode(_attr, num, type, normalized, asInt); switch (type) { @@ -618,11 +619,11 @@ namespace bgfx } } - void vertexConvert(const VertexDecl& _destDecl, void* _destData, const VertexDecl& _srcDecl, const void* _srcData, uint32_t _num) + void vertexConvert(const VertexLayout& _destLayout, void* _destData, const VertexLayout& _srcLayout, const void* _srcData, uint32_t _num) { - if (_destDecl.m_hash == _srcDecl.m_hash) + if (_destLayout.m_hash == _srcLayout.m_hash) { - bx::memCopy(_destData, _srcData, _srcDecl.getSize(_num) ); + bx::memCopy(_destData, _srcData, _srcLayout.getSize(_num) ); return; } @@ -649,23 +650,23 @@ namespace bgfx { Attrib::Enum attr = (Attrib::Enum)ii; - if (_destDecl.has(attr) ) + if (_destLayout.has(attr) ) { ConvertOp& cop = convertOp[numOps]; cop.attr = attr; - cop.dest = _destDecl.getOffset(attr); + cop.dest = _destLayout.getOffset(attr); uint8_t num; AttribType::Enum type; bool normalized; bool asInt; - _destDecl.decode(attr, num, type, normalized, asInt); + _destLayout.decode(attr, num, type, normalized, asInt); cop.size = (*s_attribTypeSize[0])[type][num-1]; - if (_srcDecl.has(attr) ) + if (_srcLayout.has(attr) ) { - cop.src = _srcDecl.getOffset(attr); - cop.op = _destDecl.m_attributes[attr] == _srcDecl.m_attributes[attr] ? ConvertOp::Copy : ConvertOp::Convert; + cop.src = _srcLayout.getOffset(attr); + cop.op = _destLayout.m_attributes[attr] == _srcLayout.m_attributes[attr] ? ConvertOp::Copy : ConvertOp::Convert; } else { @@ -679,10 +680,10 @@ namespace bgfx if (0 < numOps) { const uint8_t* src = (const uint8_t*)_srcData; - uint32_t srcStride = _srcDecl.getStride(); + uint32_t srcStride = _srcLayout.getStride(); uint8_t* dest = (uint8_t*)_destData; - uint32_t destStride = _destDecl.getStride(); + uint32_t destStride = _destLayout.getStride(); float unpacked[4]; @@ -703,8 +704,8 @@ namespace bgfx break; case ConvertOp::Convert: - vertexUnpack(unpacked, cop.attr, _srcDecl, src); - vertexPack(unpacked, true, cop.attr, _destDecl, dest); + vertexUnpack(unpacked, cop.attr, _srcLayout, src); + vertexPack(unpacked, true, cop.attr, _destLayout, dest); break; } } @@ -723,7 +724,7 @@ namespace bgfx return xx*xx + yy*yy + zz*zz; } - uint16_t weldVerticesRef(uint16_t* _output, const VertexDecl& _decl, const void* _data, uint16_t _num, float _epsilon) + uint16_t weldVerticesRef(uint16_t* _output, const VertexLayout& _layout, const void* _data, uint16_t _num, float _epsilon) { // Brute force slow vertex welding... const float epsilonSq = _epsilon*_epsilon; @@ -742,7 +743,7 @@ namespace bgfx ++numVertices; float pos[4]; - vertexUnpack(pos, Attrib::Position, _decl, _data, ii); + vertexUnpack(pos, Attrib::Position, _layout, _data, ii); for (uint32_t jj = 0; jj < _num; ++jj) { @@ -752,7 +753,7 @@ namespace bgfx } float test[4]; - vertexUnpack(test, Attrib::Position, _decl, _data, jj); + vertexUnpack(test, Attrib::Position, _layout, _data, jj); if (sqLength(test, pos) < epsilonSq) { @@ -764,7 +765,7 @@ namespace bgfx return (uint16_t)numVertices; } - uint16_t weldVertices(uint16_t* _output, const VertexDecl& _decl, const void* _data, uint16_t _num, float _epsilon) + uint16_t weldVertices(uint16_t* _output, const VertexLayout& _layout, const void* _data, uint16_t _num, float _epsilon) { const uint32_t hashSize = bx::uint32_nextpow2(_num); const uint32_t hashMask = hashSize-1; @@ -781,14 +782,14 @@ namespace bgfx for (uint32_t ii = 0; ii < _num; ++ii) { float pos[4]; - vertexUnpack(pos, Attrib::Position, _decl, _data, ii); + vertexUnpack(pos, Attrib::Position, _layout, _data, ii); uint32_t hashValue = bx::hash<bx::HashMurmur2A>(pos, 3*sizeof(float) ) & hashMask; uint16_t offset = hashTable[hashValue]; for (; UINT16_MAX != offset; offset = next[offset]) { float test[4]; - vertexUnpack(test, Attrib::Position, _decl, _data, _output[offset]); + vertexUnpack(test, Attrib::Position, _layout, _data, _output[offset]); if (sqLength(test, pos) < epsilonSq) { |