Commit 5160ec11 by Jamie Madill

Squash the attachment types.

We can store all relevant information in the base class, which lets us avoid using any virtual methods. This will finally let us avoid using reallocations on FBO attachment sets. BUG=angleproject:963 Change-Id: Ib4b61da14efaf843478b059499c01e34f9c65e4f Reviewed-on: https://chromium-review.googlesource.com/263488Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org> Reviewed-by: 's avatarBrandon Jones <bajones@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 79481d65
......@@ -556,12 +556,12 @@ bool Framebuffer::hasValidDepthStencil() const
void Framebuffer::setTextureAttachment(GLenum attachment, Texture *texture, const ImageIndex &imageIndex)
{
setAttachment(attachment, new TextureAttachment(attachment, texture, imageIndex));
setAttachment(attachment, new FramebufferAttachment(GL_TEXTURE, attachment, imageIndex, texture));
}
void Framebuffer::setRenderbufferAttachment(GLenum attachment, Renderbuffer *renderbuffer)
{
setAttachment(attachment, new RenderbufferAttachment(attachment, renderbuffer));
setAttachment(attachment, new FramebufferAttachment(GL_RENDERBUFFER, attachment, ImageIndex::MakeInvalid(), renderbuffer));
}
void Framebuffer::setNULLAttachment(GLenum attachment)
......@@ -611,13 +611,18 @@ void Framebuffer::setAttachment(GLenum attachment, FramebufferAttachment *attach
// See angle issue 686
if (attachmentObj->type() == GL_TEXTURE)
{
mData.mStencilAttachment = new TextureAttachment(GL_DEPTH_STENCIL_ATTACHMENT, attachmentObj->getTexture(),
attachmentObj->getTextureImageIndex());
mData.mStencilAttachment = new FramebufferAttachment(GL_TEXTURE,
GL_DEPTH_STENCIL_ATTACHMENT,
attachmentObj->getTextureImageIndex(),
attachmentObj->getTexture());
mImpl->setStencilAttachment(mData.mStencilAttachment);
}
else if (attachmentObj->type() == GL_RENDERBUFFER)
{
mData.mStencilAttachment = new RenderbufferAttachment(GL_DEPTH_STENCIL_ATTACHMENT, attachmentObj->getRenderbuffer());
mData.mStencilAttachment = new FramebufferAttachment(GL_RENDERBUFFER,
GL_DEPTH_STENCIL_ATTACHMENT,
ImageIndex::MakeInvalid(),
attachmentObj->getRenderbuffer());
mImpl->setStencilAttachment(mData.mStencilAttachment);
}
else
......@@ -637,15 +642,15 @@ DefaultFramebuffer::DefaultFramebuffer(const Caps &caps, rx::ImplFactory *factor
{
const egl::Config *config = surface->getConfig();
setAttachment(GL_BACK, new DefaultAttachment(GL_BACK, surface));
setAttachment(GL_BACK, new FramebufferAttachment(GL_FRAMEBUFFER_DEFAULT, GL_BACK, ImageIndex::MakeInvalid(), surface));
if (config->depthSize > 0)
{
setAttachment(GL_DEPTH, new DefaultAttachment(GL_DEPTH, surface));
setAttachment(GL_DEPTH, new FramebufferAttachment(GL_FRAMEBUFFER_DEFAULT, GL_DEPTH, ImageIndex::MakeInvalid(), surface));
}
if (config->stencilSize > 0)
{
setAttachment(GL_STENCIL, new DefaultAttachment(GL_STENCIL, surface));
setAttachment(GL_STENCIL, new FramebufferAttachment(GL_FRAMEBUFFER_DEFAULT, GL_STENCIL, ImageIndex::MakeInvalid(), surface));
}
GLenum drawBufferState = GL_BACK;
......
......@@ -43,10 +43,12 @@ FramebufferAttachment::Target &FramebufferAttachment::Target::operator=(const Ta
////// FramebufferAttachment Implementation //////
FramebufferAttachment::FramebufferAttachment(GLenum binding,
FramebufferAttachment::FramebufferAttachment(GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource)
: mTarget(binding, textureIndex)
: mType(type),
mTarget(binding, textureIndex)
{
mResource.set(resource);
}
......@@ -104,7 +106,7 @@ const ImageIndex &FramebufferAttachment::getTextureImageIndex() const
GLenum FramebufferAttachment::cubeMapFace() const
{
ASSERT(type() == GL_TEXTURE);
ASSERT(mType == GL_TEXTURE);
const auto &index = mTarget.textureIndex();
return IsCubeMapTextureTarget(index.type) ? index.type : GL_NONE;
......@@ -118,7 +120,7 @@ GLint FramebufferAttachment::mipLevel() const
GLint FramebufferAttachment::layer() const
{
ASSERT(type() == GL_TEXTURE);
ASSERT(mType == GL_TEXTURE);
const auto &index = mTarget.textureIndex();
......@@ -129,108 +131,17 @@ GLint FramebufferAttachment::layer() const
return 0;
}
GLsizei FramebufferAttachment::getWidth() const
{
return mResource->getAttachmentWidth(mTarget);
}
GLsizei FramebufferAttachment::getHeight() const
{
return mResource->getAttachmentHeight(mTarget);
}
GLenum FramebufferAttachment::getInternalFormat() const
{
return mResource->getAttachmentInternalFormat(mTarget);
}
GLsizei FramebufferAttachment::getSamples() const
{
return mResource->getAttachmentSamples(mTarget);
}
///// TextureAttachment Implementation ////////
TextureAttachment::TextureAttachment(GLenum binding, Texture *texture, const ImageIndex &index)
: FramebufferAttachment(binding, index, texture)
{
}
TextureAttachment::~TextureAttachment()
{
}
GLenum TextureAttachment::type() const
{
return GL_TEXTURE;
}
Renderbuffer *TextureAttachment::getRenderbuffer() const
{
UNREACHABLE();
return nullptr;
}
Texture *TextureAttachment::getTexture() const
Texture *FramebufferAttachment::getTexture() const
{
return rx::GetAs<Texture>(mResource.get());
}
////// RenderbufferAttachment Implementation //////
RenderbufferAttachment::RenderbufferAttachment(GLenum binding, Renderbuffer *renderbuffer)
: FramebufferAttachment(binding, ImageIndex::MakeInvalid(), renderbuffer)
{
ASSERT(renderbuffer);
}
RenderbufferAttachment::~RenderbufferAttachment()
{
}
GLenum RenderbufferAttachment::type() const
{
return GL_RENDERBUFFER;
}
Texture *RenderbufferAttachment::getTexture() const
{
UNREACHABLE();
return nullptr;
}
Renderbuffer *RenderbufferAttachment::getRenderbuffer() const
Renderbuffer *FramebufferAttachment::getRenderbuffer() const
{
return rx::GetAs<Renderbuffer>(mResource.get());
}
DefaultAttachment::DefaultAttachment(GLenum binding, egl::Surface *surface)
: FramebufferAttachment(binding, ImageIndex::MakeInvalid(), surface)
{
}
DefaultAttachment::~DefaultAttachment()
{
}
GLenum DefaultAttachment::type() const
{
return GL_FRAMEBUFFER_DEFAULT;
}
Texture *DefaultAttachment::getTexture() const
{
UNREACHABLE();
return nullptr;
}
Renderbuffer *DefaultAttachment::getRenderbuffer() const
{
UNREACHABLE();
return nullptr;
}
const egl::Surface *DefaultAttachment::getSurface() const
const egl::Surface *FramebufferAttachment::getSurface() const
{
return rx::GetAs<egl::Surface>(mResource.get());
}
......
......@@ -32,13 +32,14 @@ class Texture;
// Note: Our old naming scheme used the term "Renderbuffer" for both GL renderbuffers and for
// framebuffer attachments, which confused their usage.
class FramebufferAttachment : angle::NonCopyable
class FramebufferAttachment final : angle::NonCopyable
{
public:
FramebufferAttachment(GLenum binding,
FramebufferAttachment(GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource);
virtual ~FramebufferAttachment();
~FramebufferAttachment();
// A framebuffer attachment points to one of three types of resources: Renderbuffers,
// Textures and egl::Surface. The "Target" struct indicates which part of the
......@@ -71,8 +72,8 @@ class FramebufferAttachment : angle::NonCopyable
GLenum getComponentType() const;
GLenum getColorEncoding() const;
bool isTextureWithId(GLuint textureId) const { return type() == GL_TEXTURE && id() == textureId; }
bool isRenderbufferWithId(GLuint renderbufferId) const { return type() == GL_RENDERBUFFER && id() == renderbufferId; }
bool isTextureWithId(GLuint textureId) const { return mType == GL_TEXTURE && id() == textureId; }
bool isRenderbufferWithId(GLuint renderbufferId) const { return mType == GL_RENDERBUFFER && id() == renderbufferId; }
GLenum getBinding() const { return mTarget.binding(); }
GLuint id() const { return mResource.id(); }
......@@ -87,60 +88,18 @@ class FramebufferAttachment : angle::NonCopyable
GLsizei getHeight() const;
GLenum getInternalFormat() const;
GLsizei getSamples() const;
GLenum type() const { return mType; }
// Child class interface
virtual GLenum type() const = 0;
virtual Texture *getTexture() const = 0;
virtual Renderbuffer *getRenderbuffer() const = 0;
Renderbuffer *getRenderbuffer() const;
Texture *getTexture() const;
const egl::Surface *getSurface() const;
protected:
private:
GLenum mType;
Target mTarget;
BindingPointer<FramebufferAttachmentObject> mResource;
};
class TextureAttachment : public FramebufferAttachment
{
public:
TextureAttachment(GLenum binding, Texture *texture, const ImageIndex &index);
virtual ~TextureAttachment();
virtual GLenum type() const;
virtual Renderbuffer *getRenderbuffer() const;
Texture *getTexture() const override;
};
class RenderbufferAttachment : public FramebufferAttachment
{
public:
RenderbufferAttachment(GLenum binding, Renderbuffer *renderbuffer);
virtual ~RenderbufferAttachment();
virtual GLenum type() const;
virtual Texture *getTexture() const;
Renderbuffer *getRenderbuffer() const override;
};
class DefaultAttachment : public FramebufferAttachment
{
public:
DefaultAttachment(GLenum binding, egl::Surface *surface);
virtual ~DefaultAttachment();
virtual GLenum type() const;
virtual Texture *getTexture() const;
virtual Renderbuffer *getRenderbuffer() const;
const egl::Surface *getSurface() const;
};
// A base class for objects that FBO Attachments may point to.
class FramebufferAttachmentObject : public RefCountObject
{
......@@ -153,6 +112,26 @@ class FramebufferAttachmentObject : public RefCountObject
virtual GLsizei getAttachmentSamples(const FramebufferAttachment::Target &target) const = 0;
};
inline GLsizei FramebufferAttachment::getWidth() const
{
return mResource->getAttachmentWidth(mTarget);
}
inline GLsizei FramebufferAttachment::getHeight() const
{
return mResource->getAttachmentHeight(mTarget);
}
inline GLenum FramebufferAttachment::getInternalFormat() const
{
return mResource->getAttachmentInternalFormat(mTarget);
}
inline GLsizei FramebufferAttachment::getSamples() const
{
return mResource->getAttachmentSamples(mTarget);
}
}
#endif // LIBANGLE_FRAMEBUFFERATTACHMENT_H_
......@@ -393,13 +393,12 @@ gl::Error GetAttachmentRenderTarget(const gl::FramebufferAttachment *attachment,
}
else if (attachment->type() == GL_FRAMEBUFFER_DEFAULT)
{
const gl::DefaultAttachment *defaultAttachment = static_cast<const gl::DefaultAttachment *>(attachment);
const egl::Surface *surface = defaultAttachment->getSurface();
const egl::Surface *surface = attachment->getSurface();
ASSERT(surface);
const SurfaceD3D *surfaceD3D = GetImplAs<SurfaceD3D>(surface);
ASSERT(surfaceD3D);
if (defaultAttachment->getBinding() == GL_BACK)
if (attachment->getBinding() == GL_BACK)
{
*outRT = surfaceD3D->getSwapChain()->getColorRenderTarget();
}
......@@ -436,13 +435,12 @@ unsigned int GetAttachmentSerial(const gl::FramebufferAttachment *attachment)
}
else if (attachment->type() == GL_FRAMEBUFFER_DEFAULT)
{
const gl::DefaultAttachment *defaultAttachment = static_cast<const gl::DefaultAttachment *>(attachment);
const egl::Surface *surface = defaultAttachment->getSurface();
const egl::Surface *surface = attachment->getSurface();
ASSERT(surface);
const SurfaceD3D *surfaceD3D = GetImplAs<SurfaceD3D>(surface);
ASSERT(surfaceD3D);
if (defaultAttachment->getBinding() == GL_BACK)
if (attachment->getBinding() == GL_BACK)
{
return surfaceD3D->getSwapChain()->getColorRenderTarget()->getSerial();
}
......
......@@ -1282,7 +1282,7 @@ gl::Error Renderer9::getNullColorbuffer(const gl::FramebufferAttachment *depthbu
return error;
}
gl::RenderbufferAttachment *nullbuffer = new gl::RenderbufferAttachment(GL_NONE, nullRenderbuffer);
gl::FramebufferAttachment *nullbuffer = new gl::FramebufferAttachment(GL_RENDERBUFFER, GL_NONE, gl::ImageIndex::MakeInvalid(), nullRenderbuffer);
// add nullbuffer to the cache
NullColorbufferCacheEntry *oldest = &mNullColorbufferCache[0];
......
......@@ -50,7 +50,7 @@ static void BindFramebufferAttachment(const FunctionsGL *functions, GLenum attac
{
if (attachment->type() == GL_TEXTURE)
{
const gl::Texture *texture = GetAs<gl::TextureAttachment>(attachment)->getTexture();
const gl::Texture *texture = attachment->getTexture();
const TextureGL *textureGL = GetImplAs<TextureGL>(texture);
if (texture->getTarget() == GL_TEXTURE_2D)
......@@ -75,7 +75,7 @@ static void BindFramebufferAttachment(const FunctionsGL *functions, GLenum attac
}
else if (attachment->type() == GL_RENDERBUFFER)
{
const gl::Renderbuffer *renderbuffer = GetAs<gl::RenderbufferAttachment>(attachment)->getRenderbuffer();
const gl::Renderbuffer *renderbuffer = attachment->getRenderbuffer();
const RenderbufferGL *renderbufferGL = GetImplAs<RenderbufferGL>(renderbuffer);
functions->framebufferRenderbuffer(GL_FRAMEBUFFER, attachmentPoint, GL_RENDERBUFFER,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment