Skip to content

Commit

Permalink
Utilize CGfxLibrary::CheckAPI() for asserting current graphics API.
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamyCecil committed Nov 11, 2023
1 parent 0d0ae39 commit 4b31f60
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 165 deletions.
7 changes: 2 additions & 5 deletions Sources/Engine/Graphics/DepthCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ static void UpdateDepthPointsVisibility( const CDrawPort *pdp, const INDEX iMirr
DepthInfo *pdi, const INDEX ctCount)
{
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

ASSERT( pdp!=NULL && ctCount>0);
const CRaster *pra = pdp->dp_Raster;

Expand Down
95 changes: 20 additions & 75 deletions Sources/Engine/Graphics/DrawPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,8 @@ void CDrawPort::DrawPoint( PIX pixI, PIX pixJ, COLOR col, PIX pixRadius/*=1*/) c
{
// check API and radius
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT( eAPI==GAT_OGL || eAPI==GAT_D3D || eAPI==GAT_NONE);
#else // SE1_D3D
ASSERT( eAPI==GAT_OGL || eAPI==GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

ASSERT( pixRadius>=0);
if( pixRadius==0) return; // do nothing if radius is 0

Expand Down Expand Up @@ -490,11 +487,8 @@ void CDrawPort::DrawPoint3D( FLOAT3D v, COLOR col, FLOAT fRadius/*=1.0f*/) const
{
// check API and radius
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

ASSERT( fRadius>=0);
if( fRadius==0) return; // do nothing if radius is 0

Expand Down Expand Up @@ -539,11 +533,7 @@ void CDrawPort::DrawLine( PIX pixI0, PIX pixJ0, PIX pixI1, PIX pixJ1, COLOR col,
{
// check API
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

// setup rendering mode
gfxDisableDepthTest();
Expand Down Expand Up @@ -608,11 +598,7 @@ void CDrawPort::DrawLine3D( FLOAT3D v0, FLOAT3D v1, COLOR col) const
{
// check API
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

// setup rendering mode
gfxDisableTexture();
Expand Down Expand Up @@ -654,11 +640,7 @@ void CDrawPort::DrawBorder( PIX pixI, PIX pixJ, PIX pixWidth, PIX pixHeight, COL
{
// check API
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

// setup rendering mode
gfxDisableDepthTest();
Expand Down Expand Up @@ -744,11 +726,7 @@ void CDrawPort::Fill( PIX pixI, PIX pixJ, PIX pixWidth, PIX pixHeight, COLOR col

// check API
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

// OpenGL
if( eAPI==GAT_OGL)
Expand Down Expand Up @@ -795,11 +773,7 @@ void CDrawPort::Fill( PIX pixI, PIX pixJ, PIX pixWidth, PIX pixHeight,

// check API
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

// setup rendering mode
gfxDisableDepthTest();
Expand Down Expand Up @@ -865,11 +839,7 @@ void CDrawPort::Fill( COLOR col) const

// check API
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

// OpenGL
if( eAPI==GAT_OGL)
Expand Down Expand Up @@ -897,11 +867,7 @@ void CDrawPort::FillZBuffer( PIX pixI, PIX pixJ, PIX pixWidth, PIX pixHeight, FL
{
// check API
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

// clip and eventually reject
const BOOL bInside = ClipToDrawPort( this, pixI, pixJ, pixWidth, pixHeight);
Expand Down Expand Up @@ -938,11 +904,8 @@ void CDrawPort::FillZBuffer( FLOAT zval) const
{
// check API
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

gfxEnableDepthWrite();

// OpenGL
Expand All @@ -969,11 +932,8 @@ void CDrawPort::GrabScreen( class CImageInfo &iiGrabbedImage, INDEX iGrabZBuffer
{
// check API
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

extern INDEX ogl_bGrabDepthBuffer;
const BOOL bGrabDepth = eAPI==GAT_OGL && ((iGrabZBuffer==1 && ogl_bGrabDepthBuffer) || iGrabZBuffer==2);

Expand Down Expand Up @@ -1071,11 +1031,7 @@ BOOL CDrawPort::IsPointVisible( PIX pixI, PIX pixJ, FLOAT fOoK, INDEX iID, INDEX

// check API
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

// use delayed mechanism for checking
extern BOOL CheckDepthPoint( const CDrawPort *pdp, PIX pixI, PIX pixJ, FLOAT fOoK, INDEX iID, INDEX iMirrorLevel=0);
Expand All @@ -1088,11 +1044,7 @@ void CDrawPort::RenderLensFlare( CTextureObject *pto, FLOAT fI, FLOAT fJ,
{
// check API
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

// setup rendering mode
gfxEnableDepthTest();
Expand Down Expand Up @@ -1219,11 +1171,7 @@ void CDrawPort::PutText( const CTString &strText, PIX pixX0, PIX pixY0, const CO
{
// check API and adjust position for D3D by half pixel
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

// skip drawing if text falls above or below draw port
if( pixY0>dp_Height || pixX0>dp_Width) return;
Expand Down Expand Up @@ -1511,11 +1459,8 @@ void CDrawPort::PutTexture( class CTextureObject *pTO,

// check API and adjust position for D3D by half pixel
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

FLOAT fI0 = pixI0; FLOAT fI1 = pixI1;
FLOAT fJ0 = pixJ0; FLOAT fJ1 = pixJ1;

Expand Down
13 changes: 3 additions & 10 deletions Sources/Engine/Graphics/DrawPort_RenderScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1710,16 +1710,9 @@ void RenderScene( CDrawPort *pDP, ScenePolygon *pspoFirst, CAnyProjection3D &prP
{
// check API
eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT( eAPI==GAT_OGL || eAPI==GAT_D3D || eAPI==GAT_NONE);
#else // SE1_D3D
ASSERT( eAPI==GAT_OGL || eAPI==GAT_NONE);
#endif // SE1_D3D
if( eAPI!=GAT_OGL
#ifdef SE1_D3D
&& eAPI!=GAT_D3D
#endif // SE1_D3D
) return;
_pGfx->CheckAPI();

if (eAPI != GAT_OGL && eAPI != GAT_D3D) return;

// some cvars cannot be altered in multiplayer mode!
if( _bMultiPlayer) {
Expand Down
25 changes: 5 additions & 20 deletions Sources/Engine/Graphics/GfxLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,8 @@ static void GAPInfo(void)
{
// check API
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT( eAPI==GAT_OGL || eAPI==GAT_D3D || eAPI==GAT_NONE);
#else // SE1_D3D
ASSERT( eAPI==GAT_OGL || eAPI==GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

CPrintF( "\n");

// in case of driver hasn't been initialized yet
Expand Down Expand Up @@ -1459,11 +1456,7 @@ BOOL CGfxLibrary::SetCurrentViewport(CViewPort *pvp)
BOOL CGfxLibrary::LockDrawPort( CDrawPort *pdpToLock)
{
// check API
#ifdef SE1_D3D
ASSERT( gl_eCurrentAPI==GAT_OGL || gl_eCurrentAPI==GAT_D3D || gl_eCurrentAPI==GAT_NONE);
#else // SE1_D3D
ASSERT( gl_eCurrentAPI==GAT_OGL || gl_eCurrentAPI==GAT_NONE);
#endif // SE1_D3D
CheckAPI();

// don't allow locking if drawport is too small
if( pdpToLock->dp_Width<1 || pdpToLock->dp_Height<1) return FALSE;
Expand Down Expand Up @@ -1515,11 +1508,7 @@ BOOL CGfxLibrary::LockDrawPort( CDrawPort *pdpToLock)
void CGfxLibrary::UnlockDrawPort( CDrawPort *pdpToUnlock)
{
// check API
#ifdef SE1_D3D
ASSERT(gl_eCurrentAPI == GAT_OGL || gl_eCurrentAPI == GAT_D3D || gl_eCurrentAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(gl_eCurrentAPI == GAT_OGL || gl_eCurrentAPI == GAT_NONE);
#endif // SE1_D3D
CheckAPI();
// eventually signalize that scene rendering has ended
}

Expand Down Expand Up @@ -1725,11 +1714,7 @@ static BOOL GenerateGammaTable(void);
void CGfxLibrary::SwapBuffers(CViewPort *pvp)
{
// check API
#ifdef SE1_D3D
ASSERT(gl_eCurrentAPI == GAT_OGL || gl_eCurrentAPI == GAT_D3D || gl_eCurrentAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(gl_eCurrentAPI == GAT_OGL || gl_eCurrentAPI == GAT_NONE);
#endif // SE1_D3D
CheckAPI();

// safety check
ASSERT( gl_pvpActive!=NULL);
Expand Down
54 changes: 14 additions & 40 deletions Sources/Engine/Graphics/Gfx_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,8 @@ extern void UpdateLODBias( const FLOAT fLODBias)
{
// check API
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT( eAPI==GAT_OGL || eAPI==GAT_D3D || eAPI==GAT_NONE);
#else // SE1_D3D
ASSERT( eAPI==GAT_OGL || eAPI==GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

// only if supported and needed
if( _fCurrentLODBias==fLODBias && _pGfx->gl_fMaxTextureLODBias==0) return;
_fCurrentLODBias = fLODBias;
Expand Down Expand Up @@ -309,11 +306,8 @@ extern void gfxSetTextureUnit( INDEX iUnit)
{
// check API
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT( eAPI==GAT_OGL || eAPI==GAT_D3D || eAPI==GAT_NONE);
#else // SE1_D3D
ASSERT( eAPI==GAT_OGL || eAPI==GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

ASSERT( iUnit>=0 && iUnit<4); // supports 4 layers (for now)

// check consistency
Expand Down Expand Up @@ -356,11 +350,8 @@ extern void gfxSetTexture( ULONG &ulTexObject, CTexParams &tpLocal)

// determine API and enable texturing
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

gfxEnableTexture();

_sfStats.StartTimer(CStatForm::STI_BINDTEXTURE);
Expand Down Expand Up @@ -393,11 +384,7 @@ extern void gfxUploadTexture( ULONG *pulTexture, PIX pixWidth, PIX pixHeight, UL
{
// determine API
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

_sfStats.StartTimer(CStatForm::STI_GFXAPI);

Expand Down Expand Up @@ -429,11 +416,8 @@ extern SLONG gfxGetTextureSize( ULONG ulTexObject, BOOL bHasMipmaps/*=TRUE*/)

// determine API
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

SLONG slMipSize;

_sfStats.StartTimer(CStatForm::STI_GFXAPI);
Expand Down Expand Up @@ -489,11 +473,8 @@ extern INDEX gfxGetTexturePixRatio( ULONG ulTextureObject)
{
// determine API
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

if( eAPI==GAT_OGL) {
return GetTexturePixRatio_OGL( (GLuint)ulTextureObject);
}
Expand All @@ -509,11 +490,8 @@ extern INDEX gfxGetFormatPixRatio( ULONG ulTextureFormat)
{
// determine API
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

if( eAPI==GAT_OGL) {
return GetFormatPixRatio_OGL( (GLenum)ulTextureFormat);
}
Expand Down Expand Up @@ -658,11 +636,7 @@ extern void gfxSetTruform( INDEX iLevel, BOOL bLinearNormals)

// determine API
const GfxAPIType eAPI = _pGfx->GetCurrentAPI();
#ifdef SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_D3D || eAPI == GAT_NONE);
#else // SE1_D3D
ASSERT(eAPI == GAT_OGL || eAPI == GAT_NONE);
#endif // SE1_D3D
_pGfx->CheckAPI();

_sfStats.StartTimer(CStatForm::STI_GFXAPI);

Expand Down
Loading

0 comments on commit 4b31f60

Please sign in to comment.