Commit 1eb708e1 by Geoff Lang

Clear cached state when deleting GL objects.

Change-Id: I84eac9b3796858e5e19e26851ad83baa1f9b6af2 Reviewed-on: https://chromium-review.googlesource.com/269142Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org> Reviewed-by: 's avatarBrandon Jones <bajones@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 716cc88e
...@@ -42,11 +42,8 @@ BufferGL::BufferGL(const FunctionsGL *functions, StateManagerGL *stateManager) ...@@ -42,11 +42,8 @@ BufferGL::BufferGL(const FunctionsGL *functions, StateManagerGL *stateManager)
BufferGL::~BufferGL() BufferGL::~BufferGL()
{ {
if (mBufferID) mStateManager->deleteBuffer(mBufferID);
{ mBufferID = 0;
mFunctions->deleteBuffers(1, &mBufferID);
mBufferID = 0;
}
} }
gl::Error BufferGL::setData(const void* data, size_t size, GLenum usage) gl::Error BufferGL::setData(const void* data, size_t size, GLenum usage)
......
...@@ -36,11 +36,8 @@ FramebufferGL::FramebufferGL(const gl::Framebuffer::Data &data, const FunctionsG ...@@ -36,11 +36,8 @@ FramebufferGL::FramebufferGL(const gl::Framebuffer::Data &data, const FunctionsG
FramebufferGL::~FramebufferGL() FramebufferGL::~FramebufferGL()
{ {
if (mFramebufferID != 0) mStateManager->deleteFramebuffer(mFramebufferID);
{ mFramebufferID = 0;
mFunctions->deleteFramebuffers(1, &mFramebufferID);
mFramebufferID = 0;
}
} }
static void BindFramebufferAttachment(const FunctionsGL *functions, GLenum attachmentPoint, static void BindFramebufferAttachment(const FunctionsGL *functions, GLenum attachmentPoint,
......
...@@ -404,11 +404,8 @@ void ProgramGL::reset() ...@@ -404,11 +404,8 @@ void ProgramGL::reset()
{ {
ProgramImpl::reset(); ProgramImpl::reset();
if (mProgramID) mStateManager->deleteProgram(mProgramID);
{ mProgramID = 0;
mFunctions->deleteProgram(mProgramID);
mProgramID = 0;
}
} }
GLuint ProgramGL::getProgramID() const GLuint ProgramGL::getProgramID() const
......
...@@ -30,11 +30,8 @@ RenderbufferGL::RenderbufferGL(const FunctionsGL *functions, StateManagerGL *sta ...@@ -30,11 +30,8 @@ RenderbufferGL::RenderbufferGL(const FunctionsGL *functions, StateManagerGL *sta
RenderbufferGL::~RenderbufferGL() RenderbufferGL::~RenderbufferGL()
{ {
if (mRenderbufferID != 0) mStateManager->deleteRenderbuffer(mRenderbufferID);
{ mRenderbufferID = 0;
mFunctions->deleteRenderbuffers(1, &mRenderbufferID);
mRenderbufferID = 0;
}
} }
gl::Error RenderbufferGL::setStorage(GLenum internalformat, size_t width, size_t height) gl::Error RenderbufferGL::setStorage(GLenum internalformat, size_t width, size_t height)
......
...@@ -93,6 +93,97 @@ StateManagerGL::StateManagerGL(const FunctionsGL *functions, const gl::Caps &ren ...@@ -93,6 +93,97 @@ StateManagerGL::StateManagerGL(const FunctionsGL *functions, const gl::Caps &ren
mFramebuffers[GL_DRAW_FRAMEBUFFER] = 0; mFramebuffers[GL_DRAW_FRAMEBUFFER] = 0;
} }
void StateManagerGL::deleteProgram(GLuint program)
{
if (program != 0)
{
if (mProgram == program)
{
useProgram(0);
}
mFunctions->deleteProgram(program);
}
}
void StateManagerGL::deleteVertexArray(GLuint vao)
{
if (vao != 0)
{
if (mVAO == vao)
{
bindVertexArray(0);
}
mFunctions->deleteVertexArrays(1, &vao);
}
}
void StateManagerGL::deleteTexture(GLuint texture)
{
if (texture != 0)
{
for (const auto &textureTypeIter : mTextures)
{
const std::vector<GLuint> &textureVector = textureTypeIter.second;
for (size_t textureUnitIndex = 0; textureUnitIndex < textureVector.size(); textureUnitIndex++)
{
if (textureVector[textureUnitIndex] == texture)
{
activeTexture(textureUnitIndex);
bindTexture(textureTypeIter.first, 0);
}
}
}
mFunctions->deleteTextures(1, &texture);
}
}
void StateManagerGL::deleteBuffer(GLuint buffer)
{
if (buffer != 0)
{
for (const auto &bufferTypeIter : mBuffers)
{
if (bufferTypeIter.second == buffer)
{
bindBuffer(bufferTypeIter.first, 0);
}
}
mFunctions->deleteBuffers(1, &buffer);
}
}
void StateManagerGL::deleteFramebuffer(GLuint fbo)
{
if (fbo != 0)
{
for (auto fboTypeIter : mFramebuffers)
{
if (fboTypeIter.second == fbo)
{
bindFramebuffer(fboTypeIter.first, 0);
}
mFunctions->deleteFramebuffers(1, &fbo);
}
}
}
void StateManagerGL::deleteRenderbuffer(GLuint rbo)
{
if (rbo != 0)
{
if (mRenderbuffer == rbo)
{
bindRenderbuffer(GL_RENDERBUFFER, 0);
}
mFunctions->deleteRenderbuffers(1, &rbo);
}
}
void StateManagerGL::useProgram(GLuint program) void StateManagerGL::useProgram(GLuint program)
{ {
if (mProgram != program) if (mProgram != program)
......
...@@ -33,6 +33,13 @@ class StateManagerGL : angle::NonCopyable ...@@ -33,6 +33,13 @@ class StateManagerGL : angle::NonCopyable
public: public:
StateManagerGL(const FunctionsGL *functions, const gl::Caps &rendererCaps); StateManagerGL(const FunctionsGL *functions, const gl::Caps &rendererCaps);
void deleteProgram(GLuint program);
void deleteVertexArray(GLuint vao);
void deleteTexture(GLuint texture);
void deleteBuffer(GLuint buffer);
void deleteFramebuffer(GLuint fbo);
void deleteRenderbuffer(GLuint rbo);
void useProgram(GLuint program); void useProgram(GLuint program);
void bindVertexArray(GLuint vao); void bindVertexArray(GLuint vao);
void bindBuffer(GLenum type, GLuint buffer); void bindBuffer(GLenum type, GLuint buffer);
......
...@@ -73,11 +73,8 @@ TextureGL::TextureGL(GLenum type, const FunctionsGL *functions, StateManagerGL * ...@@ -73,11 +73,8 @@ TextureGL::TextureGL(GLenum type, const FunctionsGL *functions, StateManagerGL *
TextureGL::~TextureGL() TextureGL::~TextureGL()
{ {
if (mTextureID) mStateManager->deleteTexture(mTextureID);
{ mTextureID = 0;
mFunctions->deleteTextures(1, &mTextureID);
mTextureID = 0;
}
} }
void TextureGL::setUsage(GLenum usage) void TextureGL::setUsage(GLenum usage)
......
...@@ -48,25 +48,16 @@ VertexArrayGL::VertexArrayGL(const FunctionsGL *functions, StateManagerGL *state ...@@ -48,25 +48,16 @@ VertexArrayGL::VertexArrayGL(const FunctionsGL *functions, StateManagerGL *state
VertexArrayGL::~VertexArrayGL() VertexArrayGL::~VertexArrayGL()
{ {
if (mVertexArrayID != 0) mStateManager->deleteVertexArray(mVertexArrayID);
{ mVertexArrayID = 0;
mFunctions->deleteVertexArrays(1, &mVertexArrayID);
mVertexArrayID = 0;
}
if (mStreamingElementArrayBuffer != 0) mStateManager->deleteBuffer(mStreamingElementArrayBuffer);
{ mStreamingElementArrayBufferSize = 0;
mFunctions->deleteBuffers(1, &mStreamingElementArrayBuffer); mStreamingElementArrayBuffer = 0;
mStreamingElementArrayBufferSize = 0;
mStreamingElementArrayBuffer = 0;
}
if (mStreamingArrayBuffer != 0) mStateManager->deleteBuffer(mStreamingArrayBuffer);
{ mStreamingArrayBufferSize = 0;
mFunctions->deleteBuffers(1, &mStreamingArrayBuffer); mStreamingArrayBuffer = 0;
mStreamingArrayBufferSize = 0;
mStreamingArrayBuffer = 0;
}
mElementArrayBuffer.set(nullptr); mElementArrayBuffer.set(nullptr);
for (size_t idx = 0; idx < mAttributes.size(); idx++) for (size_t idx = 0; idx < mAttributes.size(); idx++)
......
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