Note that there are some explanatory texts on larger screens.

plurals
  1. POBind Opengl texture from the first fbo to a second fbo, use shader and render the second result (ping pong)
    text
    copied!<p>I've been working on ping pong shading and had thought that I had cracked it after my previous question. However, with further shader knowledge it looks like while I'm able to run the shader on FBO A and on FBO B, the output from A is not used as the source to B. In other words I'm not binding it correctly.</p> <p>The code I'm using is below. The output of the second shader is showing colour based output but the first shader sets the data to grayscale. So consquently I know this isn't working as required.</p> <p>I'd be grateful for any (yet further!!) assistance. </p> <p>Code below,</p> <p>Cheers,</p> <p>Simon</p> <pre><code>- (void) PingPong:(CVImageBufferRef)cameraframe; { // Standard texture coords for the rendering pipeline 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, }; if (context) { [EAGLContext setCurrentContext:context]; } // Create two textures with the same configuration int bufferHeight = CVPixelBufferGetHeight(cameraframe); int bufferWidth = CVPixelBufferGetWidth(cameraframe); // texture 1 glGenTextures(1, &amp;tex_A); glBindTexture(GL_TEXTURE_2D, tex_A); 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)); // Texture 2 glGenTextures(1, &amp;tex_B); 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); // Bind framebuffer A glBindFramebuffer(GL_FRAMEBUFFER, fbo_A); glViewport(0, 0, backingWidth, backingHeight); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, tex_A); // 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); // Use the first shader glUseProgram(greyscaleProgram); // Render a quad glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // Use the second shader glUseProgram(program); // Bind framebuffer B glBindFramebuffer(GL_FRAMEBUFFER, fbo_B); // Bind texture A and setup texture units for the shader glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, tex_A); // Render output of FBO b is texture B glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex_B, 0); // 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); // Render a quad glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // Render the whole thing glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); [context presentRenderbuffer:GL_RENDERBUFFER]; glDeleteTextures(1, &amp;tex_A); glDeleteTextures(1, &amp;tex_B); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload