Contents |
|
Methods of Rendering to Texture Surfaces
Rendering directly to
textured surfaces.
A number of
the popular consumer 3D graphics accelerators released in the past year or
two support rendering directly to texture surfaces. When available, this
is generally the fastest method for implementing this technique. No extra
copying is necessary and redundant surfaces aren't needed.
The basic procedure is as follows:
Rendering to a second, non-texture surface and then blitting
to a texture. This
approach creates a DirectDraw surface which is identical in size to the
texture surface, but is created with the DDSCAPS_3DDEVICE flag (but
without the DDSCAPS_TEXTURE flag).. After that, the steps are similar,
except that the SetRenderTarget() method is used to point the device to
the intermediate surface. Then, a blit must be done, following the
EndScene(), to copy the rendered scene to the texture surface. This will
work on some hardware that won't support the previous method because some
hardware, in order to increase performance, rearranges the data in texture
surfaces into a format that is more friendly to the graphics chip's texel
cache. This is often referred to as a swizzled texture. The rendering
device cannot render triangles to this surface type, but it can handle
blitting from one type to another. Rendering to the back buffer and then blitting a subsection
to a texture surface.
Note that if you are using Direct3D's
texture manager, textures that are going to be rendered to cannot use
the texture manager. They must be created specifying the memory type
(usually localvidmem, as few cards can render to AGP surfaces). It is
best to do this before invoking the texture manger, so that the texture
manager will know how much memory it has left over to work with.
This method uses less memory than the last method, but it can require an extra clearing of the back buffer. All rendering is done to the back buffer, but there are two BeginScene/EndScene pairs per frame, one for the scene to be rendered to the texture and one for the scene to be rendered to the back buffer.
Software rendering to a system memory surface and blitting that to the texture surface.
This approach, while fairly straight forward, should be avoided for obvious reasons (in case it's not obvious, software rendering is slow. We'd prefer to use the 3D hardware to do it). If you have to rely on this method, consider ways to scale back the quality of the effect, such as reducing the texture surface's resolution.
An example of handling some of these fallback methods can be found in The TESTRTT sample code