mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
VertexLoader: temp class for reader/writer
This commit is contained in:
parent
0b97b33ceb
commit
3cb5bb3b30
@ -56,6 +56,22 @@ __forceinline T DataRead()
|
||||
return result;
|
||||
}
|
||||
|
||||
class DataReader
|
||||
{
|
||||
public:
|
||||
inline DataReader() : buffer(g_pVideoData), offset(0) {}
|
||||
inline ~DataReader() { g_pVideoData += offset; }
|
||||
template <typename T> inline T Read()
|
||||
{
|
||||
const T result = Common::FromBigEndian(*(T*)(buffer + offset));
|
||||
offset += sizeof(T);
|
||||
return result;
|
||||
}
|
||||
private:
|
||||
u8 *buffer;
|
||||
int offset;
|
||||
};
|
||||
|
||||
// TODO: kill these
|
||||
__forceinline u8 DataReadU8()
|
||||
{
|
||||
@ -132,17 +148,26 @@ __forceinline u8* DataGetPosition()
|
||||
return g_pVideoData;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__forceinline void DataWrite(u8* &dst, T data)
|
||||
{
|
||||
*(T*)dst = data;
|
||||
dst += sizeof(T);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__forceinline void DataWrite(T data)
|
||||
{
|
||||
DataWrite(VertexManager::s_pCurBufferPointer, data);
|
||||
*(T*)VertexManager::s_pCurBufferPointer = data;
|
||||
VertexManager::s_pCurBufferPointer += sizeof(T);
|
||||
}
|
||||
|
||||
class DataWriter
|
||||
{
|
||||
public:
|
||||
inline DataWriter() : buffer(VertexManager::s_pCurBufferPointer), offset(0) {}
|
||||
inline ~DataWriter() { VertexManager::s_pCurBufferPointer += offset; }
|
||||
template <typename T> inline void Write(T data)
|
||||
{
|
||||
*(T*)(buffer+offset) = data;
|
||||
offset += sizeof(T);
|
||||
}
|
||||
private:
|
||||
u8 *buffer;
|
||||
int offset;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -48,15 +48,13 @@ template <typename T, int N>
|
||||
__forceinline void ReadIndirect(const T* data)
|
||||
{
|
||||
static_assert(3 == N || 9 == N, "N is only sane as 3 or 9!");
|
||||
auto dst = VertexManager::s_pCurBufferPointer;
|
||||
DataWriter dst;
|
||||
|
||||
for (int i = 0; i != N; ++i)
|
||||
{
|
||||
DataWrite(dst, FracAdjust(Common::FromBigEndian(data[i])));
|
||||
dst.Write(FracAdjust(Common::FromBigEndian(data[i])));
|
||||
}
|
||||
|
||||
VertexManager::s_pCurBufferPointer = dst;
|
||||
|
||||
LOG_NORM();
|
||||
}
|
||||
|
||||
|
@ -77,12 +77,11 @@ void LOADERDECL Pos_ReadDirect()
|
||||
{
|
||||
static_assert(N <= 3, "N > 3 is not sane!");
|
||||
auto const scale = posScale;
|
||||
auto dst = VertexManager::s_pCurBufferPointer;
|
||||
DataWriter dst;
|
||||
DataReader src;
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
DataWrite(dst, i<N ? PosScale(DataRead<T>(), scale) : 0.f);
|
||||
|
||||
VertexManager::s_pCurBufferPointer = dst;
|
||||
dst.Write(i<N ? PosScale(src.Read<T>(), scale) : 0.f);
|
||||
|
||||
LOG_VTX();
|
||||
}
|
||||
@ -96,12 +95,10 @@ void LOADERDECL Pos_ReadIndex()
|
||||
auto const index = DataRead<I>();
|
||||
auto const data = reinterpret_cast<const T*>(cached_arraybases[ARRAY_POSITION] + (index * arraystrides[ARRAY_POSITION]));
|
||||
auto const scale = posScale;
|
||||
auto dst = VertexManager::s_pCurBufferPointer;
|
||||
DataWriter dst;
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
DataWrite(dst, i<N ? PosScale(Common::FromBigEndian(data[i]), scale) : 0.f);
|
||||
|
||||
VertexManager::s_pCurBufferPointer = dst;
|
||||
dst.Write(i<N ? PosScale(Common::FromBigEndian(data[i]), scale) : 0.f);
|
||||
|
||||
LOG_VTX();
|
||||
}
|
||||
|
@ -56,13 +56,11 @@ template <typename T, int N>
|
||||
void LOADERDECL TexCoord_ReadDirect()
|
||||
{
|
||||
auto const scale = tcScale[tcIndex];
|
||||
auto dst = VertexManager::s_pCurBufferPointer;
|
||||
|
||||
DataWriter dst;
|
||||
DataReader src;
|
||||
|
||||
for (int i = 0; i != N; ++i)
|
||||
DataWrite(dst, TCScale(DataRead<T>(), scale));
|
||||
|
||||
VertexManager::s_pCurBufferPointer = dst;
|
||||
dst.Write(TCScale(src.Read<T>(), scale));
|
||||
|
||||
LOG_TEX<N>();
|
||||
|
||||
@ -78,12 +76,10 @@ void LOADERDECL TexCoord_ReadIndex()
|
||||
auto const data = reinterpret_cast<const T*>(cached_arraybases[ARRAY_TEXCOORD0 + tcIndex]
|
||||
+ (index * arraystrides[ARRAY_TEXCOORD0 + tcIndex]));
|
||||
auto const scale = tcScale[tcIndex];
|
||||
auto dst = VertexManager::s_pCurBufferPointer;
|
||||
DataWriter dst;
|
||||
|
||||
for (int i = 0; i != N; ++i)
|
||||
DataWrite(dst, TCScale(Common::FromBigEndian(data[i]), scale));
|
||||
|
||||
VertexManager::s_pCurBufferPointer = dst;
|
||||
dst.Write(TCScale(Common::FromBigEndian(data[i]), scale));
|
||||
|
||||
LOG_TEX<N>();
|
||||
++tcIndex;
|
||||
|
Loading…
Reference in New Issue
Block a user