   Slow Multithreaded Rendering in Windows
  Hello all,I am trying to set up an OpenGL rendering in its own thread.  I'm using SDL to set up the context in the main thread (so SDL event handling will work), then switching the context to the rendering thread using wglMakeCurrent().  That all seems to work, but when I make even a single GL call (like glClear() for example), my frame rate plummets.  I only call wglMakeCurrent() once (at startup), so I don't think there is a context switch slowing things down every frame.  Here's how I've set things up:This is called from the main thread to set up the context:bool Setup(unsigned int width, unsigned int height, bool isFullscreen) {if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {printf("Error: Unable to initialize SDL: %s\n", SDL_GetError());exit(1);} atexit(SDL_Quit);const SDL_VideoInfo* video;video = SDL_GetVideoInfo();if (video == 0) {printf("Error: SDL Error: %s\n", SDL_GetError());return false;}SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);if (SDL_SetVideoMode(width, height, video->vfmt->BitsPerPixel, SDL_OPENGL) < 0) {printf("Error: SDL Error: %s\n", SDL_GetError());return false;}SetupGL();// SDL doesn't let you handle events in one thread// and render in another.  This releases the// OpenGL context so we can switch it to the// rendering thread#if defined (SUNSHINE_OS_WIN32)mCurrentContext = wglGetCurrentContext();mCurrentDC = wglGetCurrentDC();wglMakeCurrent(NULL, NULL);#endif // SUNSHINE_OS_WIN32return true;}This is called from the rendering thread to switch the context from the main thread to the rendering thread:void SwitchThread() {// Switch the OpenGL context to this thread#if defined (SUNSHINE_OS_WIN32)wglMakeCurrent(mCurrentDC, mCurrentContext);#endif // SUNSHINE_OS_WIN32}Then when I draw from the rendering thread:void Graphics::Draw() {Clear(); // Wraps glClear(...)Present(); // Wraps SDL_GL_SwapBuffers()}I know this isn't a synchronization issue, because I've tested the rendering thread with non-rendering work, and there is no slow down.  Any ideas?Thanks!   
  Seems strange, what Windows version and compiler etc. are you using?You seem to use an unusual pixel format.. with 5-5-5 colors, why not use the standard desktop format, which should be 32 bit on all modern computers?Does it work fine, if the only difference is that you call Draw() from the main thread?I would try to set up a minimal application without wrappers or anything that does the exact same thing in one or two threads, to make sure that is the problem.   ;  I have isolated the slowdown to the OpenGL calls made by the rendering thread.  If I wipe all of the drawing code out of Draw(), things run as they should, but one call to GL, even if it's to simply swap the buffers, slows everything down.I am compiling using Visual Studio 2008 on 64 bit Vista.  I suspect that the problem lies in Vista's implementation of GL, which I believe simply wraps a DirectX context.  If that's the case, calls to wglMakeCurrent() might not implicitly switch the DirectX context to the new thread.  Versions of DirectX prior to 11 are guarded by a single mutex, the locking of which could be responsible for my slowdown.  I'm going to try to create the GL context with WGL in the rendering thread instead of using SDL to create it in the main thread and switching it to the rendering thread (which is what I should have done in the first place, but I was being lazy).  I'll let you know how it goes.Thanks for your reply!   ;  I also have Vista 64 bit and threaded rendering works fine for me, though I don't use SDL..I create everything in the main thread, and then simply start another thread that does the drawing. I use the following flags for the pixel format, PFD_SUPPORT_COMPOSITION which is necessary to work with Aero, if I remember correctly:pfd.dwFlags =PFD_DRAW_TO_WINDOW |PFD_SUPPORT_OPENGL |PFD_SUPPORT_COMPOSITION |PFD_DOUBLEBUFFER;