Merged identical VertexManager code from DX9/DX11/OGL plugins into VideoCommon. Still...
[dolphin.git] / Source / Core / VideoCommon / Src / VertexLoader_Color.cpp
blob362a777ffba93d4b49aaf9dbe7f5ddde564a9e68
1 // Copyright (C) 2003 Dolphin Project.
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0.
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 2.0 for more details.
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
15 // Official SVN repository and contact information can be found at
16 // http://code.google.com/p/dolphin-emu/
18 #ifndef _VERTEXLOADERCOLOR_H
19 #define _VERTEXLOADERCOLOR_H
21 #include "Common.h"
22 #include "VideoCommon.h"
23 #include "LookUpTables.h"
24 #include "VertexLoader.h"
25 #include "VertexLoader_Color.h"
26 #include "VertexManagerBase.h"
28 #define RSHIFT 0
29 #define GSHIFT 8
30 #define BSHIFT 16
31 #define ASHIFT 24
33 extern int colIndex;
34 extern int colElements[2];
36 __forceinline void _SetCol(u32 val)
38 *(u32*)VertexManager::s_pCurBufferPointer = val;
39 VertexManager::s_pCurBufferPointer += 4;
40 colIndex++;
43 __forceinline void _SetCol4444(u16 val)
45 u32 col = Convert4To8(val & 0xF) << ASHIFT;
46 col |= Convert4To8((val >> 12) & 0xF) << RSHIFT;
47 col |= Convert4To8((val >> 8) & 0xF) << GSHIFT;
48 col |= Convert4To8((val >> 4) & 0xF) << BSHIFT;
49 _SetCol(col);
52 __forceinline void _SetCol6666(u32 val)
54 u32 col = Convert6To8((val >> 18) & 0x3F) << RSHIFT;
55 col |= Convert6To8((val >> 12) & 0x3F) << GSHIFT;
56 col |= Convert6To8((val >> 6) & 0x3F) << BSHIFT;
57 col |= Convert6To8(val & 0x3F) << ASHIFT;
58 _SetCol(col);
61 __forceinline void _SetCol565(u16 val)
63 u32 col = Convert5To8((val >> 11) & 0x1F) << RSHIFT;
64 col |= Convert6To8((val >> 5) & 0x3F) << GSHIFT;
65 col |= Convert5To8(val & 0x1F) << BSHIFT;
66 _SetCol(col | (0xFF << ASHIFT));
70 __forceinline u32 _Read24(const u8 *addr)
72 return addr[0] | (addr[1] << 8) | (addr[2] << 16) | 0xFF000000;
75 __forceinline u32 _Read32(const u8 *addr)
77 return *(const u32 *)addr;
83 void LOADERDECL Color_ReadDirect_24b_888()
85 u32 col = DataReadU8() << RSHIFT;
86 col |= DataReadU8() << GSHIFT;
87 col |= DataReadU8() << BSHIFT;
88 _SetCol(col | (0xFF << ASHIFT));
91 void LOADERDECL Color_ReadDirect_32b_888x(){
92 u32 col = DataReadU8() << RSHIFT;
93 col |= DataReadU8() << GSHIFT;
94 col |= DataReadU8() << BSHIFT;
95 _SetCol(col | (0xFF << ASHIFT));
96 DataReadU8();
98 void LOADERDECL Color_ReadDirect_16b_565()
100 _SetCol565(DataReadU16());
102 void LOADERDECL Color_ReadDirect_16b_4444()
104 _SetCol4444(DataReadU16());
106 void LOADERDECL Color_ReadDirect_24b_6666()
108 u32 val = DataReadU8() << 16;
109 val |= DataReadU8() << 8;
110 val |= DataReadU8();
111 _SetCol6666(val);
114 // F|RES: i am not 100 percent sure, but the colElements seems to be important for rendering only
115 // at least it fixes mario party 4
117 // if (colElements[colIndex])
118 // else
119 // col |= 0xFF<<ASHIFT;
121 void LOADERDECL Color_ReadDirect_32b_8888()
123 // TODO (mb2): check this
124 u32 col = DataReadU32Unswapped();
126 // "kill" the alpha
127 if (!colElements[colIndex])
128 col |= 0xFF << ASHIFT;
130 _SetCol(col);
135 void LOADERDECL Color_ReadIndex8_16b_565()
137 u8 Index = DataReadU8();
138 u16 val = Common::swap16(*(const u16 *)(cached_arraybases[ARRAY_COLOR+colIndex] + (Index * arraystrides[ARRAY_COLOR+colIndex])));
139 _SetCol565(val);
141 void LOADERDECL Color_ReadIndex8_24b_888()
143 u8 Index = DataReadU8();
144 const u8 *iAddress = cached_arraybases[ARRAY_COLOR+colIndex] + (Index * arraystrides[ARRAY_COLOR+colIndex]);
145 _SetCol(_Read24(iAddress));
147 void LOADERDECL Color_ReadIndex8_32b_888x()
149 u8 Index = DataReadU8();
150 const u8 *iAddress = cached_arraybases[ARRAY_COLOR+colIndex] + (Index * arraystrides[ARRAY_COLOR]+colIndex);
151 _SetCol(_Read24(iAddress));
153 void LOADERDECL Color_ReadIndex8_16b_4444()
155 u8 Index = DataReadU8();
156 u16 val = Common::swap16(*(const u16 *)(cached_arraybases[ARRAY_COLOR+colIndex] + (Index * arraystrides[ARRAY_COLOR+colIndex])));
157 _SetCol4444(val);
159 void LOADERDECL Color_ReadIndex8_24b_6666()
161 u8 Index = DataReadU8();
162 const u8* pData = cached_arraybases[ARRAY_COLOR+colIndex] + (Index * arraystrides[ARRAY_COLOR+colIndex]);
163 u32 val = pData[2] | (pData[1] << 8) | (pData[0] << 16);
164 _SetCol6666(val);
166 void LOADERDECL Color_ReadIndex8_32b_8888()
168 u8 Index = DataReadU8();
169 const u8 *iAddress = cached_arraybases[ARRAY_COLOR+colIndex] + (Index * arraystrides[ARRAY_COLOR+colIndex]);
170 _SetCol(_Read32(iAddress));
175 void LOADERDECL Color_ReadIndex16_16b_565()
177 u16 Index = DataReadU16();
178 u16 val = Common::swap16(*(const u16 *)(cached_arraybases[ARRAY_COLOR+colIndex] + (Index * arraystrides[ARRAY_COLOR+colIndex])));
179 _SetCol565(val);
181 void LOADERDECL Color_ReadIndex16_24b_888()
183 u16 Index = DataReadU16();
184 const u8 *iAddress = cached_arraybases[ARRAY_COLOR+colIndex] + (Index * arraystrides[ARRAY_COLOR+colIndex]);
185 _SetCol(_Read24(iAddress));
187 void LOADERDECL Color_ReadIndex16_32b_888x()
189 u16 Index = DataReadU16();
190 const u8 *iAddress = cached_arraybases[ARRAY_COLOR+colIndex] + (Index * arraystrides[ARRAY_COLOR+colIndex]);
191 _SetCol(_Read24(iAddress));
193 void LOADERDECL Color_ReadIndex16_16b_4444()
195 u16 Index = DataReadU16();
196 u16 val = Common::swap16(*(const u16 *)(cached_arraybases[ARRAY_COLOR+colIndex] + (Index * arraystrides[ARRAY_COLOR+colIndex])));
197 _SetCol4444(val);
199 void LOADERDECL Color_ReadIndex16_24b_6666()
201 u16 Index = DataReadU16();
202 const u8 *pData = cached_arraybases[ARRAY_COLOR+colIndex] + (Index * arraystrides[ARRAY_COLOR+colIndex]);
203 u32 val = pData[2] | (pData[1] << 8) | (pData[0] << 16);
204 _SetCol6666(val);
206 void LOADERDECL Color_ReadIndex16_32b_8888()
208 u16 Index = DataReadU16();
209 const u8 *iAddress = cached_arraybases[ARRAY_COLOR+colIndex] + (Index * arraystrides[ARRAY_COLOR+colIndex]);
210 _SetCol(_Read32(iAddress));
213 #endif