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