port: GrpDetector verbatim 40250 over a host IDirect3D8 (Direct3DCreate8); GrpDevice::Create verbatim

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-09-30 15:02:12 +09:00
co-authored by Claude Opus 5.5
parent 65c43a84cd
commit fd4d9a39df
12 changed files with 1127 additions and 173 deletions
+160 -15
View File
@@ -1,12 +1,9 @@
// 40250 EterLib/GrpDevice.cpp, verbatim but for CGraphicDevice::Create, which makes the recording device
// (RecordingDevice.h) in place of the Direct3D object, adapter detection and CreateDevice.
// 40250 EterLib/GrpDevice.cpp, verbatim. Direct3DCreate8 is the host adapter of RecordingDevice.cpp.
#include "EterLib/StdAfx.h"
#include "EterLib/GrpDevice.h"
#include "EterBase/Stl.h"
#include "EterBase/Debug.h"
#include "RecordingDevice.h"
bool GRAPHICS_CAPS_CAN_NOT_DRAW_LINE = false;
bool GRAPHICS_CAPS_CAN_NOT_DRAW_SHADOW = false;
bool GRAPHICS_CAPS_HALF_SIZE_IMAGE = false;
@@ -359,12 +356,69 @@ int CGraphicDevice::Create(HWND hWnd, int iHres, int iVres, bool Windowed, int /
ms_iHeight = iVres;
ms_hWnd = hWnd;
// PORT: in place of GetDC, Direct3DCreate8, the D3D_CDisplayModeAutoDetector adapter/mode search, the
// driver black list, CreateDevice with its refresh-rate retry, the DXT format checks and the full-screen
// SetWindowPos: the recording device (RecordingDevice.h) renders through the host, which owns the window
// and supports DXT and hardware T&L at any refresh rate.
ms_lpd3dDevice = MtCreateRecordingDevice(iHres, iVres);
ms_hDC = GetDC(hWnd);
ms_lpd3d = Direct3DCreate8(D3D_SDK_VERSION);
if (!ms_lpd3d)
return CREATE_NO_DIRECTX;
if (!ms_kD3DDetector.Build(*ms_lpd3d, EL3D_ConfirmDevice))
return CREATE_ENUM;
if (!ms_kD3DDetector.Find(800, 600, 32, TRUE, &ms_iD3DModeInfo, &ms_iD3DDevInfo, &ms_iD3DAdapterInfo))
return CREATE_DETECT;
std::string stDevList;
ms_kD3DDetector.GetString(&stDevList);
//Tracen(stDevList.c_str());
//Tracenf("adapter %d, device %d, mode %d", ms_iD3DAdapterInfo, ms_iD3DDevInfo, ms_iD3DModeInfo);
D3D_CAdapterInfo * pkD3DAdapterInfo = ms_kD3DDetector.GetD3DAdapterInfop(ms_iD3DAdapterInfo);
if (!pkD3DAdapterInfo)
{
Tracenf("adapter %d is EMPTY", ms_iD3DAdapterInfo);
return CREATE_DETECT;
}
if (__IsInDriverBlackList(*pkD3DAdapterInfo))
{
iRet |= CREATE_BAD_DRIVER;
__WarningMessage(hWnd, CREATE_BAD_DRIVER);
}
D3D_SModeInfo * pkD3DModeInfo = pkD3DAdapterInfo->GetD3DModeInfop(ms_iD3DDevInfo, ms_iD3DModeInfo);
if (!pkD3DModeInfo)
{
Tracenf("device %d, mode %d is EMPTY", ms_iD3DDevInfo, ms_iD3DModeInfo);
return CREATE_DETECT;
}
D3DADAPTER_IDENTIFIER8& rkD3DAdapterId=pkD3DAdapterInfo->GetIdentifier();
if (Windowed &&
strnicmp(rkD3DAdapterId.Driver, "3dfx", 4)==0 &&
22 == pkD3DAdapterInfo->GetDesktopD3DDisplayModer().Format)
{
return CREATE_FORMAT;
}
if (pkD3DModeInfo->m_dwD3DBehavior==D3DCREATE_SOFTWARE_VERTEXPROCESSING)
{
iRet |= CREATE_NO_TNL;
// DISABLE_NOTIFY_NOT_SUPPORT_TNL_MESSAGE
//__WarningMessage(hWnd, CREATE_NO_TNL);
// END_OF_DISABLE_NOTIFY_NOT_SUPPORT_TNL_MESSAGE
}
std::string stModeInfo;
pkD3DModeInfo->GetString(&stModeInfo);
//Tracen(stModeInfo.c_str());
int ErrorCorrection = 0;
RETRY:
ZeroMemory(&ms_d3dPresentParameter, sizeof(ms_d3dPresentParameter));
ms_d3dPresentParameter.Windowed = Windowed;
@@ -374,13 +428,90 @@ int CGraphicDevice::Create(HWND hWnd, int iHres, int iVres, bool Windowed, int /
ms_d3dPresentParameter.BackBufferCount = m_uBackBufferCount;
ms_d3dPresentParameter.SwapEffect = D3DSWAPEFFECT_DISCARD;
if (!Windowed)
if (Windowed)
{
ms_d3dPresentParameter.BackBufferFormat = pkD3DAdapterInfo->GetDesktopD3DDisplayModer().Format;
}
else
{
ms_d3dPresentParameter.BackBufferFormat = pkD3DModeInfo->m_eD3DFmtPixel;
ms_d3dPresentParameter.FullScreen_RefreshRateInHz = iReflashRate;
}
ms_d3dPresentParameter.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
ms_d3dPresentParameter.EnableAutoDepthStencil = TRUE;
ms_d3dPresentParameter.AutoDepthStencilFormat = pkD3DModeInfo->m_eD3DFmtDepthStencil;
ms_dwD3DBehavior = D3DCREATE_HARDWARE_VERTEXPROCESSING;
ms_dwD3DBehavior = pkD3DModeInfo->m_dwD3DBehavior;
if (FAILED(ms_hLastResult = ms_lpd3d->CreateDevice(
ms_iD3DAdapterInfo,
D3DDEVTYPE_HAL,
hWnd,
// 2004. 1. 9 myevan 버텍스 프로세싱 방식 자동 선택 추가
pkD3DModeInfo->m_dwD3DBehavior,
&ms_d3dPresentParameter,
&ms_lpd3dDevice)))
{
switch (ms_hLastResult)
{
case D3DERR_INVALIDCALL:
Tracen("IDirect3DDevice.CreateDevice - ERROR D3DERR_INVALIDCALL\nThe method call is invalid. For example, a method's parameter may have an invalid value.");
break;
case D3DERR_NOTAVAILABLE:
Tracen("IDirect3DDevice.CreateDevice - ERROR D3DERR_NOTAVAILABLE\nThis device does not support the queried technique. ");
break;
case D3DERR_OUTOFVIDEOMEMORY:
Tracen("IDirect3DDevice.CreateDevice - ERROR D3DERR_OUTOFVIDEOMEMORY\nDirect3D does not have enough display memory to perform the operation");
break;
default:
Tracenf("IDirect3DDevice.CreateDevice - ERROR %d", ms_hLastResult);
break;
}
if (ErrorCorrection)
return CREATE_DEVICE;
// 2004. 1. 9 myevan 큰의미 없는 코드인듯.. 에러나면 표시하고 종료하자
iReflashRate = 0;
++ErrorCorrection;
iRet = CREATE_REFRESHRATE;
goto RETRY;
}
// Check DXT Support Info
if(ms_lpd3d->CheckDeviceFormat(
ms_iD3DAdapterInfo,
D3DDEVTYPE_HAL,
ms_d3dPresentParameter.BackBufferFormat,
0,
D3DRTYPE_TEXTURE,
D3DFMT_DXT1) == D3DERR_NOTAVAILABLE)
{
ms_bSupportDXT = false;
}
if(ms_lpd3d->CheckDeviceFormat(
ms_iD3DAdapterInfo,
D3DDEVTYPE_HAL,
ms_d3dPresentParameter.BackBufferFormat,
0,
D3DRTYPE_TEXTURE,
D3DFMT_DXT3) == D3DERR_NOTAVAILABLE)
{
ms_bSupportDXT = false;
}
if(ms_lpd3d->CheckDeviceFormat(
ms_iD3DAdapterInfo,
D3DDEVTYPE_HAL,
ms_d3dPresentParameter.BackBufferFormat,
0,
D3DRTYPE_TEXTURE,
D3DFMT_DXT5) == D3DERR_NOTAVAILABLE)
{
ms_bSupportDXT = false;
}
if (FAILED((ms_hLastResult = ms_lpd3dDevice->GetDeviceCaps(&ms_d3dCaps))))
{
@@ -388,9 +519,10 @@ int CGraphicDevice::Create(HWND hWnd, int iHres, int iVres, bool Windowed, int /
return CREATE_GET_DEVICE_CAPS2;
}
// PORT: the detector runs EL3D_ConfirmDevice on each device's caps; here on the one device (max texture size).
if (!EL3D_ConfirmDevice(ms_d3dCaps, ms_dwD3DBehavior, ms_d3dPresentParameter.BackBufferFormat))
return CREATE_DETECT;
if (!Windowed)
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, iHres, iVres, SWP_SHOWWINDOW);
//Tracef("vertex shader version : %X\n",(DWORD)ms_d3dCaps.VertexShaderVersion);
ms_lpd3dDevice->GetViewport(&ms_Viewport);
@@ -448,7 +580,20 @@ int CGraphicDevice::Create(HWND hWnd, int iHres, int iVres, bool Windowed, int /
else
GRAPHICS_CAPS_CAN_NOT_TEXTURE_ADDRESS_BORDER=true;
// PORT: the SIS/3dfx driver caps have no adapter identifier to test.
//D3DADAPTER_IDENTIFIER8& rkD3DAdapterId=pkD3DAdapterInfo->GetIdentifier();
if (strnicmp(rkD3DAdapterId.Driver, "SIS", 3) == 0)
{
GRAPHICS_CAPS_CAN_NOT_DRAW_LINE = true;
GRAPHICS_CAPS_CAN_NOT_DRAW_SHADOW = true;
GRAPHICS_CAPS_HALF_SIZE_IMAGE = true;
ms_isLowTextureMemory = true;
}
else if (strnicmp(rkD3DAdapterId.Driver, "3dfx", 4) == 0)
{
GRAPHICS_CAPS_CAN_NOT_DRAW_SHADOW = true;
GRAPHICS_CAPS_HALF_SIZE_IMAGE = true;
ms_isLowTextureMemory = true;
}
return (iRet);
}