Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4123126
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:34:17+00:00 2026-05-20T23:34:17+00:00

Relating to my previous two questions I’ve spent a week attempting to figure out

  • 0

Relating to my previous two questions I’ve spent a week attempting to figure out how to run multiple shaders against a core video buffer. I know what I need to do but I, frankly, can’t get the code to work (pasted below is the original, non ping-pong version).

Lacking the Eureka moment I’m now totally stuck :). The code to compile and link the shaders is not shown for brevity. The whole thing renders (successfully – but one shader overwrites the other – so missing the vital step) to a GL compatible layer and theres a UIToolbar underneath which, eventually, will have a button per shader and a button to run all shaders.

Thanks,

Simon

-(void) DrawFrame:(CVImageBufferRef)cameraframe;
{
    int bufferHeight = CVPixelBufferGetHeight(cameraframe);
    int bufferWidth = CVPixelBufferGetWidth(cameraframe);

    // Create a new texture from the camera frame data, display that using the shaders
    glGenTextures(1, &videoFrameTexture);
    glBindTexture(GL_TEXTURE_2D, videoFrameTexture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    // Using BGRA extension to pull in video frame data directly
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bufferWidth, bufferHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, CVPixelBufferGetBaseAddress(cameraframe));

    static const GLfloat squareVertices[] = {
        -1.0f, -1.0f,
        1.0f, -1.0f,
        -1.0f,  1.0f,
        1.0f,  1.0f,
    };

    static const GLfloat textureVertices[] = {
        1.0f, 1.0f,
        1.0f, 0.0f,
        0.0f,  1.0f,
        0.0f,  0.0f,
    };

    [self setDisplayFramebuffer];

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, videoFrameTexture);

    // Update uniform values
    glUniform1i(uniforms[UNIFORM_VIDEOFRAME], 0);   

    // Update attribute values.
    glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices);
    glEnableVertexAttribArray(ATTRIB_VERTEX);
    glVertexAttribPointer(ATTRIB_TEXTUREPOSITON, 2, GL_FLOAT, 0, 0, textureVertices);
    glEnableVertexAttribArray(ATTRIB_TEXTUREPOSITON);


    glUseProgram(greyscaleProgram);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    [self presentFramebuffer];

    // Obviously here is where the ping pong starts (assuming correct mods 
    // to the framebuffer setup method below
    glUseProgram(program);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    [self presentFramebuffer];

    glDeleteTextures(1, &videoFrameTexture);
}

- (void)setDisplayFramebuffer;
{
    if (context)
    {
        [EAGLContext setCurrentContext:context];

        if (!viewFramebuffer)
        {
            [self createFramebuffers];
        }

        glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);



        glViewport(0, 0, backingWidth, backingHeight);

    }
}

- (BOOL)presentFramebuffer;
{
    BOOL success = FALSE;

    if (context)
    {
        [EAGLContext setCurrentContext:context];

        glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);

        success = [context presentRenderbuffer:GL_RENDERBUFFER];
    }

    return success;
}

- (BOOL)createFramebuffers
{   
    glEnable(GL_TEXTURE_2D);
    glDisable(GL_DEPTH_TEST);

    // Onscreen framebuffer object
    glGenFramebuffers(1, &viewFramebuffer);
    glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);

    // Render buffer for final output
    glGenRenderbuffers(1, &viewRenderbuffer);
    glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);

    [context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer *)self.layer];

    glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
    glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);
    NSLog(@"Backing width: %d, height: %d", backingWidth, backingHeight);

    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, viewRenderbuffer);


    if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) 
    {
        NSLog(@"Failure with framebuffer generation");
        return NO;
    }

    return YES;
}

Edit: Clarified what is missing

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:34:17+00:00Added an answer on May 20, 2026 at 11:34 pm

    To do ping-pong rendering, you need to do the following:

    • Create 2 textures, with the exact same configuration
    • Create 2 Framebuffers with the same configuration, and attach one texture to each framebuffer.

    Let’s call the Framebuffers A and B, and the attached textures texA and texB:

    To render:

    • Use the first shader with glUseProgram.
    • Bind Framebuffer A.
    • Render a quad.

    Now you have the result of the shader execution in texA. To do the ping-pong:

    • Use the second shader with glUseProgram.
    • Bind Framebuffer B.
    • Bind texA and setup texture units for your shader.
    • Render a quad.
    • Use shader with glUseProgram.
    • Bind Framebuffer A.
    • Bind texB and setup texture units.
    • Render a quad.

    Now you have the result in texA and you can repeat the process again, hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hopefully two simple questions relating to creating a server application: Is there a theoretical/practical
relating to this post, https://apple.stackexchange.com/questions/70585/applescript-opens-new-window-for-everything-when-run . I wonder if i can highlight the selected
Following on from a previous question relating to heap usage restrictions , I'm looking
I am continuing on from a previous question relating to loading instances of plugins
This questions relating to infowindow in the google maps API v3.. Currently I loop
I have a couple of open questions relating to the same sort of thing,
I have a few questions relating to setjmp/longjmp usage - What is the use
I am aware that a thousand and one questions relating to this topic have
I have two problems relating to using Jquery mobile UI framework dropdown selectors when
Relating to a previous question of mine I've successfully interposed malloc , but calloc

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.