Difference Between Surface and Texture (SDL / General)

Can someone explain to me in simple words, what is the difference between texture and surface? I saw that it was used in SDL2 as SDL_Surface and SDL_Texture . SDL_Texture is created from SDL_Surface , which, in turn, is created from an image / raster image. Both are a collection of pixels. But I don’t see the main difference between the two (do you need to do something with the GPU?)

I tried to do this, but all the explanations I found were too complicated to understand without going into computer graphics.

+50
graphics sdl sdl-2
Jan 27 '14 at 22:10
source share
3 answers

Basically, your assumption "something needs to be done with the GPU"? is correct.

SDL_Surface used when rendering software. With software rendering, as saloomi2012 correctly noticed, you are using regular RAM to store image data. Thus, in most cases, you can directly access the data buffer associated with the surface, changing its contents, that is, use the CPU, therefore, the name of the software.

SDL_Texture , on the other hand, is used in hardware rendering, textures are stored in VRAM, and you do not have access to it directly, as with SDL_Surface . Rendering operations are accelerated using the GPU, using the internal OpenGL or DirectX interface (available only for Windows), which in turn uses your video hardware, hence the name of the hardware rendering.

Needless to say, hardware rendering is an order of magnitude faster than software rendering, and it should always be considered as the main option.

+54
Sep 30 '14 at 5:30
source share

SDL_Texture loaded into your VRAM instead of regular RAM.

+7
Aug 19 '14 at 2:59
source share

Surfaces use your RAM, and textures use your graphics card, which is faster than surfaces.

+1
Oct 14 '17 at 11:50
source share



All Articles