gpt4 book ai didi

objective-c : Most efficient way to load a texture to OpenGL

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:21:09 26 4
gpt4 key购买 nike

目前,我使用 Image I/O 在 iOS 中加载纹理,并使用 Core Graphics 提取其图像数据。然后我可以像这样将图像数据发送到 OpenGL:

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->width, texture->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture->imageData);

问题是 Core Graphics 部分真的很慢,我需要使用 Core Graphics 进行设置和绘制,只是为了提取图像数据……我不想在屏幕上显示它。一定有更高效的方法来提取 iOS 中的图像数据吗?...

这是我的代码:

...
myTexRef = CGImageSourceCreateWithURL((__bridge CFURLRef)url, myOptions);
...
MyTexture2D* texture;

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

void *imageData = malloc( tileSize.width * tileSize.height * 4 );

CGContextRef imgContext = CGBitmapContextCreate( imageData, tileSize.width, tileSize.height, 8, 4 * tileSize.width, colorSpace, kCGImageAlphaNoneSkipLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease( colorSpace );
CGContextClearRect( imgContext, CGRectMake( 0, 0, tileSize.width, tileSize.height ) );
CGContextTranslateCTM( imgContext, 0, 0 );
...
CGImageRef tiledImage = CGImageCreateWithImageInRect (imageRef, tileArea);
CGRect drawRect = CGRectMake(0, 0, tileSize.width, tileSize.height);

// *** THIS CALL IS REALLY EXPENSIVE!
CGContextDrawImage(imgContext, drawRect, tiledImage);

CGImageRelease(tiledImage);

// TamTexture2D takes the ownership of imageData and will be responsible to free it
texture = new MyTexture2D(tileSize.width, tileSize.height, imageData);

CGContextRelease(imgContext);

最佳答案

如果您正在为 iOS 5 及更高版本开发,GLKTextureLoader是你要找的:

关于 objective-c : Most efficient way to load a texture to OpenGL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11347804/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com