C++ – How would you unit-test or perform the most effective automated testing on graphics code for OpenGL

cgraphicsopengltest-automationunit testing

I'm writing a game and the accompanying graphics engine on top of OpenGL in C++. Im also a fan of good coding processes and automated testing. Graphics code + testing seems pretty immiscible, since the output is often visual only, or very heavily visual-oriented.

For example, imagine analyzing the raw image-stream that is rendered to the screen byte-by-byte – you need test-data to compare with, which is hard to create/obtain, and often the rendered images aren't identical on a byte level when running at different times – small changes in algorithms will wreck this approach completely.

I'm thinking of creating a visual unit-test suite, in which I can basically render different test-scenes, showing stuff like shadow mapping, animation, etc etc etc. As part of CI, these scenes would then be rendered to a video file (or possibly leave it as a executable) with different metrics. This would still require manual inspection of the video file, but atleast it would be somewhat automated and standardised.

What do you think? I'm hoping there are better ways?

Best Answer

The opencv image processing library does it by saving the image and comparing it to a reference image - it has a bunch of c++ test functions and macros to handle approximate image matching etc.

Related Topic