mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-08 04:08:32 +09:00
use unordered_dense to mitigate __next_prime overflow error
This commit is contained in:
+3
-3
@@ -8,13 +8,13 @@ set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -fvisibility=hidden -funwind-tables -g -D_THREAD_SAFE -fPIC -stdlib=libc++")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -fvisibility=hidden -funwind-tables -g -D_THREAD_SAFE -fPIC")
|
||||
|
||||
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w -g -std=gnu99 -funwind-tables -O3 -fvisibility=hidden")
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
|
||||
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
|
||||
|
||||
set(CMAKE_ANDROID_STL_TYPE c++_static)
|
||||
#set(CMAKE_ANDROID_STL_TYPE c++_static)
|
||||
|
||||
#set(CMAKE_BUILD_TYPE Release)
|
||||
|
||||
|
||||
@@ -108,6 +108,7 @@
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
#include "GLES3/gl32.h"
|
||||
#include <ankerl/unordered_dense.h>
|
||||
|
||||
#include "MG_Include/UncertainBool.hpp"
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -45,8 +45,9 @@ public:
|
||||
|
||||
public: // TODO
|
||||
std::unordered_map<GLuint, VertexArrayObject> vaos_;
|
||||
std::set<GLuint> freeIds_;
|
||||
GLuint lastId_ = 0;
|
||||
// std::set<GLuint> freeIds_;
|
||||
std::vector<GLuint> freeId_;
|
||||
GLuint lastId_ = 1; // reserve 0 for default vao
|
||||
GLuint currentVao_ = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -280,8 +280,8 @@ namespace MG_RHI::GLES {
|
||||
SyncAllBuffersToGLES(bufferState);
|
||||
|
||||
// VAO
|
||||
GLuint mgVAO = vaState->currentVao_;
|
||||
VertexArrayObject* vao = &vaState->vaos_[vaState->currentVao_];
|
||||
GLuint mgVAOId = vaState->currentVao_;
|
||||
VertexArrayObject* vao = &vaState->vaos_[mgVAOId];
|
||||
for (auto& [mgVAOId, mgVAO] : vaState->vaos_) {
|
||||
MG_Util::Debug::LogD("Uploading VAO: %d", mgVAOId);
|
||||
if (!mgVAO.generated) continue;
|
||||
@@ -290,6 +290,7 @@ namespace MG_RHI::GLES {
|
||||
GLuint glVAO;
|
||||
if (vaoMap_.find(mgVAOId) == vaoMap_.end()) {
|
||||
MGL_TRY(::GLES::glGenVertexArrays(1, &glVAO);)
|
||||
MG_Util::Debug::LogD("Saving VAO: %d -> %d", mgVAOId, glVAO);
|
||||
vaoMap_[mgVAOId] = glVAO;
|
||||
} else {
|
||||
glVAO = vaoMap_[mgVAOId];
|
||||
@@ -301,7 +302,7 @@ namespace MG_RHI::GLES {
|
||||
}
|
||||
|
||||
for (auto& [index, attrib] : mgVAO.attribs) {
|
||||
MG_Util::Debug::LogD("attrib #%s, type = %s, size = %d, stride = %d, pointer = %p",
|
||||
MG_Util::Debug::LogD("attrib #%d, type = %s, size = %d, stride = %d, pointer = %p",
|
||||
index, MG_Util::Debug::GLEnumToString(attrib.type), attrib.size, attrib.stride, attrib.pointer);
|
||||
if (attrib.buffer != 0 && bufferMap_.count(attrib.buffer)) {
|
||||
MGL_TRY(::GLES::glBindBuffer(GL_ARRAY_BUFFER, bufferMap_[attrib.buffer]);)
|
||||
@@ -329,11 +330,11 @@ namespace MG_RHI::GLES {
|
||||
MGL_TRY(::GLES::glBindVertexArray(0);)
|
||||
//}
|
||||
}
|
||||
GLuint currentMgVAO = vaState->currentVao_;
|
||||
if (vaoMap_.count(currentMgVAO)) {
|
||||
MGL_TRY(::GLES::glBindVertexArray(vaoMap_[currentMgVAO]);)
|
||||
// GLuint currentMgVAO = vaState->currentVao_;
|
||||
if (vaoMap_.find(mgVAOId) != vaoMap_.end()) {
|
||||
MGL_TRY(::GLES::glBindVertexArray(vaoMap_[mgVAOId]);)
|
||||
|
||||
VertexArrayObject& currentVAO = vaState->vaos_[currentMgVAO];
|
||||
VertexArrayObject& currentVAO = vaState->vaos_[mgVAOId];
|
||||
for (auto& [index, attrib] : currentVAO.attribs) {
|
||||
if (attrib.enabled) {
|
||||
MGL_TRY(::GLES::glEnableVertexAttribArray(index);)
|
||||
@@ -623,8 +624,6 @@ namespace MG_RHI::GLES {
|
||||
|
||||
lastBoundFBO = currentFBO;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-7
@@ -8,6 +8,9 @@
|
||||
#include "../../Includes.h"
|
||||
|
||||
namespace MG_RHI::GLES {
|
||||
template <typename K, typename V>
|
||||
using unordered_map = ankerl::unordered_dense::map<K, V>;
|
||||
|
||||
enum class State {
|
||||
None,
|
||||
DrawArrays,
|
||||
@@ -30,14 +33,14 @@ namespace MG_RHI::GLES {
|
||||
private:
|
||||
|
||||
State currentState_ = State::None;
|
||||
std::unordered_map<GLuint, GLuint> textureMap_;
|
||||
std::unordered_map<GLuint, std::unordered_map<GLint, bool>> textureLevelUploaded_;
|
||||
std::unordered_map<GLuint, GLuint> bufferMap_;
|
||||
std::array<GLuint, 32> lastBoundTextures { 0 };
|
||||
std::unordered_map<GLuint, GLuint> vaoMap_;
|
||||
unordered_map<GLuint, GLuint> textureMap_;
|
||||
unordered_map<GLuint, GLuint> bufferMap_;
|
||||
unordered_map<GLuint, GLuint> vaoMap_;
|
||||
unordered_map<GLuint, GLuint> programMap_;
|
||||
unordered_map<GLuint, GLuint> framebufferMap_;
|
||||
|
||||
std::unordered_map<GLuint, GLuint> programMap_;
|
||||
std::unordered_map<GLuint, GLuint> framebufferMap_;
|
||||
unordered_map<GLuint, unordered_map<GLint, bool>> textureLevelUploaded_;
|
||||
std::array<GLuint, 32> lastBoundTextures { 0 };
|
||||
|
||||
GLuint lastBoundVAO = 0;
|
||||
GLuint lastBoundProgram = 0;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "../../Includes.h"
|
||||
|
||||
#define FORCE_SYNC_WITH_LOG_FILE 0
|
||||
#define FORCE_SYNC_WITH_LOG_FILE 1
|
||||
|
||||
namespace MG_Util {
|
||||
namespace Debug {
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ android {
|
||||
minSdk 26
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
ndkVersion '27.1.12297006'
|
||||
ndkVersion '27.2.12479018'
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user