Software rendering mode - WPF
Here's what we did:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
if (ForceSoftwareRendering)
{
HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
HwndTarget hwndTarget = hwndSource.CompositionTarget;
hwndTarget.RenderMode = RenderMode.SoftwareOnly;
}
}
It worked OK for us, EXCEPT... This needs to be done for every Window. In .NET 3.5 there was no way to make the setting take effect application-wide. And there are some windows that you won't have as much control over - for example, right-click "context" windows. We found that there was no good solution for .NET 3.5 except the registry setting.
Edited
Here's the logic we used to determine when to force software rendering. It was suggested by a Microsoft support engineer.
public bool ForceSoftwareRendering
{
get
{
int renderingTier = (System.Windows.Media.RenderCapability.Tier >> 16);
return renderingTier == 0;
}
}
In .NET 4 Microsoft added an application-wide setting that works perfectly for us. Its a much better option because you don't need to set it on every window. You just set it once and it applies to all windows.
System.Windows.Media.RenderOptions.ProcessRenderMode
Edited
The new .NET 4.0 property can be set at application startup like this:
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
if (ForceSoftwareRendering)
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
}
}
How do you determine if WPF is using Hardware or Software Rendering?
Check RenderCapability.Tier
- Graphics Rendering Tiers
- RenderCapability Class
[UPDATE]
- RenderCapability.IsPixelShaderVersionSupported - Gets a value that indicates whether the specified pixel shader version is supported.
- RenderCapability.IsShaderEffectSoftwareRenderingSupported - Gets a value that indicates whether the system can render bitmap effects in software.
- RenderCapability.Tier - Gets a value that indicates the rendering tier for the current thread.
- RenderCapability.TierChanged - Occurs when the rendering tier has changed for the Dispatcher object of the current thread.
RenderCapability.Tier >> 16
- Rendering Tier 0 - No graphics hardware acceleration. The DirectX version level is less than version 7.0.
- Rendering Tier 1 - Partial graphics hardware acceleration. The DirectX version level is greater than or equal to version 7.0, and lesser than version 9.0.
- Rendering Tier 2 - Most graphics features use graphics hardware acceleration. The DirectX version level is greater than or equal to version 9.0.
WPF 4+ software rendering still an issue?
This list is still accurate.
This is covered on MSDN's page regarding Graphics Rendering Tiers. The second labeled as "The following features and capabilities are not hardware accelerated:" lists the specific criteria that can cause non-accellerated rendering in WPF.
This includes:
TileBrush
- Content rendered via
RenderTargetBitmap
- Any printed output
- Surfaces exceeding the graphics hardware's maximum texture size
- Layered windows on Windows XP.
WPF poor rendering of application
try disabling GPU acceleration:
RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
Sometimes WPF GPU caching does a lot of tricks, and this can help, without degrading much performance imo.
WPF rendering lines on window
We have similar issues with big black vertical bars. Only resolved by switching to software only rendering:
System.Windows.Media.RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
Visual Studio WinForm Render Mode
Software rendering is what WinForms do already, for all windows and controls, using GDI and GDI+, you can get started here.
If you want hardware accelerated graphics, you need to use some graphics library, like OpenGL or DirectX.
WPF uses DirectX modules to render, because of this you have such option.
Related Topics
Loop Through All Controls of a Form, Even Those in Groupboxes
How to Hide Desktop Icons Programmatically
Popup's in Selenium Webdrivers
Resolve Type from Class Name in a Different Assembly
Split String into String Array of Single Characters
C# Smtpclient Class Not Able to Send Email Using Gmail
How to Display a File's Properties Dialog from C#
How to Make JSON.Net Serializer to Call Tostring() When Serializing a Particular Type
ASP.NET Core Long Running/Background Task
Run Two Winform Windows Simultaneously
Windows 10 Scrollintoview() Is Not Scrolling to the Items in the Middle of a Listview
A Type for Date Only in C# - Why Is There No Date Type
Await Operator Can Only Be Used Within an Async Method
Convert from Scientific Notation String to Float in C#
Should I Unsubscribe from Events