Wie weiß das iPhone, welcher Kontext OpenGL ES zwischen 1.1 und 2.0 zu benutzen?
-
04-10-2019 - |
Frage
Ich habe vor kurzem im Netz zu graben um und bemerkte, einige Video-Tutorials zeigen eine ältere Vorlage (pre SDK 3.2) mit einem OpenGL ES Kontext. Nun gibt es zwei von ihnen, die ich aufgelesen haben, werden die beiden Versionen von OpenGL ES auf den neueren iMobile Geräte.
Kann ich nur die ältere oder muss ich alles zweimal tun? Wie kann ich das iPhone erzählen die älteren Kontext zu verwenden, oder wird es tun so automatisch?
Lösung
Standardmäßig werden die Vorlage versucht, einen ES2 Kontext zu schaffen, und wenn dies fehlschlägt, versucht dann, einen ES1 Kontext zu schaffen. Wenn Sie mit ES 1.1 alleine arbeiten wollen (die auf allen Geräten unterstützt wird), können Sie einfach alle Referenzen aus der Vorlage Projekt ES2 löschen.
Andere Tipps
To expand upon what Frogblast said, the template code defines two classes: ES1Renderer
and ES2Renderer
. The EAGLView
class first tries to create an ES2Renderer
instance, but if that fails it creates an ES1Renderer
. The failure comes about if the ES2Renderer
is unable to set up an OpenGL ES 2.0 context using the following code:
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if (!context || ![EAGLContext setCurrentContext:context] || ![self loadShaders])
{
[self release];
return nil;
}
If a device supports OpenGL ES 2.0, this should succeed. If not, the application falls back to the ES1Renderer
OpenGL ES 1.1 renderer.
The reason the application has two different rendering classes is that OpenGL ES 1.1 and 2.0 have different and incompatible rendering pipelines. OpenGL ES 2.0 lets you create programmable shaders for some stunning effects, but it can be more difficult to use for simple tasks than OpenGL ES 1.1.
Many people add fallbacks to their application if they use OpenGL ES 2.0, because only the iPhone 3G S and later devices have support for this never API. However, if you are developing an iPad-only application, you can assume it will have 2.0 support. You could also restrict your application to running on devices with this capability by adding the opengles-2
key to the UIRequiredDeviceCapabilities
in your Info.plist.
You can use OpenGL ES 1.1 just fine on the newer devices, so if you want to disable the 2.0 rendering path you can have the EAGLView in the template ignore the ES2Renderer
class and just work with the ES1Renderer
. You could also take the OpenGL ES code from the ES1Renderer
and just place it within the EAGLView.