Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
FramebufferSetupPool.hh
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #ifndef __FramebufferSetupPool_hh__
26 #define __FramebufferSetupPool_hh__
27 
28 #include <OpenGLFramework/Utils/FramebufferSetup.hh>
29 #include <OpenGLFramework/Utils/Texture2DPool.hh>
30 #include <OpenGLFramework/Base/glfFramebufferObject.hh>
31 
32 #include <bias_config.h>
33 #include <map>
34 
35 namespace BIAS
36 {
37 
38  /** Class containing a framebuffer and a map of setups.
39  * Class can be used instead of an stand alone glfFramebufferObject, to manage
40  * different frambuffer setups. This class so far only supports 2D textures.
41  * \ingroup g_openglframework
42  * \author bartczak 03/2009
43  **/
44 
45  class BIASOpenGLFramework_EXPORT FramebufferSetupPool
46  {
47  public:
50  {
51  texturePoolP_ = NULL;
52  }
53  ;
54 
55  /** Call this once the GLContext is valid.
56  * \attention must be called before using any other member method.
57  **/
58  void
59  Create(Texture2DPool& texturePoolP);
60 
62  CreateSetup(const std::string& setupName);
63 
64  /** Create a setup and the required 2D textures.
65  * \param setupName is the name used to identify the setup.
66  * \param width horizontal resolution.
67  * \param width vertical resolution.
68  * \param colorAttachmentName name of the glfTexture2D attached to COLOR_ATTACHMENT_0, identifying it in the internal
69  * Texture2DPool, this name must be unique across all setups.
70  * \param internalFormat is the internal format of the target glfTexture2D.
71  * \param clearColor if true the target texture is cleared when the setup is activated.
72  * \param depthAttachmentName if you want to render the depth output to a texture, give it a name for the internal Texture2DPool,
73  * if left empty to texture for the depth is attached, this name must be unique across all setups.
74  * \param clearDepth if true the target 'depth textur'e is cleared when the setup is activated.
75  * \param *Clear values the different channels are cleared, if clearing is enabled.
76  **/
78  CreateSetup(const std::string& setupName, unsigned int width,
79  unsigned int height, const std::string& colorAttachmentName,
80  GLenum internalFormat, const bool clearColors = true,
81  const std::string& depthAttachmentName = "", const bool clearDepth =
82  true, const float rClear = 0.f, const float gClear = 0.f,
83  const float bClear = 0.f, const float aClear = 0.f, const float zClear =
84  1.f);
85 
87  CreateSetup(const std::string& setupName, unsigned int width,
88  unsigned int height,
89  const std::vector<std::string>& colorAttachmentNames,
90  GLenum internalFormat, const bool clearColors = true,
91  const std::string& depthAttachmentName = "", const bool clearDepth =
92  true, const float rClear = 0.f, const float gClear = 0.f,
93  const float bClear = 0.f, const float aClear = 0.f, const float zClear =
94  1.f);
95 
96  void
97  SetColorAttachments(const std::string& setupName, const std::vector<
98  std::string>& colorAttachmentNames);
99 
100  void
101  ClearAll();
102 
103  /** Does not remove the attachment. **/
104  void
105  ClearSetup(const std::string& setupName);
106 
107  void
108  Activate(const std::string& setupName);
109 
110  //########################
111  //this method will be removed because a texture with the given name can exist in texture pool but may be not attached to a FrameBufferSetup
112  //########################
113 // /** Returns the pointer to a texture attached during a setup.
114 // * \attention it is not possible to read from and write into the same texture.
115 // **/
116 // glfTexture2D*
117 // GetAttachment(const std::string& attachmentName);
118  //########################
119 
120  glfTexture2D*
121  GetAttachment(const std::string& setupName,
122  const std::string& attachmentName);
123 
125  GetSetup(const std::string& setupName);
126 
128  GetTexturePool();
129 
131  GetFBO();
132 
133  void GetSetupAttachmentNames(const std::string& setupName, std::vector<std::string>& attachmentNames);
134 
135  private:
136 
137  void
138  SetColorAttachments_(FramebufferSetup& frameBufferSetup, const std::vector<
139  std::string>& colorAttachmentNames);
140 
142  {
143  }
144  FramebufferSetupPool&
145  operator=(const FramebufferSetupPool&)
146  {
147  return (*this);
148  }
149 
150  glfFramebufferObject fbo_;
151  // key: setup name - value: pair FramebufferSetup pointer - vector of attachment names
152  std::map<std::string,
153  std::pair<FramebufferSetup*, std::vector<std::string> > > fboSetupPool_;
154 
155  Texture2DPool* texturePoolP_;
156 
157  };
158 
159 }
160 
161 #endif
A 2D texture.
Definition: glfTexture2D.hh:40
Convenience container for managing 2D textures.
Class containing a framebuffer and a map of setups.