19template<
bool TexCoords,
bool Normals,
bool Tangents,
bool Colour,
bool Bones>
24 std::memcpy(dataOut, data._position._v,
sizeof data._position);
25 dataOut +=
sizeof data._position;
27 if constexpr (TexCoords)
29 std::memcpy(dataOut, data._texcoord._v,
sizeof data._texcoord);
30 dataOut +=
sizeof data._texcoord;
35 std::memcpy(dataOut, &data._normal,
sizeof data._normal);
36 dataOut +=
sizeof data._normal;
39 if constexpr(Tangents)
41 std::memcpy(dataOut, &data._tangent,
sizeof data._tangent);
42 dataOut +=
sizeof data._tangent;
47 std::memcpy(dataOut, data._colour._v,
sizeof data._colour);
48 dataOut +=
sizeof data._colour;
53 std::memcpy(dataOut, data._weights._v,
sizeof data._weights);
54 dataOut +=
sizeof data._weights;
56 std::memcpy(dataOut, data._indices._v,
sizeof data._indices );
57 dataOut +=
sizeof data._indices;
62template <
bool TexCoords,
bool Normals,
bool Tangents,
bool Colour>
67 FillSmallData5<TexCoords, Normals, Tangents, Colour, true>(dataIn, dataOut);
71 FillSmallData5<TexCoords, Normals, Tangents, Colour, false>(dataIn, dataOut);
75template <
bool TexCoords,
bool Normals,
bool Tangents>
80 FillSmallData4<TexCoords, Normals, Tangents, true>(dataIn, dataOut, bones);
84 FillSmallData4<TexCoords, Normals, Tangents, false>(dataIn, dataOut, bones);
88template <
bool TexCoords,
bool Normals>
93 FillSmallData3<TexCoords, Normals, true>(dataIn, dataOut, colour, bones);
97 FillSmallData3<TexCoords, Normals, false>(dataIn, dataOut, colour, bones);
101template <
bool TexCoords>
106 FillSmallData2<TexCoords, true>(dataIn, dataOut, tangents, colour, bones);
110 FillSmallData2<TexCoords, false>(dataIn, dataOut, tangents, colour, bones);
118 FillSmallData1<true>(dataIn, dataOut, normals, tangents, colour, bones);
122 FillSmallData1<false>(dataIn, dataOut, normals, tangents, colour, bones);
130 , _descriptor(descriptor)
131 , _internalGVD(context.newGVD(1u, descriptor._name))
159 _data.resize(size, defaultValue);
165 return _data[index]._position;
170 return _data[index]._texcoord;
175 return _data[index]._normal;
187 return _data[index]._tangent;
199 return _data[index]._indices;
204 return _data[index]._weights;
241 eastl::transform(eastl::cbegin(indices),
242 eastl::cend(indices),
257 primitiveRestartRequired(
true);
269 it++->_position.set(value);
287 _data[index]._position.set(x, y, z);
303 _data[index]._colour.set(r, g, b, a);
351 _data[index]._texcoord.set(s, t);
362 _data[index]._indices = indices;
383 _data[index]._weights = packedWeights;
398 size_t partitionedIndexCount = previousIndexCount + previousOffset;
442 FillSmallData(dataIn,
464 DIVIDE_ASSERT(!
_indices.empty() &&
"glVertexArray::refresh error: Invalid index data on Refresh()!");
478 setBufferParams._bufferParams._elementCount =
to_U32(
_data.size());
481 setBufferParams._initialData = { smallData.data(), smallData.size() };
482 setBufferParams._elementStride = setBufferParams._bufferParams._elementSize;
498 _data.shrink_to_fit();
508 idxBuffer.indicesNeedCast = idxBuffer.smallIndices;
522 const bool refreshed =
refresh(dataLock, indexLock);
524 _internalGVD->primitiveRestartRequired(primitiveRestartRequired());
527 if ( refreshed && dataLock.
_range.
_length > 0u && indexLock._range._length > 0u )
538 if ( indexLock._range._length > 0u )
540 if ( !indexLock._buffer->lockRange( indexLock._range, sync ) )
561 VertexBinding& vertBinding = retMap._vertexBindings.emplace_back();
643 for (
size_t i = 0u; i < indexCount; i += 3u)
666 normalBuffer[idx0] += no;
667 normalBuffer[idx1] += no;
668 normalBuffer[idx2] += no;
671 for (
U32 i = 0u; i < vertCount; ++i)
688 for (
U32 i = 0u; i < indexCount; i += 3)
712 deltaPos1.
set(v1 - v0);
713 deltaPos2.
set(v2 - v0);
716 deltaUV1.
set(uv1 - uv0);
717 deltaUV2.
set(uv2 - uv0);
719 const F32 r = 1.0f / (deltaUV1.
x * deltaUV2.
y - deltaUV1.
y * deltaUV2.
x);
720 tangent.
set((deltaPos1 * deltaUV2.
y - deltaPos2 * deltaUV1.
y) * r);
732 primitiveRestartRequired(
false);
749 primitiveRestartRequired(other.primitiveRestartRequired());
765 if (idString ==
_ID(
"VB"))
775 dataIn >> _primitiveRestartRequired;
792 dataOut <<
_ID(
"VB");
800 dataOut << _primitiveRestartRequired;
833 totalDataSizeOut +=
sizeof(
F32);
839 totalDataSizeOut +=
sizeof(
F32);
845 totalDataSizeOut +=
sizeof(
UColour4);
851 totalDataSizeOut +=
sizeof(
vec4<U8>);
854 totalDataSizeOut +=
sizeof(
vec4<U8> );
bool bufferEmpty() const noexcept
Returns true if the read position and the write position are identical.
Rough around the edges Adapter pattern abstracting the actual rendering API and access to the GPU.
static SyncObjectHandle CreateSyncObject(RenderAPI api, U8 flag=DEFAULT_SYNC_FLAG_INTERNAL)
void addIndex(const U32 index)
void modifyTexCoordValue(const U32 index, vec2< F32 > newValue)
bool deserialize(ByteBuffer &dataIn)
static constexpr U32 PRIMITIVE_RESTART_INDEX_L
U32 getIndex(const size_t index) const
void modifyPositionValues(const U32 indexOffset, const vector< vec3< F32 > > &newValues)
size_t getPartitionOffset(const U16 partitionID) const
vec4< U8 > getBoneWeightsPacked(const U32 index) const
void draw(const GenericDrawCommand &command, VDIUserData *data) override
Calculates the appropriate attribute offsets and returns the total size of a vertex for this buffer.
VertexBuffer(GFXDevice &context, const Descriptor &descriptor)
size_t getIndexCount() const noexcept
bool refresh(BufferLock &dataLockOut, BufferLock &indexLockOut)
Returns true if data was updated.
vec4< F32 > getBoneWeights(const U32 index) const
size_t lastPartitionOffset() const
AttributeFlags _useAttribute
const vector< Vertex > & getVertices() const noexcept
GenericVertexData_ptr _internalGVD
size_t partitionCount() const noexcept
size_t getPartitionIndexCount(const U16 partitionID)
vec2< F32 > getTexCoord(const U32 index) const
void addIndices(const vector< U16 > &indices)
F32 getTangent(const U32 index) const
size_t getVertexCount() const noexcept
void resizeVertexCount(const size_t size, const Vertex &defaultValue)
void fromBuffer(const VertexBuffer &other)
static size_t GetTotalDataSize(const AttributeFlags &usedAttributes)
bool getMinimalData(const vector< Vertex > &dataIn, Byte *dataOut, size_t dataOutBufferLength)
Trim down the Vertex vector to only upload the minimal amount of data to the GPU.
const vec3< F32 > & getPosition(const U32 index) const
void modifyBoneWeights(const U32 index, const FColour4 &weights)
bool serialize(ByteBuffer &dataOut) const
void modifyColourValue(const U32 index, const UColour4 &newValue)
void modifyTangentValue(const U32 index, const vec3< F32 > &newValue)
vec4< U8 > getBoneIndices(const U32 index) const
void reserveIndexCount(const size_t size)
static AttributeOffsets GetAttributeOffsets(const AttributeFlags &usedAttributes, size_t &totalDataSizeOut)
void modifyNormalValue(const U32 index, const vec3< F32 > &newValue)
void setVertexCount(const size_t size)
F32 getNormal(const U32 index) const
const vector< U32 > & getIndices() const noexcept
void modifyBoneIndices(const U32 index, const vec4< U8 > indices)
static constexpr U32 PRIMITIVE_RESTART_INDEX_S
void modifyPositionValue(const U32 index, const vec3< F32 > &newValue)
AttributeMap generateAttributeMap()
Activate and set all of the required vertex attributes.
vector< std::pair< size_t, size_t > > _partitions
vector< U32 > _indices
Used for creating an "IB". If it's empty, then an outside source should provide the indices.
void set(const T *v) noexcept
set the 2 components of the vector manually using a source pointer to a (large enough) array
vec3 & normalize() noexcept
transform the vector to unit length
void set(const T *v) noexcept
set the 3 components of the vector manually using a source pointer to a (large enough) array
F32 PACK_VEC3(F32_SNORM x, F32_SNORM y, F32_SNORM z) noexcept
void UNPACK_VEC3(F32 src, F32_SNORM &x, F32_SNORM &y, F32_SNORM &z) noexcept
void FillSmallData5(const vector< VertexBuffer::Vertex > &dataIn, Byte *dataOut) noexcept
void FillSmallData1(const vector< VertexBuffer::Vertex > &dataIn, Byte *dataOut, const bool normals, const bool tangents, const bool colour, const bool bones) noexcept
void FillSmallData2(const vector< VertexBuffer::Vertex > &dataIn, Byte *dataOut, const bool tangents, const bool colour, const bool bones) noexcept
void FillSmallData3(const vector< VertexBuffer::Vertex > &dataIn, Byte *dataOut, const bool colour, const bool bones) noexcept
void FillSmallData4(const vector< VertexBuffer::Vertex > &dataIn, Byte *dataOut, const bool bones) noexcept
void FillSmallData(const vector< VertexBuffer::Vertex > &dataIn, Byte *dataOut, const bool texCoords, const bool normals, const bool tangents, const bool colour, const bool bones) noexcept
Handle console commands that start with a forward slash.
constexpr U8 FLOAT_TO_CHAR_UNORM(F32_NORM value) noexcept
Returns round(value * 255)
vec2< T > Normalized(vec2< T > vector) noexcept
std::array< bool, to_base(AttribLocation::COUNT)> AttributeFlags
constexpr U32 to_U32(const T value)
constexpr F32_NORM UNORM_CHAR_TO_FLOAT(U8 value) noexcept
Returns value / 255.f.
constexpr U16 to_U16(const T value)
constexpr U16 BYTE_BUFFER_VERSION
eastl::vector< Type > vector
void unchecked_copy(eastl::vector< T, A1 > &dst, const eastl::vector< T, A2 > &src)
constexpr U64 _ID(const char *const str, const U64 value=val_64_const) noexcept
vec2< T > Cross(vec2< T > v1, vec2< T > v2) noexcept
general vec2 cross function
constexpr size_t to_size(const T value)
std::array< size_t, to_base(AttribLocation::COUNT)> AttributeOffsets
constexpr auto to_base(const Type value) -> Type
size_t _elementSize
Buffer primitive size in bytes.
BufferParams _bufferParams
bool lockRange(BufferRange range, SyncObjectHandle &sync) const
bool _allowDynamicUpdates