当我使用GL_HALF_FLOAT_OES纹理时;片段着色器似乎写得很好,我可以观察到它在xCode中使用gpuTrace时具有正确的值。但是当我用
回读它时glReadPixels( 0, 0, self.imageSize->v[0], self.imageSize->v[1], GL_RGBA, type, pixels );
像素组件浮动-0或浮动1.是否因为浮动值被意外剪切?有没有办法回读最初编写的浮点值?如果我使用GL_RGBA16F_EXT
或GL_RGBA32F_EXT
代替GL_RGBA
,我会收到无效的枚举。
根据Rabbid76的反馈
int formatExt, typeExt;
glGetIntegerv( GL_IMPLEMENTATION_COLOR_READ_FORMAT, &formatExt );
glGetIntegerv( GL_IMPLEMENTATION_COLOR_READ_TYPE, &typeExt );
[ self traceLog:[ NSString stringWithFormat:@"Implementation format is %@, type is %@", [ TextureImage strForFormat:formatExt ], [ TextureImage strForType:typeExt ] ] ];
返回的值是“实现格式为GL_RGBA,类型为GL_HALF_FLOAT_OES”。这可能意味着HALF_FLOAT是它能够回读的唯一值。我仍在调查它是否有可能回读GL_FLOAT,因为尽管glGetIntegerv返回glReadPixels没有用无效的枚举标记GL_FLOAT;它接受并处理它,但漂浮物似乎不是正确的漂浮物;所以它似乎做了一些意想不到的转换。
答案 0 :(得分:1)
See the documentation of glReadPixels
(OpenGL ES 3.1) which says:
void glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid * data);
format
Specifies the format of the pixel data. The following symbolic values are accepted:GL_RGBA
, andGL_RGBA_INTEGER
. An implementation-chosen format will also be accepted. This can be queried withglGet
andGL_IMPLEMENTATION_COLOR_READ_FORMAT
.
type
Specifies the data type of the pixel data. Must be one ofGL_UNSIGNED_BYTE
,GL_UNSIGNED_INT
,GL_UNSIGNED_INT_2_10_10_10_REV
,GL_INT
, orGL_FLOAT
. An implementation-chosen type will also be accepted. This can be queried withglGet
andGL_IMPLEMENTATION_COLOR_READ_TYPE
.
This means you have to read the implementation-chosen format
and type
, to read back the float values as they were originally written:
int format = glGet(GL_IMPLEMENTATION_COLOR_READ_FORMAT);
int type = glGet(GL_IMPLEMENTATION_COLOR_READ_TYPE);
glReadPixels(
0, 0, self.imageSize->v[0], self.imageSize->v[1],
format, type, pixels );
See the documentation of glGet
(OpenGL ES 3.1):
GL_IMPLEMENTATION_COLOR_READ_FORMAT
params returns one value, the format chosen by the implementation in which pixels may be read from the color buffer of the currently bound framebuffer.
GL_IMPLEMENTATION_COLOR_READ_TYPE
params returns one value, the type chosen by the implementation with which pixels may be read from the color buffer of the currently bound framebuffer.