2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "guilib/TextureFormats.h"
16 enum class TEXTURE_SCALING
24 \brief Base texture class, which holds the state of the texture, as well as all conversion functions.
30 CTextureBase() = default;
31 ~CTextureBase() = default;
33 bool HasAlpha() const { return m_textureAlpha
!= KD_TEX_ALPHA_OPAQUE
; }
34 void SetAlpha(bool hasAlpha
)
36 m_textureAlpha
= hasAlpha
? KD_TEX_ALPHA_STRAIGHT
: KD_TEX_ALPHA_OPAQUE
;
39 /*! \brief sets mipmapping. do not use in new code. will be replaced with proper scaling. */
40 void SetMipmapping() { m_mipmapping
= true; }
41 /*! \brief return true if we want to mipmap */
42 bool IsMipmapped() const { return m_mipmapping
; }
44 /*! \brief sets the scaling method. scanout systems might support more than NN/linear. */
45 void SetScalingMethod(TEXTURE_SCALING scalingMethod
) { m_scalingMethod
= scalingMethod
; }
46 /*! \brief returns the scaling method. */
47 TEXTURE_SCALING
GetScalingMethod() const { return m_scalingMethod
; }
49 int32_t GetOrientation() const { return m_orientation
; }
50 void SetOrientation(int orientation
) { m_orientation
= orientation
; }
52 /*! \brief retains a shadow copy of the texture on the CPU side. */
53 void SetCacheMemory(bool bCacheMemory
) { m_bCacheMemory
= bCacheMemory
; }
54 /*! \brief returns true if a shadow copy is kept on the CPU side. */
55 bool GetCacheMemory() const { return m_bCacheMemory
; }
57 /*! \brief returns a pointer to the staging texture. */
58 uint8_t* GetPixels() const { return m_pixels
; }
60 /*! \brief return the size of one row in bytes. */
61 uint32_t GetPitch() const { return GetPitch(m_textureWidth
); }
62 /*! \brief return the number of rows (number of blocks in the Y direction). */
63 uint32_t GetRows() const { return GetRows(m_textureHeight
); }
64 /*! \brief return the total width of the texture, which might be scaled to fit its displayed size. */
65 uint32_t GetTextureWidth() const { return m_textureWidth
; }
66 /*! \brief return the total height of the texture, which might be scaled to fit its displayed size. */
67 uint32_t GetTextureHeight() const { return m_textureHeight
; }
68 /*! \brief return the total width of "active" area, which might be equal or lower than the texture width due to alignment. */
69 uint32_t GetWidth() const { return m_imageWidth
; }
70 /*! \brief return the total height of "active" area, which might be equal or lower than the texture height due to alignment. */
71 uint32_t GetHeight() const { return m_imageHeight
; }
72 /*! \brief return the original width of the image, before scaling/cropping */
73 uint32_t GetOriginalWidth() const { return m_originalWidth
; }
74 /*! \brief return the original height of the image, before scaling/cropping */
75 uint32_t GetOriginalHeight() const { return m_originalHeight
; }
77 // allocates staging texture space.
78 void Allocate(uint32_t width
, uint32_t height
, XB_FMT format
);
81 /*! \brief rounds to power of two. deprecated. */
82 static uint32_t PadPow2(uint32_t x
);
83 /*! \brief swaps the blue/red channel. deprecated in this form. */
84 static bool SwapBlueRed(
85 uint8_t* pixels
, uint32_t height
, uint32_t pitch
, uint32_t elements
= 4, uint32_t offset
= 0);
88 // helpers for computation of texture parameters for compressed textures
89 uint32_t GetPitch(uint32_t width
) const;
90 uint32_t GetRows(uint32_t height
) const;
91 uint32_t GetBlockWidth() const;
92 uint32_t GetBlockHeight() const;
93 /*! \brief return the size of a compression block (tile) in bytes. */
94 uint32_t GetBlockSize() const;
96 void SetKDFormat(XB_FMT xbFMT
);
98 /*! \brief Textures might be in a single/dual channel format with L/A/I/LA swizzle. DX and GLES 2.0 don't
99 handle some/all at the moment. This function can convert the texture into a traditional BGRA format.*/
100 bool ConvertToLegacy(uint32_t width
, uint32_t height
, uint8_t* src
);
102 uint32_t m_imageWidth
{0};
103 uint32_t m_imageHeight
{0};
104 uint32_t m_textureWidth
{0};
105 uint32_t m_textureHeight
{0};
106 uint32_t m_originalWidth
{0}; ///< original image width before scaling or cropping
107 uint32_t m_originalHeight
{0}; ///< original image height before scaling or cropping
109 uint8_t* m_pixels
{nullptr};
110 bool m_loadedToGPU
{false};
112 KD_TEX_FMT m_textureFormat
{KD_TEX_FMT_UNKNOWN
}; // new Kodi texture format
113 KD_TEX_SWIZ m_textureSwizzle
{KD_TEX_SWIZ_RGBA
};
114 KD_TEX_COL m_textureColorspace
{KD_TEX_COL_REC709
};
115 KD_TEX_TRANSFER m_textureTransfer
{KD_TEX_TRANSFER_SRGB
};
116 KD_TEX_ALPHA m_textureAlpha
{KD_TEX_ALPHA_STRAIGHT
};
118 XB_FMT m_format
{XB_FMT_UNKNOWN
}; // legacy XB format, deprecated
119 int32_t m_orientation
{0};
120 bool m_mipmapping
{false};
121 TEXTURE_SCALING m_scalingMethod
{TEXTURE_SCALING::LINEAR
};
122 bool m_bCacheMemory
{false};