diff options
| author | degasus <wickmarkus@web.de> | 2014-01-21 23:44:51 +0100 |
|---|---|---|
| committer | degasus <wickmarkus@web.de> | 2014-01-21 23:44:51 +0100 |
| commit | 3cb5bb3b302809eb089b12d8ad6eb528d7db90ee (patch) | |
| tree | f26bfa3bb3840eae56374d205907b74e026c7ad1 /Source | |
| parent | 0b97b33ceb58cd72a9586c438f39866ec032d9a4 (diff) | |
VertexLoader: temp class for reader/writer
Diffstat (limited to 'Source')
| -rw-r--r-- | Source/Core/VideoCommon/DataReader.h | 39 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/VertexLoader_Normal.cpp | 6 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/VertexLoader_Position.cpp | 13 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/VertexLoader_TextCoord.cpp | 14 |
4 files changed, 44 insertions, 28 deletions
diff --git a/Source/Core/VideoCommon/DataReader.h b/Source/Core/VideoCommon/DataReader.h index b552ca34e4..3c56db9ae3 100644 --- a/Source/Core/VideoCommon/DataReader.h +++ b/Source/Core/VideoCommon/DataReader.h @@ -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() { @@ -133,16 +149,25 @@ __forceinline u8* DataGetPosition() } template <typename T> -__forceinline void DataWrite(u8* &dst, T data) +__forceinline void DataWrite(T data) { - *(T*)dst = data; - dst += sizeof(T); + *(T*)VertexManager::s_pCurBufferPointer = data; + VertexManager::s_pCurBufferPointer += sizeof(T); } -template <typename T> -__forceinline void DataWrite(T data) +class DataWriter { - DataWrite(VertexManager::s_pCurBufferPointer, data); -} +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 diff --git a/Source/Core/VideoCommon/VertexLoader_Normal.cpp b/Source/Core/VideoCommon/VertexLoader_Normal.cpp index fc9cf9e554..e4fb2c57ce 100644 --- a/Source/Core/VideoCommon/VertexLoader_Normal.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Normal.cpp @@ -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(); } diff --git a/Source/Core/VideoCommon/VertexLoader_Position.cpp b/Source/Core/VideoCommon/VertexLoader_Position.cpp index 6163272fb1..ee26acfbe7 100644 --- a/Source/Core/VideoCommon/VertexLoader_Position.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Position.cpp @@ -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(); } diff --git a/Source/Core/VideoCommon/VertexLoader_TextCoord.cpp b/Source/Core/VideoCommon/VertexLoader_TextCoord.cpp index ed97716768..dae72e22b8 100644 --- a/Source/Core/VideoCommon/VertexLoader_TextCoord.cpp +++ b/Source/Core/VideoCommon/VertexLoader_TextCoord.cpp @@ -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; |
