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 8 Lighting / LitColumns / FrameResource.h < prev    next >
Encoding:
C/C++ Source or Header  |  2016-03-02  |  2.6 KB  |  70 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.     DirectX::XMFLOAT4X4 TexTransform = MathHelper::Identity4x4();
  11. };
  12.  
  13. struct PassConstants
  14. {
  15.     DirectX::XMFLOAT4X4 View = MathHelper::Identity4x4();
  16.     DirectX::XMFLOAT4X4 InvView = MathHelper::Identity4x4();
  17.     DirectX::XMFLOAT4X4 Proj = MathHelper::Identity4x4();
  18.     DirectX::XMFLOAT4X4 InvProj = MathHelper::Identity4x4();
  19.     DirectX::XMFLOAT4X4 ViewProj = MathHelper::Identity4x4();
  20.     DirectX::XMFLOAT4X4 InvViewProj = MathHelper::Identity4x4();
  21.     DirectX::XMFLOAT3 EyePosW = { 0.0f, 0.0f, 0.0f };
  22.     float cbPerObjectPad1 = 0.0f;
  23.     DirectX::XMFLOAT2 RenderTargetSize = { 0.0f, 0.0f };
  24.     DirectX::XMFLOAT2 InvRenderTargetSize = { 0.0f, 0.0f };
  25.     float NearZ = 0.0f;
  26.     float FarZ = 0.0f;
  27.     float TotalTime = 0.0f;
  28.     float DeltaTime = 0.0f;
  29.  
  30.     DirectX::XMFLOAT4 AmbientLight = { 0.0f, 0.0f, 0.0f, 1.0f };
  31.  
  32.     // Indices [0, NUM_DIR_LIGHTS) are directional lights;
  33.     // indices [NUM_DIR_LIGHTS, NUM_DIR_LIGHTS+NUM_POINT_LIGHTS) are point lights;
  34.     // indices [NUM_DIR_LIGHTS+NUM_POINT_LIGHTS, NUM_DIR_LIGHTS+NUM_POINT_LIGHT+NUM_SPOT_LIGHTS)
  35.     // are spot lights for a maximum of MaxLights per object.
  36.     Light Lights[MaxLights];
  37. };
  38.  
  39. struct Vertex
  40. {
  41.     DirectX::XMFLOAT3 Pos;
  42.     DirectX::XMFLOAT3 Normal;
  43. };
  44.  
  45. // Stores the resources needed for the CPU to build the command lists
  46. // for a frame.  
  47. struct FrameResource
  48. {
  49. public:
  50.     
  51.     FrameResource(ID3D12Device* device, UINT passCount, UINT objectCount, UINT materialCount);
  52.     FrameResource(const FrameResource& rhs) = delete;
  53.     FrameResource& operator=(const FrameResource& rhs) = delete;
  54.     ~FrameResource();
  55.  
  56.     // We cannot reset the allocator until the GPU is done processing the commands.
  57.     // So each frame needs their own allocator.
  58.     Microsoft::WRL::ComPtr<ID3D12CommandAllocator> CmdListAlloc;
  59.  
  60.     // We cannot update a cbuffer until the GPU is done processing the commands
  61.     // that reference it.  So each frame needs their own cbuffers.
  62.    // std::unique_ptr<UploadBuffer<FrameConstants>> FrameCB = nullptr;
  63.     std::unique_ptr<UploadBuffer<PassConstants>> PassCB = nullptr;
  64.     std::unique_ptr<UploadBuffer<MaterialConstants>> MaterialCB = nullptr;
  65.     std::unique_ptr<UploadBuffer<ObjectConstants>> ObjectCB = nullptr;
  66.  
  67.     // Fence value to mark commands up to this fence point.  This lets us
  68.     // check if these frame resources are still in use by the GPU.
  69.     UINT64 Fence = 0;
  70. };