home *** CD-ROM | disk | FTP | other *** search
/ Introduction to 3D Game …ogramming with DirectX 12 / Introduction-to-3D-Game-Programming-with-DirectX-12.ISO / Code.Textures / Chapter 7 Drawing in Direct3D Part II / LandAndWaves / FrameResource.h < prev    next >
Encoding:
C/C++ Source or Header  |  2016-03-02  |  2.2 KB  |  63 lines

  1. #pragma once
  2.  
  3. #include "../../Common/d3dUtil.h"
  4. #include "../../Common/MathHelper.h"
  5. #include "../../Common/UploadBuffer.h"
  6.  
  7. struct ObjectConstants
  8. {
  9.     DirectX::XMFLOAT4X4 World = MathHelper::Identity4x4();
  10. };
  11.  
  12. struct PassConstants
  13. {
  14.     DirectX::XMFLOAT4X4 View = MathHelper::Identity4x4();
  15.     DirectX::XMFLOAT4X4 InvView = MathHelper::Identity4x4();
  16.     DirectX::XMFLOAT4X4 Proj = MathHelper::Identity4x4();
  17.     DirectX::XMFLOAT4X4 InvProj = MathHelper::Identity4x4();
  18.     DirectX::XMFLOAT4X4 ViewProj = MathHelper::Identity4x4();
  19.     DirectX::XMFLOAT4X4 InvViewProj = MathHelper::Identity4x4();
  20.     DirectX::XMFLOAT3 EyePosW = { 0.0f, 0.0f, 0.0f };
  21.     float cbPerObjectPad1 = 0.0f;
  22.     DirectX::XMFLOAT2 RenderTargetSize = { 0.0f, 0.0f };
  23.     DirectX::XMFLOAT2 InvRenderTargetSize = { 0.0f, 0.0f };
  24.     float NearZ = 0.0f;
  25.     float FarZ = 0.0f;
  26.     float TotalTime = 0.0f;
  27.     float DeltaTime = 0.0f;
  28. };
  29.  
  30. struct Vertex
  31. {
  32.     DirectX::XMFLOAT3 Pos;
  33.     DirectX::XMFLOAT4 Color;
  34. };
  35.  
  36. // Stores the resources needed for the CPU to build the command lists
  37. // for a frame.  
  38. struct FrameResource
  39. {
  40. public:
  41.     
  42.     FrameResource(ID3D12Device* device, UINT passCount, UINT objectCount, UINT waveVertCount);
  43.     FrameResource(const FrameResource& rhs) = delete;
  44.     FrameResource& operator=(const FrameResource& rhs) = delete;
  45.     ~FrameResource();
  46.  
  47.     // We cannot reset the allocator until the GPU is done processing the commands.
  48.     // So each frame needs their own allocator.
  49.     Microsoft::WRL::ComPtr<ID3D12CommandAllocator> CmdListAlloc;
  50.  
  51.     // We cannot update a cbuffer until the GPU is done processing the commands
  52.     // that reference it.  So each frame needs their own cbuffers.
  53.     std::unique_ptr<UploadBuffer<PassConstants>> PassCB = nullptr;
  54.     std::unique_ptr<UploadBuffer<ObjectConstants>> ObjectCB = nullptr;
  55.  
  56.     // We cannot update a dynamic vertex buffer until the GPU is done processing
  57.     // the commands that reference it.  So each frame needs their own.
  58.     std::unique_ptr<UploadBuffer<Vertex>> WavesVB = nullptr;
  59.  
  60.     // Fence value to mark commands up to this fence point.  This lets us
  61.     // check if these frame resources are still in use by the GPU.
  62.     UINT64 Fence = 0;
  63. };