Commit 9240dac6 by Nicolas Capens

Use the framebuffer object's stencil attachment.

Bug 27460431 Change-Id: Ic030624cc34b31519882e54497457a1b92eaac45 Reviewed-on: https://swiftshader-review.googlesource.com/4981Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent c39901ec
...@@ -1724,10 +1724,13 @@ bool Context::applyRenderTarget() ...@@ -1724,10 +1724,13 @@ bool Context::applyRenderTarget()
device->setRenderTarget(0, renderTarget); device->setRenderTarget(0, renderTarget);
if(renderTarget) renderTarget->release(); if(renderTarget) renderTarget->release();
egl::Image *depthStencil = framebuffer->getDepthStencil(); egl::Image *depthBuffer = framebuffer->getDepthBuffer();
device->setDepthBuffer(depthStencil); device->setDepthBuffer(depthBuffer);
device->setStencilBuffer(depthStencil); if(depthBuffer) depthBuffer->release();
if(depthStencil) depthStencil->release();
egl::Image *stencilBuffer = framebuffer->getStencilBuffer();
device->setStencilBuffer(stencilBuffer);
if(stencilBuffer) stencilBuffer->release();
Viewport viewport; Viewport viewport;
float zNear = clamp01(mState.zNear); float zNear = clamp01(mState.zNear);
......
...@@ -31,19 +31,19 @@ Framebuffer::Framebuffer() ...@@ -31,19 +31,19 @@ Framebuffer::Framebuffer()
Framebuffer::~Framebuffer() Framebuffer::~Framebuffer()
{ {
mColorbufferPointer = NULL; mColorbufferPointer = nullptr;
mDepthbufferPointer = NULL; mDepthbufferPointer = nullptr;
mStencilbufferPointer = NULL; mStencilbufferPointer = nullptr;
} }
Renderbuffer *Framebuffer::lookupRenderbuffer(GLenum type, GLuint handle) const Renderbuffer *Framebuffer::lookupRenderbuffer(GLenum type, GLuint handle) const
{ {
Context *context = getContext(); Context *context = getContext();
Renderbuffer *buffer = NULL; Renderbuffer *buffer = nullptr;
if(type == GL_NONE_OES) if(type == GL_NONE_OES)
{ {
buffer = NULL; buffer = nullptr;
} }
else if(type == GL_RENDERBUFFER_OES) else if(type == GL_RENDERBUFFER_OES)
{ {
...@@ -81,19 +81,19 @@ void Framebuffer::detachTexture(GLuint texture) ...@@ -81,19 +81,19 @@ void Framebuffer::detachTexture(GLuint texture)
if(mColorbufferPointer.name() == texture && IsTextureTarget(mColorbufferType)) if(mColorbufferPointer.name() == texture && IsTextureTarget(mColorbufferType))
{ {
mColorbufferType = GL_NONE_OES; mColorbufferType = GL_NONE_OES;
mColorbufferPointer = NULL; mColorbufferPointer = nullptr;
} }
if(mDepthbufferPointer.name() == texture && IsTextureTarget(mDepthbufferType)) if(mDepthbufferPointer.name() == texture && IsTextureTarget(mDepthbufferType))
{ {
mDepthbufferType = GL_NONE_OES; mDepthbufferType = GL_NONE_OES;
mDepthbufferPointer = NULL; mDepthbufferPointer = nullptr;
} }
if(mStencilbufferPointer.name() == texture && IsTextureTarget(mStencilbufferType)) if(mStencilbufferPointer.name() == texture && IsTextureTarget(mStencilbufferType))
{ {
mStencilbufferType = GL_NONE_OES; mStencilbufferType = GL_NONE_OES;
mStencilbufferPointer = NULL; mStencilbufferPointer = nullptr;
} }
} }
...@@ -102,19 +102,19 @@ void Framebuffer::detachRenderbuffer(GLuint renderbuffer) ...@@ -102,19 +102,19 @@ void Framebuffer::detachRenderbuffer(GLuint renderbuffer)
if(mColorbufferPointer.name() == renderbuffer && mColorbufferType == GL_RENDERBUFFER_OES) if(mColorbufferPointer.name() == renderbuffer && mColorbufferType == GL_RENDERBUFFER_OES)
{ {
mColorbufferType = GL_NONE_OES; mColorbufferType = GL_NONE_OES;
mColorbufferPointer = NULL; mColorbufferPointer = nullptr;
} }
if(mDepthbufferPointer.name() == renderbuffer && mDepthbufferType == GL_RENDERBUFFER_OES) if(mDepthbufferPointer.name() == renderbuffer && mDepthbufferType == GL_RENDERBUFFER_OES)
{ {
mDepthbufferType = GL_NONE_OES; mDepthbufferType = GL_NONE_OES;
mDepthbufferPointer = NULL; mDepthbufferPointer = nullptr;
} }
if(mStencilbufferPointer.name() == renderbuffer && mStencilbufferType == GL_RENDERBUFFER_OES) if(mStencilbufferPointer.name() == renderbuffer && mStencilbufferType == GL_RENDERBUFFER_OES)
{ {
mStencilbufferType = GL_NONE_OES; mStencilbufferType = GL_NONE_OES;
mStencilbufferPointer = NULL; mStencilbufferPointer = nullptr;
} }
} }
...@@ -129,26 +129,35 @@ egl::Image *Framebuffer::getRenderTarget() ...@@ -129,26 +129,35 @@ egl::Image *Framebuffer::getRenderTarget()
return colorbuffer->getRenderTarget(); return colorbuffer->getRenderTarget();
} }
return NULL; return nullptr;
} }
// Increments refcount on surface. // Increments refcount on surface.
// caller must Release() the returned surface // caller must Release() the returned surface
egl::Image *Framebuffer::getDepthStencil() egl::Image *Framebuffer::getDepthBuffer()
{ {
Renderbuffer *depthstencilbuffer = mDepthbufferPointer; Renderbuffer *depthbuffer = mDepthbufferPointer;
if(!depthstencilbuffer) if(depthbuffer)
{ {
depthstencilbuffer = mStencilbufferPointer; return depthbuffer->getRenderTarget();
} }
if(depthstencilbuffer) return nullptr;
}
// Increments refcount on surface.
// caller must Release() the returned surface
egl::Image *Framebuffer::getStencilBuffer()
{
Renderbuffer *stencilbuffer = mStencilbufferPointer;
if(stencilbuffer)
{ {
return depthstencilbuffer->getRenderTarget(); return stencilbuffer->getRenderTarget();
} }
return NULL; return nullptr;
} }
Renderbuffer *Framebuffer::getColorbuffer() Renderbuffer *Framebuffer::getColorbuffer()
...@@ -275,8 +284,8 @@ GLenum Framebuffer::completeness(int &width, int &height, int &samples) ...@@ -275,8 +284,8 @@ GLenum Framebuffer::completeness(int &width, int &height, int &samples)
samples = colorbuffer->getSamples(); samples = colorbuffer->getSamples();
} }
Renderbuffer *depthbuffer = NULL; Renderbuffer *depthbuffer = nullptr;
Renderbuffer *stencilbuffer = NULL; Renderbuffer *stencilbuffer = nullptr;
if(mDepthbufferType != GL_NONE_OES) if(mDepthbufferType != GL_NONE_OES)
{ {
...@@ -381,13 +390,6 @@ GLenum Framebuffer::completeness(int &width, int &height, int &samples) ...@@ -381,13 +390,6 @@ GLenum Framebuffer::completeness(int &width, int &height, int &samples)
} }
} }
// 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
if(depthbuffer && stencilbuffer && (depthbuffer != stencilbuffer))
{
return GL_FRAMEBUFFER_UNSUPPORTED_OES;
}
// We need to have at least one attachment to be complete // We need to have at least one attachment to be complete
if(width == -1 || height == -1) if(width == -1 || height == -1)
{ {
......
...@@ -43,7 +43,8 @@ public: ...@@ -43,7 +43,8 @@ public:
void detachRenderbuffer(GLuint renderbuffer); void detachRenderbuffer(GLuint renderbuffer);
egl::Image *getRenderTarget(); egl::Image *getRenderTarget();
egl::Image *getDepthStencil(); egl::Image *getDepthBuffer();
egl::Image *getStencilBuffer();
Renderbuffer *getColorbuffer(); Renderbuffer *getColorbuffer();
Renderbuffer *getDepthbuffer(); Renderbuffer *getDepthbuffer();
......
...@@ -2772,10 +2772,13 @@ bool Context::applyRenderTarget() ...@@ -2772,10 +2772,13 @@ bool Context::applyRenderTarget()
if(renderTarget) renderTarget->release(); if(renderTarget) renderTarget->release();
} }
egl::Image *depthStencil = framebuffer->getDepthStencil(); egl::Image *depthBuffer = framebuffer->getDepthBuffer();
device->setDepthBuffer(depthStencil); device->setDepthBuffer(depthBuffer);
device->setStencilBuffer(depthStencil); if(depthBuffer) depthBuffer->release();
if(depthStencil) depthStencil->release();
egl::Image *stencilBuffer = framebuffer->getStencilBuffer();
device->setStencilBuffer(stencilBuffer);
if(stencilBuffer) stencilBuffer->release();
Viewport viewport; Viewport viewport;
float zNear = clamp01(mState.zNear); float zNear = clamp01(mState.zNear);
...@@ -3436,7 +3439,7 @@ void Context::clearDepthBuffer(const GLfloat value) ...@@ -3436,7 +3439,7 @@ void Context::clearDepthBuffer(const GLfloat value)
if(mState.depthMask && !mState.rasterizerDiscardEnabled) if(mState.depthMask && !mState.rasterizerDiscardEnabled)
{ {
Framebuffer *framebuffer = getDrawFramebuffer(); Framebuffer *framebuffer = getDrawFramebuffer();
egl::Image *depthbuffer = framebuffer->getDepthStencil(); egl::Image *depthbuffer = framebuffer->getDepthBuffer();
if(depthbuffer) if(depthbuffer)
{ {
...@@ -3460,7 +3463,7 @@ void Context::clearStencilBuffer(const GLint value) ...@@ -3460,7 +3463,7 @@ void Context::clearStencilBuffer(const GLint value)
if(mState.stencilWritemask && !mState.rasterizerDiscardEnabled) if(mState.stencilWritemask && !mState.rasterizerDiscardEnabled)
{ {
Framebuffer *framebuffer = getDrawFramebuffer(); Framebuffer *framebuffer = getDrawFramebuffer();
egl::Image *stencilbuffer = framebuffer->getDepthStencil(); egl::Image *stencilbuffer = framebuffer->getStencilBuffer();
if(stencilbuffer) if(stencilbuffer)
{ {
...@@ -4098,9 +4101,6 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1 ...@@ -4098,9 +4101,6 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1
Renderbuffer *readDSBuffer = NULL; Renderbuffer *readDSBuffer = NULL;
Renderbuffer *drawDSBuffer = NULL; Renderbuffer *drawDSBuffer = NULL;
// We support OES_packed_depth_stencil, and do not support a separately attached depth and stencil buffer, so if we have
// both a depth and stencil buffer, it will be the same buffer.
if(mask & GL_DEPTH_BUFFER_BIT) if(mask & GL_DEPTH_BUFFER_BIT)
{ {
if(readFramebuffer->getDepthbuffer() && drawFramebuffer->getDepthbuffer()) if(readFramebuffer->getDepthbuffer() && drawFramebuffer->getDepthbuffer())
...@@ -4174,7 +4174,7 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1 ...@@ -4174,7 +4174,7 @@ void Context::blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1
if(blitDepthStencil) if(blitDepthStencil)
{ {
bool success = device->stretchRect(readFramebuffer->getDepthStencil(), NULL, drawFramebuffer->getDepthStencil(), NULL, false); bool success = device->stretchRect(readFramebuffer->getDepthBuffer(), nullptr, drawFramebuffer->getDepthBuffer(), nullptr, false);
if(!success) if(!success)
{ {
......
...@@ -48,20 +48,20 @@ Framebuffer::~Framebuffer() ...@@ -48,20 +48,20 @@ Framebuffer::~Framebuffer()
{ {
for(int i = 0; i < IMPLEMENTATION_MAX_COLOR_ATTACHMENTS; ++i) for(int i = 0; i < IMPLEMENTATION_MAX_COLOR_ATTACHMENTS; ++i)
{ {
mColorbufferPointer[i] = NULL; mColorbufferPointer[i] = nullptr;
} }
mDepthbufferPointer = NULL; mDepthbufferPointer = nullptr;
mStencilbufferPointer = NULL; mStencilbufferPointer = nullptr;
} }
Renderbuffer *Framebuffer::lookupRenderbuffer(GLenum type, GLuint handle, GLint level, GLint layer) const Renderbuffer *Framebuffer::lookupRenderbuffer(GLenum type, GLuint handle, GLint level, GLint layer) const
{ {
Context *context = getContext(); Context *context = getContext();
Renderbuffer *buffer = NULL; Renderbuffer *buffer = nullptr;
if(type == GL_NONE) if(type == GL_NONE)
{ {
buffer = NULL; buffer = nullptr;
} }
else if(IsRenderbuffer(type)) else if(IsRenderbuffer(type))
{ {
...@@ -126,20 +126,20 @@ void Framebuffer::detachTexture(GLuint texture) ...@@ -126,20 +126,20 @@ void Framebuffer::detachTexture(GLuint texture)
if(mColorbufferPointer[i].name() == texture && IsTextureTarget(mColorbufferType[i])) if(mColorbufferPointer[i].name() == texture && IsTextureTarget(mColorbufferType[i]))
{ {
mColorbufferType[i] = GL_NONE; mColorbufferType[i] = GL_NONE;
mColorbufferPointer[i] = NULL; mColorbufferPointer[i] = nullptr;
} }
} }
if(mDepthbufferPointer.name() == texture && IsTextureTarget(mDepthbufferType)) if(mDepthbufferPointer.name() == texture && IsTextureTarget(mDepthbufferType))
{ {
mDepthbufferType = GL_NONE; mDepthbufferType = GL_NONE;
mDepthbufferPointer = NULL; mDepthbufferPointer = nullptr;
} }
if(mStencilbufferPointer.name() == texture && IsTextureTarget(mStencilbufferType)) if(mStencilbufferPointer.name() == texture && IsTextureTarget(mStencilbufferType))
{ {
mStencilbufferType = GL_NONE; mStencilbufferType = GL_NONE;
mStencilbufferPointer = NULL; mStencilbufferPointer = nullptr;
} }
} }
...@@ -150,20 +150,20 @@ void Framebuffer::detachRenderbuffer(GLuint renderbuffer) ...@@ -150,20 +150,20 @@ void Framebuffer::detachRenderbuffer(GLuint renderbuffer)
if(mColorbufferPointer[i].name() == renderbuffer && IsRenderbuffer(mColorbufferType[i])) if(mColorbufferPointer[i].name() == renderbuffer && IsRenderbuffer(mColorbufferType[i]))
{ {
mColorbufferType[i] = GL_NONE; mColorbufferType[i] = GL_NONE;
mColorbufferPointer[i] = NULL; mColorbufferPointer[i] = nullptr;
} }
} }
if(mDepthbufferPointer.name() == renderbuffer && IsRenderbuffer(mDepthbufferType)) if(mDepthbufferPointer.name() == renderbuffer && IsRenderbuffer(mDepthbufferType))
{ {
mDepthbufferType = GL_NONE; mDepthbufferType = GL_NONE;
mDepthbufferPointer = NULL; mDepthbufferPointer = nullptr;
} }
if(mStencilbufferPointer.name() == renderbuffer && IsRenderbuffer(mStencilbufferType)) if(mStencilbufferPointer.name() == renderbuffer && IsRenderbuffer(mStencilbufferType))
{ {
mStencilbufferType = GL_NONE; mStencilbufferType = GL_NONE;
mStencilbufferPointer = NULL; mStencilbufferPointer = nullptr;
} }
} }
...@@ -178,7 +178,7 @@ egl::Image *Framebuffer::getRenderTarget(GLuint index) ...@@ -178,7 +178,7 @@ egl::Image *Framebuffer::getRenderTarget(GLuint index)
return colorbuffer->getRenderTarget(); return colorbuffer->getRenderTarget();
} }
return NULL; return nullptr;
} }
egl::Image *Framebuffer::getReadRenderTarget() egl::Image *Framebuffer::getReadRenderTarget()
...@@ -189,26 +189,35 @@ egl::Image *Framebuffer::getReadRenderTarget() ...@@ -189,26 +189,35 @@ egl::Image *Framebuffer::getReadRenderTarget()
// Increments refcount on surface. // Increments refcount on surface.
// caller must Release() the returned surface // caller must Release() the returned surface
egl::Image *Framebuffer::getDepthStencil() egl::Image *Framebuffer::getDepthBuffer()
{ {
Renderbuffer *depthstencilbuffer = mDepthbufferPointer; Renderbuffer *depthbuffer = mDepthbufferPointer;
if(!depthstencilbuffer) if(depthbuffer)
{ {
depthstencilbuffer = mStencilbufferPointer; return depthbuffer->getRenderTarget();
} }
if(depthstencilbuffer) return nullptr;
}
// Increments refcount on surface.
// caller must Release() the returned surface
egl::Image *Framebuffer::getStencilBuffer()
{
Renderbuffer *stencilbuffer = mStencilbufferPointer;
if(stencilbuffer)
{ {
return depthstencilbuffer->getRenderTarget(); return stencilbuffer->getRenderTarget();
} }
return NULL; return nullptr;
} }
Renderbuffer *Framebuffer::getColorbuffer(GLuint index) Renderbuffer *Framebuffer::getColorbuffer(GLuint index)
{ {
return (index < MAX_COLOR_ATTACHMENTS) ? mColorbufferPointer[index] : (Renderbuffer*)NULL; return (index < MAX_COLOR_ATTACHMENTS) ? mColorbufferPointer[index] : (Renderbuffer*)nullptr;
} }
Renderbuffer *Framebuffer::getReadColorbuffer() Renderbuffer *Framebuffer::getReadColorbuffer()
...@@ -364,8 +373,8 @@ GLenum Framebuffer::completeness(int &width, int &height, int &samples) ...@@ -364,8 +373,8 @@ GLenum Framebuffer::completeness(int &width, int &height, int &samples)
} }
} }
Renderbuffer *depthbuffer = NULL; Renderbuffer *depthbuffer = nullptr;
Renderbuffer *stencilbuffer = NULL; Renderbuffer *stencilbuffer = nullptr;
if(mDepthbufferType != GL_NONE) if(mDepthbufferType != GL_NONE)
{ {
...@@ -469,13 +478,6 @@ GLenum Framebuffer::completeness(int &width, int &height, int &samples) ...@@ -469,13 +478,6 @@ GLenum Framebuffer::completeness(int &width, int &height, int &samples)
} }
} }
// 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
if(depthbuffer && stencilbuffer && (depthbuffer != stencilbuffer))
{
return GL_FRAMEBUFFER_UNSUPPORTED;
}
// We need to have at least one attachment to be complete // We need to have at least one attachment to be complete
if(width == -1 || height == -1) if(width == -1 || height == -1)
{ {
......
...@@ -49,7 +49,8 @@ public: ...@@ -49,7 +49,8 @@ public:
egl::Image *getRenderTarget(GLuint index); egl::Image *getRenderTarget(GLuint index);
egl::Image *getReadRenderTarget(); egl::Image *getReadRenderTarget();
egl::Image *getDepthStencil(); egl::Image *getDepthBuffer();
egl::Image *getStencilBuffer();
Renderbuffer *getColorbuffer(GLuint index); Renderbuffer *getColorbuffer(GLuint index);
Renderbuffer *getReadColorbuffer(); Renderbuffer *getReadColorbuffer();
......
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