Texture.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Jolt/Core/Reference.h>
  5. /// Forward declares
  6. class Renderer;
  7. class Surface;
  8. class Texture : public RefTarget<Texture>
  9. {
  10. public:
  11. /// Constructor, called by Renderer::CreateTexture
  12. Texture(Renderer *inRenderer, const Surface *inSurface); // Create a normal texture
  13. Texture(Renderer *inRenderer, int inWidth, int inHeight); // Create a render target (depth only)
  14. ~Texture();
  15. /// Get dimensions of texture
  16. inline int GetWidth() const { return mWidth; }
  17. inline int GetHeight() const { return mHeight; }
  18. /// Bind texture to the pixel shader
  19. void Bind(int inSlot) const;
  20. /// Clear this texture (only possible for render targets)
  21. void ClearRenderTarget();
  22. /// Activate this texture as the current render target, called by Renderer::SetRenderTarget
  23. void SetAsRenderTarget(bool inSet) const;
  24. private:
  25. Renderer * mRenderer;
  26. int mWidth;
  27. int mHeight;
  28. ComPtr<ID3D12Resource> mTexture; ///< The texture data
  29. D3D12_CPU_DESCRIPTOR_HANDLE mSRV { 0 }; ///< Shader resource view to bind as texture
  30. D3D12_CPU_DESCRIPTOR_HANDLE mDSV { 0 }; ///< Depth shader view to bind as render target
  31. };