Search code examples
cocoamacosopenglcore-animationcore-graphics

Mixing Quartz and OpenGL?


I am trying to find out what actually happens in background when we do this (please see the image)

enter image description here

As you can see in image I have added few buttons and have checked Content View from Interface builder for window.

Now as we know it will make use of core animation or say will create layers. (Please correct me if I am wrong. Still studying...)

I want to know how does these buttons are drawn?

My assumption is when we tick Content View, these buttons are drawn from CGBitmapContextRef and bitmap created from it are handed over to Core Animation (OpenGL). But I am not being able to prove it so far. How do I prove it? Any example or some approach idea would be great?

Thing I am sure of is buttons created from CGBitmapContextRef. But what happens to those button images is unknown.

Can anyone explain how is that integration possible? How those image would have got on screen?

Edit:

To add some more information on same topic, please check the image below for layers of OpenGL. I think I am targeting common OpenGL Framework layer. enter image description here


Solution

  • Buttons are draw on CGBitmapContextRef.

    Lets say, we have CGBitmapContextRef objected created using

    CGContextRef CGBitmapContextCreate (
       void *data,
       size_t width,
       size_t height,
       size_t bitsPerComponent,
       size_t bytesPerRow,
       CGColorSpaceRef colorspace,
       CGBitmapInfo bitmapInfo
    );
    

    Here void *data, is a pointer to the destination in memory where the drawing is to be rendered.

    CGContext API can be then used to perform various operation on data. Thus buttons and background can be draw on it.

    Once done we can release the CGContextRef but data is still in memory which can be passed to OpenGLContext(CGLContextObj).

    I still do not know how it uploads data to CGLContextObj. Must be using some private api.