Commit 79481d65 by Jamie Madill

Add FramebufferAttachmentObject base class.

This lets us share objects (Textures/RBs/Surface) in the attachment class. It will let us squash the attachment classes into one type, which will in turn let us store them by-value, instead of by-pointer. BUG=angleproject:963 Change-Id: Ia9a43dbc3b99475c00f6bc2ed5475deef55addc3 Reviewed-on: https://chromium-review.googlesource.com/263487Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent a825fdce
......@@ -20,13 +20,33 @@
namespace gl
{
////// FramebufferAttachment::Target Implementation //////
FramebufferAttachment::Target::Target(GLenum binding, const ImageIndex &imageIndex)
: mBinding(binding),
mTextureIndex(imageIndex)
{
}
FramebufferAttachment::Target::Target(const Target &other)
: mBinding(other.mBinding),
mTextureIndex(other.mTextureIndex)
{
}
FramebufferAttachment::Target &FramebufferAttachment::Target::operator=(const Target &other)
{
this->mBinding = other.mBinding;
this->mTextureIndex = other.mTextureIndex;
return *this;
}
////// FramebufferAttachment Implementation //////
FramebufferAttachment::FramebufferAttachment(GLenum binding,
const ImageIndex &textureIndex,
RefCountObject *resource)
: mBinding(binding),
mTextureIndex(textureIndex)
FramebufferAttachmentObject *resource)
: mTarget(binding, textureIndex)
{
mResource.set(resource);
}
......@@ -79,60 +99,65 @@ GLenum FramebufferAttachment::getColorEncoding() const
const ImageIndex &FramebufferAttachment::getTextureImageIndex() const
{
ASSERT(type() == GL_TEXTURE);
return mTextureIndex;
return mTarget.textureIndex();
}
GLenum FramebufferAttachment::cubeMapFace() const
{
ASSERT(type() == GL_TEXTURE);
return IsCubeMapTextureTarget(mTextureIndex.type) ? mTextureIndex.type : GL_NONE;
const auto &index = mTarget.textureIndex();
return IsCubeMapTextureTarget(index.type) ? index.type : GL_NONE;
}
GLint FramebufferAttachment::mipLevel() const
{
ASSERT(type() == GL_TEXTURE);
return mTextureIndex.mipIndex;
return mTarget.textureIndex().mipIndex;
}
GLint FramebufferAttachment::layer() const
{
ASSERT(type() == GL_TEXTURE);
if (mTextureIndex.type == GL_TEXTURE_2D_ARRAY || mTextureIndex.type == GL_TEXTURE_3D)
const auto &index = mTarget.textureIndex();
if (index.type == GL_TEXTURE_2D_ARRAY || index.type == GL_TEXTURE_3D)
{
return mTextureIndex.layerIndex;
return index.layerIndex;
}
return 0;
}
///// TextureAttachment Implementation ////////
TextureAttachment::TextureAttachment(GLenum binding, Texture *texture, const ImageIndex &index)
: FramebufferAttachment(binding, index, texture)
GLsizei FramebufferAttachment::getWidth() const
{
return mResource->getAttachmentWidth(mTarget);
}
TextureAttachment::~TextureAttachment()
GLsizei FramebufferAttachment::getHeight() const
{
return mResource->getAttachmentHeight(mTarget);
}
GLsizei TextureAttachment::getSamples() const
GLenum FramebufferAttachment::getInternalFormat() const
{
return 0;
return mResource->getAttachmentInternalFormat(mTarget);
}
GLsizei TextureAttachment::getWidth() const
GLsizei FramebufferAttachment::getSamples() const
{
return getTexture()->getWidth(mTextureIndex.type, mTextureIndex.mipIndex);
return mResource->getAttachmentSamples(mTarget);
}
GLsizei TextureAttachment::getHeight() const
///// TextureAttachment Implementation ////////
TextureAttachment::TextureAttachment(GLenum binding, Texture *texture, const ImageIndex &index)
: FramebufferAttachment(binding, index, texture)
{
return getTexture()->getHeight(mTextureIndex.type, mTextureIndex.mipIndex);
}
GLenum TextureAttachment::getInternalFormat() const
TextureAttachment::~TextureAttachment()
{
return getTexture()->getInternalFormat(mTextureIndex.type, mTextureIndex.mipIndex);
}
GLenum TextureAttachment::type() const
......@@ -146,6 +171,11 @@ Renderbuffer *TextureAttachment::getRenderbuffer() const
return nullptr;
}
Texture *TextureAttachment::getTexture() const
{
return rx::GetAs<Texture>(mResource.get());
}
////// RenderbufferAttachment Implementation //////
RenderbufferAttachment::RenderbufferAttachment(GLenum binding, Renderbuffer *renderbuffer)
......@@ -158,26 +188,6 @@ RenderbufferAttachment::~RenderbufferAttachment()
{
}
GLsizei RenderbufferAttachment::getWidth() const
{
return getRenderbuffer()->getWidth();
}
GLsizei RenderbufferAttachment::getHeight() const
{
return getRenderbuffer()->getHeight();
}
GLenum RenderbufferAttachment::getInternalFormat() const
{
return getRenderbuffer()->getInternalFormat();
}
GLsizei RenderbufferAttachment::getSamples() const
{
return getRenderbuffer()->getSamples();
}
GLenum RenderbufferAttachment::type() const
{
return GL_RENDERBUFFER;
......@@ -189,35 +199,18 @@ Texture *RenderbufferAttachment::getTexture() const
return nullptr;
}
DefaultAttachment::DefaultAttachment(GLenum binding, egl::Surface *surface)
: FramebufferAttachment(binding, ImageIndex::MakeInvalid(), surface)
Renderbuffer *RenderbufferAttachment::getRenderbuffer() const
{
return rx::GetAs<Renderbuffer>(mResource.get());
}
DefaultAttachment::~DefaultAttachment()
{
}
GLsizei DefaultAttachment::getWidth() const
{
return getSurface()->getWidth();
}
GLsizei DefaultAttachment::getHeight() const
{
return getSurface()->getHeight();
}
GLenum DefaultAttachment::getInternalFormat() const
DefaultAttachment::DefaultAttachment(GLenum binding, egl::Surface *surface)
: FramebufferAttachment(binding, ImageIndex::MakeInvalid(), surface)
{
const egl::Config *config = getSurface()->getConfig();
return (getBinding() == GL_BACK ? config->renderTargetFormat : config->depthStencilFormat);
}
GLsizei DefaultAttachment::getSamples() const
DefaultAttachment::~DefaultAttachment()
{
const egl::Config *config = getSurface()->getConfig();
return config->samples;
}
GLenum DefaultAttachment::type() const
......@@ -237,4 +230,9 @@ Renderbuffer *DefaultAttachment::getRenderbuffer() const
return nullptr;
}
const egl::Surface *DefaultAttachment::getSurface() const
{
return rx::GetAs<egl::Surface>(mResource.get());
}
}
......@@ -12,13 +12,19 @@
#include "angle_gl.h"
#include "common/angleutils.h"
#include "libANGLE/Texture.h"
#include "libANGLE/Renderbuffer.h"
#include "libANGLE/Surface.h"
#include "libANGLE/ImageIndex.h"
#include "libANGLE/RefCountObject.h"
namespace egl
{
class Surface;
}
namespace gl
{
class FramebufferAttachmentObject;
class Renderbuffer;
class Texture;
// FramebufferAttachment implements a GL framebuffer attachment.
// Attachments are "light" containers, which store pointers to ref-counted GL objects.
......@@ -31,9 +37,30 @@ class FramebufferAttachment : angle::NonCopyable
public:
FramebufferAttachment(GLenum binding,
const ImageIndex &textureIndex,
RefCountObject *resource);
FramebufferAttachmentObject *resource);
virtual ~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
// object an attachment references. For the three types:
// - a Renderbuffer has a unique renderable target, and needs no target index
// - a Texture has targets for every image and uses an ImageIndex
// - a Surface has targets for Color and Depth/Stencil, and uses the attachment binding
class Target
{
public:
Target(GLenum binding, const ImageIndex &imageIndex);
Target(const Target &other);
Target &operator=(const Target &other);
GLenum binding() const { return mBinding; }
const ImageIndex &textureIndex() const { return mTextureIndex; }
private:
GLenum mBinding;
ImageIndex mTextureIndex;
};
// Helper methods
GLuint getRedSize() const;
GLuint getGreenSize() const;
......@@ -47,7 +74,7 @@ class FramebufferAttachment : angle::NonCopyable
bool isTextureWithId(GLuint textureId) const { return type() == GL_TEXTURE && id() == textureId; }
bool isRenderbufferWithId(GLuint renderbufferId) const { return type() == GL_RENDERBUFFER && id() == renderbufferId; }
GLenum getBinding() const { return mBinding; }
GLenum getBinding() const { return mTarget.binding(); }
GLuint id() const { return mResource.id(); }
// These methods are only legal to call on Texture attachments
......@@ -56,21 +83,20 @@ class FramebufferAttachment : angle::NonCopyable
GLint mipLevel() const;
GLint layer() const;
// Child class interface
virtual GLsizei getWidth() const = 0;
virtual GLsizei getHeight() const = 0;
virtual GLenum getInternalFormat() const = 0;
virtual GLsizei getSamples() const = 0;
GLsizei getWidth() const;
GLsizei getHeight() const;
GLenum getInternalFormat() const;
GLsizei getSamples() const;
// Child class interface
virtual GLenum type() const = 0;
virtual Texture *getTexture() const = 0;
virtual Renderbuffer *getRenderbuffer() const = 0;
protected:
GLenum mBinding;
ImageIndex mTextureIndex;
BindingPointer<RefCountObject> mResource;
Target mTarget;
BindingPointer<FramebufferAttachmentObject> mResource;
};
class TextureAttachment : public FramebufferAttachment
......@@ -79,20 +105,11 @@ class TextureAttachment : public FramebufferAttachment
TextureAttachment(GLenum binding, Texture *texture, const ImageIndex &index);
virtual ~TextureAttachment();
virtual GLsizei getSamples() const;
virtual GLsizei getWidth() const;
virtual GLsizei getHeight() const;
virtual GLenum getInternalFormat() const;
virtual GLenum type() const;
virtual Renderbuffer *getRenderbuffer() const;
Texture *getTexture() const override
{
return rx::GetAs<Texture>(mResource.get());
}
Texture *getTexture() const override;
};
class RenderbufferAttachment : public FramebufferAttachment
......@@ -102,19 +119,11 @@ class RenderbufferAttachment : public FramebufferAttachment
virtual ~RenderbufferAttachment();
virtual GLsizei getWidth() const;
virtual GLsizei getHeight() const;
virtual GLenum getInternalFormat() const;
virtual GLsizei getSamples() const;
virtual GLenum type() const;
virtual Texture *getTexture() const;
Renderbuffer *getRenderbuffer() const override
{
return rx::GetAs<Renderbuffer>(mResource.get());
}
Renderbuffer *getRenderbuffer() const override;
};
class DefaultAttachment : public FramebufferAttachment
......@@ -124,20 +133,24 @@ class DefaultAttachment : public FramebufferAttachment
virtual ~DefaultAttachment();
virtual GLsizei getWidth() const;
virtual GLsizei getHeight() const;
virtual GLenum getInternalFormat() const;
virtual GLsizei getSamples() const;
virtual GLenum type() const;
virtual Texture *getTexture() const;
virtual Renderbuffer *getRenderbuffer() const;
const egl::Surface *getSurface() const
{
return rx::GetAs<egl::Surface>(mResource.get());
}
const egl::Surface *getSurface() const;
};
// A base class for objects that FBO Attachments may point to.
class FramebufferAttachmentObject : public RefCountObject
{
public:
FramebufferAttachmentObject(GLuint id) : RefCountObject(id) {}
virtual GLsizei getAttachmentWidth(const FramebufferAttachment::Target &target) const = 0;
virtual GLsizei getAttachmentHeight(const FramebufferAttachment::Target &target) const = 0;
virtual GLenum getAttachmentInternalFormat(const FramebufferAttachment::Target &target) const = 0;
virtual GLsizei getAttachmentSamples(const FramebufferAttachment::Target &target) const = 0;
};
}
......
......@@ -19,8 +19,9 @@
namespace gl
{
Renderbuffer::Renderbuffer(rx::RenderbufferImpl *impl, GLuint id)
: RefCountObject(id),
: FramebufferAttachmentObject(id),
mRenderbuffer(impl),
mWidth(0),
mHeight(0),
......
......@@ -12,11 +12,9 @@
#define LIBANGLE_RENDERBUFFER_H_
#include "angle_gl.h"
#include "libANGLE/Error.h"
#include "libANGLE/RefCountObject.h"
#include "common/angleutils.h"
#include "libANGLE/Error.h"
#include "libANGLE/FramebufferAttachment.h"
namespace rx
{
......@@ -25,14 +23,12 @@ class RenderbufferImpl;
namespace gl
{
class FramebufferAttachment;
// A GL renderbuffer object is usually used as a depth or stencil buffer attachment
// for a framebuffer object. The renderbuffer itself is a distinct GL object, see
// FramebufferAttachment and Framebuffer for how they are applied to an FBO via an
// attachment point.
class Renderbuffer : public RefCountObject
class Renderbuffer : public FramebufferAttachmentObject
{
public:
Renderbuffer(rx::RenderbufferImpl *impl, GLuint id);
......@@ -55,6 +51,12 @@ class Renderbuffer : public RefCountObject
GLuint getDepthSize() const;
GLuint getStencilSize() const;
// FramebufferAttachmentObject Impl
GLsizei getAttachmentWidth(const FramebufferAttachment::Target &/*target*/) const override { return getWidth(); }
GLsizei getAttachmentHeight(const FramebufferAttachment::Target &/*target*/) const override { return getHeight(); }
GLenum getAttachmentInternalFormat(const FramebufferAttachment::Target &/*target*/) const override { return getInternalFormat(); }
GLsizei getAttachmentSamples(const FramebufferAttachment::Target &/*target*/) const override { return getSamples(); }
private:
rx::RenderbufferImpl *mRenderbuffer;
......
......@@ -20,7 +20,7 @@ namespace egl
{
Surface::Surface(rx::SurfaceImpl *impl, EGLint surfaceType, const egl::Config *config, const AttributeMap &attributes)
: RefCountObject(0), // id unused
: FramebufferAttachmentObject(0), // id unused
mImplementation(impl),
mType(surfaceType),
mConfig(config),
......@@ -163,4 +163,15 @@ Error Surface::releaseTexImage(EGLint buffer)
return mImplementation->releaseTexImage(buffer);
}
GLenum Surface::getAttachmentInternalFormat(const gl::FramebufferAttachment::Target &target) const
{
const egl::Config *config = getConfig();
return (target.binding() == GL_BACK ? config->renderTargetFormat : config->depthStencilFormat);
}
GLsizei Surface::getAttachmentSamples(const gl::FramebufferAttachment::Target &target) const
{
return getConfig()->samples;
}
}
......@@ -15,7 +15,7 @@
#include "common/angleutils.h"
#include "libANGLE/Error.h"
#include "libANGLE/RefCountObject.h"
#include "libANGLE/FramebufferAttachment.h"
namespace gl
{
......@@ -33,7 +33,7 @@ class AttributeMap;
class Display;
struct Config;
class Surface final : public RefCountObject
class Surface final : public gl::FramebufferAttachmentObject
{
public:
Surface(rx::SurfaceImpl *impl, EGLint surfaceType, const egl::Config *config, const AttributeMap &attributes);
......@@ -68,6 +68,12 @@ class Surface final : public RefCountObject
EGLint isFixedSize() const;
// FramebufferAttachmentObject implementation
GLsizei getAttachmentWidth(const gl::FramebufferAttachment::Target &/*target*/) const override { return getWidth(); }
GLsizei getAttachmentHeight(const gl::FramebufferAttachment::Target &/*target*/) const override { return getHeight(); }
GLenum getAttachmentInternalFormat(const gl::FramebufferAttachment::Target &target) const override;
GLsizei getAttachmentSamples(const gl::FramebufferAttachment::Target &target) const override;
private:
virtual ~Surface();
......
......@@ -7,14 +7,14 @@
// Texture.cpp: Implements the gl::Texture class. [OpenGL ES 2.0.24] section 3.7 page 63.
#include "libANGLE/Texture.h"
#include "libANGLE/Data.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/Config.h"
#include "libANGLE/Surface.h"
#include "common/mathutil.h"
#include "common/utilities.h"
#include "libANGLE/Config.h"
#include "libANGLE/Data.h"
#include "libANGLE/Surface.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/TextureImpl.h"
namespace gl
{
......@@ -49,7 +49,7 @@ static size_t GetImageDescIndex(GLenum target, size_t level)
unsigned int Texture::mCurrentTextureSerial = 1;
Texture::Texture(rx::TextureImpl *impl, GLuint id, GLenum target)
: RefCountObject(id),
: FramebufferAttachmentObject(id),
mTexture(impl),
mTextureSerial(issueTextureSerial()),
mUsage(GL_NONE),
......@@ -570,4 +570,25 @@ Texture::SamplerCompletenessCache::SamplerCompletenessCache()
{
}
GLsizei Texture::getAttachmentWidth(const gl::FramebufferAttachment::Target &target) const
{
return getWidth(target.textureIndex().type, target.textureIndex().mipIndex);
}
GLsizei Texture::getAttachmentHeight(const gl::FramebufferAttachment::Target &target) const
{
return getHeight(target.textureIndex().type, target.textureIndex().mipIndex);
}
GLenum Texture::getAttachmentInternalFormat(const gl::FramebufferAttachment::Target &target) const
{
return getInternalFormat(target.textureIndex().type, target.textureIndex().mipIndex);
}
GLsizei Texture::getAttachmentSamples(const gl::FramebufferAttachment::Target &/*target*/) const
{
// Multisample textures not currently supported
return 0;
}
}
......@@ -9,23 +9,27 @@
#ifndef LIBANGLE_TEXTURE_H_
#define LIBANGLE_TEXTURE_H_
#include "common/debug.h"
#include "libANGLE/RefCountObject.h"
#include "libANGLE/angletypes.h"
#include "libANGLE/Constants.h"
#include "libANGLE/renderer/TextureImpl.h"
#include "libANGLE/Caps.h"
#include "angle_gl.h"
#include <vector>
#include <map>
#include "angle_gl.h"
#include "common/debug.h"
#include "libANGLE/Caps.h"
#include "libANGLE/Constants.h"
#include "libANGLE/Error.h"
#include "libANGLE/FramebufferAttachment.h"
#include "libANGLE/angletypes.h"
namespace egl
{
class Surface;
}
namespace rx
{
class TextureImpl;
}
namespace gl
{
class Framebuffer;
......@@ -33,7 +37,7 @@ struct Data;
bool IsMipmapFiltered(const gl::SamplerState &samplerState);
class Texture final : public RefCountObject
class Texture final : public FramebufferAttachmentObject
{
public:
Texture(rx::TextureImpl *impl, GLuint id, GLenum target);
......@@ -90,6 +94,12 @@ class Texture final : public RefCountObject
static const GLuint INCOMPLETE_TEXTURE_ID = static_cast<GLuint>(-1); // Every texture takes an id at creation time. The value is arbitrary because it is never registered with the resource manager.
// FramebufferAttachmentObject implementation
GLsizei getAttachmentWidth(const FramebufferAttachment::Target &target) const override;
GLsizei getAttachmentHeight(const FramebufferAttachment::Target &target) const override;
GLenum getAttachmentInternalFormat(const FramebufferAttachment::Target &target) const override;
GLsizei getAttachmentSamples(const FramebufferAttachment::Target &target) const override;
private:
static unsigned int issueTextureSerial();
......
......@@ -10,10 +10,8 @@
#define LIBANGLE_RENDERER_RENDERBUFFERIMPL_H_
#include "angle_gl.h"
#include "libANGLE/Error.h"
#include "common/angleutils.h"
#include "libANGLE/Error.h"
namespace rx
{
......
......@@ -9,14 +9,12 @@
#ifndef LIBANGLE_RENDERER_TEXTUREIMPL_H_
#define LIBANGLE_RENDERER_TEXTUREIMPL_H_
#include "libANGLE/Error.h"
#include "libANGLE/ImageIndex.h"
#include "common/angleutils.h"
#include <stdint.h>
#include "angle_gl.h"
#include <stdint.h>
#include "common/angleutils.h"
#include "libANGLE/Error.h"
#include "libANGLE/ImageIndex.h"
namespace egl
{
......@@ -40,7 +38,8 @@ namespace rx
class TextureImpl : angle::NonCopyable
{
public:
virtual ~TextureImpl() {};
TextureImpl() {}
virtual ~TextureImpl() {}
virtual void setUsage(GLenum usage) = 0;
......
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