gpt4 book ai didi

ios - GL_HALF_FLOAT_OES 和 glReadPixels

转载 作者:行者123 更新时间:2023-11-29 11:40:51 25 4
gpt4 key购买 nike

当我使用 GL_HALF_FLOAT_OES 纹理时;片段着色器似乎可以很好地写入它,当我在 xCode 中使用 gpuTrace 时,我可以观察到它具有正确的值。但是当我使用

读回它时
glReadPixels( 0, 0, self.imageSize->v[0], self.imageSize->v[1], GL_RGBA, type, pixels );

像素分量要么 float -0 要么 float 1。这是因为 float 值被意外剪切了吗?有没有办法读回最初写入的浮点值?如果我使用 GL_RGBA16F_EXTGL_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;它接受并处理它,但 float 似乎不是正确的 float ;所以它似乎在进行一些意想不到的转换。

最佳答案

请参阅 glReadPixels (OpenGL ES 3.1) 的文档其中说:

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, and GL_RGBA_INTEGER. An implementation-chosen format will also be accepted. This can be queried with glGet and GL_IMPLEMENTATION_COLOR_READ_FORMAT.

type
Specifies the data type of the pixel data. Must be one of GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, GL_UNSIGNED_INT_2_10_10_10_REV, GL_INT, or GL_FLOAT. An implementation-chosen type will also be accepted. This can be queried with glGet and GL_IMPLEMENTATION_COLOR_READ_TYPE.


这意味着您必须读取实现选择的 formattype,以读回最初写入的浮点值:

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 );


请参阅 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.

关于ios - GL_HALF_FLOAT_OES 和 glReadPixels,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46626336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com