Back to main page

CPU surface

This collection was made for storing a copy of a draw surface that you need to access from both the graphics card and the CPU while you make small modifications.

Each CPU buffer has a staging buffer on the graphic card's memory and a vector array on the CPU's memory. Therefor, this way to read pixel data takes a lot of memory if you make a complete copy of a large draw surface.

int CPUSurface_CreateFixed(int newWidth, int newHeight, float Red, float Green, float Blue, float Alpha);

newWidth is the number of pixel columns.

newHeight is the number of pixel rows.

(Red,Green,Blue,Alpha) is the initial color.

0 < newWidth ≤ 8192, 0 < newHeight ≤ 8192

Returns the ID to the new CPU surface.

Creates a new CPU surface of dimensions newWidth * newHeight where each pixel has the color (Red,Green,Blue,Alpha).

void CPUSurface_Delete(int CPUSurface);

CPUSurface is a valid CPU surface.

The CPU surface refered to by CPUSurface is deleted.

int CPUSurface_GetWidth(int CPUSurface);

CPUSurface is a valid CPU surface.

The width of the CPU surface refered to by CPUSurface.

int CPUSurface_GetHeight(int CPUSurface);

CPUSurface is a valid CPU surface.

The height of the CPU surface refered to by CPUSurface.

void CPUSurface_FillWithColor(int CPUSurface, float Red, float Green, float Blue, float Alpha);

This method does exactly the same thing as DrawSurface_FillWithColor.

CPUSurface is a valid CPU surface.

All pixels in CPUSurface is set to the color (Red,Green,Blue,Alpha).

void CPUSurface_GetPixelColor_Clamped_OutV4(int CPUSurface, int X, int Y);

The content is stored in the interval [0..Width-1],[0..Height-1] and taking a pixel from outside will take the color from the closest pixel inside the bound.

CPUSurface is a valid CPU surface.

The RGBA color from CPUSurface at X,Y is stored in (X1,Y1,Z1,W1).

void CPUSurface_GetPixelColor_Border_OutV4(int CPUSurface, int X, int Y, float DefaultRed, float DefaultGreen, float DefaultBlue, float DefaultAlpha);

The content is stored in the interval [0..Width-1],[0..Height-1] and taking a pixel from outside will take the color that you gave as default.

CPUSurface is a valid CPU surface.

The RGBA color from CPUSurface at X,Y is stored in (X1,Y1,Z1,W1) but if X,Y is out of bound, (DefaultRed,DefaultGreen,DefaultBlue,DefaultAlpha) is written instead.

void CPUSurface_SetPixelColor_Ignore(int CPUSurface, int X, int Y, float Red, float Green, float Blue, float Alpha);

This method will set the pixel if X,Y is inside the bound and ignore any calls trying to set it out of bound.

CPUSurface is a valid CPU surface. If you want something to happend, X,Y must be inside the bound [0..Width-1],[0..Height-1].

If X,Y is inside the bound [0..Width-1],[0..Height-1], the RGBA color in CPUSurface at X,Y is set to (Red,Green,Blue,Alpha).

void CPUSurface_CopyRectFromDrawSurface(int Input_DrawSurface, int Output_CPUSurface, int SourceLeft, int SourceTop, int DestLeft, int DestTop, int Width, int Height);

This call is even slower than DrawSurface_GetPixelColor_OutV4 but don't have to be called every time you sample a pixel and is therefor much faster to use if you only copy modified regions of a draw surface.

CPUSurface is a valid CPU surface and the 2 rectangles for source and destination must be inside of the bounds.

A rectangle from [SourceLeft..SourceLeft + Width - 1],[SourceTop..SourceTop + Height - 1] in Input_DrawSurface is loaded to [DestLeft..DestLeft + Width - 1],[DestTop..DestTop + Height - 1] in Output_CPUSurface.