Compositing from a Cocoa window to a GL context efficiently
Compositing from a Cocoa window to a GL context efficiently
- Subject: Compositing from a Cocoa window to a GL context efficiently
- From: "Timothy J. Wood" <email@hidden>
- Date: Thu, 2 Jun 2005 10:47:04 -0700
I need to composite from one window to a GL context very
efficiently. While I can think of some ways to do it, nothing jumps
out at me as being all that great of a path for CG content. My
destination is always an OpenGL context, so for OpenGL sources, I can
use surface textures via -[NSOpenGLContext
createTexture:fromView:internalFormat:]. This has the benefit that
the binding is 'live' (each time I use the returned texture ID, I get
whatever is in the GL context attached to the view), though I can
live w/o that. Sadly, this call doesn't pick up the CG layer, just
the GL layer.
For CG content, I'd like to do something similar w/o disturbing
the code actually drawing into the CG context and w/o forcing my own
CG context into the pipe.
For example, I could do:
- Create a CGBitmapContext of the same size as the window
- Create a NSGraphicsContext on top of that CGBitmapContext
- Get the views into drawing into that (via -
displayRectIgnoringOpacity:inContext: or some other path)
- Create a client storage GL texture from the bag of bytes
serving as the backing store for the CGBitmapContext
- Draw into the destination using that GL texture (having set up
appropriate GL context sharing).
This approach is no good though, since my interjection of the
bitmap context would force all the drawing to be done on the CPU. My
assumption here is that the CG layer can live on the GPU under Quartz
Extreme on 10.4 (dunno if that actually happens in practice, but I
presume it does). If it can't, I guess this is all less important :)
What I'd really like is something like:
- Get the graphics context of the NSWindow via -graphicsContext
- Get the CGContext from that using -graphicsPort
- Get a CIImage representing some rect of the CGContext
- There is no way to do this efficiently w/o CPU<->GPU
traffic, AFAICT. Well, as far as I can tell, there is no way to do
it at all right now.
- Draw into my destination GL context using CoreImage
There is -[NSBitmapImageRep initWithFocusedViewRect:], but I would
presume this would do a GPU->CPU copy of the pixels... bad.
-tim
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden