[waffle] [GSOC 2014] How to deal with non win32 api, wgl(Create, Make)Context depends on existing window

Emil Velikov emil.l.velikov at gmail.com
Tue Jun 3 16:45:51 PDT 2014


On 02/06/14 19:55, Chad Versace wrote:
> On Sat, May 31, 2014 at 12:02:10PM -0700, Jose Fonseca wrote:
>>
>>
>> ----- Original Message -----
>>>
>>>
>>> ----- Original Message -----
>>>> On 24/05/14 20:28, Emil Velikov wrote:
>>>>> Hi all,
>>>>>
>>>>> Another round of interesting bits and bulbs.
>>>>>
>>>> Bit of an update:
>>>>
>>>>> The email came out a bit longer than expected, although it provides a
>>>>> decent
>>>>> list of possible solutions. Let me know which one you'll go with.
>>>>>
>>>>> Four topics sorted by priority - high to low (based on my humble opinion)
>>>>>
>>>>> * ChoosePixelFormat - close yet quite different across platforms.
>>>>>
>>>>>   - glXChoosePixelFormat    - depends on display (matches waffle's
>>>>>   model).
>>>>>   - CGLChoosePixelFormat    - no dependencies.
>>>>>   - {wgl,}ChoosePixelFormat - depends on a device_context/existing
>>>>>   window.
>>>>>
>>>> To make things better, wgl functions depend on a current context as well.
>>>> The
>>>> recommended way of doing things under windows seems to be the following:
>>>>
>>>>    window_handle = CreateWindow(...)
>>>>    device_context = GetDC(window_handle);
>>>>
>>>>    gl_rendering_context = wglCreateContext(device_context);
>>>>    wglMakeCurrent (device_handle, gl_rendering_context);
>>>>
>>>>    // any of the following
>>>>    wglGetProcAddress(...)
>>>>    wglChoosePixelFormat(...)
>>>>    ....
>>>>
>>>>    wglMakeCurrent (device_handle, NULL);
>>>>    wglDeleteContext (gl_rendering_context);
>>>>
>>>>    ReleaseDC(device_context);
>>>>    DestroyWindow(window_handle);
>>>
>>> Yep.
>>>
>>>
>>>
>>>>
>>>> AFAICS waffle is unique wrt other projects (apitrace, epoxy, glut) as it
>>>> allows the PixelFormat to be called prior to the creation of either window
>>>> or
>>>> context.
> 
> 
> If you could rewrite this problematic portion of Waffle's API, how would
> you design it? I'm asking so that, if we do redesign Waffle's API one
> day, it can better accommodate Windows and Mac.
> 
> One requirement of any API redesign, though, is to preserve the ability
> to create a context and render into it without creating a throwaway
> surface, as in EGL_KHR_surfaceless_context. (Through-away surfaces are
> ok as long as they are internal to Waffle).
> 
If I understand things correctly surface(egl)/drawable(glx) are not as clearly
separated in wgl. At least not initially.

Redesign of Waffle's API sounds like an overkill imho, as the only thing we
need is an easier way get from context/config data to window. Otherwise
wcore_(context|config|window) will be dummies and everything will be stored in
a wcore_display wrapper (wgl_display).

Perhaps the following rough flow illustrates things a bit better

glx (in the following example window is optional)
   display > glx > create_context > window > gl*

wgl (here window is the root, i.e. think of (wgl)window == (glx)display)
   window > create_context > wgl/gl

Currently I shove everything in wgl_display, although a slightly cleaner
approach might be better.

-Emil

> 
>>>>>   Options:
>>>>>     - Create a window, choose format, destroy window.
>>>>>           No guarantee that the function will behave the same for another
>>>>>           window/device_context.
>>>
>>> In practice, the odds of this happening are very low.
>>
>> Just to be clear. This assumption will break when there are multiple GPUs on the system (each CPU connected to a different display). Anyway, getting OpenGL to work across multiple GPU (if you move the window from one display to another bad things will probably happen.)
>>
>> The reason that wglGetProcAddress requires window/context is because only then will OPENGL32.DLL know which ICD DLL to load.
> 
> Emil, if you decide to create an invisible window internal to Waffle,
> maybe the best time to do that is during waffle_display_connect() and
> store it in the display. Just a thought, and maybe not a good one.
> _______________________________________________
> waffle mailing list
> waffle at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/waffle
> 



More information about the waffle mailing list