Two renderers for the same window

Why can’t I have two renderers for the same window? I am not sure if it is SDL2
limitation, but it allows me to create two, but when I try to draw on the second,
it fails with sdl2.ext.common.SDLError: ‘Invalid renderer’

Are you trying to render split-screen, one half with OpenGL and the other
half with Direct3D?
If not, then I don’t see any point to doing what you are doing.

I don’t think that it makes sense to have multiple renderers associated
with the same window. I don’t know for sure, but doesn’t something prevent
one from owning two contexts?
Also, it would make sense if OpenGL and Direct3D contexts conflict.
However, I don’t know. This is all speculation on my part.On Thu, Mar 27, 2014 at 1:36 PM, techtonik wrote:

Why can’t I have two renderers for the same window? I am not sure if it
is SDL2
limitation, but it allows me to create two, but when I try to draw on the
second,
it fails with sdl2.ext.common.SDLError: ‘Invalid renderer’


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

What about having two renderers for a window, but using only one at a time ? I can’t think of the benefits of this method, by the way.

Sorry. Missed my notification. I guess I wanted to do some pixel graphics in some separate renderer, because those 3D renderers were slow.

But perhaps the question comes from misunderstanding why SDL2 allow to create multiple renderer at all if you can only have one window?

Why have separate step for creating renderer?

Who says you can only have one window?? That hasn’t been true since the SDL 1.2 days.From: techtonik
To: sdl at lists.libsdl.org
Sent: Thursday, February 11, 2016 2:51 AM
Subject: Re: [SDL] Two renderers for the same window

Sorry. Missed my notification. I guess I wanted to do some pixel graphics in some separate renderer, because those 3D renderers were slow.

But perhaps the question comes from misunderstanding why SDL2 allow to create multiple renderer at all if you can only have one window?

Why have separate step for creating renderer?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Ok, it is possible to have two windows. But what’s the point in separating renderers from windows if they are 1:1 bound?

Ok, it is possible to have two windows. But what’s the point in separating renderers from windows if they are 1:1 bound?

The point is that a window is a window, and it’s always done the same way on your OS, but there can be multiple different types of renderers supporting different backends.
Also, basic separation of concerns.? The renderer doesn’t need to care about stuff like the window title or whether it has Minimize and Maximize buttons, and the window doesn’t need to know how to talk to OpenGL or D3D.
Mason

Ok, it is possible to have two windows. But what's the point in separating renderers from windows if they are 1:1 bound?From: techtonik

Subject: Re: [SDL] Two renderers for the same window

Also, they’re not necessarily 1:1 bound.? The default is to create a window that’s fully filled up by a single renderer, but if you use SDL_CreateRendererFrom() you can bind a renderer to a native window handle and place it inside a window (aka form).? I’ve used this before to have two renderers in the same form doing two different things.
Mason

Ok, it is possible to have two windows. But what's the point in separating renderers from windows if they are 1:1 bound?From: techtonik

Subject: Re: [SDL] Two renderers for the same window

I’m not quite sure I understand the problem, or the question, but
another reason to separate them is that you may not even want to
render into an actual window. See SDL_CreateSoftwareRenderer().

And, there is SDL_CreateWindowAndRenderer(), if you want simpler code
and fewer options.

What’s the big deal, anyway? One interface more or less… :-)On Sat, Feb 13, 2016 at 7:11 PM, Mason Wheeler wrote:

Also, they’re not necessarily 1:1 bound. The default is to create a window
that’s fully filled up by a single renderer, but if you use
SDL_CreateRendererFrom() you can bind a renderer to a native window handle
and place it inside a window (aka form). I’ve used this before to have two
renderers in the same form doing two different things.
Mason


From: techtonik
Subject: Re: [SDL] Two renderers for the same window

Ok, it is possible to have two windows. But what’s the point in separating
renderers from windows if they are 1:1 bound?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


//David Olofson - Consultant, Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://consulting.olofson.net http://olofsonarcade.com |
’---------------------------------------------------------------------’

Ok, it is possible to have two windows. But what’s the point in separating renderers from windows if they are 1:1 bound?

What’s the big deal, anyway? One interface more or less… Smile

SDL2 became much more complicated and still doesn’t have any diagrams or pictures that explain that stuff at all, so one interface more is like a headshot to for my tired brain which only dealt with plain x,y drawing planes in the past.

I think render can become invalid occasionally (context loses, driver crashes, etc.). If it’s a part of the window, then you’d need to create a new window. By separating it, a new render could be created to replace the invalid one.

One more thing is, you don’t even have to use renderer (with the Windows), in the case that you’re using OpenGL or OpenGL ES (or may be Direct3D too, if I’m not mistaken). Separating the renderer out of the Windows implementation make more sense than combining them and let half of the functionality unused.

Because windows don’t necessarily have renderers at all (you can use
Direct3D or OpenGL or Vulkan or Metal directly in an SDL window without
using SDL’s rendering API), so it’s not "you have 1 renderer per window"
it’s “you have 0-1 renderers per window.”

–ryan.On 02/13/2016 11:20 AM, techtonik wrote:

Ok, it is possible to have two windows. But what’s the point in
separating renderers from windows if they are 1:1 bound?

If you use SDL_CreateRendererFrom, you can actually have “0 or more renderers per window”.? (Yes, really.? I’ve done it for a real-world use case.)
Mason

Ok, it is possible to have two windows. But what’s the point in
separating renderers from windows if they are 1:1 bound?

Because windows don’t necessarily have renderers at all (you can use
Direct3D or OpenGL or Vulkan or Metal directly in an SDL window without
using SDL’s rendering API), so it’s not "you have 1 renderer per window"
it’s “you have 0-1 renderers per window.”

–ryan.From: Ryan C. Gordon
Subject: Re: [SDL] Two renderers for the same window
On 02/13/2016 11:20 AM, techtonik wrote:

If you use SDL_CreateRendererFrom, you can actually have “0 or more
renderers per window”. (Yes, really. I’ve done it for a real-world use
case.)

o_O

Why is that so shocking?? I created a form in a widget set and put two different SDL Frame controls on it.? It was very useful!

Mason

If you use SDL_CreateRendererFrom, you can actually have “0 or more
renderers per window”.? (Yes, really.? I’ve done it for a real-world use
case.)
o_OFrom: Ryan C. Gordon
Subject: Re: [SDL] Two renderers for the same window

I can think of a logical application for multiple renderers: game view port, game settings view port (all surfaces I guess). Manage the surfaces with another renderer combining the two previous for a nice effect. Essentially render each surface exclusively with different instances and apply the desired instance (surface) with the primary renderer. It seems, to me preliminarily, that you get a 1:1 relationship between a surface and a renderer for initial simplicity and basic functionality in a manner that’s easy to track.

Ultimately, using multiple renderers would be pre-emptive and benefit from threading creating responsive UI compositions, but could also work for background rendered screen/snap shots too. At any rate --good discussion.

Use a streamed texture to do your pixel art and render that texture using SDL’s renderer. There is no quicker way.