Diligent Engine  v.2.4.g
FBOCache.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019-2021 Diligent Graphics LLC
3  * Copyright 2015-2019 Egor Yusov
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * In no event and under no legal theory, whether in tort (including negligence),
18  * contract, or otherwise, unless required by applicable law (such as deliberate
19  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
20  * liable for any damages, including any direct, indirect, special, incidental,
21  * or consequential damages of any character arising as a result of this License or
22  * out of the use or inability to use the software (including but not limited to damages
23  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
24  * all other commercial damages or losses), even if such Contributor has been advised
25  * of the possibility of such damages.
26  */
27 
28 #pragma once
29 
30 #include "GraphicsTypes.h"
31 #include "TextureView.h"
32 #include "LockHelper.hpp"
33 #include "HashUtils.hpp"
34 #include "GLObjectWrapper.hpp"
35 
36 namespace Diligent
37 {
38 
39 class TextureViewGLImpl;
40 class GLContextState;
41 
42 class FBOCache
43 {
44 public:
45  FBOCache();
46  ~FBOCache();
47 
48  // clang-format off
49  FBOCache (const FBOCache&) = delete;
50  FBOCache ( FBOCache&&) = delete;
51  FBOCache& operator = (const FBOCache&) = delete;
52  FBOCache& operator = ( FBOCache&&) = delete;
53  // clang-format on
54 
56  Uint32 NumRenderTargets,
57  TextureViewGLImpl* ppRTVs[],
58  TextureViewGLImpl* pDSV);
59 
60  const GLObjectWrappers::GLFrameBufferObj& GetFBO(Uint32 NumRenderTargets,
61  TextureViewGLImpl* ppRTVs[],
62  TextureViewGLImpl* pDSV,
63  GLContextState& ContextState);
64 
65  void OnReleaseTexture(ITexture* pTexture);
66 
67 private:
68  // This structure is used as the key to find FBO
69  struct FBOCacheKey
70  {
71  // Using pointers is not reliable!
72 
73  Uint32 NumRenderTargets = 0;
74 
75  // Unique IDs of textures bound as render targets
76  UniqueIdentifier RTIds[MAX_RENDER_TARGETS] = {};
77  TextureViewDesc RTVDescs[MAX_RENDER_TARGETS];
78 
79  // Unique IDs of texture bound as depth stencil
80  UniqueIdentifier DSId = 0;
81  TextureViewDesc DSVDesc = {};
82 
83  mutable size_t Hash = 0;
84 
85  bool operator==(const FBOCacheKey& Key) const;
86  };
87 
88  struct FBOCacheKeyHashFunc
89  {
90  std::size_t operator()(const FBOCacheKey& Key) const;
91  };
92 
93 
94  friend class RenderDeviceGLImpl;
95  ThreadingTools::LockFlag m_CacheLockFlag;
96  std::unordered_map<FBOCacheKey, GLObjectWrappers::GLFrameBufferObj, FBOCacheKeyHashFunc> m_Cache;
97 
98  // Multimap that sets up correspondence between unique texture id and all
99  // FBOs it is used in
100  std::unordered_multimap<UniqueIdentifier, FBOCacheKey> m_TexIdToKey;
101 };
102 
103 } // namespace Diligent
Diligent::FBOCache::operator=
FBOCache & operator=(const FBOCache &)=delete
TextureView.h
ThreadingTools::LockFlag
Definition: LockHelper.hpp:36
Diligent::TextureViewGLImpl
Texture view implementation in OpenGL backend.
Definition: TextureViewGLImpl.hpp:38
Diligent::FBOCache
Definition: FBOCache.hpp:42
Diligent::operator==
bool operator==(const Plane3D &p1, const Plane3D &p2)
Definition: AdvancedMath.hpp:442
Diligent::FBOCache::GetFBO
const GLObjectWrappers::GLFrameBufferObj & GetFBO(Uint32 NumRenderTargets, TextureViewGLImpl *ppRTVs[], TextureViewGLImpl *pDSV, GLContextState &ContextState)
Definition: FBOCache.cpp:222
Diligent::FBOCache::~FBOCache
~FBOCache()
Definition: FBOCache.cpp:92
Diligent::FBOCache::CreateFBO
static GLObjectWrappers::GLFrameBufferObj CreateFBO(GLContextState &ContextState, Uint32 NumRenderTargets, TextureViewGLImpl *ppRTVs[], TextureViewGLImpl *pDSV)
Definition: FBOCache.cpp:112
Diligent::Uint32
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
Diligent::FBOCache::FBOCache
FBOCache()
Definition: FBOCache.cpp:86
Diligent::RenderDeviceGLImpl
Render device implementation in OpenGL backend.
Definition: RenderDeviceGLImpl.hpp:45
Diligent::FBOCache::OnReleaseTexture
void OnReleaseTexture(ITexture *pTexture)
Definition: FBOCache.cpp:98
HashUtils.hpp
GLObjectWrappers::GLObjWrapper
Definition: GLObjectWrapper.hpp:36
Diligent::GLContextState
Definition: GLContextState.hpp:39
GraphicsTypes.h
Diligent::UniqueIdentifier
Int32 UniqueIdentifier
Definition: UniqueIdentifier.hpp:36
Diligent::TextureViewDesc
Texture view description.
Definition: TextureView.h:80
LockHelper.hpp
Diligent::ITexture
Texture inteface.
Definition: Texture.h:273
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
GLObjectWrapper.hpp