1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #pragma once |
4 | |
5 | #include "BsCorePrerequisites.h" |
6 | #include "Image/BsTexture.h" |
7 | #include "RenderAPI/BsRenderTexture.h" |
8 | #include "Utility/BsModule.h" |
9 | |
10 | namespace bs |
11 | { |
12 | /** @addtogroup Resources-Internal |
13 | * @{ |
14 | */ |
15 | |
16 | /** |
17 | * Defines interface for creation of textures. Render systems provide their own implementations. |
18 | * |
19 | * @note Sim thread only. |
20 | */ |
21 | class BS_CORE_EXPORT TextureManager : public Module<TextureManager> |
22 | { |
23 | public: |
24 | virtual ~TextureManager() = default; |
25 | |
26 | /** @copydoc Texture::create(const TEXTURE_DESC&) */ |
27 | SPtr<Texture> createTexture(const TEXTURE_DESC& desc); |
28 | |
29 | /** |
30 | * Creates a new 2D or 3D texture initialized using the provided pixel data. Texture will not have any mipmaps. |
31 | * |
32 | * @param[in] desc Description of the texture to create. Must match the pixel data. |
33 | * @param[in] pixelData Data to initialize the texture width. |
34 | */ |
35 | SPtr<Texture> createTexture(const TEXTURE_DESC& desc, const SPtr<PixelData>& pixelData); |
36 | |
37 | /** |
38 | * Creates a completely empty and uninitialized Texture. |
39 | * |
40 | * @note |
41 | * Internal method. Should only be used for very specific purposes, like deserialization, as it requires additional |
42 | * manual initialization that is not required normally. |
43 | */ |
44 | SPtr<Texture> _createEmpty(); |
45 | |
46 | /** |
47 | * Creates a new RenderTexture and automatically generates a single color surface and (optionally) a depth/stencil |
48 | * surface. |
49 | * |
50 | * @param[in] colorDesc Description of the color surface to create. |
51 | * @param[in] createDepth Determines will a depth/stencil buffer of the same size as the color buffer be |
52 | * created for the render texture. |
53 | * @param[in] depthStencilFormat Format of the depth/stencil buffer if enabled. |
54 | */ |
55 | virtual SPtr<RenderTexture> createRenderTexture(const TEXTURE_DESC& colorDesc, |
56 | bool createDepth = true, PixelFormat depthStencilFormat = PF_D32); |
57 | |
58 | /** |
59 | * Creates a RenderTexture using the description struct. |
60 | * |
61 | * @param[in] desc Description of the render texture to create. |
62 | */ |
63 | virtual SPtr<RenderTexture> createRenderTexture(const RENDER_TEXTURE_DESC& desc); |
64 | |
65 | /** |
66 | * Gets the format which will be natively used for a requested format given the constraints of the current device. |
67 | * |
68 | * @note Thread safe. |
69 | */ |
70 | virtual PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma) = 0; |
71 | |
72 | protected: |
73 | /** |
74 | * Creates an empty and uninitialized render texture of a specific type. This is to be implemented by render |
75 | * systems with their own implementations. |
76 | */ |
77 | virtual SPtr<RenderTexture> createRenderTextureImpl(const RENDER_TEXTURE_DESC& desc) = 0; |
78 | |
79 | mutable HTexture mDummyTexture; |
80 | }; |
81 | |
82 | namespace ct |
83 | { |
84 | /** |
85 | * Defines interface for creation of textures. Render systems provide their own implementations. |
86 | * |
87 | * @note Core thread only. |
88 | */ |
89 | class BS_CORE_EXPORT TextureManager : public Module<TextureManager> |
90 | { |
91 | public: |
92 | virtual ~TextureManager() = default; |
93 | |
94 | /** @copydoc Module::onStartUp */ |
95 | void onStartUp() override; |
96 | |
97 | /** @copydoc Module::onShutDown */ |
98 | void onShutDown() override; |
99 | |
100 | /** |
101 | * @copydoc bs::TextureManager::createTexture(const TEXTURE_DESC&) |
102 | * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on. |
103 | */ |
104 | SPtr<Texture> createTexture(const TEXTURE_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT); |
105 | |
106 | /** |
107 | * @copydoc bs::TextureManager::createRenderTexture(const RENDER_TEXTURE_DESC&) |
108 | * @param[in] deviceIdx Index of the GPU device to create the object on. |
109 | */ |
110 | SPtr<RenderTexture> createRenderTexture(const RENDER_TEXTURE_DESC& desc, UINT32 deviceIdx = 0); |
111 | |
112 | protected: |
113 | friend class bs::Texture; |
114 | friend class Texture; |
115 | friend class bs::RenderTexture; |
116 | |
117 | /** |
118 | * Creates an empty and uninitialized texture of a specific type. This is to be implemented by render systems with |
119 | * their own implementations. |
120 | */ |
121 | virtual SPtr<Texture> createTextureInternal(const TEXTURE_DESC& desc, |
122 | const SPtr<PixelData>& initialData = nullptr, GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0; |
123 | |
124 | /** @copydoc createRenderTexture */ |
125 | virtual SPtr<RenderTexture> createRenderTextureInternal(const RENDER_TEXTURE_DESC& desc, |
126 | UINT32 deviceIdx = 0) = 0; |
127 | }; |
128 | } |
129 | |
130 | /** @} */ |
131 | } |