I build and installed mesa, an open-source implementation of OpenGL on Linux and windows platform. Actually, I only need several APIs of OpenGL(mesa), and need to write unit tests for the APIs. Does anyone knows how to write unit tests for OpenGL? Give me a sample. Or Is there any existed framework for OpenGL unit tests?
Asked
Active
Viewed 648 times
-1
-
1Possible duplicate of: [http://stackoverflow.com/q/3221451/416574](http://stackoverflow.com/q/3221451/416574) – pstrjds Jul 25 '12 at 02:56
-
OpenGL uses a lot of floats to process vertices you want to draw, from the vertices themselves to projection and transformation matrices. Floating point determinism becomes a huge issue that can cause very minor changes in the rendered frame. Between graphics cards, drivers versions, CPUs, and even compiler versions there's a chance you'll get slightly different results. Plus it's very hard to unit test a small section of the OpenGL API without having to use the rest of it to set up the unit test. – Robert Rouhani Jul 25 '12 at 04:01
-
My most concern is how to verify my unit tests result.e.g,glClear API,after I invoke the function, I have no idea how to verify the result. – leon_ALiang Jul 25 '12 at 04:39
-
The only way you can do that is to call swapbuffers, which stalls the thread until all OpenGL commands are processed, (commands typically get queued up instead of immediately completed, except maybe on some really old GPUs from the early 90s) then read back the frame's pixel values with `glReadPixels` and compare them to an expected image. With `glClear` you're going to get pretty consistent results, except if color/gamma settings affect OpenGL framebuffers and not just monitor output. And there's probably several other factors that I haven't taken into consideration. – Robert Rouhani Jul 25 '12 at 05:22
-
1When you get to actual drawing, you'll see that setting up and tearing down unit tests is ridiculous. If you manage to get it working, updating compilers or drivers can invalidate the expected images and all your unit tests will fail. Unit testing OpenGL when you're making a game or other 3d app is like unit testing your browser when you want to build a website. There are minor discrepancies between browser rendering engines but you don't unit test them, you just view the site on different browsers and see if anything's wrong, then fix it. – Robert Rouhani Jul 25 '12 at 05:34
1 Answers
1
Or Is there any existed framework for OpenGL unit tests?
"Piglit is a collection of automated tests for OpenGL implementations."

genpfault
- 51,148
- 11
- 85
- 139