Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

Scene.cpp

Go to the documentation of this file.
00001 /****************************************************************************************/
00002 /*  Scene.cpp                                                                           */
00003 /*                                                                                      */
00004 /*  Author: John Pollard                                                                */
00005 /*  Description: Begin/EndScene code, etc                                               */
00006 /*                                                                                      */
00007 /*  02/28/2001 Wendell Buckner
00008 /*   These render states are unsupported d3d 7.0
00009 /*  07/16/2000 Wendell Buckner
00010 /*   Convert to Directx7...    */
00011 /*
00012 /*  The contents of this file are subject to the Genesis3D Public License               */
00013 /*  Version 1.01 (the "License"); you may not use this file except in                   */
00014 /*  compliance with the License. You may obtain a copy of the License at                */
00015 /*  http://www.genesis3d.com                                                            */
00016 /*                                                                                      */
00017 /*  Software distributed under the License is distributed on an "AS IS"                 */
00018 /*  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See                */
00019 /*  the License for the specific language governing rights and limitations              */
00020 /*  under the License.                                                                  */
00021 /*                                                                                      */
00022 /*  The Original Code is Genesis3D, released March 25, 1999.                            */
00023 /*Genesis3D Version 1.1 released November 15, 1999                            */
00024 /*  Copyright (C) 1999 WildTangent, Inc. All Rights Reserved           */
00025 /*                                                                                      */
00026 /****************************************************************************************/
00027 #include <Windows.h>
00028 #include <stdio.h>
00029 
00030 /*  07/16/2000 Wendell Buckner
00031 /*   Convert to Directx7...    
00032 #include "D3DDrv.h"             */
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 //#define D3D_MANAGE_TEXTURES
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         // Make sure we clear the cache info structure...
00066         memset(&CacheInfo, 0, sizeof(DRV_CacheInfo));
00067 
00068         if (!THandle_CheckCache())
00069                 return GE_FALSE;
00070 
00071         //      Watch for inactive app or minimize
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                 // Flush everything one last time...
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 /* 02/28/2001 Wendell Buckner
00166    These render states are unsupported d3d 7.0
00167                 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FLUSHBATCH, 0);*/
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 /* 02/28/2001 Wendell Buckner
00196    These render states are unsupported d3d 7.0
00197                 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FLUSHBATCH, 0);*/
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 /* 02/28/2001 Wendell Buckner
00224    These render states are unsupported d3d 7.0
00225                 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FLUSHBATCH, 0);*/
00226                 AppInfo.lpD3DDevice->EndScene();
00227                 AppInfo.lpD3DDevice->BeginScene();
00228         #endif
00229 
00230         }
00231         return TRUE;
00232 }

Generated on Tue Sep 30 12:36:19 2003 for GTestAndEngine by doxygen 1.3.2