现在的照相机 动辄 照出 1300w 像素的在使用 opengl 处理时 会超出 纹理的限制
可用以下方法来判断
1 使用纹理代理的方法
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 不支持上面参数
-
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).
void glPixelStorei(GLenum pname,GLint param
)
;
GL_PACK_ALIGNMENT
The other storage parameter affects how pixel data is read from client memory:
-
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).
GL_UNPACK_ALIGNMENT
-
- 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
通过拆分图片 可以达到预期目的 不过需要注意 边缘位置