LOCKBUFFER

Top  Previous  Next

Syntax

INT = LOCKBUFFER(OPT buffer as POINTER)

Description

Locks a buffer into memory for multiple drawing operations or direct memory access.

Parameters

buffer - Optional. Can be one of BACKBUFFER (default), FRONTBUFFER or SPRITEBUFFER.

Return value

Returns the current lock count if the buffer could be locked or -1 on error. The lock count is incremented by 1 every time LOCKBUFFER is called and decremented by 1 every time UNLOCKBUFFER is called. If the lock count is greater then zero then this function simply returns the lockcount for performance reasons.

Remarks

Locking a buffer makes the video card memory directly accessible by your program for direct buffer manipulation. All drawing operations lock the buffer before performing any tasks on the buffer. Every call to LOCKBUFFER must be matched with a call to UNLOCKBUFFER.

Locking a buffer is a time expensive operation so drawing operations can be sped up by locking the buffer before performing many drawing operations at once and then unlocking the buffer before flipping to the display surface.

A locked buffer cannot be flipped, or blitted to so you cannot draw a sprite or image onto a locked buffer using standard commands. You should not keep a display buffer locked longer than the time it takes for one frame to be rendered or your program will suffer performance degradation.

Functions such as WritePixelFast require locking the buffer ahead of time before use.

Any Emergence BASIC window drawing commands will not work when a buffer is locked. For example the CIRCLE and ELLIPSE commands. This is because the Windows GDI requires an unlocked buffer to work with and performs a lock internally.

See Also: UNLOCKBUFFER

Example usage

LOCKBUFFER
    FOR y=0 to 599
        FOR x=0 to 799
            WritePixelFast(x,y,c)
        NEXT x
    NEXT y
UNLOCKBUFFER