Commit aa2ab7d8 by Shannon Woods

Cache bound FBO and VAO objects themselves in State

BUG=angle:685 Change-Id: I19ae6752d1a7490122dd9ca076efb08564e1901d Reviewed-on: https://chromium-review.googlesource.com/205835Tested-by: 's avatarShannon Woods <shannonwoods@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent a1851e8f
...@@ -698,12 +698,12 @@ void Context::setActiveSampler(unsigned int active) ...@@ -698,12 +698,12 @@ void Context::setActiveSampler(unsigned int active)
GLuint Context::getReadFramebufferHandle() const GLuint Context::getReadFramebufferHandle() const
{ {
return mState.readFramebuffer; return mState.readFramebuffer->id();
} }
GLuint Context::getDrawFramebufferHandle() const GLuint Context::getDrawFramebufferHandle() const
{ {
return mState.drawFramebuffer; return mState.drawFramebuffer->id();
} }
GLuint Context::getRenderbufferHandle() const GLuint Context::getRenderbufferHandle() const
...@@ -713,7 +713,7 @@ GLuint Context::getRenderbufferHandle() const ...@@ -713,7 +713,7 @@ GLuint Context::getRenderbufferHandle() const
GLuint Context::getVertexArrayHandle() const GLuint Context::getVertexArrayHandle() const
{ {
return mState.vertexArray; return mState.vertexArray->id();
} }
GLuint Context::getSamplerHandle(GLuint textureUnit) const GLuint Context::getSamplerHandle(GLuint textureUnit) const
...@@ -871,8 +871,8 @@ GLuint Context::createVertexArray() ...@@ -871,8 +871,8 @@ GLuint Context::createVertexArray()
// Although the spec states VAO state is not initialized until the object is bound, // Although the spec states VAO state is not initialized until the object is bound,
// we create it immediately. The resulting behaviour is transparent to the application, // we create it immediately. The resulting behaviour is transparent to the application,
// since it's not currently possible to access the state until the object is bound. // since it's not currently possible to access the state until the object is bound.
mVertexArrayMap[handle] = new VertexArray(mRenderer->createVertexArray(), handle, MAX_VERTEX_ATTRIBS); VertexArray *vertexArray = new VertexArray(mRenderer->createVertexArray(), handle, MAX_VERTEX_ATTRIBS);
mVertexArrayMap[handle] = vertexArray;
return handle; return handle;
} }
...@@ -1108,24 +1108,23 @@ TransformFeedback *Context::getTransformFeedback(GLuint handle) const ...@@ -1108,24 +1108,23 @@ TransformFeedback *Context::getTransformFeedback(GLuint handle) const
Framebuffer *Context::getReadFramebuffer() const Framebuffer *Context::getReadFramebuffer() const
{ {
return getFramebuffer(mState.readFramebuffer); return mState.readFramebuffer;
} }
Framebuffer *Context::getDrawFramebuffer() Framebuffer *Context::getDrawFramebuffer()
{ {
return mBoundDrawFramebuffer; return mState.drawFramebuffer;
} }
const Framebuffer *Context::getDrawFramebuffer() const const Framebuffer *Context::getDrawFramebuffer() const
{ {
return mBoundDrawFramebuffer; return mState.drawFramebuffer;
} }
VertexArray *Context::getCurrentVertexArray() const VertexArray *Context::getCurrentVertexArray() const
{ {
VertexArray *vao = getVertexArray(mState.vertexArray); ASSERT(mState.vertexArray != NULL);
ASSERT(vao != NULL); return mState.vertexArray;
return vao;
} }
TransformFeedback *Context::getCurrentTransformFeedback() const TransformFeedback *Context::getCurrentTransformFeedback() const
...@@ -1184,22 +1183,20 @@ void Context::bindReadFramebuffer(GLuint framebuffer) ...@@ -1184,22 +1183,20 @@ void Context::bindReadFramebuffer(GLuint framebuffer)
{ {
if (!getFramebuffer(framebuffer)) if (!getFramebuffer(framebuffer))
{ {
mFramebufferMap[framebuffer] = new Framebuffer(mRenderer); mFramebufferMap[framebuffer] = new Framebuffer(mRenderer, framebuffer);
} }
mState.readFramebuffer = framebuffer; mState.readFramebuffer = getFramebuffer(framebuffer);
} }
void Context::bindDrawFramebuffer(GLuint framebuffer) void Context::bindDrawFramebuffer(GLuint framebuffer)
{ {
if (!getFramebuffer(framebuffer)) if (!getFramebuffer(framebuffer))
{ {
mFramebufferMap[framebuffer] = new Framebuffer(mRenderer); mFramebufferMap[framebuffer] = new Framebuffer(mRenderer, framebuffer);
} }
mState.drawFramebuffer = framebuffer; mState.drawFramebuffer = getFramebuffer(framebuffer);
mBoundDrawFramebuffer = getFramebuffer(framebuffer);
} }
void Context::bindRenderbuffer(GLuint renderbuffer) void Context::bindRenderbuffer(GLuint renderbuffer)
...@@ -1213,10 +1210,11 @@ void Context::bindVertexArray(GLuint vertexArray) ...@@ -1213,10 +1210,11 @@ void Context::bindVertexArray(GLuint vertexArray)
{ {
if (!getVertexArray(vertexArray)) if (!getVertexArray(vertexArray))
{ {
mVertexArrayMap[vertexArray] = new VertexArray(mRenderer->createVertexArray(), vertexArray, MAX_VERTEX_ATTRIBS); VertexArray *vertexArrayObject = new VertexArray(mRenderer->createVertexArray(), vertexArray, MAX_VERTEX_ATTRIBS);
mVertexArrayMap[vertexArray] = vertexArrayObject;
} }
mState.vertexArray = vertexArray; mState.vertexArray = getVertexArray(vertexArray);
} }
void Context::bindSampler(GLuint textureUnit, GLuint sampler) void Context::bindSampler(GLuint textureUnit, GLuint sampler)
...@@ -1371,12 +1369,21 @@ void Context::endQuery(GLenum target) ...@@ -1371,12 +1369,21 @@ void Context::endQuery(GLenum target)
void Context::setFramebufferZero(Framebuffer *buffer) void Context::setFramebufferZero(Framebuffer *buffer)
{ {
delete mFramebufferMap[0]; // First, check to see if the old default framebuffer
mFramebufferMap[0] = buffer; // was set for draw or read framebuffer, and change
if (mState.drawFramebuffer == 0) // the bindings to point to the new one before deleting it.
if (mState.drawFramebuffer->id() == 0)
{
mState.drawFramebuffer = buffer;
}
if (mState.readFramebuffer->id() == 0)
{ {
mBoundDrawFramebuffer = buffer; mState.readFramebuffer = buffer;
} }
delete mFramebufferMap[0];
mFramebufferMap[0] = buffer;
} }
void Context::setRenderbufferStorage(GLsizei width, GLsizei height, GLenum internalformat, GLsizei samples) void Context::setRenderbufferStorage(GLsizei width, GLsizei height, GLenum internalformat, GLsizei samples)
...@@ -1515,11 +1522,11 @@ GLuint Context::getTargetFramebufferHandle(GLenum target) const ...@@ -1515,11 +1522,11 @@ GLuint Context::getTargetFramebufferHandle(GLenum target) const
if (target == GL_READ_FRAMEBUFFER_ANGLE) if (target == GL_READ_FRAMEBUFFER_ANGLE)
{ {
return mState.readFramebuffer; return mState.readFramebuffer->id();
} }
else else
{ {
return mState.drawFramebuffer; return mState.drawFramebuffer->id();
} }
} }
...@@ -1712,10 +1719,10 @@ void Context::getIntegerv(GLenum pname, GLint *params) ...@@ -1712,10 +1719,10 @@ void Context::getIntegerv(GLenum pname, GLint *params)
case GL_ARRAY_BUFFER_BINDING: *params = mState.arrayBuffer.id(); break; case GL_ARRAY_BUFFER_BINDING: *params = mState.arrayBuffer.id(); break;
case GL_ELEMENT_ARRAY_BUFFER_BINDING: *params = getCurrentVertexArray()->getElementArrayBufferId(); break; case GL_ELEMENT_ARRAY_BUFFER_BINDING: *params = getCurrentVertexArray()->getElementArrayBufferId(); break;
//case GL_FRAMEBUFFER_BINDING: // now equivalent to GL_DRAW_FRAMEBUFFER_BINDING_ANGLE //case GL_FRAMEBUFFER_BINDING: // now equivalent to GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE: *params = mState.drawFramebuffer; break; case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE: *params = mState.drawFramebuffer->id(); break;
case GL_READ_FRAMEBUFFER_BINDING_ANGLE: *params = mState.readFramebuffer; break; case GL_READ_FRAMEBUFFER_BINDING_ANGLE: *params = mState.readFramebuffer->id(); break;
case GL_RENDERBUFFER_BINDING: *params = mState.renderbuffer.id(); break; case GL_RENDERBUFFER_BINDING: *params = mState.renderbuffer.id(); break;
case GL_VERTEX_ARRAY_BINDING: *params = mState.vertexArray; break; case GL_VERTEX_ARRAY_BINDING: *params = mState.vertexArray->id(); break;
case GL_CURRENT_PROGRAM: *params = mState.currentProgram; break; case GL_CURRENT_PROGRAM: *params = mState.currentProgram; break;
case GL_PACK_ALIGNMENT: *params = mState.pack.alignment; break; case GL_PACK_ALIGNMENT: *params = mState.pack.alignment; break;
case GL_PACK_REVERSE_ROW_ORDER_ANGLE: *params = mState.pack.reverseRowOrder; break; case GL_PACK_REVERSE_ROW_ORDER_ANGLE: *params = mState.pack.reverseRowOrder; break;
...@@ -3209,12 +3216,12 @@ void Context::detachFramebuffer(GLuint framebuffer) ...@@ -3209,12 +3216,12 @@ void Context::detachFramebuffer(GLuint framebuffer)
// If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as though // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as though
// BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of zero. // BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of zero.
if (mState.readFramebuffer == framebuffer) if (mState.readFramebuffer->id() == framebuffer)
{ {
bindReadFramebuffer(0); bindReadFramebuffer(0);
} }
if (mState.drawFramebuffer == framebuffer) if (mState.drawFramebuffer->id() == framebuffer)
{ {
bindDrawFramebuffer(0); bindDrawFramebuffer(0);
} }
...@@ -3255,7 +3262,7 @@ void Context::detachVertexArray(GLuint vertexArray) ...@@ -3255,7 +3262,7 @@ void Context::detachVertexArray(GLuint vertexArray)
// [OpenGL ES 3.0.2] section 2.10 page 43: // [OpenGL ES 3.0.2] section 2.10 page 43:
// If a vertex array object that is currently bound is deleted, the binding // If a vertex array object that is currently bound is deleted, the binding
// for that object reverts to zero and the default vertex array becomes current. // for that object reverts to zero and the default vertex array becomes current.
if (mState.vertexArray == vertexArray) if (mState.vertexArray->id() == vertexArray)
{ {
bindVertexArray(0); bindVertexArray(0);
} }
......
...@@ -96,13 +96,13 @@ struct State ...@@ -96,13 +96,13 @@ struct State
unsigned int activeSampler; // Active texture unit selector - GL_TEXTURE0 unsigned int activeSampler; // Active texture unit selector - GL_TEXTURE0
BindingPointer<Buffer> arrayBuffer; BindingPointer<Buffer> arrayBuffer;
GLuint readFramebuffer; Framebuffer *drawFramebuffer;
GLuint drawFramebuffer; Framebuffer *readFramebuffer;
BindingPointer<Renderbuffer> renderbuffer; BindingPointer<Renderbuffer> renderbuffer;
GLuint currentProgram; GLuint currentProgram;
VertexAttribCurrentValueData vertexAttribCurrentValues[MAX_VERTEX_ATTRIBS]; // From glVertexAttrib VertexAttribCurrentValueData vertexAttribCurrentValues[MAX_VERTEX_ATTRIBS]; // From glVertexAttrib
unsigned int vertexArray; VertexArray *vertexArray;
BindingPointer<Texture> samplerTexture[TEXTURE_TYPE_COUNT][IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS]; BindingPointer<Texture> samplerTexture[TEXTURE_TYPE_COUNT][IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS];
GLuint samplers[IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS]; GLuint samplers[IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS];
...@@ -527,7 +527,6 @@ class Context ...@@ -527,7 +527,6 @@ class Context
bool mRobustAccess; bool mRobustAccess;
BindingPointer<ProgramBinary> mCurrentProgramBinary; BindingPointer<ProgramBinary> mCurrentProgramBinary;
Framebuffer *mBoundDrawFramebuffer;
int mMajorShaderModel; int mMajorShaderModel;
bool mSupportsVertexTexture; bool mSupportsVertexTexture;
......
...@@ -22,8 +22,9 @@ ...@@ -22,8 +22,9 @@
namespace gl namespace gl
{ {
Framebuffer::Framebuffer(rx::Renderer *renderer) Framebuffer::Framebuffer(rx::Renderer *renderer, GLuint id)
: mRenderer(renderer), : mRenderer(renderer),
mId(id),
mReadBufferState(GL_COLOR_ATTACHMENT0_EXT), mReadBufferState(GL_COLOR_ATTACHMENT0_EXT),
mDepthbuffer(NULL), mDepthbuffer(NULL),
mStencilbuffer(NULL) mStencilbuffer(NULL)
...@@ -563,7 +564,7 @@ GLenum Framebuffer::completeness() const ...@@ -563,7 +564,7 @@ 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, 0)
{ {
Renderbuffer *colorRenderbuffer = new Renderbuffer(0, colorbuffer); Renderbuffer *colorRenderbuffer = new Renderbuffer(0, colorbuffer);
mColorbuffers[0] = new RenderbufferAttachment(colorRenderbuffer); mColorbuffers[0] = new RenderbufferAttachment(colorRenderbuffer);
......
...@@ -30,10 +30,12 @@ class DepthStencilbuffer; ...@@ -30,10 +30,12 @@ class DepthStencilbuffer;
class Framebuffer class Framebuffer
{ {
public: public:
explicit Framebuffer(rx::Renderer *renderer); Framebuffer(rx::Renderer *renderer, GLuint id);
virtual ~Framebuffer(); virtual ~Framebuffer();
GLuint id() const { return mId; }
void setColorbuffer(unsigned int colorAttachment, GLenum type, GLuint colorbuffer, GLint level, GLint layer); void setColorbuffer(unsigned int colorAttachment, GLenum type, GLuint colorbuffer, GLint level, GLint layer);
void setDepthbuffer(GLenum type, GLuint depthbuffer, GLint level, GLint layer); void setDepthbuffer(GLenum type, GLuint depthbuffer, GLint level, GLint layer);
void setStencilbuffer(GLenum type, GLuint stencilbuffer, GLint level, GLint layer); void setStencilbuffer(GLenum type, GLuint stencilbuffer, GLint level, GLint layer);
...@@ -68,6 +70,8 @@ class Framebuffer ...@@ -68,6 +70,8 @@ class Framebuffer
protected: protected:
rx::Renderer *mRenderer; rx::Renderer *mRenderer;
GLuint mId;
FramebufferAttachment *mColorbuffers[IMPLEMENTATION_MAX_DRAW_BUFFERS]; FramebufferAttachment *mColorbuffers[IMPLEMENTATION_MAX_DRAW_BUFFERS];
GLenum mDrawBufferStates[IMPLEMENTATION_MAX_DRAW_BUFFERS]; GLenum mDrawBufferStates[IMPLEMENTATION_MAX_DRAW_BUFFERS];
GLenum mReadBufferState; GLenum mReadBufferState;
......
...@@ -15,7 +15,7 @@ namespace gl ...@@ -15,7 +15,7 @@ namespace gl
{ {
VertexArray::VertexArray(rx::VertexArrayImpl *impl, GLuint id, size_t maxAttribs) VertexArray::VertexArray(rx::VertexArrayImpl *impl, GLuint id, size_t maxAttribs)
: RefCountObject(id), : mId(id),
mVertexArray(impl), mVertexArray(impl),
mVertexAttributes(maxAttribs) mVertexAttributes(maxAttribs)
{ {
...@@ -33,6 +33,11 @@ VertexArray::~VertexArray() ...@@ -33,6 +33,11 @@ VertexArray::~VertexArray()
mElementArrayBuffer.set(NULL); mElementArrayBuffer.set(NULL);
} }
GLuint VertexArray::id() const
{
return mId;
}
void VertexArray::detachBuffer(GLuint bufferName) void VertexArray::detachBuffer(GLuint bufferName)
{ {
for (size_t attribute = 0; attribute < getMaxAttribs(); attribute++) for (size_t attribute = 0; attribute < getMaxAttribs(); attribute++)
......
...@@ -27,12 +27,14 @@ namespace gl ...@@ -27,12 +27,14 @@ namespace gl
{ {
class Buffer; class Buffer;
class VertexArray : public RefCountObject class VertexArray
{ {
public: public:
VertexArray(rx::VertexArrayImpl *impl, GLuint id, size_t maxAttribs); VertexArray(rx::VertexArrayImpl *impl, GLuint id, size_t maxAttribs);
~VertexArray(); ~VertexArray();
GLuint id() const;
const VertexAttribute& getVertexAttribute(size_t attributeIndex) const; const VertexAttribute& getVertexAttribute(size_t attributeIndex) const;
void detachBuffer(GLuint bufferName); void detachBuffer(GLuint bufferName);
void setVertexAttribDivisor(GLuint index, GLuint divisor); void setVertexAttribDivisor(GLuint index, GLuint divisor);
...@@ -47,6 +49,8 @@ class VertexArray : public RefCountObject ...@@ -47,6 +49,8 @@ class VertexArray : public RefCountObject
size_t getMaxAttribs() const { return mVertexAttributes.size(); } size_t getMaxAttribs() const { return mVertexAttributes.size(); }
private: private:
GLuint mId;
rx::VertexArrayImpl *mVertexArray; rx::VertexArrayImpl *mVertexArray;
std::vector<VertexAttribute> mVertexAttributes; std::vector<VertexAttribute> mVertexAttributes;
BindingPointer<Buffer> mElementArrayBuffer; BindingPointer<Buffer> mElementArrayBuffer;
......
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