Comments inline below.
On Oct 18, 2013, at 8:18 AM, Ardo Avancena <
email@hidden> wrote:
I created a context and I think I am drawing to it but I don't know exactly how to make it appear in Motion.
I don't exactly know how to use the [FxHostCapabilities glContextPixelFormatAttributes] to create a pixel format attribute for my new context since I can't C-style cast it to a CGLPixelFormatAttribute. So instead I printed the NSArray values out and wrote them down to get the integer values, then created a pixel format by referring to the CGLPixelFormatAttribute enumeration to find the integer equivalent and wrote them down, so I ended up with this:
CGLPixelFormatAttribute pixelFormatAttributes[] = {
kCGLPFANoRecovery,
kCGLPFAAccelerated,
kCGLPFAWindow,
kCGLPFAAllowOfflineRenderers,
kCGLPFADepthSize, (CGLPixelFormatAttribute)24,
(CGLPixelFormatAttribute) 0
};
You can convert the NSArray returned from -[FxHostCapabilities glContextPixelFormatAttributes] by following the instructions in the header:
This method allows a plug-in to create GL contexts that are compatible with
those created by the host application. A plug-in typically puts the values
for each element of the returned array into an C-style zero-terminated array
of CGPixelFormatAttributes, and passes a pointer to that array to
CGLChoosePixelFormat(). It then passes the CGLPixelFormatObj returned by
that function to CGLCreateContext() and then to CGLDestroyPixelFormat().
Then I called, to generate the pixel format:
CGLChoosePixelFormat(pixelFormatAttributes, &pixelFormat, &numberOfPixels);
What does it return? Do you get back a valid pixelFormat? Or is it NULL?
Then I created the new context using this:
CGLCreateContext(pixelFormat, renderContext, &childContext);
I have been switching around the renderContext value from renderInfo.sharedContext and the CGLGetCurrentContext(); but havent got the output I was hoping for.
Either should work as they're both in the same share group. When you say "haven't got the output I was hoping for," do you mean from that function or from your rendering?
I switch contexts
CGLSetCurrentContext(childContext);
call FTGL to draw my text
at this point i'm hopefull that I can view the context in motion, but it hasn't.
I'm not entirely sure what you mean here. A context isn't something that can be viewed. It's just a set of state that describes how and where OpenGL should draw. You can set the state in the context so that drawing happens to the screen, or to some buffer, such as a texture that's attached to an FBO. When your plug-in is called, we set up a texture-backed FBO for you to draw into. If you don't change the context or create your own FBO, all your drawing should go to that texture. If you do create a new context or FBO, or change the current FBO attachments, then drawing will go someplace else. And it looks like you're changing the current context above before calling into FTGL. So the question is - what are you drawing to?
When you create a shared context, OpenGL shares various resources between your context and the other contexts in the same share group. Resources are things like textures, VBOs, FBOs, etc. It also shares the state associated with those objects. I don't know off the top of my head which bits of OpenGL state are shared, so you might want to ask over on the OpenGL list (see below) about the details. I would think that the current output FBO would be in that state, but I'm not positive.
Any thoughts on this? I tried making a buffer in the childContext but I had no clue how to output it in a different context.
Have you ever used OpenGL Profiler? It's got its quirks, but can be very useful in untangling OpenGL state. The way I use it is to add calls to OpenGL functions that nobody else is likely to be using during my testing, such as glFogCoordd(). Then I run OpenGL Profiler, attach to Motion or FCPX and set a breakpoint on glFogCoordd(). If I have more than one call, I send a different coordinate to differentiate where I've stopped. Then I run my plug-in, and when Profiler hits the breakpoint, I look at the OpenGL state. You can use the checkboxes to see what's changed from the default state, and what's changed since you last stopped.
Once stopped, I would check things like what the current context is, and what the FBO settings are - GL_DRAW_FRAMEBUFFER_BINDING in particular. It will have an integer value. If it's 0, then it's drawing to the screen, I believe. If it's > 0, then it's drawing into an FBO. You can open the Resources window and look at the state of the FBO. It will tell you which texture is attached as the color buffer. You can then open the textures tab and see what's drawn into that texture. (But keep in mind that OpenGL is asynchronous and may not draw anything until it gets a flush.)
Using the profiler, you should be able to see what the current context is, which FBO it's drawing to, which texture is backing that FBO, and depending on when you stop, what that texture looks like. That should help you figure out what's going on and hopefully point you to some solutions.
I'm not really an expert on OpenGL. If you want more info from the people who actually work on it, I suggest joining the OpenGL mailing list if you haven't already at:
Also, here is some useful documentation on how FBOs work:
Darrin