Sign in to follow this  
remigius

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

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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 here
MultiSampleType[] 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[i]))
{
System.Diagnostics.Debug.WriteLine( String.Format("Using {0} multisampling", types[i] ));
settings.presentParams.MultiSample = types[i];
break;
}
}

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this