25 #include <OpenGLFramework/Utils/FramebufferSetupPool.hh>
39 texturePoolP_ = &texturePoolP;
58 unsigned int width,
unsigned int height,
59 const std::string& colorAttachmentName, GLenum internalFormat,
60 const bool clearColors,
const std::string& depthAttachmentName,
61 const bool clearDepth,
const float rClear,
const float gClear,
62 const float bClear,
const float aClear,
const float zClear)
64 map<std::string, pair<FramebufferSetup*, vector<string> > >::iterator it =
65 fboSetupPool_.find(setupName);
66 if (it != fboSetupPool_.end())
68 BIASERR(
"already used setup name : " << setupName
69 <<
". use clear before reusing the name!");
76 width, height, internalFormat);
80 pair<FramebufferSetup*, vector<string> > newPair = make_pair(newSetup,
82 newPair.second.push_back(colorAttachmentName);
89 if (depthAttachmentName.size() > 0) {
90 depthAttachment = texturePoolP_->
Create(depthAttachmentName, width, height,
92 newPair.second.push_back(depthAttachmentName);
96 fboSetupPool_[setupName] = newPair;
123 unsigned int width,
unsigned int height,
124 const std::vector<std::string>& colorAttachmentNames,
125 GLenum internalFormat,
const bool clearColors,
126 const std::string& depthAttachmentName,
const bool clearDepth,
127 const float rClear,
const float gClear,
const float bClear,
128 const float aClear,
const float zClear)
130 map<std::string, pair<FramebufferSetup*, vector<string> > >::iterator it =
131 fboSetupPool_.find(setupName);
132 if (it != fboSetupPool_.end())
134 BIASERR(
"already used setup name : " << setupName
135 <<
". use clear before reusing the name!");
143 pair<FramebufferSetup*, vector<string> > newPair = make_pair(newSetup,
147 for (
unsigned int i = 0; i < colorAttachmentNames.size(); i++)
150 colorAttachmentNames[i], width, height, internalFormat);
152 newPair.second.push_back(colorAttachmentNames[i]);
154 fboSetupPool_[setupName] = newPair;
158 if (depthAttachmentName.size() > 0) {
159 depthAttachment = texturePoolP_->
Create(depthAttachmentName, width, height,
161 newPair.second.push_back(depthAttachmentName);
185 const vector<string>& colorAttachmentNames)
187 if (texturePoolP_ != NULL)
189 map<string, pair<FramebufferSetup*, vector<string> > >::iterator iter =
190 fboSetupPool_.find(setupName);
191 if (iter != fboSetupPool_.end())
194 (iter->second).second = colorAttachmentNames;
195 SetColorAttachments_(*fbsP, colorAttachmentNames);
199 BIASERR(
"no frame buffer setup with name (" << setupName
207 BIASERR(
"call create first ! " << endl);
213 FramebufferSetupPool::SetColorAttachments_(
FramebufferSetup& frameBufferSetup,
214 const vector<string>& colorAttachmentNames)
216 vector<glfTexture*> textureVector(colorAttachmentNames.size());
217 for (
unsigned int i = 0; i < colorAttachmentNames.size(); i++)
219 glfTexture2D* textureP = (*texturePoolP_)[colorAttachmentNames[i]];
220 if (textureP == NULL)
222 BIASERR(
"unable to attach texture "
223 << colorAttachmentNames[i] <<
" no such texture found "
229 textureVector[i] = textureP;
240 map<string, pair<FramebufferSetup*, vector<string> > >::iterator iter =
241 fboSetupPool_.find(setupName);
242 if (iter != fboSetupPool_.end())
244 BIASERR(
"already used setup name : " << setupName
245 <<
". use clear before reusing the name!");
253 fboSetupPool_[setupName] = make_pair(newSetup, vector<string> ());
262 map<std::string, pair<FramebufferSetup*, vector<string> > >::iterator it =
263 fboSetupPool_.begin();
264 for (; it != fboSetupPool_.end(); it++)
266 delete (it->second).first;
268 fboSetupPool_.clear();
275 map<std::string, pair<FramebufferSetup*, vector<string> > >::iterator it =
276 fboSetupPool_.find(setupName);
277 if (it != fboSetupPool_.end())
279 delete (it->second).first;
280 fboSetupPool_.erase(it);
287 map<std::string, pair<FramebufferSetup*, vector<string> > >::iterator it =
288 fboSetupPool_.find(setupName);
289 if (it != fboSetupPool_.end())
291 ((it->second).first)->Execute();
307 map<std::string, pair<FramebufferSetup*, vector<string> > >::iterator it =
308 fboSetupPool_.find(setupName);
309 if (it != fboSetupPool_.end())
311 return (it->second).first;
315 BIASWARN(
"A setup with this name : " << setupName <<
" does not exist");
329 return texturePoolP_;
334 const string& attachmentName)
336 map<string, pair<FramebufferSetup*, vector<string> > >::iterator iter =
337 fboSetupPool_.find(setupName);
338 if (iter != fboSetupPool_.end())
340 vector<string>& attachmentNames = (iter->second).second;
341 vector<string>::iterator name_iter = find(attachmentNames.begin(),
342 attachmentNames.end(), attachmentName);
343 if (name_iter != attachmentNames.end())
345 return (*texturePoolP_)[attachmentName];
360 std::vector<std::string>& attachmentNames)
362 map<string, pair<FramebufferSetup*, vector<string> > >::iterator iter =
363 fboSetupPool_.find(setupName);
364 if (iter != fboSetupPool_.end())
366 attachmentNames = (iter->second).second;
370 BIASWARN(
"no such setup : "<<setupName);
void SetColorAttachments(const std::string &setupName, const std::vector< std::string > &colorAttachmentNames)
void GetSetupAttachmentNames(const std::string &setupName, std::vector< std::string > &attachmentNames)
FramebufferSetup * CreateSetup(const std::string &setupName)
void Create()
Creates the texture but does not upload any data yet.
Texture2DPool * GetTexturePool()
void SetDepthAttachment(BIAS::glfTexture *texture)
Convenience container for managing 2D textures.
glfTexture2D * GetAttachment(const std::string &setupName, const std::string &attachmentName)
Returns the pointer to a texture attached during a setup.
void SetColorAttachments(const std::vector< BIAS::glfTexture * > &textures)
replaces all previous color attachments and through given
void DisableColorClearance()
FramebufferSetup * GetSetup(const std::string &setupName)
Returns the pointer to a texture attached during a setup.
void Activate(const std::string &setupName)
void EnableColorClearance(float red=0.0f, float green=0.0f, float blue=0.0f, float alpha=0.0f)
void LinkFBO(BIAS::glfFramebufferObject *fbo)
void DisableDepthClearance()
void SetColorAttachment(BIAS::glfTexture *texture, int AttachmentPoint=0)
glfFramebufferObject * GetFBO()
void Create(Texture2DPool &texturePoolP)
Call this once the GLContext is valid.
void ClearSetup(const std::string &setupName)
Does not remove the attachment.
BIAS::glfTexture2D * Create(const std::string &name, int width, int height, GLenum internalFormat, GLenum minFilter=GL_NEAREST, GLenum magFilter=GL_NEAREST, GLenum wrapS=GL_CLAMP, GLenum wrapT=GL_CLAMP, int mipmap=0)
Allocates an empty texture.
void EnableDepthClearance(float depth=1.0f)