d07c171f |
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_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 | |
36 | enum FillMode |
37 | { |
38 | RICE_FILLMODE_WINFRAME, |
39 | RICE_FILLMODE_SOLID, |
40 | }; |
41 | |
42 | enum { MAX_VERTS = 80 }; // F3DLP.Rej supports up to 80 verts! |
43 | |
44 | void 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 |
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 |
55 | |
56 | extern RenderTexture g_textures[MAX_TEXTURES]; |
57 | |
58 | extern TLITVERTEX g_vtxBuffer[1000]; |
59 | extern unsigned short g_vtxIndex[1000]; |
60 | |
61 | extern TLITVERTEX g_clippedVtxBuffer[2000]; |
62 | extern int g_clippedVtxCount; |
63 | |
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]; |
68 | |
69 | extern TLITVERTEX g_texRectTVtx[4]; |
70 | |
71 | extern 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 | |
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; |
94 | |
95 | /************************************************************************/ |
96 | /* Don't move */ |
97 | /************************************************************************/ |
98 | typedef 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 | |
188 | extern ALIGN(16, RSP_Options gRSP) |
189 | |
190 | typedef 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 | |
230 | extern ALIGN(16, RDP_Options gRDP) |
231 | |
232 | /* |
233 | * Global functions |
234 | */ |
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); |
242 | #if !defined(NO_ASM) |
243 | void ProcessVertexDataSSE(uint32 dwAddr, uint32 dwV0, uint32 dwNum); |
244 | #endif |
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(); |
256 | |
257 | void ClipVertexes(); |
258 | void ClipVertexesOpenGL(); |
259 | void ClipVertexesForRect(); |
260 | |
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); |
264 | |
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; } |
271 | |
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) |
277 | { |
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 |
284 | } |
285 | inline uint32 GetEnvColor() { return gRDP.envColor; } |
286 | inline float* GetEnvColorfv() { return gRDP.fvEnvColor; } |
287 | |
288 | inline void SetAmbientLight(uint32 color) |
289 | { |
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)); |
295 | } |
296 | |
297 | inline void SetLighting(bool bLighting) { gRSP.bLightingEnable = bLighting; } |
298 | |
299 | // Generate texture coords? |
300 | inline void SetTextureGen(bool bTextureGen) { gRSP.bTextureGen = bTextureGen; } |
301 | inline void SetNumLights(uint32 dwNumLights) |
302 | { |
303 | gRSPnumLights = dwNumLights; |
304 | DEBUGGER_PAUSE_AND_DUMP(NEXT_SET_LIGHT,TRACE1("Set Num Of Light: %d", dwNumLights)); |
305 | } |
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; } |
310 | |
311 | #endif |
312 | |