Mobile Apps
i-phone Apps
Java

3D game Programming

 


There is a way to have a single card share resources among all "different" devices by creating the device as an adapter group. There are several limitations to this approach. See the DirectX documentation for more information on this topic.

Depending on your system, this loop has at least a single iteration. After storing some basic information about the currently active adapter, the code needs to find all the possible display modes this adapter can support in full-screen mode. You'll notice here that the supported display modes can be enumerated directly from the adapter information you are currently enumerating, and that's exactly what this code is doing.
The first thing that happens when a display mode is enumerated is it's checked against a set of minimum and maximum ranges. Most devices support a wide range of modes that nothing would actually want to render at today. A number of years ago, you might have seen games running in a 320x200 full-screen window, but today it just doesn't happen (unless you happen to be playing on a handheld such as Gameboy Advance). The default minimum size the sample framework picks is a 640x480 window, and the maximum isn't set.
Construction Cue


Just because the sample framework picks a minimum size of 640x480, that doesn't mean in full-screen mode the sample framework will choose the smallest possible size. For full-screen mode, the framework picks the best available size, which is almost always the current size of the desktop (which most likely is not 640x480).

After the supported modes that meet the requirements of the framework are added to the list, the current display mode is then added because it is naturally always supported. Finally, the modes themselves are sorted by an implementation of the IComparer interface. See Listing 3.5.
Listing 3.5. Sorting Display Modes

public class DisplayModeSorter : IComparer
{
///
/// Compare two display modes
///
public int Compare(object x, object y)
{
DisplayMode d1 = (DisplayMode)x;
DisplayMode d2 = (DisplayMode)y;

if (d1.Width > d2.Width)
return +1;
if (d1.Width < d2.Width)
return -1;
if (d1.Height > d2.Height)
return +1;
if (d1.Height < d2.Height)
return -1;
if (d1.Format > d2.Format)
return +1;
if (d1.Format < d2.Format)
return -1;
if (d1.RefreshRate > d2.RefreshRate)
return +1;
if (d1.RefreshRate < d2.RefreshRate)
return -1;

// They must be the same, return 0
return 0;
}
}

The IComparer interface allows a simple, quick sort algorithm to be executed on an array or collection. The only method the interface provides is the Compare method, which should return an integernamely, +1 if the left item is greater than the right, -1 if the left item is less than the right, and 0 if the two items are equal. As you can see with the implementation here, the width of the display mode takes the highest precedence, followed by the height, format, and refresh rate. This order dictates the correct behavior when comparing two modes such as 1280x1024 and 1280x768.
Once the modes are sorted, the EnumerateDevices method is called. You can see this method in Listing 3.6.
Listing 3.6. Enumerating Device Types

private static void EnumerateDevices(EnumAdapterInformation adapterInfo,
ArrayList adapterFormatList)
{
// Ignore any exceptions while looking for these device types
DirectXException.IgnoreExceptions();
// Enumerate each Direct3D device type
for(uint i = 0; i < deviceTypeArray.Length; i++)
{
// Create a new device information object
EnumDeviceInformation deviceInfo = new EnumDeviceInformation();

// Store the type
deviceInfo.DeviceType = deviceTypeArray[i];

// Try to get the capabilities
deviceInfo.Caps = Manager.GetDeviceCaps(
(int)adapterInfo.AdapterOrdinal, deviceInfo.DeviceType);

// Get information about each device combination on this device
EnumerateDeviceCombos( adapterInfo, deviceInfo, adapterFormatList);

// Do we have any device combinations?
if (deviceInfo.deviceSettingsList.Count > 0)
{
// Yes, add it
adapterInfo.deviceInfoList.Add(deviceInfo);
}
}
// Turn exception handling back on
DirectXException.EnableExceptions();
}

When looking at this code, you should notice and remember two very important things. Can you guess what they are? If you guessed the calls into the DirectXException class, you win the grand prize. The first one turns off exception throwing in virtually all cases from inside the Managed DirectX assemblies. You might wonder what benefit that would give you, and the answer is performance. Catching and throwing exceptions can be an expensive operation, and this particular code section could have numerous items that normally throw these exceptions. You would expect the enumeration code to execute quickly, so any exceptions that occur are simply ignored, and after the function finishes, normal exception handling is restored. The code itself seems pretty simple, though, so you're probably asking, "Why would this code be prone to throwing exceptions anyway?"
Well, I'm glad you asked, and luckily I just happen to have a good answer. The most common scenario is that the device doesn't support DirectX 9. Maybe you haven't upgraded your video driver and the current video driver doesn't have the necessary code paths. It could be that the card itself is simply too old and incapable of using DirectX 9. Many times, someone enables multimon on his system by including an old peripheral component interconnect (PCI) video card that does not support DirectX 9.
The code in this method tries to get the capabilities and enumerate the various combinations for this adapter, and it tries to get this information for every device type available. The possible device types follow:

* Hardware The most common device type created. The rendering is processed by a piece of hardware (a video card).
* Reference A device that can render with any settings supported by the Direct3D runtime, regardless of whether there is a piece of hardware capable of the processing. All processing happens in software, which means this device type is much too slow in a game.
* Software Unless you've written a software rasterizer (in which case, you're probably beyond this beginners' book), you will never use this option.

Assuming some combination of device settings was found during the enumeration, it is stored in a list. The enumeration class stores a few lists that the sample framework uses later while creating the device. See Listing 3.7 for the EnumerateDeviceCombos method.
Listing 3.7. Enumerating Device Combinations

private static void EnumerateDeviceCombos(EnumAdapterInformation adapterInfo,
EnumDeviceInformation deviceInfo, ArrayList adapterFormatList)
{
// Find out which adapter formats are supported by this device
for each(Format adapterFormat in adapterFormatList)
{
for(int i = 0; i < backbufferFormatsArray.Length; i++)
{
// Go through each windowed mode
bool windowed = false;
do
{
if ((!windowed) && (adapterInfo.displayModeList.Count == 0))
continue; // Nothing here

if (!Manager.CheckDeviceType((int)adapterInfo.AdapterOrdinal,
deviceInfo.DeviceType, adapterFormat,
backbufferFormatsArray[i], windowed))
continue; // Unsupported

// Do we require post pixel shader blending?
if (isPostPixelShaderBlendingRequired)
{
if (!Manager.CheckDeviceFormat(
(int)adapterInfo.AdapterOrdinal,
deviceInfo.DeviceType, adapterFormat,
Usage.QueryPostPixelShaderBlending,
ResourceType.Textures, backbufferFormatsArray[i]))
continue; // Unsupported
}

// If an application callback function has been provided,
// make sure this device is acceptable to the app.
if (deviceCreationInterface != null)
{
if (!deviceCreationInterface.IsDeviceAcceptable(deviceInfo.Caps,
adapterFormat, backbufferFormatsArray[i],windowed))
continue; // Application doesn't like this device
}

// At this point, we have an adapter/device/adapterformat/
// backbufferformat/iswindowed DeviceCombo that is supported
// by the system and acceptable to the app. We still need
// to find one or more suitable depth/stencil buffer format,
// multisample type, and present interval.

EnumDeviceSettingsCombo deviceCombo = new
EnumDeviceSettingsCombo();

// Store the information
deviceCombo.AdapterOrdinal = adapterInfo.AdapterOrdinal;
deviceCombo.DeviceType = deviceInfo.DeviceType;
deviceCombo.AdapterFormat = adapterFormat;
deviceCombo.BackBufferFormat = backbufferFormatsArray[i];
deviceCombo.IsWindowed = windowed;

// Build the depth stencil format and multisample type list
BuildDepthStencilFormatList(deviceCombo);
BuildMultiSampleTypeList(deviceCombo);
if (deviceCombo.multiSampleTypeList.Count == 0)
{
// Nothing to do
continue;
}
// Build the conflict and present lists
BuildConflictList(deviceCombo);
BuildPresentIntervalList(deviceInfo, deviceCombo);

deviceCombo.adapterInformation = adapterInfo;
deviceCombo.deviceInformation = deviceInfo;

// Add the combo to the list of devices
deviceInfo.deviceSettingsList.Add(deviceCombo);
// Flip value so it loops
windowed = !windowed;
}
while (windowed);
}
}
}

Much like earlier methods, this one goes through a list of items (in this case, formats) and creates a new list of valid data. The important item to take away from this method is the call into the IsDeviceAcceptable method. Notice that if false is returned from this method, the device combination is ignored.


 
 

Our Courses

virtualinfocom on Facebook
animation courses, Professional Animation Courses, 2D Animation, Internet, Cd-Presentation, Web development, Web Design, Multimedia Animation , Best Animation Academy India, Animation center india , Animation institute india , Animation training india, Animation classes india , Animations Classes India, Animation courses india , Animation training india , Animation School, Animation colleges , Animation college india , Animation university india, Animation degree india, 2d animation training india, 2d animation institute india, 2d animation courses india, Animation programs india , game development india, game design institute india, game design gaming india, gamedesign institute kolkata, gaming class india, gaming training india, Best web design Academy India, web design center india , web design School, web design institute india , Animation classes india , Animations Classes India, Animation courses india ,Animation training india , Animation college india , Animation university india, web design india, web design training india, 2d animation institute india, 2d animation courses india, web design institute india, Animation degress india , Animation training india, Best animation institute in India, Electronics and Embedded training at Kolkata, Hands on Training on Industrial Electronics and Embedded systems, For ITI, Diploma and Degree Engineering students, Real time projects and Industry interaction, Final year project guidance, Electronics and Embedded training at Kolkata, 1st Electronics and Embedded training in Eastern India
Designed by virtualinfocom