OpenGL: refactor FramebufferTexture* calls.
Change-Id: Iee67027431d791d6425e0cc502f6b6a23bc160d6 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/85141 Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Stephen White <senorblanco@chromium.org>
This commit is contained in:
parent
1e627e23f3
commit
fd41f30c0b
|
@ -390,35 +390,15 @@ namespace dawn::native::opengl {
|
||||||
gl.GenFramebuffers(1, &writeFbo);
|
gl.GenFramebuffers(1, &writeFbo);
|
||||||
}
|
}
|
||||||
|
|
||||||
const TextureBase* colorTexture =
|
TextureView* colorView = ToBackend(renderPass->colorAttachments[i].view.Get());
|
||||||
renderPass->colorAttachments[i].view->GetTexture();
|
|
||||||
ASSERT(colorTexture->IsMultisampledTexture());
|
|
||||||
ASSERT(colorTexture->GetArrayLayers() == 1);
|
|
||||||
ASSERT(renderPass->colorAttachments[i].view->GetBaseMipLevel() == 0);
|
|
||||||
|
|
||||||
GLuint colorHandle = ToBackend(colorTexture)->GetHandle();
|
|
||||||
gl.BindFramebuffer(GL_READ_FRAMEBUFFER, readFbo);
|
gl.BindFramebuffer(GL_READ_FRAMEBUFFER, readFbo);
|
||||||
gl.FramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
colorView->BindToFramebuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0);
|
||||||
ToBackend(colorTexture)->GetGLTarget(), colorHandle, 0);
|
|
||||||
|
|
||||||
const TextureBase* resolveTexture =
|
TextureView* resolveView =
|
||||||
renderPass->colorAttachments[i].resolveTarget->GetTexture();
|
ToBackend(renderPass->colorAttachments[i].resolveTarget.Get());
|
||||||
GLuint resolveTextureHandle = ToBackend(resolveTexture)->GetHandle();
|
|
||||||
GLuint resolveTargetMipmapLevel =
|
|
||||||
renderPass->colorAttachments[i].resolveTarget->GetBaseMipLevel();
|
|
||||||
gl.BindFramebuffer(GL_DRAW_FRAMEBUFFER, writeFbo);
|
gl.BindFramebuffer(GL_DRAW_FRAMEBUFFER, writeFbo);
|
||||||
if (resolveTexture->GetArrayLayers() == 1) {
|
resolveView->BindToFramebuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0);
|
||||||
gl.FramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
|
||||||
GL_TEXTURE_2D, resolveTextureHandle,
|
|
||||||
resolveTargetMipmapLevel);
|
|
||||||
} else {
|
|
||||||
GLuint resolveTargetArrayLayer =
|
|
||||||
renderPass->colorAttachments[i].resolveTarget->GetBaseArrayLayer();
|
|
||||||
gl.FramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
|
||||||
resolveTextureHandle, resolveTargetMipmapLevel,
|
|
||||||
resolveTargetArrayLayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
gl.BlitFramebuffer(0, 0, renderPass->width, renderPass->height, 0, 0,
|
gl.BlitFramebuffer(0, 0, renderPass->width, renderPass->height, 0, 0,
|
||||||
renderPass->width, renderPass->height, GL_COLOR_BUFFER_BIT,
|
renderPass->width, renderPass->height, GL_COLOR_BUFFER_BIT,
|
||||||
GL_NEAREST);
|
GL_NEAREST);
|
||||||
|
@ -889,21 +869,11 @@ namespace dawn::native::opengl {
|
||||||
ColorAttachmentIndex attachmentCount(uint8_t(0));
|
ColorAttachmentIndex attachmentCount(uint8_t(0));
|
||||||
for (ColorAttachmentIndex i :
|
for (ColorAttachmentIndex i :
|
||||||
IterateBitSet(renderPass->attachmentState->GetColorAttachmentsMask())) {
|
IterateBitSet(renderPass->attachmentState->GetColorAttachmentsMask())) {
|
||||||
TextureViewBase* textureView = renderPass->colorAttachments[i].view.Get();
|
TextureView* textureView = ToBackend(renderPass->colorAttachments[i].view.Get());
|
||||||
GLuint texture = ToBackend(textureView->GetTexture())->GetHandle();
|
|
||||||
|
|
||||||
GLenum glAttachment = GL_COLOR_ATTACHMENT0 + static_cast<uint8_t>(i);
|
GLenum glAttachment = GL_COLOR_ATTACHMENT0 + static_cast<uint8_t>(i);
|
||||||
|
|
||||||
// Attach color buffers.
|
// Attach color buffers.
|
||||||
if (textureView->GetTexture()->GetArrayLayers() == 1) {
|
textureView->BindToFramebuffer(GL_DRAW_FRAMEBUFFER, glAttachment);
|
||||||
GLenum target = ToBackend(textureView->GetTexture())->GetGLTarget();
|
|
||||||
gl.FramebufferTexture2D(GL_DRAW_FRAMEBUFFER, glAttachment, target, texture,
|
|
||||||
textureView->GetBaseMipLevel());
|
|
||||||
} else {
|
|
||||||
gl.FramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, glAttachment, texture,
|
|
||||||
textureView->GetBaseMipLevel(),
|
|
||||||
textureView->GetBaseArrayLayer());
|
|
||||||
}
|
|
||||||
drawBuffers[i] = glAttachment;
|
drawBuffers[i] = glAttachment;
|
||||||
attachmentCount = i;
|
attachmentCount = i;
|
||||||
attachmentCount++;
|
attachmentCount++;
|
||||||
|
@ -911,8 +881,7 @@ namespace dawn::native::opengl {
|
||||||
gl.DrawBuffers(static_cast<uint8_t>(attachmentCount), drawBuffers.data());
|
gl.DrawBuffers(static_cast<uint8_t>(attachmentCount), drawBuffers.data());
|
||||||
|
|
||||||
if (renderPass->attachmentState->HasDepthStencilAttachment()) {
|
if (renderPass->attachmentState->HasDepthStencilAttachment()) {
|
||||||
TextureViewBase* textureView = renderPass->depthStencilAttachment.view.Get();
|
TextureView* textureView = ToBackend(renderPass->depthStencilAttachment.view.Get());
|
||||||
GLuint texture = ToBackend(textureView->GetTexture())->GetHandle();
|
|
||||||
const Format& format = textureView->GetTexture()->GetFormat();
|
const Format& format = textureView->GetTexture()->GetFormat();
|
||||||
|
|
||||||
// Attach depth/stencil buffer.
|
// Attach depth/stencil buffer.
|
||||||
|
@ -927,15 +896,7 @@ namespace dawn::native::opengl {
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (textureView->GetTexture()->GetArrayLayers() == 1) {
|
textureView->BindToFramebuffer(GL_DRAW_FRAMEBUFFER, glAttachment);
|
||||||
GLenum target = ToBackend(textureView->GetTexture())->GetGLTarget();
|
|
||||||
gl.FramebufferTexture2D(GL_DRAW_FRAMEBUFFER, glAttachment, target, texture,
|
|
||||||
textureView->GetBaseMipLevel());
|
|
||||||
} else {
|
|
||||||
gl.FramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, glAttachment, texture,
|
|
||||||
textureView->GetBaseMipLevel(),
|
|
||||||
textureView->GetBaseArrayLayer());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -586,4 +586,19 @@ namespace dawn::native::opengl {
|
||||||
return mTarget;
|
return mTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextureView::BindToFramebuffer(GLenum target, GLenum attachment) {
|
||||||
|
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl;
|
||||||
|
|
||||||
|
// Use the texture's handle and target, and the view's base mip level and base array layer
|
||||||
|
GLuint handle = ToBackend(GetTexture())->GetHandle();
|
||||||
|
GLuint textarget = ToBackend(GetTexture())->GetGLTarget();
|
||||||
|
GLuint mipLevel = GetBaseMipLevel();
|
||||||
|
|
||||||
|
if (textarget == GL_TEXTURE_2D_ARRAY || textarget == GL_TEXTURE_3D) {
|
||||||
|
gl.FramebufferTextureLayer(target, attachment, handle, mipLevel, GetBaseArrayLayer());
|
||||||
|
} else {
|
||||||
|
gl.FramebufferTexture2D(target, attachment, textarget, handle, mipLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dawn::native::opengl
|
} // namespace dawn::native::opengl
|
||||||
|
|
|
@ -54,6 +54,7 @@ namespace dawn::native::opengl {
|
||||||
|
|
||||||
GLuint GetHandle() const;
|
GLuint GetHandle() const;
|
||||||
GLenum GetGLTarget() const;
|
GLenum GetGLTarget() const;
|
||||||
|
void BindToFramebuffer(GLenum target, GLenum attachment);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
~TextureView() override;
|
~TextureView() override;
|
||||||
|
|
Loading…
Reference in New Issue