あなたの問題は、ほぼ400倍のテクスチャをバインドしていることがほぼ確実です。すべてのタイルを1つの大きなテクスチャアトラス/スプライトシートに入れ、テクスチャを再バインドするのではなく、アトラスを一度バインドして小さな部分を描画するだけです。これを行うと、実際に減速することなく何千ものタイルを描画できるはずです。
あなたはこのようなあなたのスプライトを描画することができます使用
//Push the matrix so we can keep it as it was previously.
glPushMatrix();
//Store the coordinates/dimensions from a rectangle.
float x = CGRectGetMinX(rect);
float y = CGRectGetMinY(rect);
float w = CGRectGetWidth(rect);
float h = CGRectGetHeight(rect);
float xOffset = x;
float yOffset = y;
if (rotation != 0.0f)
{
//Translate the OpenGL context to the center of the sprite for rotation.
glTranslatef(x+w/2, y+h/2, 0.0f);
//Apply the rotation over the Z axis.
glRotatef(rotation, 0.0f, 0.0f, 1.0f);
//Have an offset for the top left corner.
xOffset = -w/2;
yOffset = -h/2;
}
// Set up an array of values to use as the sprite vertices.
GLfloat vertices[] =
{
xOffset, yOffset,
xOffset, yOffset+h,
xOffset+w, yOffset+h,
xOffset+w, yOffset,
};
// Set up an array of values for the texture coordinates.
GLfloat texcoords[] =
{
CGRectGetMinX(clippingRect), CGRectGetMinY(clippingRect),
CGRectGetMinX(clippingRect), CGRectGetHeight(clippingRect),
CGRectGetWidth(clippingRect), CGRectGetHeight(clippingRect),
CGRectGetWidth(clippingRect), CGRectGetMinY(clippingRect),
};
//If the image is flipped, flip the texture coordinates.
if (flipped)
{
texcoords[0] = CGRectGetWidth(clippingRect);
texcoords[2] = CGRectGetWidth(clippingRect);
texcoords[4] = CGRectGetMinX(clippingRect);
texcoords[6] = CGRectGetMinX(clippingRect);
}
//Render the vertices by pointing to the arrays.
glVertexPointer(2, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
// Set the texture parameters to use a linear filter when minifying.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//Allow transparency and blending.
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//Enable 2D textures.
glEnable(GL_TEXTURE_2D);
//Bind this texture.
if ([Globals getLastTextureBound] != texture)
{
glBindTexture(GL_TEXTURE_2D, texture);
}
//Finally draw the arrays.
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
//Restore the model view matrix to prevent contamination.
glPopMatrix();
2 CGRectの私は簡単のためだけです。画像を描画するためのX、Y、幅、高さを指定することができます。また、clippingRectを使用して、描画する画像の位置を指定することもできます。クリッピング矩形では、(0、0、1、1)は画像全体ですが(0、0、0.25、0.25)は左上隅を描画するだけです。クリッピング矩形を変更することで、さまざまな種類のタイルを同じテクスチャにまとめることができます。一度バインドするだけで済みます。道は安い。
問題を特定するには、さらに詳しい情報が必要です。それぞれの異なるタイルイメージはロードされ、Open GLに1度だけテクスチャとして渡されますか?同様のタイルは同じテクスチャリソースを共有しますか?これらのタイルテクスチャイメージのサイズはどれくらいですか?いくつのタイルテクスチャがありますか?あなたはテクスチャをプリロードしていますか、それとも即座にロードしていますか? –
申し訳ありませんが、明確ではありませんでした。 私がテストしたものが遅かったことについて具体的に説明します: 初期化時には、大規模な(2048x2048)タイルセットイメージをPVRTextureクラス(Apple提供)としてロードします。また、initの間に、すべてのタイル頂点を1つの配列に作成します。その後、ループの最中に、テクスチャをバインドして大きな頂点配列のglDrawArraysを呼び出します。 –