Support using a layer of a texture as a color attachment on OpenGL

This patch implements using a layer of a texture as a color attachment
on OpenGL by using glFramebufferTextureLayer. As WebGPU won't support
rendering into a texture view whose format is different from the
original texture, it is correct to use glFramebufferTexture on the
OpenGL backends.

BUG=dawn:16

Change-Id: Iab6d905ee119bb9bb2d1bb212134cf757483c4d4
Reviewed-on: https://dawn-review.googlesource.com/c/3560
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Jiawei Shao 2019-01-03 00:07:44 +00:00 committed by Commit Bot service account
parent 5dee56f39c
commit d238bb67a5
2 changed files with 9 additions and 4 deletions

View File

@ -488,8 +488,14 @@ namespace dawn_native { namespace opengl {
GLuint texture = ToBackend(textureView->GetTexture())->GetHandle();
// Attach color buffers.
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D,
texture, 0);
if (textureView->GetTexture()->GetArrayLayers() == 1) {
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
GL_TEXTURE_2D, texture, textureView->GetBaseMipLevel());
} else {
glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
texture, textureView->GetBaseMipLevel(),
textureView->GetBaseArrayLayer());
}
drawBuffers[i] = GL_COLOR_ATTACHMENT0 + i;
attachmentCount = i + 1;

View File

@ -631,5 +631,4 @@ TEST_P(TextureViewRenderingTest, Texture2DArrayViewOnALayerOf2DArrayTextureAsCol
DAWN_INSTANTIATE_TEST(TextureViewSamplingTest, D3D12Backend, MetalBackend, OpenGLBackend, VulkanBackend)
// TODO(jiawei.shao@intel.com): support using a layer of a texture as color attachment on OpenGL
DAWN_INSTANTIATE_TEST(TextureViewRenderingTest, D3D12Backend, MetalBackend, VulkanBackend)
DAWN_INSTANTIATE_TEST(TextureViewRenderingTest, D3D12Backend, MetalBackend, OpenGLBackend, VulkanBackend)