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
24
#include "ExtendedRender.h"
33
class CRender : public CExtendedRender
38
TextureUVFlag TileUFlags[8];
39
TextureUVFlag TileVFlags[8];
43
float m_fScreenViewportMultX;
44
float m_fScreenViewportMultY;
47
uint32 m_dwTexturePerspective;
48
BOOL m_bAlphaTestEnable;
54
TextureFilter m_dwMinFilter;
55
TextureFilter m_dwMagFilter;
60
BOOL m_bBlendModeValid;
62
CColorCombiner *m_pColorCombiner;
63
CBlender *m_pAlphaBlender;
68
inline bool IsTexel0Enable() {return m_pColorCombiner->m_bTex0Enabled;}
69
inline bool IsTexel1Enable() {return m_pColorCombiner->m_bTex1Enabled;}
70
inline bool IsTextureEnabled() { return (m_pColorCombiner->m_bTex0Enabled||m_pColorCombiner->m_bTex1Enabled); }
72
inline RenderTexture& GetCurrentTexture() { return g_textures[gRSP.curTile]; }
73
inline RenderTexture& GetTexture(uint32 dwTile) { return g_textures[dwTile]; }
74
void SetViewport(int nLeft, int nTop, int nRight, int nBottom, int maxZ);
75
virtual void SetViewportRender() {}
76
virtual void SetClipRatio(uint32 type, uint32 value);
77
virtual void UpdateScissor() {}
78
virtual void ApplyRDPScissor(bool force=false) {}
79
virtual void UpdateClipRectangle();
80
virtual void UpdateScissorWithClipRatio();
81
virtual void ApplyScissorWithClipRatio(bool force=false) {}
82
virtual void CaptureScreen(char *folder) {}
84
void SetTextureEnableAndScale(int dwTile, bool enable, float fScaleX, float fScaleY);
86
virtual void SetFogEnable(bool bEnable)
88
DEBUGGER_IF_DUMP( (gRSP.bFogEnabled != bEnable && logFog ), TRACE1("Set Fog %s", bEnable? "enable":"disable"));
89
gRSP.bFogEnabled = bEnable&&options.bEnableFog;
91
virtual void SetFogMinMax(float fMin, float fMax) = 0;
92
virtual void TurnFogOnOff(bool flag)=0;
94
void SetFogFlagForNegativeW();
95
void RestoreFogFlag();
97
virtual void SetFogColor(uint32 r, uint32 g, uint32 b, uint32 a)
99
gRDP.fogColor = COLOR_RGBA(r, g, b, a);
101
uint32 GetFogColor() { return gRDP.fogColor; }
103
void SetProjection(const Matrix & mat, bool bPush, bool bReplace);
104
void SetWorldView(const Matrix & mat, bool bPush, bool bReplace);
105
inline int GetProjectMatrixLevel(void) { return gRSP.projectionMtxTop; }
106
inline int GetWorldViewMatrixLevel(void) { return gRSP.modelViewMtxTop; }
108
inline void PopProjection()
110
if (gRSP.projectionMtxTop > 0)
111
gRSP.projectionMtxTop--;
113
TRACE0("Popping past projection stack limits");
117
Matrix & GetWorldProjectMatrix(void);
118
void SetWorldProjectMatrix(Matrix &mtx);
120
void ResetMatrices();
122
inline RenderShadeMode GetShadeMode() { return gRSP.shadeMode; }
124
void SetVtxTextureCoord(uint32 dwV, float tu, float tv)
126
g_fVtxTxtCoords[dwV].x = tu;
127
g_fVtxTxtCoords[dwV].y = tv;
130
virtual void RenderReset();
131
virtual void SetCombinerAndBlender();
132
virtual void SetMux(uint32 dwMux0, uint32 dwMux1);
133
virtual void SetCullMode(bool bCullFront, bool bCullBack) { gRSP.bCullFront = bCullFront; gRSP.bCullBack = bCullBack; }
135
virtual void BeginRendering(void) {CRender::gRenderReferenceCount++;} // For DirectX only
136
virtual void EndRendering(void)
138
if( CRender::gRenderReferenceCount > 0 )
139
CRender::gRenderReferenceCount--;
142
virtual void ClearBuffer(bool cbuffer, bool zbuffer)=0;
143
virtual void ClearZBuffer(float depth)=0;
144
virtual void ClearBuffer(bool cbuffer, bool zbuffer, COORDRECT &rect)
146
ClearBuffer(cbuffer, zbuffer);
148
virtual void ZBufferEnable(BOOL bZBuffer)=0;
149
virtual void SetZCompare(BOOL bZCompare)=0;
150
virtual void SetZUpdate(BOOL bZUpdate)=0;
151
virtual void SetZBias(int bias)=0;
152
virtual void SetAlphaTestEnable(BOOL bAlphaTestEnable)=0;
154
void SetTextureFilter(uint32 dwFilter);
155
virtual void ApplyTextureFilter() {}
157
virtual void SetShadeMode(RenderShadeMode mode)=0;
159
virtual void SetAlphaRef(uint32 dwAlpha)=0;
160
virtual void ForceAlphaRef(uint32 dwAlpha)=0;
162
virtual void InitOtherModes(void);
164
void SetVertexTextureUVCoord(TLITVERTEX &v, float fTex0S, float fTex0T, float fTex1S, float fTex1T);
165
void SetVertexTextureUVCoord(TLITVERTEX &v, float fTex0S, float fTex0T);
166
virtual COLOR PostProcessDiffuseColor(COLOR curDiffuseColor)=0;
167
virtual COLOR PostProcessSpecularColor()=0;
169
bool DrawTriangles();
170
virtual bool RenderFlushTris()=0;
172
bool TexRect(LONG nX0, LONG nY0, LONG nX1, LONG nY1, float fS0, float fT0, float fScaleS, float fScaleT, bool colorFlag=false, uint32 difcolor=0xFFFFFFFF);
173
bool TexRectFlip(LONG nX0, LONG nY0, LONG nX1, LONG nY1, float fS0, float fT0, float fS1, float fT1);
174
bool FillRect(LONG nX0, LONG nY0, LONG nX1, LONG nY1, uint32 dwColor);
175
bool Line3D(uint32 dwV0, uint32 dwV1, uint32 dwWidth);
177
virtual void SetAddressUAllStages(uint32 dwTile, TextureUVFlag dwFlag); // For DirectX only, fix me
178
virtual void SetAddressVAllStages(uint32 dwTile, TextureUVFlag dwFlag); // For DirectX only, fix me
179
virtual void SetTextureUFlag(TextureUVFlag dwFlag, uint32 tile)=0;
180
virtual void SetTextureVFlag(TextureUVFlag dwFlag, uint32 tile)=0;
181
virtual void SetTexelRepeatFlags(uint32 dwTile);
182
virtual void SetAllTexelRepeatFlag();
184
virtual bool SetCurrentTexture(int tile, TxtrCacheEntry *pTextureEntry)=0;
185
virtual bool SetCurrentTexture(int tile, CTexture *handler, uint32 dwTileWidth, uint32 dwTileHeight, TxtrCacheEntry *pTextureEntry) = 0;
187
virtual bool InitDeviceObjects()=0;
188
virtual bool ClearDeviceObjects()=0;
189
virtual void Initialize(void);
190
virtual void CleanUp(void);
192
virtual void SetFillMode(FillMode mode)=0;
195
virtual bool DrawTexture(int tex, TextureChannel channel = TXT_RGB );
196
virtual void SaveTextureToFile(int tex, TextureChannel channel = TXT_RGB, bool bShow = false);
199
virtual void SaveTextureToFile(CTexture &texture, char *filename, TextureChannel channel = TXT_RGB, bool bShow = false, bool bWholeTexture = true, int width = -1, int height = -1);
201
void LoadSprite2D(Sprite2DInfo &info, uint32 ucode);
202
void LoadObjBGCopy(uObjBg &info);
203
void LoadObjBG1CYC(uObjScaleBg &info);
204
void LoadObjSprite(uObjTxSprite &info, bool useTIAddr=false);
206
void LoadFrameBuffer(bool useVIreg=false, uint32 left=0, uint32 top=0, uint32 width=0, uint32 height=0);
207
void LoadTextureFromMemory(void *buf, uint32 left, uint32 top, uint32 width, uint32 height, uint32 pitch, uint32 format);
208
void LoadTxtrBufIntoTexture(void);
209
void DrawSprite2D(Sprite2DInfo &info, uint32 ucode);
210
void DrawSpriteR(uObjTxSprite &sprite, bool initCombiner=true, uint32 tile=0, uint32 left=0, uint32 top=0, uint32 width=0, uint32 height=0);
211
void DrawSprite(uObjTxSprite &sprite, bool rectR = true);
212
void DrawObjBGCopy(uObjBg &info);
213
virtual void DrawSpriteR_Render(){};
214
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;
215
void DrawFrameBuffer(bool useVIreg=false, uint32 left=0, uint32 top=0, uint32 width=0, uint32 height=0);
216
void DrawObjBG1CYC(uObjScaleBg &bg, bool scaled=true);
218
static CRender * g_pRender;
219
static int gRenderReferenceCount;
220
static CRender * GetRender(void);
221
static bool IsAvailable();
225
BOOL m_savedZBufferFlag;
226
uint32 m_savedMinFilter;
227
uint32 m_savedMagFilter;
230
virtual bool RenderFillRect(uint32 dwColor, float depth)=0;
231
VECTOR2 m_fillRectVtx[2];
234
virtual bool RenderLine3D()=0;
236
LITVERTEX m_line3DVtx[2];
237
VECTOR2 m_line3DVector[4];
240
virtual bool RenderTexRect()=0;
242
TexCord m_texRectTex1UV[2];
243
TexCord m_texRectTex2UV[2];
245
// DrawSimple2DTexture
246
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);
249
virtual void StartDrawSimpleRect(LONG nX0, LONG nY0, LONG nX1, LONG nY1, uint32 dwColor, float depth, float rhw);
250
VECTOR2 m_simpleRectVtx[2];
252
bool RemapTextureCoordinate(float s0, float s1, uint32 tileWidth, uint32 mask, float textureWidth,
253
float &u0, float &u1);
257
#define ffloor(a) (((int(a))<=(a))?(float)(int(a)):((float)(int(a))-1))
259
bool SaveRGBBufferToFile(char *filename, unsigned char *buf, int width, int height, int pitch = -1);
260
bool SaveRGBABufferToPNGFile(char *filename, unsigned char *buf, int width, int height, int pitch = -1);
262
#endif //_RICE_RENDER_H