2

Mesa 3D 声称通过 osmesa32 支持 32 位浮点颜色通道。问题是,浮点数被量化为 8 位!有没有其他人注意到这一点?以下是我用于测试的简短程序。你会看到我用特定的浮点颜色绘制了一个平面(占据整个视图),然后读取第一个像素的颜色:

#include <stdio.h>
#include <stdlib.h>
#include "GL/osmesa.h"
#include "GL/glut.h"

#define WIDTH 100
#define HEIGHT 100

void draw()
{
GLint r, g, b, a;
glGetIntegerv(GL_RED_BITS, &r);
glGetIntegerv(GL_GREEN_BITS, &g);
glGetIntegerv(GL_BLUE_BITS, &b);
glGetIntegerv(GL_ALPHA_BITS, &a);
printf("channel sizes: %d %d %d %d\n", r, g, b, a);

glEnable(GL_DEPTH_TEST);


glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glTranslatef(0.0, 0.0, -1.0); 

// draw a plane
glBegin(GL_QUADS);
glColor3f(0.5f, 0.56789f, 0.568f);
glVertex3f(-1, -1, 0);
glVertex3f(-1, 1, 0);
glVertex3f(1, 1, 0);
glVertex3f(1, -1, 0);
glEnd();

glFinish();
}

int main( int argc, char *argv[] )
{
GLfloat *buffer;

/* Create an RGBA-mode context */
#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
/* specify Z, stencil, accum sizes */
OSMesaContext ctx = OSMesaCreateContextExt( GL_RGB, 16, 0, 0, NULL );
#else
OSMesaContext ctx = OSMesaCreateContext( GL_RGB, NULL );
#endif
if (!ctx) {
    printf("OSMesaCreateContext failed!\n");
    return 0;
}

/* Allocate the image buffer */
buffer = (GLfloat *) malloc( WIDTH * HEIGHT * 3 * sizeof(GLfloat));
if (!buffer) {
    printf("Alloc image buffer failed!\n");
    return 0;
}

/* Bind the buffer to the context and make it current */
if (!OSMesaMakeCurrent( ctx, buffer, GL_FLOAT, WIDTH, HEIGHT )) {
      printf("OSMesaMakeCurrent failed!\n");
      return 0;
}

draw();

printf("RED: %f\n", buffer[0]);
printf("GREEN: %f\n", buffer[1]);
printf("BLUE: %f\n", buffer[2]);

/* free the image buffer */
free( buffer );

/* destroy the context */
OSMesaDestroyContext( ctx );

return 0;
}

在绘图代码中,行:

glColor3f(0.5f, 0.56789f, 0.568f);

应该给我浮动颜色值。当我阅读颜色时,我得到以下输出:

channel sizes: 32 32 32 32
RED: 0.501961
GREEN: 0.568627
BLUE: 0.568627

您会注意到 0.501961 = 128/255,并且 0.568627=145/255(即量化)。

我在我的 Mac 上使用以下配置构建了 Mesa:

./configure --with-driver=osmesa --with-osmesa-bits=32 --disable-gallium --disable-egl
4

2 回答 2

1

尝试使用着色器和顶点属性而不是立即模式 - 不能保证 glColor3f 不会将接收到的任何内容量化为 8 位。我不确定即使在“真正的”OpenGL 上也存在这样的保证——据我所知,glspec41-compatibility 并没有说明任何关于保持颜色精度的内容,但它包含一些有趣的段落,比如“由于精度有限,某些转换后的值将无法准确表示。” (2.13:固定功能顶点照明和着色)。

于 2012-05-01T13:39:36.947 回答
0

这是一个编译问题。在 s_span.c 中,您可以看到基于 CHAN_TYPE 的值(在 mtypes.h 中定义)到 GLubyte 的转换。

一切都归结为 CHAN_BITS == 32 或不在 config.h 中。

我在您的帖子中看到您说您正在设置 32 位 - 但我们可能正在使用不同的构建 - 我正在使用 OSMesa 在 Windows 上进行操作 - 看起来你可能不是。


我正在使用 7.5.1 - 似乎是最后一个带有 VS.sln 的 Mesa。

将通道位设置为 32 会导致 OSMESA 失败。如果您发现任何问题,请告诉我。

谢谢!

于 2012-05-02T02:08:32.813 回答