简而言之:
谁能确认是否可以使用内置变量gl_InstanceID
(or gl_InstanceIDEXT
)在 iOS 上使用 OpenGL ES 2.0 的顶点着色器中GL_EXT_draw_instanced
启用?
Longer:
我想使用绘制一个对象的多个实例glDrawArrays实例化 https://www.khronos.org/opengles/sdk/docs/man3/html/glDrawArraysInstanced.xhtml and gl_实例ID https://www.khronos.org/opengles/sdk/docs/man3/html/gl_InstanceID.xhtml,并且我希望我的应用程序可以在多个平台上运行,包括 iOS。
规范明确指出这些功能需要ES 3.0。根据iOS 设备兼容性参考 https://developer.apple.com/library/ios/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/OpenGLESPlatforms/OpenGLESPlatforms.html#//apple_ref/doc/uid/TP40013599-CH106-SW1ES 3.0 仅在少数设备上可用(基于 A7 GPU 的设备;iPhone 5s,但不适用于 iPhone 5 或更早版本)。
所以我的第一个假设是我需要避免在旧版 iOS 设备上使用实例化绘图。
然而,再向下 https://developer.apple.com/library/ios/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/OpenGLESPlatforms/OpenGLESPlatforms.html#//apple_ref/doc/uid/TP40013599-CH106-SW7在兼容性参考文档中它说EXT_draw_instanced http://www.khronos.org/registry/gles/extensions/EXT/draw_instanced.txt所有 SGX 系列 5 处理器(包括 iPhone 5 和 4s)均支持扩展。
这让我觉得我确实也可以在旧版 iOS 设备上使用实例化绘图,方法是查找并使用适当的扩展函数(EXT 或 ARB)glDrawArrays实例化 https://www.khronos.org/opengles/sdk/docs/man3/html/glDrawArraysInstanced.xhtml.
我目前只是使用运行一些测试代码SDL http://libsdl.org/ and GLEW http://glew.sourceforge.net/在 Windows 上,所以我还没有在 iOS 上进行任何测试。
但是,在我当前的设置中,我无法使用gl_实例ID https://www.khronos.org/opengles/sdk/docs/man3/html/gl_InstanceID.xhtml顶点着色器中的内置变量。我收到以下错误消息:
'gl_InstanceID' :变量在当前 GLSL 版本中不可用
在 GLSL 中启用“draw_instanced”扩展没有效果:
#extension GL_ARB_draw_instanced : enable
#extension GL_EXT_draw_instanced : enable
当我明确声明我需要 ES 3.0 (GLSL 300 ES) 时,错误消失了:
#version 300 es
虽然这似乎在我的 ES 2.0 环境中的 Windows 台式机上运行良好,但我怀疑这是否能在 iPhone 5 上运行。
那么,我是否应该放弃在旧版 iOS 设备上使用实例化绘图的想法呢?