pBuffer - how to draw in it, then display it?

Post: #1
I put together the following code which generates a pBuffer and a corresponding context.

From what I gather, the pBuffer lives a 'dual life' as a texture. I generate a texture here, have I bound it to the pBuffer? Once I manage that, how do I draw into it? I have the gl*() commands I'd like to draw into it with but where do I write them? Finally, how do I display the pBuffer?

Ultimately I'd like to do this: draw to the current (viewable )context. In another thread create the pBuffer and draw to it. On a user event, place the pBuffer contents into the viewable and spawn a thread again to draw into the pBuffer again. I'm hoping that I can somehow take advantage of Core Image transitions to make a transition between the two contexts. Anyway, here's the code:

    NSOpenGLPixelFormatAttribute    attributes[] = {
    NSOpenGLPFADepthSize, 24,
    (NSOpenGLPixelFormatAttribute) 0
    NSOpenGLPixelFormat* pBufferScreenPixelFormat =
        [[[NSOpenGLPixelFormat alloc] initWithAttributes: attributes] autorelease];
    g_pBufferContext = [[[NSOpenGLContext alloc] initWithFormat:
        shareContext: nil] retain];

    GLuint saveTextureName;

    if (!g_pBufferContext) {
        NSLog(@"setupPBuffer error!");
    } else
        g_pBuffer = [[[NSOpenGLPixelBuffer alloc] initWithTextureTarget: GL_TEXTURE_2D
                                               textureInternalFormat: GL_RGBA /* GL_RGBA */
                                               textureMaxMipMapLevel: 0
                                                          pixelsWide: 0
                                                          pixelsHigh: 0]
        // Attach the PBuffer
        [g_pBufferContext setPixelBuffer: g_pBuffer
                            cubeMapFace: 0
                            mipMapLevel: 0
                   currentVirtualScreen: [g_pBufferContext currentVirtualScreen]];

    //Create the texture on the target OpenGL context
    g_pbTexTarget = GL_TEXTURE_2D;
    glGenTextures(1, &g_pbTexName);

    //Configure the texture - For extra safety, we save and restore the currently bound texture
    glBindTexture(g_pbTexTarget, g_pbTexName);
    glTexParameteri(g_pbTexTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(g_pbTexTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    if(g_pbTexTarget == GL_TEXTURE_RECTANGLE_EXT) {
        glTexParameteri(g_pbTexTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(g_pbTexTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    else {
        glTexParameteri(g_pbTexTarget, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(g_pbTexTarget, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glBindTexture(g_pbTexTarget, saveTextureName);

    NSLog(@"makePBuffer %@ %@", g_pBuffer, g_pBufferContext);

    //[g_pBufferContext setView:self];
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  pbuffer blending problem on macmin g4 madjerry 4 6,098 Nov 27, 2009 03:14 AM
Last Post: madjerry
  Pbuffer problems on Intel NVIDIA GeForce 7300 GT NYGhost 5 6,713 Oct 26, 2006 09:39 AM
Last Post: NYGhost
  PBuffer & Render to Texture (read & write) habicht 4 7,317 Feb 7, 2005 05:33 PM
Last Post: habicht
  Problems with creating pbuffer gregorypierce 10 6,674 Jan 28, 2005 03:21 PM
Last Post: gregorypierce