2026-03-22 16:18:51 +08:00
|
|
|
#include "fixtures/RHITestFixture.h"
|
|
|
|
|
#include "XCEngine/RHI/RHISwapChain.h"
|
|
|
|
|
|
|
|
|
|
using namespace XCEngine::RHI;
|
|
|
|
|
|
2026-03-23 19:17:32 +08:00
|
|
|
TEST_P(RHITestFixture, SwapChain_Create) {
|
2026-03-22 16:18:51 +08:00
|
|
|
SwapChainDesc desc = {};
|
|
|
|
|
desc.width = 800;
|
|
|
|
|
desc.height = 600;
|
|
|
|
|
desc.bufferCount = 2;
|
|
|
|
|
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
|
|
|
desc.refreshRate = 60;
|
|
|
|
|
desc.sampleCount = 1;
|
|
|
|
|
desc.sampleQuality = 0;
|
|
|
|
|
desc.swapEffect = 0;
|
|
|
|
|
desc.flags = 0;
|
|
|
|
|
|
|
|
|
|
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
|
|
|
|
ASSERT_NE(swapChain, nullptr);
|
|
|
|
|
|
|
|
|
|
swapChain->Shutdown();
|
|
|
|
|
delete swapChain;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 19:17:32 +08:00
|
|
|
TEST_P(RHITestFixture, SwapChain_GetCurrentBackBufferIndex) {
|
2026-03-22 16:18:51 +08:00
|
|
|
SwapChainDesc desc = {};
|
|
|
|
|
desc.width = 800;
|
|
|
|
|
desc.height = 600;
|
|
|
|
|
desc.bufferCount = 2;
|
|
|
|
|
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
|
|
|
|
|
|
|
|
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
|
|
|
|
ASSERT_NE(swapChain, nullptr);
|
|
|
|
|
|
|
|
|
|
uint32_t index = swapChain->GetCurrentBackBufferIndex();
|
|
|
|
|
EXPECT_LT(index, 2u);
|
|
|
|
|
|
|
|
|
|
swapChain->Shutdown();
|
|
|
|
|
delete swapChain;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 19:17:32 +08:00
|
|
|
TEST_P(RHITestFixture, SwapChain_GetCurrentBackBuffer) {
|
2026-03-22 16:18:51 +08:00
|
|
|
SwapChainDesc desc = {};
|
|
|
|
|
desc.width = 800;
|
|
|
|
|
desc.height = 600;
|
|
|
|
|
desc.bufferCount = 2;
|
|
|
|
|
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
|
|
|
|
|
|
|
|
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
|
|
|
|
ASSERT_NE(swapChain, nullptr);
|
|
|
|
|
|
|
|
|
|
RHITexture* backBuffer = swapChain->GetCurrentBackBuffer();
|
|
|
|
|
EXPECT_NE(backBuffer, nullptr);
|
|
|
|
|
|
|
|
|
|
swapChain->Shutdown();
|
|
|
|
|
delete swapChain;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 19:17:32 +08:00
|
|
|
TEST_P(RHITestFixture, SwapChain_Resize) {
|
2026-03-22 16:18:51 +08:00
|
|
|
SwapChainDesc desc = {};
|
|
|
|
|
desc.width = 800;
|
|
|
|
|
desc.height = 600;
|
|
|
|
|
desc.bufferCount = 2;
|
|
|
|
|
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
|
|
|
|
|
|
|
|
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
|
|
|
|
ASSERT_NE(swapChain, nullptr);
|
|
|
|
|
|
|
|
|
|
swapChain->Resize(1024, 768);
|
|
|
|
|
|
|
|
|
|
swapChain->Shutdown();
|
|
|
|
|
delete swapChain;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 19:17:32 +08:00
|
|
|
TEST_P(RHITestFixture, SwapChain_FullscreenState) {
|
2026-03-22 16:18:51 +08:00
|
|
|
SwapChainDesc desc = {};
|
|
|
|
|
desc.width = 800;
|
|
|
|
|
desc.height = 600;
|
|
|
|
|
desc.bufferCount = 2;
|
|
|
|
|
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
|
|
|
|
|
|
|
|
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
|
|
|
|
ASSERT_NE(swapChain, nullptr);
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(swapChain->IsFullscreen());
|
|
|
|
|
swapChain->SetFullscreen(true);
|
|
|
|
|
EXPECT_TRUE(swapChain->IsFullscreen());
|
|
|
|
|
swapChain->SetFullscreen(false);
|
|
|
|
|
|
|
|
|
|
swapChain->Shutdown();
|
|
|
|
|
delete swapChain;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 19:17:32 +08:00
|
|
|
TEST_P(RHITestFixture, SwapChain_ShouldClose) {
|
2026-03-22 16:18:51 +08:00
|
|
|
SwapChainDesc desc = {};
|
|
|
|
|
desc.width = 800;
|
|
|
|
|
desc.height = 600;
|
|
|
|
|
desc.bufferCount = 2;
|
|
|
|
|
desc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
|
|
|
|
|
|
|
|
|
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
|
|
|
|
ASSERT_NE(swapChain, nullptr);
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(swapChain->ShouldClose());
|
|
|
|
|
swapChain->SetShouldClose(true);
|
|
|
|
|
EXPECT_TRUE(swapChain->ShouldClose());
|
|
|
|
|
|
|
|
|
|
swapChain->Shutdown();
|
|
|
|
|
delete swapChain;
|
|
|
|
|
}
|