diff --git a/gfx/gl/GLBlitTextureImageHelper.cpp b/gfx/gl/GLBlitTextureImageHelper.cpp index 1c7884927e66..58494eb5c782 100644 --- a/gfx/gl/GLBlitTextureImageHelper.cpp +++ b/gfx/gl/GLBlitTextureImageHelper.cpp @@ -146,26 +146,14 @@ GLBlitTextureImageHelper::BlitTextureImage(TextureImage *aSrc, const nsIntRect& ScopedBindTextureUnit autoTexUnit(mGL, LOCAL_GL_TEXTURE0); ScopedBindTexture autoTex(mGL, aSrc->GetTextureID()); - - mGL->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, 0); - - mGL->fVertexAttribPointer(0, 2, LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0, rects.vertCoords().Elements()); - mGL->fVertexAttribPointer(1, 2, LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0, rects.texCoords().Elements()); - - mGL->fEnableVertexAttribArray(0); - mGL->fEnableVertexAttribArray(1); + ScopedVertexAttribPointer autoAttrib0(mGL, 0, 2, LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0, 0, rects.vertCoords().Elements()); + ScopedVertexAttribPointer autoAttrib1(mGL, 1, 2, LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0, 0, rects.texCoords().Elements()); mGL->fDrawArrays(LOCAL_GL_TRIANGLES, 0, rects.elements()); - mGL->fDisableVertexAttribArray(0); - mGL->fDisableVertexAttribArray(1); - } while (aSrc->NextTile()); } while (aDst->NextTile()); - mGL->fVertexAttribPointer(0, 2, LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0, nullptr); - mGL->fVertexAttribPointer(1, 2, LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0, nullptr); - // unbind the previous texture from the framebuffer SetBlitFramebufferForDestTexture(0); diff --git a/gfx/gl/ScopedGLHelpers.cpp b/gfx/gl/ScopedGLHelpers.cpp index adb41f107ae4..f6a51e5abd2a 100644 --- a/gfx/gl/ScopedGLHelpers.cpp +++ b/gfx/gl/ScopedGLHelpers.cpp @@ -330,5 +330,76 @@ void ScopedScissorRect::UnwrapImpl() mSavedScissorRect[3]); } +/* ScopedVertexAttribPointer **************************************************/ + +ScopedVertexAttribPointer::ScopedVertexAttribPointer(GLContext* aGL, + GLuint index, + GLint size, + GLenum type, + realGLboolean normalized, + GLsizei stride, + GLuint buffer, + const GLvoid* pointer) + : ScopedGLWrapper(aGL) +{ + WrapImpl(index); + mGL->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, buffer); + mGL->fVertexAttribPointer(index, size, type, normalized, stride, pointer); + mGL->fEnableVertexAttribArray(index); +} + +ScopedVertexAttribPointer::ScopedVertexAttribPointer(GLContext* aGL, + GLuint index) + : ScopedGLWrapper(aGL) +{ + WrapImpl(index); +} + +void +ScopedVertexAttribPointer::WrapImpl(GLuint index) +{ + mAttribIndex = index; + + /* + * mGL->fGetVertexAttribiv takes: + * VERTEX_ATTRIB_ARRAY_ENABLED + * VERTEX_ATTRIB_ARRAY_SIZE, + * VERTEX_ATTRIB_ARRAY_STRIDE, + * VERTEX_ATTRIB_ARRAY_TYPE, + * VERTEX_ATTRIB_ARRAY_NORMALIZED, + * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, + * CURRENT_VERTEX_ATTRIB + * + * CURRENT_VERTEX_ATTRIB is vertex shader state. \o/ + * Others appear to be vertex array state, + * or alternatively in the internal vertex array state + * for a buffer object. + */ + + mGL->fGetVertexAttribiv(mAttribIndex, LOCAL_GL_VERTEX_ATTRIB_ARRAY_ENABLED, &mAttribEnabled); + mGL->fGetVertexAttribiv(mAttribIndex, LOCAL_GL_VERTEX_ATTRIB_ARRAY_SIZE, &mAttribSize); + mGL->fGetVertexAttribiv(mAttribIndex, LOCAL_GL_VERTEX_ATTRIB_ARRAY_STRIDE, &mAttribStride); + mGL->fGetVertexAttribiv(mAttribIndex, LOCAL_GL_VERTEX_ATTRIB_ARRAY_TYPE, &mAttribType); + mGL->fGetVertexAttribiv(mAttribIndex, LOCAL_GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &mAttribNormalized); + mGL->fGetVertexAttribiv(mAttribIndex, LOCAL_GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &mAttribBufferBinding); + mGL->fGetVertexAttribPointerv(mAttribIndex, LOCAL_GL_VERTEX_ATTRIB_ARRAY_POINTER, &mAttribPointer); + + // Note that uniform values are program state, so we don't need to rebind those. + + mGL->GetUIntegerv(LOCAL_GL_ARRAY_BUFFER_BINDING, &mBoundBuffer); +} + +void +ScopedVertexAttribPointer::UnwrapImpl() +{ + mGL->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mAttribBufferBinding); + mGL->fVertexAttribPointer(mAttribIndex, mAttribSize, mAttribType, mAttribNormalized, mAttribStride, mAttribPointer); + if (mAttribEnabled) + mGL->fEnableVertexAttribArray(mAttribIndex); + else + mGL->fDisableVertexAttribArray(mAttribIndex); + mGL->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mBoundBuffer); +} + } /* namespace gl */ } /* namespace mozilla */ diff --git a/gfx/gl/ScopedGLHelpers.h b/gfx/gl/ScopedGLHelpers.h index c55121c02dca..bf35acce4aa2 100644 --- a/gfx/gl/ScopedGLHelpers.h +++ b/gfx/gl/ScopedGLHelpers.h @@ -277,6 +277,32 @@ protected: void UnwrapImpl(); }; +struct ScopedVertexAttribPointer + : public ScopedGLWrapper +{ + friend struct ScopedGLWrapper; + +protected: + GLuint mAttribIndex; + GLint mAttribEnabled; + GLint mAttribSize; + GLint mAttribStride; + GLint mAttribType; + GLint mAttribNormalized; + GLint mAttribBufferBinding; + void* mAttribPointer; + GLuint mBoundBuffer; + +public: + ScopedVertexAttribPointer(GLContext* aGL, GLuint index, GLint size, GLenum type, realGLboolean normalized, + GLsizei stride, GLuint buffer, const GLvoid* pointer); + explicit ScopedVertexAttribPointer(GLContext* aGL, GLuint index); + +protected: + void WrapImpl(GLuint index); + void UnwrapImpl(); +}; + } /* namespace gl */ } /* namespace mozilla */