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 | |
7 | namespace bs |
8 | { |
9 | namespace ct |
10 | { |
11 | /** @addtogroup RenderAPI-Internal |
12 | * @{ |
13 | */ |
14 | |
15 | /** Data describing a texture view. */ |
16 | struct BS_CORE_EXPORT TEXTURE_VIEW_DESC |
17 | { |
18 | /** |
19 | * First mip level of the parent texture the view binds (0 - base level). This applied to all array slices |
20 | * specified below. |
21 | */ |
22 | UINT32 mostDetailMip; |
23 | |
24 | /** Number of mip levels to bind to the view. This applied to all array slices specified below. */ |
25 | UINT32 numMips; |
26 | |
27 | /** |
28 | * First array slice the view binds to. This will be array index for 1D and 2D array textures, texture slice index |
29 | * for 3D textures, and face index for cube textures(cube index * 6). |
30 | */ |
31 | UINT32 firstArraySlice; |
32 | |
33 | /** |
34 | * Number of array slices to bind tot he view. This will be number of array elements for 1D and 2D array textures, |
35 | * number of slices for 3D textures, and number of cubes for cube textures. |
36 | */ |
37 | UINT32 numArraySlices; |
38 | |
39 | /** Type of texture view. */ |
40 | GpuViewUsage usage; |
41 | }; |
42 | |
43 | /** |
44 | * Texture views allow you to reference only a party of a texture. They may reference one or multiple mip-levels on one |
45 | * or multiple texture array slices. Selected mip level will apply to all slices. |
46 | * |
47 | * They also allow you to re-purpose a texture (for example make a render target a bindable texture). |
48 | * |
49 | * @note Core thread. |
50 | */ |
51 | class BS_CORE_EXPORT TextureView |
52 | { |
53 | public: |
54 | class HashFunction |
55 | { |
56 | public: |
57 | size_t operator()(const TEXTURE_VIEW_DESC &key) const; |
58 | }; |
59 | |
60 | class EqualFunction |
61 | { |
62 | public: |
63 | bool operator()(const TEXTURE_VIEW_DESC &a, const TEXTURE_VIEW_DESC &b) const; |
64 | }; |
65 | |
66 | virtual ~TextureView() = default; |
67 | |
68 | /** Returns the most detailed mip level visible by the view. */ |
69 | UINT32 getMostDetailedMip() const { return mDesc.mostDetailMip; } |
70 | |
71 | /** Returns the number of mip levels in a single slice visible by the view. */ |
72 | UINT32 getNumMips() const { return mDesc.numMips; } |
73 | |
74 | /** Returns the first array slice index visible by this view. */ |
75 | UINT32 getFirstArraySlice() const { return mDesc.firstArraySlice; } |
76 | |
77 | /** Returns the number of array slices visible by this view. */ |
78 | UINT32 getNumArraySlices() const { return mDesc.numArraySlices; } |
79 | |
80 | /** Returns texture view usage. This determines where on the pipeline can be bind the view. */ |
81 | GpuViewUsage getUsage() const { return mDesc.usage; } |
82 | |
83 | /** Returns the descriptor structure used for initializing the view. */ |
84 | const TEXTURE_VIEW_DESC& getDesc() const { return mDesc; } |
85 | |
86 | protected: |
87 | TextureView(const TEXTURE_VIEW_DESC& _desc); |
88 | |
89 | protected: |
90 | friend class Texture; |
91 | |
92 | TEXTURE_VIEW_DESC mDesc; |
93 | }; |
94 | |
95 | /** @} */ |
96 | } |
97 | } |