microsoft / DirectX-Graphics-Samples

This repo contains the DirectX Graphics samples that demonstrate how to build graphics intensive applications on Windows.
MIT License
5.96k stars 2.02k forks source link

Convert UWP samples to use C++/WinRT instead of C++/CX #723

Open Gavin-Williams opened 3 years ago

Gavin-Williams commented 3 years ago

For a while now, Microsoft have been saying to use C++/WinRT instead of C++/CX. Why then, are these samples still using C++/CX?

When will we get good resources explaining and showing how to use C++/WinRT and DirectX together? Do they exist already and I just can't find them?

walbourn commented 3 years ago

The use of C++/CX vs. C++/WinRT is pretty much orthogonal to the use of DirectX. The samples use C++/CX to establish the UWP window and message loop, but the bulk of the samples are pure C++ using DirectX via COM.

If you want some examples of a C++/WinRT 'basic window message loop', take a look at directx-vs-templates.

Gavin-Williams commented 2 years ago

@walbourn Thanks for that clarification. I would like to mention though, that it's confusing and presents a barrier when official samples use technology that is either deprecated or not-recommended, and in this case, not even supported. It's hard enough working this stuff out given that there is a combination of complex technologies: C++, DirectX and C++/WinRT, without throwing in the extra difficulty that the code you present as official examples does not even work in the current application development environment. Why would you leave it the way it is?

It just seems like there is something lacking in the presentation of graphics technologies over at Microsoft. No one writing a DirectX tutorial today would use C++/CX. Updating this example code should be on your timeline I would think.

walbourn commented 2 years ago

I agree that would if UWP version of these samples was being written now, they would use C++/WinRT and not C++/CX. I can mark this as a TODO, but since we already have working UWP samples I'm not sure how much priority it will be given.

walbourn commented 2 years ago

If you could, please rename the issue to Convert UWP samples to use C++/WinRT instead of C++/CX

MRahilly commented 2 years ago

The samples in Petzold's PW6 which are largely UWP should be translated to C++/WinRT.

walbourn commented 2 years ago

The samples in Petzold's PW6 which are largely UWP should be translated to C++/WinRT.

To be fair, that book was written for Windows 8 which predates C++/WinRT projections.

MRahilly commented 2 years ago

I find that the book samples work well when translated to C++/WInRT. A few Windows 8 API's have been replaced but this is well documented. The biggest problem is trying to recode things like C++/CX CancellationTokenSource which appear to have come across from .NET. The C# versions of the samples are quite resilient.

I translated the Chapter 3 - Basic Event Handling samples from C++/CX to C++/WinRT and then to the Rust Crate for Windows (replacing the Xaml markup with API calls) and these samples run perfectly.

Finding small complete working samples that showcase WinRT features is a problem. This was a Petzold strong point. PW6 is a great resource that deserves samples updated for C++/WinRT.