From dfb7fb02700492ac4a3ea612b345796f0186bf3b Mon Sep 17 00:00:00 2001 From: fallenoak Date: Tue, 11 Apr 2023 00:23:06 -0500 Subject: [PATCH] feat(gx): add FFP support for vertex arrays in GLL --- src/gx/gll/GLVertexArray.cpp | 127 +++++++++++++++++++++++++++++++++-- 1 file changed, 121 insertions(+), 6 deletions(-) diff --git a/src/gx/gll/GLVertexArray.cpp b/src/gx/gll/GLVertexArray.cpp index e4cc825..ba721c2 100644 --- a/src/gx/gll/GLVertexArray.cpp +++ b/src/gx/gll/GLVertexArray.cpp @@ -124,7 +124,7 @@ void GLVertexArray::ApplyVertexFormat(GLDevice* device) { auto vertexBuffer = this->GetProperties().m_VertexBuffer[attrib.stream]; - if (useVertexShader || attrib.slot - 1 > 1) { + if (useVertexShader || static_cast(attrib.slot - 1) > 1) { if (this->m_GLStates.buffers[0] != vertexBuffer->m_BufferID) { glBindBuffer(vertexBuffer->m_Type, vertexBuffer->m_BufferID); this->m_GLStates.buffers[0] = vertexBuffer->m_BufferID; @@ -147,38 +147,153 @@ void GLVertexArray::ApplyVertexFormat(GLDevice* device) { reinterpret_cast(offset) ); } else { - // TODO + switch (attrib.slot) { + case 0: { + glVertexPointer( + k_VertexTypeInfo[attrib.type].m_Size, + k_VertexTypeInfo[attrib.type].m_Type, + stride, + reinterpret_cast(offset) + ); + + break; + } + + case 3: { + glNormalPointer( + k_VertexTypeInfo[attrib.type].m_Type, + stride, + reinterpret_cast(offset) + ); + + break; + } + + case 4: { + glColorPointer( + k_VertexTypeInfo[attrib.type].m_Size, + k_VertexTypeInfo[attrib.type].m_Type, + stride, + reinterpret_cast(offset) + ); + + break; + } + + case 5: { + glSecondaryColorPointer( + k_VertexTypeInfo[attrib.type].m_Size, + k_VertexTypeInfo[attrib.type].m_Type, + stride, + reinterpret_cast(offset) + ); + + break; + } + + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: { + auto tmu = attrib.slot - 6; + auto texCoordIndex = device->m_States.fixedFunc.texCoordIndex[tmu]; + glClientActiveTextureARB(GL_TEXTURE0 + texCoordIndex); + glTexCoordPointer( + k_VertexTypeInfo[attrib.type].m_Size, + k_VertexTypeInfo[attrib.type].m_Type, + stride, + reinterpret_cast(offset) + ); + + break; + } + } } } } for (int32_t s = 0; s < 16; s++) { bool* prevAttribEnable; + GLenum glArray; if (useVertexShader) { prevAttribEnable = &this->m_GLStates.vertexAttribs[s].enable; } else { - // TODO + switch (s) { + case 0: { + prevAttribEnable = &this->m_GLStates.position.enable; + glArray = GL_VERTEX_ARRAY; + + break; + } + + case 3: { + prevAttribEnable = &this->m_GLStates.normal.enable; + glArray = GL_NORMAL_ARRAY; + + break; + } + + case 4: { + prevAttribEnable = &this->m_GLStates.color0.enable; + glArray = GL_COLOR_ARRAY; + + break; + } + + case 5: { + prevAttribEnable = &this->m_GLStates.color1.enable; + glArray = GL_SECONDARY_COLOR_ARRAY; + + break; + } + + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: { + auto tmu = s - 6; + auto texCoordIndex = device->m_States.fixedFunc.texCoordIndex[tmu]; + prevAttribEnable = &this->m_GLStates.texCoord[texCoordIndex].enable; + glArray = GL_TEXTURE_COORD_ARRAY; + + glClientActiveTextureARB(GL_TEXTURE0 + texCoordIndex); + + break; + } + } } if (*prevAttribEnable != attribEnable[s]) { if (attribEnable[s]) { if (useVertexShader) { - glEnableVertexAttribArrayARB(s); + glEnableVertexAttribArrayARB(s); } else { - // TODO + glEnableClientState(glArray); } } else { if (useVertexShader) { glDisableVertexAttribArrayARB(s); } else { - // TODO + glDisableClientState(glArray); } } *prevAttribEnable = attribEnable[s]; } } + + if (!useVertexShader) { + // TODO device->SetColorMaterial(this->m_GLStates.color0.enable); + } } GLVertexArray::Properties& GLVertexArray::GetProperties() {