From d238bb67a52a6b940dd8299675c368230d2c7064 Mon Sep 17 00:00:00 2001 From: Jiawei Shao Date: Thu, 3 Jan 2019 00:07:44 +0000 Subject: [PATCH] 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 Reviewed-by: Kai Ninomiya Commit-Queue: Jiawei Shao --- src/dawn_native/opengl/CommandBufferGL.cpp | 10 ++++++++-- src/tests/end2end/TextureViewTests.cpp | 3 +-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/dawn_native/opengl/CommandBufferGL.cpp b/src/dawn_native/opengl/CommandBufferGL.cpp index 6602db879b..d0761852b6 100644 --- a/src/dawn_native/opengl/CommandBufferGL.cpp +++ b/src/dawn_native/opengl/CommandBufferGL.cpp @@ -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; diff --git a/src/tests/end2end/TextureViewTests.cpp b/src/tests/end2end/TextureViewTests.cpp index 1ba98b659d..470ed9f6ec 100644 --- a/src/tests/end2end/TextureViewTests.cpp +++ b/src/tests/end2end/TextureViewTests.cpp @@ -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)