35 return IsValid(format)
43 return IsValid(format)
51 return IsValid(format)
60 static bool IsAttachmentNotifier(
61 const base::Notifier* notifier,
62 const FramebufferObject::Attachment& attachment) {
63 return notifier == attachment.GetTexture().Get() ||
64 notifier == attachment.GetCubeMapTexture().Get() ||
65 notifier == attachment.GetImage().Get();
74 Construct(
kUnbound, 0, kInvalidFace);
90 const ImagePtr& image_in) : image_(image_in) {
100 const TexturePtr& texture_in) : texture_(texture_in) {
105 const TexturePtr& texture_in,
size_t mip_level)
106 : texture_(texture_in) {
112 : cubemap_(cubemap_in) {
119 size_t mip_level) : cubemap_(cubemap_in) {
123 ION_API
void FramebufferObject::Attachment::Construct(
128 mip_level_ = mip_level;
136 if (
Texture* tex = texture_.Get()) {
137 if (tex->HasImage(0))
138 format = tex->GetImage(0)->GetFormat();
142 if (tex->HasImage(face_, 0))
143 format = tex->GetImage(face_, 0)->GetFormat();
146 }
else if (image_.Get()) {
147 format = image_->GetFormat();
158 if (width_.Get() == 0 || height_.Get() == 0)
159 LOG(
ERROR) <<
"Framebuffer created with zero width or height; it will be"
160 <<
" ignored if used for rendering.";
164 SetAttachment(&color0_, IsColorFormatRenderable,
Attachment(),
"color");
165 SetAttachment(&depth_, IsDepthFormatRenderable,
Attachment(),
"depth");
166 SetAttachment(&stencil_, IsStencilFormatRenderable,
Attachment(),
"stencil");
175 DCHECK_EQ(0U, i) <<
"***ION: Only a single color attachment is supported";
176 SetAttachment(&color0_, IsColorFormatRenderable, color,
"color");
180 SetAttachment(&depth_, IsDepthFormatRenderable, depth,
"depth");
184 SetAttachment(&stencil_, IsStencilFormatRenderable, stencil,
"stencil");
188 bool renderable =
false;
190 case GL_RGB16F:
case GL_RGB32F:
case GL_RGBA16F:
case GL_RGBA32F:
191 case GL_RGB:
case GL_RGBA:
case GL_R8:
case GL_R8UI:
case GL_R8I:
192 case GL_R16UI:
case GL_R16I:
case GL_R32UI:
case GL_R32I:
case GL_RG8:
193 case GL_RG8UI:
case GL_RG8I:
case GL_RG16UI:
case GL_RG16I:
194 case GL_RG32UI:
case GL_RG32I:
case GL_RGB8:
case GL_RGB565:
195 case GL_RGB5_A1:
case GL_RGBA4:
case GL_RGB10_A2:
case GL_RGB10_A2UI:
196 case GL_RGBA8:
case GL_SRGB8_ALPHA8:
case GL_RGBA8UI:
case GL_RGBA8I:
197 case GL_RGBA16UI:
case GL_RGBA16I:
case GL_RGBA32I:
case GL_RGBA32UI:
208 return format == GL_DEPTH_COMPONENT || format == GL_DEPTH_COMPONENT16 ||
209 format == GL_DEPTH_COMPONENT24 || format == GL_DEPTH_COMPONENT32F ||
210 format == GL_DEPTH24_STENCIL8 || format == GL_DEPTH32F_STENCIL8;
214 return format == GL_DEPTH24_STENCIL8 || format == GL_DEPTH32F_STENCIL8 ||
215 format == GL_STENCIL_INDEX8;
218 void FramebufferObject::OnNotify(
const base::Notifier* notifier) {
220 if (IsAttachmentNotifier(notifier, color0_.Get())) {
222 }
else if (IsAttachmentNotifier(notifier, depth_.Get())) {
224 }
else if (IsAttachmentNotifier(notifier, stencil_.Get())) {
230 void FramebufferObject::SetAttachment(Field<Attachment>* field,
232 const Attachment& attachment,
233 const std::string& type_name) {
235 if (Texture* tex = field->Get().GetTexture().Get())
236 tex->RemoveReceiver(
this);
237 else if (CubeMapTexture* tex = field->Get().GetCubeMapTexture().Get())
238 tex->RemoveReceiver(
this);
239 else if (Image* img = field->Get().GetImage().Get())
240 img->RemoveReceiver(
this);
242 if (attachment.GetBinding() !=
kUnbound &&
243 !validator(attachment.GetFormat())) {
244 LOG(
ERROR) <<
"Invalid " << type_name <<
" attachment format "
246 field->Set(Attachment());
248 if (Texture* tex = attachment.GetTexture().Get())
249 tex->AddReceiver(
this);
250 else if (CubeMapTexture* tex = attachment.GetCubeMapTexture().Get())
251 tex->AddReceiver(
this);
252 else if (Image* img = attachment.GetImage().Get())
253 img->AddReceiver(
this);
254 field->Set(attachment);
A Texture object represents the image data and mipmaps associated with a single texture.
Format
Supported image formats.
const size_t kInvalidIndex
kInvalidIndex is a size_t value that is very unlikely to be a valid index.
#define LOG(severity)
Logs the streamed message unconditionally with a severity of severity.
A Notifier both sends notifications to and receives notifications from other Notifiers.
CubeFace
The names of faces of the cube map.
void SetDepthAttachment(const Attachment &attachment)
~FramebufferObject() override
The destructor is protected because all base::Referent classes must have protected or private destruc...
AttachmentBinding
The type of binding for an Attachment.
static bool IsStencilRenderable(uint32 gl_format)
void OnChanged(int bit) const
Forwards OnChanged to all resources.
FramebufferObject(uint32 width, uint32 height)
Creates a FramebufferObject with the passed dimensions and unbound attachments.
T * Get() const
Returns a raw pointer to the instance, which may be NULL.
void Resize(uint32 width, uint32 height)
Resizes the FramebufferObject to the passed dimensions.
static const PixelFormat & GetPixelFormat(Format format)
Convenience function that returns a PixelFormat given a Format.
void SetStencilAttachment(const Attachment &attachment)
static bool IsDepthRenderable(uint32 gl_format)
Attachment()
Creates an unbound Attachment.
#define DCHECK_EQ(val1, val2)
A CubeMapTexture object represents the image data and mipmaps associated with the six faces of a cube...
int GetResourceCount() const
Returns the number of resources that this holder holds.
void SetColorAttachment(size_t i, const Attachment &attachment)
An attachment represents a data store attached to one of the framebuffer's targets.
static bool IsColorRenderable(uint32 gl_format)
Returns whether the passed GL formats are renderable.
A SharedPtr is a smart shared pointer to an instance of some class that implements reference counting...
static const uint32 kNumFormats
static const char * GetFormatString(Format format)
Convenience function that returns a string representing the name of a given Format.
Image::Format GetFormat() const
Gets the format of the attachment, which is the texture format if it is a texture attachment...