Jump to content
  • Advertisement
Sign in to follow this  

GL_RGBA4 and FBO problem

This topic is 4532 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I think i've found a problem using FBO's and GL_RGBA4 textures. The problem lies in wrong color conversion when writing a value into FBO. For example, when I write the color 0.167969, I get the 0.2 value inside the buffer. But when I write 0.171875 (=0.167969+1.0/256), the buffer is updated with a value of 0.1333333, which is smaller than 0.2! Writtig the value 0.175781 (=0.171875+1.0/256) updates the buffer with a value of 0.2 again. So, basically, when I write 256 values from 0.0 to 1.0 in +1.0/256 steps, the resulting readback from the FBO is not in an ascending order! Following is the source that shows the problem I mentioned. I modified the source found on gpgpu.org, so that the texture internal format is GL_RGBA4.
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glut.h>

static texSize = 8;
static GLenum textarget = GL_TEXTURE_2D;
static GLenum texinternalformat = GL_RGBA4;

int main(int argc, char **argv) {
    // declare texture size, the actual data will be a vector 
    // of size texSize*texSize*4
    // create test data and fill arbitrarily
    float* data = (float*)malloc(4*texSize*texSize*sizeof(float));
    float* result = (float*)malloc(4*texSize*texSize*sizeof(float));

	// Make a 256-element texture. 
	//Each element is +1.0/256 greater than the previous one. 
	for (int i=0; i<4*texSize*texSize; i++)
		data = ((float)i)/256.0;

	// set up glut to get valid GL context and 
    // get extension entry points
    glutInit (&argc, argv);
    // viewport transform for 1:1 pixel=texel=data mapping
    // create FBO and bind it (that is, use offscreen render target)
    GLuint fb;
    // create texture
    GLuint tex;
    glGenTextures (1, &tex);
    // set texture parameters
    glTexParameteri(textarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(textarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(textarget, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(textarget, GL_TEXTURE_WRAP_T, GL_CLAMP);
    // define texture with floating point format
    // attach texture
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, textarget,tex,0);

	GLenum status = glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT );
	switch( status )
			printf("FBO complete!\n");
			printf("FBO wrong!\n");
	// transfer data to texture
	glReadPixels(0, 0, texSize, texSize,GL_RGBA,GL_FLOAT,result);
    // print out results
    for (int i=0; i<texSize*texSize*4; i++)
		printf("%d:\t %f quantized to %f\n",i, data, result);
    glDeleteFramebuffersEXT (1,&fb);
    glDeleteTextures (1,&tex);
    return 0;
A few lines from the program output:
54:      0.210938 quantized to 0.200000
55:      0.214844 quantized to 0.200000
56:      0.218750 quantized to 0.266667
57:      0.222656 quantized to 0.266667
58:      0.226563 quantized to 0.266667
59:      0.230469 quantized to 0.266667
60:      0.234375 quantized to 0.200000
61:      0.238281 quantized to 0.200000
62:      0.242188 quantized to 0.266667
63:      0.246094 quantized to 0.266667
64:      0.250000 quantized to 0.200000
65:      0.253906 quantized to 0.266667
66:      0.257813 quantized to 0.266667
The problem does not show when the format is GL_RGBA. The buffer testing in booth cases says that the buffer is complete. The quantization errors might be small, but I have a huge problem with this. I use the RGBA4 to render each scene polygon using different color, which is used for visibility check in a realtime radiosity GPGPU project. There a few pixels on the scene that fail the visibility check even if they are visible, just because of this problem. I'm using an ATIx1800xl and 6.5 driver on WinXP. Can someone check if there is a similar problem on NV cards?

Share this post

Link to post
Share on other sites
Original post by Kambiz
I get a "FBO wrong!" message...
Geforce 6800GT
ForceWare version 84.21

Looks like NVidia doesn't support GL_RGBA4 attached to a FBO :( ...

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!