|
|
|
|
The SciTech SNAP Graphics Architecture supports drawing on and copying video memory data to and from offscreen video memory and the display screen. Although the core functionality is provided via the SetDrawBuffer function, the SciTech SNAP Graphics Architecture also supports a higher level interface to video memory mangement via the Buffer Manager. The Buffer Manager functions are provided through the GA_bufferFuncs function group, and implement support for allocating, freeing, displaying and copying data to and from offscreen video memory buffers. The buffers can be allocated entirely in video memory, entirely in system memory or to fall back to system memory when video memory runs out. The buffers can also be allocated as fixed or moveable buffers in video memory, where moveable buffers can be moved around in video memory by the buffer manager to collect free video memory for future buffer allocations. Buffers can also be implemented as discardable buffers with a system memory buffer cache, such that non-critical buffers can be pushed out to system memory automatically when more video memory is needed.
Using the Buffer Manager is actually quite simple. The first thing to do is to allocate the primary display buffer along with a set number of ‘flippable’ buffers that can be made visible for page flipping and animation. This is done using the InitBuffers function, where you will pass in the total number of flippable buffers that you need. To display a flippable buffer and make it visible, you would pass a pointer to the buffer to the FlipToBuffer function (pointers to the flip buffers can be obtained using the GetFlippableBuffer function). By default after initializing the buffer manager, all drawing will go to the first buffer or ‘primary’ buffer in the flippable buffers list. To make another buffer active for drawing, the SetActiveBuffer function is used. After this function is called, all drawing using the functions in the GA_2DRenderFuncs function group will go to the newly active buffer.
Apart from flippable buffers, it is also possible to allocate arbitrary sized buffers in offscreen video memory using the AllocBuffer function. You can allocate buffers with many different types of attributes with dimensions smaller or larger than the current display mode (some hardware does not support offscreen buffers larger than the display mode though). Once you have allocated the buffers, you can use them just like flippable buffers in that you can draw on them and copy between them, you just can’t make them directly visible via the FlipToBuffer function.
Once you have allocated a buffer (whether it is a flippable buffer or a regular offscreen buffer), if you wish to directly access the video memory in the buffer, you must use the LockBuffer and UnlockBuffer functions. Once you have called the LockBuffer function, the Surface pointer of the GA_buf structure will point to a linear memory access that can be used to directly access the surface of the buffer. Prior to calling the LockBuffer function, the Surface pointer will be set to NULL (and will be reset to NULL after calling the UnlockBuffer function). The LockBuffer function also returns a physical memory address of the buffer in video memory, which can be used to program the video memory address into hardware DMA engines (note that not all drivers will support returning a physical memory address, and this will be 0 if not supported).
You can also directly copy data from any buffer to another buffer using the BitBltBuf and related functions. This allows you to copy data between any source buffer and the currently active buffer, with all features normally available in the hardware such as color key transparency, stretching, blending and more.
Note: Another reason to use the buffer manager is that internally the SciTech SNAP Graphics Architecture drivers may utilize the buffer manager when it is enabled to speed up some software rendering functions through partial hardware acceleration. Until the application or shell driver enables the buffer manager, that functionality will not be enabled and those functions will run entirely in software.
Also note that if you are using the DirectX SNAP driver on Microsoft Windows, you must use the buffer manager functions to manage offscreen video memory. Directly calling on this driver is not supported.
Copyright © 2002 SciTech Software, Inc. Visit our web site at http://www.scitechsoft.com