开发者

How to determine which error i'm receiving, when calling glTexSubImage2d

I'm trying to draw some texture with CAOpenGLLayer, but receiving GL_INVALID_OPERATION when i try to call glTexSubImage2d. According to this document : http://www.opengl.org/sdk/docs/man/xhtml/glTexSubImage2D.xml it's one of the errors described there. But seems i'm not breaking any rule described there and i don't understand what i'm doing wrong. Here is a code that i'm trying to run:

- (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat
{
    uint32_t plugin_width = 32, plugin_height = 32;

    texture_data = new uint8_t[plugin_width * plugin_height * 4];


    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity();

    glScalef(1.0f, -1.0f, 1.0f);
    glOrtho(0, plugin_width , 0, plugin_height , -1.0, 1.0);

    glActiveTexture(GL_TEXTURE0);
    glEnable(GL_TEXTURE_RECTANGLE_EXT);
    glGenTextures(1, &textureName); 
    glBindTexture(GL_TEXTURE_RECTANGLE_EXT, textureName);
    glTextureRangeAPPLE(GL_TEXTURE_RECTANGLE_EXT, plugin_width * plugin_height * 4, texture_data);
    glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_STORAGE_HINT_APPLE , GL_STORAGE_SHARED_APPLE);

    glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

    glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA, plugin_width, plugin_height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, texture_data);      
    glBindTexture(GL_TEXTURE_RECTANGLE_EXT, 0);

    return [super copyCGLContextForPixelFormat:pixelFormat];
}

- (void)drawInCGLContext:(CGLContextObj)ctx pixelFormat:(CGLPixelFormatObj)pf forLayerTime:(CFTimeInterval)t displayTime:(const CVTimeStamp *)ts 
{
    uint32_t plugin_width = 32, plugin_height = 32;
    uint32_t width  = plugin_width;
    uint32_t height = plugin_height;


    srand(time(NULL));
    for (int i = 0; i < 32*32*4; i ++)
        texture_data[i] = rand() % 255;

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_RECTANGLE_EXT, textureName);


    glTexSubImage2D (GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, width, height,GL_BGRA, GL_UNSIGNED_INT_8_8_8_8 ,texture_data);  

    assert(glGetError() == GL_NO_ERROR); // here i'm getting GL_INVALID_OPERATION

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glBegin(GL_QUADS);

    glTexCoord2f(0.0f,0.0f);
    glVertex2f(0.0f, 0.0f);

    glTexCoord2f(1.0f,0.0f);
    glVertex2f(width, 0);

    glTexCoord2f(0.0f,1.0f);
    glVertex2f(0, height);

    glTexCoord2f(1.0f,1.0f);
    glVertex2f(width, height);      
    glEnd();


    [super drawInCGLC开发者_开发问答ontext:ctx pixelFormat:pf forLayerTime:t displayTime:ts];
}


Did you try to replace the external format GL_UNSIGNED_INT_8_8_8_8 with GL_UNSIGNED_BYTE in both calls (glTexImage2D and glTexSubImage2D)? That might help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜