void GLBlitHelper::BlitFramebufferToTexture(GLuint srcFB, GLuint destTex, const gfxIntSize& srcSize, const gfxIntSize& destSize, GLenum destTarget) { MOZ_ASSERT(!srcFB || mGL->fIsFramebuffer(srcFB)); MOZ_ASSERT(mGL->fIsTexture(destTex)); if (mGL->IsSupported(GLFeature::framebuffer_blit)) { ScopedFramebufferForTexture destWrapper(mGL, destTex, destTarget); BlitFramebufferToFramebuffer(srcFB, destWrapper.FB(), srcSize, destSize); return; } ScopedBindTexture autoTex(mGL, destTex, destTarget); ScopedBindFramebuffer boundFB(mGL, srcFB); ScopedGLState scissor(mGL, LOCAL_GL_SCISSOR_TEST, false); mGL->fCopyTexSubImage2D(destTarget, 0, 0, 0, 0, 0, srcSize.width, srcSize.height); }
void GLScreenBuffer::AssureBlitted() { if (!mNeedsBlit) return; if (mDraw) { GLuint drawFB = DrawFB(); GLuint readFB = ReadFB(); MOZ_ASSERT(drawFB != 0); MOZ_ASSERT(drawFB != readFB); MOZ_ASSERT(mGL->IsSupported(GLFeature::framebuffer_blit)); MOZ_ASSERT(mDraw->Size() == mRead->Size()); ScopedBindFramebuffer boundFB(mGL); ScopedGLState scissor(mGL, LOCAL_GL_SCISSOR_TEST, false); BindReadFB_Internal(drawFB); BindDrawFB_Internal(readFB); const gfx::IntSize& srcSize = mDraw->Size(); const gfx::IntSize& destSize = mRead->Size(); mGL->raw_fBlitFramebuffer(0, 0, srcSize.width, srcSize.height, 0, 0, destSize.width, destSize.height, LOCAL_GL_COLOR_BUFFER_BIT, LOCAL_GL_NEAREST); // Done! } mNeedsBlit = false; }
void GLBlitHelper::BlitTextureToFramebuffer(GLuint srcTex, GLuint destFB, const gfxIntSize& srcSize, const gfxIntSize& destSize, GLenum srcTarget) { MOZ_ASSERT(mGL->fIsTexture(srcTex)); MOZ_ASSERT(!destFB || mGL->fIsFramebuffer(destFB)); if (mGL->IsSupported(GLFeature::framebuffer_blit)) { ScopedFramebufferForTexture srcWrapper(mGL, srcTex, srcTarget); MOZ_ASSERT(srcWrapper.IsComplete()); BlitFramebufferToFramebuffer(srcWrapper.FB(), destFB, srcSize, destSize); return; } ScopedBindFramebuffer boundFB(mGL, destFB); // UseTexQuadProgram initializes a shader that reads // from texture unit 0. ScopedBindTextureUnit boundTU(mGL, LOCAL_GL_TEXTURE0); ScopedBindTexture boundTex(mGL, srcTex, srcTarget); GLuint boundProgram = 0; mGL->GetUIntegerv(LOCAL_GL_CURRENT_PROGRAM, &boundProgram); GLuint boundBuffer = 0; mGL->GetUIntegerv(LOCAL_GL_ARRAY_BUFFER_BINDING, &boundBuffer); /* * 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. */ GLint attrib0_enabled = 0; GLint attrib0_size = 0; GLint attrib0_stride = 0; GLint attrib0_type = 0; GLint attrib0_normalized = 0; GLint attrib0_bufferBinding = 0; void* attrib0_pointer = nullptr; mGL->fGetVertexAttribiv(0, LOCAL_GL_VERTEX_ATTRIB_ARRAY_ENABLED, &attrib0_enabled); mGL->fGetVertexAttribiv(0, LOCAL_GL_VERTEX_ATTRIB_ARRAY_SIZE, &attrib0_size); mGL->fGetVertexAttribiv(0, LOCAL_GL_VERTEX_ATTRIB_ARRAY_STRIDE, &attrib0_stride); mGL->fGetVertexAttribiv(0, LOCAL_GL_VERTEX_ATTRIB_ARRAY_TYPE, &attrib0_type); mGL->fGetVertexAttribiv(0, LOCAL_GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &attrib0_normalized); mGL->fGetVertexAttribiv(0, LOCAL_GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &attrib0_bufferBinding); mGL->fGetVertexAttribPointerv(0, LOCAL_GL_VERTEX_ATTRIB_ARRAY_POINTER, &attrib0_pointer); // Note that uniform values are program state, so we don't need to rebind those. ScopedGLState blend (mGL, LOCAL_GL_BLEND, false); ScopedGLState cullFace (mGL, LOCAL_GL_CULL_FACE, false); ScopedGLState depthTest (mGL, LOCAL_GL_DEPTH_TEST, false); ScopedGLState dither (mGL, LOCAL_GL_DITHER, false); ScopedGLState polyOffsFill(mGL, LOCAL_GL_POLYGON_OFFSET_FILL, false); ScopedGLState sampleAToC (mGL, LOCAL_GL_SAMPLE_ALPHA_TO_COVERAGE, false); ScopedGLState sampleCover (mGL, LOCAL_GL_SAMPLE_COVERAGE, false); ScopedGLState scissor (mGL, LOCAL_GL_SCISSOR_TEST, false); ScopedGLState stencil (mGL, LOCAL_GL_STENCIL_TEST, false); realGLboolean colorMask[4]; mGL->fGetBooleanv(LOCAL_GL_COLOR_WRITEMASK, colorMask); mGL->fColorMask(LOCAL_GL_TRUE, LOCAL_GL_TRUE, LOCAL_GL_TRUE, LOCAL_GL_TRUE); GLint viewport[4]; mGL->fGetIntegerv(LOCAL_GL_VIEWPORT, viewport); mGL->fViewport(0, 0, destSize.width, destSize.height); // Does destructive things to (only!) what we just saved above. bool good = UseTexQuadProgram(srcTarget, srcSize); if (!good) { // We're up against the wall, so bail. // This should really be MOZ_CRASH(why) or MOZ_RUNTIME_ASSERT(good). printf_stderr("[%s:%d] Fatal Error: Failed to prepare to blit texture->framebuffer.\n", __FILE__, __LINE__); MOZ_CRASH(); } mGL->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4); mGL->fViewport(viewport[0], viewport[1], viewport[2], viewport[3]); mGL->fColorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]); if (attrib0_enabled) mGL->fEnableVertexAttribArray(0); mGL->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, attrib0_bufferBinding); mGL->fVertexAttribPointer(0, attrib0_size, attrib0_type, attrib0_normalized, attrib0_stride, attrib0_pointer); mGL->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, boundBuffer); mGL->fUseProgram(boundProgram); }