00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <Windows.h>
00023 #include <stdio.h>
00024
00025 #include "D3DDrv.h"
00026 #include "DCommon.h"
00027 #include "Scene.h"
00028 #include "Render.h"
00029 #include "GSpan.h"
00030 #include "D3DCache.h"
00031 #include "D3D_Fx.h"
00032 #include "D3D_Main.h"
00033 #include "PCache.h"
00034 #include "D3D_Err.h"
00035 #include "THandle.h"
00036
00037
00038 #define SUPER_FLUSH
00039
00040 int32 RenderMode;
00041
00042 uint32 CurrentLRU;
00043
00044 BOOL DRIVERCC BeginScene(BOOL Clear, BOOL ClearZ, RECT *WorldRect)
00045 {
00046 HRESULT Result;
00047
00048 CurrentLRU++;
00049
00050 if (!AppInfo.lpD3DDevice)
00051 {
00052 D3DMain_Log("BeginScene: No D3D Device!.");
00053 return FALSE;
00054 }
00055
00056
00057 memset(&CacheInfo, 0, sizeof(DRV_CacheInfo));
00058
00059 if (!THandle_CheckCache())
00060 return GE_FALSE;
00061
00062
00063 if(AppInfo.RenderingIsOK)
00064 {
00065 if (!Main_ClearBackBuffer(Clear, ClearZ))
00066 {
00067 D3DMain_Log("D3DClearBuffers failed.");
00068 return FALSE;
00069 }
00070
00071 D3DDRV.NumRenderedPolys = 0;
00072
00073 Result = AppInfo.lpD3DDevice->BeginScene();
00074
00075 if (Result != D3D_OK)
00076 {
00077 D3DMain_Log("BeginScene: D3D BeginScene Failed.\n%s.", D3DErrorToString(Result));
00078 return FALSE;
00079 }
00080
00081 D3DBilinearFilter(D3DFILTER_LINEAR, D3DFILTER_LINEAR);
00082 D3DPolygonMode (D3DFILL_WIREFRAME);
00083
00084 D3DZWriteEnable (TRUE);
00085 D3DZEnable(TRUE);
00086 D3DZFunc(D3DCMP_LESSEQUAL);
00087
00088 D3DBlendFunc (D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA);
00089 D3DBlendEnable(TRUE);
00090
00091 if (AppInfo.FogEnable)
00092 {
00093 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE , TRUE);
00094 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR , ((DWORD)AppInfo.FogR<<16)|((DWORD)AppInfo.FogG<<8)|(DWORD)AppInfo.FogB);
00095 }
00096 else
00097 {
00098 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE , FALSE);
00099 }
00100 }
00101
00102 return TRUE;
00103 }
00104
00105 BOOL DRIVERCC EndScene(void)
00106 {
00107 HRESULT Result;
00108
00109 if (!AppInfo.lpD3DDevice)
00110 return FALSE;
00111
00112 if(AppInfo.RenderingIsOK)
00113 {
00114
00115 PCache_FlushWorldPolys();
00116 PCache_FlushMiscPolys();
00117
00118 Result = AppInfo.lpD3DDevice->EndScene();
00119
00120 if (Result != D3D_OK)
00121 {
00122 D3DMain_Log("EndScene: D3D EndScene Failed.\n%s", D3DErrorToString(Result));
00123 return FALSE;
00124 }
00125
00126 if (!Main_ShowBackBuffer())
00127 return FALSE;
00128 }
00129 return TRUE;
00130 }
00131
00132 BOOL DRIVERCC BeginWorld(void)
00133 {
00134 #ifdef USE_SPANS
00135 if(AppInfo.RenderingIsOK)
00136 {
00137 ResetSpans(ClientWindow.Height);
00138 }
00139 #endif
00140
00141 RenderMode = RENDER_WORLD;
00142 return TRUE;
00143 }
00144
00145 BOOL DRIVERCC EndWorld(void)
00146 {
00147 RenderMode = RENDER_NONE;
00148
00149 if(AppInfo.RenderingIsOK)
00150 {
00151 PCache_FlushWorldPolys();
00152 PCache_FlushMiscPolys();
00153
00154 assert(AppInfo.lpD3DDevice);
00155 #ifdef SUPER_FLUSH
00156 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FLUSHBATCH, 0);
00157 AppInfo.lpD3DDevice->EndScene();
00158 AppInfo.lpD3DDevice->BeginScene();
00159 #endif
00160
00161 }
00162 return TRUE;
00163 }
00164
00165 BOOL GlobalMeshHack;
00166
00167 BOOL DRIVERCC BeginMeshes(void)
00168 {
00169 GlobalMeshHack = TRUE;
00170 RenderMode = RENDER_MESHES;
00171 return TRUE;
00172 }
00173
00174 BOOL DRIVERCC EndMeshes(void)
00175 {
00176 RenderMode = RENDER_NONE;
00177
00178 if(AppInfo.RenderingIsOK)
00179 {
00180 PCache_FlushMiscPolys();
00181 PCache_FlushWorldPolys();
00182
00183 #ifdef SUPER_FLUSH
00184 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FLUSHBATCH, 0);
00185 AppInfo.lpD3DDevice->EndScene();
00186 AppInfo.lpD3DDevice->BeginScene();
00187 #endif
00188
00189 GlobalMeshHack = FALSE;
00190 }
00191 return TRUE;
00192 }
00193
00194 BOOL DRIVERCC BeginModels(void)
00195 {
00196 RenderMode = RENDER_MODELS;
00197 return TRUE;
00198 }
00199
00200 BOOL DRIVERCC EndModels(void)
00201 {
00202 RenderMode = RENDER_NONE;
00203
00204 if(AppInfo.RenderingIsOK)
00205 {
00206 PCache_FlushWorldPolys();
00207 PCache_FlushMiscPolys();
00208
00209 #ifdef SUPER_FLUSH
00210 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FLUSHBATCH, 0);
00211 AppInfo.lpD3DDevice->EndScene();
00212 AppInfo.lpD3DDevice->BeginScene();
00213 #endif
00214
00215 }
00216 return TRUE;
00217 }