2 Copyright (C) 2002 Rice1964
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.
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.
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.
19 #ifndef _DECODEDMUX_H_
20 #define _DECODEDMUX_H_
26 #include "CombinerDefs.h"
75 N64CombinerType m_n64Combiners[4];
86 CombinerFormatType splitType[4];
87 CombinerFormatType mType;
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
95 bool m_bShadeIsUsed[2]; // 0 for color channel, 1 for alpha channel
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
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
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);
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)
140 int CountTexels(void);
141 int Count(uint8 val, int cycle= -1, uint8 mask = MUX_MASK);
144 void DisplayMuxString(const char *prompt);
145 void DisplaySimpliedMuxString(const char *prompt);
146 void DisplayConstantsWithShade(uint32 flag,CombineChannel channel);
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);
156 virtual DecodedMux& operator=(const DecodedMux& mux)
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];
169 m_dwShadeColorChannelFlag = mux.m_dwShadeColorChannelFlag;
170 m_dwShadeAlphaChannelFlag = mux.m_dwShadeAlphaChannelFlag;
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;
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];
185 static inline bool IsConstFactor(uint8 val)
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 );
193 memset(m_bytes, 0, sizeof(m_bytes));
194 mType=CM_FMT_TYPE_NOT_CHECKED;
195 for( int i=0; i<4; i++ )
197 splitType[i] = CM_FMT_TYPE_NOT_CHECKED;
203 virtual ~DecodedMux() {}
206 class DecodedMuxForPixelShader : public DecodedMux
209 virtual void Simplify(void);
210 void SplitComplexStages() {};
213 class DecodedMuxForSemiPixelShader : public DecodedMux
219 class DecodedMuxForOGL14V2 : public DecodedMuxForPixelShader
222 virtual void Simplify(void);
223 void UseTextureForConstant(void);
228 bool bFurtherFormatForOGL2;
229 bool bUseShadeForConstants;
230 bool bUseTextureForConstants;
231 bool bUseMoreThan2TextureForConstants;
232 bool bReformatToAB_CD;
234 bool bAllowComplimentary;
235 bool bCheckCombineInCycle1;
237 bool bMergeShadeWithConstants;
238 bool bSplitComplexStage;
239 bool bReformatAgainWithTwoTexels;
240 } MuxConverterOptions;