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 = {};
|
2026-03-24 23:00:49 +08:00
|
|
|
desc.windowHandle = GetWindowHandle();
|
2026-03-22 16:18:51 +08:00
|
|
|
desc.width = 800;
|
|
|
|
|
desc.height = 600;
|
|
|
|
|
desc.bufferCount = 2;
|
2026-03-24 23:00:49 +08:00
|
|
|
desc.format = Format::R8G8B8A8_UNorm;
|
2026-03-22 16:18:51 +08:00
|
|
|
|
|
|
|
|
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 = {};
|
2026-03-24 23:00:49 +08:00
|
|
|
desc.windowHandle = GetWindowHandle();
|
2026-03-22 16:18:51 +08:00
|
|
|
desc.width = 800;
|
|
|
|
|
desc.height = 600;
|
|
|
|
|
desc.bufferCount = 2;
|
2026-03-24 23:00:49 +08:00
|
|
|
desc.format = Format::R8G8B8A8_UNorm;
|
2026-03-22 16:18:51 +08:00
|
|
|
|
|
|
|
|
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 = {};
|
2026-03-24 23:00:49 +08:00
|
|
|
desc.windowHandle = GetWindowHandle();
|
2026-03-22 16:18:51 +08:00
|
|
|
desc.width = 800;
|
|
|
|
|
desc.height = 600;
|
|
|
|
|
desc.bufferCount = 2;
|
2026-03-24 23:00:49 +08:00
|
|
|
desc.format = Format::R8G8B8A8_UNorm;
|
2026-03-22 16:18:51 +08:00
|
|
|
|
|
|
|
|
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 = {};
|
2026-03-24 23:00:49 +08:00
|
|
|
desc.windowHandle = GetWindowHandle();
|
2026-03-22 16:18:51 +08:00
|
|
|
desc.width = 800;
|
|
|
|
|
desc.height = 600;
|
|
|
|
|
desc.bufferCount = 2;
|
2026-03-24 23:00:49 +08:00
|
|
|
desc.format = Format::R8G8B8A8_UNorm;
|
2026-03-22 16:18:51 +08:00
|
|
|
|
|
|
|
|
RHISwapChain* swapChain = GetDevice()->CreateSwapChain(desc);
|
|
|
|
|
ASSERT_NE(swapChain, nullptr);
|
|
|
|
|
|
|
|
|
|
swapChain->Resize(1024, 768);
|
|
|
|
|
|
|
|
|
|
swapChain->Shutdown();
|
|
|
|
|
delete swapChain;
|
|
|
|
|
}
|