Texture.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #pragma once
  2. #include "Critical.h"
  3. #include "Point.h"
  4. #include "ReferenceCounter.h"
  5. struct ID3D11Texture2D;
  6. struct ID3D11ShaderResourceView;
  7. struct ID3D11Device;
  8. struct ID3D11DeviceContext;
  9. namespace Framework
  10. {
  11. class Image; //! Image.h
  12. class Render3D; //! Render3D.h
  13. class TextureList; //! TextureList.h
  14. class DX12CopyCommandQueue;
  15. class DX12DirectCommandQueue;
  16. //! Converts an image to a texture that can be passed to the graphics
  17. //! card for rendering
  18. class Texture : public virtual ReferenceCounter
  19. {
  20. protected:
  21. Image* bild;
  22. bool changed;
  23. Point lastGr;
  24. int id;
  25. public:
  26. //! Constructor
  27. DLLEXPORT Texture();
  28. //! Destructor
  29. DLLEXPORT virtual ~Texture();
  30. //! Sets a pointer to the image that contains the texture
  31. //! \param b The pointer to the image
  32. DLLEXPORT void setImageZ(Image* b);
  33. //! Sets the image that contains the texture by copying it
  34. //! \param b The image to copy
  35. DLLEXPORT void setImage(Image* b);
  36. //! Updates the texture. The pixels of the current image are copied
  37. //! to graphics memory
  38. DLLEXPORT virtual bool updateTextur() = 0;
  39. //! Returns true if updateTextur needs to be called
  40. DLLEXPORT virtual bool needsUpdate() const = 0;
  41. //! Returns a pointer to the image
  42. DLLEXPORT Image* getImage() const;
  43. //! Returns a pointer to the image without increased reference counter
  44. DLLEXPORT Image* zImage() const;
  45. //! Returns the id of the texture if it was registered in a TextureList.
  46. //! (see Framework::zTextureRegister())
  47. DLLEXPORT int getId() const;
  48. friend TextureList;
  49. };
  50. //! Converts an image to a texture that can be passed to the graphics
  51. //! card for rendering
  52. class DX9Texture : public Texture
  53. {
  54. public:
  55. //! Updates the texture. The pixels of the current image are copied
  56. //! to graphics memory
  57. DLLEXPORT virtual bool updateTextur() override;
  58. //! Returns true if updateTextur needs to be called
  59. DLLEXPORT virtual bool needsUpdate() const override;
  60. };
  61. class DX11Texture : public Texture
  62. {
  63. private:
  64. ID3D11Texture2D* txt;
  65. ID3D11ShaderResourceView* view;
  66. ID3D11Device* device;
  67. ID3D11DeviceContext* context;
  68. bool renderTarget;
  69. bool useMips;
  70. Critical& deviceLock;
  71. public:
  72. DLLEXPORT DX11Texture(ID3D11Device* device,
  73. ID3D11DeviceContext* context,
  74. Critical& deviceLock);
  75. DLLEXPORT ~DX11Texture();
  76. //! Updates the texture. The pixels of the current image are copied
  77. //! to graphics memory
  78. DLLEXPORT bool updateTextur() override;
  79. //! Returns true if updateTextur needs to be called
  80. DLLEXPORT bool needsUpdate() const override;
  81. //! Returns the used shader resource view
  82. DLLEXPORT operator ID3D11ShaderResourceView*() const;
  83. //! Returns the used texture
  84. DLLEXPORT operator ID3D11Texture2D*() const;
  85. //! specifies that this texture is used as a render target
  86. DLLEXPORT void setRenderTarget(bool rt);
  87. //! specifies if a mip map should be generated
  88. DLLEXPORT void setUseMips(bool useMips);
  89. //! copy the texture to an image
  90. DLLEXPORT void copyToImage(Image* zB);
  91. };
  92. } // namespace Framework