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_BASE_H
21 #define _RICE_RENDER_BASE_H
23 #include "osal_preproc.h"
25 #include "RSP_Parser.h"
29 * Global variables defined in this file were moved out of Render class
30 * to make them be accessed faster
33 #define RICE_MATRIX_STACK 60
34 #define MAX_TEXTURES 8
38 RICE_FILLMODE_WINFRAME,
42 enum { MAX_VERTS = 80 }; // F3DLP.Rej supports up to 80 verts!
44 void myVec3Transform(float *vecout, float *vecin, float* m);
46 // All these arrays are moved out of the class CRender
47 // to be accessed in faster speed
48 extern ALIGN(16, XVECTOR4 g_vtxTransformed[MAX_VERTS])
49 extern ALIGN(16, XVECTOR4 g_vecProjected[MAX_VERTS])
50 extern float g_vtxProjected5[1000][5];
51 extern float g_vtxProjected5Clipped[2000][5];
52 extern VECTOR2 g_fVtxTxtCoords[MAX_VERTS];
53 extern uint32 g_dwVtxDifColor[MAX_VERTS];
54 //extern uint32 g_dwVtxFlags[MAX_VERTS]; // Z_POS Z_NEG etc
56 extern RenderTexture g_textures[MAX_TEXTURES];
58 extern TLITVERTEX g_vtxBuffer[1000];
59 extern unsigned short g_vtxIndex[1000];
61 extern TLITVERTEX g_clippedVtxBuffer[2000];
62 extern int g_clippedVtxCount;
64 extern uint8 g_oglVtxColors[1000][4];
65 extern uint32 g_clipFlag[MAX_VERTS];
66 extern uint32 g_clipFlag2[MAX_VERTS];
67 extern float g_fFogCoord[MAX_VERTS];
69 extern TLITVERTEX g_texRectTVtx[4];
71 extern EXTERNAL_VERTEX g_vtxForExternal[MAX_VERTS];
74 //#define INIT_VERTEX_METHOD_2
80 /************************************************************************/
82 /************************************************************************/
84 extern uint32 gRSPnumLights;
85 extern Light gRSPlights[16];
86 extern ALIGN(16, Matrix gRSPworldProjectTransported)
87 extern ALIGN(16, Matrix gRSPworldProject)
88 extern N64Light gRSPn64lights[16];
89 extern ALIGN(16, Matrix gRSPmodelViewTop)
90 extern ALIGN(16, Matrix gRSPmodelViewTopTranspose)
91 extern float gRSPfFogMin;
92 extern float gRSPfFogMax;
93 extern float gRSPfFogDivider;
95 /************************************************************************/
97 /************************************************************************/
100 /************************************************************************/
102 /************************************************************************/
105 float fAmbientLightR;
106 float fAmbientLightG;
107 float fAmbientLightB;
108 float fAmbientLightA;
110 float fAmbientColors[4];
112 /************************************************************************/
113 /* Don't move above */
114 /************************************************************************/
115 bool bTextureEnabled;
120 RenderShadeMode shadeMode;
123 bool bLightingEnable;
126 BOOL bZBufferEnabled;
128 uint32 ambientLightColor;
129 uint32 ambientLightIndex;
131 uint32 projectionMtxTop;
132 uint32 modelViewMtxTop;
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;
143 Matrix projectionMtxs[RICE_MATRIX_STACK];
144 Matrix modelviewMtxs[RICE_MATRIX_STACK];
146 bool bWorldMatrixIsUpdated;
147 bool bMatrixIsUpdated;
148 bool bCombinedMatrixIsUpdated;
149 bool bLightIsUpdated;
157 uint32 dwDKRMatrixAddr;
158 Matrix DKRMatrixes[4];
166 bool bProcessDiffuseColor;
167 bool bProcessSpecularColor;
174 // Texture coordinates computation constants
188 extern ALIGN(16, RSP_Options gRSP)
199 bool bFogEnableInBlender;
202 uint32 primitiveColor;
204 uint32 primitiveDepth;
209 float fPrimitiveDepth;
211 float fvPrimitiveColor[4];
215 uint32 originalFillColor;
220 RDP_OtherMode otherMode;
225 bool textureIsChanged;
226 bool texturesAreReloaded;
227 bool colorsAreReloaded;
230 extern ALIGN(16, RDP_Options gRDP)
235 void InitRenderBase();
236 void SetFogMinMax(float fMin, float fMax, float fMul, float fOffset);
237 void InitVertex(uint32 dwV, uint32 vtxIndex, bool bTexture, bool openGL = true );
238 void InitVertexTextureConstants();
239 bool PrepareTriangle(uint32 dwV0, uint32 dwV1, uint32 dwV2);
240 bool IsTriangleVisible(uint32 dwV0, uint32 dwV1, uint32 dwV2);
241 extern void (*ProcessVertexData)(uint32 dwAddr, uint32 dwV0, uint32 dwNum);
243 void ProcessVertexDataSSE(uint32 dwAddr, uint32 dwV0, uint32 dwNum);
245 void ProcessVertexDataNoSSE(uint32 dwAddr, uint32 dwV0, uint32 dwNum);
246 void ProcessVertexDataExternal(uint32 dwAddr, uint32 dwV0, uint32 dwNum);
247 void SetPrimitiveColor(uint32 dwCol, uint32 LODMin, uint32 LODFrac);
248 void SetPrimitiveDepth(uint32 z, uint32 dwDZ);
249 void SetVertexXYZ(uint32 vertex, float x, float y, float z);
250 void ModifyVertexInfo(uint32 where, uint32 vertex, uint32 val);
251 void ProcessVertexDataDKR(uint32 dwAddr, uint32 dwV0, uint32 dwNum);
252 void SetLightCol(uint32 dwLight, uint32 dwCol);
253 void SetLightDirection(uint32 dwLight, float x, float y, float z, float range);
254 void ForceMainTextureIndex(int dwTile);
255 void UpdateCombinedMatrix();
258 void ClipVertexesOpenGL();
259 void ClipVertexesForRect();
261 void LogTextureCoords(float fTex0S, float fTex0T, float fTex1S, float fTex1T);
262 bool CheckTextureCoords(int tex);
263 void ResetTextureCoordsLog(float maxs0, float maxt0, float maxs1, float maxt1);
265 inline float ViewPortTranslatef_x(float x) { return ( (x+1) * windowSetting.vpWidthW/2) + windowSetting.vpLeftW; }
266 inline float ViewPortTranslatef_y(float y) { return ( (1-y) * windowSetting.vpHeightW/2) + windowSetting.vpTopW; }
267 inline float ViewPortTranslatei_x(int x) { return x*windowSetting.fMultX; }
268 inline float ViewPortTranslatei_y(int y) { return y*windowSetting.fMultY; }
269 inline float ViewPortTranslatei_x(float x) { return x*windowSetting.fMultX; }
270 inline float ViewPortTranslatei_y(float y) { return y*windowSetting.fMultY; }
272 inline float GetPrimitiveDepth() { return gRDP.fPrimitiveDepth; }
273 inline uint32 GetPrimitiveColor() { return gRDP.primitiveColor; }
274 inline float* GetPrimitiveColorfv() { return gRDP.fvPrimitiveColor; }
275 inline uint32 GetLODFrac() { return gRDP.LODFrac; }
276 inline void SetEnvColor(uint32 dwCol)
278 gRDP.colorsAreReloaded = true;
279 gRDP.envColor = dwCol;
280 gRDP.fvEnvColor[0] = ((dwCol>>16)&0xFF)/255.0f; //r
281 gRDP.fvEnvColor[1] = ((dwCol>>8)&0xFF)/255.0f; //g
282 gRDP.fvEnvColor[2] = ((dwCol)&0xFF)/255.0f; //b
283 gRDP.fvEnvColor[3] = ((dwCol>>24)&0xFF)/255.0f; //a
285 inline uint32 GetEnvColor() { return gRDP.envColor; }
286 inline float* GetEnvColorfv() { return gRDP.fvEnvColor; }
288 inline void SetAmbientLight(uint32 color)
290 gRSP.ambientLightColor = color;
291 gRSP.fAmbientLightR = (float)RGBA_GETRED(gRSP.ambientLightColor);
292 gRSP.fAmbientLightG = (float)RGBA_GETGREEN(gRSP.ambientLightColor);
293 gRSP.fAmbientLightB = (float)RGBA_GETBLUE(gRSP.ambientLightColor);
294 LIGHT_DUMP(TRACE1("Set Ambient Light: %08X", color));
297 inline void SetLighting(bool bLighting) { gRSP.bLightingEnable = bLighting; }
299 // Generate texture coords?
300 inline void SetTextureGen(bool bTextureGen) { gRSP.bTextureGen = bTextureGen; }
301 inline void SetNumLights(uint32 dwNumLights)
303 gRSPnumLights = dwNumLights;
304 DEBUGGER_PAUSE_AND_DUMP(NEXT_SET_LIGHT,TRACE1("Set Num Of Light: %d", dwNumLights));
306 inline uint32 GetNumLights() { return gRSPnumLights; }
307 inline COLOR GetVertexDiffuseColor(uint32 ver) { return g_dwVtxDifColor[ver]; }
308 inline void SetScreenMult(float fMultX, float fMultY) { windowSetting.fMultX = fMultX; windowSetting.fMultY = fMultY; }
309 inline COLOR GetLightCol(uint32 dwLight) { return gRSPlights[dwLight].col; }