GteDrawTarget.cpp
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #include <GTEnginePCH.h>
9 #include <LowLevel/GteLogger.h>
10 #include <Graphics/GteDrawTarget.h>
11 using namespace gte;
12 
14 {
15  msLFDMutex.lock();
16  {
17  for (auto listener : msLFDSet)
18  {
19  listener->OnDestroy(this);
20  }
21  }
22  msLFDMutex.unlock();
23 }
24 
25 DrawTarget::DrawTarget(unsigned int numRenderTargets, DFType rtFormat,
26  unsigned int width, unsigned int height, bool hasRTMipmaps,
27  bool createRTStorage, DFType dsFormat, bool createDSStorage)
28 {
29  if (numRenderTargets > 0)
30  {
31  mRTTextures.resize(numRenderTargets);
32  for (auto& texture : mRTTextures)
33  {
34  texture = std::make_shared<TextureRT>(rtFormat, width, height,
35  hasRTMipmaps, createRTStorage);
36  }
37 
38  if (dsFormat != DF_UNKNOWN)
39  {
40  if (DataFormat::IsDepth(dsFormat))
41  {
42  mDSTexture = std::make_shared<TextureDS>(dsFormat, width,
43  height, createDSStorage);
44  }
45  else
46  {
47  LogError("Invalid depth-stencil format.");
48  }
49  }
50  }
51  else
52  {
53  LogError("Number of targets must be at least one.");
54  }
55 }
56 
57 unsigned int DrawTarget::GetNumTargets() const
58 {
59  return static_cast<unsigned int>(mRTTextures.size());
60 }
61 
63 {
64  if (mRTTextures.size() > 0)
65  {
66  return mRTTextures[0]->GetFormat();
67  }
68 
69  LogError("Unexpected condition.");
70  return DF_UNKNOWN;
71 }
72 
73 unsigned int DrawTarget::GetWidth() const
74 {
75  if (mRTTextures.size() > 0)
76  {
77  return mRTTextures[0]->GetWidth();
78  }
79 
80  LogError("Unexpected condition.");
81  return 0;
82 }
83 
84 unsigned int DrawTarget::GetHeight() const
85 {
86  if (mRTTextures.size() > 0)
87  {
88  return mRTTextures[0]->GetHeight();
89  }
90 
91  LogError("Unexpected condition.");
92  return 0;
93 }
94 
96 {
97  if (mRTTextures.size() > 0)
98  {
99  return mRTTextures[0]->HasMipmaps();
100  }
101 
102  LogError("Unexpected condition.");
103  return false;
104 }
105 
107 {
108  if (mDSTexture)
109  {
110  return mDSTexture->GetFormat();
111  }
112 
113  LogError("Unexpected condition.");
114  return DF_UNKNOWN;
115 }
116 
117 std::shared_ptr<TextureRT> const DrawTarget::GetRTTexture(unsigned int i)
118  const
119 {
120  if (i < static_cast<int>(mRTTextures.size()))
121  {
122  return mRTTextures[i];
123  }
124 
125  LogError("Invalid index.");
126  return nullptr;
127 }
128 
129 std::shared_ptr<TextureDS> const DrawTarget::GetDSTexture() const
130 {
131  return mDSTexture;
132 }
133 
135 {
136  if (HasRTMipmaps())
137  {
138  for (auto& texture : mRTTextures)
139  {
140  texture->AutogenerateMipmaps();
141  }
142  }
143 }
144 
146 {
147  if (mRTTextures.size() > 0)
148  {
149  return mRTTextures[0]->WantAutogenerateMipmaps();
150  }
151 
152  LogError("Unexpected condition.");
153  return false;
154 }
155 
156 void DrawTarget::SubscribeForDestruction(std::shared_ptr<ListenerForDestruction> const& listener)
157 {
158  msLFDMutex.lock();
159  {
160  msLFDSet.insert(listener);
161  }
162  msLFDMutex.unlock();
163 }
164 
165 void DrawTarget::UnsubscribeForDestruction(std::shared_ptr<ListenerForDestruction> const& listener)
166 {
167  msLFDMutex.lock();
168  {
169  msLFDSet.erase(listener);
170  }
171  msLFDMutex.unlock();
172 }
173 
174 
175 std::mutex DrawTarget::msLFDMutex;
176 std::set<std::shared_ptr<DrawTarget::ListenerForDestruction>> DrawTarget::msLFDSet;
std::shared_ptr< TextureRT > const GetRTTexture(unsigned int i) const
unsigned int GetWidth() const
bool HasRTMipmaps() const
unsigned int GetHeight() const
GLint GLsizei width
Definition: glcorearb.h:98
std::shared_ptr< TextureDS > const GetDSTexture() const
DFType GetRTFormat() const
std::shared_ptr< TextureDS > mDSTexture
Definition: GteDrawTarget.h:71
DFType GetDSFormat() const
static std::set< std::shared_ptr< ListenerForDestruction > > msLFDSet
Definition: GteDrawTarget.h:76
bool WantAutogenerateRTMipmaps() const
static bool IsDepth(DFType type)
#define LogError(message)
Definition: GteLogger.h:92
void AutogenerateRTMipmaps()
virtual ~DrawTarget()
GLuint texture
Definition: glcorearb.h:410
unsigned int GetNumTargets() const
GLint GLsizei GLsizei height
Definition: glcorearb.h:98
static void SubscribeForDestruction(std::shared_ptr< ListenerForDestruction > const &listener)
static std::mutex msLFDMutex
Definition: GteDrawTarget.h:75
static void UnsubscribeForDestruction(std::shared_ptr< ListenerForDestruction > const &listener)
DrawTarget(unsigned int numRenderTargets, DFType rtFormat, unsigned int width, unsigned int height, bool hasRTMipmaps=false, bool createRTStorage=true, DFType dsFormat=DF_UNKNOWN, bool createDSStorage=false)
std::vector< std::shared_ptr< TextureRT > > mRTTextures
Definition: GteDrawTarget.h:70
DF_UNKNOWN
Definition: GteDataFormat.h:20


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59