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 #include <SDL_opengles.h>
21 #include "CGLESCombiner.h"
23 CGLESCombiner::CGLESCombiner()
28 CGLESCombiner::~CGLESCombiner()
33 int CGLESCombiner::FindCompiledMux( )
35 for( uint32 i=0; i<m_vCompiledGLESSettings.size(); i++ )
37 if( m_vCompiledGLESSettings[i].dwMux0 == (*m_ppDecodedMux)->m_dwMux0 && m_vCompiledGLESSettings[i].dwMux1 == (*m_ppDecodedMux)->m_dwMux1 )
47 bool isTex(uint32 val);
48 bool isComb(uint32 val);
50 int CGLESCombiner::ParseDecodedMux()
52 GLESCombinerSaveType res;
55 (*m_ppDecodedMux)->To_AB_Add_CD_Format();
57 for( int i=0; i<res.numOfUnits*2; i++ ) // Set combiner for each texture unit
59 // For each texture unit, set both RGB and Alpha channel
60 // Keep in mind that the m_pDecodeMux has been reformated and simplified very well
62 GLESCombinerType &unit = res.units[i/2];
63 GLESCombType &comb = unit.Combs[i%2];
65 CombinerFormatType type = (*m_ppDecodedMux)->splitType[i];
66 N64CombinerType &m = (*m_ppDecodedMux)->m_n64Combiners[i];
68 comb.arg0 = comb.arg1 = comb.arg2 = comb.arg3 = MUX_0;
69 unit.ops[i%2] = 0x0104; //Add;
74 case CM_FMT_TYPE_NOT_USED:
75 comb.arg0 = MUX_COMBINED;
79 case CM_FMT_TYPE_D: // = A
85 case CM_FMT_TYPE_A_ADD_D: // = A+D
92 swap(comb.arg0, comb.arg2);
93 swap(comb.arg1, comb.arg3);
96 case CM_FMT_TYPE_A_SUB_B: // = A-B
97 comb.arg0 = m.a^MUX_COMPLEMENT;
99 unit.ops[i%2] = GL_SUBTRACT_ARB;
103 case CM_FMT_TYPE_A_MOD_C: // = A*C
109 case CM_FMT_TYPE_A_MOD_C_ADD_D: // = A*C+D
116 swap(comb.arg0, comb.arg2);
117 swap(comb.arg1, comb.arg3);
120 case CM_FMT_TYPE_A_LERP_B_C: // = (A-B)*C+B
123 comb.arg2 = m.c^MUX_COMPLEMENT;
127 swap(comb.arg0, comb.arg2);
128 swap(comb.arg1, comb.arg3);
131 case CM_FMT_TYPE_A_SUB_B_ADD_D: // = A-B+D
132 // fix me, to use 2 texture units
133 if( isTex(m.b) && isTex(m.d) )
141 swap(comb.arg0, comb.arg2);
142 swap(comb.arg1, comb.arg3);
145 else if( isTex(m.b) && !isComb(m.d) )
147 comb.arg0 = m.a^MUX_COMPLEMENT;
151 unit.ops[i%2] = GL_SUBTRACT_ARB;
153 else if( !isTex(m.b) && isTex(m.d) )
161 swap(comb.arg0, comb.arg2);
162 swap(comb.arg1, comb.arg3);
173 swap(comb.arg0, comb.arg2);
174 swap(comb.arg1, comb.arg3);
178 case CM_FMT_TYPE_A_SUB_B_MOD_C: // = (A-B)*C
179 comb.arg0 = m.a^MUX_COMPLEMENT;
183 unit.ops[i%2] = GL_SUBTRACT_ARB;
185 case CM_FMT_TYPE_AB_ADD_CD: // = AB+CD
190 if( isComb(m.d) || isComb(m.c) )
192 swap(comb.arg0, comb.arg2);
193 swap(comb.arg1, comb.arg3);
197 case CM_FMT_TYPE_AB_SUB_CD: // = AB-CD
198 comb.arg0 = m.a^MUX_COMPLEMENT;
200 unit.ops[i%2] = GL_SUBTRACT_ARB;
204 case CM_FMT_TYPE_A_B_C_D: // = (A-B)*C+D
206 if( !isComb(m.d) && !isTex(m.d) )
208 comb.arg0 = m.a^MUX_COMPLEMENT;
210 unit.ops[i%2] = GL_SUBTRACT_ARB;
214 else if( !isComb(m.b) && !isTex(m.b) )
222 swap(comb.arg0, comb.arg2);
223 swap(comb.arg1, comb.arg3);
226 else if( !isComb(m.c) && !isTex(m.c) )
234 swap(comb.arg0, comb.arg2);
235 swap(comb.arg1, comb.arg3);
246 swap(comb.arg0, comb.arg2);
247 swap(comb.arg1, comb.arg3);
254 ParseDecodedMuxForConstants(res);
255 return SaveParserResult(res);
258 int CNvTNTCombiner::SaveParserResult(TNT2CombinerSaveType &result)
260 result.dwMux0 = (*m_ppDecodedMux)->m_dwMux0;
261 result.dwMux1 = (*m_ppDecodedMux)->m_dwMux1;
263 m_vCompiledTNTSettings.push_back(result);
264 m_lastIndexTNT = m_vCompiledTNTSettings.size()-1;
269 DisplaySimpleMuxString();
273 return m_lastIndexTNT;
276 void CNvTNTCombiner::ParseDecodedMuxForConstants(TNT2CombinerSaveType &res)
278 res.unit1.constant = MUX_0;
279 res.unit2.constant = MUX_0;
281 for( int i=0; i<2; i++ )
283 if( (*m_ppDecodedMux)->isUsedInCycle(MUX_PRIM, i,COLOR_CHANNEL) || (*m_ppDecodedMux)->isUsedInCycle(MUX_PRIM, i,ALPHA_CHANNEL) )
285 res.units[i].constant = MUX_PRIM;
287 else if( (*m_ppDecodedMux)->isUsedInCycle(MUX_ENV, i,COLOR_CHANNEL) || (*m_ppDecodedMux)->isUsedInCycle(MUX_ENV, i,ALPHA_CHANNEL) )
289 res.units[i].constant = MUX_ENV;
291 else if( (*m_ppDecodedMux)->isUsedInCycle(MUX_LODFRAC, i,COLOR_CHANNEL) || (*m_ppDecodedMux)->isUsedInCycle(MUX_LODFRAC, i,ALPHA_CHANNEL) )
293 res.units[i].constant = MUX_LODFRAC;
295 else if( (*m_ppDecodedMux)->isUsedInCycle(MUX_PRIMLODFRAC, i,COLOR_CHANNEL) || (*m_ppDecodedMux)->isUsedInCycle(MUX_PRIMLODFRAC, i,ALPHA_CHANNEL) )
297 res.units[i].constant = MUX_PRIMLODFRAC;
303 extern const char *translatedCombTypes[];
304 void CNvTNTCombiner::DisplaySimpleMuxString()
311 TNT2CombinerSaveType &result = m_vCompiledTNTSettings[m_lastIndexTNT];
313 TRACE0("\nNVidia TNT2+ Combiner\n");
314 DebuggerAppendMsg("//aRGB0:\t(%s * %s) %s (%s * %s)\n", DecodedMux::FormatStr(result.unit1.rgbArg0,buf0), DecodedMux::FormatStr(result.unit1.rgbArg1,buf1), result.unit1.rgbOp==0x0104?"+":"-", DecodedMux::FormatStr(result.unit1.rgbArg2,buf2), DecodedMux::FormatStr(result.unit1.rgbArg3,buf3));
315 DebuggerAppendMsg("//aRGB1:\t(%s * %s) %s (%s * %s)\n", DecodedMux::FormatStr(result.unit2.rgbArg0,buf0), DecodedMux::FormatStr(result.unit2.rgbArg1,buf1), result.unit2.rgbOp==0x0104?"+":"-", DecodedMux::FormatStr(result.unit2.rgbArg2,buf2), DecodedMux::FormatStr(result.unit2.rgbArg3,buf3));
316 DebuggerAppendMsg("//aAlpha0:\t(%s * %s) %s (%s * %s)\n", DecodedMux::FormatStr(result.unit1.alphaArg0,buf0), DecodedMux::FormatStr(result.unit1.alphaArg1,buf1), result.unit1.alphaOp==0x0104?"+":"-", DecodedMux::FormatStr(result.unit1.alphaArg2,buf2), DecodedMux::FormatStr(result.unit1.alphaArg3,buf3));
317 DebuggerAppendMsg("//aAlpha1:\t(%s * %s) %s (%s * %s)\n", DecodedMux::FormatStr(result.unit2.alphaArg0,buf0), DecodedMux::FormatStr(result.unit2.alphaArg1,buf1), result.unit2.alphaOp==0x0104?"+":"-", DecodedMux::FormatStr(result.unit2.alphaArg2,buf2), DecodedMux::FormatStr(result.unit2.alphaArg3,buf3));
318 if( result.unit1.constant != MUX_0 )
319 DebuggerAppendMsg("//Constant for unit 1:\t%s\n", DecodedMux::FormatStr(result.unit1.constant,buf0));
320 if( result.unit2.constant != MUX_0 )
321 DebuggerAppendMsg("//Constant for unit 2:\t%s\n", DecodedMux::FormatStr(result.unit2.constant,buf0));