LCOV - code coverage report
Current view: top level - source/renderer/backend/vulkan - Texture.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 18 0.0 %
Date: 2023-01-19 00:18:29 Functions: 0 18 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2023 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #ifndef INCLUDED_RENDERER_BACKEND_VULKAN_TEXTURE
      19             : #define INCLUDED_RENDERER_BACKEND_VULKAN_TEXTURE
      20             : 
      21             : #include "renderer/backend/ITexture.h"
      22             : #include "renderer/backend/Sampler.h"
      23             : #include "renderer/backend/vulkan/VMA.h"
      24             : 
      25             : #include <glad/vulkan.h>
      26             : #include <memory>
      27             : 
      28             : namespace Renderer
      29             : {
      30             : 
      31             : namespace Backend
      32             : {
      33             : 
      34             : namespace Vulkan
      35             : {
      36             : 
      37             : class CDevice;
      38             : 
      39             : class CTexture final : public ITexture
      40             : {
      41             : public:
      42             :     ~CTexture() override;
      43             : 
      44             :     IDevice* GetDevice() override;
      45             : 
      46           0 :     Type GetType() const override { return m_Type; }
      47           0 :     uint32_t GetUsage() const override { return m_Usage; }
      48           0 :     Format GetFormat() const override { return m_Format; }
      49             : 
      50           0 :     uint32_t GetWidth() const override { return m_Width; }
      51           0 :     uint32_t GetHeight() const override { return m_Height; }
      52           0 :     uint32_t GetMIPLevelCount() const override { return m_MIPLevelCount; }
      53           0 :     uint32_t GetSampleCount() const { return m_SampleCount; }
      54           0 :     uint32_t GetLayerCount() const { return m_LayerCount; }
      55             : 
      56           0 :     VkImage GetImage() { return m_Image; }
      57           0 :     VkImageView GetAttachmentImageView() { return m_AttachmentImageView; }
      58           0 :     VkImageView GetSamplerImageView() { return m_SamplerImageView; }
      59           0 :     VkSampler GetSampler() { return m_Sampler; }
      60           0 :     bool IsCompareEnabled() { return m_IsCompareEnabled; }
      61           0 :     VkFormat GetVkFormat() const { return m_VkFormat; }
      62             : 
      63           0 :     VkImageAspectFlags GetAttachmentImageAspectMask() { return m_AttachmentImageAspectMask; }
      64             :     VkImageAspectFlags GetSamplerImageAspectMask() { return m_SamplerImageAspectMask; }
      65             : 
      66           0 :     bool IsInitialized() const { return m_Initialized; }
      67           0 :     void SetInitialized() { m_Initialized = true; }
      68             : 
      69             :     /**
      70             :      * @return UID of the texture. It's unique along all textures during a whole
      71             :      * application run. We assume that 32bits should be enough, else we'd have
      72             :      * a too big texture flow.
      73             :      */
      74             :     using UID = uint32_t;
      75           0 :     UID GetUID() const { return m_UID; }
      76             : 
      77             : private:
      78             :     friend class CDevice;
      79             :     friend class CSwapChain;
      80             : 
      81             :     CTexture();
      82             : 
      83             :     static std::unique_ptr<CTexture> Create(
      84             :         CDevice* device, const char* name, const Type type, const uint32_t usage,
      85             :         const Format format, const uint32_t width, const uint32_t height,
      86             :         const Sampler::Desc& defaultSamplerDesc,
      87             :         const uint32_t MIPLevelCount, const uint32_t sampleCount);
      88             : 
      89             :     static std::unique_ptr<CTexture> WrapBackbufferImage(
      90             :         CDevice* device, const char* name, const VkImage image, const VkFormat format,
      91             :         const VkImageUsageFlags usage, const uint32_t width, const uint32_t height);
      92             : 
      93             :     Type m_Type = Type::TEXTURE_2D;
      94             :     uint32_t m_Usage = 0;
      95             :     Format m_Format = Format::UNDEFINED;
      96             :     VkFormat m_VkFormat = VK_FORMAT_UNDEFINED;
      97             :     uint32_t m_Width = 0;
      98             :     uint32_t m_Height = 0;
      99             :     uint32_t m_MIPLevelCount = 0;
     100             :     uint32_t m_SampleCount = 0;
     101             :     uint32_t m_LayerCount = 0;
     102             : 
     103             :     CDevice* m_Device = nullptr;
     104             : 
     105             :     VkImage m_Image = VK_NULL_HANDLE;
     106             :     VkImageView m_AttachmentImageView = VK_NULL_HANDLE;
     107             :     VkImageView m_SamplerImageView = VK_NULL_HANDLE;
     108             :     VkSampler m_Sampler = VK_NULL_HANDLE;
     109             :     bool m_IsCompareEnabled = false;
     110             :     VmaAllocation m_Allocation{};
     111             : 
     112             :     UID m_UID = 0;
     113             : 
     114             :     // Sampler image aspect mask is submask of the attachment one. As we can't
     115             :     // have both VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT for
     116             :     // VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL.
     117             :     VkImageAspectFlags m_AttachmentImageAspectMask = 0;
     118             :     VkImageAspectFlags m_SamplerImageAspectMask = 0;
     119             : 
     120             :     // We store a flag of all subresources, we don't have to handle them separately.
     121             :     // It's safe to store the current state while we use a single device command
     122             :     // context.
     123             :     bool m_Initialized = false;
     124             : };
     125             : 
     126             : } // namespace Vulkan
     127             : 
     128             : } // namespace Backend
     129             : 
     130             : } // namespace Renderer
     131             : 
     132             : #endif // INCLUDED_RENDERER_BACKEND_VULKAN_TEXTURE

Generated by: LCOV version 1.13