如何处理超出 GL_MAX_TEXTURE_SIZE 的图片

现在的照相机 动辄 照出 1300w 像素的在使用 opengl 处理时 会超出 纹理的限制

可用以下方法来判断

使用纹理代理的方法

GLint width = 0;
while ( 0 == width ) {  /* use a better condition to prevent possible endless loop */
    glTexImage2D(GL_PROXY_TEXTURE_2D, 
                      0,                /* mip map level */
                      GL_RGBA,          /* internal format */
                      desiredWidth,     /* width of image */
                      desiredHeight,    /* height of image */
                      0,                /* texture border */
                      GL_RGBA           /* pixel data format, */ 
                      GL_UNSIGNED_BYTE, /* pixel data type */
                      NULL              /* null pointer because this a proxy texture */
    );

    /* the queried width will NOT be 0, if the texture format is supported */
    glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);

    desiredWidth /= 2; desiredHeight /= 2;
}
返回值为零 说明超出限制 宽高除二以后继续查看返回值。

2 根据 GL_MAX_TEXTURE_SIZE 的返回值进行修改

glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);


  • Image tiling: use multiple quads after splitting your image into smaller supported chunks. Image tiling for something like a splash screen should not be too tricky. You can use glPixelStorei's GL_PACK_ROW_LENGTH parameter to load sections of a larger image into a texture.
  • 将图片分割
  • opengl es2.0 不支持上面参数
    void glPixelStorei(GLenum pname,GLint param);

    GL_PACK_ALIGNMENT

    Specifies the alignment requirements for the start of each pixel row in memory. The allowable values are 1 (byte-alignment), 2 (rows aligned to even-numbered bytes), 4 (word-alignment), and 8 (rows start on double-word boundaries).

    The other storage parameter affects how pixel data is read from client memory:

    GL_UNPACK_ALIGNMENT

    Specifies the alignment requirements for the start of each pixel row in memory. The allowable values are 1 (byte-alignment), 2 (rows aligned to even-numbered bytes), 4 (word-alignment), and 8 (rows start on double-word boundaries).


  • Image resizing: resize your image to fit the maximum supported texture size. There's even a GLU helper function to do this for you, gluScaleImage.
  • 图像缩放 将图片缩放到支持的纹理大小
所以处理大图片还需进行分割。

一段拆分的代码
void ProcessChunk(unsigned char *pImage, int x, int y, int width, int height);

#define MIN(a, b) ((a) < (b) ? (a) : (b))    
#define CHUNKSIZE 64

void ProcessImage(unsigned char *pImage, int nWidth, int nHeight)
{
    int x, y;

    for (x = 0; x < nWidth; x += CHUNKSIZE)
        for (y = 0; y < nHeight; y += CHUNKSIZE)
            ProcessChunk(pImage, x, y, MIN(nWidth - x, CHUNKSIZE), MIN(nHeight - y, CHUNKSIZE));
}

http://stackoverflow.com/questions/4761365/i-have-a-1024x1024-png-i-want-to-split-it-into-64x64-256-equal-parts

通过拆分图片 可以达到预期目的 不过需要注意 边缘位置

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值