diff options
Diffstat (limited to 'Source/Core/VideoCommon/VertexLoader.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/VertexLoader.cpp | 224 |
1 files changed, 39 insertions, 185 deletions
diff --git a/Source/Core/VideoCommon/VertexLoader.cpp b/Source/Core/VideoCommon/VertexLoader.cpp index f06b60a430..0d49ef1a4b 100644 --- a/Source/Core/VideoCommon/VertexLoader.cpp +++ b/Source/Core/VideoCommon/VertexLoader.cpp @@ -72,21 +72,16 @@ VertexLoader::VertexLoader(const TVtxDesc& vtx_desc, const VAT& vtx_attr) CompileVertexTranslator(); // generate frac factors - m_posScale = 1.0f / (1U << m_VtxAttr.PosFrac); - for (int i = 0; i < 8; i++) - m_tcScale[i] = 1.0f / (1U << m_VtxAttr.texCoord[i].Frac); + m_posScale = 1.0f / (1U << m_VtxAttr.g0.PosFrac); + for (u32 i = 0; i < 8; i++) + m_tcScale[i] = 1.0f / (1U << m_VtxAttr.GetTexFrac(i)); } void VertexLoader::CompileVertexTranslator() { - m_VertexSize = 0; - const TVtxAttr& vtx_attr = m_VtxAttr; - // Reset pipeline m_numPipelineStages = 0; - u32 components = 0; - // Position in pc vertex format. int nat_offset = 0; @@ -94,72 +89,25 @@ void VertexLoader::CompileVertexTranslator() if (m_VtxDesc.low.PosMatIdx) { WriteCall(PosMtx_ReadDirect_UByte); - components |= VB_HAS_POSMTXIDX; m_native_vtx_decl.posmtx.components = 4; m_native_vtx_decl.posmtx.enable = true; m_native_vtx_decl.posmtx.offset = nat_offset; m_native_vtx_decl.posmtx.type = VAR_UNSIGNED_BYTE; m_native_vtx_decl.posmtx.integer = true; nat_offset += 4; - m_VertexSize += 1; } - if (m_VtxDesc.low.Tex0MatIdx) - { - m_VertexSize += 1; - components |= VB_HAS_TEXMTXIDX0; - WriteCall(TexMtx_ReadDirect_UByte); - } - if (m_VtxDesc.low.Tex1MatIdx) - { - m_VertexSize += 1; - components |= VB_HAS_TEXMTXIDX1; - WriteCall(TexMtx_ReadDirect_UByte); - } - if (m_VtxDesc.low.Tex2MatIdx) - { - m_VertexSize += 1; - components |= VB_HAS_TEXMTXIDX2; - WriteCall(TexMtx_ReadDirect_UByte); - } - if (m_VtxDesc.low.Tex3MatIdx) - { - m_VertexSize += 1; - components |= VB_HAS_TEXMTXIDX3; - WriteCall(TexMtx_ReadDirect_UByte); - } - if (m_VtxDesc.low.Tex4MatIdx) - { - m_VertexSize += 1; - components |= VB_HAS_TEXMTXIDX4; - WriteCall(TexMtx_ReadDirect_UByte); - } - if (m_VtxDesc.low.Tex5MatIdx) - { - m_VertexSize += 1; - components |= VB_HAS_TEXMTXIDX5; - WriteCall(TexMtx_ReadDirect_UByte); - } - if (m_VtxDesc.low.Tex6MatIdx) + for (auto texmtxidx : m_VtxDesc.low.TexMatIdx) { - m_VertexSize += 1; - components |= VB_HAS_TEXMTXIDX6; - WriteCall(TexMtx_ReadDirect_UByte); - } - if (m_VtxDesc.low.Tex7MatIdx) - { - m_VertexSize += 1; - components |= VB_HAS_TEXMTXIDX7; - WriteCall(TexMtx_ReadDirect_UByte); + if (texmtxidx) + WriteCall(TexMtx_ReadDirect_UByte); } // Write vertex position loader - WriteCall(VertexLoader_Position::GetFunction(m_VtxDesc.low.Position, m_VtxAttr.PosFormat, - m_VtxAttr.PosElements)); + WriteCall(VertexLoader_Position::GetFunction(m_VtxDesc.low.Position, m_VtxAttr.g0.PosFormat, + m_VtxAttr.g0.PosElements)); - m_VertexSize += VertexLoader_Position::GetSize(m_VtxDesc.low.Position, m_VtxAttr.PosFormat, - m_VtxAttr.PosElements); - int pos_elements = m_VtxAttr.PosElements == CoordComponentCount::XY ? 2 : 3; + int pos_elements = m_VtxAttr.g0.PosElements == CoordComponentCount::XY ? 2 : 3; m_native_vtx_decl.position.components = pos_elements; m_native_vtx_decl.position.enable = true; m_native_vtx_decl.position.offset = nat_offset; @@ -170,22 +118,19 @@ void VertexLoader::CompileVertexTranslator() // Normals if (m_VtxDesc.low.Normal != VertexComponentFormat::NotPresent) { - m_VertexSize += VertexLoader_Normal::GetSize(m_VtxDesc.low.Normal, m_VtxAttr.NormalFormat, - m_VtxAttr.NormalElements, m_VtxAttr.NormalIndex3); - TPipelineFunction pFunc = - VertexLoader_Normal::GetFunction(m_VtxDesc.low.Normal, m_VtxAttr.NormalFormat, - m_VtxAttr.NormalElements, m_VtxAttr.NormalIndex3); + VertexLoader_Normal::GetFunction(m_VtxDesc.low.Normal, m_VtxAttr.g0.NormalFormat, + m_VtxAttr.g0.NormalElements, m_VtxAttr.g0.NormalIndex3); if (pFunc == nullptr) { PanicAlertFmt("VertexLoader_Normal::GetFunction({} {} {} {}) returned zero!", - m_VtxDesc.low.Normal, m_VtxAttr.NormalFormat, m_VtxAttr.NormalElements, - m_VtxAttr.NormalIndex3); + m_VtxDesc.low.Normal, m_VtxAttr.g0.NormalFormat, m_VtxAttr.g0.NormalElements, + m_VtxAttr.g0.NormalIndex3); } WriteCall(pFunc); - for (int i = 0; i < (vtx_attr.NormalElements == NormalComponentCount::NBT ? 3 : 1); i++) + for (int i = 0; i < (m_VtxAttr.g0.NormalElements == NormalComponentCount::NBT ? 3 : 1); i++) { m_native_vtx_decl.normals[i].components = 3; m_native_vtx_decl.normals[i].enable = true; @@ -194,10 +139,6 @@ void VertexLoader::CompileVertexTranslator() m_native_vtx_decl.normals[i].integer = false; nat_offset += 12; } - - components |= VB_HAS_NRM0; - if (m_VtxAttr.NormalElements == NormalComponentCount::NBT) - components |= VB_HAS_NRM1 | VB_HAS_NRM2; } for (size_t i = 0; i < m_VtxDesc.low.Color.Size(); i++) @@ -205,101 +146,17 @@ void VertexLoader::CompileVertexTranslator() m_native_vtx_decl.colors[i].components = 4; m_native_vtx_decl.colors[i].type = VAR_UNSIGNED_BYTE; m_native_vtx_decl.colors[i].integer = false; - switch (m_VtxDesc.low.Color[i]) - { - case VertexComponentFormat::NotPresent: - break; - case VertexComponentFormat::Direct: - switch (m_VtxAttr.color[i].Comp) - { - case ColorFormat::RGB565: - m_VertexSize += 2; - WriteCall(Color_ReadDirect_16b_565); - break; - case ColorFormat::RGB888: - m_VertexSize += 3; - WriteCall(Color_ReadDirect_24b_888); - break; - case ColorFormat::RGB888x: - m_VertexSize += 4; - WriteCall(Color_ReadDirect_32b_888x); - break; - case ColorFormat::RGBA4444: - m_VertexSize += 2; - WriteCall(Color_ReadDirect_16b_4444); - break; - case ColorFormat::RGBA6666: - m_VertexSize += 3; - WriteCall(Color_ReadDirect_24b_6666); - break; - case ColorFormat::RGBA8888: - m_VertexSize += 4; - WriteCall(Color_ReadDirect_32b_8888); - break; - default: - ASSERT(0); - break; - } - break; - case VertexComponentFormat::Index8: - m_VertexSize += 1; - switch (m_VtxAttr.color[i].Comp) - { - case ColorFormat::RGB565: - WriteCall(Color_ReadIndex8_16b_565); - break; - case ColorFormat::RGB888: - WriteCall(Color_ReadIndex8_24b_888); - break; - case ColorFormat::RGB888x: - WriteCall(Color_ReadIndex8_32b_888x); - break; - case ColorFormat::RGBA4444: - WriteCall(Color_ReadIndex8_16b_4444); - break; - case ColorFormat::RGBA6666: - WriteCall(Color_ReadIndex8_24b_6666); - break; - case ColorFormat::RGBA8888: - WriteCall(Color_ReadIndex8_32b_8888); - break; - default: - ASSERT(0); - break; - } - break; - case VertexComponentFormat::Index16: - m_VertexSize += 2; - switch (m_VtxAttr.color[i].Comp) - { - case ColorFormat::RGB565: - WriteCall(Color_ReadIndex16_16b_565); - break; - case ColorFormat::RGB888: - WriteCall(Color_ReadIndex16_24b_888); - break; - case ColorFormat::RGB888x: - WriteCall(Color_ReadIndex16_32b_888x); - break; - case ColorFormat::RGBA4444: - WriteCall(Color_ReadIndex16_16b_4444); - break; - case ColorFormat::RGBA6666: - WriteCall(Color_ReadIndex16_24b_6666); - break; - case ColorFormat::RGBA8888: - WriteCall(Color_ReadIndex16_32b_8888); - break; - default: - ASSERT(0); - break; - } - break; - } - // Common for the three bottom cases + + TPipelineFunction pFunc = + VertexLoader_Color::GetFunction(m_VtxDesc.low.Color[i], m_VtxAttr.GetColorFormat(i)); + + if (pFunc != nullptr) + WriteCall(pFunc); + else + ASSERT(m_VtxDesc.low.Color[i] == VertexComponentFormat::NotPresent); + if (m_VtxDesc.low.Color[i] != VertexComponentFormat::NotPresent) { - components |= VB_HAS_COL0 << i; m_native_vtx_decl.colors[i].offset = nat_offset; m_native_vtx_decl.colors[i].enable = true; nat_offset += 4; @@ -314,8 +171,8 @@ void VertexLoader::CompileVertexTranslator() m_native_vtx_decl.texcoords[i].integer = false; const auto tc = m_VtxDesc.high.TexCoord[i].Value(); - const auto format = m_VtxAttr.texCoord[i].Format; - const auto elements = m_VtxAttr.texCoord[i].Elements; + const auto format = m_VtxAttr.GetTexFormat(i); + const auto elements = m_VtxAttr.GetTexElements(i); if (tc != VertexComponentFormat::NotPresent) { @@ -326,26 +183,21 @@ void VertexLoader::CompileVertexTranslator() ASSERT_MSG(VIDEO, elements == TexComponentCount::S || elements == TexComponentCount::ST, "Invalid number of texture coordinates elements!\n(elements = %d)", (u32)elements); - components |= VB_HAS_UV0 << i; WriteCall(VertexLoader_TextCoord::GetFunction(tc, format, elements)); - m_VertexSize += VertexLoader_TextCoord::GetSize(tc, format, elements); } - if (components & (VB_HAS_TEXMTXIDX0 << i)) + if (m_VtxDesc.low.TexMatIdx[i]) { m_native_vtx_decl.texcoords[i].enable = true; + m_native_vtx_decl.texcoords[i].components = 3; + nat_offset += 12; if (tc != VertexComponentFormat::NotPresent) { // if texmtx is included, texcoord will always be 3 floats, z will be the texmtx index - m_native_vtx_decl.texcoords[i].components = 3; - nat_offset += 12; - WriteCall(m_VtxAttr.texCoord[i].Elements == TexComponentCount::ST ? TexMtx_Write_Float : - TexMtx_Write_Float2); + WriteCall(elements == TexComponentCount::ST ? TexMtx_Write_Float : TexMtx_Write_Float2); } else { - m_native_vtx_decl.texcoords[i].components = 3; - nat_offset += 12; WriteCall(TexMtx_Write_Float3); } } @@ -354,26 +206,29 @@ void VertexLoader::CompileVertexTranslator() if (tc != VertexComponentFormat::NotPresent) { m_native_vtx_decl.texcoords[i].enable = true; - m_native_vtx_decl.texcoords[i].components = - vtx_attr.texCoord[i].Elements == TexComponentCount::ST ? 2 : 1; - nat_offset += 4 * (vtx_attr.texCoord[i].Elements == TexComponentCount::ST ? 2 : 1); + m_native_vtx_decl.texcoords[i].components = elements == TexComponentCount::ST ? 2 : 1; + nat_offset += 4 * (elements == TexComponentCount::ST ? 2 : 1); } } if (tc == VertexComponentFormat::NotPresent) { // if there's more tex coords later, have to write a dummy call - size_t j = i + 1; - for (; j < m_VtxDesc.high.TexCoord.Size(); ++j) + bool has_more = false; + for (size_t j = 0; j < m_VtxDesc.high.TexCoord.Size(); ++j) { if (m_VtxDesc.high.TexCoord[j] != VertexComponentFormat::NotPresent) { + has_more = true; WriteCall(VertexLoader_TextCoord::GetDummyFunction()); // important to get indices right! break; } + else if (m_VtxDesc.low.TexMatIdx[i]) + { + has_more = true; + } } - // tricky! - if (j == 8 && !((components & VB_HAS_TEXMTXIDXALL) & (VB_HAS_TEXMTXIDXALL << (i + 1)))) + if (!has_more) { // no more tex coords and tex matrices, so exit loop break; @@ -387,7 +242,6 @@ void VertexLoader::CompileVertexTranslator() WriteCall(SkipVertex); } - m_native_components = components; m_native_vtx_decl.stride = nat_offset; } |
