Is there a standard way, using only OpenGL functions, to obtain the size of the backbuffer, in pixels? The closest I’ve found is querying the size of the viewport, but I doubt it always matches the backbuffer size. I’m looking for the maximum width and height values I can supply to glReadPixels, for example.
Share
The backbuffer is part of the window framebuffer planes set (front color, back color, depth, stencil, etc. depending on what’s been configured). Since they all belong together they all have the same dimensions. Since the standard framebuffer is tied to the visible window the accessible part is determined by the window dimensions.
However there’s one important thing to be aware of: A window’s framebuffer is (or used to be) just a slice of the screen framebuffer. If the window is moved or resized only the offset and the stride of the slice in the screen framebuffer changes. It also means that if the window is (partially) obstructed by another window, the occluded parts of the window don’t contribute to the framebuffer. Reading from a framebuffer partially covered by other windows you may end up with either undefined contents there, or the contents of the occluding window.
On modern operating systems windows are rendered into off screen areas which can not be occluded, to support compositing window management.