2 Copyright (C) 2003 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 _GENERAL_COMBINER_H_
20 #define _GENERAL_COMBINER_H_
24 #include "DecodedMux.h"
26 class GeneralCombineStage
31 uint32 dwTexture; //Which texture to apply, 0 or 1
34 BOOL operator!=(const GeneralCombineStage & cs) const { return !(operator==(cs)); }
35 BOOL operator==(const GeneralCombineStage & cs) const
38 cs.colorOp.Arg1 == colorOp.Arg1 &&
39 cs.colorOp.Arg2 == colorOp.Arg2 &&
40 cs.colorOp.Arg0 == colorOp.Arg0 &&
41 cs.alphaOp.Arg1 == alphaOp.Arg1 &&
42 cs.alphaOp.Arg2 == alphaOp.Arg2 &&
43 cs.alphaOp.Arg0 == alphaOp.Arg0 &&
44 cs.colorOp.op == colorOp.op &&
45 cs.alphaOp.op == alphaOp.op &&
46 cs.dwTexture == dwTexture&&
47 cs.bTextureUsed==bTextureUsed);
51 class GeneralCombinerInfo
54 uint32 muxDWords[4]; // Simplified Mux
59 BlendingFunc blendingFunc;
61 uint32 m_dwShadeColorChannelFlag;
62 uint32 m_dwShadeAlphaChannelFlag;
63 uint32 specularPostOp;
64 uint32 colorTextureFlag[2];
66 GeneralCombineStage stages[8];
68 bool bResultIsGoodWithinStages;
70 BOOL operator!=(const GeneralCombinerInfo & sci) const { return !(operator==(sci)); }
71 BOOL operator==(const GeneralCombinerInfo & sci) const
75 if (sci.nStages != nStages)
77 if (sci.blendingFunc != blendingFunc)
80 for (i = 0; i < nStages; i++)
82 if (sci.stages[i] != stages[i])
86 if( sci.TFactor != TFactor )
88 if( sci.specularPostOp != specularPostOp )
90 if( sci.m_dwShadeColorChannelFlag != m_dwShadeColorChannelFlag )
92 if( sci.m_dwShadeAlphaChannelFlag != m_dwShadeAlphaChannelFlag )
94 if( sci.colorTextureFlag[0] != colorTextureFlag[0] )
96 if( sci.colorTextureFlag[1] != colorTextureFlag[1] )
109 CM_INTERPOLATE, // == LERP in DirectX, INTERPOLATE = OpenGL
111 CM_ADDSMOOTH, // For DirectX only, for OpenGL, use INTERPOLATE
112 CM_BLENDCURRENTALPHA, // For DirectX only, for OpenGL, use INTERPOLATE
113 CM_BLENDDIFFUSEALPHA, // For DirectX only, for OpenGL, use INTERPOLATE
114 CM_BLENDFACTORALPHA, // For DirectX only, for OpenGL, use INTERPOLATE
115 CM_BLENDTEXTUREALPHA, // For DirectX only, for OpenGL, use INTERPOLATE
116 CM_MULTIPLYADD, // For DirectX only
120 #define CM_IGNORE_BYTE 0xFF
122 /************************************************************************/
123 /* This general combiner class is designed for general DirectX combiner */
124 /* and OpenGL 1.2/1.3 combiner. Such combiners have the following */
125 /* limitions and conditions: */
127 /* - Supporting at least 2 textures */
128 /* - Supporting at least 2 combiner stages */
129 /* - At each combiner stages, only 1 texture can be used */
130 /* - Supporting only 1 constant color */
131 /* - Supporting more or less texture combine operations, depending */
132 /* on devices caps */
134 /* Before using this class, device caps boolean flags must be set */
135 /* externally by owner of the class object (or a subclass object). */
138 /************************************************************************/
139 class CGeneralCombiner
144 int FindCompiledMux();
145 int ParseDecodedMux();
146 void ParseDecodedMuxForConstants(GeneralCombinerInfo &res);
147 int SaveParserResult(GeneralCombinerInfo &result);
149 int m_lastGeneralIndex;
150 DecodedMux **m_ppGeneralDecodedMux;
158 bool m_bTxtOpLerp; // LERP is for DirectX, INTERPOLATE is for OpenGL
160 bool m_bTxtOpAddSmooth; // For DirectX only, for OpenGL, use INTERPOLATE
161 bool m_bTxtOpBlendCurAlpha; // For DirectX only, for OpenGL, use INTERPOLATE
162 bool m_bTxtOpBlendDifAlpha; // For DirectX only, for OpenGL, use INTERPOLATE
163 bool m_bTxtOpBlendFacAlpha; // For DirectX only, for OpenGL, use INTERPOLATE
164 bool m_bTxtOpBlendTxtAlpha; // For DirectX only, for OpenGL, use INTERPOLATE
165 bool m_bTxtOpMulAdd; // For DirectX only
167 int m_dwGeneralMaxStages;
169 std::vector<GeneralCombinerInfo> m_vCompiledCombinerStages;
172 // combiner info generating functions
173 void GenCI_Init(GeneralCombinerInfo &ci);
174 void SkipStage(StageOperate &op, int &curStage);
175 void NextStage(int &curStage);
176 void Check1TxtrForAlpha(int curN64Stage, int &curStage, GeneralCombinerInfo &ci, int tex);
177 int Check2TxtrForAlpha(int curN64Stage, int &curStage, GeneralCombinerInfo &ci, int tex1, int tex2);
178 int CheckWhichTexToUseInThisStage(int curN64Stage, int curStage, GeneralCombinerInfo &ci);
180 int GenCI_Type_D(int curN64Stage, int curStage, GeneralCombinerInfo &ci);
181 int GenCI_Type_A_MOD_C(int curN64Stage, int curStage, GeneralCombinerInfo &ci, uint32 dxop=CM_MODULATE);
182 int GenCI_Type_A_ADD_D(int curN64Stage, int curStage, GeneralCombinerInfo &ci);
183 int GenCI_Type_A_SUB_B(int curN64Stage, int curStage, GeneralCombinerInfo &ci);
184 int GenCI_Type_A_LERP_B_C(int curN64Stage, int curStage, GeneralCombinerInfo &ci);
185 int GenCI_Type_A_MOD_C_ADD_D(int curN64Stage, int curStage, GeneralCombinerInfo &ci);
186 int GenCI_Type_A_SUB_B_ADD_D(int curN64Stage, int curStage, GeneralCombinerInfo &ci);
187 int GenCI_Type_A_SUB_B_MOD_C(int curN64Stage, int curStage, GeneralCombinerInfo &ci);
188 int GenCI_Type_A_ADD_B_MOD_C(int curN64Stage, int curStage, GeneralCombinerInfo &ci);
189 int GenCI_Type_A_B_C_D(int curN64Stage, int curStage, GeneralCombinerInfo &ci);
190 int GenCI_Type_A_B_C_A(int curN64Stage, int curStage, GeneralCombinerInfo &ci);
193 // New functions, generate stages within the stage limition
194 // And return the number of stages used
195 // channel = 0 for color channel
196 // channel = 1 for alpha channel
197 // checktexture = true, need to use if texture matching in the stage
198 // checktexture = false, no check, just use any texture in the stage (since this stage hasn't been used)
199 int LM_GenCI_Type_D(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci);
200 int LM_GenCI_Type_A_MOD_C(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci, uint32 dxop=CM_MODULATE);
201 int LM_GenCI_Type_A_ADD_D(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci);
202 int LM_GenCI_Type_A_SUB_B(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci);
203 int LM_GenCI_Type_A_LERP_B_C(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci);
204 int LM_GenCI_Type_A_MOD_C_ADD_D(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci);
205 int LM_GenCI_Type_A_SUB_B_ADD_D(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci);
206 int LM_GenCI_Type_A_SUB_B_MOD_C(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci);
207 int LM_GenCI_Type_A_ADD_B_MOD_C(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci);
208 int LM_GenCI_Type_A_B_C_D(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci);
209 int LM_GenCI_Type_A_B_C_A(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci);
210 void LM_GenCI_Init(GeneralCombinerInfo &ci);
211 int LM_ParseDecodedMux();
212 bool LM_Check1TxtrForAlpha(int curStage, GeneralCombinerInfo &ci, uint32 val);
213 void LM_SkipStage(StageOperate &op);
216 bool IsTextureUsedInStage(GeneralCombineStage &stage);
219 void General_DisplayBlendingStageInfo(GeneralCombinerInfo &ci);