关于OpenGL ES的glTexImage2D API的问题

关于OpenGL ES的glTexImage2D API的问题

目前我在做一个iphone上的wmv播放器,采用OpenGL ES画屏。在decoder之后得到RGBA数据,调用glTexImage2D画屏。正常情况下,这个API花费4 ms,但是每隔30-40帧左右,就会有一次调用的时间在12ms左右,远远大于平均时间,此时CPU load只有60%,造成播放的时候会感觉到停顿。

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, frameData);

使用OpenGL ES 1.0, RGBA格式,代码片段如下,有懂的朋友请指教.

context = [[EAGLContext alloc] initWithAPI: kEAGLRenderingAPIOpenGLES1];

。。。

    glDisable(GL_DEPTH_TEST);
    glDisable(GL_ALPHA_TEST);
    glDisable(GL_LIGHTING);
    glDisable(GL_BLEND);
    glDisable(GL_DITHER);

    glEnable(GL_TEXTURE_2D);    
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

。。。


        eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                        [NSNumber numberWithBool: NO], kEAGLDrawablePropertyRetainedBacking,
                                        kEAGLColorFormatRGBA8,
                                        kEAGLDrawablePropertyColorFormat,
                                        nil];
。。。

    glGenFramebuffersOES(1, &frameBuffer);
    glGenRenderbuffersOES(1, &renderBuffer);
    
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, frameBuffer);
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, renderBuffer);
    
    [context renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: (CAEAGLLayer *)_view.layer];
    glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, renderBuffer);
    
    if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
        
        return NO;


。。。
    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
    
    /* Set viewport size to match the renderbuffer size */
    int glX = 0;
    int glY = 0;
    glViewport(glX, glY, backingWidth, backingHeight);
    
    /* Setup orthographic projection mode */
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrthof(0, backingWidth, 0, backingHeight, -1.0, 0);
    
    /* Reset the matrix mode to model/view */
    glMatrixMode(GL_MODELVIEW);


最后画屏

    [EAGLContext setCurrentContext: context];
    glClear(GL_COLOR_BUFFER_BIT);

        //这里速度每隔30-40帧变慢
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, frameData);    
    
       glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
    glVertexPointer(2, GL_FLOAT, 0, vertices);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);            
                                                    
    /* All rendered, so make render buffer appear on the screen */
    [context presentRenderbuffer: GL_RENDERBUFFER_OES];

你可能感兴趣的:(api,buffer,float,byte,Blend,Matrix)