ios - iOS、android 之间的 glTexImage2D 错误细微差别- 不一致的文档

标签 ios textures opengl-es-2.0

所以我有这行代码:

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_ALPHAGL_LUMINANCEGL_LUMINANCE_ALPHAGL_RGBGL_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/

相关文章:

安卓 native OGLES2 : esLoadProgram not declared

ios - react-native-push-notification 在 ios 设备上不起作用

ios - 将 UISlider 旋钮移至中间,同时双击它

ios - -[EAGLContext renderbufferStorage :fromDrawable:] Failing the second time on?

c++ - SDL2 纹理操作教程无法执行 - Lazy Foo http ://lazyfoo.net/tutorials/SDL/40_texture_manipulation/index.php

three.js - 为什么透明度在我的网格上不起作用?

opengl-es - 我应该将 OpenGL 2.0 还是 1.0 与 libgdx 一起使用?

具有第二级子域的 iOS 通用链接不会深层链接到 native 应用程序,但在第一级子域(同一主机)上深层链接正常

ios - 带有快速下载按钮的视频播放器

opengl - 在单个纹理中存储多个纹理