[MDX] Checking multisample capabilities (Revisited - .NET question)

Started by
2 comments, last by remigius 18 years, 6 months ago
Hello, I just added multisampling to my MDX app and it works fine, but I'm a bit confused on how to check what level of multisampling is actually supported on the device. The documentation contains a code snippet for Manager.CheckDeviceMultiSampleType I could use, but iirc I'll have to check all possible multisample types with the current device settings to find out if it'll work. And changing the device settings will require new checks, right? Isn't there something like device.Caps.MaxMultiSampleType to check this more easily, or perhaps something similar in the DXUT framework I've missed? [Edited by - remigius on October 7, 2005 5:14:16 AM]
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
Advertisement
Well, I haven't worked too much with MDX, but with my unmanaged DirectX program I am only checking to see if the multisampling levels that I want are supported (2x, 4x, and 6x). I really don't know how often any other ones are used. You might be able to try something similar...
Well, I went with the documented Managed code and especially in combination with the sample framework it turns out to be surprisingly easy to use. You can paste the following code to the end of the sample framework's ModifyDeviceSettings method and voila, scaling multisampling is yours :)

[source lang=c#]// define types you want to support hereMultiSampleType[] types = new MultiSampleType[] { MultiSampleType.EightSamples, MultiSampleType.SixSamples, MultiSampleType.FourSamples, MultiSampleType.TwoSamples, MultiSampleType.None };for (int i = 0; i < types.Length; i++){	if (Manager.CheckDeviceMultiSampleType( 0, settings.DeviceType, settings.AdapterFormat, settings.presentParams.Windowed, types))	{						System.Diagnostics.Debug.WriteLine( String.Format("Using {0} multisampling", types ));		settings.presentParams.MultiSample = types;		break;	}}
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
I was tinkering to make the above code use reflection to check the available multisample types. This way I won't have to add the types manually and any future types will be automatically used. The code for this is quite straightforward and working correctly:

[source lang=c#]System.Reflection.FieldInfo[] fields = typeof(MultiSampleType).GetFields();foreach(System.Reflection.FieldInfo field in fields){					if (field.IsSpecialName) continue; // ignore special fields					MultiSampleType type = (MultiSampleType)field.GetValue(0);	if (Manager.CheckDeviceMultiSampleType( 0, settings.DeviceType, settings.AdapterFormat, settings.presentParams.Windowed, type))	{								settings.presentParams.MultiSample = type;			break;	}}


First I was thinking I'd need to implement a comparator to sort the types ordered by descending quality, but the retrieved fields array already seems in perfect order for this code. My question is, how reliable is the order in which these fields are returned by the .NET reflection?
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!

This topic is closed to new replies.

Advertisement