Rice GLES2 (from mupen64plus-ae) plugin. Compile but doesn't works well on the OpenPa...
[mupen64plus-pandora.git] / source / gles2rice / src / FrameBuffer.h
1 /*
2 Copyright (C) 2002 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 _FRAME_BUFFER_H_
21 #define _FRAME_BUFFER_H_
22
23 #include "typedefs.h"
24 #include "RenderTexture.h"
25 #include "TextureManager.h"
26
27 typedef int SURFFORMAT;
28
29 extern void TexRectToN64FrameBuffer_16b(uint32 x0, uint32 y0, uint32 width, uint32 height, uint32 dwTile);
30 extern void TexRectToFrameBuffer_8b(uint32 dwXL, uint32 dwYL, uint32 dwXH, uint32 dwYH, float t0u0, float t0v0, float t0u1, float t0v1, uint32 dwTile);
31
32 class FrameBufferManager
33 {
34     friend class CGraphicsContext;
35     friend class CDXGraphicsContext;
36 public:
37     FrameBufferManager();
38     virtual ~FrameBufferManager();
39
40     void Initialize();
41     void CloseUp();
42     void Set_CI_addr(SetImgInfo &newCI);
43     void UpdateRecentCIAddr(SetImgInfo &ciinfo);
44     void SetAddrBeDisplayed(uint32 addr);
45     bool HasAddrBeenDisplayed(uint32 addr, uint32 width);
46     int FindRecentCIInfoIndex(uint32 addr);
47     bool IsDIaRenderTexture();
48
49     int         CheckAddrInRenderTextures(uint32 addr, bool checkcrc = true);
50     uint32      ComputeRenderTextureCRCInRDRAM(int infoIdx);
51     void        CheckRenderTextureCRCInRDRAM(void);
52     int         CheckRenderTexturesWithNewCI(SetImgInfo &CIinfo, uint32 height, bool byNewTxtrBuf);
53     virtual void ClearN64FrameBufferToBlack(uint32 left=0, uint32 top=0, uint32 width=0, uint32 height=0);
54     virtual int SetBackBufferAsRenderTexture(SetImgInfo &CIinfo, int ciInfoIdx);
55     void        LoadTextureFromRenderTexture(TxtrCacheEntry* pEntry, int infoIdx);
56     void        UpdateFrameBufferBeforeUpdateFrame();
57     virtual void RestoreNormalBackBuffer();                 // restore the normal back buffer
58     virtual void CopyBackToFrameBufferIfReadByCPU(uint32 addr);
59     virtual void SetRenderTexture(void);
60     virtual void CloseRenderTexture(bool toSave);
61     virtual void ActiveTextureBuffer(void);
62
63     int IsAddrInRecentFrameBuffers(uint32 addr);
64     int CheckAddrInBackBuffers(uint32 addr, uint32 memsize, bool copyToRDRAM = false);
65
66     uint8 CIFindIndex(uint16 val);
67     uint32 ComputeCImgHeight(SetImgInfo &info, uint32 &height);
68
69     int FindASlot(void);
70
71     bool ProcessFrameWriteRecord();
72     void FrameBufferWriteByCPU(uint32 addr, uint32 size);
73     void FrameBufferReadByCPU( uint32 addr );
74     bool FrameBufferInRDRAMCheckCRC();
75     void StoreRenderTextureToRDRAM(int infoIdx = -1);
76
77     virtual bool IsRenderingToTexture() {return m_isRenderingToTexture;}
78
79     // Device dependent functions
80     virtual void SaveBackBuffer(int ciInfoIdx, RECT* pRect=NULL, bool forceToSaveToRDRAM = false);    // Copy the current back buffer to temp buffer
81     virtual void CopyBackBufferToRenderTexture(int idx, RecentCIInfo &ciInfo, RECT* pRect=NULL) {}    // Copy the current back buffer to temp buffer
82     virtual void CopyBufferToRDRAM(uint32 addr, uint32 fmt, uint32 siz, uint32 width, 
83         uint32 height, uint32 bufWidth, uint32 bufHeight, uint32 startaddr, 
84         uint32 memsize, uint32 pitch, TextureFmt bufFmt, void *surf, uint32 bufPitch);
85     virtual void StoreBackBufferToRDRAM(uint32 addr, uint32 fmt, uint32 siz, uint32 width, 
86         uint32 height, uint32 bufWidth, uint32 bufHeight, uint32 startaddr=0xFFFFFFFF, 
87         uint32 memsize=0xFFFFFFFF, uint32 pitch=0, SURFFORMAT surf_fmt=SURFFMT_A8R8G8B8) {}
88 #ifdef DEBUGGER
89     virtual void DisplayRenderTexture(int infoIdx = -1);
90 #endif
91
92 protected:
93     bool    m_isRenderingToTexture;
94     int     m_curRenderTextureIndex;
95     int     m_lastTextureBufferIndex;
96 };
97
98 class DXFrameBufferManager : public FrameBufferManager
99 {
100     virtual ~DXFrameBufferManager() {}
101
102 public:
103     // Device dependent functions
104     virtual void CopyBackBufferToRenderTexture(int idx, RecentCIInfo &ciInfo, RECT* pRect=NULL);    // Copy the current back buffer to temp buffer
105     virtual void StoreBackBufferToRDRAM(uint32 addr, uint32 fmt, uint32 siz, uint32 width, 
106         uint32 height, uint32 bufWidth, uint32 bufHeight, uint32 startaddr=0xFFFFFFFF, 
107         uint32 memsize=0xFFFFFFFF, uint32 pitch=0, SURFFORMAT surf_fmt=SURFFMT_A8R8G8B8);
108 };
109
110 class OGLFrameBufferManager : public FrameBufferManager
111 {
112     virtual ~OGLFrameBufferManager() {}
113
114 public:
115     // Device dependent functions
116     virtual void CopyBackBufferToRenderTexture(int idx, RecentCIInfo &ciInfo, RECT* pRect=NULL);    // Copy the current back buffer to temp buffer
117     virtual void StoreBackBufferToRDRAM(uint32 addr, uint32 fmt, uint32 siz, uint32 width, 
118         uint32 height, uint32 bufWidth, uint32 bufHeight, uint32 startaddr=0xFFFFFFFF, 
119         uint32 memsize=0xFFFFFFFF, uint32 pitch=0, SURFFORMAT surf_fmt=SURFFMT_A8R8G8B8);
120 };
121
122 extern RenderTextureInfo gRenderTextureInfos[];
123 extern RenderTextureInfo newRenderTextureInfo;
124
125 #define NEW_TEXTURE_BUFFER
126
127 extern RenderTextureInfo g_ZI_saves[2];
128 extern RenderTextureInfo *g_pRenderTextureInfo;
129
130
131 extern FrameBufferManager* g_pFrameBufferManager;
132
133 extern RecentCIInfo g_RecentCIInfo[];
134 extern RecentViOriginInfo g_RecentVIOriginInfo[];
135 extern RenderTextureInfo gRenderTextureInfos[];
136 extern int numOfTxtBufInfos;
137 extern RecentCIInfo *g_uRecentCIInfoPtrs[5];
138 extern uint8 RevTlutTable[0x10000];
139
140 extern uint32 CalculateRDRAMCRC(void *pAddr, uint32 left, uint32 top, uint32 width, uint32 height, uint32 size, uint32 pitchInBytes );
141 extern uint16 ConvertRGBATo555(uint8 r, uint8 g, uint8 b, uint8 a);
142 extern uint16 ConvertRGBATo555(uint32 color32);
143 extern void InitTlutReverseLookup(void);
144
145 #endif
146