Search code examples
renderingsdl-2multiple-monitors

SDL2: Share renderer between multiple windows


I have a set of images, and I need show it on different displays. So I create two windows and two renderers. But some image may be show on several displays. And if the texture was created using rendererOne, and shown with rendererTwo, we have a program crash. If I create texture in runtime each time, when I need show - I have falling of FPS.

How it is better to solve this problem? Can I share renderer between windows (on different displays)? Or can I share texture between different renderers?

p.s. I can mark image's name like "Image1.one.two.png" or "Image2.one.png" and so on, and create two copies of Image1 and one copy of Image2, but it very difficult way, and require many RAM.

p.p.s. I don't use OpenGL directly.


Solution

  • I have solved this problem by using a lazy initialization of texture. I store SDL_Surface, and when I need show some Texture then I check it:

    if (m_texture == nullptr || !m_texture->CompatibleWithRenderer(renderer))
    {
        m_texture = new Texture(renderer, m_surface);
    }