/////////////////////////////////////////////////////////////////////////////// // 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]; _snprintf( (LPSTR) 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]; _snprintf( (LPSTR) 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 szTmp[1024]; _snprintf( szTmp, 1024, "D3DRR ASSERT: <%d,%s> %s", iLine, pszFile, pszString ); 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<