所以我正在處理一堆2048x2048精靈表,它們很快填滿了內存。原樣,我使用下面的方法(通過雷Wenderlich)加載紋理:關於iOS紋理加載的OpenGL ES - 我如何從RGBA8888 .png文件獲取RGB565紋理?
- (GLuint)setupTexture:(NSString *)fileName
{
CGImageRef spriteImage = [UIImage imageNamed:fileName].CGImage;
if (!spriteImage)
{
NSLog(@"Failed to load image %@", fileName);
exit(1);
}
size_t width = CGImageGetWidth(spriteImage);
size_t height = CGImageGetHeight(spriteImage);
GLubyte * spriteData = (GLubyte *) calloc(width*height*4, sizeof(GLubyte));
CGContextRef spriteContext = CGBitmapContextCreate(spriteData, width, height, 8, width*4,CGImageGetColorSpace(spriteImage), kCGImageAlphaPremultipliedLast);
CGContextDrawImage(spriteContext, CGRectMake(0, 0, width, height), spriteImage);
CGContextRelease(spriteContext);
GLuint texName;
glGenTextures(1, &texName);
glBindTexture(GL_TEXTURE_2D, texName);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, spriteData);
GLenum err = glGetError();
if (err != GL_NO_ERROR)
NSLog(@"Error uploading texture. glError: 0x%04X", err);
free(spriteData);
return texName;
}
所以我的問題是,我如何丟棄來自CGImageα信息,然後在「下采樣」圖像以更少的每像素位,最後告訴OpenGL呢?
'uint8x8_t'類型在'arm_neon.h'中定義# – brigadir
精彩!不得不改變glTexImage2D線以下參數:'glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,寬度,高度,0,GL_RGB,GL_UNSIGNED_SHORT_5_6_5,spriteData);' – Jakob
偉大的答案,你看不到太多NEON代碼在那裏。爲了更加硬件無關,你有沒有考慮過使用Accelerate框架來實現它? –