microsoft / DirectXTK12

The DirectX Tool Kit (aka DirectXTK12) is a collection of helper classes for writing DirectX 12 code in C++
https://walbourn.github.io/directx-tool-kit-for-directx-12/
MIT License
1.5k stars 404 forks source link

Have the GeometricPrimitive Create* functions implicitly instantiate the GraphicsMemory singleton object #15

Closed rskryptik61636 closed 7 years ago

rskryptik61636 commented 7 years ago

Hello,

I noticed that if I use any of the GeometricPrimitive Create* functions, a GraphicsMemory object needs to be created in order for the GraphicsMemory singleton to be initialized which is required for GeometricPrimitive objects to be created.

I was wondering if it might be possible for the Create functions to implicitly initialize the GraphicsMemory singleton if necessary as they those functions do not consume the separate GraphicsMemory object that needs to be created. This might be useful for apps that only want to use the GeometricPrimitive class.

rskryptik61636 commented 7 years ago

The GraphicsMemory class is under DirectXTK12\Inc\GraphicsMemory.h. An object of its type needs to be created before any of the GeometricPrimitive's Create functions are called or else the call fails due to the GraphicsMemory class' singleton not being initialized.

On Mon, Jan 2, 2017 at 6:53 PM, Shawn Hargreaves notifications@github.com wrote:

Sorry, what is a GraphicsMemory object? I'm not familiar with that API, and it's not a part of Win2D.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Microsoft/DirectXTK12/issues/15#issuecomment-270044804, or mute the thread https://github.com/notifications/unsubscribe-auth/AAiZxapnd7b6MoOa90pftkAnoxbJtBuxks5rObgQgaJpZM4LZK99 .

walbourn commented 7 years ago

@GraphicsMemory is an explicitly initialized singleton. You must create one before using any of the DirectX Tool Kit classes that need it. I don't use implicit intialization because you must ensure you are calling GraphicsMemory::Commit every frame as part of your present loop.

See the wiki

For the DirectX Tool Kit for DirectX 11 I have the same explicit initialization for GraphicsMemory there which is only needed for the Xbox One XDK platform. In that case, you must provide the constructor some additional parameters (such as the back buffer count of your main swapchain) as well as call Commit every frame. See that wiki.