[QUERY] Implementation of SDL_RenderPresent : SDL2

Hi,
May I know how SDL_RenderPresent is implemented/coded?

Is the implementation of SDL2 closed source?

I tried looking at the definitions but all it shows is the following.

I’m modifying my question a bit.

How do I statically link SDL2 into my project so I don’t have to refer to the individual files just to read what each function does?

Thank you very much.

Edit: You have to get the Source code, find a file called “SDL_render.c”. I added the cutout in the comments.

  • Update the screen with any rendering performed since the previous call.
  • SDL’s rendering functions operate on a backbuffer; that is, calling a
  • rendering function such as SDL_RenderDrawLine() does not directly put a
  • line on the screen, but rather updates the backbuffer. As such, you compose
  • your entire scene and present the composed backbuffer to the screen as a
  • complete picture.
  • Therefore, when using SDL’s rendering API, one does all drawing intended
  • for the frame, and then calls this function once per frame to present the
  • final drawing to the user.
  • The backbuffer should be considered invalidated after each present; do not
  • assume that previous contents will exist between frames. You are strongly
  • encouraged to call SDL_RenderClear() to initialize the backbuffer before
  • starting each new frame’s drawing, even if you plan to overwrite every
  • pixel.
  • \param renderer the rendering context
  • \sa SDL_RenderClear
  • \sa SDL_RenderDrawLine
  • \sa SDL_RenderDrawLines
  • \sa SDL_RenderDrawPoint
  • \sa SDL_RenderDrawPoints
  • \sa SDL_RenderDrawRect
  • \sa SDL_RenderDrawRects
  • \sa SDL_RenderFillRect
  • \sa SDL_RenderFillRects
  • \sa SDL_SetRenderDrawBlendMode
  • \sa SDL_SetRenderDrawColor
    */
    extern DECLSPEC void SDLCALL SDL_RenderPresent(SDL_Renderer * renderer);"

This is the implementation of SDL_RenderPresent from "SDL_render.c"

void
SDL_RenderPresent(SDL_Renderer * renderer)
{
CHECK_RENDERER_MAGIC(renderer, );

FlushRenderCommands(renderer);  /* time to send everything to the GPU! */

#if DONT_DRAW_WHILE_HIDDEN
/* Don’t present while we’re hidden */
if (renderer->hidden) {
return;
}
#endif

renderer->RenderPresent(renderer);

}

RenderPresent() is implemented in render backends code:

For example here is D3D version:

Hi @DJm00n, did I use the wrong file?

Is it not supposed to be “SDL_render.c”?

The code looks different.

The idea behind SDL is to take away the hard and complicated task of writing code for multiple sets of hardware across platforms. If you have it set up correctly you shouldn’t need to know how anything is implemented or access any SDL source code. It’s not a good idea to statically link SDL2 because you are denying your end-users access to future bug-fixes and performance improvements that come with new DLLs.

Knowing the implementation is quite important actually.

Imagine if I define a function called doesSomething(char something);*.

Then, I tell everyone just use doesSomething().

Does anyone even know what it does?

Do you even know where or how to use it?

How do you debug it when somethine goes wrong?

There isn’t even a Wiki entry on its implementation.

At the very least, create an implementation Wiki so that developers know its implementation and you can update your DLLs.

Hiding the implementation in the DLLs will just lead to more problems.

I forgot to tag you and Discourse doesn’t allow me to edit my earlier post (only the OP)

How many times have you needed to see the source code of printf(), or memcpy()? I never have. We only need to know what they do so we can focus on using them. If you want to know how they do what they do then it sounds like a strange hobby. Abstraction means you can be more productive.

The only time you’ll want to look into the source code is to fix a bug. I’ve been using SDL for many years, maybe 15 years and even I don’t dig around in the source code when there’s a bug - I leave that to the main devs who know more about how it all works under the surface. I try to point them in the right direction of the bug.

It seems SDL2 is not the tool you are looking for if you are wanting to look at the source code to know how it works, but in contrast to that you want a YouTube video to help you understand it? I’d love to help guide you to what you want to achieve, but it’s difficult to understand what you’re looking for at this stage.

1 Like

At least once.

The default tutorial is to open up and read what printf() does.

Why do you want to hide the source code?

If you’re not the developer of SDL2, why do you care if other developers want to read the source code?

SDL2 doesn’t belong to you, it’s not your tool.

If SDL2 source code can’t be read, then SDL2 is closed source instead.

I disagree. Information hiding implies that you don’t need to know anything about the implementation.

Your argument is absurd. There are multitudes of closed source libraries out there that beg to differ.

Besides, SDL is not closed source and nothing is preventing you from reading the source. The entirety of SDL_Renderer is an abstraction over many backends. Thats the entire reason for it existing.

If its a problem with SDL, open an issue on github. You’re free to build SDL any way you want and debug it yourself too.

Did you miss it?

SDL supports a lot of different platforms. As an example, you cannot have the DX11 backend included in the builds for Mac or Linux. You have to abstract these out to separate implementations.

Are you the developer of SDL2?

Are you developing any games with SDL2?

I’ll have to do that.

Thanks.

BBCSDL Games (proggies.uk)

Oh, interesting.

If you make it prettier, you could easily sell it.