From 4f471ffeb6230d28223455c527ec810fb4986a93 Mon Sep 17 00:00:00 2001 From: hrydgard Date: Sun, 15 Feb 2009 13:08:21 +0000 Subject: [PATCH] color vertexloader: make read24 safer, speedup direct 8888 a tiny bit git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2253 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/VideoCommon/Src/DataReader.h | 34 +++++++++++++++++++ .../VideoCommon/Src/VertexLoader_Color.cpp | 19 +++++------ .../Plugins/Plugin_VideoOGL/Src/BPStructs.cpp | 3 +- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/Source/Core/VideoCommon/Src/DataReader.h b/Source/Core/VideoCommon/Src/DataReader.h index af604fafb3..97340c2928 100644 --- a/Source/Core/VideoCommon/Src/DataReader.h +++ b/Source/Core/VideoCommon/Src/DataReader.h @@ -54,6 +54,40 @@ inline u32 DataReadU32() return tmp; } +inline u32 DataReadU32Unswapped() +{ + u32 tmp = *(u32*)g_pVideoData; + g_pVideoData += 4; + return tmp; +} + + +// These are not used yet. If they don't build under Linux, delete them and let me know. -ector +template +inline T DataRead() +{ + T tmp = *(T*)g_pVideoData; + g_pVideoData += sizeof(T); + return tmp; +} + +template <> +inline u16 DataRead() +{ + u16 tmp = Common::swap16(*(u16*)g_pVideoData); + g_pVideoData += 2; + return tmp; +} + +template <> +inline u32 DataRead() +{ + u32 tmp = Common::swap32(*(u32*)g_pVideoData); + g_pVideoData += 4; + return tmp; +} + + inline float DataReadF32() { union {u32 i; float f;} temp; diff --git a/Source/Core/VideoCommon/Src/VertexLoader_Color.cpp b/Source/Core/VideoCommon/Src/VertexLoader_Color.cpp index 8ef382c353..ec76f05e6e 100644 --- a/Source/Core/VideoCommon/Src/VertexLoader_Color.cpp +++ b/Source/Core/VideoCommon/Src/VertexLoader_Color.cpp @@ -67,14 +67,14 @@ void _SetCol565(u16 val) } ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// -inline u32 _Read24(const u8 *iAddress) +inline u32 _Read24(const u8 *addr) { - return *(const u32 *)iAddress | 0xFF000000; + return addr[0] | (addr[1] << 8) | (addr[2] << 16) | 0xFF000000; } -inline u32 _Read32(const u8 *iAddress) +inline u32 _Read32(const u8 *addr) { - return *(const u32 *)iAddress; + return *(const u32 *)addr; } ////////////////////////////////////////////////////////////////////////// @@ -105,9 +105,9 @@ void LOADERDECL Color_ReadDirect_16b_4444() } void LOADERDECL Color_ReadDirect_24b_6666() { - u32 val = DataReadU8()<<16; - val|=DataReadU8()<<8; - val|=DataReadU8(); + u32 val = DataReadU8() << 16; + val |= DataReadU8() << 8; + val |= DataReadU8(); _SetCol6666(val); } @@ -121,10 +121,7 @@ void LOADERDECL Color_ReadDirect_24b_6666() void LOADERDECL Color_ReadDirect_32b_8888() { // TODO (mb2): check this - u32 col = DataReadU8()<