|
LockBuffer | ||
LockBuffer | ||
Parameters: NONE | ||
Returns: NONE | ||
LockBuffer lets us lock the current graphics buffer. Which can be either the Screen or an Image. When graphics are drawn, PlayBASIC can not simply start placing pixels on the screen immediately, Windows unfortunately does not allow it! So before PB can draw anything, the surface were drawing to (screen or image) has to be locked. Once it is, the graphics are then drawn and the surface is unlocked again. (see: UnLockBuffer This is necessary to ensure that windows doesn't decide to move/alter our screen/image memory while were drawing to it. This is possible as your computer is running many programs at the one time, not just our game. A nasty by product of this constant Locking and Unlocking process, is that valuable drawing time can be wasted. As It can take some time for Windows to Lock/Unlock a surface. So what LockBuffer does, is place you in control of the buffer lock/unlocking process in regards to most drawing operations. By controlling the buffer locking/unlocking process yourself, you can reduce the impact of locking/unlocking has upon certainly types of drawing. This can be particularly effective when you need to draw a batch of graphical elements like dot's for example. Without manual control over locking, every time we draw DOT, the buffer is locked/ the dot is drawn, and then it's unlocked again. All the locking/unlocking really adds up. However if you control the locking yourself, then PB only has to lock and unlock the surface once, regardless of how many dots are drawn. If you look at the example bellow, this can give a very handy speed up. Once you have finishing drawing, you must unlock the buffer again by using the UnLockBuffer command. Failing to do so will not doubt result in your program crashing. So some care is needed ! But, make sure that you UNLOCK the buffer later. Failing to do so will most likely crash your program. So some care is needed ! FACTS: * If you enable LockBuffer, PlayBASIC will expect you to handle the UnLocking of this buffer manually. See UnLockBuffer. * LockBuffer can be used when rendering to either the Screen or an Image. It most likely won't as noticeable effect when drawing to FX images though. * The following operations will generally benefit from you manually controlling the buffer locking. Ie. Dot, Line, Box, Circle,Tri, DrawImage/DrawSprite (When rendering FX images to a video surface) etc * While most GFX operations benefit from Locking the buffer, some don't. Some may even not render at all! (Print,Text generally don't like it rendering to locked buffers) * Locking and Unlocking the current buffer will NOT improve the speed of captured drawing. * Note: We highly recommended you read the Images tutorials also! Mini Tutorial: This example times (in milliseconds) how long it takes to draw 1000 dots to the screen with and without the lockbuffer commands.
Note: These results are from my Duron 800mhz system. The times will vary from system to system.
|
Related Info: | Box | Circle | Dot | DrawImage | DRawShape | DrawSprite | FastDot | Images | Line | PixelRunLength | Quad | Tri | UnLockBuffer : |
|
|||||||||||||||||||||||||||||||||||||||
(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com |