How to fix: create the shared context in the main thread, at initialization time of the low priority queues but not inside the thread proc. Do the wglMakeCurrent only in the thread proc of the queues.
(Actually I'm not yet sure if this is a complete fix, because the display is still quite weird and some rectangles seem to not show textures at all.., but I think that's because I still only have spinning HDD)
For the curious, it took me 1h30 to find the problem.
Summary of the paths I took:
1. Handmade Hero only shows black screen only. Fixed by setting HANDMADE_STREAMING=0
2. Handmade Hero now show only white rectangles. Fixed by #define GlobalConstants_Renderer_UseSoftware 1
This proves that OpenGL is capable of showing our assets.. So that's not an error having to do with the asset file.
3. Compared OpenGLDisplayBitmap (used by software renderer) and OpenGLRenderCommands.. We seem to use the same texture attributes in both so does not seem to be a trivial OpenGL error.
4. Add checks of glGetError() inside the Win32AllocateTexture function. Like so:
1 2 | GLenum Error; while ((Error = glGetError()) != GL_NO_ERROR) { /* breakpoint here */ } |
This turns out to be an infinite loop, always returning GL_INVALID_OPERATION which is unexpected when you read the docs at http://docs.gl/es3/glGetError
That's at that point that I start to suspect a bigger, more general issue with the GL context of the worker thread and debug the Win32CreateOpenGLContextForWorkerThread function. ModernGLRC is there always 0.. Which is my clue that we have a problem calling wglCreateContextAttribsARB inside the thread proc.
I then fixed that by adding the HGLRC to the platform_work_queue structure, instantiate in the main thread and there you go, I start seeing bitmaps on the screen.