How does OpenGL round off floats during viewport transformation?
This might sound trivial, but it's causing me some issues. I haven't been able to find any documentation about this.
How does OpenGL perform viewport transformation? At some point the normalized device coordinates get turned into viewport coordinates, which I presume is still expressed in floating point numbers. How does OpenGL convert these viewport 开发者_如何学编程coordinates to pixels on the screen? Does it floor? ceil? average?
And can this behavior be customized in any way?
How does OpenGL perform viewport transformation?
The OpenGL-3.1 specification defines this in Section 2.12. It's too long to quote here, just download the document from http://opengl.org and read for yourself.
AFAIK OpenGL doesn't specify a specific roundoff operation. OpenGL isn't pixel exact at all, so implementations are free to implement this however it suits them.
And can this behavior be customized in any way?
None I'm aware of. The best thing you could do is writing a vertex shader that transforms vertices in a way they end up on integer coordinates (+/- a small offset if floor or ceil is used) after the whole transformation chain.
精彩评论