Click here to Skip to main content
11,706,979 members (45,377 online)
Click here to Skip to main content
Add your own
alternative version

MFC D3D Application: Direct3D Tutorial: Part I

, 9 Dec 2012 CPOL 94.6K 2.7K 114
Yet another Direct3D framework, this time for MFC apps, with a step by step tutorial
//-----------------------------------------------------------------------------
// XD3DSettings.cpp: settings class for the XD3D framework
//-----------------------------------------------------------------------------

#include "stdafx.h"
#include "XD3DSettings.h"

//-----------------------------------------------------------------------------
// Settings constructor: sizes the arrays to 2 growing in 2s, to save some
// memory (the default grow factor is 8, but we only need 2). It also
// initialises the DeviceInfo and DeviceCombo position indices, and defaults
// to Windowed, but notice that we will not get any meaningful values until
// the settings get initialised by the CXD3D class; the values will just
// save an access violation.
//-----------------------------------------------------------------------------

CXD3DSettings::CXD3DSettings()
{
	AdapterInfos.SetGrowFactor(2);
	AdapterInfos.SetLength(2);

	ndm[0] = ndm[1] = ndi[0] = ndi[1] = ndc[0] = ndc[1] = 0;

	Windowed = 1;

	nDSFormat = 0;
};

// adapter info wrapper, based on the windowed index

AdapterInfo* CXD3DSettings::GetAdapterInfo()
{
	return AdapterInfos[Windowed];
}

// device info wrapper, based on the windowed index and the di index

DeviceInfo*  CXD3DSettings::GetDeviceInfo()
{
	return &AdapterInfos[Windowed]->DeviceInfos[ndi[Windowed]];
}

// display mode wrapper, based on the windowed index

D3DDISPLAYMODE CXD3DSettings::GetDisplayMode()
{
	return AdapterInfos[Windowed]->DisplayModes[ndm[Windowed]];
}

// VP type wrapper

VPTYPE CXD3DSettings::GetVPType()
{
	return (VPTYPE)AdapterInfos[Windowed]->
				   DeviceInfos[ndi[Windowed]].
				   DeviceCombos[ndc[Windowed]].
				   VPTypes[0];
}

// back buffer format wrapper

D3DFORMAT CXD3DSettings::GetBackBufferFormat()
{
	return (D3DFORMAT)AdapterInfos[Windowed]->
					  DeviceInfos[ndi[Windowed]].
					  DeviceCombos[ndc[Windowed]].
					  BackBufferFormat;
}

// depth/stencil format wrapper

D3DFORMAT CXD3DSettings::GetDSFormat()
{
	return (D3DFORMAT)AdapterInfos[Windowed]->
					  DeviceInfos[ndi[Windowed]].
					  DeviceCombos[ndc[Windowed]].
					  DSFormats[nDSFormat];
}

// multisampling wrapper

D3DMULTISAMPLE_TYPE CXD3DSettings::GetMSType()
{
	return (D3DMULTISAMPLE_TYPE)AdapterInfos[Windowed]->
								DeviceInfos[ndi[Windowed]].
								DeviceCombos[ndc[Windowed]].
								MSTypes[0];
}

// multisampling quality levels wrapper

DWORD CXD3DSettings::GetMSQuality()
{
	return (DWORD)AdapterInfos[Windowed]->
				  DeviceInfos[ndi[Windowed]].
				  DeviceCombos[ndc[Windowed]].
				  MSQualityLevels[0];
}


// presentation interval wrapper

DWORD CXD3DSettings::GetPresentInterval()
{
	return (DWORD)AdapterInfos[Windowed]->
				  DeviceInfos[ndi[Windowed]].
				  DeviceCombos[ndc[Windowed]].
				  PresentIntervals[0];
}

// Set DS format wrapper

void CXD3DSettings::SetDSFormat(UINT nFmt)
{

	if (nFmt < AdapterInfos[Windowed]->
			   DeviceInfos[ndi[Windowed]].
			   DeviceCombos[ndc[Windowed]].
			   DSFormats.Length())
		nDSFormat = nFmt;
}

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) Code Authority, Inc.
United States United States
Pride in craftsmanship is my new thing.

You may also be interested in...

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