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

@@ -90,12 +90,18 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
RenderDocCapture::Get().SetCaptureFilePath(".\\quad_frame30");
OpenGLDevice device;
if (!device.InitializeWithExistingWindow(hwnd)) {
RHIDeviceDesc desc = {};
desc.windowHandle = hwnd;
desc.width = gWidth;
desc.height = gHeight;
desc.appName = L"OpenGL_Quad_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);
@@ -104,7 +110,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;
@@ -190,9 +196,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;
@@ -200,6 +207,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);
@@ -211,24 +220,23 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
commandList.Draw(PrimitiveType::TriangleStrip, 4, 0);
if (frameCount >= targetFrameCount - 1) {
if (RenderDocCapture::Get().BeginCapture("OpenGL_Quad_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_Quad_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, "quad.ppm");
sampler.Shutdown();

View File

@@ -169,12 +169,18 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
RenderDocCapture::Get().SetCaptureFilePath(".\\sphere_frame30");
OpenGLDevice device;
if (!device.InitializeWithExistingWindow(hwnd)) {
RHIDeviceDesc desc = {};
desc.windowHandle = hwnd;
desc.width = gWidth;
desc.height = gHeight;
desc.appName = L"OpenGL_Sphere_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);
@@ -183,7 +189,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;
@@ -299,10 +305,11 @@ 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;
int renderCount = 0;
while (frameCount < targetFrameCount) {
while (frameCount < captureEndFrame) {
if (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT) {
break;
@@ -310,6 +317,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
TranslateMessage(&msg);
DispatchMessageW(&msg);
} else {
wglMakeCurrent(device.GetPresentationDC(), device.GetGLContext());
renderCount++;
GLenum err = glGetError();
if (err != GL_NO_ERROR) Log("[DEBUG] GL error before clear: 0x%x", err);
@@ -336,25 +345,24 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
commandList.DrawIndexed(PrimitiveType::Triangles, (uint32_t)indices.size(), 0, 0);
if (frameCount >= targetFrameCount - 1) {
if (RenderDocCapture::Get().BeginCapture("OpenGL_Sphere_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_Sphere_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] Rendered %d frames (target was %d)", renderCount, targetFrameCount);
Log("[INFO] Reached target frame count %d - taking screenshot!", targetFrameCount);
Log("[INFO] Rendered %d frames (capture was %d-%d)", renderCount, captureStartFrame, captureEndFrame);
Log("[INFO] Capture complete - taking screenshot!");
char exePath[MAX_PATH];
GetModuleFileNameA(NULL, exePath, MAX_PATH);

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();

View File

@@ -17,6 +17,7 @@ protected:
HWND GetWindow() { return m_hwnd; }
HDC GetDC() { return m_hdc; }
HGLRC GetContext() { return m_hglrc; }
OpenGLDevice* GetDevice() { return m_device; }
void MakeContextCurrent();
void DoneContextCurrent();

View File

@@ -7,7 +7,7 @@ TEST_F(OpenGLTestFixture, SwapChain_Initialize_Window) {
OpenGLSwapChain swapChain;
HWND window = GetWindow();
bool result = swapChain.Initialize(window, 800, 600);
bool result = swapChain.Initialize(GetDevice(), window, 800, 600);
ASSERT_TRUE(result);
@@ -17,7 +17,7 @@ TEST_F(OpenGLTestFixture, SwapChain_Initialize_Window) {
TEST_F(OpenGLTestFixture, SwapChain_Present) {
OpenGLSwapChain swapChain;
HWND window = GetWindow();
swapChain.Initialize(window, 800, 600);
swapChain.Initialize(GetDevice(), window, 800, 600);
swapChain.Present();
@@ -30,7 +30,7 @@ TEST_F(OpenGLTestFixture, SwapChain_Present) {
TEST_F(OpenGLTestFixture, SwapChain_Resize_ChangesSize) {
OpenGLSwapChain swapChain;
HWND window = GetWindow();
swapChain.Initialize(window, 800, 600);
swapChain.Initialize(GetDevice(), window, 800, 600);
swapChain.Resize(1024, 768);