//-------------------------------------------------------------------------------------- // File: DXUTMisc.h // // Helper functions for Direct3D programming. // // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. // // Copyright (c) Microsoft Corporation. All rights reserved. // // http://go.microsoft.com/fwlink/?LinkId=320437 //-------------------------------------------------------------------------------------- #pragma once //-------------------------------------------------------------------------------------- // XInput helper state/function // This performs extra processing on XInput gamepad data to make it slightly more convenient to use // // Example usage: // // DXUT_GAMEPAD gamepad[4]; // for( DWORD iPort=0; iPortSetPrivateData( WKPDID_D3DDebugObjectName, (UINT)strlen(pstrName), pstrName ); } inline void DXUT_SetDebugName( _In_ ID3D11Device* pObj, _In_z_ const CHAR* pstrName ) { if ( pObj ) pObj->SetPrivateData( WKPDID_D3DDebugObjectName, (UINT)strlen(pstrName), pstrName ); } inline void DXUT_SetDebugName( _In_ ID3D11DeviceChild* pObj, _In_z_ const CHAR* pstrName ) { if ( pObj ) pObj->SetPrivateData( WKPDID_D3DDebugObjectName, (UINT)strlen(pstrName), pstrName ); } #else #define DXUT_SetDebugName( pObj, pstrName ) #endif //-------------------------------------------------------------------------------------- // Some D3DPERF APIs take a color that can be used when displaying user events in // performance analysis tools. The following constants are provided for your // convenience, but you can use any colors you like. //-------------------------------------------------------------------------------------- const DWORD DXUT_PERFEVENTCOLOR = 0xFFC86464; const DWORD DXUT_PERFEVENTCOLOR2 = 0xFF64C864; const DWORD DXUT_PERFEVENTCOLOR3 = 0xFF6464C8; //-------------------------------------------------------------------------------------- // The following macros provide a convenient way for your code to call the D3DPERF // functions only when PROFILE is defined. If PROFILE is not defined (as for the final // release version of a program), these macros evaluate to nothing, so no detailed event // information is embedded in your shipping program. It is recommended that you create // and use three build configurations for your projects: // Debug (nonoptimized code, asserts active, PROFILE defined to assist debugging) // Profile (optimized code, asserts disabled, PROFILE defined to assist optimization) // Release (optimized code, asserts disabled, PROFILE not defined) //-------------------------------------------------------------------------------------- #ifdef PROFILE // PROFILE is defined, so these macros call the D3DPERF functions #define DXUT_BeginPerfEvent( color, pstrMessage ) DXUT_Dynamic_D3DPERF_BeginEvent( color, pstrMessage ) #define DXUT_EndPerfEvent() DXUT_Dynamic_D3DPERF_EndEvent() #define DXUT_SetPerfMarker( color, pstrMessage ) DXUT_Dynamic_D3DPERF_SetMarker( color, pstrMessage ) #else // PROFILE is not defined, so these macros do nothing #define DXUT_BeginPerfEvent( color, pstrMessage ) (__noop) #define DXUT_EndPerfEvent() (__noop) #define DXUT_SetPerfMarker( color, pstrMessage ) (__noop) #endif //-------------------------------------------------------------------------------------- // CDXUTPerfEventGenerator is a helper class that makes it easy to attach begin and end // events to a block of code. Simply define a CDXUTPerfEventGenerator variable anywhere // in a block of code, and the class's constructor will call DXUT_BeginPerfEvent when // the block of code begins, and the class's destructor will call DXUT_EndPerfEvent when // the block ends. //-------------------------------------------------------------------------------------- class CDXUTPerfEventGenerator { public: CDXUTPerfEventGenerator( _In_ DWORD color, _In_z_ LPCWSTR pstrMessage ) { #ifdef PROFILE DXUT_BeginPerfEvent( color, pstrMessage ); #else UNREFERENCED_PARAMETER(color); UNREFERENCED_PARAMETER(pstrMessage); #endif } ~CDXUTPerfEventGenerator() { DXUT_EndPerfEvent(); } }; //-------------------------------------------------------------------------------------- // Multimon handling to support OSes with or without multimon API support. // Purposely avoiding the use of multimon.h so DXUT.lib doesn't require // COMPILE_MULTIMON_STUBS and cause complication with MFC or other users of multimon.h //-------------------------------------------------------------------------------------- #ifndef MONITOR_DEFAULTTOPRIMARY #define MONITORINFOF_PRIMARY 0x00000001 #define MONITOR_DEFAULTTONULL 0x00000000 #define MONITOR_DEFAULTTOPRIMARY 0x00000001 #define MONITOR_DEFAULTTONEAREST 0x00000002 typedef struct tagMONITORINFO { DWORD cbSize; RECT rcMonitor; RECT rcWork; DWORD dwFlags; } MONITORINFO, *LPMONITORINFO; typedef struct tagMONITORINFOEXW : public tagMONITORINFO { WCHAR szDevice[CCHDEVICENAME]; } MONITORINFOEXW, *LPMONITORINFOEXW; typedef MONITORINFOEXW MONITORINFOEX; typedef LPMONITORINFOEXW LPMONITORINFOEX; #endif HMONITOR WINAPI DXUTMonitorFromWindow( _In_ HWND hWnd, _In_ DWORD dwFlags ); HMONITOR WINAPI DXUTMonitorFromRect( _In_ LPCRECT lprcScreenCoords, _In_ DWORD dwFlags ); BOOL WINAPI DXUTGetMonitorInfo( _In_ HMONITOR hMonitor, _Out_ LPMONITORINFO lpMonitorInfo ); void WINAPI DXUTGetDesktopResolution( _In_ UINT AdapterOrdinal, _Out_ UINT* pWidth, _Out_ UINT* pHeight ); //-------------------------------------------------------------------------------------- // Helper functions to create SRGB formats from typeless formats and vice versa //-------------------------------------------------------------------------------------- DXGI_FORMAT MAKE_SRGB( _In_ DXGI_FORMAT format ); DXGI_FORMAT MAKE_TYPELESS( _In_ DXGI_FORMAT format );