From 02d1d8e6a04f0536b6dff014e1223605f8b661ac Mon Sep 17 00:00:00 2001 From: degasus Date: Fri, 24 Jan 2014 14:18:55 +0100 Subject: NativeVertexFormat: swap unsigned / signed formats to match GX order --- Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp') diff --git a/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp b/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp index c0112c4e9e..b23836ac90 100644 --- a/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp +++ b/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp @@ -37,7 +37,7 @@ GLVertexFormat::~GLVertexFormat() inline GLuint VarToGL(VarType t) { static const GLuint lookup[5] = { - GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_FLOAT + GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT, GL_FLOAT }; return lookup[t]; } -- cgit v1.2.3 From 210f4f3e559696afea64244c29994aed9685d483 Mon Sep 17 00:00:00 2001 From: degasus Date: Fri, 24 Jan 2014 14:46:05 +0100 Subject: PortableVertexFormat: add a struct which hold all needed information for every vertex and use this for position atm, position attribute is hardcoded both in VertexLoader and in backends. v2: fix coding style + cleanup lookup table --- Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp') diff --git a/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp b/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp index b23836ac90..49098b24b4 100644 --- a/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp +++ b/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp @@ -42,6 +42,18 @@ inline GLuint VarToGL(VarType t) return lookup[t]; } +static void SetPointer(u32 attrib, u32 stride, const AttributeFormat &format) +{ + if (!format.enable) + return; + + glEnableVertexAttribArray(attrib); + if (format.integer) + glVertexAttribIPointer(attrib, format.components, VarToGL(format.type), stride, (u8*)NULL + format.offset); + else + glVertexAttribPointer(attrib, format.components, VarToGL(format.type), true, stride, (u8*)NULL + format.offset); +} + void GLVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl) { this->vtx_decl = _vtx_decl; @@ -60,8 +72,7 @@ void GLVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vm->m_index_buffers); glBindBuffer(GL_ARRAY_BUFFER, vm->m_vertex_buffers); - glEnableVertexAttribArray(SHADER_POSITION_ATTRIB); - glVertexAttribPointer(SHADER_POSITION_ATTRIB, 3, GL_FLOAT, GL_FALSE, vtx_decl.stride, (u8*)NULL); + SetPointer(SHADER_POSITION_ATTRIB, vertex_stride, vtx_decl.position); for (int i = 0; i < 3; i++) { if (vtx_decl.num_normals > i) { -- cgit v1.2.3 From b38ef39ab7b88eb7e4fa253deec64cecb72508aa Mon Sep 17 00:00:00 2001 From: degasus Date: Fri, 24 Jan 2014 15:16:52 +0100 Subject: PortableVertexFormat: use AttributeFormat for normal attribute format --- Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp') diff --git a/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp b/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp index 49098b24b4..88147aa755 100644 --- a/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp +++ b/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp @@ -75,10 +75,7 @@ void GLVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl) SetPointer(SHADER_POSITION_ATTRIB, vertex_stride, vtx_decl.position); for (int i = 0; i < 3; i++) { - if (vtx_decl.num_normals > i) { - glEnableVertexAttribArray(SHADER_NORM0_ATTRIB+i); - glVertexAttribPointer(SHADER_NORM0_ATTRIB+i, vtx_decl.normal_gl_size, VarToGL(vtx_decl.normal_gl_type), GL_TRUE, vtx_decl.stride, (u8*)NULL + vtx_decl.normal_offset[i]); - } + SetPointer(SHADER_NORM0_ATTRIB+i, vertex_stride, vtx_decl.normals[i]); } for (int i = 0; i < 2; i++) { -- cgit v1.2.3 From ef2d6e7d530c2f61360d370f3b98bba7989ada6e Mon Sep 17 00:00:00 2001 From: degasus Date: Fri, 24 Jan 2014 15:23:50 +0100 Subject: PortableVertexFormat: use AttributeFormat for color attribute format --- Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp') diff --git a/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp b/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp index 88147aa755..784191c1d2 100644 --- a/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp +++ b/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp @@ -79,10 +79,7 @@ void GLVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl) } for (int i = 0; i < 2; i++) { - if (vtx_decl.color_offset[i] != -1) { - glEnableVertexAttribArray(SHADER_COLOR0_ATTRIB+i); - glVertexAttribPointer(SHADER_COLOR0_ATTRIB+i, 4, GL_UNSIGNED_BYTE, GL_TRUE, vtx_decl.stride, (u8*)NULL + vtx_decl.color_offset[i]); - } + SetPointer(SHADER_COLOR0_ATTRIB+i, vertex_stride, vtx_decl.colors[i]); } for (int i = 0; i < 8; i++) { -- cgit v1.2.3 From 6c59b691b0247f4a56ff17d7cf134364b258a6c5 Mon Sep 17 00:00:00 2001 From: degasus Date: Fri, 24 Jan 2014 15:32:27 +0100 Subject: PortableVertexFormat: use AttributeFormat for texcoord attribute format --- Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp') diff --git a/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp b/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp index 784191c1d2..97b0b7a7a2 100644 --- a/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp +++ b/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp @@ -83,11 +83,7 @@ void GLVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl) } for (int i = 0; i < 8; i++) { - if (vtx_decl.texcoord_offset[i] != -1) { - glEnableVertexAttribArray(SHADER_TEXTURE0_ATTRIB+i); - glVertexAttribPointer(SHADER_TEXTURE0_ATTRIB+i, vtx_decl.texcoord_size[i], VarToGL(vtx_decl.texcoord_gl_type[i]), - GL_FALSE, vtx_decl.stride, (u8*)NULL + vtx_decl.texcoord_offset[i]); - } + SetPointer(SHADER_TEXTURE0_ATTRIB+i, vertex_stride, vtx_decl.texcoords[i]); } if (vtx_decl.posmtx_offset != -1) { -- cgit v1.2.3 From a65162f1cd345b8f206fd01e19ac261d09ac291b Mon Sep 17 00:00:00 2001 From: degasus Date: Fri, 24 Jan 2014 15:41:08 +0100 Subject: PortableVertexFormat: use AttributeFormat for posmtx attribute format --- Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp') diff --git a/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp b/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp index 97b0b7a7a2..4f3f2ad0d7 100644 --- a/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp +++ b/Source/Core/VideoBackends/OGL/NativeVertexFormat.cpp @@ -86,10 +86,7 @@ void GLVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl) SetPointer(SHADER_TEXTURE0_ATTRIB+i, vertex_stride, vtx_decl.texcoords[i]); } - if (vtx_decl.posmtx_offset != -1) { - glEnableVertexAttribArray(SHADER_POSMTX_ATTRIB); - glVertexAttribPointer(SHADER_POSMTX_ATTRIB, 4, GL_UNSIGNED_BYTE, GL_FALSE, vtx_decl.stride, (u8*)NULL + vtx_decl.posmtx_offset); - } + SetPointer(SHADER_POSMTX_ATTRIB, vertex_stride, vtx_decl.posmtx); vm->m_last_vao = VAO; } -- cgit v1.2.3