所以我有这行代码:
glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT,shadow_tex_dim.x,shadow_tex_dim.y,0,GL_DEPTH_COMPONENT,GL_FLOAT,shadow_texture_data);
在 android(运行 OpenGLES2)(和 OSX)上建立深度纹理效果很好。
当我在 iOS 中运行它时(iOS 10,也运行 OpenGLES2
), glGetError()
返回 GL_INVALID_OPERATION
。 (glGetError()
就在该行返回干净之前)。
这是 glTexImage2D
的文档:http://docs.gl/es2/glTexImage2D
请注意,“internalformat”指定唯一有效的参数是“GL_ALPHA
、 GL_LUMINANCE
、 GL_LUMINANCE_ALPHA
、 GL_RGB
、 GL_RGBA
”,但在“示例”部分下方,它显示 glTexImage2D(GL_TEXTURE_2D, 0,
GL_D EPTH_COMPONENT , fbo_width, fbo_height, 0,
GL_DEPTH_COMPONENT ,
GL_UNSIGNED_BYTE , NULL);
(非常相似到我当前的行,但使用 GL_UNSIGNED_BYTE
而不是 GL_FLOAT
。
那么,我可以使用 GL_DEPTH_COMPONENT
吗?为什么这适用于 android 的 OpenGLES2
而不是 iOS?我从哪里得知我应该使用 GL_FLOAT
(请注意,无论哪种方式在 iOS 或 android 上行为似乎都没有改变...)?
最佳答案
Apple 对深度纹理的支持将在此处定义:https://www.khronos.org/registry/gles/extensions/OES/OES_depth_texture.txt
文档中有 2 个相关领域:
Textures with and values of DEPTH_COMPONENT refer to a texture that contains depth component data. is used to determine the number of bits used to specify depth texel values.
A value of UNSIGNED_SHORT refers to a 16-bit depth value. A value of UNSIGNED_INT refers to a 32-bit depth value.
和
The error INVALID_OPERATION is generated if the and is DEPTH_COMPONENT and is not UNSIGNED_SHORT, or UNSIGNED_INT.
这也很有趣:https://www.opengl.org/wiki/Common_Mistakes
In OpenGL, all depth values lie in the range [0, 1]. The integer normalization process simply converts this floating-point range into integer values of the appropriate precision. It is the integer value that is stored in the depth buffer.
Typically, 24-bit depth buffers will pad each depth value out to 32-bits, so 8-bits per pixel will go unused. However, if you ask for an 8-bit Stencil Buffer along with the depth buffer, the two separate images will generally be combined into a single depth/stencil image. 24-bits will be used for depth, and the remaining 8-bits for stencil.
Now that the misconception about depth buffers being floating point is resolved, what is wrong with this call?
glReadPixels(0, 0, width, height, GL_DEPTH_COMPONENT, GL_FLOAT, my pixels);
Because the depth format is a normalized integer format, the driver will have to use the CPU to convert the normalized integer data into floating-point values. This is slow.
Android 似乎支持深度纹理的 GL_FLOAT
类型。
关于ios - iOS、android 之间的 glTexImage2D 错误细微差别- 不一致的文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39606483/