00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 #include "wdxGraphicsPipe8.h"
00020 #include "wdxGraphicsWindow8.h"
00021 #include "config_dxgsg8.h"
00022 
00023 TypeHandle wdxGraphicsPipe8::_type_handle;
00024 
00025 
00026 #define LOWVIDMEMTHRESHOLD 5700000  // 4MB cards should fall below this
00027 #define CRAPPY_DRIVER_IS_LYING_VIDMEMTHRESHOLD 1000000  // if # is > 1MB, card is lying and I cant tell what it is
00028 #define UNKNOWN_VIDMEM_SIZE 0xFFFFFFFF
00029 
00030 
00031 
00032 
00033 
00034 
00035 wdxGraphicsPipe8::
00036 wdxGraphicsPipe8() {
00037   _hDDrawDLL = NULL;
00038   _hD3D8_DLL = NULL;
00039   _pD3D8 = NULL;
00040   _is_valid = init();
00041 }
00042 
00043 
00044 
00045 
00046 
00047 
00048 wdxGraphicsPipe8::
00049 ~wdxGraphicsPipe8() {
00050 
00051   RELEASE(_pD3D8,wdxdisplay8,"ID3D8",RELEASE_DOWN_TO_ZERO);
00052   SAFE_FREELIB(_hD3D8_DLL);
00053   SAFE_FREELIB(_hDDrawDLL);
00054 }
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 string wdxGraphicsPipe8::
00067 get_interface_name() const {
00068   return "DirectX8";
00069 }
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 PT(GraphicsPipe) wdxGraphicsPipe8::
00079 pipe_constructor() {
00080   return new wdxGraphicsPipe8;
00081 }
00082 
00083 
00084 
00085 
00086 
00087 
00088 PT(GraphicsWindow) wdxGraphicsPipe8::
00089 make_window(GraphicsStateGuardian *gsg) {
00090   if (!_is_valid) {
00091     return NULL;
00092   }
00093 
00094   
00095   
00096   return new wdxGraphicsWindow8(this, gsg);
00097 }
00098 
00099 
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 bool wdxGraphicsPipe8::
00109 init() {
00110   if(!MyLoadLib(_hDDrawDLL,"ddraw.dll")) {
00111       goto error;
00112   }
00113 
00114   if(!MyGetProcAddr(_hDDrawDLL, (FARPROC*)&_DirectDrawCreateEx, "DirectDrawCreateEx")) {
00115       goto error;
00116   }
00117 
00118   if(!MyGetProcAddr(_hDDrawDLL, (FARPROC*)&_DirectDrawEnumerateExA, "DirectDrawEnumerateExA")) {
00119       goto error;
00120   }
00121 
00122   if(!MyLoadLib(_hD3D8_DLL,"d3d8.dll")) {
00123       goto error;
00124   }
00125 
00126   if(!MyGetProcAddr(_hD3D8_DLL, (FARPROC*)&_Direct3DCreate8, "Direct3DCreate8")) {
00127       goto error;
00128   }
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 
00137 
00138 
00139 
00140 
00141   
00142 
00143   
00144   #define D3D_SDK_VERSION_8_0  120
00145   #define D3D_SDK_VERSION_8_1  220
00146 
00147   
00148   WIN32_FIND_DATA TempFindData;
00149   HANDLE hFind;
00150   char tmppath[_MAX_PATH + 128];
00151   GetSystemDirectory(tmppath, MAX_PATH);
00152   strcat(tmppath, "\\dpnhpast.dll");
00153   hFind = FindFirstFile (tmppath, &TempFindData);
00154   if (hFind != INVALID_HANDLE_VALUE) {
00155     FindClose(hFind);
00156     _bIsDX81 = true;
00157     _pD3D8 = (*_Direct3DCreate8)(D3D_SDK_VERSION_8_1);
00158   } else {
00159     _bIsDX81 = false;
00160     _pD3D8 = (*_Direct3DCreate8)(D3D_SDK_VERSION_8_0);
00161   }
00162 
00163   if (_pD3D8 == NULL) {
00164     wdxdisplay8_cat.error() << "Direct3DCreate8(8." << (_bIsDX81 ? "1" : "0") << ") failed!, error=" << GetLastError() << endl;
00165     
00166     goto error;
00167   }
00168 
00169   Init_D3DFORMAT_map();
00170 
00171   return find_all_card_memavails();
00172 
00173   error:
00174     
00175     return false;
00176 }
00177 
00178 
00179 
00180 
00181 
00182 
00183 
00184 
00185 bool wdxGraphicsPipe8::
00186 find_all_card_memavails() {
00187   HRESULT hr;
00188 
00189   hr = (*_DirectDrawEnumerateExA)(dx7_driver_enum_callback, this, 
00190                                   DDENUM_ATTACHEDSECONDARYDEVICES | DDENUM_NONDISPLAYDEVICES);
00191   if (FAILED(hr)) {
00192     wdxdisplay8_cat.fatal()
00193       << "DirectDrawEnumerateEx failed" << D3DERRORSTRING(hr);
00194     return false;
00195   }
00196 
00197   if (_card_ids.empty()) {
00198     wdxdisplay8_cat.error()
00199       << "DirectDrawEnumerateEx enum'ed no devices!\n";
00200     return false;
00201   }
00202 
00203   GUID ZeroGUID;
00204   ZeroMemory(&ZeroGUID, sizeof(GUID));
00205 
00206   if (_card_ids.size() > 1) {
00207     assert(IsEqualGUID(ZeroGUID, _card_ids[0].DX7_DeviceGUID));
00208     
00209     
00210     _card_ids.erase(_card_ids.begin());
00211   }
00212 
00213   for (UINT i=0; i < _card_ids.size(); i++) {
00214     LPDIRECTDRAW7 pDD;
00215     BYTE ddd_space[sizeof(DDDEVICEIDENTIFIER2)+4];  
00216     DDDEVICEIDENTIFIER2 *pDX7DeviceID=(DDDEVICEIDENTIFIER2 *)&ddd_space[0];
00217     GUID *pGUID= &(_card_ids[i].DX7_DeviceGUID);
00218 
00219     if (IsEqualGUID(*pGUID, ZeroGUID)) {
00220       pGUID=NULL;
00221     }
00222 
00223     
00224     hr = (*_DirectDrawCreateEx)(pGUID,(void **)&pDD, IID_IDirectDraw7, NULL);
00225     if (FAILED(hr)) {
00226       wdxdisplay8_cat.error()
00227         << "DirectDrawCreateEx failed for device (" << i
00228         << ")" << D3DERRORSTRING(hr);
00229       continue;
00230     }
00231 
00232     ZeroMemory(ddd_space, sizeof(DDDEVICEIDENTIFIER2));
00233 
00234     hr = pDD->GetDeviceIdentifier(pDX7DeviceID, 0x0);
00235     if (FAILED(hr)) {
00236       wdxdisplay8_cat.error()
00237         << "GetDeviceID failed for device ("<< i << ")" << D3DERRORSTRING(hr);
00238       continue;
00239     }
00240 
00241     _card_ids[i].DeviceID = pDX7DeviceID->dwDeviceId;
00242     _card_ids[i].VendorID = pDX7DeviceID->dwVendorId;
00243 
00244     
00245     
00246     
00247     
00248     
00249     DDSCAPS2 ddsGAVMCaps;
00250     DWORD dwVidMemTotal,dwVidMemFree;
00251     dwVidMemTotal=dwVidMemFree=0;
00252     {
00253       
00254       
00255       
00256       
00257       ZeroMemory(&ddsGAVMCaps, sizeof(DDSCAPS2));
00258       ddsGAVMCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
00259 
00260       hr = pDD->GetAvailableVidMem(&ddsGAVMCaps, &dwVidMemTotal, &dwVidMemFree);
00261       if (FAILED(hr)) {
00262         wdxdisplay8_cat.error()
00263           << "GetAvailableVidMem failed for device #" << i 
00264           << D3DERRORSTRING(hr);
00265         
00266         exit(1);  
00267       }
00268     }
00269 
00270     wdxdisplay8_cat.info()
00271       << "GetAvailableVidMem (including AGP) returns Total: "
00272       << dwVidMemTotal <<", Free: " << dwVidMemFree
00273       << " for device #" << i << endl;
00274 
00275     ZeroMemory(&ddsGAVMCaps, sizeof(DDSCAPS2));
00276 
00277     
00278     ddsGAVMCaps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM;
00279 
00280     hr = pDD->GetAvailableVidMem(&ddsGAVMCaps, &dwVidMemTotal, &dwVidMemFree);
00281     if (FAILED(hr)) {
00282       wdxdisplay8_cat.error() << "GetAvailableVidMem failed for device #"<< i<< D3DERRORSTRING(hr);
00283       
00284       
00285       if(hr==DDERR_NODIRECTDRAWHW)
00286           continue;
00287       exit(1);  
00288     }
00289 
00290     wdxdisplay8_cat.info()
00291       << "GetAvailableVidMem (no AGP) returns Total: " << dwVidMemTotal
00292       << ", Free: " << dwVidMemFree << " for device #"<< i<< endl;
00293 
00294     pDD->Release();  
00295 
00296     if (!dx_do_vidmemsize_check) {
00297       
00298       _card_ids[i].MaxAvailVidMem = UNKNOWN_VIDMEM_SIZE;
00299       _card_ids[i].bIsLowVidMemCard = false;
00300       continue;
00301     }
00302 
00303     if (dwVidMemTotal == 0) {  
00304       dwVidMemTotal = UNKNOWN_VIDMEM_SIZE;
00305     } else {
00306       if (!ISPOW2(dwVidMemTotal)) {
00307         
00308         
00309         UINT count=0;
00310         while ((dwVidMemTotal >> count) != 0x0) {
00311           count++;
00312         }
00313         dwVidMemTotal = (1 << count);
00314       }
00315     }
00316 
00317     
00318     
00319     
00320     
00321     _card_ids[i].MaxAvailVidMem = dwVidMemTotal;
00322 
00323     
00324     
00325     
00326     
00327     
00328 
00329     
00330     
00331     bool bLowVidMemFlag = 
00332       ((dwVidMemTotal > CRAPPY_DRIVER_IS_LYING_VIDMEMTHRESHOLD) && 
00333        (dwVidMemTotal< LOWVIDMEMTHRESHOLD));
00334 
00335     _card_ids[i].bIsLowVidMemCard = bLowVidMemFlag;
00336     wdxdisplay8_cat.info() 
00337       << "SetLowVidMem flag to " << bLowVidMemFlag
00338       << " based on adjusted VidMemTotal: " << dwVidMemTotal << endl;
00339   }
00340   return true;
00341 }
00342 
00343 
00344 
00345 
00346 
00347 
00348 BOOL WINAPI wdxGraphicsPipe8::
00349 dx7_driver_enum_callback(GUID *pGUID, TCHAR *strDesc, TCHAR *strName,
00350                          VOID *argptr, HMONITOR hm) {
00351   
00352   
00353   wdxGraphicsPipe8 *self = (wdxGraphicsPipe8 *)argptr;
00354 
00355   CardID card_id;
00356   ZeroMemory(&card_id, sizeof(CardID));
00357 
00358   if (hm == NULL) {
00359     card_id.hMon = MonitorFromWindow(GetDesktopWindow(), 
00360                                      MONITOR_DEFAULTTOPRIMARY);
00361   } else {
00362     card_id.hMon = hm;
00363   }
00364 
00365   if (pGUID != NULL) {
00366     memcpy(&card_id.DX7_DeviceGUID, pGUID, sizeof(GUID));
00367   }
00368 
00369   card_id.MaxAvailVidMem = UNKNOWN_VIDMEM_SIZE;
00370 
00371   self->_card_ids.push_back(card_id);
00372 
00373   return DDENUMRET_OK;
00374 }
00375 
00376 
00377 
00378 
00379 
00380 
00381 bool wdxGraphicsPipe8::
00382 find_best_depth_format(DXScreenData &Display, D3DDISPLAYMODE &TestDisplayMode,
00383                        D3DFORMAT *pBestFmt, bool bWantStencil,
00384                        bool bForce16bpp, bool bVerboseMode) const {
00385   
00386 #define NUM_TEST_ZFMTS 3
00387   static D3DFORMAT NoStencilPrefList[NUM_TEST_ZFMTS]={D3DFMT_D32,D3DFMT_D24X8,D3DFMT_D16};
00388   static D3DFORMAT StencilPrefList[NUM_TEST_ZFMTS]={D3DFMT_D24S8,D3DFMT_D24X4S4,D3DFMT_D15S1};
00389 
00390   
00391 
00392   
00393   
00394 
00395   *pBestFmt = D3DFMT_UNKNOWN;
00396   HRESULT hr;
00397 
00398     
00399   bool bOnlySelect16bpp = (bForce16bpp ||
00400                            (IS_NVIDIA(Display.DXDeviceID) && IS_16BPP_DISPLAY_FORMAT(TestDisplayMode.Format)));
00401 
00402   if (bVerboseMode) {
00403     wdxdisplay8_cat.info()
00404       << "FindBestDepthFmt: bSelectOnly16bpp: " << bOnlySelect16bpp << endl;
00405   }
00406 
00407   for (int i=0; i < NUM_TEST_ZFMTS; i++) {
00408     D3DFORMAT TestDepthFmt = 
00409       (bWantStencil ? StencilPrefList[i] : NoStencilPrefList[i]);
00410 
00411     if (bOnlySelect16bpp && !IS_16BPP_ZBUFFER(TestDepthFmt)) {
00412       continue;
00413     }
00414 
00415     hr = Display.pD3D8->CheckDeviceFormat(Display.CardIDNum,
00416                                           D3DDEVTYPE_HAL,
00417                                           TestDisplayMode.Format,
00418                                           D3DUSAGE_DEPTHSTENCIL,
00419                                           D3DRTYPE_SURFACE,TestDepthFmt);
00420 
00421     if (FAILED(hr)) {
00422       if (hr == D3DERR_NOTAVAILABLE) {
00423         if (bVerboseMode)
00424           wdxdisplay8_cat.info() 
00425             << "FindBestDepthFmt: ChkDevFmt returns NotAvail for " 
00426             << D3DFormatStr(TestDepthFmt) << endl;
00427         continue;
00428       }
00429 
00430       wdxdisplay8_cat.error()
00431         << "unexpected CheckDeviceFormat failure" << D3DERRORSTRING(hr) 
00432         << endl;
00433       exit(1);
00434     }
00435 
00436     hr = Display.pD3D8->CheckDepthStencilMatch(Display.CardIDNum,
00437                                                D3DDEVTYPE_HAL,
00438                                                TestDisplayMode.Format,   
00439                                                TestDisplayMode.Format,   
00440                                                TestDepthFmt);
00441     if (SUCCEEDED(hr)) {
00442       *pBestFmt = TestDepthFmt;
00443       break;
00444     } else {
00445       if (hr==D3DERR_NOTAVAILABLE) {
00446         if (bVerboseMode) {
00447           wdxdisplay8_cat.info()
00448             << "FindBestDepthFmt: ChkDepMatch returns NotAvail for "
00449             << D3DFormatStr(TestDisplayMode.Format) << ", " 
00450             << D3DFormatStr(TestDepthFmt) << endl;
00451         }
00452       } else {
00453         wdxdisplay8_cat.error()
00454           << "unexpected CheckDepthStencilMatch failure for "
00455           << D3DFormatStr(TestDisplayMode.Format) << ", " 
00456           << D3DFormatStr(TestDepthFmt) << endl;
00457         exit(1);
00458       }
00459     }
00460   }
00461 
00462   if (bVerboseMode) {
00463     wdxdisplay8_cat.info()
00464       << "FindBestDepthFmt returns fmt " << D3DFormatStr(*pBestFmt) << endl;
00465   }
00466 
00467   return (*pBestFmt != D3DFMT_UNKNOWN);
00468 }
00469 
00470 
00471 
00472 
00473 
00474 
00475 
00476 
00477 bool wdxGraphicsPipe8::
00478 special_check_fullscreen_resolution(DXScreenData &scrn,UINT x_size,UINT y_size) {
00479   DWORD VendorId = scrn.DXDeviceID.VendorId;
00480   DWORD DeviceId = scrn.DXDeviceID.DeviceId;
00481 
00482   switch (VendorId) {
00483       case 0x8086:  
00484         
00485 
00486 
00487 
00488 
00489 
00490         if ((x_size == 640) && (y_size == 480)) {
00491           return true;
00492         }
00493         if ((x_size == 800) && (y_size == 600)) {
00494           return true;
00495         }
00496         if ((x_size == 1024) && (y_size == 768)) {
00497           return true;
00498         }
00499         break;
00500   }
00501 
00502   return false;
00503 }
00504 
00505 
00506 
00507 
00508 
00509 
00510 
00511 void wdxGraphicsPipe8::
00512 search_for_valid_displaymode(DXScreenData &scrn,
00513                              UINT RequestedX_Size, UINT RequestedY_Size,
00514                              bool bWantZBuffer, bool bWantStencil,
00515                              UINT *pSupportedScreenDepthsMask,
00516                              bool *pCouldntFindAnyValidZBuf,
00517                              D3DFORMAT *pSuggestedPixFmt,
00518                              bool bForce16bppZBuffer,
00519                              bool bVerboseMode) {
00520 
00521   assert(IS_VALID_PTR(scrn.pD3D8));
00522   HRESULT hr;
00523 
00524 #ifndef NDEBUG
00525   
00526   
00527   
00528 #endif
00529 
00530   *pSuggestedPixFmt = D3DFMT_UNKNOWN;
00531   *pSupportedScreenDepthsMask = 0x0;
00532   *pCouldntFindAnyValidZBuf = false;
00533 
00534   int cNumModes = scrn.pD3D8->GetAdapterModeCount(scrn.CardIDNum);
00535   D3DDISPLAYMODE BestDispMode;
00536   ZeroMemory(&BestDispMode,sizeof(BestDispMode));
00537 
00538   if (bVerboseMode) {
00539     wdxdisplay8_cat.info()
00540       << "searching for valid display modes at res: ("
00541       << RequestedX_Size << "," << RequestedY_Size
00542       << "), TotalModes: " << cNumModes << endl;
00543   }
00544 
00545   
00546   
00547   
00548   bool bDoMemBasedChecks = 
00549     ((!((RequestedX_Size==640)&&(RequestedY_Size==480))) &&
00550      (scrn.MaxAvailVidMem!=UNKNOWN_VIDMEM_SIZE) &&
00551      (!special_check_fullscreen_resolution(scrn,RequestedX_Size,RequestedY_Size)));
00552 
00553   if (bVerboseMode || wdxdisplay8_cat.is_spam()) {
00554     wdxdisplay8_cat.info()
00555       << "DoMemBasedChecks = " << bDoMemBasedChecks << endl;
00556   }
00557 
00558   for (int i=0; i < cNumModes; i++) {
00559     D3DDISPLAYMODE dispmode;
00560     hr = scrn.pD3D8->EnumAdapterModes(scrn.CardIDNum,i,&dispmode);
00561     if (FAILED(hr)) {
00562       wdxdisplay8_cat.error()
00563         << "EnumAdapterDisplayMode failed for device #"
00564         << scrn.CardIDNum << D3DERRORSTRING(hr);
00565       exit(1);
00566     }
00567 
00568     if ((dispmode.Width!=RequestedX_Size) ||
00569         (dispmode.Height!=RequestedY_Size)) {
00570       continue;
00571     }
00572 
00573     if ((dispmode.RefreshRate<60) && (dispmode.RefreshRate>1)) {
00574       
00575       
00576       if (bVerboseMode) {
00577         wdxdisplay8_cat.info()
00578           << "skipping mode[" << i << "], bad refresh rate: " 
00579           << dispmode.RefreshRate << endl;
00580       }
00581       continue;
00582     }
00583 
00584     
00585     
00586     
00587 
00588     hr = scrn.pD3D8->CheckDeviceFormat(scrn.CardIDNum, D3DDEVTYPE_HAL, dispmode.Format,
00589                                                D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE,
00590                                                dispmode.Format);
00591     if (FAILED(hr)) {
00592       if (hr==D3DERR_NOTAVAILABLE) {
00593         if (bVerboseMode) {
00594           wdxdisplay8_cat.info()
00595             << "skipping mode[" << i 
00596             << "], CheckDevFmt returns NotAvail for fmt: "
00597             << D3DFormatStr(dispmode.Format) << endl;
00598         }
00599         continue;
00600       } else {
00601         wdxdisplay8_cat.error()
00602           << "CheckDeviceFormat failed for device #" 
00603           << scrn.CardIDNum << D3DERRORSTRING(hr);
00604         exit(1);
00605       }
00606     }
00607 
00608     bool bIs16bppRenderTgt = IS_16BPP_DISPLAY_FORMAT(dispmode.Format);
00609     float RendTgtMinMemReqmt;
00610 
00611     
00612     
00613     if (bDoMemBasedChecks) {
00614       
00615       
00616       
00617 
00618       
00619       
00620 
00621 #define REQD_TEXMEM 1800000
00622 
00623       float bytes_per_pixel = (bIs16bppRenderTgt ? 2 : 4);
00624       
00625 
00626 
00627 
00628       
00629 
00630       RendTgtMinMemReqmt = 
00631         ((float)RequestedX_Size) * ((float)RequestedY_Size) * 
00632         bytes_per_pixel * 2 + REQD_TEXMEM;
00633 
00634       if (bVerboseMode || wdxdisplay8_cat.is_spam())
00635         wdxdisplay8_cat.info()
00636           << "Testing Mode (" <<RequestedX_Size<<"x" << RequestedY_Size 
00637           << "," << D3DFormatStr(dispmode.Format) << ")\nReqdVidMem: "
00638           << (int)RendTgtMinMemReqmt << " AvailVidMem: " 
00639           << scrn.MaxAvailVidMem << endl;
00640 
00641       if (RendTgtMinMemReqmt > scrn.MaxAvailVidMem) {
00642         if (bVerboseMode || wdxdisplay8_cat.is_debug())
00643           wdxdisplay8_cat.info()
00644             << "not enough VidMem for render tgt, skipping display fmt "
00645             << D3DFormatStr(dispmode.Format) << " (" 
00646             << (int)RendTgtMinMemReqmt << " > " 
00647             << scrn.MaxAvailVidMem << ")\n";
00648         continue;
00649       }
00650     }
00651 
00652     if (bWantZBuffer) {
00653       D3DFORMAT zformat;
00654       if (!find_best_depth_format(scrn,dispmode, &zformat,
00655                                   bWantStencil, bForce16bppZBuffer)) {
00656         *pCouldntFindAnyValidZBuf=true;
00657         continue;
00658       }
00659 
00660       float MinMemReqmt = 0.0f;
00661 
00662       if (bDoMemBasedChecks) {
00663         
00664         float zbytes_per_pixel = (IS_16BPP_ZBUFFER(zformat) ? 2 : 4);
00665         float MinMemReqmt = RendTgtMinMemReqmt + ((float)RequestedX_Size)*((float)RequestedY_Size)*zbytes_per_pixel;
00666 
00667         if (bVerboseMode || wdxdisplay8_cat.is_spam())
00668           wdxdisplay8_cat.info()
00669             << "Testing Mode w/Z (" << RequestedX_Size << "x"
00670             << RequestedY_Size << "," << D3DFormatStr(dispmode.Format)
00671             << ")\nReqdVidMem: "<< (int)MinMemReqmt << " AvailVidMem: " 
00672             << scrn.MaxAvailVidMem << endl;
00673 
00674         if (MinMemReqmt > scrn.MaxAvailVidMem) {
00675           if (bVerboseMode || wdxdisplay8_cat.is_debug())
00676             wdxdisplay8_cat.info()
00677               << "not enough VidMem for RendTgt+zbuf, skipping display fmt "
00678               << D3DFormatStr(dispmode.Format) << " (" << (int)MinMemReqmt
00679               << " > " << scrn.MaxAvailVidMem << ")\n";
00680           continue;
00681         }
00682       }
00683 
00684       if ((!bDoMemBasedChecks) || (MinMemReqmt<scrn.MaxAvailVidMem)) {
00685         if (!IS_16BPP_ZBUFFER(zformat)) {
00686           
00687 
00688           if (!find_best_depth_format(scrn, dispmode, &zformat, 
00689                                       bWantStencil, true, bVerboseMode)) {
00690             if (bVerboseMode)
00691               wdxdisplay8_cat.info()
00692                 << "FindBestDepthFmt rejected Mode[" << i << "] (" 
00693                 << RequestedX_Size << "x" << RequestedY_Size 
00694                 << "," << D3DFormatStr(dispmode.Format) << endl;
00695             *pCouldntFindAnyValidZBuf=true;
00696             continue;
00697           }
00698           
00699           
00700           
00701           *pSupportedScreenDepthsMask |= 
00702             (IS_16BPP_DISPLAY_FORMAT(dispmode.Format) ? DISPLAY_16BPP_REQUIRES_16BPP_ZBUFFER_FLAG : DISPLAY_32BPP_REQUIRES_16BPP_ZBUFFER_FLAG);
00703         }
00704       }
00705     }
00706 
00707     if (bVerboseMode || wdxdisplay8_cat.is_spam())
00708       wdxdisplay8_cat.info()
00709         << "Validated Mode (" << RequestedX_Size << "x" 
00710         << RequestedY_Size << "," << D3DFormatStr(dispmode.Format) << endl;
00711 
00712     switch (dispmode.Format) {
00713     case D3DFMT_X1R5G5B5:
00714       *pSupportedScreenDepthsMask |= X1R5G5B5_FLAG;
00715       break;
00716     case D3DFMT_X8R8G8B8:
00717       *pSupportedScreenDepthsMask |= X8R8G8B8_FLAG;
00718       break;
00719     case D3DFMT_R8G8B8:
00720       *pSupportedScreenDepthsMask |= R8G8B8_FLAG;
00721       break;
00722     case D3DFMT_R5G6B5:
00723       *pSupportedScreenDepthsMask |= R5G6B5_FLAG;
00724       break;
00725     default:
00726       
00727       
00728       wdxdisplay8_cat.error()
00729         << "unrecognized supported fmt "<< D3DFormatStr(dispmode.Format)
00730         << " returned by EnumAdapterDisplayModes!\n";
00731     }
00732   }
00733 
00734   
00735   
00736   if (*pSupportedScreenDepthsMask & X8R8G8B8_FLAG) {
00737     *pSuggestedPixFmt = D3DFMT_X8R8G8B8;
00738   } else if (*pSupportedScreenDepthsMask & R8G8B8_FLAG) {
00739     *pSuggestedPixFmt = D3DFMT_R8G8B8;
00740   } else if (*pSupportedScreenDepthsMask & R5G6B5_FLAG) {
00741     *pSuggestedPixFmt = D3DFMT_R5G6B5;
00742   } else if (*pSupportedScreenDepthsMask & X1R5G5B5_FLAG) {
00743     *pSuggestedPixFmt = D3DFMT_X1R5G5B5;
00744   }
00745 
00746   if (bVerboseMode || wdxdisplay8_cat.is_spam()) {
00747     wdxdisplay8_cat.info() 
00748       << "search_for_valid_device returns fmt: "
00749       << D3DFormatStr(*pSuggestedPixFmt) << endl;
00750   }
00751 }
00752 
00753 
00754 
00755 
00756 
00757 
00758 
00759 
00760 PT(GraphicsStateGuardian) wdxGraphicsPipe8::
00761 make_gsg(const FrameBufferProperties &properties) {
00762 
00763 
00764   
00765   
00766   PT(DXGraphicsStateGuardian8) gsg = new DXGraphicsStateGuardian8(properties);
00767   return gsg.p();
00768 
00769 
00770 
00771 
00772 
00773 
00774 
00775 
00776 
00777 
00778 
00779 
00780 
00781 
00782 
00783 
00784 
00785 
00786 
00787 
00788 
00789 
00790 
00791 
00792 
00793 }
00794 
00795 map<D3DFORMAT_FLAG,D3DFORMAT> g_D3DFORMATmap;
00796 
00797 void Init_D3DFORMAT_map(void) {
00798   if(g_D3DFORMATmap.size()!=0)
00799     return;
00800 
00801     #define INSERT_ELEM(XX)  g_D3DFORMATmap[XX##_FLAG] = D3DFMT_##XX;
00802 
00803     INSERT_ELEM(R8G8B8);
00804     INSERT_ELEM(A8R8G8B8);
00805     INSERT_ELEM(X8R8G8B8);
00806     INSERT_ELEM(R5G6B5);
00807     INSERT_ELEM(X1R5G5B5);
00808     INSERT_ELEM(A1R5G5B5);
00809     INSERT_ELEM(A4R4G4B4);
00810     INSERT_ELEM(R3G3B2);
00811     INSERT_ELEM(A8);
00812     INSERT_ELEM(A8R3G3B2);
00813     INSERT_ELEM(X4R4G4B4);
00814     INSERT_ELEM(A2B10G10R10);
00815     INSERT_ELEM(G16R16);
00816     INSERT_ELEM(A8P8);
00817     INSERT_ELEM(P8);
00818     INSERT_ELEM(L8);
00819     INSERT_ELEM(A8L8);
00820     INSERT_ELEM(A4L4);
00821     INSERT_ELEM(V8U8);
00822     INSERT_ELEM(L6V5U5);
00823     INSERT_ELEM(X8L8V8U8);
00824     INSERT_ELEM(Q8W8V8U8);
00825     INSERT_ELEM(V16U16);
00826     INSERT_ELEM(W11V11U10);
00827     INSERT_ELEM(A2W10V10U10);
00828     INSERT_ELEM(UYVY);
00829     INSERT_ELEM(YUY2);
00830     INSERT_ELEM(DXT1);
00831     INSERT_ELEM(DXT2);
00832     INSERT_ELEM(DXT3);
00833     INSERT_ELEM(DXT4);
00834     INSERT_ELEM(DXT5);
00835 }
00836 
00837 
00838 const char *D3DFormatStr(D3DFORMAT fmt) {
00839 
00840 #define CASESTR(XX) case XX: return #XX;
00841 
00842   switch(fmt) {
00843     CASESTR(D3DFMT_UNKNOWN);
00844     CASESTR(D3DFMT_R8G8B8);
00845     CASESTR(D3DFMT_A8R8G8B8);
00846     CASESTR(D3DFMT_X8R8G8B8);
00847     CASESTR(D3DFMT_R5G6B5);
00848     CASESTR(D3DFMT_X1R5G5B5);
00849     CASESTR(D3DFMT_A1R5G5B5);
00850     CASESTR(D3DFMT_A4R4G4B4);
00851     CASESTR(D3DFMT_R3G3B2);
00852     CASESTR(D3DFMT_A8);
00853     CASESTR(D3DFMT_A8R3G3B2);
00854     CASESTR(D3DFMT_X4R4G4B4);
00855     CASESTR(D3DFMT_A2B10G10R10);
00856     CASESTR(D3DFMT_G16R16);
00857     CASESTR(D3DFMT_A8P8);
00858     CASESTR(D3DFMT_P8);
00859     CASESTR(D3DFMT_L8);
00860     CASESTR(D3DFMT_A8L8);
00861     CASESTR(D3DFMT_A4L4);
00862     CASESTR(D3DFMT_V8U8);
00863     CASESTR(D3DFMT_L6V5U5);
00864     CASESTR(D3DFMT_X8L8V8U8);
00865     CASESTR(D3DFMT_Q8W8V8U8);
00866     CASESTR(D3DFMT_V16U16);
00867     CASESTR(D3DFMT_W11V11U10);
00868     CASESTR(D3DFMT_A2W10V10U10);
00869     CASESTR(D3DFMT_UYVY);
00870     CASESTR(D3DFMT_YUY2);
00871     CASESTR(D3DFMT_DXT1);
00872     CASESTR(D3DFMT_DXT2);
00873     CASESTR(D3DFMT_DXT3);
00874     CASESTR(D3DFMT_DXT4);
00875     CASESTR(D3DFMT_DXT5);
00876     CASESTR(D3DFMT_D16_LOCKABLE);
00877     CASESTR(D3DFMT_D32);
00878     CASESTR(D3DFMT_D15S1);
00879     CASESTR(D3DFMT_D24S8);
00880     CASESTR(D3DFMT_D16);
00881     CASESTR(D3DFMT_D24X8);
00882     CASESTR(D3DFMT_D24X4S4);
00883     CASESTR(D3DFMT_VERTEXDATA);
00884     CASESTR(D3DFMT_INDEX16);
00885     CASESTR(D3DFMT_INDEX32);
00886   }
00887 
00888   return "Invalid D3DFORMAT";
00889 }
00890