1

I'm trying to make a SDL2 adapter for a graphics library. I believe this library assumes that all the things it draws in the screens stay in the screen as long as it never draws something in top of it. (See the end of the question for details about this)

What would be the best way to do it?

I've come across multiple solutions, including:

  • Hardware rendering without calling SDL_RenderClear. The problem with this is that SDL uses a double buffer, so the contents can end up in either of them, and I end up seing only a subset of the render at a time.
  • Software rendering, in which if I'm understanding SDL correctly, it would mean having a surface that I mapped to a texture, so I can render the texture, and I would edit the pixels field of the surface in main memory. This would be very slow, and also as the library expects everything rendered instantly and has no notion of frames would mean to send the data to the gpu every time there's an update (even single pixels).

I'm probably missing something about SDL2 and definitely about the library (Adafruit-GFX-Library). What does transaction api means in this context? I've not been able to find any information about it, and I feel like it could be something important.

Sergio B
  • 105
  • 1
  • 1
  • 10
  • 1
    Even without double buffering there can be overshadowing by other windows. You can render to texture and then copy that texture to framebuffer. Or use software rendering with e.g. fixed update interval (flush to screen every 1/nth second, e.g. monitor vsync interval). Unclear what your goal is though. Are you, for some reason, emulating a VGA? – keltar Feb 14 '19 at 11:27
  • Yes, my objective is emulating a tft arduino screen, which is controlled by the library I linked. Flushing at intervals can be a good idea, and the performance would probably be enough for my application. – Sergio B Feb 14 '19 at 11:40
  • @keltar I'm having trouble finding information about overshadowing. Would you mind elaborating a bit more on that? – Sergio B Feb 14 '19 at 16:55
  • Let's say you've minimised your window and then restored it. It is possible that front buffer contents will be lost after that. If other window overshadows yours (displayed on top of it, so you don't see parts of your window), or window goes partially out of screen - I suppose it is windowing system/graphics driver that will define what will happen to front buffer in that case. – keltar Feb 15 '19 at 04:17

1 Answers1

0

In my understanding of SDL2 and general rendering application programming, SDL2 is designed that you draw a complete frame every time, meaning you would clear your "current window" either by OpenGL API calls

glClearColor(0, 1.0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);

which clears the current OpenGL context i.e. frame buffer, of which you would have 2 or by using the SDL2 renderer which I am not familiar with. Then you would swap the buffers, and repeat. (Which fits perfectly with this architecture proposal I am relying on)

So either you would have to replay the draw commands from your library for the second frame somehow, or you could also disable the double frame buffering, at least for the OpenGL backend, by

SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);

(For the other OpenGL SDL2 setup code see this GitHub repository with a general helper class of mine

Superlokkus
  • 4,731
  • 1
  • 25
  • 57