Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opengl can only draw to the lastly created window #96

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Closed

opengl can only draw to the lastly created window #96

SDLBugzilla opened this issue Feb 10, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

Reported in version: HG 2.0
Reported for operating system, platform: Mac OS X 10.5 (Intel), PowerPC

Comments on the original bug report:

On 2008-05-25 09:36:53 +0000, Daniel Oberhoff wrote:

if I use multiple windows all drawing seems to go to the lastly created window. this also shows in the simple multiwindow opengl test case in the repository. it seems to be leopard only. it might be related to the fact that the current impl tries to reattach the context to the window each time it is made active, which I am testing now.

On 2008-05-25 10:00:15 +0000, Daniel Oberhoff wrote:

indeed, I was right: continuously reattaching the context somehow messed things up. I "fixed" it locally by making Cocoa_GL_MakeCurrent accept 0 as window argument, in which case it will not reattach the context, and I patched testgl2 a bit to use this (and multiple contexts which it didnt properly do before). Though this does not feel like a final answer.

Question is: what are the usecases for reattaching contexts to different drawables? If no convincing ones can be found I would actually suggest hiding the glcontext from the api altogether except for maybe a single function (i.e. sdl_gl_get_internal_context(window)) allowing access to the internal data if needed but making it an explicit point of leaving the portable api (like when accessing other platform specific internal data).

In this case the context would need to be kept in the window itself, adding an ivar, but would that matter? It would also make code simpler, freeing the user from having to store window and context separately and eliminate many probable errors in getting this wrong.

On 2008-05-25 13:59:36 +0000, Daniel Oberhoff wrote:

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.

By the looks of it this bug should also apply to all other platforms, though I haven't tested this.

On 2008-05-26 05:28:23 +0000, Sam Lantinga wrote:

This was broken in revision 3416, I'm working on a fix now.

On 2008-05-26 05:45:08 +0000, Sam Lantinga wrote:

This is fixed in revision 3622, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant