// Copyright 2008 Dolphin Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include "VideoCommon/VertexLoader_TextCoord.h" #include #include "Common/CommonTypes.h" #include "Common/Swap.h" #include "VideoCommon/VertexLoader.h" #include "VideoCommon/VertexLoaderManager.h" #include "VideoCommon/VertexLoaderUtils.h" namespace { void TexCoord_Read_Dummy(VertexLoader* loader) { loader->m_tcIndex++; } template constexpr float TCScale(T val, float scale) { return val * scale; } template <> constexpr float TCScale(float val, [[maybe_unused]] float scale) { return val; } template void TexCoord_ReadDirect(VertexLoader* loader) { const auto scale = loader->m_tcScale[loader->m_tcIndex]; for (int i = 0; i != N; ++i) DataWrite(TCScale(DataRead(), scale)); ++loader->m_tcIndex; } template void TexCoord_ReadIndex(VertexLoader* loader) { static_assert(std::is_unsigned::value, "Only unsigned I is sane!"); const auto index = DataRead(); const auto data = reinterpret_cast( VertexLoaderManager::cached_arraybases[CPArray::TexCoord0 + loader->m_tcIndex] + (index * g_main_cp_state.array_strides[CPArray::TexCoord0 + loader->m_tcIndex])); const auto scale = loader->m_tcScale[loader->m_tcIndex]; for (int i = 0; i != N; ++i) DataWrite(TCScale(Common::FromBigEndian(data[i]), scale)); ++loader->m_tcIndex; } using ComponentCountRow = Common::EnumMap; using ComponentFormatTable = Common::EnumMap; using Table = Common::EnumMap; constexpr Table s_table_read_tex_coord = { ComponentFormatTable({ ComponentCountRow(nullptr, nullptr), ComponentCountRow(nullptr, nullptr), ComponentCountRow(nullptr, nullptr), ComponentCountRow(nullptr, nullptr), ComponentCountRow(nullptr, nullptr), ComponentCountRow(nullptr, nullptr), ComponentCountRow(nullptr, nullptr), ComponentCountRow(nullptr, nullptr), }), ComponentFormatTable({ ComponentCountRow(TexCoord_ReadDirect, TexCoord_ReadDirect), ComponentCountRow(TexCoord_ReadDirect, TexCoord_ReadDirect), ComponentCountRow(TexCoord_ReadDirect, TexCoord_ReadDirect), ComponentCountRow(TexCoord_ReadDirect, TexCoord_ReadDirect), ComponentCountRow(TexCoord_ReadDirect, TexCoord_ReadDirect), ComponentCountRow(TexCoord_ReadDirect, TexCoord_ReadDirect), ComponentCountRow(TexCoord_ReadDirect, TexCoord_ReadDirect), ComponentCountRow(TexCoord_ReadDirect, TexCoord_ReadDirect), }), ComponentFormatTable({ ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), }), ComponentFormatTable({ ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), }), }; } // Anonymous namespace TPipelineFunction VertexLoader_TextCoord::GetFunction(VertexComponentFormat type, ComponentFormat format, TexComponentCount elements) { return s_table_read_tex_coord[type][format][elements]; } TPipelineFunction VertexLoader_TextCoord::GetDummyFunction() { return TexCoord_Read_Dummy; }