Fix OpenGL render target binding composition
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "XCEngine/RHI/RHIRenderPass.h"
|
||||
#include "XCEngine/RHI/RHIFramebuffer.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLDevice.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLResourceView.h"
|
||||
#include <glad/glad.h>
|
||||
|
||||
using namespace XCEngine::RHI;
|
||||
@@ -363,6 +364,145 @@ TEST_P(RHITestFixture, CommandList_SetRenderTargets_WithRealViews) {
|
||||
delete texture;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandList_SetRenderTargets_BindsColorAndDepthAttachmentsOnOpenGL) {
|
||||
if (GetBackendType() != RHIType::OpenGL) {
|
||||
GTEST_SKIP() << "OpenGL-specific framebuffer attachment verification";
|
||||
}
|
||||
|
||||
TextureDesc colorDesc = {};
|
||||
colorDesc.width = 128;
|
||||
colorDesc.height = 128;
|
||||
colorDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||||
colorDesc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
||||
|
||||
TextureDesc depthDesc = {};
|
||||
depthDesc.width = 128;
|
||||
depthDesc.height = 128;
|
||||
depthDesc.format = static_cast<uint32_t>(Format::D24_UNorm_S8_UInt);
|
||||
depthDesc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
||||
|
||||
RHITexture* colorTexture = GetDevice()->CreateTexture(colorDesc);
|
||||
RHITexture* depthTexture = GetDevice()->CreateTexture(depthDesc);
|
||||
ASSERT_NE(colorTexture, nullptr);
|
||||
ASSERT_NE(depthTexture, nullptr);
|
||||
|
||||
ResourceViewDesc colorViewDesc = {};
|
||||
colorViewDesc.format = colorDesc.format;
|
||||
RHIResourceView* rtv = GetDevice()->CreateRenderTargetView(colorTexture, colorViewDesc);
|
||||
|
||||
ResourceViewDesc depthViewDesc = {};
|
||||
depthViewDesc.format = depthDesc.format;
|
||||
RHIResourceView* dsv = GetDevice()->CreateDepthStencilView(depthTexture, depthViewDesc);
|
||||
ASSERT_NE(rtv, nullptr);
|
||||
ASSERT_NE(dsv, nullptr);
|
||||
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->SetRenderTargets(1, &rtv, dsv);
|
||||
|
||||
GLint framebuffer = 0;
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &framebuffer);
|
||||
EXPECT_NE(framebuffer, 0);
|
||||
EXPECT_EQ(glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER), GL_FRAMEBUFFER_COMPLETE);
|
||||
|
||||
GLint colorAttachment = 0;
|
||||
glGetFramebufferAttachmentParameteriv(
|
||||
GL_DRAW_FRAMEBUFFER,
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
|
||||
&colorAttachment);
|
||||
EXPECT_EQ(static_cast<GLuint>(colorAttachment), static_cast<OpenGLResourceView*>(rtv)->GetTexture());
|
||||
|
||||
GLint depthAttachment = 0;
|
||||
glGetFramebufferAttachmentParameteriv(
|
||||
GL_DRAW_FRAMEBUFFER,
|
||||
GL_DEPTH_ATTACHMENT,
|
||||
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
|
||||
&depthAttachment);
|
||||
EXPECT_EQ(static_cast<GLuint>(depthAttachment), static_cast<OpenGLResourceView*>(dsv)->GetTexture());
|
||||
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
delete dsv;
|
||||
delete rtv;
|
||||
depthTexture->Shutdown();
|
||||
delete depthTexture;
|
||||
colorTexture->Shutdown();
|
||||
delete colorTexture;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandList_SetRenderTargets_BindsMultipleColorAttachmentsOnOpenGL) {
|
||||
if (GetBackendType() != RHIType::OpenGL) {
|
||||
GTEST_SKIP() << "OpenGL-specific multiple render target verification";
|
||||
}
|
||||
|
||||
TextureDesc texDesc = {};
|
||||
texDesc.width = 128;
|
||||
texDesc.height = 128;
|
||||
texDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||||
texDesc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
||||
|
||||
RHITexture* texture0 = GetDevice()->CreateTexture(texDesc);
|
||||
RHITexture* texture1 = GetDevice()->CreateTexture(texDesc);
|
||||
ASSERT_NE(texture0, nullptr);
|
||||
ASSERT_NE(texture1, nullptr);
|
||||
|
||||
ResourceViewDesc viewDesc = {};
|
||||
viewDesc.format = texDesc.format;
|
||||
RHIResourceView* rtv0 = GetDevice()->CreateRenderTargetView(texture0, viewDesc);
|
||||
RHIResourceView* rtv1 = GetDevice()->CreateRenderTargetView(texture1, viewDesc);
|
||||
ASSERT_NE(rtv0, nullptr);
|
||||
ASSERT_NE(rtv1, nullptr);
|
||||
|
||||
RHIResourceView* rtvs[] = { rtv0, rtv1 };
|
||||
|
||||
CommandListDesc cmdDesc = {};
|
||||
cmdDesc.commandListType = static_cast<uint32_t>(CommandQueueType::Direct);
|
||||
RHICommandList* cmdList = GetDevice()->CreateCommandList(cmdDesc);
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
cmdList->Reset();
|
||||
cmdList->SetRenderTargets(2, rtvs, nullptr);
|
||||
|
||||
GLint framebuffer = 0;
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &framebuffer);
|
||||
EXPECT_NE(framebuffer, 0);
|
||||
EXPECT_EQ(glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER), GL_FRAMEBUFFER_COMPLETE);
|
||||
|
||||
GLint colorAttachment0 = 0;
|
||||
glGetFramebufferAttachmentParameteriv(
|
||||
GL_DRAW_FRAMEBUFFER,
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
|
||||
&colorAttachment0);
|
||||
EXPECT_EQ(static_cast<GLuint>(colorAttachment0), static_cast<OpenGLResourceView*>(rtv0)->GetTexture());
|
||||
|
||||
GLint colorAttachment1 = 0;
|
||||
glGetFramebufferAttachmentParameteriv(
|
||||
GL_DRAW_FRAMEBUFFER,
|
||||
GL_COLOR_ATTACHMENT1,
|
||||
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
|
||||
&colorAttachment1);
|
||||
EXPECT_EQ(static_cast<GLuint>(colorAttachment1), static_cast<OpenGLResourceView*>(rtv1)->GetTexture());
|
||||
|
||||
cmdList->Close();
|
||||
|
||||
cmdList->Shutdown();
|
||||
delete cmdList;
|
||||
delete rtv1;
|
||||
delete rtv0;
|
||||
texture1->Shutdown();
|
||||
delete texture1;
|
||||
texture0->Shutdown();
|
||||
delete texture0;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, CommandList_CopyResource_WithRealResources) {
|
||||
TextureDesc texDesc = {};
|
||||
texDesc.width = 256;
|
||||
|
||||
Reference in New Issue
Block a user