Path: blob/master/libmupen64plus/mupen64plus-video-rice/src/GeneralCombiner.h
2 views
/*1Copyright (C) 2003 Rice196423This program is free software; you can redistribute it and/or4modify it under the terms of the GNU General Public License5as published by the Free Software Foundation; either version 26of the License, or (at your option) any later version.78This program is distributed in the hope that it will be useful,9but WITHOUT ANY WARRANTY; without even the implied warranty of10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11GNU General Public License for more details.1213You should have received a copy of the GNU General Public License14along with this program; if not, write to the Free Software15Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.16*/1718#ifndef _GENERAL_COMBINER_H_19#define _GENERAL_COMBINER_H_2021#include <vector>2223#include "DecodedMux.h"2425class GeneralCombineStage26{27public:28StageOperate colorOp;29StageOperate alphaOp;30uint32 dwTexture; //Which texture to apply, 0 or 131bool bTextureUsed;3233BOOL operator!=(const GeneralCombineStage & cs) const { return !(operator==(cs)); }34BOOL operator==(const GeneralCombineStage & cs) const35{36return (37cs.colorOp.Arg1 == colorOp.Arg1 &&38cs.colorOp.Arg2 == colorOp.Arg2 &&39cs.colorOp.Arg0 == colorOp.Arg0 &&40cs.alphaOp.Arg1 == alphaOp.Arg1 &&41cs.alphaOp.Arg2 == alphaOp.Arg2 &&42cs.alphaOp.Arg0 == alphaOp.Arg0 &&43cs.colorOp.op == colorOp.op &&44cs.alphaOp.op == alphaOp.op &&45cs.dwTexture == dwTexture&&46cs.bTextureUsed==bTextureUsed);47}48};4950class GeneralCombinerInfo51{52public:53uint32 muxDWords[4]; // Simplified Mux54uint32 dwMux0;55uint32 dwMux1;56int nStages;5758BlendingFunc blendingFunc;59uint32 TFactor;60uint32 m_dwShadeColorChannelFlag;61uint32 m_dwShadeAlphaChannelFlag;62uint32 specularPostOp;63uint32 colorTextureFlag[2];6465GeneralCombineStage stages[8];6667bool bResultIsGoodWithinStages;6869BOOL operator!=(const GeneralCombinerInfo & sci) const { return !(operator==(sci)); }70BOOL operator==(const GeneralCombinerInfo & sci) const71{72int i;7374if (sci.nStages != nStages)75return FALSE;76if (sci.blendingFunc != blendingFunc)77return FALSE;7879for (i = 0; i < nStages; i++)80{81if (sci.stages[i] != stages[i])82return FALSE;83}8485if( sci.TFactor != TFactor )86return FALSE;87if( sci.specularPostOp != specularPostOp )88return FALSE;89if( sci.m_dwShadeColorChannelFlag != m_dwShadeColorChannelFlag )90return FALSE;91if( sci.m_dwShadeAlphaChannelFlag != m_dwShadeAlphaChannelFlag )92return FALSE;93if( sci.colorTextureFlag[0] != colorTextureFlag[0] )94return FALSE;95if( sci.colorTextureFlag[1] != colorTextureFlag[1] )96return FALSE;9798return TRUE;99}100};101102enum CombinerOp103{104CM_REPLACE,105CM_MODULATE,106CM_ADD,107CM_SUBTRACT,108CM_INTERPOLATE, // == LERP in DirectX, INTERPOLATE = OpenGL109110CM_ADDSMOOTH, // For DirectX only, for OpenGL, use INTERPOLATE111CM_BLENDCURRENTALPHA, // For DirectX only, for OpenGL, use INTERPOLATE112CM_BLENDDIFFUSEALPHA, // For DirectX only, for OpenGL, use INTERPOLATE113CM_BLENDFACTORALPHA, // For DirectX only, for OpenGL, use INTERPOLATE114CM_BLENDTEXTUREALPHA, // For DirectX only, for OpenGL, use INTERPOLATE115CM_MULTIPLYADD, // For DirectX only116};117118#define CM_IGNORE 0119#define CM_IGNORE_BYTE 0xFF120121/************************************************************************/122/* This general combiner class is designed for general DirectX combiner */123/* and OpenGL 1.2/1.3 combiner. Such combiners have the following */124/* limitions and conditions: */125/* */126/* - Supporting at least 2 textures */127/* - Supporting at least 2 combiner stages */128/* - At each combiner stages, only 1 texture can be used */129/* - Supporting only 1 constant color */130/* - Supporting more or less texture combine operations, depending */131/* on devices caps */132/* */133/* Before using this class, device caps boolean flags must be set */134/* externally by owner of the class object (or a subclass object). */135/* */136/* */137/************************************************************************/138class CGeneralCombiner139{140protected:141CGeneralCombiner();142143int FindCompiledMux();144int ParseDecodedMux();145void ParseDecodedMuxForConstants(GeneralCombinerInfo &res);146int SaveParserResult(GeneralCombinerInfo &result);147148int m_lastGeneralIndex;149DecodedMux **m_ppGeneralDecodedMux;150151/*152* Texture ops flags153*/154155bool m_bTxtOpAdd;156bool m_bTxtOpSub;157bool m_bTxtOpLerp; // LERP is for DirectX, INTERPOLATE is for OpenGL158159bool m_bTxtOpAddSmooth; // For DirectX only, for OpenGL, use INTERPOLATE160bool m_bTxtOpBlendCurAlpha; // For DirectX only, for OpenGL, use INTERPOLATE161bool m_bTxtOpBlendDifAlpha; // For DirectX only, for OpenGL, use INTERPOLATE162bool m_bTxtOpBlendFacAlpha; // For DirectX only, for OpenGL, use INTERPOLATE163bool m_bTxtOpBlendTxtAlpha; // For DirectX only, for OpenGL, use INTERPOLATE164bool m_bTxtOpMulAdd; // For DirectX only165166int m_dwGeneralMaxStages;167168std::vector<GeneralCombinerInfo> m_vCompiledCombinerStages;169170protected:171// combiner info generating functions172void GenCI_Init(GeneralCombinerInfo &ci);173void SkipStage(StageOperate &op, int &curStage);174void NextStage(int &curStage);175void Check1TxtrForAlpha(int curN64Stage, int &curStage, GeneralCombinerInfo &ci, int tex);176int Check2TxtrForAlpha(int curN64Stage, int &curStage, GeneralCombinerInfo &ci, int tex1, int tex2);177int CheckWhichTexToUseInThisStage(int curN64Stage, int curStage, GeneralCombinerInfo &ci);178179int GenCI_Type_D(int curN64Stage, int curStage, GeneralCombinerInfo &ci);180int GenCI_Type_A_MOD_C(int curN64Stage, int curStage, GeneralCombinerInfo &ci, uint32 dxop=CM_MODULATE);181int GenCI_Type_A_ADD_D(int curN64Stage, int curStage, GeneralCombinerInfo &ci);182int GenCI_Type_A_SUB_B(int curN64Stage, int curStage, GeneralCombinerInfo &ci);183int GenCI_Type_A_LERP_B_C(int curN64Stage, int curStage, GeneralCombinerInfo &ci);184int GenCI_Type_A_MOD_C_ADD_D(int curN64Stage, int curStage, GeneralCombinerInfo &ci);185int GenCI_Type_A_SUB_B_ADD_D(int curN64Stage, int curStage, GeneralCombinerInfo &ci);186int GenCI_Type_A_SUB_B_MOD_C(int curN64Stage, int curStage, GeneralCombinerInfo &ci);187int GenCI_Type_A_ADD_B_MOD_C(int curN64Stage, int curStage, GeneralCombinerInfo &ci);188int GenCI_Type_A_B_C_D(int curN64Stage, int curStage, GeneralCombinerInfo &ci);189int GenCI_Type_A_B_C_A(int curN64Stage, int curStage, GeneralCombinerInfo &ci);190191192// New functions, generate stages within the stage limition193// And return the number of stages used194// channel = 0 for color channel195// channel = 1 for alpha channel196// checktexture = true, need to use if texture matching in the stage197// checktexture = false, no check, just use any texture in the stage (since this stage hasn't been used)198int LM_GenCI_Type_D(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci);199int LM_GenCI_Type_A_MOD_C(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci, uint32 dxop=CM_MODULATE);200int LM_GenCI_Type_A_ADD_D(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci);201int LM_GenCI_Type_A_SUB_B(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci);202int LM_GenCI_Type_A_LERP_B_C(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci);203int LM_GenCI_Type_A_MOD_C_ADD_D(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci);204int LM_GenCI_Type_A_SUB_B_ADD_D(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci);205int LM_GenCI_Type_A_SUB_B_MOD_C(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci);206int LM_GenCI_Type_A_ADD_B_MOD_C(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci);207int LM_GenCI_Type_A_B_C_D(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci);208int LM_GenCI_Type_A_B_C_A(N64CombinerType &m, int curStage, int limit, int channel, bool checktexture, GeneralCombinerInfo &ci);209void LM_GenCI_Init(GeneralCombinerInfo &ci);210int LM_ParseDecodedMux();211bool LM_Check1TxtrForAlpha(int curStage, GeneralCombinerInfo &ci, uint32 val);212void LM_SkipStage(StageOperate &op);213214215bool IsTextureUsedInStage(GeneralCombineStage &stage);216217#ifdef DEBUGGER218void General_DisplayBlendingStageInfo(GeneralCombinerInfo &ci);219#endif220221};222223#endif224225226227