⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xd3denum.cpp

📁 MFC+D3D编程:在MFC单文档界面下使用D3D9.0进行编程
💻 CPP
📖 第 1 页 / 共 2 页
字号:
            pdc->VPTypes.Append(MIXD_VP);
    }
    
    pdc->VPTypes.Append(SOFT_VP);
}

//-----------------------------------------------------------------------------
// EnumeratePIntervals(): query device caps to add the presentation intervals
// that may deal with flicker or other artifacts.
//-----------------------------------------------------------------------------
void CXD3DEnum::EnumeratePIntervals(DeviceInfo* pdi, DeviceCombo* pdc)
{
	// the default interval (the same as D3DPRESENT_INTERVAL_ONE) is always
	// available; we will put it at the top, to avoid mouse flicker in windowed
	//apps
	pdc->PresentIntervals.Append(D3DPRESENT_INTERVAL_DEFAULT);

	// the immediate interval is always available, but is worth checking...
	if ((pdi->Caps.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE) != 0)
		pdc->PresentIntervals.Append(D3DPRESENT_INTERVAL_IMMEDIATE);

	// the rest are truly hardware-dependant
	if ((pdi->Caps.PresentationIntervals & D3DPRESENT_INTERVAL_TWO) != 0)
		pdc->PresentIntervals.Append(D3DPRESENT_INTERVAL_TWO);

	if ((pdi->Caps.PresentationIntervals & D3DPRESENT_INTERVAL_THREE) != 0)
		pdc->PresentIntervals.Append(D3DPRESENT_INTERVAL_THREE);

	if ((pdi->Caps.PresentationIntervals & D3DPRESENT_INTERVAL_FOUR) != 0)
		pdc->PresentIntervals.Append(D3DPRESENT_INTERVAL_FOUR);	
}

//-----------------------------------------------------------------------------
// EnumerateDeviceCombos(): for a particular device
//-----------------------------------------------------------------------------
HRESULT CXD3DEnum::EnumerateDeviceCombos(DeviceInfo* pdi,
										 DWORDARRAY* pDisplayFormats)
{
	D3DFORMAT fmt;	
	D3DFORMAT bbfmt;
	
	// traverse the passed-in display formats
	for (UINT i = 0; i < pDisplayFormats->Length(); i++)
	{
		fmt = (D3DFORMAT)(*pDisplayFormats)[i];
		
		// traverse the app allowed backbuffer formats
		for (UINT j = 0; j < AppBackBufferFormats.Length(); j++)
		{
			bbfmt = (D3DFORMAT)AppBackBufferFormats[j];
			
			// check each against the app constraint
			if (ALPHABITS(bbfmt) < AppMinAlphaBits)
				continue;
			
			// we'll check if the device supports a display mode-backbuffer
			// formats combination, once for windowed display modes,
			// once for fullscreen modes
			for (UINT k = 0; k < 2; k++)
			{                
				// check for system support
				if (FAILED(m_pd3d->CheckDeviceType(pdi->AdapterOrdinal,
												   pdi->DevType,
												   fmt,
												   bbfmt,
												   k % 2 == 0)))
					continue;
				
				// at this point we have a DeviceCombo supported by the system,
				// but we still need to confirm that it is compatible with
				// other app constraints; we'll fill in a device combo with
				// what we know so far
				
				DeviceCombo dc;
				
				dc.Windowed			= k % 2 == 0;
				dc.AdapterOrdinal   = pdi->AdapterOrdinal;
				dc.DevType          = pdi->DevType;
				dc.DisplayFormat    = fmt;
				dc.BackBufferFormat = bbfmt;
				
				// enumerate VP types (software VP should always be available)
				EnumerateVPTypes(pdi, &dc);

				// enumerate presentation intervals (the default should always
				// be available)
				EnumeratePIntervals(pdi, &dc);

				// check for multisampling requirements
				EnumerateMSTypes(&dc);
				
				if (dc.MSTypes.Length() == 0)
					continue;
				
				// check the depth/stencil requirements
				if (AppUsesDepthBuffer)
				{
					EnumerateDSFormats(&dc);
					
					if (dc.DSFormats.Length() == 0)
						continue;
					
					// gather depth/stecil-multisampling conflicts
					EnumerateDSMSConflicts(&dc);
				}
				
				// met every requirement!
				pdi->DeviceCombos.Append(dc);
			}
		}
	}
	
	return S_OK;
}

//-----------------------------------------------------------------------------
// EnumerateDevices(): Enumerates D3D devices for a particular adapter
//-----------------------------------------------------------------------------
HRESULT CXD3DEnum::EnumerateDevices(AdapterInfo* pai, DWORDARRAY* pDisplayFormats)
{
	HRESULT hr;
	
	DeviceInfo di;
	
	// traverse the device types, there are only three, namely, a HAL device, a
	// reference device and a software device, defined by the D3DDEVTYPE enum
	// with values 1, 2 and 3 respectively
	for (UINT i = 1; i < 4; i++)
	{
		// save members of this device info
		di.AdapterOrdinal = pai->AdapterOrdinal;
		di.DevType = (D3DDEVTYPE)i;
		
		// retrieve and store device capabilities in this device
		// info for inspection later
		if (FAILED(m_pd3d->GetDeviceCaps(di.AdapterOrdinal,
										 di.DevType,
										 &di.Caps)))
			continue;
		
		// get info for each device combo on this device info
		if (FAILED(hr = EnumerateDeviceCombos(&di, pDisplayFormats)))
			return hr;
		
		if (di.DeviceCombos.Length() == 0)
			continue;
		
		// if at least one device combo for this device was found,
		// add it to the corresponding list
		pai->DeviceInfos.Append(di);
	}
	
	return S_OK;
}

//-----------------------------------------------------------------------------
// Enumerate(): available D3D adapters, devices, modes, etc. for the passed-in
// D3D object, a reference to which is mantained by the class.
//-----------------------------------------------------------------------------
HRESULT CXD3DEnum::Enumerate(LPDIRECT3D9 pD3D)
{
	// we need a valid D3D object to continue
    if (pD3D == NULL)
		return E_FAIL;
	
	// keep a local reference to it
	m_pd3d = pD3D;

    HRESULT hr;

    AdapterInfo ai;
    
	DWORDARRAY formats;

    // traverse adapters (usually just one)
	for (UINT i = 0; i < m_pd3d->GetAdapterCount(); i++)
    {
		// identify this adapter (retrieve and store a description)
		ai.AdapterOrdinal = i;
        m_pd3d->GetAdapterIdentifier(i, 0, &ai.AdapterIdentifier);

        D3DFORMAT fmt;
        D3DDISPLAYMODE dm;			

		// we will check adapter modes for compatibility with each of the
		// app defined display formats, resolution and color depth,
		// setup in the constructor
		for (UINT j = 0; j < AppDisplayFormats.Length(); j++)
        {
			// get one of the application defined formats
			fmt = (D3DFORMAT)AppDisplayFormats[j];
            
			// get a list of modes for this adapter that support it
			for (UINT k = 0; k < m_pd3d->GetAdapterModeCount(i, fmt); k++)
            {
				//  retrieve a display mode with an enumeration call
				m_pd3d->EnumAdapterModes(i, fmt, k, &dm);
                
				// check the display mode for resolution, color and 
				// alpha bit depth
				if (dm.Width  < AppMinFullscreenWidth  ||
					dm.Height < AppMinFullscreenHeight ||
                    RGBBITS(dm.Format)   < AppMinRGBBits ||
					ALPHABITS(dm.Format) < AppMinAlphaBits)
                    continue;

				// it meets the requirements, so the current adapter info
				// inherits it, for it is compatible with the app
                ai.DisplayModes.Append(dm);
                
				// append the format to the temp list that we'll use to
				// enumerate devices, if not already there
				if (formats.Find(dm.Format) == -1)
					formats.Append(dm.Format);
            }
        }

        // sort the display modes list so that the smallest and fastest
		// gets to the top of the list (see SortModesCallback)
		ai.DisplayModes.Sort(SortModesCallback);

        // get info for each device on this adapter, providing the formats
		// that met the application requirements
        if (FAILED(hr = EnumerateDevices(&ai, &formats)))
            return hr;

        // if at least one device on this adapter is available and compatible
        // with the app, add the adapterInfo to the list
        if (ai.DeviceInfos.Length() != 0)
            AdapterInfos.Append(ai);

        // clear the format list for the next adapter
		formats.Clear();
    }
    
	return S_OK;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -