gpt4 book ai didi

iphone - 像这样加载openGL纹理是否正确?

转载 作者:行者123 更新时间:2023-12-03 19:42:57 25 4
gpt4 key购买 nike

几个月前,我开始了一个 OpenGL 项目,该项目变得越来越大......我从 crashLanding 示例开始,并使用 Texture2D。

我还使用单例类来加载我的纹理,这是纹理加载的样子:

//Load the background texture and configure it
_textures[kTexture_Background] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"fond.png"]];
glBindTexture(GL_TEXTURE_2D, [_textures[kTexture_Background] name]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

// Load the textures
_textures[kTexture_Batiment] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"batiment_Ext.png"]];
_textures[kTexture_Balcon] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"balcon.png"]];
_textures[kTexture_Devanture] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"devanture.png"]];
_textures[kTexture_Cactus_Troncs] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"cactus-troncs.png"]];
_textures[kTexture_Cactus_Gauche] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"cactus1.png"]];
_textures[kTexture_Cactus_Droit] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"cactus2.png"]];
_textures[kTexture_Pierre] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"pierre.png"]];
_textures[kTexture_Enseigne] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"enseigne.png"]];
_textures[kTexture_Menu] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"saloonIntro.jpg"]];
_textures[kTexture_GameOver] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"gameOver.jpg"]];

for (int i = 0 ; i < kNumTexturesScene ; i ++)
{
[arrayOfText addObject:[[[NSData alloc] init] autorelease]];
}
// sort my array
for (int i = 0 ; i < kNumTexturesScene ; i ++)
{
[arrayOfText replaceObjectAtIndex:i withObject:_textures[i]];
}

[dictionaryOfTexture setObject:[arrayOfText copy] forKey:kTextureDecor];
[arrayOfText removeAllObjects];

等等近50张图片

它在 3GS 上运行良好,但有时在 3G 上会出现一些问题。

我这一切都错了吗?

谢谢

最佳答案

您需要考虑的事项:

  • iPhone 仅适用于尺寸为 2 的幂的纹理 - 如果您的纹理没有这样的尺寸,但它们仍然有效,这意味着它们会被软件调整大小 - 这需要时间等等重要的是有值(value)的纹理内存。
  • iPhone 的视频内存可容纳大约 3 个 1024x1024 大小的纹理 - 您可能会耗尽纹理内存。
  • 渲染期间切换纹理很慢...非常慢。切换纹理越少越好 - 理想情况下,最多创建 3 个纹理,并最多切换 3 次
  • 要实现这一目标,您需要学习一种名为 texture atlasing 的技术

关于iphone - 像这样加载openGL纹理是否正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2154372/

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