问题
In the SDL wiki it says
Use this function to perform a fast blit from the source surface to the destination surface.
However that doesn't help me much.
What does the term surface blitting mean in this context?
回答1:
Basically it means copying the image from one surface to another -- possibly cropped and shifted.
回答2:
Blitting means bit-boundary block transfer as defined by Wikipedia or Block Information Transfer, well known among the Pygame developers. Assume you have a Surface(your screen). And you would like to draw a circle on the screen. So what you want to do is, draw the circle and transfer the circle block of the buffer to the screen buffer, this process is called "Blitting". You can go ahead and read more about Blit here.
回答3:
It copies memory from one place in memory (source) to another place in memory (destination).
Eg. It can copy the pixels from one bitmap to another, from a bitmap to texture, or any of the above to the screen's surface or the screen's back buffer surface.
Say you have an image/tile that you want to display on the screen. You would perform a "blit" to copy the memory making up the image to the memory that is used on the screen.
It is, essentially, calling a function very much similar to memcpy() which copies the bytes specified as the source one-by-one to the bytes specified as the destination.
回答4:
Official code sample
Intuitively, it means to "draw a sprite on top of another surface".
This operation can be GPU accelerated with SDL_Texture
+ SDL_RenderCopy
.
Have a look at http://hg.libsdl.org/SDL/file/e12c38730512/test/testsprite2.c for an example, in particular the comment:
/* Blit the sprite onto the screen */
SDL_RenderCopy(renderer, sprite, NULL, position);
which explicitly says that SDL_RenderCopy
is a way to blit.
In that example, the texture is created and sent to the GPU memory only once, and from then on it is reused efficiently, see also: Difference between surface and texture (SDL / general)
When I run this example on Ubuntu 15.10, nvidia-settings
says that GPU usage is goes to 100%, and I get a much higher FPS than by drawing pixel by pixel to the screen, so it is GPU accelerated.
来源:https://stackoverflow.com/questions/3700610/what-is-a-blit-in-sdl