0

There are many GDI functions, such as SetPixel(), but it is very expensive to set each pixel to a certain color, so I wonder what function does the library use.

Searched the SDL2 source code, didn't find the drawing function.

genpfault
  • 51,148
  • 11
  • 85
  • 139
MY-97
  • 1
  • 1
    Build SDL2 in debug mode, then debug the drawing function. – HolyBlackCat Apr 22 '23 at 09:18
  • 1
    SDL uses the Direct3D api on Windows. Which takes care of software rendering by itself. Also available directly: https://learn.microsoft.com/en-us/windows/win32/direct3darticles/directx-warp – Hans Passant Apr 22 '23 at 09:29
  • SDL's graphics subsystem is just a wrapper around the graphics API of the underlying OS. That means, depending on OS, it can use OpenGL, Vulkan, Metal or Direct3D. On Windows, it uses Direct3D. – jtxkopt Apr 22 '23 at 12:49

1 Answers1

1

Searched the SDL2 source code, didn't find the drawing function.

You mean this one? As you can see, SDL2's software renderer just works with surfaces like SDL1 did, and a SDL_RenderCopy roughly translates to a SDL_BlitSurface.

SDL_BlitSurface is an alias for SDL_UpperBlit, which calls SDL_LowerBlit, which calls src->map->blit, which can be many things but might be for example SDL_BlitCopy, and that finally does the copying of pixels. Of course pixels aren't set one by one manually. Well, unless you use SDL_RenderDrawPoints (that translates to SDL_DrawPoints for a software renderer).

Nelfeal
  • 12,593
  • 1
  • 20
  • 39