The use of KxMovie and GPUImage conflict

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/shengpeng3344/article/details/84945157

Problem Description

Used in the project GPUImage for camera capture, while the data using OpenGL the soft solution rendering, where draws logic code KxMovie when both operations, such GPUImage image inverted by 90 degrees, and splash screen, image distortion, here to share some of the issues under KxMovie, the other GPUImage there are some issues that need improvement

1, KxMovie rendered view size sometimes inaccurate

When the small-screen and full-frame switching, OpenGL rendering size is not set correctly, the relevant code is as follows

- (void)layoutSubviews
{
    glBindRenderbuffer(GL_RENDERBUFFER, _renderbuffer);
    [_context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer];
    glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &_backingWidth);
    glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &_backingHeight);
    
    GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
    if (status != GL_FRAMEBUFFER_COMPLETE) {
        
        NSLog(@"failed to make complete framebuffer object %x", status);
        
    } else {
        
        NSLog(@"OK setup GL framebuffer %d:%d", _backingWidth, _backingHeight);
        NSLog(@"OK setup GL %@", NSStringFromCGRect(self.frame));
    }
    
    [self updateVertices];
    [self render: nil];
}

Should be set before each operation currentContext, the code before it is added to a

[EAGLContext setCurrentContext:_context];

Solve

2, KxMovie GPUImage with the lead layer overlapping images flipped 90 degrees GPUImage

Do not try to ensure initialized with a UIView like two opengles layer, or a lot of unexpected problems

3, GPUImage preview flicker problem

This problem only after the creation KxMovie, appear, there is no specific reason is set to release currentContext opengl environment variables, GPUImage in its own thread set currentContext, multithreading context can lead to confusion

- (void)cleanRender
{
    if ([EAGLContext currentContext] != _context) { // add this line , to resolve shine
        [EAGLContext setCurrentContext:_context];
    }
    _renderer = nil;
    
    if (vertex_shader) {
        glDeleteShader(vertex_shader);
        vertex_shader = 0;
    }
    
    if (fragment_shader) {
        glDeleteShader(fragment_shader);
        fragment_shader = 0;
    }
    
    if (_framebuffer) {
        glDeleteFramebuffers(1, &_framebuffer);
        _framebuffer = 0;
    }
    
    if (_renderbuffer) {
        glDeleteRenderbuffers(1, &_renderbuffer);
        _renderbuffer = 0;
    }
    
    if (_program) {
        glDeleteProgram(_program);
        _program = 0;
    }
    
    glFinish(); // add this line , need finish
    
    if ([EAGLContext currentContext] == _context) {
        [EAGLContext setCurrentContext:nil];
    }
    _context = nil;
    
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
    
}

Comparing the source specific reference KxMovie
all be provided in the context keep consistent thread to the operating element of the variable opengl

In addition GPUImage also have a watermark problem https://blog.csdn.net/shengpeng3344/article/details/84944765

Guess you like

Origin blog.csdn.net/shengpeng3344/article/details/84945157