DrawingBuffer::TextureInfo DrawingBuffer::createDefaultTextureAndAllocateMemory(const IntSize& size) { TextureParameters parameters = defaultTextureParameters(); GLuint textureId = createColorTexture(parameters); texImage2DResourceSafe(parameters.target, 0, parameters.creationInternalColorFormat, size.width(), size.height(), 0, parameters.colorFormat, GL_UNSIGNED_BYTE); DrawingBuffer::TextureInfo info; info.textureId = textureId; info.parameters = parameters; return info; }
unsigned DrawingBuffer::createColorTexture(const IntSize& size) { if (!m_context) return 0; unsigned offscreenColorTexture = m_context->createTexture(); if (!offscreenColorTexture) return 0; m_context->bindTexture(GL_TEXTURE_2D, offscreenColorTexture); m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); if (!size.isEmpty()) texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, size.width(), size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); return offscreenColorTexture; }
PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::recycledMailbox() { if (!m_context || m_recycledMailboxes.isEmpty()) return PassRefPtr<MailboxInfo>(); RefPtr<MailboxInfo> mailboxInfo = m_recycledMailboxes.last().release(); m_recycledMailboxes.removeLast(); if (mailboxInfo->mailbox.syncPoint) { m_context->waitSyncPoint(mailboxInfo->mailbox.syncPoint); mailboxInfo->mailbox.syncPoint = 0; } if (mailboxInfo->size != m_size) { m_context->bindTexture(GL_TEXTURE_2D, mailboxInfo->textureId); texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, m_size.width(), m_size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); mailboxInfo->size = m_size; } return mailboxInfo.release(); }
void DrawingBuffer::resizeTextureMemory(TextureInfo* info, const IntSize& size) { ASSERT(info->textureId); if (info->imageId) { deleteChromiumImageForTexture(info); info->imageId = m_gl->CreateGpuMemoryBufferImageCHROMIUM(size.width(), size.height(), info->parameters.creationInternalColorFormat, GC3D_SCANOUT_CHROMIUM); if (info->imageId) { m_gl->BindTexture(info->parameters.target, info->textureId); m_gl->BindTexImage2DCHROMIUM(info->parameters.target, info->imageId); clearChromiumImageAlpha(*info); return; } // If the desired texture target is different, there's no way to fall back // to a non CHROMIUM_image texture. if (chromiumImageTextureParameters().target != defaultTextureParameters().target) return; } m_gl->BindTexture(info->parameters.target, info->textureId); texImage2DResourceSafe(info->parameters.target, 0, info->parameters.creationInternalColorFormat, size.width(), size.height(), 0, info->parameters.colorFormat, GL_UNSIGNED_BYTE); }
bool DrawingBuffer::resizeFramebuffer(const IntSize& size) { // resize regular FBO m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); m_context->bindTexture(GL_TEXTURE_2D, m_colorBuffer); texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, size.width(), size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); if (m_multisampleMode == ImplicitResolve) m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_colorBuffer, 0, m_sampleCount); else m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_colorBuffer, 0); m_context->bindTexture(GL_TEXTURE_2D, 0); if (m_multisampleMode != ExplicitResolve) resizeDepthStencil(size); if (m_context->checkFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) return false; return true; }