ezEngine  Milestone 7
ConstantBufferResource.h
1 #pragma once
2 
3 #include <RendererCore/Basics.h>
4 #include <Core/ResourceManager/Resource.h>
5 #include <RendererFoundation/Basics.h>
6 
8 
10 {
11 protected:
12  ezConstantBufferResourceDescriptorBase() { m_pBytes = nullptr; m_uiSize = 0; }
13 
14  friend class ezConstantBufferResource;
15  ezUInt8* m_pBytes;
16  ezUInt32 m_uiSize;
17 };
18 
19 template<typename STRUCT>
21 {
23  {
24  m_pBytes = reinterpret_cast<ezUInt8*>(&m_Data);
25  m_uiSize = sizeof(STRUCT);
26  }
27 
28  STRUCT m_Data;
29 };
30 
32 {
34  {
35  m_Data.SetCount(uiBytes);
36 
37  m_pBytes = m_Data.GetData();
38  m_uiSize = uiBytes;
39  }
40 
42 };
43 
44 class EZ_RENDERERCORE_DLL ezConstantBufferResource : public ezResource<ezConstantBufferResource, ezConstantBufferResourceDescriptorBase>
45 {
47 
48 public:
50 
51 private:
52  virtual ezResourceLoadDesc UnloadData(Unload WhatToUnload) override;
53  virtual ezResourceLoadDesc UpdateContent(ezStreamReaderBase* Stream) override;
54  virtual void UpdateMemoryUsage(MemoryUsage& out_NewMemoryUsage) override;
56 
57 
58 private:
59  friend class ezRenderContext;
60  ezGALBufferHandle GetGALBufferHandle() const { return m_hGALConstantBuffer; }
61 
62  void UploadStateToGPU(ezGALContext* pContext);
63 
64  bool m_bHasBeenModified;
65  ezGALBufferHandle m_hGALConstantBuffer;
67 };