Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS使用OpenGL绘图命令从for循环更新ui_Ios_For Loop_Opengl Es - Fatal编程技术网

iOS使用OpenGL绘图命令从for循环更新ui

iOS使用OpenGL绘图命令从for循环更新ui,ios,for-loop,opengl-es,Ios,For Loop,Opengl Es,我正在编写一个iOS绘图应用程序。 我有一个for循环,里面有OpenGL绘图命令。 现在,我必须在for循环中更新一些UI,每更新一步 但问题是OpenGL命令和UI更新代码都应该在主线程中运行。所有UI更新代码都将运行,直到for循环完成 有没有办法解决延迟for循环以更新ui的问题 更新: //flood fill for (int i = 0; i < width; i += FloodFillStep) { for (int j = 0; j < height;

我正在编写一个iOS绘图应用程序。 我有一个for循环,里面有OpenGL绘图命令。 现在,我必须在for循环中更新一些UI,每更新一步

但问题是OpenGL命令和UI更新代码都应该在主线程中运行。所有UI更新代码都将运行,直到for循环完成

有没有办法解决延迟for循环以更新ui的问题

更新:

//flood fill 
for (int i = 0; i < width; i += FloodFillStep) {
    for (int j = 0; j < height; j += FloodFillStep) {
        CGPoint point = CGPointMake(i, j);            
        GLubyte *data = (GLubyte*)malloc(4 * sizeof(GLubyte));
        // Read pixel data from the framebuffer
        glReadPixels(point.x, point.y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, data);
        if (data[3] != 0) {
            free(data);
            continue;
        }
        free(data);

        unsigned int byteIndex = (self.maskData.bytesPerRow * roundf(point.y)) + roundf(point.x) * self.maskData.bytesPerPixel;
        unsigned long int maskIndex =  getMaskCode(byteIndex, self.maskData.maskIndexData);

        if ([dic valueForKey:[NSString stringWithFormat:@"%lu", maskIndex]]) {
            continue;
        }

        [dic setValue:[NSNumber numberWithBool:true] forKey:[NSString stringWithFormat:@"%lu", maskIndex]];

        [[REGLWrapper current] bindFramebufferOES:self.brushTexture.frameBuffer discardHint:true clear:true];

        const CGFloat *components = CGColorGetComponents(self.autoFillColorSystem.resultColor.CGColor);
        glClearColor(components[0], components[1], components[2], components[3]);
        glClear(GL_COLOR_BUFFER_BIT);

        self.brush.brushState.maskIndex = [ACFloodFill maskIndexWithMaskData:self.maskData atPoint:point];

        [[REGLWrapper current] bindFramebufferOES:self.curPaintedLayerTexture.frameBuffer discardHint:true clear:false];

        [self drawQuad:self.VAOQuad brush:self.brush.brushState texture2D:self.brushTexture.texID alpha:1.0];

        //            [self updateFinalRender];
    }

    DebugLog(@"autoFloodfill updateUIBlock percent %.2f", (CGFloat)i / (CGFloat)width * 100);
    if (updateUIBlock) {
        updateUIBlock((CGFloat)i / (CGFloat)width * 100);
    }
}
//洪水填充
对于(int i=0;i
听起来你做的事情真的很奇怪。for循环的每一步都会发生什么?渲染代码应该在每次屏幕刷新都会触发一次的事件循环中完成,所以您的for循环似乎是在进行冗余绘制。也许可以发布一些代码来帮助我们了解您的想法。doRender循环是复杂的事情。你读过关于这个主题的文章了吗?我已经发布了我的代码。我正在为我的绘图应用程序开发洪水填充功能。因为该过程需要一些时间,所以我想用完成百分比将ui更新为nortify user。您是否从当前帧缓冲区执行glReadPixels(),然后将某些内容渲染到同一帧缓冲区?这是非常糟糕的做法…听起来你做的事情真的很奇怪。for循环的每一步都会发生什么?渲染代码应该在每次屏幕刷新都会触发一次的事件循环中完成,所以您的for循环似乎是在进行冗余绘制。也许可以发布一些代码来帮助我们了解您的想法。doRender循环是复杂的事情。你读过关于这个主题的文章了吗?我已经发布了我的代码。我正在为我的绘图应用程序开发洪水填充功能。因为该过程需要一些时间,所以我想用完成百分比将ui更新为nortify user。您是否从当前帧缓冲区执行glReadPixels(),然后将某些内容渲染到同一帧缓冲区?这是非常糟糕的做法。。。