PortableVertexFormat: use AttributeFormat for texcoord attribute format

This commit is contained in:
degasus 2014-01-24 15:32:27 +01:00
parent ef2d6e7d53
commit 6c59b691b0
4 changed files with 15 additions and 28 deletions

View File

@ -102,12 +102,13 @@ void D3DVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl)
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
if (_vtx_decl.texcoord_offset[i] > 0) format = &_vtx_decl.texcoords[i];
if (format->enable)
{ {
m_elems[m_num_elems].SemanticName = "TEXCOORD"; m_elems[m_num_elems].SemanticName = "TEXCOORD";
m_elems[m_num_elems].SemanticIndex = i; m_elems[m_num_elems].SemanticIndex = i;
m_elems[m_num_elems].AlignedByteOffset = _vtx_decl.texcoord_offset[i]; m_elems[m_num_elems].AlignedByteOffset = format->offset;
m_elems[m_num_elems].Format = VarToD3D(_vtx_decl.texcoord_gl_type[i], _vtx_decl.texcoord_size[i], false); m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
++m_num_elems; ++m_num_elems;
} }

View File

@ -83,11 +83,7 @@ void GLVertexFormat::Initialize(const PortableVertexDeclaration &_vtx_decl)
} }
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
if (vtx_decl.texcoord_offset[i] != -1) { SetPointer(SHADER_TEXTURE0_ATTRIB+i, vertex_stride, vtx_decl.texcoords[i]);
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]);
}
} }
if (vtx_decl.posmtx_offset != -1) { if (vtx_decl.posmtx_offset != -1) {

View File

@ -88,11 +88,8 @@ struct PortableVertexDeclaration
AttributeFormat position; AttributeFormat position;
AttributeFormat normals[3]; AttributeFormat normals[3];
AttributeFormat colors[2]; AttributeFormat colors[2];
AttributeFormat texcoords[8];
VarType texcoord_gl_type[8];
//int texcoord_gl_size[8];
int texcoord_offset[8];
int texcoord_size[8];
int posmtx_offset; int posmtx_offset;
}; };

View File

@ -550,12 +550,6 @@ void VertexLoader::CompileVertexTranslator()
int nat_offset = 0; int nat_offset = 0;
PortableVertexDeclaration vtx_decl; PortableVertexDeclaration vtx_decl;
memset(&vtx_decl, 0, sizeof(vtx_decl)); memset(&vtx_decl, 0, sizeof(vtx_decl));
for (int i = 0; i < 8; i++)
{
vtx_decl.texcoord_offset[i] = -1;
}
// m_VBVertexStride for texmtx and posmtx is computed later when writing.
// Position Matrix Index // Position Matrix Index
if (m_VtxDesc.PosMatIdx) if (m_VtxDesc.PosMatIdx)
@ -688,7 +682,10 @@ void VertexLoader::CompileVertexTranslator()
// Texture matrix indices (remove if corresponding texture coordinate isn't enabled) // Texture matrix indices (remove if corresponding texture coordinate isn't enabled)
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
vtx_decl.texcoord_offset[i] = -1; vtx_decl.texcoords[i].offset = nat_offset;
vtx_decl.texcoords[i].type = VAR_FLOAT;
vtx_decl.texcoords[i].integer = false;
const int format = m_VtxAttr.texCoord[i].Format; const int format = m_VtxAttr.texCoord[i].Format;
const int elements = m_VtxAttr.texCoord[i].Elements; const int elements = m_VtxAttr.texCoord[i].Elements;
@ -709,21 +706,18 @@ void VertexLoader::CompileVertexTranslator()
if (components & (VB_HAS_TEXMTXIDX0 << i)) if (components & (VB_HAS_TEXMTXIDX0 << i))
{ {
vtx_decl.texcoords[i].enable = true;
if (tc[i] != NOT_PRESENT) if (tc[i] != NOT_PRESENT)
{ {
// if texmtx is included, texcoord will always be 3 floats, z will be the texmtx index // if texmtx is included, texcoord will always be 3 floats, z will be the texmtx index
vtx_decl.texcoord_offset[i] = nat_offset; vtx_decl.texcoords[i].components = 3;
vtx_decl.texcoord_gl_type[i] = VAR_FLOAT;
vtx_decl.texcoord_size[i] = 3;
nat_offset += 12; nat_offset += 12;
WriteCall(m_VtxAttr.texCoord[i].Elements ? TexMtx_Write_Float : TexMtx_Write_Float2); WriteCall(m_VtxAttr.texCoord[i].Elements ? TexMtx_Write_Float : TexMtx_Write_Float2);
} }
else else
{ {
components |= VB_HAS_UV0 << i; // have to include since using now components |= VB_HAS_UV0 << i; // have to include since using now
vtx_decl.texcoord_offset[i] = nat_offset; vtx_decl.texcoords[i].components = 4;
vtx_decl.texcoord_gl_type[i] = VAR_FLOAT;
vtx_decl.texcoord_size[i] = 4;
nat_offset += 16; // still include the texture coordinate, but this time as 6 + 2 bytes nat_offset += 16; // still include the texture coordinate, but this time as 6 + 2 bytes
WriteCall(TexMtx_Write_Float4); WriteCall(TexMtx_Write_Float4);
} }
@ -732,9 +726,8 @@ void VertexLoader::CompileVertexTranslator()
{ {
if (tc[i] != NOT_PRESENT) if (tc[i] != NOT_PRESENT)
{ {
vtx_decl.texcoord_offset[i] = nat_offset; vtx_decl.texcoords[i].enable = true;
vtx_decl.texcoord_gl_type[i] = VAR_FLOAT; vtx_decl.texcoords[i].components = vtx_attr.texCoord[i].Elements ? 2 : 1;
vtx_decl.texcoord_size[i] = vtx_attr.texCoord[i].Elements ? 2 : 1;
nat_offset += 4 * (vtx_attr.texCoord[i].Elements ? 2 : 1); nat_offset += 4 * (vtx_attr.texCoord[i].Elements ? 2 : 1);
} }
} }