diff --git a/plugins/GSdx/GSDeviceOGL.cpp b/plugins/GSdx/GSDeviceOGL.cpp index 8003324ab3..edef23e959 100644 --- a/plugins/GSdx/GSDeviceOGL.cpp +++ b/plugins/GSdx/GSDeviceOGL.cpp @@ -347,18 +347,17 @@ bool GSDeviceOGL::Create(const std::shared_ptr &wnd) GL_PUSH("GSDeviceOGL::Vertex Buffer"); static_assert(sizeof(GSVertexPT1) == sizeof(GSVertex), "wrong GSVertex size"); - GSInputLayoutOGL il_convert[] = - { - {2 , GL_FLOAT , GL_FALSE , sizeof(GSVertexPT1) , (const GLvoid*)(0) } , - {2 , GL_FLOAT , GL_FALSE , sizeof(GSVertexPT1) , (const GLvoid*)(16) } , - {4 , GL_UNSIGNED_BYTE , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(8) } , - {1 , GL_FLOAT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(12) } , - {2 , GL_UNSIGNED_SHORT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(16) } , - {1 , GL_UNSIGNED_INT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(20) } , - {2 , GL_UNSIGNED_SHORT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(24) } , - {4 , GL_UNSIGNED_BYTE , GL_TRUE , sizeof(GSVertex) , (const GLvoid*)(28) } , // Only 1 byte is useful but hardware unit only support 4B + std::vector il_convert = { + {0, 2 , GL_FLOAT , GL_FALSE , sizeof(GSVertexPT1) , (const GLvoid*)(0) } , + {1, 2 , GL_FLOAT , GL_FALSE , sizeof(GSVertexPT1) , (const GLvoid*)(16) } , + {2, 4 , GL_UNSIGNED_BYTE , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(8) } , + {3, 1 , GL_FLOAT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(12) } , + {4, 2 , GL_UNSIGNED_SHORT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(16) } , + {5, 1 , GL_UNSIGNED_INT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(20) } , + {6, 2 , GL_UNSIGNED_SHORT , GL_FALSE , sizeof(GSVertex) , (const GLvoid*)(24) } , + {7, 4 , GL_UNSIGNED_BYTE , GL_TRUE , sizeof(GSVertex) , (const GLvoid*)(28) } , // Only 1 byte is useful but hardware unit only support 4B }; - m_va = new GSVertexBufferStateOGL(il_convert, countof(il_convert)); + m_va = new GSVertexBufferStateOGL(il_convert); } // **************************************************************** diff --git a/plugins/GSdx/GSVertexArrayOGL.h b/plugins/GSdx/GSVertexArrayOGL.h index f98739d7f2..19b648b7d9 100644 --- a/plugins/GSdx/GSVertexArrayOGL.h +++ b/plugins/GSdx/GSVertexArrayOGL.h @@ -28,6 +28,7 @@ extern uint64 g_vertex_upload_byte; #endif struct GSInputLayoutOGL { + GLint location; GLint size; GLenum type; GLboolean normalize; @@ -216,12 +217,13 @@ class GSVertexBufferStateOGL { GLuint m_va; GLenum m_topology; + std::vector m_layout; // No copy constructor please GSVertexBufferStateOGL(const GSVertexBufferStateOGL& ) = delete; public: - GSVertexBufferStateOGL(GSInputLayoutOGL* layout, uint32 layout_nbr) : m_vb(NULL), m_ib(NULL), m_topology(0) + GSVertexBufferStateOGL(const std::vector& layout) : m_vb(NULL), m_ib(NULL), m_topology(0), m_layout(layout) { glGenVertexArrays(1, &m_va); glBindVertexArray(m_va); @@ -232,7 +234,7 @@ public: m_vb->bind(); m_ib->bind(); - set_internal_format(layout, layout_nbr); + set_internal_format(); } void bind() @@ -243,23 +245,23 @@ public: m_vb->bind(); } - void set_internal_format(GSInputLayoutOGL* layout, uint32 layout_nbr) + void set_internal_format() { - for (uint32 i = 0; i < layout_nbr; i++) { + for (const auto &l : m_layout) { // Note this function need both a vertex array object and a GL_ARRAY_BUFFER buffer - glEnableVertexAttribArray(i); - switch (layout[i].type) { + glEnableVertexAttribArray(l.location); + switch (l.type) { case GL_UNSIGNED_SHORT: case GL_UNSIGNED_INT: - if (layout[i].normalize) { - glVertexAttribPointer(i, layout[i].size, layout[i].type, layout[i].normalize, layout[i].stride, layout[i].offset); + if (l.normalize) { + glVertexAttribPointer(l.location, l.size, l.type, l.normalize, l.stride, l.offset); } else { // Rule: when shader use integral (not normalized) you must use glVertexAttribIPointer (note the extra I) - glVertexAttribIPointer(i, layout[i].size, layout[i].type, layout[i].stride, layout[i].offset); + glVertexAttribIPointer(l.location, l.size, l.type, l.stride, l.offset); } break; default: - glVertexAttribPointer(i, layout[i].size, layout[i].type, layout[i].normalize, layout[i].stride, layout[i].offset); + glVertexAttribPointer(l.location, l.size, l.type, l.normalize, l.stride, l.offset); break; } }