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