Path: blob/master/libmupen64plus/mupen64plus-video-rice/src/DecodedMux.h
2 views
/*1Copyright (C) 2002 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 _DECODEDMUX_H_19#define _DECODEDMUX_H_2021#include <string.h>22#include <stdio.h>2324#include "typedefs.h"25#include "CombinerDefs.h"2627typedef enum {28N64Cycle0RGB=0,29N64Cycle0Alpha=1,30N64Cycle1RGB=2,31N64Cycle1Alpha=3,32} N64StageNumberType;3334typedef union {35struct {36uint32 dwMux0;37uint32 dwMux1;38};39uint64 Mux64;40} MuxType;4142typedef struct {43MuxType ori_mux;44MuxType simple_mux;45} SimpleMuxMapType;4647class DecodedMux48{49public:50union {51struct {52uint8 aRGB0;53uint8 bRGB0;54uint8 cRGB0;55uint8 dRGB0;5657uint8 aA0;58uint8 bA0;59uint8 cA0;60uint8 dA0;6162uint8 aRGB1;63uint8 bRGB1;64uint8 cRGB1;65uint8 dRGB1;6667uint8 aA1;68uint8 bA1;69uint8 cA1;70uint8 dA1;71};72uint8 m_bytes[16];73uint32 m_dWords[4];74N64CombinerType m_n64Combiners[4];75};7677union {78struct {79uint32 m_dwMux0;80uint32 m_dwMux1;81};82uint64 m_u64Mux;83};8485CombinerFormatType splitType[4];86CombinerFormatType mType;8788uint32 m_dwShadeColorChannelFlag;89uint32 m_dwShadeAlphaChannelFlag;90uint32 m_ColorTextureFlag[2]; // I may use a texture to represent a constant color91// when there are more constant colors are used than92// the system can support9394bool m_bShadeIsUsed[2]; // 0 for color channel, 1 for alpha channel95bool m_bTexel0IsUsed;96bool m_bTexel1IsUsed;9798int m_maxConstants; // OpenGL 1.1 does not really support a constant color in combiner99// must use shade for constants;100int m_maxTextures; // 1 or 2101102103void Decode(uint32 dwMux0, uint32 dwMux1);104virtual void Hack(void);105bool isUsed(uint8 fac, uint8 mask=MUX_MASK);106bool isUsedInAlphaChannel(uint8 fac, uint8 mask=MUX_MASK);107bool isUsedInColorChannel(uint8 fac, uint8 mask=MUX_MASK);108bool isUsedInCycle(uint8 fac, int cycle, CombineChannel channel, uint8 mask=MUX_MASK);109bool isUsedInCycle(uint8 fac, int cycle, uint8 mask=MUX_MASK);110uint32 GetCycle(int cycle, CombineChannel channel);111uint32 GetCycle(int cycle);112CombinerFormatType GetCombinerFormatType(uint32 cycle);113void Display(bool simplified=true, FILE *fp=NULL);114static char* FormatStr(uint8 val, char *buf);115void CheckCombineInCycle1(void);116virtual void Simplify(void);117virtual void Reformat(bool do_complement = true);118virtual void To_AB_Add_CD_Format(void); // Use by TNT,Geforce119virtual void To_AB_Add_C_Format(void); // Use by ATI Radeon120121virtual void MergeShadeWithConstants(void);122virtual void MergeShadeWithConstantsInChannel(CombineChannel channel);123virtual void MergeConstants(void);124virtual void UseShadeForConstant(void);125virtual void UseTextureForConstant(void);126127void ConvertComplements();128int HowManyConstFactors();129int HowManyTextures();130void MergeConstFactors();131virtual void SplitComplexStages(); // Only used if the combiner supports more than 1 stages132void ConvertLODFracTo0();133void ReplaceVal(uint8 val1, uint8 val2, int cycle= -1, uint8 mask = MUX_MASK);134void Replace1Val(uint8 &val1, const uint8 val2, uint8 mask = MUX_MASK)135{136val1 &= (~mask);137val1 |= val2;138}139int CountTexels(void);140int Count(uint8 val, int cycle= -1, uint8 mask = MUX_MASK);141142#ifdef DEBUGGER143void DisplayMuxString(const char *prompt);144void DisplaySimpliedMuxString(const char *prompt);145void DisplayConstantsWithShade(uint32 flag,CombineChannel channel);146#else147void DisplayMuxString(const char *prompt) {}148void DisplaySimpliedMuxString(const char *prompt){}149void DisplayConstantsWithShade(uint32 flag,CombineChannel channel){}150void LogMuxString(const char *prompt, FILE *fp);151void LogSimpliedMuxString(const char *prompt, FILE *fp);152void LogConstantsWithShade(uint32 flag,CombineChannel channel, FILE *fp);153#endif154155virtual DecodedMux& operator=(const DecodedMux& mux)156{157m_dWords[0] = mux.m_dWords[0];158m_dWords[1] = mux.m_dWords[1];159m_dWords[2] = mux.m_dWords[2];160m_dWords[3] = mux.m_dWords[3];161m_u64Mux = mux.m_u64Mux;162splitType[0] = mux.splitType[0];163splitType[1] = mux.splitType[1];164splitType[2] = mux.splitType[2];165splitType[3] = mux.splitType[3];166mType = mux.mType;167168m_dwShadeColorChannelFlag = mux.m_dwShadeColorChannelFlag;169m_dwShadeAlphaChannelFlag = mux.m_dwShadeAlphaChannelFlag;170171m_bShadeIsUsed[0] = mux.m_bShadeIsUsed[0];172m_bShadeIsUsed[1] = mux.m_bShadeIsUsed[1];173m_bTexel0IsUsed = mux.m_bTexel0IsUsed;174m_bTexel1IsUsed = mux.m_bTexel1IsUsed;175176m_maxConstants = mux.m_maxConstants;177m_maxTextures = mux.m_maxTextures;178m_ColorTextureFlag[0] = mux.m_ColorTextureFlag[0];179m_ColorTextureFlag[1] = mux.m_ColorTextureFlag[1];180181return *this;182}183184static inline bool IsConstFactor(uint8 val)185{186uint8 v = val&MUX_MASK;187return( v == MUX_0 || v == MUX_1 || v == MUX_PRIM || v == MUX_ENV || v == MUX_LODFRAC || v == MUX_PRIMLODFRAC );188}189190DecodedMux()191{192memset(m_bytes, 0, sizeof(m_bytes));193mType=CM_FMT_TYPE_NOT_CHECKED;194for( int i=0; i<4; i++ )195{196splitType[i] = CM_FMT_TYPE_NOT_CHECKED;197}198m_maxConstants = 1;199m_maxTextures = 2;200}201202virtual ~DecodedMux() {}203};204205class DecodedMuxForPixelShader : public DecodedMux206{207public:208virtual void Simplify(void);209void SplitComplexStages() {};210};211212class DecodedMuxForSemiPixelShader : public DecodedMux213{214public:215void Reset(void);216};217218class DecodedMuxForOGL14V2 : public DecodedMuxForPixelShader219{220public:221virtual void Simplify(void);222void UseTextureForConstant(void);223};224225typedef struct226{227bool bFurtherFormatForOGL2;228bool bUseShadeForConstants;229bool bUseTextureForConstants;230bool bUseMoreThan2TextureForConstants;231bool bReformatToAB_CD;232bool bAllowHack;233bool bAllowComplimentary;234bool bCheckCombineInCycle1;235bool bSetLODFracTo0;236bool bMergeShadeWithConstants;237bool bSplitComplexStage;238bool bReformatAgainWithTwoTexels;239} MuxConverterOptions;240241#endif242243244245246