English 中文(简体)
OSMesa32中的点数为8比数。
原标题:Floating point numbers are quantized to 8-bits in OSMesa32
  • 时间:2012-05-01 11:00:08
  •  标签:
  • opengl
  • mesa

Mesa 3D声称通过osmesa32支持32条浮动点色道。 问题在于,浮点号被装入8轨! 是否有任何人注意到这一点? 下面是用于测试的短程Im。 您将看到我起草一份带有特定浮点颜色的平面图(全方位观点),然后读到第一页的颜色:

#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
", 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!
");
    return 0;
}

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

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

draw();

printf("RED: %f
", buffer[0]);
printf("GREEN: %f
", buffer[1]);
printf("BLUE: %f
", 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.50 1961=128/255,0.568627=145/255(即固定数目)。

我在我的玉米基础上建造了Mesa:

./configure --with-driver=osmesa --with-osmesa-bits=32 --disable-gallium --disable-egl
最佳回答

这是一个汇编问题。 在S_span.c ,你可以根据CHAN_TYPE(用mtypes.h加以界定)的价值,看到转换为GLubyte。

这一切都归于CHAN_BITS=32, 或不属于混淆。

在您的岗位上,我看到你再次为32个轨道设定了条件——但我们可能与不同的建筑合作——我把事情放在Windows上,与OSMesa接触——我看不到你。


我使用的是7.5.1——似乎是最后的Mesa和VS.sln。

向32个轨道设置通道导致中小企业协会失败。 请让我知道,你是否发现任何东西。

感谢!

问题回答

Try using a shader and vertex attributes instead of immediate mode - there s no warranty that glColor3f doesn t quantize anything it receives into 8 bit. I m not sure such warranty exists even on "real" OpenGL - as far as I can tell, glspec41-compatibility doesn t say anything about preserving color precision, but it contains some interesting passages like " As a result of limited precision, some converted values will not be rep- resented exactly." (2.13: Fixed-Function Vertex Lighting and coloring).





相关问题
OpenGL 3D Selection

I am trying to create a 3D robot that should perform certain actions when certain body parts are clicked. I have successfully (sort of) implemented picking in that if you click on any x-plane part, it ...

CVDisplayLink instead of NSTimer

I have started to implement cvDisplayLink to drive the render loop instead of nstimer, as detailed in this technical note https://developer.apple.com/library/archive/qa/qa1385/_index.html Is it ...

Can the iPhone simulator handle PVR textures?

I have a really weird problem with PVR textures on the iPhone simulator- the framerate falls through the floor on the iPhone simulator, but on the iPhone itself it works just fine. Has anyone had any ...

Calculate fps (frames per second) for iphone app

I am using an opengl es iphone application. What is the most accurate way to calculate the frames per second of my application for performance tuning?

Java - Zoom / 3D Data Visualization Libraries

What are the best libraries/frameworks for doing 3D and/or Zoom interfaces in Java? I d like to be able to do some prototyping of creating new types of interfaces for navigating within data and ...

FLTK in Cygwin using Eclipse (Linking errors)

I have this assignment due that requires the usage of FLTK. The code is given to us and it should compile straight off of the bat, but I am having linking errors and do not know which other libraries ...

热门标签