This section tells you how to do two things:
- How to render to multiple windows
- How to render to a texture
Initially, it may seem that these subjects are unrelated. However, in Panda, rendering to a texture consists of three basic steps:
- Create a hidden window.
- Render into the hidden window.
- Transfer the contents of the hidden window into a texture.
So clearly, in order to render to texture, you first need to know how to create additional windows and how to render into them.
When I say Panda can "transfer" the contents of a window into a texture, I don't necessarily mean "copy." There are other ways to transfer the contents of a window into a texture that may be faster. For example, if the OpenGL implementation supports the ARB_pbuffers extension, then the transfer might be achieved using wglBindTexImageARB. The Panda user does not need to worry about how the transfer is done. It is only important that you know that Panda will use the fastest means available to transfer the contents of the window into a texture.
The panda rendering loop can be summarized as follows:
for each window (hidden or otherwise):
clear the window (usually)
render all appropriate content into the window
if the window has an associated texture:
transfer contents of window into a texture
|
The windows have a sort value that controls the order in which the loop processes them. The texture gathered from the first window can be used when rendering the second window, and so forth.
Earlier, I said that to render to a texture, you have to create a hidden window. In fact, that isn't strictly true - the window doesn't have to be hidden. You can transfer the contents of any window, hidden or not, into a texture. That's potentially useful - for example, you can transfer the contents of the main window into a texture, which you can then use when rendering the next frame. This can be used to create interesting motion-blur effects.
Panda has two different classes to represent hidden and non-hidden windows. Visible windows are of class GraphicsWindow. Hidden ones are of class GraphicsBuffer. Both have almost exactly the same API.
Some video cards aren't powerful enough to create a GraphicsBuffer. For instance, an OpenGL implementation cannot create a GraphicsBuffer unless it supports the ARB_pbuffers extension. Fortunately, Panda provides an emulation mechanism that lets you simulate a GraphicsBuffer even if the video card can't create one. This emulation mechanism is called the ParasiteBuffer. A parasite buffer acts in most ways like a GraphicsBuffer. You can use it to render to texture, just like you would a GraphicsBuffer. However, the ParasiteBuffer doesn't actually contain its own framebuffer - it borrows the framebuffer from some other window (usually the main window). Therefore, using a parasite buffer has the side effect of trashing the contents of the main window. That usually isn't a problem - since the parasite buffers are usually rendered before the main window, the main window usually doesn't contain anything yet anyhow. In this way, a machine with no special hardware can render to texture.
Throughout this section, when I use the word "window," I mean either a visible window (a GraphicsWindow), a hidden window (a GraphicsBuffer), or an emulated hidden window (a ParasiteBuffer). All three of these have the same API. They all inherit their API from a general class GraphicsOutput that represents "anything that you can render into."
|