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.
20 #ifndef _RICE_RENDER_H
21 #define _RICE_RENDER_H
27 #include "RenderBase.h"
28 #include "ExtendedRender.h"
29 #include "RSP_Parser.h"
30 #include "RSP_S2DEX.h"
39 class CRender : public CExtendedRender
44 TextureUVFlag TileUFlags[8];
45 TextureUVFlag TileVFlags[8];
49 float m_fScreenViewportMultX;
50 float m_fScreenViewportMultY;
53 uint32 m_dwTexturePerspective;
54 BOOL m_bAlphaTestEnable;
60 TextureFilter m_dwMinFilter;
61 TextureFilter m_dwMagFilter;
66 BOOL m_bBlendModeValid;
68 CColorCombiner *m_pColorCombiner;
69 CBlender *m_pAlphaBlender;
74 inline bool IsTexel0Enable() {return m_pColorCombiner->m_bTex0Enabled;}
75 inline bool IsTexel1Enable() {return m_pColorCombiner->m_bTex1Enabled;}
76 inline bool IsTextureEnabled() { return (m_pColorCombiner->m_bTex0Enabled||m_pColorCombiner->m_bTex1Enabled); }
78 inline RenderTexture& GetCurrentTexture() { return g_textures[gRSP.curTile]; }
79 inline RenderTexture& GetTexture(uint32 dwTile) { return g_textures[dwTile]; }
80 void SetViewport(int nLeft, int nTop, int nRight, int nBottom, int maxZ);
81 virtual void SetViewportRender() {}
82 virtual void SetClipRatio(uint32 type, uint32 value);
83 virtual void UpdateScissor() {}
84 virtual void ApplyRDPScissor(bool force=false) {}
85 virtual void UpdateClipRectangle();
86 virtual void UpdateScissorWithClipRatio();
87 virtual void ApplyScissorWithClipRatio(bool force=false) {}
89 void SetTextureEnableAndScale(int dwTile, bool enable, float fScaleX, float fScaleY);
91 virtual void SetFogEnable(bool bEnable)
93 DEBUGGER_IF_DUMP( (gRSP.bFogEnabled != bEnable && logFog ), TRACE1("Set Fog %s", bEnable? "enable":"disable"));
94 gRSP.bFogEnabled = bEnable&&(options.fogMethod > 0);
96 virtual void SetFogMinMax(float fMin, float fMax) = 0;
97 virtual void TurnFogOnOff(bool flag)=0;
99 void SetFogFlagForNegativeW();
100 void RestoreFogFlag();
102 virtual void SetFogColor(uint32 r, uint32 g, uint32 b, uint32 a)
104 gRDP.fogColor = COLOR_RGBA(r, g, b, a);
106 uint32 GetFogColor() { return gRDP.fogColor; }
108 void SetProjection(const Matrix & mat, bool bPush, bool bReplace);
109 void SetWorldView(const Matrix & mat, bool bPush, bool bReplace);
110 inline int GetProjectMatrixLevel(void) { return gRSP.projectionMtxTop; }
111 inline int GetWorldViewMatrixLevel(void) { return gRSP.modelViewMtxTop; }
113 inline void PopProjection()
115 if (gRSP.projectionMtxTop > 0)
116 gRSP.projectionMtxTop--;
118 TRACE0("Popping past projection stack limits");
122 Matrix & GetWorldProjectMatrix(void);
123 void SetWorldProjectMatrix(Matrix &mtx);
125 void ResetMatrices();
127 inline RenderShadeMode GetShadeMode() { return gRSP.shadeMode; }
129 void SetVtxTextureCoord(uint32 dwV, float tu, float tv)
131 g_fVtxTxtCoords[dwV].x = tu;
132 g_fVtxTxtCoords[dwV].y = tv;
135 virtual void RenderReset();
136 virtual void SetCombinerAndBlender();
137 virtual void SetMux(uint32 dwMux0, uint32 dwMux1);
138 virtual void SetCullMode(bool bCullFront, bool bCullBack) { gRSP.bCullFront = bCullFront; gRSP.bCullBack = bCullBack; }
140 virtual void BeginRendering(void) {CRender::gRenderReferenceCount++;} // For DirectX only
141 virtual void EndRendering(void)
143 if( CRender::gRenderReferenceCount > 0 )
144 CRender::gRenderReferenceCount--;
147 virtual void ClearBuffer(bool cbuffer, bool zbuffer)=0;
148 virtual void ClearZBuffer(float depth)=0;
149 virtual void ClearBuffer(bool cbuffer, bool zbuffer, COORDRECT &rect)
151 ClearBuffer(cbuffer, zbuffer);
153 virtual void ZBufferEnable(BOOL bZBuffer)=0;
154 virtual void SetZCompare(BOOL bZCompare)=0;
155 virtual void SetZUpdate(BOOL bZUpdate)=0;
156 virtual void SetZBias(int bias)=0;
157 virtual void SetAlphaTestEnable(BOOL bAlphaTestEnable)=0;
159 void SetTextureFilter(uint32 dwFilter);
160 virtual void ApplyTextureFilter() {}
162 virtual void SetShadeMode(RenderShadeMode mode)=0;
164 virtual void SetAlphaRef(uint32 dwAlpha)=0;
165 virtual void ForceAlphaRef(uint32 dwAlpha)=0;
167 virtual void InitOtherModes(void);
169 void SetVertexTextureUVCoord(TLITVERTEX &v, float fTex0S, float fTex0T, float fTex1S, float fTex1T);
170 void SetVertexTextureUVCoord(TLITVERTEX &v, float fTex0S, float fTex0T);
171 virtual COLOR PostProcessDiffuseColor(COLOR curDiffuseColor)=0;
172 virtual COLOR PostProcessSpecularColor()=0;
174 bool DrawTriangles();
175 virtual bool RenderFlushTris()=0;
177 bool TexRect(int nX0, int nY0, int nX1, int nY1, float fS0, float fT0, float fScaleS, float fScaleT, bool colorFlag=false, uint32 difcolor=0xFFFFFFFF);
178 bool TexRectFlip(int nX0, int nY0, int nX1, int nY1, float fS0, float fT0, float fS1, float fT1);
179 bool FillRect(int nX0, int nY0, int nX1, int nY1, uint32 dwColor);
180 bool Line3D(uint32 dwV0, uint32 dwV1, uint32 dwWidth);
182 virtual void SetAddressUAllStages(uint32 dwTile, TextureUVFlag dwFlag); // For DirectX only, fix me
183 virtual void SetAddressVAllStages(uint32 dwTile, TextureUVFlag dwFlag); // For DirectX only, fix me
184 virtual void SetTextureUFlag(TextureUVFlag dwFlag, uint32 tile)=0;
185 virtual void SetTextureVFlag(TextureUVFlag dwFlag, uint32 tile)=0;
186 virtual void SetTexelRepeatFlags(uint32 dwTile);
187 virtual void SetAllTexelRepeatFlag();
189 virtual bool SetCurrentTexture(int tile, TxtrCacheEntry *pTextureEntry)=0;
190 virtual bool SetCurrentTexture(int tile, CTexture *handler, uint32 dwTileWidth, uint32 dwTileHeight, TxtrCacheEntry *pTextureEntry) = 0;
192 virtual bool InitDeviceObjects()=0;
193 virtual bool ClearDeviceObjects()=0;
194 virtual void Initialize(void);
195 virtual void CleanUp(void);
197 virtual void SetFillMode(FillMode mode)=0;
200 virtual bool DrawTexture(int tex, TextureChannel channel = TXT_RGB );
201 virtual void SaveTextureToFile(int tex, TextureChannel channel = TXT_RGB, bool bShow = false);
204 virtual void SaveTextureToFile(CTexture &texture, char *filename, TextureChannel channel = TXT_RGB, bool bShow = false, bool bWholeTexture = true, int width = -1, int height = -1);
206 void LoadSprite2D(Sprite2DInfo &info, uint32 ucode);
207 void LoadObjBGCopy(uObjBg &info);
208 void LoadObjBG1CYC(uObjScaleBg &info);
209 void LoadObjSprite(uObjTxSprite &info, bool useTIAddr=false);
211 void LoadFrameBuffer(bool useVIreg=false, uint32 left=0, uint32 top=0, uint32 width=0, uint32 height=0);
212 void LoadTextureFromMemory(void *buf, uint32 left, uint32 top, uint32 width, uint32 height, uint32 pitch, uint32 format);
213 void LoadTxtrBufIntoTexture(void);
214 void DrawSprite2D(Sprite2DInfo &info, uint32 ucode);
215 void DrawSpriteR(uObjTxSprite &sprite, bool initCombiner=true, uint32 tile=0, uint32 left=0, uint32 top=0, uint32 width=0, uint32 height=0);
216 void DrawSprite(uObjTxSprite &sprite, bool rectR = true);
217 void DrawObjBGCopy(uObjBg &info);
218 virtual void DrawSpriteR_Render(){};
219 virtual void DrawSimple2DTexture(float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1, COLOR dif, COLOR spe, float z, float rhw)=0;
220 void DrawFrameBuffer(bool useVIreg=false, uint32 left=0, uint32 top=0, uint32 width=0, uint32 height=0);
221 void DrawObjBG1CYC(uObjScaleBg &bg, bool scaled=true);
223 static CRender * g_pRender;
224 static int gRenderReferenceCount;
225 static CRender * GetRender(void);
226 static bool IsAvailable();
230 BOOL m_savedZBufferFlag;
231 uint32 m_savedMinFilter;
232 uint32 m_savedMagFilter;
235 virtual bool RenderFillRect(uint32 dwColor, float depth)=0;
236 VECTOR2 m_fillRectVtx[2];
239 virtual bool RenderLine3D()=0;
241 LITVERTEX m_line3DVtx[2];
242 VECTOR2 m_line3DVector[4];
245 virtual bool RenderTexRect()=0;
247 TexCord m_texRectTex1UV[2];
248 TexCord m_texRectTex2UV[2];
250 // DrawSimple2DTexture
251 virtual void StartDrawSimple2DTexture(float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1, COLOR dif, COLOR spe, float z, float rhw);
254 virtual void StartDrawSimpleRect(int nX0, int nY0, int nX1, int nY1, uint32 dwColor, float depth, float rhw);
255 VECTOR2 m_simpleRectVtx[2];
257 bool RemapTextureCoordinate(float s0, float s1, uint32 tileWidth, uint32 mask, float textureWidth,
258 float &u0, float &u1);
262 #define ffloor(a) (((int(a))<=(a))?(float)(int(a)):((float)(int(a))-1))
264 bool SaveRGBBufferToFile(char *filename, unsigned char *buf, int width, int height, int pitch = -1);
265 bool SaveRGBABufferToPNGFile(char *filename, unsigned char *buf, int width, int height, int pitch = -1);
267 #endif //_RICE_RENDER_H