6.12  gl-context<%>

A gl-context<%> object represents a context for drawing with OpenGL to a specific dc<%> instance. To obtain a gl-context<%> object, call get-gl-context of the target drawing context.

Only canvas dc<%> and bitmap-dc% objects support OpenGL (always under Windows and Mac OS, sometimes under X), and in the case of a bitmap-dc%, the context is usable only when the target bitmap is non-monochrome. When the target bitmap for a bitmap-dc% context is changed via set-bitmap, the associated OpenGL context is reset, but the gl-context<%> keeps its identity. Canvas contexts are double buffered, and bitmap contexts are single buffered.

MrEd provides no OpenGL routines. Instead, they must be obtained from a separate library, such as (lib "sgl.ss" "sgl"). MrEd merely manages the current GL context, connecting it to windows and bitmaps.

Only one OpenGL context can be active at a time across all threads and eventspaces. Except under Mac OS, OpenGL contexts are not protected against interference among threads; that is, if a thread selects one of its OpenGL contexts, then other threads can write into the context via OpenGL commands. However, if all threads issue OpenGL commands only within a thunk passed to call-as-current, then drawing from the separate threads will not interfere, because call-as-current uses a lock to serialize context selection across all threads in MrEd.