Writing syphon texture into GPUImage framebuffer problem

Home Forums Syphon Syphon Implementations – User Writing syphon texture into GPUImage framebuffer problem

This topic contains 0 replies, has 1 voice, and was last updated by  eight 4 weeks ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #59723

    eight
    Participant

    I am reading a syphon texture from a syphon client into GPUImage outputframebuffer, but the image in the said buffer is textured wrongly.
    red background added for clarity

    [outputframebuffer is a means to pass images between the filters in GPUImage framework]

    Spent a week trying to debug it, and now kindly asking for support.

    
    static const GLfloat squareVertices[] = {
        -1.0f, -1.0f,
        1.0f, -1.0f,
        -1.0f,  1.0f,
        1.0f,  1.0f,
    };
    
    static const GLfloat textureCoordinates[] = {
        -1.0f, -1.0f,
        1.0f, -1.0f,
        -1.0f,  1.0f,
        1.0f,  1.0f,
    };
    
    NSString *const kGPUImageSyphonVertexShaderString = SHADER_STRING
    (
     attribute vec4 position;
     attribute vec4 inputTextureCoordinate;
     
     varying vec2 textureCoordinate;
     
     void main()
     {
         gl_Position = position;
         textureCoordinate = inputTextureCoordinate.xy;
     }
     );
    
    NSString *const kGPUImageSyphonFragmentShaderString = SHADER_STRING
    (
     varying vec2 textureCoordinate;
     uniform sampler2DRect inputImageTexture;
     uniform float width;
     uniform float height;
     
     void main()
     {
         vec2 texCoord = vec2(textureCoordinate.x * width, textureCoordinate.y*height);
         gl_FragColor = texture2DRect(inputImageTexture, texCoord);
     }
     );
    
    -(void) processSyphonFrame:(SyphonClient*) client;
    {
        CGLContextObj context = CGLGetCurrentContext();
        runSynchronouslyOnVideoProcessingQueue(^{
                // ...then we check to see if our dimensions display or window shape needs to be updated
                SyphonImage *syFrame = [client newFrameImageForContext:context];
    
                GLsizei w = syFrame.textureSize.width;
                GLsizei h = syFrame.textureSize.height;
                
                ///================draw to output framebuffer
                [GPUImageContext useImageProcessingContext];
    
                //this fbo already has a texture attached to it (to write into)
                outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:CGSizeMake(w, h) textureOptions:self.outputTextureOptions onlyTexture:NO];
    
                [self->outputFramebuffer lock];
    
                //bind framebuffer and set the viewport
                [outputFramebuffer activateFramebuffer];
    
                //clear framebuffer attachments -- a hint for future ops to ignore the existing content
                glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
                glClear(GL_COLOR_BUFFER_BIT);
                
                [GPUImageContext setActiveShaderProgram:syphonImageConversionProg];
                
                //now, specify the source texture for the framebuffer
                //first select an active texture unit
                //////
                glActiveTexture(GL_TEXTURE0);
                glClientActiveTexture(GL_TEXTURE0);
                glEnable(GL_TEXTURE_RECTANGLE_ARB);
    
                glBindTexture(GL_TEXTURE_RECTANGLE_EXT, syFrame.textureName);
    
                GLint whichID;
                glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &whichID);
                if (whichID != syFrame.textureName) {
                    NSLog(@"did not bind syphon texture");
                }
    
            // Configure texturing as we want it
                glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP);
                glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP);
                glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
                glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                
                glUniform1i (inputImageTextureUniform, 0);
                glUniform1f (widthUniform, w);
                glUniform1f (heightUniform, h);
                
                glVertexAttribPointer(syPosAttribute, 2, GL_FLOAT, 0, 0, squareVertices);
                glVertexAttribPointer(syTexCoordAttribute, 2, GL_FLOAT, 0, 0, textureCoordinates);
                glEnableVertexAttribArray(syPosAttribute);
                glEnableVertexAttribArray(syTexCoordAttribute);
                //finally, draw to the buffer
                glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    
                if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE){
                    NSLog(@"framebuffer incomplete");
                }
                glBindFramebuffer(GL_FRAMEBUFFER, 0);
            
    
    //for debugging save the image
                CGImageRef imageRef = [outputFramebuffer newCGImageFromFramebufferContents];
                CGImageWriteToFile(imageRef, @"/Users/eigh_io/tmp.png");
    //end saving the image
                [self updateTargetsForSyphonUsingCacheTextureAtWidth:w height:h];
    
        });
    };
    • This topic was modified 4 weeks ago by  eight.
    • This topic was modified 4 weeks ago by  eight.
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.