Commit d1405e51 by Jamie Madill

Share FBO state with object and Impl.

This patch introduces a new Framebuffer::Data class, which stores attachment related state. This will eliminate the need to store duplicated state between the classes. BUG=angleproject:930 Change-Id: I80de4db39ab99d623b0ad8306bf3cbb794cd8bd5 Reviewed-on: https://chromium-review.googlesource.com/254100Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 0af26e10
...@@ -184,10 +184,8 @@ void Context::makeCurrent(egl::Surface *surface) ...@@ -184,10 +184,8 @@ void Context::makeCurrent(egl::Surface *surface)
mHasBeenCurrent = true; mHasBeenCurrent = true;
} }
Framebuffer *framebufferZero = new DefaultFramebuffer(mRenderer->createFramebuffer(), // TODO(jmadill): do not allocate new pointers here
mRenderer->createDefaultAttachment(GL_BACK, surface), Framebuffer *framebufferZero = new DefaultFramebuffer(mCaps, mRenderer, surface);
mRenderer->createDefaultAttachment(GL_DEPTH, surface),
mRenderer->createDefaultAttachment(GL_STENCIL, surface));
setFramebufferZero(framebufferZero); setFramebufferZero(framebufferZero);
...@@ -523,7 +521,7 @@ void Context::bindReadFramebuffer(GLuint framebuffer) ...@@ -523,7 +521,7 @@ void Context::bindReadFramebuffer(GLuint framebuffer)
{ {
if (!getFramebuffer(framebuffer)) if (!getFramebuffer(framebuffer))
{ {
mFramebufferMap[framebuffer] = new Framebuffer(mRenderer->createFramebuffer(), framebuffer); mFramebufferMap[framebuffer] = new Framebuffer(mCaps, mRenderer, framebuffer);
} }
mState.setReadFramebufferBinding(getFramebuffer(framebuffer)); mState.setReadFramebufferBinding(getFramebuffer(framebuffer));
...@@ -533,7 +531,7 @@ void Context::bindDrawFramebuffer(GLuint framebuffer) ...@@ -533,7 +531,7 @@ void Context::bindDrawFramebuffer(GLuint framebuffer)
{ {
if (!getFramebuffer(framebuffer)) if (!getFramebuffer(framebuffer))
{ {
mFramebufferMap[framebuffer] = new Framebuffer(mRenderer->createFramebuffer(), framebuffer); mFramebufferMap[framebuffer] = new Framebuffer(mCaps, mRenderer, framebuffer);
} }
mState.setDrawFramebufferBinding(getFramebuffer(framebuffer)); mState.setDrawFramebufferBinding(getFramebuffer(framebuffer));
......
...@@ -20,23 +20,29 @@ ...@@ -20,23 +20,29 @@
namespace rx namespace rx
{ {
class RenderbufferImpl;
struct Workarounds;
class DefaultAttachmentImpl; class DefaultAttachmentImpl;
class FramebufferImpl; class FramebufferImpl;
class RenderbufferImpl;
class Renderer;
struct Workarounds;
}
namespace egl
{
class Surface;
} }
namespace gl namespace gl
{ {
class FramebufferAttachment; class FramebufferAttachment;
class Texture;
class Renderbuffer; class Renderbuffer;
struct ImageIndex; class State;
struct Caps; class Texture;
struct Extensions;
class TextureCapsMap; class TextureCapsMap;
struct Caps;
struct Data; struct Data;
class State; struct Extensions;
struct ImageIndex;
struct Rectangle; struct Rectangle;
typedef std::vector<FramebufferAttachment *> ColorbufferInfo; typedef std::vector<FramebufferAttachment *> ColorbufferInfo;
...@@ -44,7 +50,25 @@ typedef std::vector<FramebufferAttachment *> ColorbufferInfo; ...@@ -44,7 +50,25 @@ typedef std::vector<FramebufferAttachment *> ColorbufferInfo;
class Framebuffer class Framebuffer
{ {
public: public:
Framebuffer(rx::FramebufferImpl *impl, GLuint id);
class Data final
{
public:
Data(const Caps &caps);
~Data();
std::vector<FramebufferAttachment *> mColorAttachments;
FramebufferAttachment *mDepthAttachment;
FramebufferAttachment *mStencilAttachment;
std::vector<GLenum> mDrawBufferStates;
GLenum mReadBufferState;
private:
DISALLOW_COPY_AND_ASSIGN(Data);
};
Framebuffer(const Caps &caps, rx::Renderer *renderer, GLuint id);
virtual ~Framebuffer(); virtual ~Framebuffer();
const rx::FramebufferImpl *getImplementation() const { return mImpl; } const rx::FramebufferImpl *getImplementation() const { return mImpl; }
...@@ -108,17 +132,12 @@ class Framebuffer ...@@ -108,17 +132,12 @@ class Framebuffer
protected: protected:
void setAttachment(GLenum attachment, FramebufferAttachment *attachmentObj); void setAttachment(GLenum attachment, FramebufferAttachment *attachmentObj);
void detachResourceById(GLenum resourceType, GLuint resourceId);
Data mData;
rx::FramebufferImpl *mImpl; rx::FramebufferImpl *mImpl;
GLuint mId; GLuint mId;
FramebufferAttachment *mColorbuffers[IMPLEMENTATION_MAX_DRAW_BUFFERS];
GLenum mDrawBufferStates[IMPLEMENTATION_MAX_DRAW_BUFFERS];
GLenum mReadBufferState;
FramebufferAttachment *mDepthbuffer;
FramebufferAttachment *mStencilbuffer;
private: private:
DISALLOW_COPY_AND_ASSIGN(Framebuffer); DISALLOW_COPY_AND_ASSIGN(Framebuffer);
}; };
...@@ -126,8 +145,7 @@ class Framebuffer ...@@ -126,8 +145,7 @@ class Framebuffer
class DefaultFramebuffer : public Framebuffer class DefaultFramebuffer : public Framebuffer
{ {
public: public:
DefaultFramebuffer(rx::FramebufferImpl *impl, rx::DefaultAttachmentImpl *colorAttachment, DefaultFramebuffer(const gl::Caps &caps, rx::Renderer *renderer, egl::Surface *surface);
rx::DefaultAttachmentImpl *depthAttachment, rx::DefaultAttachmentImpl *stencilAttachment);
private: private:
DISALLOW_COPY_AND_ASSIGN(DefaultFramebuffer); DISALLOW_COPY_AND_ASSIGN(DefaultFramebuffer);
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "angle_gl.h" #include "angle_gl.h"
#include "common/angleutils.h" #include "common/angleutils.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/Framebuffer.h"
namespace gl namespace gl
{ {
...@@ -27,8 +28,8 @@ namespace rx ...@@ -27,8 +28,8 @@ namespace rx
class FramebufferImpl class FramebufferImpl
{ {
public: public:
FramebufferImpl() {} FramebufferImpl(const gl::Framebuffer::Data &data) : mData(data) { }
virtual ~FramebufferImpl() {}; virtual ~FramebufferImpl() { }
virtual void setColorAttachment(size_t index, const gl::FramebufferAttachment *attachment) = 0; virtual void setColorAttachment(size_t index, const gl::FramebufferAttachment *attachment) = 0;
virtual void setDepthttachment(const gl::FramebufferAttachment *attachment) = 0; virtual void setDepthttachment(const gl::FramebufferAttachment *attachment) = 0;
...@@ -56,6 +57,11 @@ class FramebufferImpl ...@@ -56,6 +57,11 @@ class FramebufferImpl
virtual GLenum checkStatus() const = 0; virtual GLenum checkStatus() const = 0;
const gl::Framebuffer::Data &getData() const { return mData; }
protected:
const gl::Framebuffer::Data &mData;
private: private:
DISALLOW_COPY_AND_ASSIGN(FramebufferImpl); DISALLOW_COPY_AND_ASSIGN(FramebufferImpl);
}; };
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "libANGLE/Caps.h" #include "libANGLE/Caps.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/Framebuffer.h"
#include "libANGLE/Uniform.h" #include "libANGLE/Uniform.h"
#include "libANGLE/angletypes.h" #include "libANGLE/angletypes.h"
#include "libANGLE/renderer/Workarounds.h" #include "libANGLE/renderer/Workarounds.h"
...@@ -31,7 +32,6 @@ class Surface; ...@@ -31,7 +32,6 @@ class Surface;
namespace gl namespace gl
{ {
class Buffer; class Buffer;
class Framebuffer;
struct Data; struct Data;
} }
...@@ -76,7 +76,7 @@ class Renderer ...@@ -76,7 +76,7 @@ class Renderer
// Framebuffer creation // Framebuffer creation
virtual DefaultAttachmentImpl *createDefaultAttachment(GLenum type, egl::Surface *surface) = 0; virtual DefaultAttachmentImpl *createDefaultAttachment(GLenum type, egl::Surface *surface) = 0;
virtual FramebufferImpl *createFramebuffer() = 0; virtual FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) = 0;
// Texture creation // Texture creation
virtual TextureImpl *createTexture(GLenum target) = 0; virtual TextureImpl *createTexture(GLenum target) = 0;
......
...@@ -61,8 +61,9 @@ RenderTargetD3D *DefaultAttachmentD3D::getRenderTarget() const ...@@ -61,8 +61,9 @@ RenderTargetD3D *DefaultAttachmentD3D::getRenderTarget() const
} }
FramebufferD3D::FramebufferD3D(RendererD3D *renderer) FramebufferD3D::FramebufferD3D(const gl::Framebuffer::Data &data, RendererD3D *renderer)
: mRenderer(renderer), : FramebufferImpl(data),
mRenderer(renderer),
mColorBuffers(renderer->getRendererCaps().maxColorAttachments), mColorBuffers(renderer->getRendererCaps().maxColorAttachments),
mDepthbuffer(nullptr), mDepthbuffer(nullptr),
mStencilbuffer(nullptr), mStencilbuffer(nullptr),
......
...@@ -51,7 +51,7 @@ class DefaultAttachmentD3D : public DefaultAttachmentImpl ...@@ -51,7 +51,7 @@ class DefaultAttachmentD3D : public DefaultAttachmentImpl
class FramebufferD3D : public FramebufferImpl class FramebufferD3D : public FramebufferImpl
{ {
public: public:
FramebufferD3D(RendererD3D *renderer); FramebufferD3D(const gl::Framebuffer::Data &data, RendererD3D *renderer);
virtual ~FramebufferD3D(); virtual ~FramebufferD3D();
void setColorAttachment(size_t index, const gl::FramebufferAttachment *attachment) override; void setColorAttachment(size_t index, const gl::FramebufferAttachment *attachment) override;
......
...@@ -24,8 +24,8 @@ ...@@ -24,8 +24,8 @@
namespace rx namespace rx
{ {
Framebuffer11::Framebuffer11(Renderer11 *renderer) Framebuffer11::Framebuffer11(const gl::Framebuffer::Data &data, Renderer11 *renderer)
: FramebufferD3D(renderer), : FramebufferD3D(data, renderer),
mRenderer(renderer) mRenderer(renderer)
{ {
ASSERT(mRenderer != nullptr); ASSERT(mRenderer != nullptr);
......
...@@ -18,7 +18,7 @@ class Renderer11; ...@@ -18,7 +18,7 @@ class Renderer11;
class Framebuffer11 : public FramebufferD3D class Framebuffer11 : public FramebufferD3D
{ {
public: public:
Framebuffer11(Renderer11 *renderer); Framebuffer11(const gl::Framebuffer::Data &data, Renderer11 *renderer);
virtual ~Framebuffer11(); virtual ~Framebuffer11();
// Invalidate the cached swizzles of all bound texture attachments. // Invalidate the cached swizzles of all bound texture attachments.
......
...@@ -2626,9 +2626,9 @@ DefaultAttachmentImpl *Renderer11::createDefaultAttachment(GLenum type, egl::Sur ...@@ -2626,9 +2626,9 @@ DefaultAttachmentImpl *Renderer11::createDefaultAttachment(GLenum type, egl::Sur
} }
} }
FramebufferImpl *Renderer11::createFramebuffer() FramebufferImpl *Renderer11::createFramebuffer(const gl::Framebuffer::Data &data)
{ {
return new Framebuffer11(this); return new Framebuffer11(data, this);
} }
CompilerImpl *Renderer11::createCompiler(const gl::Data &data) CompilerImpl *Renderer11::createCompiler(const gl::Data &data)
......
...@@ -149,8 +149,8 @@ class Renderer11 : public RendererD3D ...@@ -149,8 +149,8 @@ class Renderer11 : public RendererD3D
virtual gl::Error createRenderTarget(int width, int height, GLenum format, GLsizei samples, RenderTargetD3D **outRT); virtual gl::Error createRenderTarget(int width, int height, GLenum format, GLsizei samples, RenderTargetD3D **outRT);
// Framebuffer creation // Framebuffer creation
virtual DefaultAttachmentImpl *createDefaultAttachment(GLenum type, egl::Surface *surface) override; DefaultAttachmentImpl *createDefaultAttachment(GLenum type, egl::Surface *surface) override;
virtual FramebufferImpl *createFramebuffer() override; FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override;
// Shader creation // Shader creation
virtual CompilerImpl *createCompiler(const gl::Data &data); virtual CompilerImpl *createCompiler(const gl::Data &data);
......
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
namespace rx namespace rx
{ {
Framebuffer9::Framebuffer9(Renderer9 *renderer) Framebuffer9::Framebuffer9(const gl::Framebuffer::Data &data, Renderer9 *renderer)
: FramebufferD3D(renderer), : FramebufferD3D(data, renderer),
mRenderer(renderer) mRenderer(renderer)
{ {
ASSERT(mRenderer != nullptr); ASSERT(mRenderer != nullptr);
......
...@@ -18,7 +18,7 @@ class Renderer9; ...@@ -18,7 +18,7 @@ class Renderer9;
class Framebuffer9 : public FramebufferD3D class Framebuffer9 : public FramebufferD3D
{ {
public: public:
Framebuffer9(Renderer9 *renderer); Framebuffer9(const gl::Framebuffer::Data &data, Renderer9 *renderer);
virtual ~Framebuffer9(); virtual ~Framebuffer9();
private: private:
......
...@@ -2650,9 +2650,9 @@ DefaultAttachmentImpl *Renderer9::createDefaultAttachment(GLenum type, egl::Surf ...@@ -2650,9 +2650,9 @@ DefaultAttachmentImpl *Renderer9::createDefaultAttachment(GLenum type, egl::Surf
} }
} }
FramebufferImpl *Renderer9::createFramebuffer() FramebufferImpl *Renderer9::createFramebuffer(const gl::Framebuffer::Data &data)
{ {
return new Framebuffer9(this); return new Framebuffer9(data, this);
} }
CompilerImpl *Renderer9::createCompiler(const gl::Data &data) CompilerImpl *Renderer9::createCompiler(const gl::Data &data)
......
...@@ -158,8 +158,8 @@ class Renderer9 : public RendererD3D ...@@ -158,8 +158,8 @@ class Renderer9 : public RendererD3D
virtual gl::Error createRenderTarget(int width, int height, GLenum format, GLsizei samples, RenderTargetD3D **outRT); virtual gl::Error createRenderTarget(int width, int height, GLenum format, GLsizei samples, RenderTargetD3D **outRT);
// Framebuffer creation // Framebuffer creation
virtual DefaultAttachmentImpl *createDefaultAttachment(GLenum type, egl::Surface *surface) override; DefaultAttachmentImpl *createDefaultAttachment(GLenum type, egl::Surface *surface) override;
virtual FramebufferImpl *createFramebuffer() override; FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override;
// Shader creation // Shader creation
virtual CompilerImpl *createCompiler(const gl::Data &data); virtual CompilerImpl *createCompiler(const gl::Data &data);
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
namespace rx namespace rx
{ {
FramebufferGL::FramebufferGL() FramebufferGL::FramebufferGL(const gl::Framebuffer::Data &data)
: FramebufferImpl() : FramebufferImpl(data)
{} {}
FramebufferGL::~FramebufferGL() FramebufferGL::~FramebufferGL()
......
...@@ -17,7 +17,7 @@ namespace rx ...@@ -17,7 +17,7 @@ namespace rx
class FramebufferGL : public FramebufferImpl class FramebufferGL : public FramebufferImpl
{ {
public: public:
FramebufferGL(); FramebufferGL(const gl::Framebuffer::Data &data);
~FramebufferGL() override; ~FramebufferGL() override;
void setColorAttachment(size_t index, const gl::FramebufferAttachment *attachment) override; void setColorAttachment(size_t index, const gl::FramebufferAttachment *attachment) override;
......
...@@ -100,9 +100,9 @@ DefaultAttachmentImpl *RendererGL::createDefaultAttachment(GLenum type, egl::Sur ...@@ -100,9 +100,9 @@ DefaultAttachmentImpl *RendererGL::createDefaultAttachment(GLenum type, egl::Sur
return new DefaultAttachmentGL(); return new DefaultAttachmentGL();
} }
FramebufferImpl *RendererGL::createFramebuffer() FramebufferImpl *RendererGL::createFramebuffer(const gl::Framebuffer::Data &data)
{ {
return new FramebufferGL(); return new FramebufferGL(data);
} }
TextureImpl *RendererGL::createTexture(GLenum target) TextureImpl *RendererGL::createTexture(GLenum target)
......
...@@ -38,7 +38,7 @@ class RendererGL : public Renderer ...@@ -38,7 +38,7 @@ class RendererGL : public Renderer
// Framebuffer creation // Framebuffer creation
DefaultAttachmentImpl *createDefaultAttachment(GLenum type, egl::Surface *surface) override; DefaultAttachmentImpl *createDefaultAttachment(GLenum type, egl::Surface *surface) override;
FramebufferImpl *createFramebuffer() override; FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override;
// Texture creation // Texture creation
TextureImpl *createTexture(GLenum target) override; TextureImpl *createTexture(GLenum target) override;
......
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