/////////////////////////////////////////////////////////////////////////////// // Copyright (C) Microsoft Corporation, 1998. // // rrutil.cpp // // Direct3D Reference Rasterizer - Utilities // // // // /////////////////////////////////////////////////////////////////////////////// #include "pch.cpp" #pragma hdrstop ////////////////////////////////////////////////////////////////////////////////// // // // DPF support // // // ////////////////////////////////////////////////////////////////////////////////// // control globals int g_iDPFLevel = 0; unsigned long g_uDPFMask = 0x0; //----------------------------------------------------------------------------- // // RRDebugPrintf(L) - Utilities to print varargs-formatted strings of debugging // info. The 'L' version takes a level into account in deciding to print or // not. // //----------------------------------------------------------------------------- void RRDebugPrintf( const char* pszFormat, ... ) { char tmp[1024] = "D3DRR: "; va_list marker; va_start(marker, pszFormat); _vsnprintf(tmp+lstrlen(tmp), 1024-lstrlen(tmp), pszFormat, marker); OutputDebugString(tmp); printf(tmp); } void RRDebugPrintfL( int iLevel, const char* pszFormat, ... ) { if ( (iLevel <= g_iDPFLevel) ) { char tmp[1024] = "D3DRR: "; va_list marker; va_start(marker, pszFormat); _vsnprintf(tmp+lstrlen(tmp), 1024-lstrlen(tmp), pszFormat, marker); OutputDebugString(tmp); printf(tmp); } } /////////////////////////////////////////////////////////////////////////////// // // Assert Reporting // /////////////////////////////////////////////////////////////////////////////// // little-bit-o-state to track file and line number reporting - this is makes // this code non-reentrant and non-threadsafe... oh well... static const char* _pszLastReportFile = NULL; static int _iLastReportLine = -1; //----------------------------------------------------------------------------- void RRAssertReport( const char* pszString, const char* pszFile, int iLine ) { char szNum[33]; _itoa( iLine, szNum, 10 ); char szTmp[ 1024 ] = "D3DRR ASSERT: <"; strcat( szTmp, szNum ); char* pCur = szTmp + strlen( szTmp ); char* const pEnd = szTmp + sizeof( szTmp ) / sizeof( szTmp[ 0 ] ) - 1; if( pCur < pEnd ) { const char szNext[] = ","; strncpy( pCur, szNext, pEnd - pCur ); pCur += sizeof( szNext ) / sizeof( szNext[ 0 ] ) - 1; pCur = min( pCur, pEnd ); } if( pCur < pEnd ) { const size_t uiFileLen = strlen( pszFile ); strncpy( pCur, pszFile, pEnd - pCur ); pCur += uiFileLen; pCur = min( pCur, pEnd ); } if( pCur < pEnd ) { const char szNext[] = "> "; strncpy( pCur, szNext, pEnd - pCur ); pCur += sizeof( szNext ) / sizeof( szNext[ 0 ] ) - 1; pCur = min( pCur, pEnd ); } if( pCur < pEnd ) { const size_t uiStringLen = strlen( pszString ); strncpy( pCur, pszString, pEnd - pCur ); pCur += uiStringLen; pCur = min( pCur, pEnd ); } if( pCur < pEnd ) { const char szNext[] = "\n"; strncpy( pCur, szNext, pEnd - pCur ); pCur += sizeof( szNext ) / sizeof( szNext[ 0 ] ) - 1; pCur = min( pCur, pEnd ); } *pEnd = '\0'; OutputDebugString( szTmp ); } //----------------------------------------------------------------------------- void RRAssertReportPrefix( const char* pszFile, int iLine ) { _pszLastReportFile = pszFile; _iLastReportLine = iLine; } //----------------------------------------------------------------------------- void RRAssertReportMessage( const char* pszFormat, ... ) { char szTmp[1024]; va_list marker; va_start( marker, pszFormat ); _vsnprintf( szTmp, 1024, pszFormat, marker ); RRAssertReport( szTmp, _pszLastReportFile, _iLastReportLine ); } /////////////////////////////////////////////////////////////////////////////// // // // Generic bit twiddling utilities // // // /////////////////////////////////////////////////////////////////////////////// //----------------------------------------------------------------------------- // // CountSetBits - Returns number of set bits in a multibit value (up to // 32 bits). // //----------------------------------------------------------------------------- INT32 CountSetBits( UINT32 uVal, INT32 nBits ) { INT32 iRet = 0; for (INT32 i=0; i=0; i--) { if (uVal & (0x1<