Fix OpenGL integration tests for new SwapChain API

- triangle/quad/sphere tests: Update to use new Initialize signature with OpenGLDevice*
- triangle/quad/sphere tests: Use GetGLContext() for RenderDoc SetDevice
- triangle/quad/sphere tests: Add wglMakeCurrent in render loop
- triangle/quad/sphere tests: Update capture timing to frame 25-35
- unit test fixture: Add GetDevice() method
- unit test swap_chain: Update to use new Initialize signature
This commit is contained in:
2026-03-23 21:48:46 +08:00
parent 89d13a4ae4
commit 5267c61c2c
5 changed files with 77 additions and 52 deletions

View File

@@ -86,12 +86,18 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
RenderDocCapture::Get().SetCaptureFilePath(".\\triangle_frame30");
OpenGLDevice device;
if (!device.InitializeWithExistingWindow(hwnd)) {
RHIDeviceDesc desc = {};
desc.windowHandle = hwnd;
desc.width = gWidth;
desc.height = gHeight;
desc.appName = L"OpenGL_Triangle_Test";
desc.enableDebugLayer = true;
if (!device.Initialize(desc)) {
Log("[ERROR] Failed to initialize OpenGL device");
return -1;
}
RenderDocCapture::Get().SetDevice(device.GetContext());
RenderDocCapture::Get().SetDevice(device.GetGLContext());
ShowWindow(hwnd, nShowCmd);
UpdateWindow(hwnd);
@@ -100,7 +106,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
Log("[INFO] OpenGL Version: %S", device.GetDeviceInfo().version.c_str());
OpenGLSwapChain swapChain;
swapChain.Initialize(hwnd, gWidth, gHeight);
swapChain.Initialize(&device, hwnd, gWidth, gHeight);
OpenGLCommandList commandList;
@@ -168,9 +174,10 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
MSG msg = {};
int frameCount = 0;
const int targetFrameCount = 30;
const int captureStartFrame = 25;
const int captureEndFrame = 35;
while (frameCount < targetFrameCount) {
while (frameCount < captureEndFrame) {
if (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT) {
break;
@@ -178,6 +185,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
TranslateMessage(&msg);
DispatchMessageW(&msg);
} else {
wglMakeCurrent(device.GetPresentationDC(), device.GetGLContext());
commandList.SetViewport(0, 0, gWidth, gHeight);
commandList.Clear(0.0f, 0.0f, 1.0f, 1.0f, 1);
@@ -185,24 +194,23 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
vertexArray.Bind();
commandList.Draw(PrimitiveType::Triangles, 3, 0);
if (frameCount >= targetFrameCount - 1) {
if (RenderDocCapture::Get().BeginCapture("OpenGL_Triangle_Test")) {
Log("[INFO] RenderDoc capture started");
}
}
swapChain.Present(0, 0);
frameCount++;
if (frameCount >= targetFrameCount) {
if (RenderDocCapture::Get().EndCapture()) {
Log("[INFO] RenderDoc capture ended");
}
if (frameCount == captureStartFrame) {
RenderDocCapture::Get().BeginCapture("OpenGL_Triangle_Test");
Log("[INFO] RenderDoc capture started at frame %d", frameCount);
}
if (frameCount == captureEndFrame) {
RenderDocCapture::Get().EndCapture();
Log("[INFO] RenderDoc capture ended at frame %d", frameCount);
break;
}
}
}
Log("[INFO] Reached target frame count %d - taking screenshot!", targetFrameCount);
Log("[INFO] Capture complete - taking screenshot!");
OpenGLScreenshot::Capture(device, swapChain, "triangle.ppm");
vertexArray.Shutdown();