Texture.h 1.3 KB

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