For two contexts to be compatible, their pixel formats
must be compatible, which is why you see these two things speci?¬?ed together
to successfully enable sharing.
What makes pixel formats incompatible? On the Mac, usually it??™s one thing??”
incompatible renderers. As a rule of thumb, if you can choose pixel formats that
use the same renderers, you can share contexts created with those pixel formats.
Additional Topics 141
So we??™ve covered the how and why of sharing a context, but what, exactly, is
shared when context sharing is enabled? Interestingly enough, most OpenGL
objects are shared, but the overall context state is not. That??™s not entirely intuitive,
but it correlates well with what people usually want to do. You save valuable
card memory by reusing heavyweight objects in multiple spots, but still
preserve the ability to customize each OpenGL view as needed. Speci?¬?cally, the
following entities are shared:
??? Display lists
??? Vertex array objects (VAOs)
??? Buffer objects (VBOs, PBOs)
??? Texture objects
??? Vertex and fragment programs and shaders
??? Frame buffer objects (FBOs)
Now that we have an overview of how context sharing works, let??™s walk
through some code. For purposes of this example, we will build a twowindowed
version of our earlier Cocoa example in which we created a custom
context. In this case we??™ll modify the example to share the context between the
two views and surfaces, render some shared data (a display list), and visualize
the data in two views, each with a different-color background color.
Pages:
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233