OpenGL: Add test documentation for minimal integration test
- Create TEST_SPEC.md with OpenGL test hierarchy and specifications - Add section and inline comments to main.cpp explaining: - Window size calculation with AdjustWindowRect - glFinish before screenshot for GPU sync - Target frame count warm-up period - Shutdown order (reverse of initialization)
This commit is contained in:
@@ -77,12 +77,14 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
||||
}
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
|
||||
// Initialize logger
|
||||
Logger::Get().Initialize();
|
||||
Logger::Get().AddSink(std::make_unique<ConsoleLogSink>());
|
||||
Logger::Get().SetMinimumLevel(LogLevel::Debug);
|
||||
|
||||
Log("[INFO] OpenGL Integration Test Starting");
|
||||
|
||||
// Register window class
|
||||
WNDCLASSEXW wc = {};
|
||||
wc.cbSize = sizeof(WNDCLASSEXW);
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||
@@ -95,9 +97,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Calculate full window size from client area size
|
||||
RECT rect = { 0, 0, gWidth, gHeight };
|
||||
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
|
||||
|
||||
// Create window
|
||||
HWND hwnd = CreateWindowExW(
|
||||
0,
|
||||
L"XCEngine_OpenGL_Test",
|
||||
@@ -113,6 +117,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Initialize OpenGL device with existing window
|
||||
OpenGLDevice device;
|
||||
if (!device.InitializeWithExistingWindow(hwnd)) {
|
||||
Log("[ERROR] Failed to initialize OpenGL device");
|
||||
@@ -122,12 +127,15 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
ShowWindow(hwnd, nShowCmd);
|
||||
UpdateWindow(hwnd);
|
||||
|
||||
// Log OpenGL device info
|
||||
Log("[INFO] OpenGL Device: %S", device.GetDeviceInfo().renderer.c_str());
|
||||
Log("[INFO] OpenGL Version: %S", device.GetDeviceInfo().version.c_str());
|
||||
|
||||
// Create swap chain for rendering
|
||||
OpenGLSwapChain swapChain;
|
||||
swapChain.Initialize(hwnd, gWidth, gHeight);
|
||||
|
||||
// Main render loop
|
||||
MSG msg = {};
|
||||
int frameCount = 0;
|
||||
const int targetFrameCount = 30;
|
||||
@@ -140,21 +148,27 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessageW(&msg);
|
||||
} else {
|
||||
// Set viewport and clear color for each frame
|
||||
glViewport(0, 0, gWidth, gHeight);
|
||||
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Present the rendered frame
|
||||
swapChain.Present(0, 0);
|
||||
frameCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// Take screenshot after target frame count is reached
|
||||
// glFinish ensures all OpenGL commands are completed before reading pixels
|
||||
Log("[INFO] Reached target frame count %d - taking screenshot!", targetFrameCount);
|
||||
SaveScreenshotPPM("minimal.ppm", gWidth, gHeight);
|
||||
|
||||
// Shutdown in reverse order of initialization
|
||||
swapChain.Shutdown();
|
||||
device.Shutdown();
|
||||
Logger::Get().Shutdown();
|
||||
|
||||
Log("[INFO] OpenGL Integration Test Finished");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user