Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

MFC D3D Application: Direct3D Tutorial: Part I

, 9 Dec 2012 CPOL
Yet another Direct3D framework, this time for MFC apps, with a step by step tutorial
//-----------------------------------------------------------------------------
// XD3DEnum.h.: enumerates D3D adapters, devices, modes, etc.
//-----------------------------------------------------------------------------

#ifndef XD3DENUM_H
#define XD3DENUM_H

// D3D9 util stuff
#include "d3dutil.h"
#include "dxutil.h"

#include "TArray.h"

//-----------------------------------------------------------------------------
// DSMSConflict: a depth/stencil buffer format that is incompatible with a
// multisample type. We'll use an array of them, hence the typedef.
//-----------------------------------------------------------------------------
struct DSMSConflict
{
    D3DFORMAT			fmt;
    D3DMULTISAMPLE_TYPE	mst;
};

typedef CTArray<DSMSConflict> DSMSConflictArray;

//-----------------------------------------------------------------------------
// DeviceCombo class: a combination of adapter format and back buffer format
// that is compatible with a particular D3D device and the application. We
// will also use arrays of DeviceCombos, hence the typedef.
//-----------------------------------------------------------------------------
struct DeviceCombo
{
    int			AdapterOrdinal;			// the host adapter
    D3DDEVTYPE	DevType;
    D3DFORMAT	DisplayFormat;
    D3DFORMAT	BackBufferFormat;
    bool		Windowed;
    
	DWORDARRAY DSFormats;				// List of depth/stencil formats
    DWORDARRAY MSTypes;					// List of D3DMULTISAMPLE_TYPEs
    DWORDARRAY MSQualityLevels;			// List of quality levels for ea. type
    DWORDARRAY VPTypes;					// List of VP Types
    DWORDARRAY PresentIntervals;		// List of D3DPRESENT_INTERVALs

    DSMSConflictArray DSMSConflicts;	// List of DSMSConflicts
};

typedef CTArray<DeviceCombo> DeviceComboArray;

//-----------------------------------------------------------------------------
// DeviceInfo: info about a D3D device, including a list of device combos
// that work with the device; we'll use arrays of these, hence the typedef
//-----------------------------------------------------------------------------
struct DeviceInfo
{
    int			AdapterOrdinal;		// the host adapter
    D3DDEVTYPE	DevType;
    D3DCAPS9	Caps;				// device capabilities
    
	DeviceComboArray DeviceCombos; // List of DeviceCombos
};

typedef CTArray<DeviceInfo> DeviceInfoArray;

// this is a d3d structure we want to use an array of
typedef CTArray<D3DDISPLAYMODE> D3DDISPLAYMODEARRAY;

//-----------------------------------------------------------------------------
// AdapterInfo: info about a display adapter, and a typedef for an array of
// them
//-----------------------------------------------------------------------------
struct AdapterInfo
{
	int						AdapterOrdinal;

	D3DADAPTER_IDENTIFIER9	AdapterIdentifier;

	D3DDISPLAYMODEARRAY DisplayModes;	// List of D3DDISPLAYMODE s

	DeviceInfoArray DeviceInfos;		// List of DeviceInfos
};

typedef CTArray<AdapterInfo> AdapterInfoArray;

//-----------------------------------------------------------------------------
// CXD3DEnum class: enumerates available D3D adapters, devices, modes, etc.
//-----------------------------------------------------------------------------
class CXD3DEnum
{
private:
	// pointer to the IDirect3D9 interface
    LPDIRECT3D9 m_pd3d;

	// implementation, called by EnumerateDeviceCombos
    void	EnumerateDSFormats(DeviceCombo* pdc);
    void	EnumerateMSTypes(DeviceCombo* pdc);
    void	EnumerateDSMSConflicts(DeviceCombo* pdc);
    void	EnumerateVPTypes(DeviceInfo* pdi, DeviceCombo* pdc);
    void	EnumeratePIntervals(DeviceInfo* pdi, DeviceCombo* pdc);

	// device combo enumeration, called by EnumerateDevices
    HRESULT EnumerateDeviceCombos(DeviceInfo* pdi, DWORDARRAY* pDisplayFormats);    

	// device enumeration, called by Enumerate
	HRESULT EnumerateDevices(AdapterInfo* pai, DWORDARRAY* pDisplayFormats);

public:
	// adapter enumeration
	HRESULT Enumerate(LPDIRECT3D9 pD3D);

	// constructor, initialises the app constraints
    CXD3DEnum();	

    // application constraints
    
	UINT AppMinFullscreenWidth;			// app min fullscreen width
    UINT AppMinFullscreenHeight;		// app min fullscreen height

    UINT AppMinRGBBits;					// min RGB bits per channel
    UINT AppMinAlphaBits;				// min alpha bits per pixel
    
	bool AppUsesMixedVP;				// whether the app can take advantage
										// of the mixed VP type

	bool AppUsesDepthBuffer;			// wether the app uses a depth buffer  
    	
	UINT AppMinDepthBits;				// min depth bits
	UINT AppMinStencilBits;				// min stencil bits
    
	DWORDARRAY AppDisplayFormats;		// list of app allowed display formats
	DWORDARRAY AppBackBufferFormats;	// list of app allowed BB formats
	DWORDARRAY AppDepthStencilFormats;	// list of app allowed DS formats
	DWORDARRAY AppMultiSamplingTypes;	// list of app allowed MS types
    
	AdapterInfoArray AdapterInfos;		// list of enumerated AdapterInfos
};

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

hector [.j.] rivas
Software Developer (Senior) CompuCom, Inc.
United States United States
Hector J. Rivas has 25+ years of experience managing hardware and software development under many different operating systems, platforms and languages. He has developed microcontroller interfaces and PC games; authored computer based training lessons and delivered fully functional financial and administrative data-intensive applications, as well as image processing and other calculation-intensive applications. Mr. Rivas has also managed Y2K remediation, large scale platform migration and Web site projects, from R&D to actual deployment.
Follow on   LinkedIn

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141216.1 | Last Updated 9 Dec 2012
Article Copyright 2006 by hector [.j.] rivas
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid