C++ と OpenGL ES 1.x ライブラリを使用する iPhone のゲームに取り組んでいます。シミュレータ上では問題なく動作します。しかし、実際の iPhone にインストールしてみると、オリジナルの iPhone では 1 フレームのレンダリングに約 20 ミリ秒かかることがわかりました。ただし、iPhone 3GS では 1 フレームのレンダリングに 35 ~ 40 ミリ秒かかりました。
3GS + iOS 3.1.2、3G + iOS 4.0、3GS + iOS 4.1、iPad + iOS 3.2 など、さまざまな OS を試しました。それらはすべて、iPhone のオリジナルよりもはるかにレンダリングが遅く、私にはばかげているように思えます。関連する可能性のあるすべての問題を修正して、考えられることは何でもグーグルで試しましたが、何も変わりませんでした。
これらのコードがより高速にレンダリングされるマシンが 2 台あります。1) iOS 3.1.3 を搭載した iPhone オリジナル、2) iOS 3.1.3 を搭載した iPod Touch。どちらも、フレームのレンダリングに約 20 ミリ秒かかりました。不可解なほど遅くレンダリングする 4 つのマシン: 1) iOS 4.0 を搭載した iPhone 3G、2) iOS 3.1.2 を搭載した iPhone 3GS、3) iOS 4.1 を搭載した iPhone 3GS、4) iOS 3.2 を搭載した iPad。iPhone はフレームのレンダリングに約 35 ~ 40 ミリ秒かかり、iPad は約 25 ミリ秒かかりました。
PVRTC を食感に使用し、最初に調理して束にします。512x512 のテクスチャを合計 10 個、1024x1024 のテクスチャを 3 個使用します。テクスチャをバインドするコードは次のとおりです。
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 よりもはるかに高速である理由がまったくわかりません。
ps言い忘れました。テクスチャのみで 2D の長方形のみを描画します。私のゲームでは約 20 の長方形です (1 つの背景と 480x360 サイズの 1 つの UI。その他は通常 64x64 ユニットです)。