gpt4 book ai didi

ios - opengl中的内存增长

转载 作者:行者123 更新时间:2023-11-28 20:09:40 26 4
gpt4 key购买 nike

我的绘画应用程序中有更改画笔的代码。一切正常,但我发现,如果我多次调用该方法,内存不会释放,并且会越来越大...而且我找不到它在哪里?

- (void)setBrush:(UIImage *)brush withColor:(UIColor *)color andOpacity:(CGFloat)opacity andSize:(CGFloat)size {
CGImageRef brushImage;
CGContextRef brushContext;
GLubyte *brushData;
size_t width, height;
brushImage = brush.CGImage;
width = CGImageGetWidth(brushImage);
height = CGImageGetHeight(brushImage);
if(brushImage) {
brushData = (GLubyte *) calloc(width * height * 4, sizeof(GLubyte));
brushContext = CGBitmapContextCreate(brushData, width, height, 8, width * 4, CGImageGetColorSpace(brushImage), (CGBitmapInfo)kCGImageAlphaPremultipliedFirst);
CGContextDrawImage(brushContext, CGRectMake(0.0, 0.0, (CGFloat)width, (CGFloat)height), brushImage);
CGContextRelease(brushContext);
glGenTextures(1, &brushTexture);
glBindTexture(GL_TEXTURE_2D, brushTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, brushData);
free(brushData);
}
CGColorRef clr = [color CGColor];
const CGFloat *components = CGColorGetComponents(clr);
CGFloat red = components[0];
CGFloat green = components[1];
CGFloat blue = components[2];
glColor4f(red * opacity/3, green * opacity/3, blue * opacity/3, opacity/3);
glPointSize(width * size / 2);
}

它可能在哪里,它是如何纠正的?

最佳答案

您永远不会删除使用 glGenTextures() 创建的纹理,因此您只需分配越来越多的空间来容纳所有纹理数据。

关于ios - opengl中的内存增长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20785946/

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