Skip to content
Permalink
Browse files

Merge pull request #8143 from lioncash/loader

VertexLoader_*: Minor cleanup
  • Loading branch information...
leoetlino committed May 31, 2019
2 parents eed4fcc + 2452747 commit a4837a5c5dc5d71f4b93dcb2fd5b80c5cfab381a
@@ -12,17 +12,19 @@
#include "VideoCommon/VertexLoaderUtils.h"
#include "VideoCommon/VertexLoader_Color.h"

#define AMASK 0xFF000000
namespace
{
constexpr u32 alpha_mask = 0xFF000000;

static void SetCol(VertexLoader* loader, u32 val)
void SetCol(VertexLoader* loader, u32 val)
{
DataWrite(val);
loader->m_colIndex++;
}

// Color comes in format BARG in 16 bits
// BARG -> AABBGGRR
static void SetCol4444(VertexLoader* loader, u16 val_)
void SetCol4444(VertexLoader* loader, u16 val_)
{
u32 col, val = val_;
col = val & 0x00F0; // col = 000000R0;
@@ -35,7 +37,7 @@ static void SetCol4444(VertexLoader* loader, u16 val_)

// Color comes in format RGBA
// RRRRRRGG GGGGBBBB BBAAAAAA
static void SetCol6666(VertexLoader* loader, u32 val)
void SetCol6666(VertexLoader* loader, u32 val)
{
u32 col = (val >> 16) & 0x000000FC;
col |= (val >> 2) & 0x0000FC00;
@@ -47,69 +49,36 @@ static void SetCol6666(VertexLoader* loader, u32 val)

// Color comes in RGB
// RRRRRGGG GGGBBBBB
static void SetCol565(VertexLoader* loader, u16 val_)
void SetCol565(VertexLoader* loader, u16 val_)
{
u32 col, val = val_;
col = (val >> 8) & 0x0000F8;
col |= (val << 5) & 0x00FC00;
col |= (val << 19) & 0xF80000;
col |= (col >> 5) & 0x070007;
col |= (col >> 6) & 0x000300;
SetCol(loader, col | AMASK);
SetCol(loader, col | alpha_mask);
}

static u32 Read32(const u8* addr)
u32 Read32(const u8* addr)
{
u32 value;
std::memcpy(&value, addr, sizeof(u32));
return value;
}

static u32 Read24(const u8* addr)
{
return Read32(addr) | AMASK;
}

void Color_ReadDirect_24b_888(VertexLoader* loader)
{
SetCol(loader, Read24(DataGetPosition()));
DataSkip(3);
}

void Color_ReadDirect_32b_888x(VertexLoader* loader)
{
SetCol(loader, Read24(DataGetPosition()));
DataSkip(4);
}
void Color_ReadDirect_16b_565(VertexLoader* loader)
{
SetCol565(loader, DataRead<u16>());
}
void Color_ReadDirect_16b_4444(VertexLoader* loader)
{
u16 value;
std::memcpy(&value, DataGetPosition(), sizeof(u16));

SetCol4444(loader, value);
DataSkip(2);
}
void Color_ReadDirect_24b_6666(VertexLoader* loader)
{
SetCol6666(loader, Common::swap32(DataGetPosition() - 1));
DataSkip(3);
}
void Color_ReadDirect_32b_8888(VertexLoader* loader)
u32 Read24(const u8* addr)
{
SetCol(loader, DataReadU32Unswapped());
return Read32(addr) | alpha_mask;
}

template <typename I>
void Color_ReadIndex_16b_565(VertexLoader* loader)
{
auto const Index = DataRead<I>();
const auto index = DataRead<I>();
const u8* const address =
VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(Index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]);
(index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]);

u16 value;
std::memcpy(&value, address, sizeof(u16));
@@ -120,28 +89,28 @@ void Color_ReadIndex_16b_565(VertexLoader* loader)
template <typename I>
void Color_ReadIndex_24b_888(VertexLoader* loader)
{
auto const Index = DataRead<I>();
const u8* iAddress = VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(Index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]);
SetCol(loader, Read24(iAddress));
const auto index = DataRead<I>();
const u8* address = VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]);
SetCol(loader, Read24(address));
}

template <typename I>
void Color_ReadIndex_32b_888x(VertexLoader* loader)
{
auto const Index = DataRead<I>();
const u8* iAddress = VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(Index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]);
SetCol(loader, Read24(iAddress));
const auto index = DataRead<I>();
const u8* address = VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]);
SetCol(loader, Read24(address));
}

template <typename I>
void Color_ReadIndex_16b_4444(VertexLoader* loader)
{
auto const Index = DataRead<I>();
auto const index = DataRead<I>();
const u8* const address =
VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(Index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]);
(index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]);

u16 value;
std::memcpy(&value, address, sizeof(u16));
@@ -152,20 +121,54 @@ void Color_ReadIndex_16b_4444(VertexLoader* loader)
template <typename I>
void Color_ReadIndex_24b_6666(VertexLoader* loader)
{
auto const Index = DataRead<I>();
const u8* pData = VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(Index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]) - 1;
u32 val = Common::swap32(pData);
const auto index = DataRead<I>();
const u8* data = VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]) - 1;
const u32 val = Common::swap32(data);
SetCol6666(loader, val);
}

template <typename I>
void Color_ReadIndex_32b_8888(VertexLoader* loader)
{
auto const Index = DataRead<I>();
const u8* iAddress = VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(Index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]);
SetCol(loader, Read32(iAddress));
const auto index = DataRead<I>();
const u8* address = VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]);
SetCol(loader, Read32(address));
}
} // Anonymous namespace

void Color_ReadDirect_24b_888(VertexLoader* loader)
{
SetCol(loader, Read24(DataGetPosition()));
DataSkip(3);
}

void Color_ReadDirect_32b_888x(VertexLoader* loader)
{
SetCol(loader, Read24(DataGetPosition()));
DataSkip(4);
}
void Color_ReadDirect_16b_565(VertexLoader* loader)
{
SetCol565(loader, DataRead<u16>());
}
void Color_ReadDirect_16b_4444(VertexLoader* loader)
{
u16 value;
std::memcpy(&value, DataGetPosition(), sizeof(u16));

SetCol4444(loader, value);
DataSkip(2);
}
void Color_ReadDirect_24b_6666(VertexLoader* loader)
{
SetCol6666(loader, Common::swap32(DataGetPosition() - 1));
DataSkip(3);
}
void Color_ReadDirect_32b_8888(VertexLoader* loader)
{
SetCol(loader, DataReadU32Unswapped());
}

void Color_ReadIndex8_16b_565(VertexLoader* loader)

0 comments on commit a4837a5

Please sign in to comment.
You can’t perform that action at this time.