Texture.h 3.3 KB

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