Arachnoid GLESv1.1 plugin. Compile and run (a bit glitchy and no frameskip) on the...
[mupen64plus-pandora.git] / source / mupen64plus-video-arachnoid / src / RDP / RDP.h
CommitLineData
22726e4d 1/******************************************************************************
2 * Arachnoid Graphics Plugin for Mupen64Plus
3 * http://bitbucket.org/wahrhaft/mupen64plus-video-arachnoid/
4 *
5 * Copyright (C) 2007 Kristofer Karlsson, Rickard Niklasson
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *****************************************************************************/
21
22#ifndef REALITY_DRAWING_PROCESSOR_H_
23#define REALITY_DRAWING_PROCESSOR_H_
24
25//Includes
26#define M64P_PLUGIN_PROTOTYPES 1
27#include "m64p_plugin.h"
28#include "UCodeDefs.h"
29#include "GBI.h"
30#include "GBIDefs.h"
31#include "TextureLoader.h"
32
33//Forward declaration
34class RSP;
35class VI;
36class Memory;
37class DisplayListParser;
38class TextureCache;
39class AdvancedCombinerManager;
40class FogManager;
41class TextureLoader;
42class OpenGL2DRenderer;
43
44//*****************************************************************************
45//! RDPSetImgInfo
46//! Used by RDP to set color- and depth- image info
47//*****************************************************************************
48struct RDPSetImgInfo
49{
50 unsigned int format;
51 unsigned int size;
52 unsigned int width;
53 unsigned int rdramAddress;
54 unsigned int bpl;
55};
56
57//*****************************************************************************
58//* OtherMode
59//! Struct used to get input to combiner
60//*****************************************************************************
61union OtherMode
62{
63 struct
64 {
65 //Low 32:
66 unsigned int alphaCompare : 2;
67 unsigned int depthSource : 1;
68
69 //RenderMode
70 unsigned int AAEnable : 1;
71 unsigned int depthCompare : 1;
72 unsigned int depthUpdate : 1;
73 unsigned int imageRead : 1;
74 unsigned int clearOnCvg : 1;
75 unsigned int cvgDest : 2;
76 unsigned int depthMode : 2;
77 unsigned int cvgXAlpha : 1;
78 unsigned int alphaCvgSel : 1;
79 unsigned int forceBlender : 1;
80 unsigned int textureEdge : 1;
81
82 //Blender
83 unsigned int c2_m2b : 2;
84 unsigned int c1_m2b : 2;
85 unsigned int c2_m2a : 2;
86 unsigned int c1_m2a : 2;
87 unsigned int c2_m1b : 2;
88 unsigned int c1_m1b : 2;
89 unsigned int c2_m1a : 2;
90 unsigned int c1_m1a : 2;
91
92 // High 32:
93 unsigned int blendMask : 4;
94 unsigned int alphaDither : 2;
95 unsigned int colorDither : 2;
96 unsigned int combineKey : 1;
97 unsigned int textureConvert : 3;
98 unsigned int textureFilter : 2;
99 unsigned int textureLUT : 2;
100 unsigned int textureLOD : 1;
101 unsigned int textureDetail : 2;
102 unsigned int texturePersp : 1;
103 unsigned int cycleType : 2;
104 unsigned int unusedColorDither : 1; // unsupported
105 unsigned int pipelineMode : 1;
106 unsigned int pad : 8;
107 };
108
109 struct
110 {
111 unsigned int l, h; //!< Low and high values
112 };
113};
114
115//*****************************************************************************
116//* RDP
117//! Class for emulating the Reality Drawing Processor
118//*****************************************************************************
119class RDP
120{
121public:
122
123 //Constructor / Destructor
124 RDP();
125 ~RDP();
126
127 //initialize
128 bool initialize(GFX_INFO* graphicsInfo, RSP* rsp, Memory* memory, GBI* gbi, TextureCache* textureCache, VI* vi, DisplayListParser* displayListParser, FogManager* fogMgr);
129 void updateStates();
130 void dispose();
131 void reset();
132 void triggerInterrupt();
133
134public:
135 void signalUpdate() { m_screenUpdatePending = true; }
136
137 //Get Combiner Manager
138 AdvancedCombinerManager* getCombinerMgr() { return m_combinerMgr; }
139
140 //Set/Get Cycle Type
141 void setCycleType(unsigned int cycleType) { m_otherMode.cycleType = cycleType; m_updateCombiner = true; }
142 unsigned int getCycleType() { return m_otherMode.cycleType; }
143
144 //Set Texture LUT
145 void setTextureLUT(unsigned int lut) { m_textureLUT = lut; }
146 unsigned int getTextureLUT() { return m_textureLUT; }
147
148 //Set/Get Texture Filtering
149 void setTextureFiltering(unsigned int filterMode) { m_otherMode.textureFilter = filterMode; }
150 unsigned int getTextureFiltering() { return m_otherMode.textureFilter; }
151
152 // Set / Get Alpha Compare
153 void setAlphaCompareMode(unsigned int mode);
154 unsigned int getAlphaCompareMode() { return m_otherMode.alphaCompare; }
155
156 // Set Rendermode
157 void setRenderMode(unsigned int w1);
158
159 //Get Textures, Tiles
160 TextureImage* getTextureImage() { return m_textureLoader->getTextureImage(); }
161 RDPTile* getCurrentTile() { return m_textureLoader->getCurrentTile(); }
162 RDPTile* getTile(unsigned int tile) { return m_textureLoader->getTile(tile); }
163
164 //Get texture modes
165 TextureMode getTextureMode() { return m_textureMode; }
166 LoadType getLoadType() { return m_loadType; }
167 bool getChangedTiles() { return m_changedTiles; }
168 bool getChangedTMEM() { return m_tmemChanged; }
169
170 //Texture rectangle Size
171 unsigned int getTexRectWidth() { return m_texRectWidth; }
172 unsigned int getTexRectHeight() { return m_texRectHeight; }
173
174 //Half
175 void setHalf1(unsigned int half1) { m_half1 = half1; }
176 void setHalf2(unsigned int half2) { m_half2 = half2; }
177 unsigned int getHalf1() { return m_half1; }
178 unsigned int getHalf2() { return m_half2; }
179
180 //Get Primitive Depth
181 float getPrimitiveZ() { return m_primitiveZ; }
182
183 //Depth Source (get z value from prim depth?)
184 void setDepthSource(unsigned int source) { m_otherMode.depthSource = source; }
185 unsigned int getDepthSource() { return m_otherMode.depthSource; }
186
187 void setUpdateCombiner(bool update) { m_updateCombiner = update; }
188
189public:
190
191 //Texture Rectangle
192 void _textureRectangle(float ulx, float uly, float lrx, float lry, int tile, float s, float t, float dsdx, float dtdy,bool flip);
193 void _textureRectangleFlip(int nX0, int nY0, int nX1, int nY1, float fS0, float fT0, float fS1, float fT1, int tile);
194
195public:
196
197 //Texturing
198 void RDP_SetCImg(unsigned int format, unsigned int size, unsigned int width, unsigned int segmentAddress);
199 void RDP_SetZImg(unsigned int format, unsigned int size, unsigned int width, unsigned int segmentAddress);
200 void RDP_SetTImg(unsigned int format, unsigned int size, unsigned int width, unsigned int segmentAddress);
201 void RDP_SetTile(int format, int size, int line, int tmem, int tile, int palette,
202 int clampS, int clampT, int mirrorS, int mirrorT, int maskS,
203 int maskT, int shiftS, int shiftT);
204 void RDP_SetTileSize(int tile, unsigned int s0, unsigned int t0, unsigned int s1, unsigned int t1);
205 void RDP_LoadTile(int tile, int s0, int t0, int s1, int t1);
206 void RDP_LoadBlock(int tile, int s0, int t0, int s1, int t1);
207 void RDP_LoadTLUT(int tile, int s0, int t0, int s1, int t1);
208
209 //Colors
210 void RDP_SetEnvColor(float r, float g, float b, float a);
211 void RDP_SetFogColor(float r, float g, float b, float a);
212 void RDP_SetBlendColor(float r, float g, float b, float a);
213 void RDP_SetPrimColor(float r, float g, float b, float a, unsigned int primLodMin, unsigned int primLevel);
214 void RDP_SetFillColor(float r, float g, float b, float a);
215
216 //Combiner
217 void RDP_SetCombine(MicrocodeArgument* ucode);
218
219 //Misc
220 void RDP_SetOtherMode(MicrocodeArgument* ucode);
221 void RDP_SetPrimDepth(unsigned int dwZ, unsigned int dwDZ);
222 void RDP_SetScissor(int x0, int y0, int x1, int y1, int mode);
223
224 //Rendering
225 void RDP_FillRect(unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1);
226 void RDP_TexRectFlip(unsigned int dwXH, unsigned int dwYH, unsigned int dwXL, unsigned int dwYL,
227 unsigned int tileno, unsigned int dwS, unsigned int dwT, int nDSDX, int nDTDY);
228 void RDP_TexRect(unsigned int dwXH, unsigned int dwYH, unsigned int dwXL, unsigned int dwYL,
229 unsigned int tileno, unsigned short dwS, unsigned short dwT, unsigned short nDSDX, unsigned short nDTDY);
230
231 //Other
232 void RDP_FullSync();
233
234public:
235
236 static Memory* m_memory; //!< Pointer to memory manager
237
238public:
239
240 //Other Mode
241 OtherMode m_otherMode; //!< Lots of states for graphics and combiner
242
243 //Hash values for paletts
244 unsigned int m_paletteCRC16[16]; //!< Hash values used to select correct texture
245 unsigned int m_paletteCRC256; //!< Hash values used to select correct texture
246
247protected:
248
249 //Pointers to other objects and managers
250 GFX_INFO* m_graphicsInfo; //!< Access to emulator data (like RDRAM ...)
251 RSP* m_rsp; //!< Pointer to Reality Signal Processor
252 VI* m_vi; //!< Pointer to video interface
253 DisplayListParser* m_displayListParser; //!< Pointer to display list parser
254 TextureCache* m_textureCache; //!< Pointer to texture cache
255 FogManager* m_fogMgr; //!< Pointer to fog manager
256 AdvancedCombinerManager* m_combinerMgr; //!< Pointer to combiner manager
257 TextureLoader* m_textureLoader; //!< Pointer to texture loader
258 OpenGL2DRenderer* m_openGL2DRenderer; //!< Pointer to OpenGL 2D Renderer
259
260 //Prim Depth
261 float m_primitiveZ; //!< Z value assigned to vertices z value if depth source says so
262 float m_primitiveDeltaZ; //!< ??? Unused by this plugin
263
264 //Update?
265 bool m_updateCombiner; //!< Update combiner?
266 bool m_updateCombineColors; //!< Update colors combiner uses?
267 bool m_tmemChanged; //!< True when texture memory has been altered
268 bool m_changedTiles; //!< True if tiles have been changed
269
270 //Textures
271 LoadType m_loadType; //!< What kind of texture was previusly loaded
272 TextureMode m_textureMode; //!< Texture mode (NORMAL, TEXRECT, BACKGROUND, FRAMEBUFFER)
273 unsigned int m_textureLUT; //!< Texture Look Up Table
274 unsigned int m_texRectWidth; //!< Width of the texture rectangle to be rendered
275 unsigned int m_texRectHeight; //!< Height of the texture rectangle to be rendered
276
277 //Images
278 RDPSetImgInfo m_colorImageInfo; //!< Information about color image
279 RDPSetImgInfo m_depthImageInfo; //!< Information about depth image
280
281 //Half
282 unsigned int m_half1; //!< First half value
283 unsigned int m_half2; //!< Second half value
284
285 //Update on first CI
286 bool m_screenUpdatePending;
287
288};
289
290#endif