RICE: Copy of Notaz optim to GLES1.1 version
[mupen64plus-pandora.git] / source / rice_gles / src / RenderBase.h
CommitLineData
d07c171f 1/*
2Copyright (C) 2003 Rice1964
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18*/
19
20#ifndef _RICE_RENDER_BASE_H
21#define _RICE_RENDER_BASE_H
22
23#include "osal_preproc.h"
24#include "Debugger.h"
25#include "RSP_Parser.h"
26#include "Video.h"
27
28/*
29 * Global variables defined in this file were moved out of Render class
30 * to make them be accessed faster
31 */
32
33#define RICE_MATRIX_STACK 60
34#define MAX_TEXTURES 8
35
36enum FillMode
37{
38 RICE_FILLMODE_WINFRAME,
39 RICE_FILLMODE_SOLID,
40};
41
42enum { MAX_VERTS = 80 }; // F3DLP.Rej supports up to 80 verts!
43
44void myVec3Transform(float *vecout, float *vecin, float* m);
45
46// All these arrays are moved out of the class CRender
47// to be accessed in faster speed
48extern ALIGN(16, XVECTOR4 g_vtxTransformed[MAX_VERTS])
49extern ALIGN(16, XVECTOR4 g_vecProjected[MAX_VERTS])
50extern float g_vtxProjected5[1000][5];
51extern float g_vtxProjected5Clipped[2000][5];
52extern VECTOR2 g_fVtxTxtCoords[MAX_VERTS];
53extern uint32 g_dwVtxDifColor[MAX_VERTS];
54//extern uint32 g_dwVtxFlags[MAX_VERTS]; // Z_POS Z_NEG etc
55
56extern RenderTexture g_textures[MAX_TEXTURES];
57
58extern TLITVERTEX g_vtxBuffer[1000];
59extern unsigned short g_vtxIndex[1000];
60
61extern TLITVERTEX g_clippedVtxBuffer[2000];
62extern int g_clippedVtxCount;
63
64extern uint8 g_oglVtxColors[1000][4];
65extern uint32 g_clipFlag[MAX_VERTS];
66extern uint32 g_clipFlag2[MAX_VERTS];
67extern float g_fFogCoord[MAX_VERTS];
68
69extern TLITVERTEX g_texRectTVtx[4];
70
71extern EXTERNAL_VERTEX g_vtxForExternal[MAX_VERTS];
72
73
74//#define INIT_VERTEX_METHOD_2
75
76/*
77 * Global variables
78 */
79
80/************************************************************************/
81/* Don't move */
82/************************************************************************/
83
84extern uint32 gRSPnumLights;
85extern Light gRSPlights[16];
86extern ALIGN(16, Matrix gRSPworldProjectTransported)
87extern ALIGN(16, Matrix gRSPworldProject)
88extern N64Light gRSPn64lights[16];
89extern ALIGN(16, Matrix gRSPmodelViewTop)
90extern ALIGN(16, Matrix gRSPmodelViewTopTranspose)
91extern float gRSPfFogMin;
92extern float gRSPfFogMax;
93extern float gRSPfFogDivider;
94
95/************************************************************************/
96/* Don't move */
97/************************************************************************/
98typedef struct
99{
100 /************************************************************************/
101 /* Don't move */
102 /************************************************************************/
103 union {
104 struct {
105 float fAmbientLightR;
106 float fAmbientLightG;
107 float fAmbientLightB;
108 float fAmbientLightA;
109 };
110 float fAmbientColors[4];
111 };
112 /************************************************************************/
113 /* Don't move above */
114 /************************************************************************/
115 bool bTextureEnabled;
116 uint32 curTile;
117 float fTexScaleX;
118 float fTexScaleY;
119
120 RenderShadeMode shadeMode;
121 bool bCullFront;
122 bool bCullBack;
123 bool bLightingEnable;
124 bool bTextureGen;
125 bool bFogEnabled;
126 BOOL bZBufferEnabled;
127
128 uint32 ambientLightColor;
129 uint32 ambientLightIndex;
130
131 uint32 projectionMtxTop;
132 uint32 modelViewMtxTop;
133
134 uint32 numVertices;
135 uint32 maxVertexID;
136
137 int nVPLeftN, nVPTopN, nVPRightN, nVPBottomN, nVPWidthN, nVPHeightN, maxZ;
138 int clip_ratio_negx, clip_ratio_negy, clip_ratio_posx, clip_ratio_posy;
139 int clip_ratio_left, clip_ratio_top, clip_ratio_right, clip_ratio_bottom;
140 int real_clip_scissor_left, real_clip_scissor_top, real_clip_scissor_right, real_clip_scissor_bottom;
141 float real_clip_ratio_negx, real_clip_ratio_negy, real_clip_ratio_posx, real_clip_ratio_posy;
142
143 Matrix projectionMtxs[RICE_MATRIX_STACK];
144 Matrix modelviewMtxs[RICE_MATRIX_STACK];
145
146 bool bWorldMatrixIsUpdated;
147 bool bMatrixIsUpdated;
148 bool bCombinedMatrixIsUpdated;
149 bool bLightIsUpdated;
150
151 uint32 segments[16];
152
153 int DKRCMatrixIndex;
154 int DKRVtxCount;
155 bool DKRBillBoard;
156 uint32 dwDKRVtxAddr;
157 uint32 dwDKRMatrixAddr;
158 Matrix DKRMatrixes[4];
159 XVECTOR4 DKRBaseVec;
160
161 int ucode;
162 int vertexMult;
163 bool bNearClip;
164 bool bRejectVtx;
165
166 bool bProcessDiffuseColor;
167 bool bProcessSpecularColor;
168
169 float vtxXMul;
170 float vtxXAdd;
171 float vtxYMul;
172 float vtxYAdd;
173
174 // Texture coordinates computation constants
175 float tex0scaleX;
176 float tex0scaleY;
177 float tex1scaleX;
178 float tex1scaleY;
179 float tex0OffsetX;
180 float tex0OffsetY;
181 float tex1OffsetX;
182 float tex1OffsetY;
183 float texGenYRatio;
184 float texGenXRatio;
185
186} RSP_Options;
187
188extern ALIGN(16, RSP_Options gRSP)
189
190typedef struct {
191 uint32 keyR;
192 uint32 keyG;
193 uint32 keyB;
194 uint32 keyA;
195 uint32 keyRGB;
196 uint32 keyRGBA;
197 float fKeyA;
198
199 bool bFogEnableInBlender;
200
201 uint32 fogColor;
202 uint32 primitiveColor;
203 uint32 envColor;
204 uint32 primitiveDepth;
205 uint32 primLODMin;
206 uint32 primLODFrac;
207 uint32 LODFrac;
208
209 float fPrimitiveDepth;
210 float fvFogColor[4];
211 float fvPrimitiveColor[4];
212 float fvEnvColor[4];
213
214 uint32 fillColor;
215 uint32 originalFillColor;
216
217 uint32 geometryMode;
218 uint32 otherModeL;
219 uint32 otherModeH;
220 RDP_OtherMode otherMode;
221
222 Tile tiles[8];
223 ScissorType scissor;
224
225 bool textureIsChanged;
226 bool texturesAreReloaded;
227 bool colorsAreReloaded;
228} RDP_Options;
229
230extern ALIGN(16, RDP_Options gRDP)
231
232/*
233* Global functions
234*/
235void InitRenderBase();
236void SetFogMinMax(float fMin, float fMax, float fMul, float fOffset);
237void InitVertex(uint32 dwV, uint32 vtxIndex, bool bTexture, bool openGL = true );
238void InitVertexTextureConstants();
239bool PrepareTriangle(uint32 dwV0, uint32 dwV1, uint32 dwV2);
240bool IsTriangleVisible(uint32 dwV0, uint32 dwV1, uint32 dwV2);
241extern void (*ProcessVertexData)(uint32 dwAddr, uint32 dwV0, uint32 dwNum);
242#if !defined(NO_ASM)
243void ProcessVertexDataSSE(uint32 dwAddr, uint32 dwV0, uint32 dwNum);
244#endif
245void ProcessVertexDataNoSSE(uint32 dwAddr, uint32 dwV0, uint32 dwNum);
48d77f73 246void ProcessVertexDataNEON(uint32 dwAddr, uint32 dwV0, uint32 dwNum);
d07c171f 247void ProcessVertexDataExternal(uint32 dwAddr, uint32 dwV0, uint32 dwNum);
248void SetPrimitiveColor(uint32 dwCol, uint32 LODMin, uint32 LODFrac);
249void SetPrimitiveDepth(uint32 z, uint32 dwDZ);
250void SetVertexXYZ(uint32 vertex, float x, float y, float z);
251void ModifyVertexInfo(uint32 where, uint32 vertex, uint32 val);
252void ProcessVertexDataDKR(uint32 dwAddr, uint32 dwV0, uint32 dwNum);
253void SetLightCol(uint32 dwLight, uint32 dwCol);
254void SetLightDirection(uint32 dwLight, float x, float y, float z, float range);
255void ForceMainTextureIndex(int dwTile);
256void UpdateCombinedMatrix();
257
258void ClipVertexes();
259void ClipVertexesOpenGL();
260void ClipVertexesForRect();
261
262void LogTextureCoords(float fTex0S, float fTex0T, float fTex1S, float fTex1T);
263bool CheckTextureCoords(int tex);
264void ResetTextureCoordsLog(float maxs0, float maxt0, float maxs1, float maxt1);
265
266inline float ViewPortTranslatef_x(float x) { return ( (x+1) * windowSetting.vpWidthW/2) + windowSetting.vpLeftW; }
267inline float ViewPortTranslatef_y(float y) { return ( (1-y) * windowSetting.vpHeightW/2) + windowSetting.vpTopW; }
268inline float ViewPortTranslatei_x(int x) { return x*windowSetting.fMultX; }
269inline float ViewPortTranslatei_y(int y) { return y*windowSetting.fMultY; }
270inline float ViewPortTranslatei_x(float x) { return x*windowSetting.fMultX; }
271inline float ViewPortTranslatei_y(float y) { return y*windowSetting.fMultY; }
272
273inline float GetPrimitiveDepth() { return gRDP.fPrimitiveDepth; }
274inline uint32 GetPrimitiveColor() { return gRDP.primitiveColor; }
275inline float* GetPrimitiveColorfv() { return gRDP.fvPrimitiveColor; }
276inline uint32 GetLODFrac() { return gRDP.LODFrac; }
277inline void SetEnvColor(uint32 dwCol)
278{
279 gRDP.colorsAreReloaded = true;
280 gRDP.envColor = dwCol;
281 gRDP.fvEnvColor[0] = ((dwCol>>16)&0xFF)/255.0f; //r
282 gRDP.fvEnvColor[1] = ((dwCol>>8)&0xFF)/255.0f; //g
283 gRDP.fvEnvColor[2] = ((dwCol)&0xFF)/255.0f; //b
284 gRDP.fvEnvColor[3] = ((dwCol>>24)&0xFF)/255.0f; //a
285}
286inline uint32 GetEnvColor() { return gRDP.envColor; }
287inline float* GetEnvColorfv() { return gRDP.fvEnvColor; }
288
289inline void SetAmbientLight(uint32 color)
290{
291 gRSP.ambientLightColor = color;
292 gRSP.fAmbientLightR = (float)RGBA_GETRED(gRSP.ambientLightColor);
293 gRSP.fAmbientLightG = (float)RGBA_GETGREEN(gRSP.ambientLightColor);
294 gRSP.fAmbientLightB = (float)RGBA_GETBLUE(gRSP.ambientLightColor);
295 LIGHT_DUMP(TRACE1("Set Ambient Light: %08X", color));
296}
297
298inline void SetLighting(bool bLighting) { gRSP.bLightingEnable = bLighting; }
299
300// Generate texture coords?
301inline void SetTextureGen(bool bTextureGen) { gRSP.bTextureGen = bTextureGen; }
302inline void SetNumLights(uint32 dwNumLights)
303{
304 gRSPnumLights = dwNumLights;
305 DEBUGGER_PAUSE_AND_DUMP(NEXT_SET_LIGHT,TRACE1("Set Num Of Light: %d", dwNumLights));
306}
307inline uint32 GetNumLights() { return gRSPnumLights; }
308inline COLOR GetVertexDiffuseColor(uint32 ver) { return g_dwVtxDifColor[ver]; }
309inline void SetScreenMult(float fMultX, float fMultY) { windowSetting.fMultX = fMultX; windowSetting.fMultY = fMultY; }
310inline COLOR GetLightCol(uint32 dwLight) { return gRSPlights[dwLight].col; }
311
312#endif
313