~ubuntu-branches/ubuntu/precise/mupen64plus/precise

« back to all changes in this revision

Viewing changes to rice_video/Render.h

  • Committer: Bazaar Package Importer
  • Author(s): Sven Eckelmann
  • Date: 2009-09-08 22:17:00 UTC
  • Revision ID: james.westby@ubuntu.com-20090908221700-yela0ckgc1xwiqtn
Tags: upstream-1.5+dfsg1
ImportĀ upstreamĀ versionĀ 1.5+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 2003 Rice1964
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
17
 
 
18
*/
 
19
 
 
20
#ifndef _RICE_RENDER_H
 
21
#define _RICE_RENDER_H
 
22
 
 
23
#include "stdafx.h"
 
24
#include "ExtendedRender.h"
 
25
 
 
26
enum TextureChannel 
 
27
{
 
28
    TXT_RGB,
 
29
    TXT_ALPHA,
 
30
    TXT_RGBA,
 
31
};
 
32
 
 
33
class CRender : public CExtendedRender
 
34
{
 
35
protected:
 
36
    CRender();
 
37
 
 
38
    TextureUVFlag TileUFlags[8];
 
39
    TextureUVFlag TileVFlags[8];
 
40
 
 
41
public:
 
42
 
 
43
    float m_fScreenViewportMultX;
 
44
    float m_fScreenViewportMultY;
 
45
 
 
46
 
 
47
    uint32  m_dwTexturePerspective;
 
48
    BOOL    m_bAlphaTestEnable;
 
49
 
 
50
    BOOL    m_bZUpdate;
 
51
    BOOL    m_bZCompare;
 
52
    uint32  m_dwZBias;
 
53
 
 
54
    TextureFilter   m_dwMinFilter;
 
55
    TextureFilter   m_dwMagFilter;
 
56
 
 
57
    uint32  m_dwAlpha;
 
58
 
 
59
    uint64      m_Mux;
 
60
    BOOL    m_bBlendModeValid;
 
61
 
 
62
    CColorCombiner *m_pColorCombiner;
 
63
    CBlender *m_pAlphaBlender;
 
64
    
 
65
    
 
66
    virtual ~CRender();
 
67
    
 
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); }
 
71
 
 
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) {}
 
83
 
 
84
    void SetTextureEnableAndScale(int dwTile, bool enable, float fScaleX, float fScaleY);
 
85
    
 
86
    virtual void SetFogEnable(bool bEnable) 
 
87
    { 
 
88
        DEBUGGER_IF_DUMP( (gRSP.bFogEnabled != bEnable && logFog ), TRACE1("Set Fog %s", bEnable? "enable":"disable"));
 
89
        gRSP.bFogEnabled = bEnable&&options.bEnableFog;
 
90
    }
 
91
    virtual void SetFogMinMax(float fMin, float fMax) = 0;
 
92
    virtual void TurnFogOnOff(bool flag)=0;
 
93
    bool m_bFogStateSave;
 
94
    void SetFogFlagForNegativeW();
 
95
    void RestoreFogFlag();
 
96
 
 
97
    virtual void SetFogColor(uint32 r, uint32 g, uint32 b, uint32 a) 
 
98
    { 
 
99
        gRDP.fogColor = COLOR_RGBA(r, g, b, a); 
 
100
    }
 
101
    uint32 GetFogColor() { return gRDP.fogColor; }
 
102
 
 
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; }
 
107
 
 
108
    inline void PopProjection()
 
109
    {
 
110
        if (gRSP.projectionMtxTop > 0)
 
111
            gRSP.projectionMtxTop--;
 
112
        else
 
113
            TRACE0("Popping past projection stack limits");
 
114
    }
 
115
 
 
116
    void PopWorldView();
 
117
    Matrix & GetWorldProjectMatrix(void);
 
118
    void SetWorldProjectMatrix(Matrix &mtx);
 
119
    
 
120
    void ResetMatrices();
 
121
 
 
122
    inline RenderShadeMode GetShadeMode() { return gRSP.shadeMode; }
 
123
 
 
124
    void SetVtxTextureCoord(uint32 dwV, float tu, float tv)
 
125
    {
 
126
        g_fVtxTxtCoords[dwV].x = tu;
 
127
        g_fVtxTxtCoords[dwV].y = tv;
 
128
    }
 
129
 
 
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; }
 
134
 
 
135
    virtual void BeginRendering(void) {CRender::gRenderReferenceCount++;}       // For DirectX only
 
136
    virtual void EndRendering(void) 
 
137
    {
 
138
        if( CRender::gRenderReferenceCount > 0 )
 
139
            CRender::gRenderReferenceCount--;
 
140
    }
 
141
 
 
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) 
 
145
    {
 
146
        ClearBuffer(cbuffer, zbuffer);
 
147
    }
 
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;
 
153
 
 
154
    void SetTextureFilter(uint32 dwFilter);
 
155
    virtual void ApplyTextureFilter() {}
 
156
    
 
157
    virtual void SetShadeMode(RenderShadeMode mode)=0;
 
158
 
 
159
    virtual void SetAlphaRef(uint32 dwAlpha)=0;
 
160
    virtual void ForceAlphaRef(uint32 dwAlpha)=0;
 
161
 
 
162
    virtual void InitOtherModes(void);
 
163
 
 
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;
 
168
    
 
169
    bool DrawTriangles();
 
170
    virtual bool RenderFlushTris()=0;
 
171
 
 
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);
 
176
 
 
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();
 
183
    
 
184
    virtual bool SetCurrentTexture(int tile, TxtrCacheEntry *pTextureEntry)=0;
 
185
    virtual bool SetCurrentTexture(int tile, CTexture *handler, uint32 dwTileWidth, uint32 dwTileHeight, TxtrCacheEntry *pTextureEntry) = 0;
 
186
 
 
187
    virtual bool InitDeviceObjects()=0;
 
188
    virtual bool ClearDeviceObjects()=0;
 
189
    virtual void Initialize(void);
 
190
    virtual void CleanUp(void);
 
191
    
 
192
    virtual void SetFillMode(FillMode mode)=0;
 
193
 
 
194
#ifdef _DEBUG
 
195
    virtual bool DrawTexture(int tex, TextureChannel channel = TXT_RGB );
 
196
    virtual void SaveTextureToFile(int tex, TextureChannel channel = TXT_RGB,  bool bShow = false);
 
197
#endif
 
198
 
 
199
    virtual void SaveTextureToFile(CTexture &texture, char *filename, TextureChannel channel = TXT_RGB,  bool bShow = false, bool bWholeTexture = true, int width = -1, int height = -1);
 
200
 
 
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);
 
205
 
 
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);
 
217
 
 
218
    static CRender * g_pRender;
 
219
    static int gRenderReferenceCount;
 
220
    static CRender * GetRender(void);
 
221
    static bool IsAvailable();
 
222
 
 
223
 
 
224
protected:
 
225
    BOOL            m_savedZBufferFlag;
 
226
    uint32          m_savedMinFilter;
 
227
    uint32          m_savedMagFilter;
 
228
 
 
229
    // FillRect
 
230
    virtual bool    RenderFillRect(uint32 dwColor, float depth)=0;
 
231
    VECTOR2         m_fillRectVtx[2];
 
232
    
 
233
    // Line3D
 
234
    virtual bool    RenderLine3D()=0;
 
235
 
 
236
    LITVERTEX       m_line3DVtx[2];
 
237
    VECTOR2         m_line3DVector[4];
 
238
    
 
239
    // TexRect
 
240
    virtual bool    RenderTexRect()=0;
 
241
 
 
242
    TexCord         m_texRectTex1UV[2];
 
243
    TexCord         m_texRectTex2UV[2];
 
244
 
 
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);
 
247
 
 
248
    // DrawSimpleRect
 
249
    virtual void    StartDrawSimpleRect(LONG nX0, LONG nY0, LONG nX1, LONG nY1, uint32 dwColor, float depth, float rhw);
 
250
    VECTOR2         m_simpleRectVtx[2];
 
251
 
 
252
    bool            RemapTextureCoordinate(float s0, float s1, uint32 tileWidth, uint32 mask, float textureWidth,
 
253
                                            float &u0, float &u1);
 
254
 
 
255
};
 
256
 
 
257
#define ffloor(a) (((int(a))<=(a))?(float)(int(a)):((float)(int(a))-1))
 
258
 
 
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);
 
261
 
 
262
#endif  //_RICE_RENDER_H
 
263