Accessing Surface Memory Directly


Surface memory can be accessed directly by using the Surface.LockRectangle method. When this method is called, the rect parameter is a reference to a Rectangle Leave Site structure that describes the rectangle on the surface to access directly. To request that the entire surface be locked, either call one of the Surface.LockRectangle overloads that do not take a Rectangle Leave Site structure, or set the rect parameter to the dimensions of the entire surface. It is also possible to specify a Rectangle Leave Site that covers only a portion of the surface. Providing that no two rectangles overlap, two threads or processes can simultaneously lock multiple rectangles in a surface. Note that a multisample back buffer cannot be locked.

Depending on which Surface.LockRectangle method overload is called, the method returns either a GraphicsStream object or an Array Leave Site that describes the locked region. The method call returns the pitch value in the pitch parameter. When access to the surface memory is finished, the Surface.UnlockRectangle method should be called to unlock it.

While a surface is locked, its contents can be manipulated directly. The following list provides some tips for avoiding common problems associated with directly rendering surface memory.


Send comments about this topic to Microsoft. © Microsoft Corporation. All rights reserved.

Feedback? Please provide us with your comments on this topic.
For more help, visit the DirectX Developer Center