Sdl 1.3 multiple opengl windows on osx

Hi,

I am playing with sdl 1.3 because I want multiple windows. I use opengl
in each of them. It seems I can not draw to any but the lastly created
window. The same btw is true for any of the test programs that come
with the lib (f.e. testgl2 draws one frame each in all but the last
window, and the last window is the only one animating). Has anyone
succeeded with this?

Daniel

On 2008-05-11 15:05:32 +0200, Daniel Oberhoff
<daniel.oberhoff at fit.fraunhofer.de> said:

Hi,

I am playing with sdl 1.3 because I want multiple windows. I use opengl
in each of them. It seems I can not draw to any but the lastly created
window. The same btw is true for any of the test programs that come
with the lib (f.e. testgl2 draws one frame each in all but the last
window, and the last window is the only one animating). Has anyone
succeeded with this?

Daniel

anyone? Should I file a bug?

anyone? Should I file a bug?

Yes, please do: http://bugzilla.libsdl.org/

It’s very likely to be a bug at this point, as it’s still
work-in-progress, but we tend to forget things that Bugzilla isn’t
tracking for us, so reporting it there is very helpful.

Thanks,
–ryan.

I am playing with sdl 1.3 because I want multiple windows. I use opengl
in each of them. It seems I can not draw to any but the lastly created
window. The same btw is true for any of the test programs that come
with the lib (f.e. testgl2 draws one frame each in all but the last
window, and the last window is the only one animating). Has anyone
succeeded with this?

I’m seeing this too, which is wierd, because I developed and tested this
code in Mac OS X 10.4. Do you know if this is a Leopard bug or something
broken in SDL?

See ya,
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

Hi,

On 2008-05-18 06:09:47 +0200, Sam Lantinga said:

I am playing with sdl 1.3 because I want multiple windows. I use opengl
in each of them. It seems I can not draw to any but the lastly created
window. The same btw is true for any of the test programs that come
with the lib (f.e. testgl2 draws one frame each in all but the last
window, and the last window is the only one animating). Has anyone
succeeded with this?

I’m seeing this too, which is wierd, because I developed and tested this
code in Mac OS X 10.4. Do you know if this is a Leopard bug or something
broken in SDL?

I looked at the responsible sdl code, and it looks quite sensible. So
it may be with Leopard. It is possible they changed how opengl contexts
are handled and attached to drawables. One thing I noticed in the sdl
code though is, that it seems to reattach the context to the drawable
(i.e. the window) everytime the context is made active through calling
SDL_GL_MakeCurrent. I suppose the intent of the semantics of
SDL_GL_MakeCurrent is to be able to freely reattach gl contexts on the
fly, but I am not sure how useful this is, as opengl contexts are quite
tightly integrate with their drawables. I might try hacking sdl 1.3 to
only attach on context creation and see if this is better.

Best

Daniel

On 2008-05-25 18:08:56 +0200, Daniel Oberhoff said:

Hi,

On 2008-05-18 06:09:47 +0200, Sam Lantinga said:

I am playing with sdl 1.3 because I want multiple windows. I use opengl
in each of them. It seems I can not draw to any but the lastly created
window. The same btw is true for any of the test programs that come
with the lib (f.e. testgl2 draws one frame each in all but the last
window, and the last window is the only one animating). Has anyone
succeeded with this?

I’m seeing this too, which is wierd, because I developed and tested this
code in Mac OS X 10.4. Do you know if this is a Leopard bug or something
broken in SDL?

I looked at the responsible sdl code, and it looks quite sensible. So
it may be with Leopard. It is possible they changed how opengl contexts
are handled and attached to drawables. One thing I noticed in the sdl
code though is, that it seems to reattach the context to the drawable
(i.e. the window) everytime the context is made active through calling
SDL_GL_MakeCurrent. I suppose the intent of the semantics of
SDL_GL_MakeCurrent is to be able to freely reattach gl contexts on the
fly, but I am not sure how useful this is, as opengl contexts are quite
tightly integrate with their drawables. I might try hacking sdl 1.3 to
only attach on context creation and see if this is better.

Best

Daniel

Ok, I was right. Also filed a bug here:
http://bugzilla.libsdl.org/show_bug.cgi?id=589 with an appropriate
discussion starter. Basically my “fix” of stopping the additional
reattachaments of the context to the window is cumbersome and I would
suggest an api change, hiding the glcontext from the api (except maybe
one explicit accessor to allow platform specific stuff).

Daniel

I looked at the responsible sdl code, and it looks quite sensible. So
it may be with Leopard. It is possible they changed how opengl contexts
are handled and attached to drawables. One thing I noticed in the sdl
code though is, that it seems to reattach the context to the drawable
(i.e. the window) everytime the context is made active through calling
SDL_GL_MakeCurrent. I suppose the intent of the semantics of
SDL_GL_MakeCurrent is to be able to freely reattach gl contexts on the
fly, but I am not sure how useful this is, as opengl contexts are quite
tightly integrate with their drawables. I might try hacking sdl 1.3 to
only attach on context creation and see if this is better.

Best

Daniel

Ok, I was right. Also filed a bug here:
http://bugzilla.libsdl.org/show_bug.cgi?id=589 with an appropriate
discussion starter. Basically my “fix” of stopping the additional
reattachaments of the context to the window is cumbersome and I would
suggest an api change, hiding the glcontext from the api (except maybe
one explicit accessor to allow platform specific stuff).

Daniel

Hmm, talking to myself hu? :slight_smile:

Anyhow, I found the real bug: SDL_GL_MakeCurrent returns before calling
the actual platform specific code if it has encountered this
combination before. I.e. it sets window->context to the context given.
And if window->context is already set to this context it returns. My
"fix" just resultecd in undefined behaviour (the window variable I set
to 0 was actually being dereferenced) which just happened to work by
chance.

Now this is all looking a little strange to me: SDL_GL_MakeCurrent
seems to just want to bind a context to a window. And since this is
already done at creation time (at least in the cocoa impl) it only
makes sense if I change the target of a context. Now this might
actually make sense in some scenario (though I cant think of any…)
but then there is no way to make some context current for rendering.

So as I understand it SDL_GL_MakeCurrent in its current form should be
called somethink like SDL_GL_ContextSetWindow and there should be a
SDL_GL_ContextMakeCurrent which only takes the window or the context as
argument, as the window contains the context anyhow at that point. I
would actually recommend the new SDL_GL_ContextMakeCurrent only taking
a context as arg and having yet another methood
SDL_GL_GetWindowContext. This would also free the user from having to
keep track of contexts on top of windows, which is reduntant.

I still wonder though if there is a use case where I ever need a
context separate from a window, other than sharing it between windows,
which also does not seem possible with the current api. If there is
not, then I would still recommend not exposing the context in the api,
and implement SDL_GL_GetWindowContext for any platform specific hacks a
user might want to do.

I will cc this to my bug report.

Best

Daniel