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

D3d_main.h File Reference

#include <Windows.h>
#include <DDraw.h>
#include <D3D.h>
#include "DCommon.h"

Go to the source code of this file.

Compounds

struct  App_Info
struct  App_Mode
struct  DD_Enum
struct  DDMain_D3DDriver
struct  DDMain_SurfFormat
struct  RGB_LUT

Defines

#define INITGUID
#define MAX_APP_MODES   50
#define DDMAIN_MAX_D3D_DRIVERS   10
#define DDMAIN_MAX_TEXTURE_FORMATS   128
#define DDMAIN_MAX_SURFACE_FORMATS   128
#define D3DMAIN_LOG_FILENAME   "D3DDrv.Log"
#define MAX_DRIVER_NAME   1024

Functions

BOOL D3DMain_InitD3D (HWND hWnd, const char *DriverName, int32 Width, int32 Height)
BOOL D3DMain_ShutdownD3D (void)
geBoolean D3DMain_Reset (void)
void D3DMain_Log (LPSTR Str,...)
BOOL D3DMain_RestoreAllSurfaces (void)
BOOL Main_EnumTextureFormats (void)
BOOL D3DMain_EnumDisplayModes (void)
BOOL Main_ClearBackBuffer (BOOL Clear, BOOL ClearZ)
BOOL Main_ShowBackBuffer (void)
BOOL D3DMain_GetSurfaceFormats (void)
BOOL Main_CheckDD (void)
BOOL D3DMain_GetTextureMemory (void)
void Main_BuildRGBGammaTables (geFloat Gamma)
BOOL D3DMain_GetClientWindowOffset (HWND hWnd)
geBoolean DRIVERCC D3DMain_UpdateWindow (void)
geBoolean DRIVERCC D3DMain_SetActive (geBoolean wParam)
geBoolean DRIVERCC D3DMain_SetFogEnable (geBoolean Enable, geFloat r, geFloat g, geFloat b, geFloat Start, geFloat End)

Variables

App_Info AppInfo


Define Documentation

#define D3DMAIN_LOG_FILENAME   "D3DDrv.Log"
 

Definition at line 38 of file D3DDrv/D3d_main.h.

#define DDMAIN_MAX_D3D_DRIVERS   10
 

Definition at line 34 of file D3DDrv/D3d_main.h.

#define DDMAIN_MAX_SURFACE_FORMATS   128
 

Definition at line 36 of file D3DDrv/D3d_main.h.

#define DDMAIN_MAX_TEXTURE_FORMATS   128
 

Definition at line 35 of file D3DDrv/D3d_main.h.

#define INITGUID
 

Definition at line 29 of file D3DDrv/D3d_main.h.

#define MAX_APP_MODES   50
 

Definition at line 33 of file D3DDrv/D3d_main.h.

#define MAX_DRIVER_NAME   1024
 

Definition at line 40 of file D3DDrv/D3d_main.h.


Function Documentation

BOOL D3DMain_EnumDisplayModes void   ) 
 

Definition at line 546 of file D3D7xDrv/D3d_main.cpp.

00547 {
00548         HRESULT         LastError;
00549 
00550         D3DMain_Log("--- D3DMain_EnumDisplayModes ---\n");
00551 
00552         // Get a list of available display modes from DirectDraw
00553         AppInfo.NumModes = 0;
00554   
00555         LastError = AppInfo.lpDD->EnumDisplayModes(0, NULL, 0, EnumDisplayModesCallback);
00556 
00557         if(LastError != DD_OK ) 
00558         {
00559                 D3DMain_Log("EnumDisplayModes failed.\n  %s\n", D3DErrorToString(LastError));
00560                 AppInfo.NumModes = 0;
00561                 return FALSE;
00562         }
00563 
00564         // Sort the list of display modes
00565         qsort((void *)&AppInfo.Modes[0], (size_t)AppInfo.NumModes, sizeof(App_Mode), CompareModes);
00566         
00567         return TRUE;
00568 }

BOOL D3DMain_GetClientWindowOffset HWND  hWnd  ) 
 

Definition at line 2051 of file D3D7xDrv/D3d_main.cpp.

02052 {
02053         POINT                   CPoint;
02054 
02055         CPoint.x = CPoint.y = 0;
02056 
02057         ClientToScreen(hWnd, &CPoint);
02058 
02059         AppInfo.WindowXOffset = CPoint.x;
02060         AppInfo.WindowYOffset = CPoint.y;
02061 
02062         return TRUE;
02063 }

BOOL D3DMain_GetSurfaceFormats void   ) 
 

Definition at line 1573 of file D3D7xDrv/D3d_main.cpp.

01574 {
01575         int32           i;
01576 
01577     D3DMain_Log("--- D3DMain_GetSurfaceFormats ---\n");
01578         
01579         if (!Main_EnumTextureFormats())
01580         {
01581         D3DMain_Log("D3DMain_GetSurfaceFormats:  Main_EnumTextureFormats failed.\n");
01582                 return FALSE;
01583     }
01584         
01585         if (!Main_EnumSurfaceFormats())
01586         {
01587         D3DMain_Log("D3DMain_GetSurfaceFormats:  Main_EnumSurfaceFormats failed.\n");
01588                 return FALSE;
01589         }
01590 
01591 #if 1
01592         for(i = 0; i < AppInfo.NumSurfFormats; i++)
01593         {
01594                 LPDDPIXELFORMAT lpddpfPixelFormat;
01595 
01596                 lpddpfPixelFormat = &AppInfo.SurfFormats[i].ddsd.ddpfPixelFormat;
01597 
01598                 if(lpddpfPixelFormat->dwRGBBitCount != AppInfo.ddsd.ddpfPixelFormat.dwRGBBitCount)
01599                         continue;
01600 
01601         if (lpddpfPixelFormat->dwRGBAlphaBitMask != AppInfo.ddsd.ddpfPixelFormat.dwRGBAlphaBitMask)
01602                         continue;
01603                 if (lpddpfPixelFormat->dwRBitMask != AppInfo.ddsd.ddpfPixelFormat.dwRBitMask)
01604                         continue;
01605         if (lpddpfPixelFormat->dwGBitMask != AppInfo.ddsd.ddpfPixelFormat.dwGBitMask)
01606                         continue;
01607         if (lpddpfPixelFormat->dwBBitMask != AppInfo.ddsd.ddpfPixelFormat.dwBBitMask)
01608                         continue;
01609 
01610         #if 0   // For debugging (This is the surface it is going to use for 2d decals)
01611                 D3DMain_Log("Bits: %i, A:%x, R:%x, G:%x, B:%x\n",       AppInfo.ddsd.ddpfPixelFormat.dwRGBBitCount, 
01612                                                                                                                         AppInfo.ddsd.ddpfPixelFormat.dwRGBAlphaBitMask, 
01613                                                                                                                         AppInfo.ddsd.ddpfPixelFormat.dwRBitMask, 
01614                                                                                                                         AppInfo.ddsd.ddpfPixelFormat.dwGBitMask, 
01615                                                                                                                         AppInfo.ddsd.ddpfPixelFormat.dwBBitMask);
01616                 return FALSE;
01617         #endif
01618 
01619                 
01620                 AppInfo.ddSurfFormat = AppInfo.SurfFormats[i].ddsd;
01621 
01622                 break;
01623         }
01624 
01625     if(i == AppInfo.NumSurfFormats) 
01626         {
01627                 D3DMain_Log("D3DMain_GetSurfaceFormats:  Unable to find a 2d surface format that matches current bit depth.\n");
01628         return FALSE;
01629     }
01630 
01631 #else
01632         for(i = 0; i < AppInfo.NumTextureFormats; i++)
01633         {
01634                 LPDDPIXELFORMAT lpddpfPixelFormat;
01635 
01636                 lpddpfPixelFormat = &AppInfo.TextureFormats[i].ddsd.ddpfPixelFormat;
01637 
01638                 if(lpddpfPixelFormat->dwRGBBitCount != AppInfo.ddsd.ddpfPixelFormat.dwRGBBitCount)
01639                         continue;
01640 
01641         if (lpddpfPixelFormat->dwRGBAlphaBitMask != AppInfo.ddsd.ddpfPixelFormat.dwRGBAlphaBitMask)
01642                         continue;
01643                 if (lpddpfPixelFormat->dwRBitMask != AppInfo.ddsd.ddpfPixelFormat.dwRBitMask)
01644                         continue;
01645         if (lpddpfPixelFormat->dwGBitMask != AppInfo.ddsd.ddpfPixelFormat.dwGBitMask)
01646                         continue;
01647         if (lpddpfPixelFormat->dwBBitMask != AppInfo.ddsd.ddpfPixelFormat.dwBBitMask)
01648                         continue;
01649 
01650         #if 0   // For debugging (This is the surface it is going to use for 2d decals)
01651                 D3DMain_Log("Bits: %i, A:%x, R:%x, G:%x, B:%x\n",       AppInfo.ddsd.ddpfPixelFormat.dwRGBBitCount, 
01652                                                                                                                         AppInfo.ddsd.ddpfPixelFormat.dwRGBAlphaBitMask, 
01653                                                                                                                         AppInfo.ddsd.ddpfPixelFormat.dwRBitMask, 
01654                                                                                                                         AppInfo.ddsd.ddpfPixelFormat.dwGBitMask, 
01655                                                                                                                         AppInfo.ddsd.ddpfPixelFormat.dwBBitMask);
01656                 return FALSE;
01657         #endif
01658 
01659                 
01660                 AppInfo.ddSurfFormat = AppInfo.TextureFormats[i].ddsd;
01661 
01662                 break;
01663         }
01664 
01665     if(i == AppInfo.NumTextureFormats) 
01666         {
01667                 D3DMain_Log("D3DMain_GetSurfaceFormats:  Unable to find a 2d surface format that matches current bit depth.\n");
01668         return FALSE;
01669     }
01670 #endif
01671 
01672         // Now get the 3d surface formats
01673 
01674         // Get 1555
01675         for(i = 0; i < AppInfo.NumTextureFormats; i++)
01676         {
01677         if(AppInfo.TextureFormats[i].HasOneBitAlpha == TRUE) 
01678                 {
01679             AppInfo.ddOneBitAlphaSurfFormat = AppInfo.TextureFormats[i].ddsd;
01680             break;
01681         }
01682         }
01683 
01684     if(i == AppInfo.NumTextureFormats) 
01685         {
01686                 D3DMain_Log("D3DMain_GetSurfaceFormats:  Unable to find 1555 texture support.\n");
01687         return FALSE;
01688     }
01689     
01690     // Get 4444
01691         for(i = 0; i < AppInfo.NumTextureFormats; i++)
01692         {
01693         if(AppInfo.TextureFormats[i].HasFourBitAlpha == TRUE) 
01694                 {
01695             AppInfo.ddFourBitAlphaSurfFormat = AppInfo.TextureFormats[i].ddsd;
01696             break;
01697         }
01698         }
01699 
01700     if(i == AppInfo.NumTextureFormats) 
01701         {
01702                 D3DMain_Log("D3DMain_GetSurfaceFormats:  Unable to find 4444 texture support.\n");
01703         return FALSE;
01704     }
01705 
01706         // Get either 555, or 565.
01707         for(i = 0; i < AppInfo.NumTextureFormats; i++)
01708         {
01709                 LPDDPIXELFORMAT lpddpfPixelFormat;
01710 
01711         if(AppInfo.TextureFormats[i].HasOneBitAlpha == TRUE)
01712                         continue;
01713 
01714                 if (AppInfo.TextureFormats[i].HasFourBitAlpha == TRUE) 
01715                         continue;
01716 
01717                 lpddpfPixelFormat = &AppInfo.TextureFormats[i].ddsd.ddpfPixelFormat;
01718 
01719                 // For now, force 3d textures with RGB only info to be either 565 or 555
01720                 // We could enum all formats and let the caller pick between several different RGB formats...
01721                 if (lpddpfPixelFormat->dwFlags & DDPF_ALPHAPIXELS)
01722                         continue;               // We don't want any surface that has alpha, just pure RGB...
01723 
01724                 if(lpddpfPixelFormat->dwRGBBitCount != 16) 
01725                         continue;
01726 
01727                 if(     (lpddpfPixelFormat->dwRBitMask != 0xf800 && lpddpfPixelFormat->dwRBitMask != 0x7c00) ||
01728                         (lpddpfPixelFormat->dwGBitMask != 0x7e0 && lpddpfPixelFormat->dwGBitMask != 0x3e0) ||
01729                         (lpddpfPixelFormat->dwBBitMask != 0x1f))
01730                                 continue;
01731 
01732 
01733                 // This is it
01734                 AppInfo.ddTexFormat = AppInfo.TextureFormats[i].ddsd;
01735                 break;
01736         }
01737 
01738     if(i == AppInfo.NumTextureFormats) 
01739         {
01740                 D3DMain_Log("D3DMain_GetSurfaceFormats:  Unable to find 555 or 565 texture support.\n");
01741                 return FALSE;
01742     }
01743 
01744         Main_BuildRGBGammaTables(1.0f);
01745         
01746         return TRUE;
01747 }

BOOL D3DMain_GetTextureMemory void   ) 
 

Definition at line 1829 of file D3D7xDrv/D3d_main.cpp.

01830 {
01831 
01832         DDSCAPS2                ddsCaps;
01833         DWORD                   dwTotal;
01834         DWORD                   dwFree;
01835         HRESULT                 Error;
01836 
01837         D3DMain_Log("--- D3DMain_GetTextureMemory ---\n");
01838 
01839         memset(&ddsCaps, 0, sizeof(ddsCaps));
01840 
01841         //ddsCaps.dwSize = sizeof(DDSCAPS2);
01842         ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM;
01843 
01844         Error = AppInfo.lpDD->GetAvailableVidMem(&ddsCaps, &dwTotal, &dwFree);
01845 
01846         if(Error !=DD_OK)
01847         {
01848                 D3DMain_Log("Getting DD capabilities failed while checking total video memory.\n  %s\n", D3DErrorToString(Error));
01849                 return FALSE;
01850         }
01851 
01852         AppInfo.VidMemFree = dwFree;
01853 
01854         D3DMain_Log("  Ram free: %i\n", AppInfo.VidMemFree);
01855 
01856         return TRUE;
01857 }

BOOL D3DMain_InitD3D HWND  hWnd,
const char *  DriverName,
int32  Width,
int32  Height
 

Definition at line 193 of file D3D7xDrv/D3d_main.cpp.

00194 {
00195         HRESULT                 LastError;
00196         SYSTEMTIME              Time;
00197 
00198         memset(&AppInfo, 0, sizeof(App_Info));
00199         
00200         GetSystemTime(&Time);
00201                 
00202         unlink(D3DMAIN_LOG_FILENAME);
00203 
00204         D3DMain_Log("=================================================================\n");
00205         D3DMain_Log(" D3DDrv v%i.%i\n", DRV_VERSION_MAJOR, DRV_VERSION_MINOR);
00206         D3DMain_Log(" Build Date: "__DATE__", Time: "__TIME__"\n");
00207         D3DMain_Log("=================================================================\n\n");
00208 
00209         D3DMain_Log("Current Time: %2i:%2i:%2i\n", Time.wHour, Time.wMinute, Time.wSecond);
00210         D3DMain_Log("Current Date: %2i-%2i-%4i\n", Time.wMonth, Time.wDay, Time.wYear);
00211         D3DMain_Log("\n ** D3D Driver Initializing **\n\n");
00212 
00213         AppInfo.hWnd = hWnd;
00214 
00215         // Create DD
00216         ATTEMPT(D3DMain_CreateDDFromName(DriverName));
00217         
00218         ATTEMPT(D3DMain_GetTextureMemory());
00219 
00220         // We must do this after the DD object is created!!!
00221         ATTEMPT(D3DMain_RememberOldMode(hWnd));         // Store old mode
00222 
00223         // Get available fullscreen display modes
00224         ATTEMPT(D3DMain_EnumDisplayModes());
00225 
00226         // Create D3D, and enum it's devices
00227         ATTEMPT(D3DMain_CreateD3D());
00228         ATTEMPT(D3DMain_EnumDevices());
00229 
00230         // start 32 bit changes
00231         // Open the config file and read the bpp variable
00232         stream = fopen("D3D24.ini","r");
00233         if(stream)
00234         {
00235                 fscanf(stream,"%d",&BPP32);
00236                 fscanf(stream,"%d",&ZbufferD);
00237                 fclose(stream);
00238         }
00239         else
00240         {
00241                 BPP32 = 16;
00242                 ZbufferD = 16;
00243         }
00244 
00245         // Set our global width and height to the real width and height
00246         gWidth = Width;
00247         gHeight = Height;
00248 
00249         if (Width == -1 && Height == -1)                // Window Mode
00250         {
00251                 // Force Width/Height to client window area size
00252                 Width = AppInfo.OldWindowWidth;
00253                 Height = AppInfo.OldWindowHeight;
00254                 
00255                 ATTEMPT(D3DMain_SetDisplayMode(hWnd, Width, Height, AppInfo.OldBpp, FALSE));
00256         }
00257         else
00258         {
00259                 ATTEMPT(D3DMain_SetDisplayMode(hWnd, Width, Height, BPP32, TRUE));
00260         }
00261 // end 32 bit changes
00262 
00263 
00264         // Pick a device we will be happy with
00265         ATTEMPT(D3DMain_PickDevice());
00266 
00267         // Create front/back buffer
00268         ATTEMPT(D3DMain_CreateBuffers());               
00269         
00270         // For some reason, we have to create the zbuffer BEFORE the device??? Why???
00271         ATTEMPT(D3DMain_CreateZBuffer());
00272 
00273         // Create the device and viewport
00274         ATTEMPT(D3DMain_CreateDevice());
00275         ATTEMPT(D3DMain_CreateViewPort(Width, Height));
00276 
00277         // Get the surface formats for textures, and 2d surfaces
00278         ATTEMPT(D3DMain_GetSurfaceFormats());
00279 
00280 #if 0           // For selective debugging
00281         AppInfo.CanDoMultiTexture = GE_FALSE;
00282 #else
00283         AppInfo.CanDoMultiTexture = (AppInfo.Drivers[AppInfo.CurrentDriver].MaxSimultaneousTextures > 1) ? GE_TRUE : GE_FALSE;
00284 #endif
00285 
00286         D3DMain_Log("--- D3DMain_SetRenderState --- \n");
00287     
00288         // Set some defaults render states
00289         LastError = AppInfo.lpD3DDevice->BeginScene();
00290 
00291         if (LastError != D3D_OK)
00292         {
00293                 D3DMain_Log("D3DMain_InitD3D:  BeginScene failed.\n  %s\n",
00294                         D3DErrorToString(LastError));
00295                 goto exit_with_error;
00296         }
00297 
00298 /*   07/16/2000 Wendell Buckner
00299 /*    Convert to Directx7...    
00300         LastError = AppInfo.lpD3DDevice->SetCurrentViewport(AppInfo.lpD3DViewport);*/
00301         LastError = AppInfo.lpD3DDevice->SetViewport(AppInfo.lpD3DViewport);
00302         
00303         
00304         if (LastError != D3D_OK)
00305         {
00306                 D3DMain_Log("D3DMain_InitD3D:  SetViewport failed.\n  %s\n",
00307                         D3DErrorToString(LastError));
00308                 goto exit_with_error;
00309         }
00310 
00311         //D3DMain_SetFogEnable(GE_TRUE, 255.0f, 0.0f, 0.0f, 500.0f, 1500.0f);
00312         D3DMain_SetFogEnable(GE_FALSE, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
00313 
00314 /* 02/28/2001 Wendell Buckner
00315         Lighting is on by default so turn it off...*/
00316     AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, FALSE);
00317 
00318 /*      02/08/2002 Wendell Buckner
00319     Optimization from GeForce_Optimization2.doc
00320     9.  Do not duplicate render state commands.  Worse is useless renderstates.  Do not set a renderstate unless it is needed. */
00321         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPING,FALSE);
00322         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_EXTENTS,FALSE); 
00323 
00324 /*      02/08/2002 Wendell Buckner
00325     Optimization from GeForce_Optimization2.doc
00326     Lights
00327     Apps should be sure to turn off per-vertex color material support when appropriate for increased performance.             */
00328         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_COLORVERTEX,FALSE); 
00329 
00330 /*      02/08/2002 Wendell Buckner
00331     Optimization from GeForce_Optimization2.doc
00332     Lights
00333         Also turning D3DRENDERSTATE_LOCALVIEWER to false saves transform cycles when exact specular highlights are not necessary.*/
00334     AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_LOCALVIEWER,FALSE); 
00335 
00336         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);
00337         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, D3DCMP_GREATEREQUAL);
00338 
00339         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_TEXTUREPERSPECTIVE, TRUE);
00340     AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_SPECULARENABLE, FALSE);
00341 
00342         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE);
00343 
00344 /* 12/06/2001 Wendell Buckner
00345     ENHANCEMENT - Allow full-scene anti-aliasing 
00346     if ( AppInfo.Drivers[AppInfo.CurrentDriver].Desc.dpcLineCaps.dwRasterCaps & D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT )
00347         {
00348          D3DMain_Log("sort independent anti-aliasing available");
00349      AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_ANTIALIAS,D3DANTIALIAS_SORTINDEPENDENT );
00350         }*/
00351 
00352 #if 0
00353         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_ANTIALIAS, D3DANTIALIAS_SORTINDEPENDENT);
00354         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_EDGEANTIALIAS, TRUE);
00355 #endif
00356         
00357         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_SHADEMODE, D3DSHADE_GOURAUD);
00358     AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
00359         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, TRUE);
00360 
00361         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_TEXTUREMIN, D3DFILTER_LINEARMIPNEAREST);
00362         AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_TEXTUREMAG, D3DFILTER_LINEAR);
00363 
00364         LastError = AppInfo.lpD3DDevice->EndScene();
00365 
00366         if (LastError != D3D_OK)
00367         {
00368                 D3DMain_Log("D3DMain_InitD3D:  EndScene failed.\n  %s\n",
00369                         D3DErrorToString(LastError));
00370                 goto exit_with_error;
00371         }
00372 
00373         AppInfo.RenderingIsOK = TRUE;
00374 
00375         ATTEMPT(D3DMain_ClearBuffers());
00376         ATTEMPT(D3DMain_GetTextureMemory());
00377 
00378         if (!THandle_Startup())
00379                 return GE_FALSE;
00380 
00381         D3DViewport (0, 0, Width, Height);
00382         D3DDepthRange (0.0f, 1.0f);
00383 
00384         D3DMain_Log("\n ** Initialization was successful **\n\n");
00385 
00386         return TRUE;
00387 
00388         exit_with_error:;
00389                 D3DMain_Log(" ** Initialization was NOT successful **\n");
00390                 D3DMain_ShutdownD3D();
00391                 return FALSE;
00392 }

void D3DMain_Log LPSTR  Str,
... 
 

Definition at line 473 of file D3D7xDrv/D3d_main.cpp.

00474 {
00475         char    Buffer[2048];
00476         FILE    *f;
00477 
00478         wvsprintf(Buffer, Str, (char*)(&Str+1));
00479 
00480         f = fopen(D3DMAIN_LOG_FILENAME, "a+t");
00481 
00482         if (!f)
00483                 return;
00484 
00485         fprintf(f, "%s", Buffer);
00486 
00487         fclose(f);
00488 }

geBoolean D3DMain_Reset void   ) 
 

Definition at line 457 of file D3D7xDrv/D3d_main.cpp.

00458 {
00459         THandle_Shutdown();
00460         PCache_Reset();
00461 
00462         if (!THandle_Startup())
00463                 return GE_FALSE;
00464 
00465         CurrentLRU = 0;
00466 
00467         return GE_TRUE;
00468 }

BOOL D3DMain_RestoreAllSurfaces void   ) 
 

Definition at line 124 of file D3D7xDrv/D3d_main.cpp.

00125 {
00126         HRESULT ddrval;
00127 
00128 #ifdef _DEBUG
00129         OutputDebugString("--- D3DMain_RestoreAllSurfaces ---\n");
00130 #endif
00131         
00132         if (AppInfo.lpDD)
00133         {
00134                 if (!D3DMain_SetDisplayMode(AppInfo.hWnd, AppInfo.CurrentWidth, AppInfo.CurrentHeight, AppInfo.CurrentBpp, AppInfo.FullScreen))
00135                         return FALSE;
00136 
00137                 // Restore all the surfaces
00138                 ddrval = AppInfo.lpDD->RestoreAllSurfaces();
00139 
00140                 if(ddrval!=DD_OK)
00141                 {
00142                         D3DMain_Log("D3DMain_RestoreAllSurfaces: AppInfo.lpDD->RestoreAllSurfaces() failed:\n  %s\n", D3DErrorToString(ddrval));
00143                         return  FALSE;
00144                 }
00145         }
00146 
00147         // Force an update in the cache system
00148         if (TextureCache)
00149                 if (!D3DCache_EvictAllSurfaces(TextureCache))
00150                         return FALSE;
00151 
00152         if (LMapCache)
00153                 if (!D3DCache_EvictAllSurfaces(LMapCache))
00154                         return FALSE;
00155 
00156         return TRUE;
00157 }

geBoolean DRIVERCC D3DMain_SetActive geBoolean  wParam  ) 
 

Definition at line 1969 of file D3D7xDrv/D3d_main.cpp.

01970 {
01971         if (AppInfo.lpFrontBuffer)
01972                 AppInfo.RenderingIsOK = wParam;
01973 
01974         if(AppInfo.RenderingIsOK)                                                       // Regaining focus
01975         {
01976                 HRESULT Result;
01977 
01978                 if (AppInfo.lpFrontBuffer)
01979                 {
01980                         Result = AppInfo.lpFrontBuffer->IsLost();
01981 
01982                         if(Result == DDERR_SURFACELOST)
01983                         {
01984                                 if(!D3DMain_RestoreAllSurfaces())
01985                                 {
01986                                         OutputDebugString("Couldn't restore surfaces!\n");
01987                                         return GE_FALSE;
01988                                 }
01989                                 
01990                                 OutputDebugString("D3DMain_SetActive: Regained Focus...\n");
01991                 
01992                                 ShowWindow(AppInfo.hWnd, SW_SHOWNORMAL);                // Dx doesn't restore it
01993                         }
01994                         else
01995                                 OutputDebugString("D3DMain_SetActive: No surfaces lost...\n");
01996                 }
01997         }
01998 
01999         return  GE_TRUE;
02000 }

geBoolean DRIVERCC D3DMain_SetFogEnable geBoolean  Enable,
geFloat  r,
geFloat  g,
geFloat  b,
geFloat  Start,
geFloat  End
 

Definition at line 1820 of file D3DDrv/D3d_main.cpp.

01821 {
01822         D3DMATERIAL                     Material;
01823 
01824         AppInfo.FogEnable = Enable;
01825         AppInfo.FogR = r;
01826         AppInfo.FogG = g;
01827         AppInfo.FogB = b;
01828         AppInfo.FogStart = Start;
01829         AppInfo.FogEnd = End;
01830 
01831         // Fill in the material with the data
01832         memset(&Material, 0, sizeof(D3DMATERIAL));
01833 
01834         Material.dwSize       = sizeof(D3DMATERIAL);
01835 
01836         if (Enable)
01837         {
01838                 Material.dcvDiffuse.r = Material.dcvAmbient.r = r/255.0f;
01839                 Material.dcvDiffuse.g = Material.dcvAmbient.g = g/255.0f;
01840                 Material.dcvDiffuse.b = Material.dcvAmbient.b = b/255.0f;
01841         }
01842         else
01843         {
01844                 Material.dcvDiffuse.r = Material.dcvAmbient.r = 0.0f;
01845                 Material.dcvDiffuse.g = Material.dcvAmbient.g = 0.0f;
01846                 Material.dcvDiffuse.b = Material.dcvAmbient.b = 0.0f;
01847         }
01848         
01849         Material.dwRampSize = 16L; // A default ramp size
01850 
01851         AppInfo.BackgroundMaterial->SetMaterial(&Material);
01852 
01853         return GE_TRUE;
01854 }

BOOL D3DMain_ShutdownD3D void   ) 
 

Definition at line 397 of file D3D7xDrv/D3d_main.cpp.

00398 {
00399         D3DMain_Log("\n--- D3DMain_ShutdownD3D ---\n");
00400 
00401         THandle_Shutdown();
00402 
00403         // Destroys all objects including Direct Draw.
00404         AppInfo.RenderingIsOK = FALSE;
00405 
00406         if (AppInfo.lpD3DViewport)
00407         {
00408                 assert(AppInfo.lpD3DDevice);
00409 
00410 /*  07/16/2000 Wendell Buckner
00411     Convert to Directx7...    
00412                 AppInfo.lpD3DDevice->DeleteViewport(AppInfo.lpD3DViewport); */
00413                 AppInfo.lpD3DDevice->Clear(0,0,0,0,0,0);
00414 
00415 //03/01/2002 Wendell Buckner    
00416 //This wasn't commented in the original code but it was in my genesis 1.0 converted code...
00417 //not sure I should do this.            
00418 //              RELEASE(AppInfo.lpD3DViewport);
00419         }
00420 
00421         RELEASE(AppInfo.lpD3DDevice);
00422 
00423 /* 03/09/2002 Wendell Buckner
00424    The BackgroundMaterial variable is a copy of lpD3Device, so don't release it just set it to NULL
00425         RELEASE(AppInfo.BackgroundMaterial);                                                            */
00426     AppInfo.BackgroundMaterial = NULL;                                                            
00427 
00428         if (AppInfo.lpZBuffer)
00429         {
00430                 assert(AppInfo.lpBackBuffer);
00431                 AppInfo.lpBackBuffer->DeleteAttachedSurface(0, AppInfo.lpZBuffer);
00432                 RELEASE(AppInfo.lpZBuffer);
00433         }
00434 
00435         if (AppInfo.lpFrontBuffer)
00436                 AppInfo.lpFrontBuffer->SetClipper(NULL);
00437 
00438         RELEASE(AppInfo.lpClipper);
00439         RELEASE(AppInfo.lpBackBuffer);
00440         RELEASE(AppInfo.lpFrontBuffer);
00441 
00442         D3DMain_RestoreDisplayMode();
00443 
00444         RELEASE(AppInfo.lpD3D);
00445         RELEASE(AppInfo.lpDD);
00446 
00447         memset(&AppInfo, 0, sizeof(App_Info));
00448 
00449         D3DMain_Log("  Shutdown was successful...\n\n");
00450 
00451         return TRUE;
00452 }

geBoolean DRIVERCC D3DMain_UpdateWindow void   ) 
 

Definition at line 1960 of file D3D7xDrv/D3d_main.cpp.

01961 {
01962         D3DMain_GetClientWindowOffset(AppInfo.hWnd);
01963         return GE_TRUE;
01964 }

void Main_BuildRGBGammaTables geFloat  Gamma  ) 
 

Definition at line 1677 of file D3DDrv/D3d_main.cpp.

01678 {
01679         int32                           i, Val;
01680         int32                           GammaTable[256];
01681         D3D_PixelMask   PixelMask;
01682         DWORD                   R_Left, G_Left, B_Left, A_Left;
01683         DWORD                   R_Right, G_Right, B_Right, A_Right;
01684         
01685 
01686         AppInfo.Gamma = Gamma;
01687 
01688         if (Gamma == 1.0)
01689         {
01690                 for (i=0 ; i<256 ; i++)
01691                         GammaTable[i] = i;
01692         }
01693         else for (i=0 ; i<256 ; i++)
01694         {
01695                 geFloat Ratio = (i+0.5f)/255.5f;
01696 
01697                 geFloat RGB = (geFloat)(255.0 * pow((double)Ratio, 1.0/(double)Gamma) + 0.5);
01698                 
01699                 if (RGB < 0.0f)
01700                         RGB = 0.0f;
01701                 if (RGB > 255.0f)
01702                         RGB = 255.0f;
01703 
01704                 GammaTable[i] = (int32)RGB;
01705         }
01706 
01707         GetSurfacePixelMask(&AppInfo.ddTexFormat, &PixelMask);
01708         for (i=0; i< 256; i++)
01709         {
01710                 // Get shift constants for current video mode/pixel format
01711                 R_Left = PixelMask.R_Shift;
01712                 G_Left = PixelMask.G_Shift;
01713                 B_Left = PixelMask.B_Shift;
01714                 A_Left = PixelMask.A_Shift;
01715 
01716                 R_Right = 8 - PixelMask.R_Width;
01717                 G_Right = 8 - PixelMask.G_Width;
01718                 B_Right = 8 - PixelMask.B_Width;
01719                 A_Right = 8 - PixelMask.A_Width;
01720 
01721                 Val = GammaTable[i];
01722 
01723                 AppInfo.Lut1.R[i] = (((uint32)Val >> R_Right) << R_Left) & PixelMask.R_Mask;
01724                 AppInfo.Lut1.G[i] = (((uint32)Val >> G_Right) << G_Left) & PixelMask.G_Mask;
01725                 AppInfo.Lut1.B[i] = (((uint32)Val >> B_Right) << B_Left) & PixelMask.B_Mask;
01726                 AppInfo.Lut1.A[i] = (((uint32)  i >> A_Right) << A_Left) & PixelMask.A_Mask;
01727         }
01728         GetSurfacePixelMask(&AppInfo.ddFourBitAlphaSurfFormat, &PixelMask);
01729         for (i=0; i< 256; i++)
01730         {
01731                 // Get shift constants for current video mode/pixel format
01732                 R_Left = PixelMask.R_Shift;
01733                 G_Left = PixelMask.G_Shift;
01734                 B_Left = PixelMask.B_Shift;
01735                 A_Left = PixelMask.A_Shift;
01736 
01737                 R_Right = 8 - PixelMask.R_Width;
01738                 G_Right = 8 - PixelMask.G_Width;
01739                 B_Right = 8 - PixelMask.B_Width;
01740                 A_Right = 8 - PixelMask.A_Width;
01741 
01742                 Val = GammaTable[i];
01743 
01744                 AppInfo.Lut2.R[i] = (((uint32)Val >> R_Right) << R_Left) & PixelMask.R_Mask;
01745                 AppInfo.Lut2.G[i] = (((uint32)Val >> G_Right) << G_Left) & PixelMask.G_Mask;
01746                 AppInfo.Lut2.B[i] = (((uint32)Val >> B_Right) << B_Left) & PixelMask.B_Mask;
01747                 AppInfo.Lut2.A[i] = (((uint32)  i >> A_Right) << A_Left) & PixelMask.A_Mask;
01748         }
01749         GetSurfacePixelMask(&AppInfo.ddOneBitAlphaSurfFormat, &PixelMask);
01750         for (i=0; i< 256; i++)
01751         {
01752                 // Get shift constants for current video mode/pixel format
01753                 R_Left = PixelMask.R_Shift;
01754                 G_Left = PixelMask.G_Shift;
01755                 B_Left = PixelMask.B_Shift;
01756                 A_Left = PixelMask.A_Shift;
01757 
01758                 R_Right = 8 - PixelMask.R_Width;
01759                 G_Right = 8 - PixelMask.G_Width;
01760                 B_Right = 8 - PixelMask.B_Width;
01761                 A_Right = 8 - PixelMask.A_Width;
01762 
01763                 Val = GammaTable[i];
01764 
01765                 AppInfo.Lut3.R[i] = (((uint32)Val >> R_Right) << R_Left) & PixelMask.R_Mask;
01766                 AppInfo.Lut3.G[i] = (((uint32)Val >> G_Right) << G_Left) & PixelMask.G_Mask;
01767                 AppInfo.Lut3.B[i] = (((uint32)Val >> B_Right) << B_Left) & PixelMask.B_Mask;
01768                 AppInfo.Lut3.A[i] = (((uint32)  i >> A_Right) << A_Left) & PixelMask.A_Mask;
01769         }
01770 }

BOOL Main_CheckDD void   ) 
 

Definition at line 1753 of file D3D7xDrv/D3d_main.cpp.

01754 {
01755         AppInfo.NumDrivers = 0;
01756         AppInfo.CurrentDriver = 0;
01757         AppInfo.FoundGoodDevice = FALSE;
01758         AppInfo.CanDoWindow = FALSE;
01759 
01760         assert(AppInfo.lpDD);
01761         
01762         if (!D3DMain_RememberOldMode(GetDesktopWindow()))
01763                 return FALSE;
01764 
01765         memset(AppInfo.Drivers, 0, sizeof(DDMain_D3DDriver)*DDMAIN_MAX_D3D_DRIVERS);
01766 
01767         if (!D3DMain_CreateD3D())
01768                 return FALSE;
01769 
01770         if (!D3DMain_EnumDevices())                     // See if we can enumerate at least one good device for this DD Driver
01771                 return FALSE;
01772 
01773         if (!AppInfo.FoundGoodDevice)           // Return FALSE if not...
01774                 return FALSE;
01775 
01776         return TRUE;    // Found at least one!!!
01777 }

BOOL Main_ClearBackBuffer BOOL  Clear,
BOOL  ClearZ
 

Definition at line 1407 of file D3D7xDrv/D3d_main.cpp.

01408 {
01409     int                 ClearFlags;
01410     D3DRECT             Dummy;
01411         HRESULT         LastError;
01412 
01413         if (!AppInfo.RenderingIsOK) 
01414                 return TRUE;
01415         
01416     // Default to clear nothing
01417         ClearFlags = 0;
01418 
01419         // Then set in what callers wants to clear
01420         if (Clear)
01421                 ClearFlags |= D3DCLEAR_TARGET;
01422         
01423         if (ClearZ)
01424                 ClearFlags |= D3DCLEAR_ZBUFFER;
01425 
01426     Dummy.x1 = Dummy.y1 = 0;
01427     Dummy.x2 = AppInfo.CurrentWidth;
01428     Dummy.y2 = AppInfo.CurrentHeight;
01429  
01430 /* 07/16/2000 Wendell Buckner
01431     Convert to Directx7...    /
01432     LastError = AppInfo.lpD3DViewport->Clear(1, &Dummy, ClearFlags);
01433 
01434     POTENTIAL GOTCHA 
01435     Need to understand this value => 1.0f better, the original code above has it set to 0 but my
01436     sample code won't work with this value set to 0     */
01437         LastError = AppInfo.lpD3DDevice->Clear( 1, &Dummy, ClearFlags,  0,  1.0f, 0L ); 
01438         
01439     
01440         if (LastError != D3D_OK) 
01441         {
01442                 D3DMain_Log("Viewport clear failed.\n  %s\n",
01443                         D3DErrorToString(LastError));
01444                 return FALSE;
01445         }
01446 
01447         return TRUE;
01448 }

BOOL Main_EnumTextureFormats void   ) 
 

Definition at line 1065 of file D3D7xDrv/D3d_main.cpp.

01066 {
01067         HRESULT LastError;
01068 
01069         assert(AppInfo.lpD3DDevice);
01070 
01071         AppInfo.NumTextureFormats = 0;
01072 
01073         LastError = AppInfo.lpD3DDevice->EnumTextureFormats(EnumTextureFormatsCallback, NULL);
01074         
01075         if (LastError != DD_OK) 
01076         {
01077                 D3DMain_Log("Main_EnumTextureFormats:  Enumeration of texture formats failed.\n  %s\n",
01078                         D3DErrorToString(LastError));
01079                 return FALSE;
01080         }
01081 
01082         return TRUE;
01083 }

BOOL Main_ShowBackBuffer void   ) 
 

Definition at line 1316 of file D3D7xDrv/D3d_main.cpp.

01317 {
01318         HRESULT         LastError;
01319 
01320         if (!AppInfo.RenderingIsOK) 
01321                 return TRUE;
01322   
01323         if (AppInfo.FullScreen) 
01324         {  
01325                 // Flip the back and front buffers
01326                 #if 1
01327 
01328 /*      01/24/2002 Wendell Buckner
01329     Change flags for speed...           
01330                         LastError = AppInfo.lpFrontBuffer->Flip(AppInfo.lpBackBuffer, DDFLIP_WAIT);*/
01331                         LastError = AppInfo.lpFrontBuffer->Flip(AppInfo.lpBackBuffer, DDFLIP_DONOTWAIT | DDFLIP_NOVSYNC);
01332 
01333                 #else
01334 /*      01/24/2002 Wendell Buckner
01335     Change flags for speed...           
01336                         LastError = AppInfo.lpFrontBuffer->Flip(AppInfo.lpBackBuffer, DDFLIP_NOVSYNC);*/
01337                         LastError = AppInfo.lpFrontBuffer->Flip(AppInfo.lpBackBuffer, DDFLIP_DONOTWAIT | DDFLIP_NOVSYNC);
01338                 #endif
01339                 
01340                 if (LastError == DDERR_SURFACELOST) 
01341                 {
01342                         D3DMain_RestoreAllSurfaces();
01343                         //AppInfo.lpFrontBuffer->Restore();
01344                         //AppInfo.lpBackBuffer->Restore();
01345                         
01346                         D3DMain_ClearBuffers();
01347 
01348                 } 
01349                 else if (LastError == DDERR_WASSTILLDRAWING)
01350                 {
01351                 }
01352                 else if (LastError != DD_OK) 
01353                 {
01354                         D3DMain_Log("Flipping complex display surface failed.\n  %s\n", D3DErrorToString(LastError));
01355                         return FALSE;
01356                 }
01357         } 
01358         else 
01359         {
01360                 RECT    FRect, BRect;
01361 
01362                 FRect.left = AppInfo.WindowXOffset;
01363                 FRect.right = FRect.left + AppInfo.CurrentWidth;
01364                 FRect.top = AppInfo.WindowYOffset;
01365                 FRect.bottom = FRect.top + AppInfo.CurrentHeight;
01366 
01367                 BRect.left = 0;
01368                 BRect.right = AppInfo.CurrentWidth;
01369                 BRect.top = 0;
01370                 BRect.bottom = AppInfo.CurrentHeight;
01371 
01372 /*  03/10/2002 Wendell Buckner
01373      Optimization from GeForce_Optimization2.doc                                        
01374      Procedural Textures
01375      Also, Load is even faster than BLT under Dx7.
01376  *      01/24/2002 Wendell Buckner
01377      Change flags for speed...
01378                 LastError = AppInfo.lpFrontBuffer->Blt(&FRect, AppInfo.lpBackBuffer,
01379                                 &BRect, DDBLT_WAIT, NULL);                                   */
01380                 LastError = AppInfo.lpFrontBuffer->Blt(&FRect, AppInfo.lpBackBuffer,
01381                                 &BRect, DDBLT_DONOTWAIT | DDBLT_ASYNC, NULL);                
01382   
01383                 if (LastError != DD_OK) 
01384                 {
01385                         if(LastError==DDERR_SURFACELOST)
01386                         {
01387                                 if (!D3DMain_RestoreAllSurfaces())
01388                                 {
01389                                         D3DMain_Log("Main_ShowBackBuffer:  D3DMain_RestoreAllSurfaces.\n");
01390                                         return FALSE;
01391                                 }
01392                         }
01393                         else
01394                         {
01395                                 D3DMain_Log("Main_ShowBackBuffer:  Blt of back buffer to front buffer failed.\n  %s\n", D3DErrorToString(LastError));
01396                                 return FALSE;
01397                         }
01398                 }
01399         }
01400 
01401         return TRUE;
01402 }


Variable Documentation

App_Info AppInfo
 

Definition at line 200 of file D3DDrv/D3d_main.h.


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