PDA

View Full Version : FBO + glGetTexImage == no go?



ScottManDeath
05-10-2005, 07:08 AM
I'm using NV_float_buffer, ARB_texture_rectangle, EXT_framebuffer_object and GLSL (using the 2.0 entrypoints) for doing GPGPU on a GF FX 5600 go, with the 76.91 drivers.

I have a problem with readback of the data. I render into a single channel 32 bit float texture. After that, I would like to use glGetTexImage to get the results back. But it seems that glGetTexImage returns the texture image as if there were no rendering. The returned image is identical to that specified using glTexSubimage before rendering. Perhaps the driver is bugged and returns a RAM cached version and doesn't copy it back from the GPU?
If I use glReadPixels, the data returns as it should. I checked the specs, there seems to be no restrictions of using glGetTexImage. So could this be a bug?

Here is the commented glIntercept (great tool btw :) )log [why isn't it possible to nest the CODE and the B tag :( ]:

// creating of the rendertarget texture
glGenTextures(1,0xb713fc)
glGetError()=GL_NO_ERROR
glBindTexture(GL_TEXTURE_RECTANGLE_ARB,1)
glGetError()=GL_NO_ERROR
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTUR E_MAG_FILTER,GL_NEAREST)
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTUR E_MIN_FILTER,GL_NEAREST)
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTUR E_WRAP_S,GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB,GL_TEXTUR E_WRAP_T,GL_CLAMP_TO_EDGE)
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB,0,GL_FLOAT_R 32_NV,4,7,0,GL_RED,GL_FLOAT,0x0000)
glGetError()=GL_NO_ERROR
glBindTexture(GL_TEXTURE_RECTANGLE_ARB,0)
glGetError()=GL_NO_ERROR

// downloading data
glBindTexture(GL_TEXTURE_RECTANGLE_ARB,1)
glGetError()=GL_NO_ERROR
glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB,0,0,0,4,7 ,GL_RED,GL_FLOAT,0xb71498)
glGetError()=GL_NO_ERROR
glBindTexture(GL_TEXTURE_RECTANGLE_ARB,0)
glGetError()=GL_NO_ERROR
glBindTexture(GL_TEXTURE_RECTANGLE_ARB,1)
glGetError()=GL_NO_ERROR

// ... again
glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB,0,0,0,4,7 ,GL_RED,GL_FLOAT,0xb71498)
glGetError()=GL_NO_ERROR
glBindTexture(GL_TEXTURE_RECTANGLE_ARB,0)
glGetError()=GL_NO_ERROR
glBindTexture(GL_TEXTURE_RECTANGLE_ARB,1)
glGetError()=GL_NO_ERROR

// ... readback, works
glGetTexImage(GL_TEXTURE_RECTANGLE_ARB,0,GL_RED,GL _FLOAT,0xb715a0)
glGetError()=GL_NO_ERROR
glBindTexture(GL_TEXTURE_RECTANGLE_ARB,0)
glGetError()=GL_NO_ERROR

// framebuffer setup
glGenFramebuffersEXT(1,0xb7149c)
glGetError()=GL_NO_ERROR
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,1)
----->wglDescribePixelFormat(0x5011a43,1,0,0x0000)=102
glGetError()=GL_NO_ERROR
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_CO LOR_ATTACHMENT0_EXT,GL_TEXTURE_RECTANGLE_ARB,1,0)
glGetError()=GL_NO_ERROR

// Shader Setup
glCreateProgram()=1
glGetError()=GL_NO_ERROR
glCreateShader(GL_VERTEX_SHADER)=2
glGetError()=GL_NO_ERROR
glShaderSource(2,1,0xb73d98,0x0000)
glGetError()=GL_NO_ERROR
glCompileShader(2)
glGetError()=GL_NO_ERROR
glGetShaderiv(2,GL_COMPILE_STATUS,0x12f234)
glGetError()=GL_NO_ERROR
glAttachShader(1,2)
glGetError()=GL_NO_ERROR
glCreateShader(GL_FRAGMENT_SHADER)=3
glGetError()=GL_NO_ERROR
glShaderSource(3,1,0xb73ee8,0x0000)
glGetError()=GL_NO_ERROR
glCompileShader(3)
glGetError()=GL_NO_ERROR
glGetShaderiv(3,GL_COMPILE_STATUS,0x12f234)
glGetError()=GL_NO_ERROR
glAttachShader(1,3)
glGetError()=GL_NO_ERROR
glLinkProgram(1)
glGetProgramiv(1,GL_VALIDATE_STATUS,0x12f4a8)
glGetError()=GL_NO_ERROR
glValidateProgram(1)
glGetProgramiv(1,GL_VALIDATE_STATUS,0x12f2c0)
glGetError()=GL_NO_ERROR

// binding framebuffer
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,1)
glGetError()=GL_NO_ERROR
glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)=GL _FRAMEBUFFER_COMPLETE_EXT
glGetError()=GL_NO_ERROR
glValidateProgram(1)
glGetProgramiv(1,GL_VALIDATE_STATUS,0x12f3ac)
glGetError()=GL_NO_ERROR

// start of rendering
glUseProgram(1)
glGetError()=GL_NO_ERROR

glViewport(0,0,4,7)
// warnings are ok, NV_float_buffer allows unclamped values for this
glClearColor(8.760000- Invalid clamped value,
8.770000- Invalid clamped value,
8.780000- Invalid clamped value,
8.790000- Invalid clamped value)
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(0.500000,0.600000,0.700000)

glBegin(GL_QUADS) GLSL=1
glVertex2f(-1.000000,-1.000000)
glVertex2f(1.000000,-1.000000)
glVertex2f(1.000000,1.000000)
glVertex2f(0.000000,1.000000)
glEnd()
glGetError()=GL_NO_ERROR

// readback with glReadPixels, works :)
glReadPixels(0,0,4,7,GL_RED,GL_FLOAT,0xb71840)
glGetError()=GL_NO_ERROR

// unbinding shader & frambuffer
glUseProgram(0)
glGetError()=GL_NO_ERROR
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0)
glGetError()=GL_NO_ERROR

// readback with glGetTeximage, sucks :(
glBindTexture(GL_TEXTURE_RECTANGLE_ARB,1)
glGetError()=GL_NO_ERROR
glGetTexImage(GL_TEXTURE_RECTANGLE_ARB,0,GL_RED,GL _FLOAT,0xb71840)
glGetError()=GL_NO_ERROR
glBindTexture(GL_TEXTURE_RECTANGLE_ARB,0)
glGetError()=GL_NO_ERROR

// cleanup
glDeleteProgram(1)
glDeleteShader(2)
glDeleteShader(3)
glDeleteFramebuffersEXT(1,0xb7149c)
glDeleteTextures(1,0xb713fc)

// done
wglMakeCurrent(0x0000,0x0000)=true
wglDeleteContext(0x10000)=true [ /CODE]

Korval
05-10-2005, 09:15 AM
nVidia's implementation of FBO is still beta; it may not always work as expected.

As a simple (potential) workaround, you could just use glReadPixels while the texture is bound as the framebuffer.

ScottManDeath
05-10-2005, 09:25 AM
Originally posted by Korval:
nVidia's implementation of FBO is still beta; it may not always work as expected.

As a simple (potential) workaround, you could just use glReadPixels while the texture is bound as the framebuffer.Yes, glReadPixels will be the workaround until they "unbeta" their drivers ;) And I'll don't add PBO to the mix until the other stuff is working :)