Simon
Simon

Reputation: 994

OpenGL ES Run multiple shaders

Based on a previous question I've been researching how to run multiple shaders in one pass (ie have one FBO and render to texture). This is OpenGLES 2 on Iphone.

I've created some code which runs but only for one frame. So obviously I'm doing something wrong but I just can't spot it.

The inout data is the corevideo buffer from the camera.

Any pointers or fixes are extremely welcomed :).

Thanks,

Simon

PS: I've put everything into one method for now - just so I can simply focus on getting it to work!

- (void) PingPong:(CVImageBufferRef)cameraframe;
{
int bufferHeight = CVPixelBufferGetHeight(cameraframe);

int bufferWidth = CVPixelBufferGetWidth(cameraframe);

// Build the first FBO - this is wasteful - don't do this everytime
GLuint firstFBO;
glGenFramebuffers(1, &firstFBO);
glBindFramebuffer(GL_FRAMEBUFFER, firstFBO);

// Build the first texture and copy the video stuff into it
GLuint sourcetexture;
glGenTextures(1, &sourcetexture);
glBindTexture(GL_TEXTURE_2D, sourcetexture);
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);


// Build the second texture
GLuint nextTexture;
glGenTextures(1, &nextTexture);
glBindTexture(GL_TEXTURE_2D, nextTexture);
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);

// Attach the texture to our first FBO
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, sourcetexture, 0);


// 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));

//glDrawBuffer(sourcetexture);
glEnable(GL_TEXTURE_2D);
glViewport(0, 0, backingWidth, backingHeight);
glBindTexture(GL_TEXTURE_2D, sourcetexture);
glUseProgram(greyscaleProgram);

// Now do the 2nd pass using the sourcetexture as input
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, nextTexture, 0);
glBindTexture(GL_TEXTURE_2D, nextTexture);
glUseProgram(program);

// Present the framebuffer to the render buffer
[EAGLContext setCurrentContext:context];

glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);

[context presentRenderbuffer:GL_RENDERBUFFER];

// Clean up stuff
glDeleteTextures(1, &sourcetexture);
glDeleteTextures(1, &nextTexture);

}

Upvotes: 2

Views: 2013

Answers (1)

Dr. Snoopy
Dr. Snoopy

Reputation: 56397

Where is your draw code? Drawing is what triggers shader execution, and your code as i see it right now has zero draw calls (glDrawArrays, glDrawElements, etc), so it's not working because you're not drawing.

Draw a full screen quad to trigger shader execution for each pass and it will work.

Also it's recommended to use glCheckFramebufferStatus to check that your FBO configuration is supported and will work in your GL implementation.

Upvotes: 3

Related Questions