| 1 | /* |
| 2 | Copyright (C) 2002 Rice1964 |
| 3 | |
| 4 | This program is free software; you can redistribute it and/or |
| 5 | modify it under the terms of the GNU General Public License |
| 6 | as published by the Free Software Foundation; either version 2 |
| 7 | of the License, or (at your option) any later version. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License |
| 15 | along with this program; if not, write to the Free Software |
| 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | #ifndef _DECODEDMUX_H_ |
| 20 | #define _DECODEDMUX_H_ |
| 21 | |
| 22 | #include <string.h> |
| 23 | #include <stdio.h> |
| 24 | |
| 25 | #include "typedefs.h" |
| 26 | #include "CombinerDefs.h" |
| 27 | |
| 28 | typedef enum { |
| 29 | N64Cycle0RGB=0, |
| 30 | N64Cycle0Alpha=1, |
| 31 | N64Cycle1RGB=2, |
| 32 | N64Cycle1Alpha=3, |
| 33 | } N64StageNumberType; |
| 34 | |
| 35 | typedef union { |
| 36 | struct { |
| 37 | uint32 dwMux0; |
| 38 | uint32 dwMux1; |
| 39 | }; |
| 40 | uint64 Mux64; |
| 41 | } MuxType; |
| 42 | |
| 43 | typedef struct { |
| 44 | MuxType ori_mux; |
| 45 | MuxType simple_mux; |
| 46 | } SimpleMuxMapType; |
| 47 | |
| 48 | class DecodedMux |
| 49 | { |
| 50 | public: |
| 51 | union { |
| 52 | struct { |
| 53 | uint8 aRGB0; |
| 54 | uint8 bRGB0; |
| 55 | uint8 cRGB0; |
| 56 | uint8 dRGB0; |
| 57 | |
| 58 | uint8 aA0; |
| 59 | uint8 bA0; |
| 60 | uint8 cA0; |
| 61 | uint8 dA0; |
| 62 | |
| 63 | uint8 aRGB1; |
| 64 | uint8 bRGB1; |
| 65 | uint8 cRGB1; |
| 66 | uint8 dRGB1; |
| 67 | |
| 68 | uint8 aA1; |
| 69 | uint8 bA1; |
| 70 | uint8 cA1; |
| 71 | uint8 dA1; |
| 72 | }; |
| 73 | uint8 m_bytes[16]; |
| 74 | uint32 m_dWords[4]; |
| 75 | N64CombinerType m_n64Combiners[4]; |
| 76 | }; |
| 77 | |
| 78 | union { |
| 79 | struct { |
| 80 | uint32 m_dwMux0; |
| 81 | uint32 m_dwMux1; |
| 82 | }; |
| 83 | uint64 m_u64Mux; |
| 84 | }; |
| 85 | |
| 86 | CombinerFormatType splitType[4]; |
| 87 | CombinerFormatType mType; |
| 88 | |
| 89 | uint32 m_dwShadeColorChannelFlag; |
| 90 | uint32 m_dwShadeAlphaChannelFlag; |
| 91 | uint32 m_ColorTextureFlag[2]; // I may use a texture to represent a constant color |
| 92 | // when there are more constant colors are used than |
| 93 | // the system can support |
| 94 | |
| 95 | bool m_bShadeIsUsed[2]; // 0 for color channel, 1 for alpha channel |
| 96 | bool m_bTexel0IsUsed; |
| 97 | bool m_bTexel1IsUsed; |
| 98 | |
| 99 | int m_maxConstants; // OpenGL 1.1 does not really support a constant color in combiner |
| 100 | // must use shade for constants; |
| 101 | int m_maxTextures; // 1 or 2 |
| 102 | |
| 103 | |
| 104 | void Decode(uint32 dwMux0, uint32 dwMux1); |
| 105 | virtual void Hack(void); |
| 106 | bool isUsed(uint8 fac, uint8 mask=MUX_MASK); |
| 107 | bool isUsedInAlphaChannel(uint8 fac, uint8 mask=MUX_MASK); |
| 108 | bool isUsedInColorChannel(uint8 fac, uint8 mask=MUX_MASK); |
| 109 | bool isUsedInCycle(uint8 fac, int cycle, CombineChannel channel, uint8 mask=MUX_MASK); |
| 110 | bool isUsedInCycle(uint8 fac, int cycle, uint8 mask=MUX_MASK); |
| 111 | uint32 GetCycle(int cycle, CombineChannel channel); |
| 112 | uint32 GetCycle(int cycle); |
| 113 | CombinerFormatType GetCombinerFormatType(uint32 cycle); |
| 114 | void Display(bool simplified=true, FILE *fp=NULL); |
| 115 | static char* FormatStr(uint8 val, char *buf); |
| 116 | void CheckCombineInCycle1(void); |
| 117 | virtual void Simplify(void); |
| 118 | virtual void Reformat(bool do_complement = true); |
| 119 | virtual void To_AB_Add_CD_Format(void); // Use by TNT,Geforce |
| 120 | virtual void To_AB_Add_C_Format(void); // Use by ATI Radeon |
| 121 | |
| 122 | virtual void MergeShadeWithConstants(void); |
| 123 | virtual void MergeShadeWithConstantsInChannel(CombineChannel channel); |
| 124 | virtual void MergeConstants(void); |
| 125 | virtual void UseShadeForConstant(void); |
| 126 | virtual void UseTextureForConstant(void); |
| 127 | |
| 128 | void ConvertComplements(); |
| 129 | int HowManyConstFactors(); |
| 130 | int HowManyTextures(); |
| 131 | void MergeConstFactors(); |
| 132 | virtual void SplitComplexStages(); // Only used if the combiner supports more than 1 stages |
| 133 | void ConvertLODFracTo0(); |
| 134 | void ReplaceVal(uint8 val1, uint8 val2, int cycle= -1, uint8 mask = MUX_MASK); |
| 135 | void Replace1Val(uint8 &val1, const uint8 val2, uint8 mask = MUX_MASK) |
| 136 | { |
| 137 | val1 &= (~mask); |
| 138 | val1 |= val2; |
| 139 | } |
| 140 | int CountTexels(void); |
| 141 | int Count(uint8 val, int cycle= -1, uint8 mask = MUX_MASK); |
| 142 | |
| 143 | #ifdef DEBUGGER |
| 144 | void DisplayMuxString(const char *prompt); |
| 145 | void DisplaySimpliedMuxString(const char *prompt); |
| 146 | void DisplayConstantsWithShade(uint32 flag,CombineChannel channel); |
| 147 | #else |
| 148 | void DisplayMuxString(const char *prompt) {} |
| 149 | void DisplaySimpliedMuxString(const char *prompt){} |
| 150 | void DisplayConstantsWithShade(uint32 flag,CombineChannel channel){} |
| 151 | void LogMuxString(const char *prompt, FILE *fp); |
| 152 | void LogSimpliedMuxString(const char *prompt, FILE *fp); |
| 153 | void LogConstantsWithShade(uint32 flag,CombineChannel channel, FILE *fp); |
| 154 | #endif |
| 155 | |
| 156 | virtual DecodedMux& operator=(const DecodedMux& mux) |
| 157 | { |
| 158 | m_dWords[0] = mux.m_dWords[0]; |
| 159 | m_dWords[1] = mux.m_dWords[1]; |
| 160 | m_dWords[2] = mux.m_dWords[2]; |
| 161 | m_dWords[3] = mux.m_dWords[3]; |
| 162 | m_u64Mux = mux.m_u64Mux; |
| 163 | splitType[0] = mux.splitType[0]; |
| 164 | splitType[1] = mux.splitType[1]; |
| 165 | splitType[2] = mux.splitType[2]; |
| 166 | splitType[3] = mux.splitType[3]; |
| 167 | mType = mux.mType; |
| 168 | |
| 169 | m_dwShadeColorChannelFlag = mux.m_dwShadeColorChannelFlag; |
| 170 | m_dwShadeAlphaChannelFlag = mux.m_dwShadeAlphaChannelFlag; |
| 171 | |
| 172 | m_bShadeIsUsed[0] = mux.m_bShadeIsUsed[0]; |
| 173 | m_bShadeIsUsed[1] = mux.m_bShadeIsUsed[1]; |
| 174 | m_bTexel0IsUsed = mux.m_bTexel0IsUsed; |
| 175 | m_bTexel1IsUsed = mux.m_bTexel1IsUsed; |
| 176 | |
| 177 | m_maxConstants = mux.m_maxConstants; |
| 178 | m_maxTextures = mux.m_maxTextures; |
| 179 | m_ColorTextureFlag[0] = mux.m_ColorTextureFlag[0]; |
| 180 | m_ColorTextureFlag[1] = mux.m_ColorTextureFlag[1]; |
| 181 | |
| 182 | return *this; |
| 183 | } |
| 184 | |
| 185 | static inline bool IsConstFactor(uint8 val) |
| 186 | { |
| 187 | uint8 v = val&MUX_MASK; |
| 188 | return( v == MUX_0 || v == MUX_1 || v == MUX_PRIM || v == MUX_ENV || v == MUX_LODFRAC || v == MUX_PRIMLODFRAC ); |
| 189 | } |
| 190 | |
| 191 | DecodedMux() |
| 192 | { |
| 193 | memset(m_bytes, 0, sizeof(m_bytes)); |
| 194 | mType=CM_FMT_TYPE_NOT_CHECKED; |
| 195 | for( int i=0; i<4; i++ ) |
| 196 | { |
| 197 | splitType[i] = CM_FMT_TYPE_NOT_CHECKED; |
| 198 | } |
| 199 | m_maxConstants = 1; |
| 200 | m_maxTextures = 2; |
| 201 | } |
| 202 | |
| 203 | virtual ~DecodedMux() {} |
| 204 | }; |
| 205 | |
| 206 | class DecodedMuxForPixelShader : public DecodedMux |
| 207 | { |
| 208 | public: |
| 209 | virtual void Simplify(void); |
| 210 | void SplitComplexStages() {}; |
| 211 | }; |
| 212 | |
| 213 | class DecodedMuxForSemiPixelShader : public DecodedMux |
| 214 | { |
| 215 | public: |
| 216 | void Reset(void); |
| 217 | }; |
| 218 | |
| 219 | class DecodedMuxForOGL14V2 : public DecodedMuxForPixelShader |
| 220 | { |
| 221 | public: |
| 222 | virtual void Simplify(void); |
| 223 | void UseTextureForConstant(void); |
| 224 | }; |
| 225 | |
| 226 | typedef struct |
| 227 | { |
| 228 | bool bFurtherFormatForOGL2; |
| 229 | bool bUseShadeForConstants; |
| 230 | bool bUseTextureForConstants; |
| 231 | bool bUseMoreThan2TextureForConstants; |
| 232 | bool bReformatToAB_CD; |
| 233 | bool bAllowHack; |
| 234 | bool bAllowComplimentary; |
| 235 | bool bCheckCombineInCycle1; |
| 236 | bool bSetLODFracTo0; |
| 237 | bool bMergeShadeWithConstants; |
| 238 | bool bSplitComplexStage; |
| 239 | bool bReformatAgainWithTwoTexels; |
| 240 | } MuxConverterOptions; |
| 241 | |
| 242 | #endif |
| 243 | |
| 244 | |