Skip to content

Commit

Permalink
Add CGfxLibrary::GetApiName() for retrieving API name from its type.
Browse files Browse the repository at this point in the history
- Add GAT_MAX type for keeping track of the amount of available graphics APIs.
  • Loading branch information
DreamyCecil committed Nov 11, 2023
1 parent 4b31f60 commit 4638bcc
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 47 deletions.
9 changes: 2 additions & 7 deletions Sources/Engine/Graphics/Benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,8 @@ void CGfxLibrary::Benchmark(CViewPort *pvp, CDrawPort *pdp)
_pixSizeI = pdp->GetWidth();
_pixSizeJ = pdp->GetHeight();

CTString strAPI = "";

if (_pGfx->GetCurrentAPI() == GAT_OGL) {
strAPI = "OpenGL";
} else if (_pGfx->GetCurrentAPI()==GAT_D3D) {
strAPI = "Direct3D";
}
// [Cecil] API name
CTString strAPI = _pGfx->GetApiName(_pGfx->GetCurrentAPI());

CPrintF("=====================================\n");
CPrintF("%s performance testing ...\n", strAPI);
Expand Down
20 changes: 17 additions & 3 deletions Sources/Engine/Graphics/GfxLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,8 @@ static void GAPInfo(void)
}

// report API
CPrintF( "- Graphics API: ");
if( eAPI==GAT_OGL) CPrintF( "OpenGL\n");
else CPrintF( "Direct3D\n");
CPrintF( "- Graphics API: %s\n", _pGfx->GetApiName(eAPI));

// and number of adapters
CPrintF( "- Adapters found: %d\n", _pGfx->gl_gaAPI[eAPI].ga_ctAdapters);
CPrintF( "\n");
Expand Down Expand Up @@ -1242,7 +1241,22 @@ void CGfxLibrary::Init(void)
InitAPIs();
}

// [Cecil] Get API name from type
const CTString &CGfxLibrary::GetApiName(GfxAPIType eAPI)
{
// Invalid API
if (eAPI == GAT_NONE || eAPI >= GAT_MAX) {
static const CTString strNone = "none";
return strNone;
}

static const CTString astrApiNames[GAT_MAX] = {
"OpenGL",
"Direct3D",
};

return astrApiNames[eAPI];
};

// set new display mode
BOOL CGfxLibrary::SetDisplayMode( enum GfxAPIType eAPI, INDEX iAdapter, PIX pixSizeI, PIX pixSizeJ,
Expand Down
6 changes: 6 additions & 0 deletions Sources/Engine/Graphics/GfxLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ enum GfxAPIType
GAT_NONE = -1, // no gfx API (gfx functions are disabled)
GAT_OGL = 0, // OpenGL
GAT_D3D = 1, // Direct3D

GAT_MAX, // [Cecil] Amount of graphics APIs

GAT_CURRENT = 9, // current API
};

Expand Down Expand Up @@ -283,6 +286,9 @@ class ENGINE_API CGfxLibrary
return FALSE;
};

// [Cecil] Get API name from type
const CTString &GetApiName(GfxAPIType eAPI);

// [Cecil] Check currently used API for debugging
inline void CheckAPI(void)
{
Expand Down
23 changes: 6 additions & 17 deletions Sources/EngineGui/DlgSelectMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,8 @@ CDlgSelectMode::CDlgSelectMode( CDisplayMode &dm, enum GfxAPIType &gfxAPI,
str.PrintF( "%d x %d x %s", dm.dm_pixSizeI, dm.dm_pixSizeJ, dm.DepthString());
m_strCurrentMode = str.ConstData();

switch(gfxAPI) {
case GAT_OGL:
m_strCurrentDriver = "OpenGL";
break;
#ifdef SE1_D3D
case GAT_D3D:
m_strCurrentDriver = "Direct3D";
break;
#endif // SE1_D3D
default:
m_strCurrentDriver = "none";
break;
}
// [Cecil] API name
m_strCurrentDriver = _pGfx->GetApiName(_pGfx->GetCurrentAPI());
}

CDlgSelectMode::~CDlgSelectMode()
Expand Down Expand Up @@ -253,12 +242,12 @@ void CDlgSelectMode::DoDataExchange(CDataExchange* pDX)
m_ctrlResCombo.ResetContent();

// init driver combo
i = m_ctrlDriverCombo.AddString( L"OpenGL");
m_ctrlDriverCombo.SetItemData( i, (INDEX)GAT_OGL);
i = m_ctrlDriverCombo.AddString(CString(_pGfx->GetApiName(GAT_OGL).ConstData()));
m_ctrlDriverCombo.SetItemData(i, GAT_OGL);
if( *m_pGfxAPI==GAT_OGL) iSelect = i;
#ifdef SE1_D3D
i = m_ctrlDriverCombo.AddString( L"Direct3D");
m_ctrlDriverCombo.SetItemData( i, (INDEX)GAT_D3D);
i = m_ctrlDriverCombo.AddString(CString(_pGfx->GetApiName(GAT_D3D).ConstData()));
m_ctrlDriverCombo.SetItemData(i, GAT_D3D);
if( *m_pGfxAPI==GAT_D3D) iSelect = i;
#endif // SE1_D3D
// set old driver to be default
Expand Down
21 changes: 10 additions & 11 deletions Sources/EngineGui/EngineGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,23 +267,22 @@ void CEngineGUI::GetFullScreenModeFromRegistry( CTString strSectionName, CDispla
CTString strResult = CStringA(AfxGetApp()->GetProfileString(CString(strSectionName.ConstData()), L"Full screen mode", L"640 x 480 x 0"));
strResult.ScanF( "%d x %d x %d", &dm.dm_pixSizeI, &dm.dm_pixSizeJ, &dm.dm_ddDepth);
if( dm.dm_ddDepth<DD_DEFAULT || dm.dm_ddDepth>DD_32BIT) dm.dm_ddDepth = DD_DEFAULT;
strResult = CStringA(AfxGetApp()->GetProfileString(CString(strSectionName.ConstData()), L"Full screen API", L"OpenGL"));
#ifdef SE1_D3D
gat = (strResult=="Direct3D") ? GAT_D3D : GAT_OGL;
#else // SE1_D3D
gat = GAT_OGL;
#endif // SE1_D3D

// [Cecil] API name
const CTString &strOGL = _pGfx->GetApiName(GAT_OGL);
strResult = CStringA(AfxGetApp()->GetProfileString(CString(strSectionName.ConstData()), L"Full screen API", CString(strOGL.ConstData())));

gat = (strResult != strOGL) ? GAT_D3D : GAT_OGL;
}


void CEngineGUI::SetFullScreenModeToRegistry( CTString strSectionName, CDisplayMode dm, GfxAPIType gat)
{
CTString strDM( 0, "%d x %d x %d", dm.dm_pixSizeI, dm.dm_pixSizeJ, dm.dm_ddDepth);
#ifdef SE1_D3D
CTString strGAT = (gat==GAT_D3D) ? "Direct3D" : "OpenGL";
#else // SE1_D3D
CTString strGAT = "OpenGL";
#endif // SE1_D3D

// [Cecil] API name
CTString strGAT = _pGfx->GetApiName(_pGfx->GetCurrentAPI());

AfxGetApp()->WriteProfileString(CString(strSectionName.ConstData()), L"Full screen mode", CString(strDM.ConstData()));
AfxGetApp()->WriteProfileString(CString(strSectionName.ConstData()), L"Full screen API", CString(strGAT.ConstData()));
}
4 changes: 2 additions & 2 deletions Sources/Modeler/DlgPreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ BOOL CDlgPreferences::OnInitDialog()
CDialog::OnInitDialog();

m_ctrlGfxApi.ResetContent();
m_ctrlGfxApi.AddString(L"OpenGL");
m_ctrlGfxApi.AddString(CString(_pGfx->GetApiName(GAT_OGL).ConstData()));
#ifdef SE1_D3D
m_ctrlGfxApi.AddString(L"DirectX");
m_ctrlGfxApi.AddString(CString(_pGfx->GetApiName(GAT_D3D).ConstData()));
#endif // SE1_D3D

if( IsWindow(m_ctrlGfxApi.m_hWnd))
Expand Down
1 change: 1 addition & 0 deletions Sources/SeriousSam/GUI/Menus/MenuStuff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ extern CTString astrDisplayPrefsRadioTexts[] = {
};

extern CTString astrDisplayAPIRadioTexts[] = {
// [Cecil] TODO: Get names using CGfxLibrary::GetApiName()
RADIOTRANS("OpenGL"),
RADIOTRANS("Direct3D"),
};
Expand Down
8 changes: 3 additions & 5 deletions Sources/SeriousSam/SeriousSam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,11 +640,9 @@ void PrintDisplayModeInfo(void)
strRes.PrintF( "%dx%dx%s", slDPWidth, slDPHeight, _pGfx->gl_dmCurrentDisplayMode.DepthString());
if( dm.IsDualHead()) strRes += TRANS(" DualMonitor");
if( dm.IsWideScreen()) strRes += TRANS(" WideScreen");
if (_pGfx->GetCurrentAPI() == GAT_OGL) {
strRes += " (OpenGL)";
} else if (_pGfx->GetCurrentAPI() == GAT_D3D) {
strRes += " (Direct3D)";
}

// [Cecil] API name
strRes += CTString(0, " (%s)", _pGfx->GetApiName(_pGfx->GetCurrentAPI()));

CTString strDescr;
strDescr.PrintF("\n%s (%s)\n", _strPreferencesDescription, RenderingPreferencesDescription(sam_iVideoSetup));
Expand Down
4 changes: 2 additions & 2 deletions Sources/WorldEditor/DlgPreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ BOOL CDlgPreferences::OnInitDialog()

if( _pGfx->HasAPI( GAT_OGL))
{
INDEX iAddedAs=m_ctrGfxApi.AddString(L"OpenGL");
INDEX iAddedAs = m_ctrGfxApi.AddString(CString(_pGfx->GetApiName(GAT_OGL).ConstData()));
m_ctrGfxApi.SetItemData(iAddedAs, GAT_OGL);
}
#ifdef SE1_D3D
if( _pGfx->HasAPI( GAT_D3D))
{
INDEX iAddedAs=m_ctrGfxApi.AddString(L"Direct3D");
INDEX iAddedAs = m_ctrGfxApi.AddString(CString(_pGfx->GetApiName(GAT_D3D).ConstData()));
m_ctrGfxApi.SetItemData(iAddedAs, GAT_D3D);
}
#endif // SE1_D3D
Expand Down

0 comments on commit 4638bcc

Please sign in to comment.