ezEngine  Milestone 7
TextureResource.h
1 #pragma once
2 
3 #include <RendererCore/Basics.h>
4 #include <Core/ResourceManager/Resource.h>
5 #include <Core/ResourceManager/ResourceTypeLoader.h>
6 #include <Foundation/IO/MemoryStream.h>
7 #include <CoreUtils/Image/Image.h>
8 #include <RendererFoundation/Basics.h>
9 #include <RendererFoundation/Descriptors/Descriptors.h>
10 
12 
15 {
17  {
20  }
21 
24 
27 
30 
33 };
34 
35 class EZ_RENDERERCORE_DLL ezTextureResource : public ezResource<ezTextureResource, ezTextureResourceDescriptor>
36 {
38 
39 public:
41 
44 
45 private:
46  virtual ezResourceLoadDesc UnloadData(Unload WhatToUnload) override;
47  virtual ezResourceLoadDesc UpdateContent(ezStreamReaderBase* Stream) override;
48  virtual void UpdateMemoryUsage(MemoryUsage& out_NewMemoryUsage) override;
49  virtual ezResourceLoadDesc CreateResource(const ezTextureResourceDescriptor& descriptor) override;
50 
51 private:
52  friend class ezRenderContext;
53 
54  const ezGALResourceViewHandle& GetGALTextureView() const { return m_hGALTexView[m_uiLoadedTextures - 1]; }
55  const ezGALTextureHandle& GetGALTexture() const { return m_hGALTexture[m_uiLoadedTextures - 1]; }
56  const ezGALSamplerStateHandle& GetGALSamplerState() const { return m_hSamplerState; }
57 
58 private:
59  ezUInt8 m_uiLoadedTextures;
60  ezGALTextureHandle m_hGALTexture[2];
61  ezGALResourceViewHandle m_hGALTexView[2];
62  ezUInt32 m_uiMemoryGPU[2];
63  ezGALSamplerStateHandle m_hSamplerState; // HACK
64 };
65 
66 
67 class EZ_RENDERERCORE_DLL ezTextureResourceLoader : public ezResourceTypeLoader
68 {
69 public:
70 
71  struct LoadedData
72  {
73  LoadedData() : m_Reader(&m_Storage) { }
74 
75  ezMemoryStreamStorage m_Storage;
76  ezMemoryStreamReader m_Reader;
77  ezImage m_Image;
78  };
79 
80  virtual ezResourceLoadData OpenDataStream(const ezResourceBase* pResource) override;
81  virtual void CloseDataStream(const ezResourceBase* pResource, const ezResourceLoadData& LoaderData) override;
82  virtual bool IsResourceOutdated(const ezResourceBase* pResource) const override;
83 };
84 
85