Make the default framebuffer owned by Surface
Reland with a fix for SurfaceTest in angle_unittests and fixes for
signed-unsigned warnings
In CGL there is no notion of default Framebuffer and MakeCurrent only
makes a context current but not a drawable. Instead, everything is done
via render to texture. For that reason, different surfaces will have
different FBOs as default framebuffers, which causes that change.
BUG=angleproject:891
Change-Id: I0664896bc335b1a757226aaa212536b8f9d0f08f
Reviewed-on: https://chromium-review.googlesource.com/293752
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Tested-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/libANGLE/Framebuffer.cpp b/src/libANGLE/Framebuffer.cpp
index 0880984..afc1630 100644
--- a/src/libANGLE/Framebuffer.cpp
+++ b/src/libANGLE/Framebuffer.cpp
@@ -20,6 +20,7 @@
#include "libANGLE/renderer/FramebufferImpl.h"
#include "libANGLE/renderer/ImplFactory.h"
#include "libANGLE/renderer/RenderbufferImpl.h"
+#include "libANGLE/renderer/SurfaceImpl.h"
namespace gl
{
@@ -37,6 +38,14 @@
}
}
+Framebuffer::Data::Data()
+ : mColorAttachments(1),
+ mDrawBufferStates(1, GL_NONE),
+ mReadBufferState(GL_COLOR_ATTACHMENT0_EXT)
+{
+ mDrawBufferStates[0] = GL_COLOR_ATTACHMENT0_EXT;
+}
+
Framebuffer::Data::Data(const Caps &caps)
: mColorAttachments(caps.maxColorAttachments),
mDrawBufferStates(caps.maxDrawBuffers, GL_NONE),
@@ -83,7 +92,7 @@
return nullptr;
}
-const FramebufferAttachment *Framebuffer::Data::getColorAttachment(unsigned int colorAttachment) const
+const FramebufferAttachment *Framebuffer::Data::getColorAttachment(size_t colorAttachment) const
{
ASSERT(colorAttachment < mColorAttachments.size());
return mColorAttachments[colorAttachment].isAttached() ?
@@ -116,18 +125,15 @@
}
Framebuffer::Framebuffer(const Caps &caps, rx::ImplFactory *factory, GLuint id)
- : mData(caps),
- mImpl(nullptr),
- mId(id)
+ : mData(caps), mImpl(factory->createFramebuffer(mData)), mId(id)
{
- if (mId == 0)
- {
- mImpl = factory->createDefaultFramebuffer(mData);
- }
- else
- {
- mImpl = factory->createFramebuffer(mData);
- }
+ ASSERT(mId != 0);
+ ASSERT(mImpl != nullptr);
+}
+
+Framebuffer::Framebuffer(rx::SurfaceImpl *surface)
+ : mData(), mImpl(surface->createDefaultFramebuffer(mData)), mId(0)
+{
ASSERT(mImpl != nullptr);
}
@@ -157,7 +163,7 @@
DetachMatchingAttachment(&mData.mStencilAttachment, resourceType, resourceId);
}
-const FramebufferAttachment *Framebuffer::getColorbuffer(unsigned int colorAttachment) const
+const FramebufferAttachment *Framebuffer::getColorbuffer(size_t colorAttachment) const
{
return mData.getColorAttachment(colorAttachment);
}
@@ -257,7 +263,7 @@
mImpl->setReadBuffer(buffer);
}
-bool Framebuffer::isEnabledColorAttachment(unsigned int colorAttachment) const
+bool Framebuffer::isEnabledColorAttachment(size_t colorAttachment) const
{
ASSERT(colorAttachment < mData.mColorAttachments.size());
return (mData.mColorAttachments[colorAttachment].isAttached() &&
@@ -277,6 +283,11 @@
return false;
}
+size_t Framebuffer::getNumColorBuffers() const
+{
+ return mData.mColorAttachments.size();
+}
+
bool Framebuffer::hasStencil() const
{
return (mData.mStencilAttachment.isAttached() && mData.mStencilAttachment.getStencilSize() > 0);