Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
framebufferobject.h
Go to the documentation of this file.
1 
18 #ifndef ION_GFX_FRAMEBUFFEROBJECT_H_
19 #define ION_GFX_FRAMEBUFFEROBJECT_H_
20 
21 #include "base/macros.h"
22 #include "ion/base/referent.h"
23 #include "ion/gfx/cubemaptexture.h"
24 #include "ion/gfx/image.h"
25 #include "ion/gfx/resourceholder.h"
26 #include "ion/gfx/texture.h"
27 
28 namespace ion {
29 namespace gfx {
30 
54 class ION_API FramebufferObject : public ResourceHolder {
55  public:
57  enum Changes {
58  kColorAttachmentChanged = kNumBaseChanges,
62  kNumChanges
63  };
64 
71  };
72 
77  class Attachment {
78  public:
80  Attachment();
82  Attachment(Image::Format format, size_t samples);
86  explicit Attachment(Image::Format format_in);
90  explicit Attachment(const ImagePtr& image_in);
96  explicit Attachment(const TexturePtr& texture_in);
98  Attachment(const TexturePtr& texture_in, size_t mip_level);
101  Attachment(const CubeMapTexturePtr& texture_in,
104  Attachment(const CubeMapTexturePtr& texture_in,
106  size_t mip_level);
107 
110  Image::Format GetFormat() const;
112  AttachmentBinding GetBinding() const { return binding_; }
114  const ImagePtr& GetImage() const { return image_; }
116  const TexturePtr& GetTexture() const { return texture_; }
118  const CubeMapTexturePtr& GetCubeMapTexture() const { return cubemap_; }
120  CubeMapTexture::CubeFace GetCubeMapFace() const { return face_; }
122  size_t GetMipLevel() const { return mip_level_; }
124  size_t GetSamples() const { return samples_; }
125 
127  inline bool operator !=(const Attachment& other) const {
128  return binding_ != other.binding_ || format_ != other.format_ ||
129  texture_.Get() != other.texture_.Get() ||
130  image_.Get() != other.image_.Get() ||
131  cubemap_.Get() != other.cubemap_.Get() ||
132  mip_level_ != other.mip_level_ || samples_ != other.samples_;
133  }
134 
135  private:
136  void Construct(AttachmentBinding binding,
137  size_t mip_level,
139  AttachmentBinding binding_;
141  CubeMapTexturePtr cubemap_;
142  ImagePtr image_;
143  TexturePtr texture_;
144  Image::Format format_;
145  size_t mip_level_;
146  size_t samples_;
147  };
148 
151  FramebufferObject(uint32 width, uint32 height);
152 
154  void Resize(uint32 width, uint32 height);
156  uint32 GetWidth() const { return width_.Get(); }
158  uint32 GetHeight() const { return height_.Get(); }
159 
163  const Attachment& GetColorAttachment(size_t i) const {
164  DCHECK_EQ(0U, i) << "***ION: Only a single color attachment is supported";
165  return color0_.Get();
166  }
167  void SetColorAttachment(size_t i, const Attachment& attachment);
169  const Attachment& GetDepthAttachment() const { return depth_.Get(); }
170  void SetDepthAttachment(const Attachment& attachment);
173  return stencil_.Get();
174  }
175  void SetStencilAttachment(const Attachment& attachment);
176 
178  static bool IsColorRenderable(uint32 gl_format);
179  static bool IsDepthRenderable(uint32 gl_format);
180  static bool IsStencilRenderable(uint32 gl_format);
181 
182  protected:
185  ~FramebufferObject() override;
186 
187  private:
189  void OnNotify(const base::Notifier* notifier) override;
190 
195  void SetAttachment(Field<Attachment>* field, bool (*validator)(Image::Format),
196  const Attachment& attachment,
197  const std::string& type_name);
198 
199  Field<uint32> width_;
200  Field<uint32> height_;
201  Field<Attachment> color0_;
202  Field<Attachment> depth_;
203  Field<Attachment> stencil_;
204 
205  DISALLOW_COPY_AND_ASSIGN(FramebufferObject);
206 };
207 
210 
211 } // namespace gfx
212 } // namespace ion
213 
214 #endif // ION_GFX_FRAMEBUFFEROBJECT_H_
base::ReferentPtr< FramebufferObject >::Type FramebufferObjectPtr
Convenience typedef for shared pointer to a FramebufferObject.
Changes
Changes that affect the resource.
Format
Supported image formats.
Definition: image.h:38
const CubeMapTexturePtr & GetCubeMapTexture() const
Gets the cubemap of the attachment, if any.
AttachmentBinding GetBinding() const
Gets the binding of the attachment.
uint32 GetWidth() const
Gets the width of the FramebufferObject and its attachments.
A Notifier both sends notifications to and receives notifications from other Notifiers.
Definition: notifier.h:35
size_t GetSamples() const
Returns the number of samples for multisampling.
const TexturePtr & GetTexture() const
Gets the texture of the attachment, if any.
CubeFace
The names of faces of the cube map.
AttachmentBinding
The type of binding for an Attachment.
A FramebufferObject describes an off-screen framebuffer that can be drawn to and read from like a reg...
T * Get() const
Returns a raw pointer to the instance, which may be NULL.
Definition: sharedptr.h:89
const Attachment & GetDepthAttachment() const
Gets and sets the depth Attachment.
size_t GetMipLevel() const
Returns the mipmap level of a Texture or CubeMapTexture attachment.
int width
#define DCHECK_EQ(val1, val2)
Definition: logging.h:332
uint32 GetHeight() const
Gets the height of the FramebufferObject and its attachments.
const Attachment & GetStencilAttachment() const
Gets and sets the stencil Attachment.
const ImagePtr & GetImage() const
Gets the image of the attachment, if any.
bool operator!=(const StlAllocator< T1 > &lhs, const StlAllocator< T2 > &rhs)
Definition: stlallocator.h:242
CubeMapTexture::CubeFace GetCubeMapFace() const
Gets the cubemap face of the attachment.
An attachment represents a data store attached to one of the framebuffer's targets.
A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting...
Definition: sharedptr.h:60
ResourceHolder is an internal base class for objects that hold resources managed by an outside entity...
const Attachment & GetColorAttachment(size_t i) const
Gets and sets the i-th color Attachment.