gpt4 book ai didi

iphone - glReadPixels 清除 openGL ES 2 中的缓冲区?

转载 作者:行者123 更新时间:2023-12-03 18:40:17 26 4
gpt4 key购买 nike

我有一个 OpenGL ES 2 绘图应用程序 (iOS 4),因此我在 CAEAGLLayer 中保留支持,而不是清除每一帧:

eaglLayer.opaque = TRUE;
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:TRUE], kEAGLDrawablePropertyRetainedBacking,
kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat,
nil];

我有一个按钮,可以使用以下代码将作品保存到相册。问题就在这里。当保存完成并再次开始绘图时,整个缓冲区都会被清除,我的绘图将在空白屏幕上从头开始。有办法防止这种情况吗?我希望能够继续从我刚刚保存的状态进行绘图。

我正在运行相同的代码来保存在 OpenGL ES 1 中,并且不会出现此问题。此外,此问题仅在 iPhone 设备 (3GS) 上可见,在模拟器上不可见。如果您有想法请告诉我。谢谢。

-(void)saveCurrentScreenToPhotoAlbum 
{
CGRect rect = [[UIScreen mainScreen] bounds];
int width = rect.size.width;
int height = rect.size.height;

NSInteger myDataLength = width * height * 4;
GLubyte *buffer = (GLubyte *) malloc(myDataLength);
GLubyte *buffer2 = (GLubyte *) malloc(myDataLength);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

for(int y = 0; y <height; y++)
{
for(int x = 0; x <width * 4; x++)
{
buffer2[(int)((height - 1 - y) * width * 4 + x)] = buffer[(int)(y * 4 * width + x)];
}
}
free(buffer);

CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer2, myDataLength, releaseData);
int bitsPerComponent = 8;
int bitsPerPixel = 32;
int bytesPerRow = 4 * width;
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
CGImageRef imageRef = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);

CGColorSpaceRelease(colorSpaceRef);
CGDataProviderRelease(provider);

UIImage *image = [[UIImage alloc] initWithCGImage:imageRef]; // change this to manual alloc/init instead of autorelease
CGImageRelease(imageRef);

UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); // add callback for finish saving
}

// callback for CGDataProviderCreateWithData
void releaseData(void *info, const void *data, size_t dataSize)
{

free((void*)data);
}

// callback for UIImageWriteToSavedPhotosAlbum
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{

[image release];
}

最佳答案

安娜的回答。

我在执行此函数时进行了另一个调用,这导致缓冲区行为困惑

关于iphone - glReadPixels 清除 openGL ES 2 中的缓冲区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4306693/

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