Changing vertex data interfaces
This commit is contained in:
@@ -228,8 +228,8 @@ void DepthCullingPass::render() {
|
||||
void DepthCullingPass::endFrame() {}
|
||||
|
||||
void DepthCullingPass::publishOutputs() {
|
||||
uint32 width = (viewport->getOwner()->getFramebufferWidth() + BLOCK_SIZE - 1) / BLOCK_SIZE;
|
||||
uint32 height = (viewport->getOwner()->getFramebufferHeight() + BLOCK_SIZE - 1) / BLOCK_SIZE;
|
||||
uint32 width = viewport->getOwner()->getFramebufferWidth();
|
||||
uint32 height = viewport->getOwner()->getFramebufferHeight();
|
||||
uint32 bufferSize = 0;
|
||||
while (width > 1 && height > 1) {
|
||||
mipOffsets.add(bufferSize);
|
||||
|
||||
@@ -16,67 +16,37 @@ StaticMeshVertexData* StaticMeshVertexData::getInstance() {
|
||||
return &instance;
|
||||
}
|
||||
|
||||
void StaticMeshVertexData::loadPositions(MeshId id, const Array<Vector4>& data) {
|
||||
uint64 offset;
|
||||
{
|
||||
std::unique_lock l(mutex);
|
||||
offset = meshOffsets[id];
|
||||
}
|
||||
void StaticMeshVertexData::loadPositions(uint64 offset, const Array<Vector4>& data) {
|
||||
assert(offset + data.size() <= head);
|
||||
std::memcpy(positionData.data() + offset, data.data(), data.size() * sizeof(Vector4));
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void StaticMeshVertexData::loadTexCoords(MeshId id, uint64 index, const Array<Vector2>& data) {
|
||||
uint64 offset;
|
||||
{
|
||||
std::unique_lock l(mutex);
|
||||
offset = meshOffsets[id];
|
||||
}
|
||||
void StaticMeshVertexData::loadTexCoords(uint64 offset, uint64 index, const Array<Vector2>& data) {
|
||||
assert(offset + data.size() <= head);
|
||||
std::memcpy(texCoordsData[index].data() + offset, data.data(), data.size() * sizeof(Vector2));
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void StaticMeshVertexData::loadNormals(MeshId id, const Array<Vector4>& data) {
|
||||
uint64 offset;
|
||||
{
|
||||
std::unique_lock l(mutex);
|
||||
offset = meshOffsets[id];
|
||||
}
|
||||
void StaticMeshVertexData::loadNormals(uint64 offset, const Array<Vector4>& data) {
|
||||
assert(offset + data.size() <= head);
|
||||
std::memcpy(normalData.data() + offset, data.data(), data.size() * sizeof(Vector4));
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void StaticMeshVertexData::loadTangents(MeshId id, const Array<Vector4>& data) {
|
||||
uint64 offset;
|
||||
{
|
||||
std::unique_lock l(mutex);
|
||||
offset = meshOffsets[id];
|
||||
}
|
||||
void StaticMeshVertexData::loadTangents(uint64 offset, const Array<Vector4>& data) {
|
||||
assert(offset + data.size() <= head);
|
||||
std::memcpy(tangentData.data() + offset, data.data(), data.size() * sizeof(Vector4));
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void StaticMeshVertexData::loadBiTangents(MeshId id, const Array<Vector4>& data) {
|
||||
uint64 offset;
|
||||
{
|
||||
std::unique_lock l(mutex);
|
||||
offset = meshOffsets[id];
|
||||
}
|
||||
void StaticMeshVertexData::loadBiTangents(uint64 offset, const Array<Vector4>& data) {
|
||||
assert(offset + data.size() <= head);
|
||||
std::memcpy(biTangentData.data() + offset, data.data(), data.size() * sizeof(Vector4));
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void Seele::StaticMeshVertexData::loadColors(MeshId id, const Array<Vector4>& data) {
|
||||
uint64 offset;
|
||||
{
|
||||
std::unique_lock l(mutex);
|
||||
offset = meshOffsets[id];
|
||||
}
|
||||
void Seele::StaticMeshVertexData::loadColors(uint64 offset, const Array<Vector4>& data) {
|
||||
assert(offset + data.size() <= head);
|
||||
std::memcpy(colorData.data() + offset, data.data(), data.size() * sizeof(Vector4));
|
||||
dirty = true;
|
||||
@@ -85,7 +55,7 @@ void Seele::StaticMeshVertexData::loadColors(MeshId id, const Array<Vector4>& da
|
||||
void StaticMeshVertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) {
|
||||
uint64 offset;
|
||||
{
|
||||
std::unique_lock l(mutex);
|
||||
std::unique_lock l(vertexDataLock);
|
||||
offset = meshOffsets[id];
|
||||
}
|
||||
Array<Vector4> pos(numVertices);
|
||||
@@ -112,11 +82,16 @@ void StaticMeshVertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveB
|
||||
}
|
||||
|
||||
void StaticMeshVertexData::deserializeMesh(MeshId id, ArchiveBuffer& buffer) {
|
||||
uint64 offset;
|
||||
{
|
||||
std::unique_lock l(vertexDataLock);
|
||||
offset = meshOffsets[id];
|
||||
}
|
||||
Array<Vector4> pos;
|
||||
Array<Vector2> tex[MAX_TEXCOORDS];
|
||||
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
|
||||
Serialization::load(buffer, tex[i]);
|
||||
loadTexCoords(id, i, tex[i]);
|
||||
loadTexCoords(offset, i, tex[i]);
|
||||
}
|
||||
Array<Vector4> nor;
|
||||
Array<Vector4> tan;
|
||||
@@ -127,11 +102,11 @@ void StaticMeshVertexData::deserializeMesh(MeshId id, ArchiveBuffer& buffer) {
|
||||
Serialization::load(buffer, tan);
|
||||
Serialization::load(buffer, bit);
|
||||
Serialization::load(buffer, col);
|
||||
loadPositions(id, pos);
|
||||
loadNormals(id, nor);
|
||||
loadTangents(id, tan);
|
||||
loadBiTangents(id, bit);
|
||||
loadColors(id, col);
|
||||
loadPositions(offset, pos);
|
||||
loadNormals(offset, nor);
|
||||
loadTangents(offset, tan);
|
||||
loadBiTangents(offset, bit);
|
||||
loadColors(offset, col);
|
||||
}
|
||||
|
||||
void StaticMeshVertexData::init(Gfx::PGraphics _graphics) {
|
||||
|
||||
@@ -22,12 +22,12 @@ class StaticMeshVertexData : public VertexData {
|
||||
StaticMeshVertexData();
|
||||
virtual ~StaticMeshVertexData();
|
||||
static StaticMeshVertexData* getInstance();
|
||||
void loadPositions(MeshId id, const Array<Vector4>& data);
|
||||
void loadTexCoords(MeshId id, uint64 index, const Array<Vector2>& data);
|
||||
void loadNormals(MeshId id, const Array<Vector4>& data);
|
||||
void loadTangents(MeshId id, const Array<Vector4>& data);
|
||||
void loadBiTangents(MeshId id, const Array<Vector4>& data);
|
||||
void loadColors(MeshId id, const Array<Vector4>& data);
|
||||
void loadPositions(uint64 offset, const Array<Vector4>& data);
|
||||
void loadTexCoords(uint64 offset, uint64 index, const Array<Vector2>& data);
|
||||
void loadNormals(uint64 offset, const Array<Vector4>& data);
|
||||
void loadTangents(uint64 offset, const Array<Vector4>& data);
|
||||
void loadBiTangents(uint64 offset, const Array<Vector4>& data);
|
||||
void loadColors(uint64 offset, const Array<Vector4>& data);
|
||||
virtual void serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) override;
|
||||
virtual void deserializeMesh(MeshId id, ArchiveBuffer& buffer) override;
|
||||
virtual void init(Gfx::PGraphics graphics) override;
|
||||
@@ -44,7 +44,6 @@ class StaticMeshVertexData : public VertexData {
|
||||
virtual void updateBuffers() override;
|
||||
Array<StaticMatData> staticData;
|
||||
|
||||
std::mutex mutex;
|
||||
Gfx::OShaderBuffer positions;
|
||||
Array<Vector4> positionData;
|
||||
Gfx::OShaderBuffer texCoords[MAX_TEXCOORDS];
|
||||
|
||||
@@ -294,8 +294,9 @@ void VertexData::commitMeshes() {
|
||||
MeshId VertexData::allocateVertexData(uint64 numVertices) {
|
||||
std::unique_lock l(vertexDataLock);
|
||||
MeshId res{idCounter++};
|
||||
meshOffsets[res] = head;
|
||||
meshVertexCounts[res] = numVertices;
|
||||
meshOffsets.add(head);
|
||||
meshVertexCounts.add(numVertices);
|
||||
meshData.add({});
|
||||
head += numVertices;
|
||||
if (head > verticesAllocated) {
|
||||
verticesAllocated = std::max(head, verticesAllocated + NUM_DEFAULT_ELEMENTS);
|
||||
|
||||
@@ -15,6 +15,7 @@ DECLARE_REF(MaterialInstance)
|
||||
DECLARE_REF(Mesh)
|
||||
struct MeshId {
|
||||
uint64 id;
|
||||
operator uint64() const { return id; }
|
||||
std::strong_ordering operator<=>(const MeshId& other) const { return id <=> other.id; }
|
||||
bool operator==(const MeshId& other) const { return id == other.id; }
|
||||
};
|
||||
@@ -102,9 +103,9 @@ class VertexData {
|
||||
Array<TransparentDraw> transparentData;
|
||||
|
||||
std::mutex vertexDataLock;
|
||||
Map<MeshId, MeshData> meshData;
|
||||
Map<MeshId, uint64> meshOffsets;
|
||||
Map<MeshId, uint64> meshVertexCounts;
|
||||
Array<MeshData> meshData;
|
||||
Array<uint64> meshOffsets;
|
||||
Array<uint64> meshVertexCounts;
|
||||
|
||||
Array<MeshletDescription> meshlets;
|
||||
Array<uint8> primitiveIndices;
|
||||
|
||||
@@ -192,10 +192,9 @@ void Buffer::readContents(uint64 regionOffset, uint64 regionSize, void* buffer)
|
||||
}
|
||||
|
||||
void Buffer::rotateBuffer(uint64 size, bool preserveContents) {
|
||||
if (size == 0)
|
||||
return;
|
||||
assert(dynamic);
|
||||
if (buffers.size() > 0) {
|
||||
size = std::max(getSize(), size);
|
||||
}
|
||||
for (uint32 i = 0; i < buffers.size(); ++i) {
|
||||
if (buffers[i]->isCurrentlyBound()) {
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user