Commit 423fd912 by Alexis Hetu Committed by Alexis Hétu

Fixed read buffer and draw buffers

Specifying a read buffer or draw buffers was set on the context instead of being set on the Framebuffer object, which led to multiple Framebuffer objects wrongly sharing this state. Change-Id: I9d137c52f50e58a48b95f7ed9a44b4dad275e710 Reviewed-on: https://swiftshader-review.googlesource.com/4745Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 10eaf2ed
......@@ -151,12 +151,6 @@ Context::Context(const egl::Config *config, const Context *shareContext, EGLint
bindGenericUniformBuffer(0);
bindTransformFeedback(0);
mState.readFramebufferColorIndex = 0;
for(int i = 0; i < MAX_COLOR_ATTACHMENTS; ++i)
{
mState.drawFramebufferColorIndices[i] = GL_NONE;
}
mState.currentProgram = 0;
mState.packAlignment = 4;
......@@ -735,22 +729,32 @@ GLuint Context::getRenderbufferName() const
return mState.renderbuffer.name();
}
void Context::setReadFramebufferColorIndex(GLuint index)
void Context::setFramebufferReadBuffer(GLuint buf)
{
mState.readFramebufferColorIndex = index;
getReadFramebuffer()->setReadBuffer(buf);
}
void Context::setDrawFramebufferColorIndices(GLsizei n, const GLenum *bufs)
void Context::setFramebufferDrawBuffers(GLsizei n, const GLenum *bufs)
{
Framebuffer* drawFramebuffer = getDrawFramebuffer();
for(int i = 0; i < n; ++i)
{
mState.drawFramebufferColorIndices[i] = ((bufs[i] == GL_BACK) || (bufs[i] == GL_NONE)) ? bufs[i] : i;
drawFramebuffer->setDrawBuffer(i, bufs[i]);
}
}
GLuint Context::getReadFramebufferColorIndex() const
{
return mState.readFramebufferColorIndex;
GLenum buf = getReadFramebuffer()->getReadBuffer();
switch(buf)
{
case GL_BACK:
return 0;
case GL_NONE:
return GL_INVALID_INDEX;
default:
return buf - GL_COLOR_ATTACHMENT0;
}
}
GLuint Context::getArrayBufferName() const
......@@ -2164,9 +2168,6 @@ template<typename T> bool Context::getIntegerv(GLenum pname, T *params) const
}
break;
case GL_DRAW_BUFFER0: // symbolic constant, initial value is GL_BACK​
UNIMPLEMENTED();
*params = GL_BACK;
break;
case GL_DRAW_BUFFER1: // symbolic constant, initial value is GL_NONE
case GL_DRAW_BUFFER2:
case GL_DRAW_BUFFER3:
......@@ -2182,8 +2183,7 @@ template<typename T> bool Context::getIntegerv(GLenum pname, T *params) const
case GL_DRAW_BUFFER13:
case GL_DRAW_BUFFER14:
case GL_DRAW_BUFFER15:
UNIMPLEMENTED();
*params = GL_NONE;
*params = getDrawFramebuffer()->getDrawBuffer(pname - GL_DRAW_BUFFER0);
break;
case GL_MAJOR_VERSION: // integer, at least 3
if(clientVersion >= 3)
......@@ -2338,8 +2338,7 @@ template<typename T> bool Context::getIntegerv(GLenum pname, T *params) const
*params = 0;
break;
case GL_READ_BUFFER: // symbolic constant, initial value is GL_BACK​
UNIMPLEMENTED();
*params = GL_BACK;
*params = getReadFramebuffer()->getReadBuffer();
break;
case GL_SAMPLER_BINDING: // GLint, default 0
*params = mState.sampler[mState.activeSampler].name();
......
......@@ -381,8 +381,6 @@ struct State
GLuint readFramebuffer;
GLuint drawFramebuffer;
GLuint readFramebufferColorIndex;
GLuint drawFramebufferColorIndices[MAX_COLOR_ATTACHMENTS];
gl::BindingPointer<Renderbuffer> renderbuffer;
GLuint currentProgram;
GLuint vertexArray;
......@@ -482,8 +480,8 @@ public:
GLuint getDrawFramebufferName() const;
GLuint getRenderbufferName() const;
void setReadFramebufferColorIndex(GLuint index);
void setDrawFramebufferColorIndices(GLsizei n, const GLenum *bufs);
void setFramebufferReadBuffer(GLenum buf);
void setFramebufferDrawBuffers(GLsizei n, const GLenum *bufs);
GLuint getReadFramebufferColorIndex() const;
GLuint getActiveQuery(GLenum target) const;
......
......@@ -30,6 +30,13 @@ Framebuffer::Framebuffer()
}
mDepthbufferType = GL_NONE;
mStencilbufferType = GL_NONE;
readBuffer = GL_BACK;
drawBuffer[0] = GL_BACK;
for(int i = 1; i < MAX_COLOR_ATTACHMENTS; ++i)
{
drawBuffer[i] = GL_NONE;
}
}
Framebuffer::~Framebuffer()
......@@ -68,6 +75,11 @@ void Framebuffer::setColorbuffer(GLenum type, GLuint colorbuffer, GLuint index,
{
mColorbufferType[index] = (colorbuffer != 0) ? type : GL_NONE;
mColorbufferPointer[index] = lookupRenderbuffer(type, colorbuffer, level, layer);
drawBuffer[index] = (colorbuffer != 0) ? GL_COLOR_ATTACHMENT0 + index : GL_NONE;
if(index == 0)
{
readBuffer = drawBuffer[0];
}
}
void Framebuffer::setDepthbuffer(GLenum type, GLuint depthbuffer, GLint level, GLint layer)
......@@ -82,6 +94,26 @@ void Framebuffer::setStencilbuffer(GLenum type, GLuint stencilbuffer, GLint leve
mStencilbufferPointer = lookupRenderbuffer(type, stencilbuffer, level, layer);
}
void Framebuffer::setReadBuffer(GLenum buf)
{
readBuffer = buf;
}
void Framebuffer::setDrawBuffer(GLuint index, GLenum buf)
{
drawBuffer[index] = buf;
}
GLenum Framebuffer::getReadBuffer() const
{
return readBuffer;
}
GLenum Framebuffer::getDrawBuffer(GLuint index) const
{
return drawBuffer[index];
}
void Framebuffer::detachTexture(GLuint texture)
{
for(int i = 0; i < IMPLEMENTATION_MAX_COLOR_ATTACHMENTS; ++i)
......
......@@ -39,6 +39,11 @@ public:
void setDepthbuffer(GLenum type, GLuint depthbuffer, GLint level = 0, GLint layer = 0);
void setStencilbuffer(GLenum type, GLuint stencilbuffer, GLint level = 0, GLint layer = 0);
void setReadBuffer(GLenum buf);
void setDrawBuffer(GLuint index, GLenum buf);
GLenum getReadBuffer() const;
GLenum getDrawBuffer(GLuint index) const;
void detachTexture(GLuint texture);
void detachRenderbuffer(GLuint renderbuffer);
......@@ -76,6 +81,8 @@ public:
protected:
GLenum mColorbufferType[MAX_COLOR_ATTACHMENTS];
gl::BindingPointer<Renderbuffer> mColorbufferPointer[MAX_COLOR_ATTACHMENTS];
GLenum readBuffer;
GLenum drawBuffer[MAX_COLOR_ATTACHMENTS];
GLenum mDepthbufferType;
gl::BindingPointer<Renderbuffer> mDepthbufferPointer;
......
......@@ -513,10 +513,10 @@ GL_APICALL void GL_APIENTRY glReadBuffer(GLenum src)
{
return error(GL_INVALID_OPERATION);
}
context->setReadFramebufferColorIndex(0);
context->setFramebufferReadBuffer(src);
break;
case GL_NONE:
context->setReadFramebufferColorIndex(GL_INVALID_INDEX);
context->setFramebufferReadBuffer(src);
break;
case GL_COLOR_ATTACHMENT0:
case GL_COLOR_ATTACHMENT1:
......@@ -560,7 +560,7 @@ GL_APICALL void GL_APIENTRY glReadBuffer(GLenum src)
{
return error(GL_INVALID_OPERATION);
}
context->setReadFramebufferColorIndex(index);
context->setFramebufferReadBuffer(src);
}
break;
default:
......@@ -1211,7 +1211,7 @@ GL_APICALL void GL_APIENTRY glDrawBuffers(GLsizei n, const GLenum *bufs)
}
}
context->setDrawFramebufferColorIndices(n, bufs);
context->setFramebufferDrawBuffers(n, bufs);
}
}
......
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