| Summary: | opengl can only draw to the lastly created window | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Daniel Oberhoff <daniel> |
| Component: | video | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | major | ||
| Priority: | P2 | ||
| Version: | HG 2.0 | ||
| Hardware: | PowerPC | ||
| OS: | Mac OS X 10.5 (Intel) | ||
|
Description
Daniel Oberhoff
2008-05-25 09:36:53 UTC
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. 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. This was broken in revision 3416, I'm working on a fix now. This is fixed in revision 3622, thanks! |