How to specify maximum mipmap level in opengles?

This topic contains 5 replies, has 4 voices, and was last updated by  Gordon 6 years, 11 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #30072

    I specify the maximum mipmap level in opengl by the following code,but GL_TEXTURE_MAX_LEVEL not define in opengles.
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, maxLevel);

    I use mipmap function  by the following method, but the texture does not show:

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glTexImage2D(GL_TEXTURE_2D, 0, internalFormat,
                        width0, height0, 0,
                        internalFormat, dataType, data0);
    glTexImage2D(GL_TEXTURE_2D, 1, internalFormat,
                        width1, height1, 0,
                        internalFormat, dataType, data1);
    glTexImage2D(GL_TEXTURE_2D, 2, internalFormat,
                        width2, height2, 0,
                        internalFormat, dataType, data2);

    #33765

    Xmas
    Member
    mashangming wrote:
    I specify the maximum mipmap level in opengl by the following code,but GL_TEXTURE_MAX_LEVEL not define in opengles.

    Unfortunately this functionality does not exist in OpenGL ES. You have to provide a complete mipmap pyramid.

    #33766

    Thank you!
    I use compressed texture load each level of mipmap , when the width or high  is less than 4 ,loading failed OpenGLES return GL_INVALID_VALUE.Code is as follows:(level0 is 256*256)

        glGenTextures(1, &textureID);

        if(textureID == GL_INVALID_VALUE)
        {
            return NULL;
        }

        glBindTexture(GL_TEXTURE_2D , textureID );
       
        if (levelCount>1)
        {
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
        }
        else
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

       
       
        GLenum dataType;
        GLenum internalFormat = GetGLInternalPixelFormat(format,dataType);

        width = 256;
        height = 256;
       
        for(int mip=0; mip<levelCount; mip++)
        {

            glCompressedTexImage2D(GL_TEXTURE_2D, mip, internalFormat,
                    width, height, 0,
                    pixelDataSize, pixelData);
            width/=2;
            width = width?1:width;
            height/=2;
            height = height?1:height;
            pixelData +=pixelDataSize;
            pixelDataSize/=4;
        }

    #33767

    Xmas
    Member

    With PVRTC a texture level is always at least two blocks (4×4 pixels for 4bpp, 8×4 pixels for 2bpp) wide and high. However this only affects the imageSize argument, not width and height which still go down to 1×1 for the last level.

    Code:
        

    if (internalFormat == GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG ||

        internalFormat == GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG)

    {

        for(int mip=0; mip<levelCount; mip++)

        {

            pixelDataSize = MAX(width, 8) * MAX(height, 8) / 2;

            glCompressedTexImage2D(GL_TEXTURE_2D, mip, internalFormat,

                   width, height, 0,

                   pixelDataSize, pixelData);

            width/=2;

            width = width?1:width;

            height/=2;

            height = height?1:height;

            pixelData +=pixelDataSize;

        }

    }
    #33768

    Kris
    Member
    Xmas wrote:
    With PVRTC a texture level is always at least two blocks (4×4 pixels for 4bpp, 8×4 pixels for 2bpp) wide and high. However this only affects the imageSize argument, not width and height which still go down to 1×1 for the last level.

     

    So for the PVRTC miplevels below the minimum block size (i.e. 2×2, 1×1), you’re supposed to keep passing the minimum-size-block’s data into glCompressedTexImage2D, even though it represents an image that is larger than the width && height parameters passed to glCompressedTexImage2D indicate?

     

    Kris2010-11-05 00:07:42

    #33769

    Gordon
    Moderator
    Kris wrote:
    So for the PVRTC miplevels below the minimum block size (i.e. 2×2, 1×1), you’re supposed to keep passing the minimum-size-block’s data into glCompressedTexImage2D, even though it represents an image that is larger than the width && height parameters passed to glCompressedTexImage2D indicate?

    That’s correct.

Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic.