Commit 6c7b4ada by Jamie Madill

Add new ref-counted Renderbuffer class.

Renderbuffers are a clear object type in GL, and this patch adds a more consistent state representation for them. They're managed by the ResourceManager, and have a storage implementation similar to Textures, but much simpler. BUG=angle:660 Change-Id: Ia17199bb8cb570d48db42e1f28ccbcc12a902fcf Reviewed-on: https://chromium-review.googlesource.com/201834Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org>
parent 4d632d8e
...@@ -1066,7 +1066,7 @@ Texture *Context::getTexture(GLuint handle) ...@@ -1066,7 +1066,7 @@ Texture *Context::getTexture(GLuint handle)
return mResourceManager->getTexture(handle); return mResourceManager->getTexture(handle);
} }
FramebufferAttachment *Context::getRenderbuffer(GLuint handle) Renderbuffer *Context::getRenderbuffer(GLuint handle)
{ {
return mResourceManager->getRenderbuffer(handle); return mResourceManager->getRenderbuffer(handle);
} }
...@@ -1399,7 +1399,7 @@ void Context::setRenderbufferStorage(GLsizei width, GLsizei height, GLenum inter ...@@ -1399,7 +1399,7 @@ void Context::setRenderbufferStorage(GLsizei width, GLsizei height, GLenum inter
return; return;
} }
FramebufferAttachment *renderbufferObject = mState.renderbuffer.get(); Renderbuffer *renderbufferObject = mState.renderbuffer.get();
renderbufferObject->setStorage(renderbuffer); renderbufferObject->setStorage(renderbuffer);
} }
......
...@@ -51,7 +51,7 @@ class TextureCubeMap; ...@@ -51,7 +51,7 @@ class TextureCubeMap;
class Texture3D; class Texture3D;
class Texture2DArray; class Texture2DArray;
class Framebuffer; class Framebuffer;
class FramebufferAttachment; class Renderbuffer;
class RenderbufferStorage; class RenderbufferStorage;
class Colorbuffer; class Colorbuffer;
class Depthbuffer; class Depthbuffer;
...@@ -101,7 +101,7 @@ struct State ...@@ -101,7 +101,7 @@ struct State
BindingPointer<Buffer> arrayBuffer; BindingPointer<Buffer> arrayBuffer;
GLuint readFramebuffer; GLuint readFramebuffer;
GLuint drawFramebuffer; GLuint drawFramebuffer;
BindingPointer<FramebufferAttachment> renderbuffer; BindingPointer<Renderbuffer> renderbuffer;
GLuint currentProgram; GLuint currentProgram;
VertexAttribCurrentValueData vertexAttribCurrentValues[MAX_VERTEX_ATTRIBS]; // From glVertexAttrib VertexAttribCurrentValueData vertexAttribCurrentValues[MAX_VERTEX_ATTRIBS]; // From glVertexAttrib
...@@ -332,7 +332,7 @@ class Context ...@@ -332,7 +332,7 @@ class Context
Program *getProgram(GLuint handle) const; Program *getProgram(GLuint handle) const;
Texture *getTexture(GLuint handle); Texture *getTexture(GLuint handle);
Framebuffer *getFramebuffer(GLuint handle) const; Framebuffer *getFramebuffer(GLuint handle) const;
FramebufferAttachment *getRenderbuffer(GLuint handle); Renderbuffer *getRenderbuffer(GLuint handle);
VertexArray *getVertexArray(GLuint handle) const; VertexArray *getVertexArray(GLuint handle) const;
Sampler *getSampler(GLuint handle) const; Sampler *getSampler(GLuint handle) const;
Query *getQuery(GLuint handle, bool create, GLenum type); Query *getQuery(GLuint handle, bool create, GLenum type);
......
...@@ -42,8 +42,13 @@ Framebuffer::~Framebuffer() ...@@ -42,8 +42,13 @@ Framebuffer::~Framebuffer()
mStencilbuffer.set(NULL, GL_NONE, 0, 0); mStencilbuffer.set(NULL, GL_NONE, 0, 0);
} }
FramebufferAttachment *Framebuffer::lookupAttachment(GLenum type, GLuint handle, GLint level, GLint layer) const FramebufferAttachmentImpl *Framebuffer::createAttachmentImpl(GLenum type, GLuint handle, GLint level, GLint layer) const
{ {
if (handle == 0)
{
return NULL;
}
gl::Context *context = gl::getContext(); gl::Context *context = gl::getContext();
switch (type) switch (type)
...@@ -52,14 +57,15 @@ FramebufferAttachment *Framebuffer::lookupAttachment(GLenum type, GLuint handle, ...@@ -52,14 +57,15 @@ FramebufferAttachment *Framebuffer::lookupAttachment(GLenum type, GLuint handle,
return NULL; return NULL;
case GL_RENDERBUFFER: case GL_RENDERBUFFER:
return context->getRenderbuffer(handle); return new RenderbufferAttachment(context->getRenderbuffer(handle));
case GL_TEXTURE_2D: case GL_TEXTURE_2D:
{ {
Texture *texture = context->getTexture(handle); Texture *texture = context->getTexture(handle);
if (texture && texture->getTarget() == GL_TEXTURE_2D) if (texture && texture->getTarget() == GL_TEXTURE_2D)
{ {
return static_cast<Texture2D*>(texture)->getAttachment(level); Texture2D *tex2D = static_cast<Texture2D*>(texture);
return new Texture2DAttachment(tex2D, level);
} }
else else
{ {
...@@ -77,7 +83,8 @@ FramebufferAttachment *Framebuffer::lookupAttachment(GLenum type, GLuint handle, ...@@ -77,7 +83,8 @@ FramebufferAttachment *Framebuffer::lookupAttachment(GLenum type, GLuint handle,
Texture *texture = context->getTexture(handle); Texture *texture = context->getTexture(handle);
if (texture && texture->getTarget() == GL_TEXTURE_CUBE_MAP) if (texture && texture->getTarget() == GL_TEXTURE_CUBE_MAP)
{ {
return static_cast<TextureCubeMap*>(texture)->getAttachment(type, level); TextureCubeMap *texCube = static_cast<TextureCubeMap*>(texture);
return new TextureCubeMapAttachment(texCube, type, level);
} }
else else
{ {
...@@ -90,7 +97,8 @@ FramebufferAttachment *Framebuffer::lookupAttachment(GLenum type, GLuint handle, ...@@ -90,7 +97,8 @@ FramebufferAttachment *Framebuffer::lookupAttachment(GLenum type, GLuint handle,
Texture *texture = context->getTexture(handle); Texture *texture = context->getTexture(handle);
if (texture && texture->getTarget() == GL_TEXTURE_3D) if (texture && texture->getTarget() == GL_TEXTURE_3D)
{ {
return static_cast<Texture3D*>(texture)->getAttachment(level, layer); Texture3D *tex3D = static_cast<Texture3D*>(texture);
return new Texture3DAttachment(tex3D, level, layer);
} }
else else
{ {
...@@ -103,7 +111,8 @@ FramebufferAttachment *Framebuffer::lookupAttachment(GLenum type, GLuint handle, ...@@ -103,7 +111,8 @@ FramebufferAttachment *Framebuffer::lookupAttachment(GLenum type, GLuint handle,
Texture *texture = context->getTexture(handle); Texture *texture = context->getTexture(handle);
if (texture && texture->getTarget() == GL_TEXTURE_2D_ARRAY) if (texture && texture->getTarget() == GL_TEXTURE_2D_ARRAY)
{ {
return static_cast<Texture2DArray*>(texture)->getAttachment(level, layer); Texture2DArray *tex2DArray = static_cast<Texture2DArray*>(texture);
return new Texture2DArrayAttachment(tex2DArray, level, layer);
} }
else else
{ {
...@@ -120,10 +129,11 @@ FramebufferAttachment *Framebuffer::lookupAttachment(GLenum type, GLuint handle, ...@@ -120,10 +129,11 @@ FramebufferAttachment *Framebuffer::lookupAttachment(GLenum type, GLuint handle,
void Framebuffer::setColorbuffer(unsigned int colorAttachment, GLenum type, GLuint colorbuffer, GLint level, GLint layer) void Framebuffer::setColorbuffer(unsigned int colorAttachment, GLenum type, GLuint colorbuffer, GLint level, GLint layer)
{ {
ASSERT(colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS); ASSERT(colorAttachment < IMPLEMENTATION_MAX_DRAW_BUFFERS);
FramebufferAttachment *attachment = lookupAttachment(type, colorbuffer, level, layer); FramebufferAttachmentImpl *attachmentImpl = createAttachmentImpl(type, colorbuffer, level, layer);
if (attachment) if (attachmentImpl)
{ {
mColorbuffers[colorAttachment].set(attachment, type, level, layer); FramebufferAttachment *newAttachment = new FramebufferAttachment(mRenderer, colorbuffer, attachmentImpl);
mColorbuffers[colorAttachment].set(newAttachment, type, level, layer);
} }
else else
{ {
...@@ -133,10 +143,11 @@ void Framebuffer::setColorbuffer(unsigned int colorAttachment, GLenum type, GLui ...@@ -133,10 +143,11 @@ void Framebuffer::setColorbuffer(unsigned int colorAttachment, GLenum type, GLui
void Framebuffer::setDepthbuffer(GLenum type, GLuint depthbuffer, GLint level, GLint layer) void Framebuffer::setDepthbuffer(GLenum type, GLuint depthbuffer, GLint level, GLint layer)
{ {
FramebufferAttachment *attachment = lookupAttachment(type, depthbuffer, level, layer); FramebufferAttachmentImpl *attachmentImpl = createAttachmentImpl(type, depthbuffer, level, layer);
if (attachment) if (attachmentImpl)
{ {
mDepthbuffer.set(attachment, type, level, layer); FramebufferAttachment *newAttachment = new FramebufferAttachment(mRenderer, depthbuffer, attachmentImpl);
mDepthbuffer.set(newAttachment, type, level, layer);
} }
else else
{ {
...@@ -146,10 +157,11 @@ void Framebuffer::setDepthbuffer(GLenum type, GLuint depthbuffer, GLint level, G ...@@ -146,10 +157,11 @@ void Framebuffer::setDepthbuffer(GLenum type, GLuint depthbuffer, GLint level, G
void Framebuffer::setStencilbuffer(GLenum type, GLuint stencilbuffer, GLint level, GLint layer) void Framebuffer::setStencilbuffer(GLenum type, GLuint stencilbuffer, GLint level, GLint layer)
{ {
FramebufferAttachment *attachment = lookupAttachment(type, stencilbuffer, level, layer); FramebufferAttachmentImpl *attachmentImpl = createAttachmentImpl(type, stencilbuffer, level, layer);
if (attachment) if (attachmentImpl)
{ {
mStencilbuffer.set(attachment, type, level, layer); FramebufferAttachment *newAttachment = new FramebufferAttachment(mRenderer, stencilbuffer, attachmentImpl);
mStencilbuffer.set(newAttachment, type, level, layer);
} }
else else
{ {
...@@ -159,16 +171,18 @@ void Framebuffer::setStencilbuffer(GLenum type, GLuint stencilbuffer, GLint leve ...@@ -159,16 +171,18 @@ void Framebuffer::setStencilbuffer(GLenum type, GLuint stencilbuffer, GLint leve
void Framebuffer::setDepthStencilBuffer(GLenum type, GLuint depthStencilBuffer, GLint level, GLint layer) void Framebuffer::setDepthStencilBuffer(GLenum type, GLuint depthStencilBuffer, GLint level, GLint layer)
{ {
FramebufferAttachment *attachment = lookupAttachment(type, depthStencilBuffer, level, layer); mDepthbuffer.set(NULL, GL_NONE, 0, 0);
if (attachment && attachment->getDepthSize() > 0 && attachment->getStencilSize() > 0) mStencilbuffer.set(NULL, GL_NONE, 0, 0);
{
mDepthbuffer.set(attachment, type, level, layer); FramebufferAttachmentImpl *attachmentImpl = createAttachmentImpl(type, depthStencilBuffer, level, layer);
mStencilbuffer.set(attachment, type, level, layer); if (attachmentImpl)
}
else
{ {
mDepthbuffer.set(NULL, GL_NONE, 0, 0); FramebufferAttachment *newAttachment = new FramebufferAttachment(mRenderer, depthStencilBuffer, attachmentImpl);
mStencilbuffer.set(NULL, GL_NONE, 0, 0); if (newAttachment->getDepthSize() > 0 && newAttachment->getStencilSize() > 0)
{
mDepthbuffer.set(newAttachment, type, level, layer);
mStencilbuffer.set(newAttachment, type, level, layer);
}
} }
} }
...@@ -683,7 +697,9 @@ GLenum Framebuffer::completeness() const ...@@ -683,7 +697,9 @@ GLenum Framebuffer::completeness() const
// if we have both a depth and stencil buffer, they must refer to the same object // if we have both a depth and stencil buffer, they must refer to the same object
// since we only support packed_depth_stencil and not separate depth and stencil // since we only support packed_depth_stencil and not separate depth and stencil
if (depthbuffer && stencilbuffer && (depthbuffer != stencilbuffer)) if (depthbuffer && stencilbuffer &&
!(depthbuffer->id() == stencilbuffer->id() &&
depthbuffer->isTexture() == stencilbuffer->isTexture()))
{ {
return GL_FRAMEBUFFER_UNSUPPORTED; return GL_FRAMEBUFFER_UNSUPPORTED;
} }
...@@ -700,11 +716,14 @@ GLenum Framebuffer::completeness() const ...@@ -700,11 +716,14 @@ GLenum Framebuffer::completeness() const
DefaultFramebuffer::DefaultFramebuffer(rx::Renderer *renderer, Colorbuffer *colorbuffer, DepthStencilbuffer *depthStencil) DefaultFramebuffer::DefaultFramebuffer(rx::Renderer *renderer, Colorbuffer *colorbuffer, DepthStencilbuffer *depthStencil)
: Framebuffer(renderer) : Framebuffer(renderer)
{ {
mColorbuffers[0].set(new FramebufferAttachment(mRenderer, 0, colorbuffer), GL_RENDERBUFFER, 0, 0); Renderbuffer *colorRenderbuffer = new Renderbuffer(mRenderer, 0, colorbuffer);
FramebufferAttachment *colorAttachment = new FramebufferAttachment(mRenderer, 0, new RenderbufferAttachment(colorRenderbuffer));
mColorbuffers[0].set(colorAttachment, GL_RENDERBUFFER, 0, 0);
FramebufferAttachment *depthStencilRenderbuffer = new FramebufferAttachment(mRenderer, 0, depthStencil); Renderbuffer *depthStencilRenderbuffer = new Renderbuffer(mRenderer, 0, depthStencil);
mDepthbuffer.set(depthStencilRenderbuffer, (depthStencilRenderbuffer->getDepthSize() != 0) ? GL_RENDERBUFFER : GL_NONE, 0, 0); FramebufferAttachment *depthStencilAttachment = new FramebufferAttachment(mRenderer, 0, new RenderbufferAttachment(depthStencilRenderbuffer));
mStencilbuffer.set(depthStencilRenderbuffer, (depthStencilRenderbuffer->getStencilSize() != 0) ? GL_RENDERBUFFER : GL_NONE, 0, 0); mDepthbuffer.set(depthStencilAttachment, (depthStencilRenderbuffer->getDepthSize() != 0) ? GL_RENDERBUFFER : GL_NONE, 0, 0);
mStencilbuffer.set(depthStencilAttachment, (depthStencilRenderbuffer->getStencilSize() != 0) ? GL_RENDERBUFFER : GL_NONE, 0, 0);
mDrawBufferStates[0] = GL_BACK; mDrawBufferStates[0] = GL_BACK;
mReadBufferState = GL_BACK; mReadBufferState = GL_BACK;
......
...@@ -22,6 +22,7 @@ class Renderer; ...@@ -22,6 +22,7 @@ class Renderer;
namespace gl namespace gl
{ {
class FramebufferAttachment; class FramebufferAttachment;
class FramebufferAttachmentImpl;
class Colorbuffer; class Colorbuffer;
class Depthbuffer; class Depthbuffer;
class Stencilbuffer; class Stencilbuffer;
...@@ -99,7 +100,7 @@ class Framebuffer ...@@ -99,7 +100,7 @@ class Framebuffer
private: private:
DISALLOW_COPY_AND_ASSIGN(Framebuffer); DISALLOW_COPY_AND_ASSIGN(Framebuffer);
FramebufferAttachment *lookupAttachment(GLenum type, GLuint handle, GLint level, GLint layer) const; FramebufferAttachmentImpl *createAttachmentImpl(GLenum type, GLuint handle, GLint level, GLint layer) const;
}; };
class DefaultFramebuffer : public Framebuffer class DefaultFramebuffer : public Framebuffer
......
...@@ -21,18 +21,18 @@ ...@@ -21,18 +21,18 @@
namespace gl namespace gl
{ {
FramebufferAttachmentInterface::FramebufferAttachmentInterface() FramebufferAttachmentImpl::FramebufferAttachmentImpl()
{ {
} }
// The default case for classes inherited from FramebufferAttachmentInterface is not to // The default case for classes inherited from FramebufferAttachmentImpl is not to
// need to do anything upon the reference count to the parent FramebufferAttachment incrementing // need to do anything upon the reference count to the parent FramebufferAttachment incrementing
// or decrementing. // or decrementing.
void FramebufferAttachmentInterface::addProxyRef(const FramebufferAttachment *proxy) void FramebufferAttachmentImpl::addProxyRef(const FramebufferAttachment *proxy)
{ {
} }
void FramebufferAttachmentInterface::releaseProxy(const FramebufferAttachment *proxy) void FramebufferAttachmentImpl::releaseProxy(const FramebufferAttachment *proxy)
{ {
} }
...@@ -355,69 +355,69 @@ unsigned int Texture2DArrayAttachment::getTextureSerial() const ...@@ -355,69 +355,69 @@ unsigned int Texture2DArrayAttachment::getTextureSerial() const
////// FramebufferAttachment Implementation ////// ////// FramebufferAttachment Implementation //////
FramebufferAttachment::FramebufferAttachment(rx::Renderer *renderer, GLuint id, FramebufferAttachmentInterface *instance) : RefCountObject(id) FramebufferAttachment::FramebufferAttachment(rx::Renderer *renderer, GLuint id, FramebufferAttachmentImpl *instance)
: RefCountObject(id),
mRenderer(renderer),
mImpl(instance)
{ {
ASSERT(instance != NULL); ASSERT(mRenderer != NULL);
mInstance = instance; ASSERT(mImpl != NULL);
ASSERT(renderer != NULL);
mRenderer = renderer;
} }
FramebufferAttachment::~FramebufferAttachment() FramebufferAttachment::~FramebufferAttachment()
{ {
delete mInstance; SafeDelete(mImpl);
} }
// The FramebufferAttachmentInterface contained in this FramebufferAttachment may need to maintain // The FramebufferAttachmentImpl contained in this FramebufferAttachment may need to maintain
// its own reference count, so we pass it on here. // its own reference count, so we pass it on here.
void FramebufferAttachment::addRef() const void FramebufferAttachment::addRef() const
{ {
mInstance->addProxyRef(this); mImpl->addProxyRef(this);
RefCountObject::addRef(); RefCountObject::addRef();
} }
void FramebufferAttachment::release() const void FramebufferAttachment::release() const
{ {
mInstance->releaseProxy(this); mImpl->releaseProxy(this);
RefCountObject::release(); RefCountObject::release();
} }
rx::RenderTarget *FramebufferAttachment::getRenderTarget() rx::RenderTarget *FramebufferAttachment::getRenderTarget()
{ {
return mInstance->getRenderTarget(); return mImpl->getRenderTarget();
} }
rx::RenderTarget *FramebufferAttachment::getDepthStencil() rx::RenderTarget *FramebufferAttachment::getDepthStencil()
{ {
return mInstance->getDepthStencil(); return mImpl->getDepthStencil();
} }
rx::TextureStorage *FramebufferAttachment::getTextureStorage() rx::TextureStorage *FramebufferAttachment::getTextureStorage()
{ {
return mInstance->getTextureStorage(); return mImpl->getTextureStorage();
} }
GLsizei FramebufferAttachment::getWidth() const GLsizei FramebufferAttachment::getWidth() const
{ {
return mInstance->getWidth(); return mImpl->getWidth();
} }
GLsizei FramebufferAttachment::getHeight() const GLsizei FramebufferAttachment::getHeight() const
{ {
return mInstance->getHeight(); return mImpl->getHeight();
} }
GLenum FramebufferAttachment::getInternalFormat() const GLenum FramebufferAttachment::getInternalFormat() const
{ {
return mInstance->getInternalFormat(); return mImpl->getInternalFormat();
} }
GLenum FramebufferAttachment::getActualFormat() const GLenum FramebufferAttachment::getActualFormat() const
{ {
return mInstance->getActualFormat(); return mImpl->getActualFormat();
} }
GLuint FramebufferAttachment::getRedSize() const GLuint FramebufferAttachment::getRedSize() const
...@@ -504,30 +504,98 @@ GLenum FramebufferAttachment::getColorEncoding() const ...@@ -504,30 +504,98 @@ GLenum FramebufferAttachment::getColorEncoding() const
GLsizei FramebufferAttachment::getSamples() const GLsizei FramebufferAttachment::getSamples() const
{ {
return mInstance->getSamples(); return mImpl->getSamples();
} }
unsigned int FramebufferAttachment::getSerial() const unsigned int FramebufferAttachment::getSerial() const
{ {
return mInstance->getSerial(); return mImpl->getSerial();
} }
bool FramebufferAttachment::isTexture() const bool FramebufferAttachment::isTexture() const
{ {
return mInstance->isTexture(); return mImpl->isTexture();
} }
unsigned int FramebufferAttachment::getTextureSerial() const unsigned int FramebufferAttachment::getTextureSerial() const
{ {
return mInstance->getTextureSerial(); return mImpl->getTextureSerial();
}
void FramebufferAttachment::setImplementation(FramebufferAttachmentImpl *newImpl)
{
ASSERT(newImpl != NULL);
delete mImpl;
mImpl = newImpl;
}
RenderbufferAttachment::RenderbufferAttachment(Renderbuffer *renderbuffer)
{
ASSERT(renderbuffer);
mRenderbuffer.set(renderbuffer);
}
RenderbufferAttachment::~RenderbufferAttachment()
{
mRenderbuffer.set(NULL);
} }
void FramebufferAttachment::setStorage(RenderbufferStorage *newStorage) rx::RenderTarget *RenderbufferAttachment::getRenderTarget()
{ {
ASSERT(newStorage != NULL); return mRenderbuffer->getStorage()->getRenderTarget();
}
rx::RenderTarget *RenderbufferAttachment::getDepthStencil()
{
return mRenderbuffer->getStorage()->getDepthStencil();
}
rx::TextureStorage *RenderbufferAttachment::getTextureStorage()
{
UNREACHABLE();
return NULL;
}
GLsizei RenderbufferAttachment::getWidth() const
{
return mRenderbuffer->getWidth();
}
delete mInstance; GLsizei RenderbufferAttachment::getHeight() const
mInstance = newStorage; {
return mRenderbuffer->getHeight();
}
GLenum RenderbufferAttachment::getInternalFormat() const
{
return mRenderbuffer->getInternalFormat();
}
GLenum RenderbufferAttachment::getActualFormat() const
{
return mRenderbuffer->getActualFormat();
}
GLsizei RenderbufferAttachment::getSamples() const
{
return mRenderbuffer->getStorage()->getSamples();
}
unsigned int RenderbufferAttachment::getSerial() const
{
return mRenderbuffer->getStorage()->getSerial();
}
bool RenderbufferAttachment::isTexture() const
{
return false;
}
unsigned int RenderbufferAttachment::getTextureSerial() const
{
UNREACHABLE();
return 0;
} }
} }
...@@ -29,24 +29,27 @@ class Texture2D; ...@@ -29,24 +29,27 @@ class Texture2D;
class TextureCubeMap; class TextureCubeMap;
class Texture3D; class Texture3D;
class Texture2DArray; class Texture2DArray;
class FramebufferAttachment; class FramebufferAttachmentImpl;
class FramebufferAttachmentInterface; class Renderbuffer;
class RenderbufferStorage;
// FramebufferAttachment implements a GL framebuffer attachment.
// Attachments are "light" containers, which store pointers to ref-counted GL objects.
// We support GL texture (2D/3D/Cube/2D array) and renderbuffer object attachments.
// Note: Renderbuffers are specialized storage for depth and stencil buffes. Our old
// naming scheme used the term "Renderbuffer" for both GL renderbuffers and for
// framebuffer attachments, which confused their usage.
// FramebufferAttachment implements the GL renderbuffer object.
// It's only a proxy for a FramebufferAttachmentInterface instance; the internal object
// can change whenever glRenderbufferStorage is called.
class FramebufferAttachment : public RefCountObject class FramebufferAttachment : public RefCountObject
{ {
public: public:
FramebufferAttachment(rx::Renderer *renderer, GLuint id, FramebufferAttachmentInterface *storage); FramebufferAttachment(rx::Renderer *renderer, GLuint id, FramebufferAttachmentImpl *storage);
virtual ~FramebufferAttachment(); virtual ~FramebufferAttachment();
// These functions from RefCountObject are overloaded here because // These functions from RefCountObject are overloaded here because
// Textures need to maintain their own count of references to them via // Textures need to maintain their own count of references to them via
// Renderbuffers/RenderbufferTextures. These functions invoke those // Renderbuffers/RenderbufferTextures. These functions invoke those
// reference counting functions on the FramebufferAttachmentInterface. // reference counting functions on the FramebufferAttachmentImpl.
void addRef() const; void addRef() const;
void release() const; void release() const;
...@@ -73,21 +76,21 @@ class FramebufferAttachment : public RefCountObject ...@@ -73,21 +76,21 @@ class FramebufferAttachment : public RefCountObject
bool isTexture() const; bool isTexture() const;
unsigned int getTextureSerial() const; unsigned int getTextureSerial() const;
void setStorage(RenderbufferStorage *newStorage); void setImplementation(FramebufferAttachmentImpl *newImpl);
private: private:
DISALLOW_COPY_AND_ASSIGN(FramebufferAttachment); DISALLOW_COPY_AND_ASSIGN(FramebufferAttachment);
rx::Renderer const *mRenderer; rx::Renderer const *mRenderer;
FramebufferAttachmentInterface *mInstance; FramebufferAttachmentImpl *mImpl;
}; };
class FramebufferAttachmentInterface class FramebufferAttachmentImpl
{ {
public: public:
FramebufferAttachmentInterface(); FramebufferAttachmentImpl();
virtual ~FramebufferAttachmentInterface() {}; virtual ~FramebufferAttachmentImpl() {};
virtual void addProxyRef(const FramebufferAttachment *proxy); virtual void addProxyRef(const FramebufferAttachment *proxy);
virtual void releaseProxy(const FramebufferAttachment *proxy); virtual void releaseProxy(const FramebufferAttachment *proxy);
...@@ -108,10 +111,10 @@ class FramebufferAttachmentInterface ...@@ -108,10 +111,10 @@ class FramebufferAttachmentInterface
virtual unsigned int getTextureSerial() const = 0; virtual unsigned int getTextureSerial() const = 0;
private: private:
DISALLOW_COPY_AND_ASSIGN(FramebufferAttachmentInterface); DISALLOW_COPY_AND_ASSIGN(FramebufferAttachmentImpl);
}; };
class Texture2DAttachment : public FramebufferAttachmentInterface class Texture2DAttachment : public FramebufferAttachmentImpl
{ {
public: public:
Texture2DAttachment(Texture2D *texture, GLint level); Texture2DAttachment(Texture2D *texture, GLint level);
...@@ -143,7 +146,7 @@ class Texture2DAttachment : public FramebufferAttachmentInterface ...@@ -143,7 +146,7 @@ class Texture2DAttachment : public FramebufferAttachmentInterface
const GLint mLevel; const GLint mLevel;
}; };
class TextureCubeMapAttachment : public FramebufferAttachmentInterface class TextureCubeMapAttachment : public FramebufferAttachmentImpl
{ {
public: public:
TextureCubeMapAttachment(TextureCubeMap *texture, GLenum faceTarget, GLint level); TextureCubeMapAttachment(TextureCubeMap *texture, GLenum faceTarget, GLint level);
...@@ -176,7 +179,7 @@ class TextureCubeMapAttachment : public FramebufferAttachmentInterface ...@@ -176,7 +179,7 @@ class TextureCubeMapAttachment : public FramebufferAttachmentInterface
const GLenum mFaceTarget; const GLenum mFaceTarget;
}; };
class Texture3DAttachment : public FramebufferAttachmentInterface class Texture3DAttachment : public FramebufferAttachmentImpl
{ {
public: public:
Texture3DAttachment(Texture3D *texture, GLint level, GLint layer); Texture3DAttachment(Texture3D *texture, GLint level, GLint layer);
...@@ -209,7 +212,7 @@ class Texture3DAttachment : public FramebufferAttachmentInterface ...@@ -209,7 +212,7 @@ class Texture3DAttachment : public FramebufferAttachmentInterface
const GLint mLayer; const GLint mLayer;
}; };
class Texture2DArrayAttachment : public FramebufferAttachmentInterface class Texture2DArrayAttachment : public FramebufferAttachmentImpl
{ {
public: public:
Texture2DArrayAttachment(Texture2DArray *texture, GLint level, GLint layer); Texture2DArrayAttachment(Texture2DArray *texture, GLint level, GLint layer);
...@@ -242,6 +245,34 @@ class Texture2DArrayAttachment : public FramebufferAttachmentInterface ...@@ -242,6 +245,34 @@ class Texture2DArrayAttachment : public FramebufferAttachmentInterface
const GLint mLayer; const GLint mLayer;
}; };
class RenderbufferAttachment : public FramebufferAttachmentImpl
{
public:
RenderbufferAttachment(Renderbuffer *renderbuffer);
virtual ~RenderbufferAttachment();
rx::RenderTarget *getRenderTarget();
rx::RenderTarget *getDepthStencil();
rx::TextureStorage *getTextureStorage();
virtual GLsizei getWidth() const;
virtual GLsizei getHeight() const;
virtual GLenum getInternalFormat() const;
virtual GLenum getActualFormat() const;
virtual GLsizei getSamples() const;
virtual unsigned int getSerial() const;
virtual bool isTexture() const;
virtual unsigned int getTextureSerial() const;
private:
DISALLOW_COPY_AND_ASSIGN(RenderbufferAttachment);
BindingPointer<Renderbuffer> mRenderbuffer;
};
} }
#endif // LIBGLESV2_FRAMEBUFFERATTACHMENT_H_ #endif // LIBGLESV2_FRAMEBUFFERATTACHMENT_H_
...@@ -22,6 +22,88 @@ namespace gl ...@@ -22,6 +22,88 @@ namespace gl
{ {
unsigned int RenderbufferStorage::mCurrentSerial = 1; unsigned int RenderbufferStorage::mCurrentSerial = 1;
Renderbuffer::Renderbuffer(rx::Renderer *renderer, GLuint id, RenderbufferStorage *newStorage)
: RefCountObject(id),
mRenderer(renderer),
mStorage(newStorage)
{
ASSERT(mStorage);
}
void Renderbuffer::setStorage(RenderbufferStorage *newStorage)
{
ASSERT(newStorage);
SafeDelete(mStorage);
mStorage = newStorage;
}
RenderbufferStorage *Renderbuffer::getStorage()
{
ASSERT(mStorage);
return mStorage;
}
GLsizei Renderbuffer::getWidth() const
{
ASSERT(mStorage);
return mStorage->getWidth();
}
GLsizei Renderbuffer::getHeight() const
{
ASSERT(mStorage);
return mStorage->getHeight();
}
GLenum Renderbuffer::getInternalFormat() const
{
ASSERT(mStorage);
return mStorage->getInternalFormat();
}
GLenum Renderbuffer::getActualFormat() const
{
ASSERT(mStorage);
return mStorage->getActualFormat();
}
GLsizei Renderbuffer::getSamples() const
{
ASSERT(mStorage);
return mStorage->getSamples();
}
GLuint Renderbuffer::getRedSize() const
{
return gl::GetRedBits(getActualFormat(), mRenderer->getCurrentClientVersion());
}
GLuint Renderbuffer::getGreenSize() const
{
return gl::GetGreenBits(getActualFormat(), mRenderer->getCurrentClientVersion());
}
GLuint Renderbuffer::getBlueSize() const
{
return gl::GetBlueBits(getActualFormat(), mRenderer->getCurrentClientVersion());
}
GLuint Renderbuffer::getAlphaSize() const
{
return gl::GetAlphaBits(getActualFormat(), mRenderer->getCurrentClientVersion());
}
GLuint Renderbuffer::getDepthSize() const
{
return gl::GetDepthBits(getActualFormat(), mRenderer->getCurrentClientVersion());
}
GLuint Renderbuffer::getStencilSize() const
{
return gl::GetStencilBits(getActualFormat(), mRenderer->getCurrentClientVersion());
}
RenderbufferStorage::RenderbufferStorage() : mSerial(issueSerials(1)) RenderbufferStorage::RenderbufferStorage() : mSerial(issueSerials(1))
{ {
mWidth = 0; mWidth = 0;
......
...@@ -29,11 +29,42 @@ class TextureStorage; ...@@ -29,11 +29,42 @@ class TextureStorage;
namespace gl namespace gl
{ {
class RenderbufferStorage;
// 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
{
public:
Renderbuffer(rx::Renderer *renderer, GLuint id, RenderbufferStorage *newStorage);
void setStorage(RenderbufferStorage *newStorage);
RenderbufferStorage *getStorage();
GLsizei getWidth() const;
GLsizei getHeight() const;
GLenum getInternalFormat() const;
GLenum getActualFormat() const;
GLsizei getSamples() const;
GLuint getRedSize() const;
GLuint getGreenSize() const;
GLuint getBlueSize() const;
GLuint getAlphaSize() const;
GLuint getDepthSize() const;
GLuint getStencilSize() const;
private:
rx::Renderer *mRenderer;
RenderbufferStorage *mStorage;
};
// A class derived from RenderbufferStorage is created whenever glRenderbufferStorage // A class derived from RenderbufferStorage is created whenever glRenderbufferStorage
// is called. The specific concrete type depends on whether the internal format is // is called. The specific concrete type depends on whether the internal format is
// colour depth, stencil or packed depth/stencil. // colour depth, stencil or packed depth/stencil.
class RenderbufferStorage : public FramebufferAttachmentInterface class RenderbufferStorage
{ {
public: public:
RenderbufferStorage(); RenderbufferStorage();
...@@ -126,6 +157,7 @@ class Stencilbuffer : public DepthStencilbuffer ...@@ -126,6 +157,7 @@ class Stencilbuffer : public DepthStencilbuffer
private: private:
DISALLOW_COPY_AND_ASSIGN(Stencilbuffer); DISALLOW_COPY_AND_ASSIGN(Stencilbuffer);
}; };
} }
#endif // LIBGLESV2_RENDERBUFFER_H_ #endif // LIBGLESV2_RENDERBUFFER_H_
...@@ -311,7 +311,7 @@ Program *ResourceManager::getProgram(unsigned int handle) ...@@ -311,7 +311,7 @@ Program *ResourceManager::getProgram(unsigned int handle)
} }
} }
FramebufferAttachment *ResourceManager::getRenderbuffer(unsigned int handle) Renderbuffer *ResourceManager::getRenderbuffer(unsigned int handle)
{ {
RenderbufferMap::iterator renderbuffer = mRenderbufferMap.find(handle); RenderbufferMap::iterator renderbuffer = mRenderbufferMap.find(handle);
...@@ -353,7 +353,7 @@ FenceSync *ResourceManager::getFenceSync(unsigned int handle) ...@@ -353,7 +353,7 @@ FenceSync *ResourceManager::getFenceSync(unsigned int handle)
} }
} }
void ResourceManager::setRenderbuffer(GLuint handle, FramebufferAttachment *buffer) void ResourceManager::setRenderbuffer(GLuint handle, Renderbuffer *buffer)
{ {
mRenderbufferMap[handle] = buffer; mRenderbufferMap[handle] = buffer;
} }
...@@ -405,7 +405,7 @@ void ResourceManager::checkRenderbufferAllocation(GLuint renderbuffer) ...@@ -405,7 +405,7 @@ void ResourceManager::checkRenderbufferAllocation(GLuint renderbuffer)
{ {
if (renderbuffer != 0 && !getRenderbuffer(renderbuffer)) if (renderbuffer != 0 && !getRenderbuffer(renderbuffer))
{ {
FramebufferAttachment *renderbufferObject = new FramebufferAttachment(mRenderer, renderbuffer, new Colorbuffer(mRenderer, 0, 0, GL_RGBA4, 0)); Renderbuffer *renderbufferObject = new Renderbuffer(mRenderer, renderbuffer, new Colorbuffer(mRenderer, 0, 0, GL_RGBA4, 0));
mRenderbufferMap[renderbuffer] = renderbufferObject; mRenderbufferMap[renderbuffer] = renderbufferObject;
renderbufferObject->addRef(); renderbufferObject->addRef();
} }
......
...@@ -30,7 +30,7 @@ class Buffer; ...@@ -30,7 +30,7 @@ class Buffer;
class Shader; class Shader;
class Program; class Program;
class Texture; class Texture;
class FramebufferAttachment; class Renderbuffer;
class Sampler; class Sampler;
class FenceSync; class FenceSync;
...@@ -63,11 +63,11 @@ class ResourceManager ...@@ -63,11 +63,11 @@ class ResourceManager
Shader *getShader(GLuint handle); Shader *getShader(GLuint handle);
Program *getProgram(GLuint handle); Program *getProgram(GLuint handle);
Texture *getTexture(GLuint handle); Texture *getTexture(GLuint handle);
FramebufferAttachment *getRenderbuffer(GLuint handle); Renderbuffer *getRenderbuffer(GLuint handle);
Sampler *getSampler(GLuint handle); Sampler *getSampler(GLuint handle);
FenceSync *getFenceSync(GLuint handle); FenceSync *getFenceSync(GLuint handle);
void setRenderbuffer(GLuint handle, FramebufferAttachment *renderbuffer); void setRenderbuffer(GLuint handle, Renderbuffer *renderbuffer);
void checkBufferAllocation(unsigned int buffer); void checkBufferAllocation(unsigned int buffer);
void checkTextureAllocation(GLuint texture, TextureType type); void checkTextureAllocation(GLuint texture, TextureType type);
...@@ -97,7 +97,7 @@ class ResourceManager ...@@ -97,7 +97,7 @@ class ResourceManager
TextureMap mTextureMap; TextureMap mTextureMap;
HandleAllocator mTextureHandleAllocator; HandleAllocator mTextureHandleAllocator;
typedef std::unordered_map<GLuint, FramebufferAttachment*> RenderbufferMap; typedef std::unordered_map<GLuint, Renderbuffer*> RenderbufferMap;
RenderbufferMap mRenderbufferMap; RenderbufferMap mRenderbufferMap;
HandleAllocator mRenderbufferHandleAllocator; HandleAllocator mRenderbufferHandleAllocator;
......
...@@ -3092,25 +3092,25 @@ void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* ...@@ -3092,25 +3092,25 @@ void __stdcall glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint*
return gl::error(GL_INVALID_OPERATION); return gl::error(GL_INVALID_OPERATION);
} }
gl::FramebufferAttachment *attachment = context->getRenderbuffer(context->getRenderbufferHandle()); gl::Renderbuffer *renderbuffer = context->getRenderbuffer(context->getRenderbufferHandle());
switch (pname) switch (pname)
{ {
case GL_RENDERBUFFER_WIDTH: *params = attachment->getWidth(); break; case GL_RENDERBUFFER_WIDTH: *params = renderbuffer->getWidth(); break;
case GL_RENDERBUFFER_HEIGHT: *params = attachment->getHeight(); break; case GL_RENDERBUFFER_HEIGHT: *params = renderbuffer->getHeight(); break;
case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = attachment->getInternalFormat(); break; case GL_RENDERBUFFER_INTERNAL_FORMAT: *params = renderbuffer->getInternalFormat(); break;
case GL_RENDERBUFFER_RED_SIZE: *params = attachment->getRedSize(); break; case GL_RENDERBUFFER_RED_SIZE: *params = renderbuffer->getRedSize(); break;
case GL_RENDERBUFFER_GREEN_SIZE: *params = attachment->getGreenSize(); break; case GL_RENDERBUFFER_GREEN_SIZE: *params = renderbuffer->getGreenSize(); break;
case GL_RENDERBUFFER_BLUE_SIZE: *params = attachment->getBlueSize(); break; case GL_RENDERBUFFER_BLUE_SIZE: *params = renderbuffer->getBlueSize(); break;
case GL_RENDERBUFFER_ALPHA_SIZE: *params = attachment->getAlphaSize(); break; case GL_RENDERBUFFER_ALPHA_SIZE: *params = renderbuffer->getAlphaSize(); break;
case GL_RENDERBUFFER_DEPTH_SIZE: *params = attachment->getDepthSize(); break; case GL_RENDERBUFFER_DEPTH_SIZE: *params = renderbuffer->getDepthSize(); break;
case GL_RENDERBUFFER_STENCIL_SIZE: *params = attachment->getStencilSize(); break; case GL_RENDERBUFFER_STENCIL_SIZE: *params = renderbuffer->getStencilSize(); break;
case GL_RENDERBUFFER_SAMPLES_ANGLE: case GL_RENDERBUFFER_SAMPLES_ANGLE:
if (!context->getCaps().extensions.framebufferMultisample) if (!context->getCaps().extensions.framebufferMultisample)
{ {
return gl::error(GL_INVALID_ENUM); return gl::error(GL_INVALID_ENUM);
} }
*params = attachment->getSamples(); *params = renderbuffer->getSamples();
break; break;
default: default:
return gl::error(GL_INVALID_ENUM); return gl::error(GL_INVALID_ENUM);
...@@ -4138,7 +4138,7 @@ GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer) ...@@ -4138,7 +4138,7 @@ GLboolean __stdcall glIsRenderbuffer(GLuint renderbuffer)
if (context && renderbuffer) if (context && renderbuffer)
{ {
gl::FramebufferAttachment *renderbufferObject = context->getRenderbuffer(renderbuffer); gl::Renderbuffer *renderbufferObject = context->getRenderbuffer(renderbuffer);
if (renderbufferObject) if (renderbufferObject)
{ {
......
...@@ -1121,7 +1121,8 @@ gl::FramebufferAttachment *Renderer9::getNullColorbuffer(gl::FramebufferAttachme ...@@ -1121,7 +1121,8 @@ gl::FramebufferAttachment *Renderer9::getNullColorbuffer(gl::FramebufferAttachme
} }
} }
gl::FramebufferAttachment *nullbuffer = new gl::FramebufferAttachment(this, 0, new gl::Colorbuffer(this, width, height, GL_NONE, 0)); gl::Renderbuffer *nullRenderbuffer = new gl::Renderbuffer(this, 0, new gl::Colorbuffer(this, width, height, GL_NONE, 0));
gl::FramebufferAttachment *nullbuffer = new gl::FramebufferAttachment(this, 0, new gl::RenderbufferAttachment(nullRenderbuffer));
// add nullbuffer to the cache // add nullbuffer to the cache
NullColorbufferCacheEntry *oldest = &mNullColorbufferCache[0]; NullColorbufferCacheEntry *oldest = &mNullColorbufferCache[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