use unordered_dense to mitigate __next_prime overflow error

This commit is contained in:
2025-05-07 10:57:26 +08:00
parent 96774ef3da
commit b082e2e06b
9 changed files with 2142 additions and 34 deletions
+14 -11
View File
@@ -13,25 +13,21 @@ VertexArrayState::VertexArrayState() {
GLenum VertexArrayState::Create(GLuint* array) {
if (array == nullptr) return GL_INVALID_VALUE;
GLuint id = freeIds_.empty() ? ++lastId_ : *freeIds_.begin();
if (!freeIds_.empty()) {
freeIds_.erase(freeIds_.begin());
GLuint id = freeId_.empty() ? lastId_++ : freeId_.back();
if (!freeId_.empty()) {
freeId_.pop_back();
}
*array = id;
// vaos_[id].generated = true;
vaos_[id] = { .generated = false };
return GL_NO_ERROR;
}
GLenum VertexArrayState::CreateN(GLsizei n, GLuint* arrays) {
if (n < 0) {
if (n <= 0 || arrays == nullptr) {
return GL_INVALID_VALUE;
}
if (n > 0 && arrays == nullptr) {
return GL_INVALID_VALUE;
}
for (GLsizei i = 0; i < n; ++i) {
if (GLenum error = Create(&arrays[i]); error != GL_NO_ERROR) {
return error;
@@ -41,7 +37,9 @@ GLenum VertexArrayState::CreateN(GLsizei n, GLuint* arrays) {
}
GLenum VertexArrayState::Bind(GLuint array) {
if (array != 0 && vaos_.find(array) == vaos_.end()) return GL_INVALID_OPERATION;
if (array != 0 && vaos_.find(array) == vaos_.end())
return GL_INVALID_OPERATION;
currentVao_ = array;
GetCurrentVAO()->generated = true;
return GL_NO_ERROR;
@@ -92,5 +90,10 @@ GLuint VertexArrayState::GetBoundElementBuffer() {
VertexArrayObject* VertexArrayState::GetCurrentVAO() {
auto it = vaos_.find(currentVao_);
return (it != vaos_.end()) ? &it->second : &vaos_.at(0);
if (it != vaos_.end())
return &it->second;
else {
MG_Util::Debug::LogD("%s: VAO not found, currentVao_ = %u !", __func__, currentVao_);
return nullptr;
}
}