void DrawingBuffer::reset(const IntSize& newSize) { if (!m_context) return; IntSize adjustedSize; bool evictContext = false; bool isNewContext = m_size.isEmpty(); if (s_allowContextEvictionOnCreate && isNewContext) adjustedSize = adjustSizeWithContextEviction(newSize, evictContext); else adjustedSize = adjustSize(newSize); if (adjustedSize.isEmpty()) return; if (evictContext) m_contextEvictionManager->forciblyLoseOldestContext("WARNING: WebGL contexts have exceeded the maximum allowed backbuffer area. Oldest context will be lost."); if (adjustedSize != m_size) { do { // resize multisample FBO if (!resizeMultisampleFramebuffer(adjustedSize) || !resizeFramebuffer(adjustedSize)) { adjustedSize.scale(s_resourceAdjustedRatio); continue; } break; } while (!adjustedSize.isEmpty()); setSize(adjustedSize); if (adjustedSize.isEmpty()) return; } m_context->disable(GL_SCISSOR_TEST); m_context->clearColor(0, 0, 0, 0); m_context->colorMask(true, true, true, true); GLbitfield clearMask = GL_COLOR_BUFFER_BIT; if (m_attributes.depth) { m_context->clearDepth(1.0f); clearMask |= GL_DEPTH_BUFFER_BIT; m_context->depthMask(true); } if (m_attributes.stencil) { m_context->clearStencil(0); clearMask |= GL_STENCIL_BUFFER_BIT; m_context->stencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); } clearFramebuffers(clearMask); }
bool DrawingBuffer::reset(const IntSize& newSize) { ASSERT(!newSize.isEmpty()); IntSize adjustedSize = adjustSize(newSize, m_size, m_maxTextureSize); if (adjustedSize.isEmpty()) return false; if (adjustedSize != m_size) { do { if (!resizeDefaultFramebuffer(adjustedSize)) { adjustedSize.scale(s_resourceAdjustedRatio); continue; } break; } while (!adjustedSize.isEmpty()); setSize(adjustedSize); if (adjustedSize.isEmpty()) return false; } m_gl->Disable(GL_SCISSOR_TEST); m_gl->ClearColor(0, 0, 0, defaultBufferRequiresAlphaChannelToBePreserved() ? 1 : 0); m_gl->ColorMask(true, true, true, true); GLbitfield clearMask = GL_COLOR_BUFFER_BIT; if (!!m_depthStencilBuffer) { m_gl->ClearDepthf(1.0f); clearMask |= GL_DEPTH_BUFFER_BIT; m_gl->DepthMask(true); } if (!!m_depthStencilBuffer) { m_gl->ClearStencil(0); clearMask |= GL_STENCIL_BUFFER_BIT; m_gl->StencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); } clearFramebuffers(clearMask); return true; }
bool DrawingBuffer::reset(const IntSize& newSize) { if (!m_context) return false; m_context->makeContextCurrent(); int maxTextureSize = 0; m_context->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &maxTextureSize); if (newSize.height() > maxTextureSize || newSize.width() > maxTextureSize) { clear(); return false; } int pixelDelta = newSize.width() * newSize.height(); int oldSize = 0; if (!m_size.isEmpty()) { oldSize = m_size.width() * m_size.height(); pixelDelta -= oldSize; } IntSize adjustedSize = newSize; if (s_maximumResourceUsePixels) { while ((s_currentResourceUsePixels + pixelDelta) > s_maximumResourceUsePixels) { adjustedSize.scale(s_resourceAdjustedRatio); if (adjustedSize.isEmpty()) { clear(); return false; } pixelDelta = adjustedSize.width() * adjustedSize.height(); pixelDelta -= oldSize; } } const GraphicsContext3D::Attributes& attributes = m_context->getContextAttributes(); if (adjustedSize != m_size) { unsigned internalColorFormat, colorFormat, internalRenderbufferFormat; if (attributes.alpha) { internalColorFormat = GraphicsContext3D::RGBA; colorFormat = GraphicsContext3D::RGBA; internalRenderbufferFormat = Extensions3D::RGBA8_OES; } else { internalColorFormat = GraphicsContext3D::RGB; colorFormat = GraphicsContext3D::RGB; internalRenderbufferFormat = Extensions3D::RGB8_OES; } do { m_size = adjustedSize; // resize multisample FBO if (multisample()) { int maxSampleCount = 0; m_context->getIntegerv(Extensions3D::MAX_SAMPLES, &maxSampleCount); int sampleCount = std::min(4, maxSampleCount); m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO); m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_multisampleColorBuffer); m_context->getExtensions()->renderbufferStorageMultisample(GraphicsContext3D::RENDERBUFFER, sampleCount, internalRenderbufferFormat, m_size.width(), m_size.height()); m_context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::RENDERBUFFER, m_multisampleColorBuffer); resizeDepthStencil(sampleCount); if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) { adjustedSize.scale(s_resourceAdjustedRatio); continue; } } // resize regular FBO m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_colorBuffer); m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE, 0); m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_colorBuffer, 0); // resize the front color buffer if (m_separateFrontTexture) { m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_frontColorBuffer); m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE, 0); } m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0); if (!multisample()) resizeDepthStencil(0); if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) == GraphicsContext3D::FRAMEBUFFER_COMPLETE) break; adjustedSize.scale(s_resourceAdjustedRatio); } while (!adjustedSize.isEmpty()); pixelDelta = m_size.width() * m_size.height(); pixelDelta -= oldSize; s_currentResourceUsePixels += pixelDelta; if (!newSize.isEmpty() && adjustedSize.isEmpty()) { clear(); return false; } } m_context->disable(GraphicsContext3D::SCISSOR_TEST); m_context->clearColor(0, 0, 0, 0); m_context->colorMask(true, true, true, true); GC3Dbitfield clearMask = GraphicsContext3D::COLOR_BUFFER_BIT; if (attributes.depth) { m_context->clearDepth(1.0f); clearMask |= GraphicsContext3D::DEPTH_BUFFER_BIT; m_context->depthMask(true); } if (attributes.stencil) { m_context->clearStencil(0); clearMask |= GraphicsContext3D::STENCIL_BUFFER_BIT; m_context->stencilMaskSeparate(GraphicsContext3D::FRONT, 0xFFFFFFFF); } clearFramebuffers(clearMask); return true; }
void DrawingBuffer::reset(const IntSize& newSize) { if (!m_context) return; IntSize adjustedSize; bool evictContext = false; bool isNewContext = m_size.isEmpty(); if (s_allowContextEvictionOnCreate && isNewContext) adjustedSize = adjustSizeWithContextEviction(newSize, evictContext); else adjustedSize = adjustSize(newSize); if (adjustedSize.isEmpty()) return; if (evictContext) m_contextEvictionManager->forciblyLoseOldestContext("WARNING: WebGL contexts have exceeded the maximum allowed backbuffer area. Oldest context will be lost."); if (adjustedSize != m_size) { do { // resize multisample FBO if (!resizeMultisampleFramebuffer(adjustedSize) || !resizeFramebuffer(adjustedSize)) { adjustedSize.scale(s_resourceAdjustedRatio); continue; } #if OS(DARWIN) // FIXME: This can be removed once renderbufferStorageMultisample starts reporting GL_OUT_OF_MEMORY properly on OSX. if (!checkBufferIntegrity()) { adjustedSize.scale(s_resourceAdjustedRatio); continue; } #endif break; } while (!adjustedSize.isEmpty()); setSize(adjustedSize); if (adjustedSize.isEmpty()) return; } m_context->disable(GraphicsContext3D::SCISSOR_TEST); m_context->clearColor(0, 0, 0, 0); m_context->colorMask(true, true, true, true); GC3Dbitfield clearMask = GraphicsContext3D::COLOR_BUFFER_BIT; if (m_attributes.depth) { m_context->clearDepth(1.0f); clearMask |= GraphicsContext3D::DEPTH_BUFFER_BIT; m_context->depthMask(true); } if (m_attributes.stencil) { m_context->clearStencil(0); clearMask |= GraphicsContext3D::STENCIL_BUFFER_BIT; m_context->stencilMaskSeparate(GraphicsContext3D::FRONT, 0xFFFFFFFF); } clearFramebuffers(clearMask); }