What is a Blit in SDL?

别来无恙 提交于 2019-12-03 22:32:34
Radomir Dopieralski

Basically it means copying the image from one surface to another -- possibly cropped and shifted.

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.

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.

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!