mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 21:58:31 +09:00
[Feat] (MG_State/VertexArrayState): Replace dirty mark with resource version for VA.
This commit is contained in:
@@ -22,20 +22,20 @@ namespace MobileGL {
|
|||||||
attr.Offset = 0;
|
attr.Offset = 0;
|
||||||
attr.Buffer = nullptr;
|
attr.Buffer = nullptr;
|
||||||
|
|
||||||
MarkAttributeDirty(index);
|
BumpAttributeFormatVersion(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexArrayObject::EnableAttribute(Uint index) {
|
void VertexArrayObject::EnableAttribute(Uint index) {
|
||||||
if (index >= MAX_VERTEX_ATTRIBS) return;
|
if (index >= MAX_VERTEX_ATTRIBS) return;
|
||||||
m_attributes[index].Enabled = true;
|
m_attributes[index].Enabled = true;
|
||||||
MarkAttributeDirty(index);
|
BumpAttributeFormatVersion(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexArrayObject::DisableAttribute(Uint index) {
|
void VertexArrayObject::DisableAttribute(Uint index) {
|
||||||
if (index >= MAX_VERTEX_ATTRIBS) return;
|
if (index >= MAX_VERTEX_ATTRIBS) return;
|
||||||
m_attributes[index].Enabled = false;
|
m_attributes[index].Enabled = false;
|
||||||
MarkAttributeDirty(index);
|
BumpAttributeFormatVersion(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bool VertexArrayObject::IsAttributeEnabled(Uint index) const {
|
Bool VertexArrayObject::IsAttributeEnabled(Uint index) const {
|
||||||
@@ -59,13 +59,13 @@ namespace MobileGL {
|
|||||||
attr.Offset = offset;
|
attr.Offset = offset;
|
||||||
attr.IsInteger = isInteger;
|
attr.IsInteger = isInteger;
|
||||||
|
|
||||||
MarkAttributeDirty(index);
|
BumpAttributeFormatVersion(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexArrayObject::BindAttributeBuffer(Uint index, const SharedPtr<BufferObject>& buffer) {
|
void VertexArrayObject::BindAttributeBuffer(Uint index, const SharedPtr<BufferObject>& buffer) {
|
||||||
if (index >= MAX_VERTEX_ATTRIBS) return;
|
if (index >= MAX_VERTEX_ATTRIBS) return;
|
||||||
m_attributes[index].Buffer = buffer;
|
m_attributes[index].Buffer = buffer;
|
||||||
MarkAttributeDirty(index);
|
BumpAttributeBufferVersion(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
BindingSlot<BufferObject>& VertexArrayObject::GetIndexBufferBindingSlot() {
|
BindingSlot<BufferObject>& VertexArrayObject::GetIndexBufferBindingSlot() {
|
||||||
@@ -83,22 +83,6 @@ namespace MobileGL {
|
|||||||
return m_attributes;
|
return m_attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexArrayObject::MarkAttributeDirty(Uint index) {
|
|
||||||
if (index >= MAX_VERTEX_ATTRIBS) return;
|
|
||||||
if (std::find(m_dirtyAttributes.begin(), m_dirtyAttributes.end(), index) != m_dirtyAttributes.end()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_dirtyAttributes.push_back(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
const Vector<Uint>& VertexArrayObject::GetDirtyAttributeIndices() const {
|
|
||||||
return m_dirtyAttributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VertexArrayObject::ClearDirtyAttributes() {
|
|
||||||
m_dirtyAttributes.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint VertexArrayObject::GetExternalIndex() const {
|
Uint VertexArrayObject::GetExternalIndex() const {
|
||||||
return m_externalIndex;
|
return m_externalIndex;
|
||||||
}
|
}
|
||||||
@@ -107,13 +91,34 @@ namespace MobileGL {
|
|||||||
if (index >= MAX_VERTEX_ATTRIBS) return;
|
if (index >= MAX_VERTEX_ATTRIBS) return;
|
||||||
if (m_attributes[index].Divisor == divisor) return;
|
if (m_attributes[index].Divisor == divisor) return;
|
||||||
m_attributes[index].Divisor = divisor;
|
m_attributes[index].Divisor = divisor;
|
||||||
MarkAttributeDirty(index);
|
BumpAttributeFormatVersion(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint VertexArrayObject::GetAttributeDivisor(Uint index) const {
|
Uint VertexArrayObject::GetAttributeDivisor(Uint index) const {
|
||||||
if (index >= MAX_VERTEX_ATTRIBS) return 0;
|
if (index >= MAX_VERTEX_ATTRIBS) return 0;
|
||||||
return m_attributes[index].Divisor;
|
return m_attributes[index].Divisor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VertexArrayObject::BumpAttributeFormatVersion(Uint index) {
|
||||||
|
if (index >= MAX_VERTEX_ATTRIBS) return;
|
||||||
|
++m_attributeVersions[index].FormatVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VertexArrayObject::BumpAttributeBufferVersion(Uint index) {
|
||||||
|
if (index >= MAX_VERTEX_ATTRIBS) return;
|
||||||
|
++m_attributeVersions[index].BufferVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
const VertexAttributeVersion& VertexArrayObject::GetAttributeVersion(Uint index) const {
|
||||||
|
static VertexAttributeVersion emptyVersion;
|
||||||
|
if (index >= MAX_VERTEX_ATTRIBS) return emptyVersion;
|
||||||
|
return m_attributeVersions[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
const Array<VertexAttributeVersion, VertexArrayObject::MAX_VERTEX_ATTRIBS>& VertexArrayObject::
|
||||||
|
GetAllAttributeVersions() const {
|
||||||
|
return m_attributeVersions;
|
||||||
|
}
|
||||||
} // namespace GLState
|
} // namespace GLState
|
||||||
} // namespace MG_State
|
} // namespace MG_State
|
||||||
} // namespace MobileGL
|
} // namespace MobileGL
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Includes.h>
|
#include <Includes.h>
|
||||||
#include "../BufferState/BufferObject.h"
|
#include "../BufferState/BufferObject.h"
|
||||||
|
#include "MG_Util/Types.h"
|
||||||
|
|
||||||
namespace MobileGL {
|
namespace MobileGL {
|
||||||
namespace MG_State {
|
namespace MG_State {
|
||||||
@@ -25,6 +26,11 @@ namespace MobileGL {
|
|||||||
SharedPtr<BufferObject> Buffer;
|
SharedPtr<BufferObject> Buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct VertexAttributeVersion {
|
||||||
|
Uint16 FormatVersion = 0;
|
||||||
|
Uint16 BufferVersion = 0;
|
||||||
|
};
|
||||||
|
|
||||||
class VertexArrayObject {
|
class VertexArrayObject {
|
||||||
public:
|
public:
|
||||||
static constexpr int MAX_VERTEX_ATTRIBS = 16;
|
static constexpr int MAX_VERTEX_ATTRIBS = 16;
|
||||||
@@ -45,19 +51,21 @@ namespace MobileGL {
|
|||||||
const VertexAttribute& GetAttribute(Uint index) const;
|
const VertexAttribute& GetAttribute(Uint index) const;
|
||||||
const Array<VertexAttribute, MAX_VERTEX_ATTRIBS>& GetAllAttributes() const;
|
const Array<VertexAttribute, MAX_VERTEX_ATTRIBS>& GetAllAttributes() const;
|
||||||
|
|
||||||
const Vector<Uint>& GetDirtyAttributeIndices() const;
|
|
||||||
void ClearDirtyAttributes();
|
|
||||||
Uint GetExternalIndex() const;
|
Uint GetExternalIndex() const;
|
||||||
|
|
||||||
void SetAttributeDivisor(Uint index, Uint divisor);
|
void SetAttributeDivisor(Uint index, Uint divisor);
|
||||||
Uint GetAttributeDivisor(Uint index) const;
|
Uint GetAttributeDivisor(Uint index) const;
|
||||||
|
|
||||||
|
const VertexAttributeVersion& GetAttributeVersion(Uint index) const;
|
||||||
|
const Array<VertexAttributeVersion, MAX_VERTEX_ATTRIBS>& GetAllAttributeVersions() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void MarkAttributeDirty(Uint index);
|
void BumpAttributeFormatVersion(Uint index);
|
||||||
|
void BumpAttributeBufferVersion(Uint index);
|
||||||
|
|
||||||
const Uint m_externalIndex = 0;
|
const Uint m_externalIndex = 0;
|
||||||
Array<VertexAttribute, MAX_VERTEX_ATTRIBS> m_attributes;
|
Array<VertexAttribute, MAX_VERTEX_ATTRIBS> m_attributes;
|
||||||
Vector<Uint> m_dirtyAttributes;
|
Array<VertexAttributeVersion, MAX_VERTEX_ATTRIBS> m_attributeVersions; // format version, buffer version
|
||||||
BindingSlot<BufferObject> m_indexBufferBindingSlot;
|
BindingSlot<BufferObject> m_indexBufferBindingSlot;
|
||||||
};
|
};
|
||||||
} // namespace GLState
|
} // namespace GLState
|
||||||
|
|||||||
Reference in New Issue
Block a user