【问题标题】:iPhone original render faster than iPhone 3GS?iPhone原版渲染速度比iPhone 3GS快?
【发布时间】:2011-05-05 12:03:51
【问题描述】:

我正在 iPhone 上开发一款使用 C++ 和 OpenGL ES 1.x 库的游戏。 它在模拟器上运行良好。但是当我将它安装在真机上时,我发现在 iPhone 原版上,渲染一帧大约需要 20 毫秒。然而,在 iPhone 3GS 上渲染一帧需要 35~40 毫秒。

我尝试过各种操作系统,包括 3GS + iOS 3.1.2、3G + iOS 4.0、3GS + iOS 4.1、iPad + iOS 3.2。它们的渲染速度都比 iPhone 原版慢得多,这对我来说听起来很荒谬。我用谷歌搜索了我能想到的任何东西,修复了所有可能与之相关的问题,但没有任何改变。

我有 2 台机器,这些代码的渲染速度更快:1) iPhone 原装 iOS 3.1.3,2) iPod Touch 和 iOS 3.1.3。两者都花了大约 20 毫秒来渲染一帧。 还有 4 台机器的渲染速度出奇地慢:1) iPhone 3G 运行 iOS 4.0,2) iPhone 3GS 运行 iOS 3.1.2,3) iPhone 3GS 运行 iOS 4.1,4) iPad 运行 iOS 3.2。 iPhone 大约需要 35-40 毫秒来渲染一帧,而 iPad 大约需要 25 毫秒。

我使用 PVRTC 制作质地,首先将其煮熟并制成一束。它总共使用十个 512x512 纹理,三个 1024x1024 纹理。 绑定纹理的代码如下:

 GLenum internalFormat = 0;
 GLenum pixelType      = 0;

 // resolve type
 ResetFlags_();
 assert(2==attr.Dimension && 1==attr.Depth);
 switch (attr.Format) 
 {
 case FORMAT_PVRTC2:
  assert(attr.Width==attr.Height);
  if (attr.AlphaBits>0)
   internalFormat = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  else
   internalFormat = GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  break; 
 case FORMAT_PVRTC4:
  assert(attr.Width==attr.Height);
  if (attr.AlphaBits>0)
   internalFormat = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  else
   internalFormat = GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  break;

  ... other formats ...

 }

 // prepare temp buffer to load
 MemoryBuffer tmpBuffer(true);
 uint8* buffer = tmpBuffer.GetWritePtr(attr.TextureSize);

 // read data
 stream.Read(buffer, attr.TextureSize);
 if (stream.Fail())
  return false;

 // init
 width_    = attr.Width;
 height_    = attr.Height;
 LODs_    = attr.LODs;
 alphaBits_ = attr.AlphaBits;

 // create and upload texture
 glGenTextures(1, &glTexture_);
 glBindTexture(GL_TEXTURE_2D, glTexture_);

 uint32 offset = 0;
 uint32 dim    = width_; // = height
 uint32 w, h;
 switch (internalFormat)
 {
 case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG:
 case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG:
 case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG:
 case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG:
  for (uint32 i=0; i<LODs_; ++i) {
   assert(offset<attr.TextureSize);
   w = dim >> ((FORMAT_PVRTC2==attr.Format) ? 3:2);
   h = dim >> 2;

   // Clamp to minimum number of blocks
   if (w<2) w = 2;
   if (h<2) h = 2;

   uint32 const image_size = w * h * 8; //  8 bytes for each block
   glCompressedTexImage2D(GL_TEXTURE_2D, i, internalFormat, dim, dim, 0, image_size, buffer+offset);
   dim >>= 1;
   offset += image_size;
   break;

  ... other formats ...

 }


 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); // tri-linear?
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

 SetContext_(&glTexture_);
 return true;

渲染部分很大,因为它使用了别人开发的引擎。据我所知,它使用 glDrawArrays 并且没有使用着色器。

有人遇到过同样的问题吗?我真的不明白为什么 iPhone 原版的渲染速度比 iPhone 3GS 快。

附言我忘了说。我只绘制带有纹理的 2D 矩形。在我的游戏中大约有 20 个矩形(一个背景和一个 480x360 大小的 UI。其他通常是 64x64 单位。)

【问题讨论】:

  • 你在使用粒子系统吗?你提到的引擎是cocos2d吗?
  • 不,我没有使用粒子系统。该引擎不是cocos2D,它是一个用C++编写的引擎,最初是在PC上,然后移植到iPhone上。

标签: iphone performance opengl-es iphone-3gs


【解决方案1】:

您得到的行为可能是由于可能通过可编程管道(即着色器)模拟固定功能管道 (FFP)。

您能否执行一个测试,以某种方式加载和显示您的纹理,完全无需您的引擎。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-15
    • 1970-01-01
    相关资源
    最近更新 更多