mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 05:38:31 +09:00
Merge commit '54826327' into dev
This commit is contained in:
@@ -36,7 +36,7 @@ namespace MobileGL {
|
||||
return m_bindingSlots[i];
|
||||
}
|
||||
}
|
||||
return m_bindingSlots[0]; // Fallback to the first slot if not found
|
||||
assert(false);
|
||||
}
|
||||
|
||||
void BufferState::MarkBufferObjectForDeletion(Uint index) {
|
||||
@@ -63,4 +63,4 @@ namespace MobileGL {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,8 +60,12 @@ namespace MobileGL {
|
||||
void GLContext::MarkBufferObjectForDeletion(Uint index) {
|
||||
if (ValidateBufferObject(index)) {
|
||||
auto bufferObject = m_bufferState.GetBufferObject(index);
|
||||
for (SizeT i = 0; i < m_vertexArrayState.GetAllVertexArrays().size(); ++i) {
|
||||
auto vao = m_vertexArrayState.GetAllVertexArrays()[i];
|
||||
auto& vaos = m_vertexArrayState.GetAllVertexArrays();
|
||||
for (SizeT i = 0; i < vaos.size(); ++i) {
|
||||
auto vao = vaos[i];
|
||||
if (vao == nullptr)
|
||||
continue;
|
||||
|
||||
if (vao->GetIndexBufferBindingSlot().GetBoundObject() == bufferObject) {
|
||||
vao->GetIndexBufferBindingSlot().Bind(nullptr);
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
SharedPtr<VertexArrayObject> VertexArrayState::GetVertexArrayObject(Uint index) {
|
||||
auto it = m_vertexArrays.find(index);
|
||||
if (it != m_vertexArrays.end()) {
|
||||
return it->second;
|
||||
}
|
||||
return nullptr;
|
||||
if (index >= m_vertexArrays.size())
|
||||
// FIXME: report a GL error here
|
||||
return nullptr;
|
||||
|
||||
return m_vertexArrays[index];
|
||||
}
|
||||
|
||||
Vector<Uint> VertexArrayState::GenerateNames(Uint number) {
|
||||
@@ -23,35 +23,37 @@ namespace MobileGL {
|
||||
|
||||
void VertexArrayState::Bind(Uint index) {
|
||||
if (index == 0) {
|
||||
// FIXME: should we make a dummy VAO at index 0?
|
||||
m_boundVertexArray = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
auto it = m_vertexArrays.find(index);
|
||||
if (it != m_vertexArrays.end()) {
|
||||
m_boundVertexArray = it->second;
|
||||
}
|
||||
else {
|
||||
m_boundVertexArray = nullptr;
|
||||
}
|
||||
m_boundVertexArray = GetVertexArrayObject(index);
|
||||
}
|
||||
|
||||
SharedPtr<VertexArrayObject> VertexArrayState::CreateVertexArrayObject(Uint index) {
|
||||
auto vao = MakeShared<VertexArrayObject>();
|
||||
m_vertexArrays[index] = vao;
|
||||
if (index >= m_vertexArrays.size()) {
|
||||
// power-of-2 reallocation
|
||||
m_vertexArrays.reserve(std::bit_ceil(index + 1));
|
||||
m_vertexArrays.resize(index + 1, nullptr);
|
||||
}
|
||||
auto vao = m_vertexArrays[index] = MakeShared<VertexArrayObject>();
|
||||
return vao;
|
||||
}
|
||||
|
||||
void VertexArrayState::MarkVertexArrayForDeletion(Uint index) {
|
||||
if (m_indexGenerator.IsValid(index)) {
|
||||
if (m_boundVertexArray && m_vertexArrays.find(index) != m_vertexArrays.end() &&
|
||||
m_vertexArrays[index] == m_boundVertexArray) {
|
||||
if (m_boundVertexArray) {
|
||||
m_boundVertexArray = nullptr;
|
||||
}
|
||||
|
||||
m_vertexArrays.erase(index);
|
||||
if (ValidateVertexArrayObject(index)) {
|
||||
m_vertexArrays[index] = nullptr;
|
||||
}
|
||||
|
||||
m_indexGenerator.Delete(index);
|
||||
}
|
||||
// FIXME: report GL error here?
|
||||
}
|
||||
|
||||
bool VertexArrayState::ValidateName(Uint index) const {
|
||||
@@ -59,20 +61,15 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
bool VertexArrayState::ValidateVertexArrayObject(Uint index) const {
|
||||
return m_vertexArrays.find(index) != m_vertexArrays.end();
|
||||
return index < m_vertexArrays.size() && m_vertexArrays[index] != nullptr;
|
||||
}
|
||||
|
||||
SharedPtr<VertexArrayObject> VertexArrayState::GetBoundVertexArray() {
|
||||
return m_boundVertexArray;
|
||||
}
|
||||
|
||||
Vector<SharedPtr<VertexArrayObject>> VertexArrayState::GetAllVertexArrays() {
|
||||
Vector<SharedPtr<VertexArrayObject>> arrays;
|
||||
arrays.reserve(m_vertexArrays.size());
|
||||
for (const auto& pair : m_vertexArrays) {
|
||||
arrays.push_back(pair.second);
|
||||
}
|
||||
return arrays;
|
||||
Vector<SharedPtr<VertexArrayObject>>& VertexArrayState::GetAllVertexArrays() {
|
||||
return m_vertexArrays;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@ namespace MobileGL {
|
||||
bool ValidateName(Uint index) const;
|
||||
bool ValidateVertexArrayObject(Uint index) const;
|
||||
SharedPtr<VertexArrayObject> GetBoundVertexArray();
|
||||
Vector<SharedPtr<VertexArrayObject>> GetAllVertexArrays();
|
||||
Vector<SharedPtr<VertexArrayObject>>& GetAllVertexArrays();
|
||||
|
||||
private:
|
||||
UnorderedMap<Uint, SharedPtr<VertexArrayObject>> m_vertexArrays;
|
||||
Vector<SharedPtr<VertexArrayObject>> m_vertexArrays;
|
||||
IndexGenerator<Uint> m_indexGenerator;
|
||||
SharedPtr<VertexArrayObject> m_boundVertexArray;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user