Home › Forums › Syphon › Syphon Implementations – User › Writing syphon texture into GPUImage framebuffer problem
- This topic has 0 replies, 1 voice, and was last updated 2 years, 4 months ago by eight.
Viewing 1 post (of 1 total)
-
AuthorPosts
-
October 19, 2018 at 2:33 pm #59723eightParticipant
I am reading a syphon texture from a syphon client into GPUImage outputframebuffer, but the image in the said buffer is textured wrongly.
[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]; }); };
-
AuthorPosts
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.