diff --git a/MG/Constants.h b/MG/Constants.h index 4e7a4882..da68874a 100644 --- a/MG/Constants.h +++ b/MG/Constants.h @@ -98,6 +98,10 @@ namespace MG_Constants { }; // OpenGL 3 } + namespace VertexArray { + constexpr uint32_t MAX_VERTEX_ATTRIBS = 32; + } + namespace PixelStore { static const MG_Global::unordered_map DEFAULT_VALUES_MAP = { {GL_PACK_SWAP_BYTES, GL_FALSE}, diff --git a/MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.cpp b/MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.cpp index 9768b1b0..80364a06 100644 --- a/MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.cpp +++ b/MG/MG_GL/Implementations/EGL/Diligent/EGL_impl.cpp @@ -33,7 +33,9 @@ namespace MG_Diligent { auto& programObj = MG_State_T::programState->programs_[program]; - for (const auto& [attribIndex, attrib] : vaState.vaos_[vaState.currentVao_].attribs) { +// for (const auto& [attribIndex, attrib] : vaState.vaos_[vaState.currentVao_].attribs) { + for (uint32_t attribIndex = 0; attribIndex < MG_Constants::VertexArray::MAX_VERTEX_ATTRIBS; ++attribIndex) { + const auto& attrib = vaState.vaos_[vaState.currentVao_].attribs[attribIndex]; if (!attrib.enabled) continue; std::string attribName; @@ -124,15 +126,11 @@ namespace MG_Diligent { hash_combine(hash, capabilities[GL_STENCIL_TEST]); auto *pVAO = vaState.GetCurrentVAO(); - - std::vector attribIndices; - for (const auto& [index, _] : pVAO->attribs) - attribIndices.push_back(index); - std::sort(attribIndices.begin(), attribIndices.end()); - for (auto index : attribIndices) { - const auto& attrib = pVAO->attribs.at(index); + + for (uint32_t i = 0; i < MG_Constants::VertexArray::MAX_VERTEX_ATTRIBS; ++i) { + const auto& attrib = pVAO->attribs[i]; if (attrib.enabled) { - hash_combine(hash, index); + hash_combine(hash, i); hash_combine(hash, attrib.size); hash_combine(hash, attrib.type); hash_combine(hash, attrib.normalized); diff --git a/MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp b/MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp index 1b7f713a..80aa9a95 100644 --- a/MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp +++ b/MG/MG_GL/Implementations/GL/Drawing/GL_Drawing.cpp @@ -476,7 +476,9 @@ namespace MG_GL::GL { std::unordered_map createdBuffers; - for (const auto& [attribIndex, attrib] : pVAO->attribs) { +// for (const auto& [attribIndex, attrib] : pVAO->attribs) { + for (uint32_t attribIndex = 0; attribIndex < MG_Constants::VertexArray::MAX_VERTEX_ATTRIBS; ++attribIndex) { + const auto& attrib = pVAO->attribs[attribIndex]; if (!attrib.enabled || attrib.buffer == 0) continue; GLuint buffer = attrib.buffer; @@ -569,7 +571,8 @@ namespace MG_GL::GL { std::vector vertexBuffers; std::vector offsets; - for (const auto& [attribIndex, attrib] : pVAO->attribs) { + for (uint32_t attribIndex = 0; attribIndex < MG_Constants::VertexArray::MAX_VERTEX_ATTRIBS; ++attribIndex) { + const auto& attrib = pVAO->attribs[attribIndex]; if (!attrib.enabled || attrib.buffer == 0) continue; GLuint buffer = attrib.buffer; diff --git a/MG/MG_GL/Implementations/GL/Program/GL_Program.cpp b/MG/MG_GL/Implementations/GL/Program/GL_Program.cpp index eef2d54a..0b9808fb 100644 --- a/MG/MG_GL/Implementations/GL/Program/GL_Program.cpp +++ b/MG/MG_GL/Implementations/GL/Program/GL_Program.cpp @@ -379,7 +379,9 @@ namespace MG_GL::GL { auto* pVAO = MG_State_T::vertexArrayState->GetCurrentVAO(); if (!pVAO) return; - for (const auto& [index, attrib] : pVAO->attribs) { +// for (const auto& [index, attrib] : pVAO->attribs) { + for (uint32_t index = 0; index < MG_Constants::VertexArray::MAX_VERTEX_ATTRIBS; ++index) { + const auto& attrib = pVAO->attribs[index]; if (attrib.enabled) { Diligent::LayoutElement elem; elem.InputIndex = index; diff --git a/MG/MG_GL/State/VertexArray/VertexArrayState.cpp b/MG/MG_GL/State/VertexArray/VertexArrayState.cpp index 59e9199f..eae9b552 100644 --- a/MG/MG_GL/State/VertexArray/VertexArrayState.cpp +++ b/MG/MG_GL/State/VertexArray/VertexArrayState.cpp @@ -107,7 +107,7 @@ bool VertexArrayState::ValidateAllocatedHandle(GLuint array) { GLenum VertexArrayState::EnableAttrib(GLuint index) { if (!ValidateAllocatedHandle(currentVao_)) return GL_INVALID_OPERATION; - if (index >= GL_MAX_VERTEX_ATTRIBS) return GL_INVALID_VALUE; + if (index >= MG_Constants::VertexArray::MAX_VERTEX_ATTRIBS) return GL_INVALID_VALUE; GetCurrentVAO()->attribs[index].enabled = true; MG_Util::Debug::LogD("Attrib vaos_[%u].attribs[%u].enabled = %d", currentVao_, index, vaos_[currentVao_].attribs[index].enabled); @@ -118,7 +118,7 @@ GLenum VertexArrayState::EnableAttrib(GLuint index) { GLenum VertexArrayState::DisableAttrib(GLuint index) { if (!ValidateAllocatedHandle(currentVao_)) return GL_INVALID_OPERATION; - if (index >= GL_MAX_VERTEX_ATTRIBS) return GL_INVALID_VALUE; + if (index >= MG_Constants::VertexArray::MAX_VERTEX_ATTRIBS) return GL_INVALID_VALUE; GetCurrentVAO()->attribs[index].enabled = false; MG_Util::Debug::LogD("Attrib vaos_[%u].attribs[%u].enabled = %d", currentVao_, index, vaos_[currentVao_].attribs[index].enabled); @@ -132,7 +132,7 @@ GLenum VertexArrayState::SetAttribPointer(GLuint index, GLint size, GLenum type, GLuint currentArrayBuffer) { if (!ValidateAllocatedHandle(currentVao_)) return GL_INVALID_OPERATION; - if (index >= GL_MAX_VERTEX_ATTRIBS) return GL_INVALID_VALUE; + if (index >= MG_Constants::VertexArray::MAX_VERTEX_ATTRIBS) return GL_INVALID_VALUE; VertexAttribState state; state.size = size; @@ -142,8 +142,7 @@ GLenum VertexArrayState::SetAttribPointer(GLuint index, GLint size, GLenum type, state.pointer = pointer; state.buffer = currentArrayBuffer; state.isInteger = isInteger; - if (vaos_[currentVao_].attribs.count(index) && vaos_[currentVao_].attribs[index].enabled) - state.enabled = true; + state.enabled = vaos_[currentVao_].attribs[index].enabled; vaos_[currentVao_].attribs[index] = state; diff --git a/MG/MG_GL/State/VertexArray/VertexArrayState.h b/MG/MG_GL/State/VertexArray/VertexArrayState.h index 236cf2e9..ac736bac 100644 --- a/MG/MG_GL/State/VertexArray/VertexArrayState.h +++ b/MG/MG_GL/State/VertexArray/VertexArrayState.h @@ -10,7 +10,7 @@ #include "../../../Includes.h" struct VertexAttribState { - bool enabled; + bool enabled = false; GLint size = 4; GLenum type = GL_FLOAT; GLboolean normalized = GL_FALSE; @@ -25,7 +25,7 @@ struct VertexArrayObject { bool attribDirty = false; bool eboDirty = false; GLuint elementBuffer = 0; - MG_Global::unordered_map attribs; + std::array attribs; }; class VertexArrayState {