fix: simplify RenderDocCapture usage with TriggerCapture

- Remove BeginCapture/EndCapture complexity for manual frame capture
- Use TriggerCapture for single frame capture (simpler API)
- Move TriggerCapture before Present to ensure frame is captured
- Add SetForegroundWindow/SetFocus before TriggerCapture
- Remove default capture path in Initialize to allow SetCaptureFilePath to work
This commit is contained in:
2026-03-23 19:40:50 +08:00
parent 067c82c3a9
commit 79422cfddd
3 changed files with 28 additions and 65 deletions

View File

@@ -86,13 +86,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
return -1;
}
// Initialize RenderDoc capture (MUST be before OpenGL init)
// For OpenGL: device=nullptr (will be set via SetDevice), window=hwnd
if (!RenderDocCapture::Get().Initialize(nullptr, hwnd)) {
Log("[WARNING] Failed to initialize RenderDoc, frame capture will not be available");
} else {
RenderDocCapture::Get().SetCaptureFilePath(".\\minimal_frame30");
}
RenderDocCapture::Get().Initialize(nullptr, hwnd);
RenderDocCapture::Get().SetCaptureFilePath(".\\minimal_frame30");
// Initialize OpenGL device with existing window
OpenGLDevice device;
@@ -101,8 +96,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
return -1;
}
// Set device for RenderDoc (must be called after OpenGL init)
// For OpenGL, device pointer must be HGLRC, not HDC!
RenderDocCapture::Get().SetDevice(device.GetContext());
ShowWindow(hwnd, nShowCmd);
@@ -132,35 +125,21 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
TranslateMessage(&msg);
DispatchMessageW(&msg);
} else {
if (frameCount == targetFrameCount - 1) {
wglMakeCurrent(device.GetDC(), device.GetContext());
if (RenderDocCapture::Get().BeginCapture("OpenGL_Minimal_Test")) {
Log("[INFO] RenderDoc capture started at frame %d", frameCount + 1);
} else {
Log("[ERROR] Failed to start RenderDoc capture");
}
}
wglMakeCurrent(device.GetDC(), device.GetContext());
// Set viewport and clear color using encapsulated command list
commandList.SetViewport(0, 0, gWidth, gHeight);
commandList.Clear(1.0f, 0.0f, 0.0f, 1.0f, 1 | 2);
// Present the rendered frame
if (frameCount >= targetFrameCount - 1) {
RenderDocCapture::Get().TriggerCapture();
Log("[INFO] RenderDoc capture triggered");
}
swapChain.Present(0, 0);
frameCount++;
if (frameCount >= targetFrameCount) {
if (RenderDocCapture::Get().EndCapture()) {
Log("[INFO] RenderDoc capture ended, NumCaptures: %u", RenderDocCapture::Get().GetNumCaptures());
if (RenderDocCapture::Get().GetNumCaptures() > 0) {
RenderDocCaptureInfo info;
if (RenderDocCapture::Get().GetCapture(0, &info)) {
Log("[INFO] Capture file: %s (%u bytes)", info.filename, info.length);
}
}
} else {
Log("[ERROR] Failed to end RenderDoc capture");
}
break;
}
}
}