Instanced drawing with OpenGL ES 2.0 on iOS

左心房为你撑大大i 提交于 2019-12-13 11:51:03

问题


In short:

Can anyone confirm whether it is possible to use the built-in variable gl_InstanceID (or gl_InstanceIDEXT) in a vertex shader using OpenGL ES 2.0 on iOS with GL_EXT_draw_instanced enabled?


Longer:

I want to draw multiple instances of an object using glDrawArraysInstanced and gl_InstanceID, and I want my application to run on multiple platforms, including iOS.

The specification clearly says that these features require ES 3.0. According to the iOS Device Compatibility Reference ES 3.0 is only available on a few devices (those based on the A7 GPU; so iPhone 5s, but not on iPhone 5 or earlier).

So my first assumption was that I needed to avoid using instanced drawing on older iOS devices.

However, further down in the compatibility reference document it says that the EXT_draw_instanced extension is supported for all SGX Series 5 processors (that includes iPhone 5 and 4s).

This makes me think that I could indeed use instanced drawing on older iOS devices too, by looking up and using the appropriate extension function (EXT or ARB) for glDrawArraysInstanced.

I'm currently just running some test code using SDL and GLEW on Windows so I haven't tested anything on iOS yet.

However, in my current setup I'm having trouble using the gl_InstanceID built-in variable in a vertex shader. I'm getting the following error message:

'gl_InstanceID' : variable is not available in current GLSL version

Enabling the "draw_instanced" extension in GLSL has no effect:

#extension GL_ARB_draw_instanced : enable
#extension GL_EXT_draw_instanced : enable

The error goes away when I specifically declare that I need ES 3.0 (GLSL 300 ES):

#version 300 es

Although that seem to work fine on my Windows desktop machine in an ES 2.0 context I doubt that this would work on an iPhone 5.

So, shall I abandon the idea of being able to use instanced drawing on older iOS devices?


回答1:


From here:

Instanced drawing is available in the core OpenGL ES 3.0 API and in OpenGL ES 2.0 through the EXT_draw_instanced and EXT_instanced_arrays extensions.

You can see that it's available on all of their GPUs, PowerVR SGX, Apple A7, A8.

(Looks like @Shammi's not coming back... if they do, you can change the accepted answer :)



来源:https://stackoverflow.com/questions/25387959/instanced-drawing-with-opengl-es-2-0-on-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!