Trouble when rendering to slices of a 3D texture..

Hi…

So i lost all the text from my post with some weird manip… :frowning: So i’ll think i’ll be quicker this time… :slight_smile:

I’m running into trouble while trying to render to multiple slices of a 3d textures using FBO & GLSL & ARB_draw_buffers.
It looks like the data inside the 3D texure after querying it back to central memory is corrupted.
For starters, it is not impossible at all that there is some problem due to the way i use FBO extension :slight_smile:
so here is the source code for my FBO wrapper: http://pastebin.com/f62d8799b
I’m not getting any opengl error and the FBO status is complete after checking.
I’m using the renderTo3DTexture procedure afterwards this way:


	distmaptex = new texture3d( axisLengths[0], axisLengths[1], axisLengths[2], TEX_RGB_F32, NULL );
	distmaptex->filterNearest();

	// pass 1 init
	if (!shComputeDist2DSlice)
		shComputeDist2DSlice = new shader( "shDistanceMap2D" );

	shaderTextureSet *pass1Textures = new shaderTextureSet;
	pass1Textures->add( depthPeelTexPX, "texturePX", 0 );
	pass1Textures->add( depthPeelTexNX, "textureNX", 1 );
	pass1Textures->add( depthPeelTexPY, "texturePY", 2 );
	pass1Textures->add( depthPeelTexNY, "textureNY", 3 );

	shComputeDist2DSlice->attachTextures( pass1Textures );

	float *shComputeDist2DSlice_xInvSize = shComputeDist2DSlice->GetUniform( "xInvSize" );
	if (shComputeDist2DSlice_xInvSize) *shComputeDist2DSlice_xInvSize = 1.f / axisLengths[0];
	float *shComputeDist2DSlice_yInvSize = shComputeDist2DSlice->GetUniform( "yInvSize" );
	if (shComputeDist2DSlice_yInvSize) *shComputeDist2DSlice_yInvSize = 1.f / axisLengths[1];

	// pass 1
	renderTo3DTexture( shComputeDist2DSlice, "layer", "nLayers", "layerInvSize", distmaptex );

	float *testTex = new float [3*axisLengths[0]*axisLengths[1]*axisLengths[2]];
	glGetTexImage( GL_TEXTURE_3D, 0, GL_RGB, GL_FLOAT, testTex );

	for (int i=0; i<axisLengths[2]; i++)
	{
		int ind = 3*axisLengths[0]*axisLengths[1]*i;
		fprintf( glslLog, "%f
", testTex[ind] );
	}

	delete [] testTex;
	assert( glGetError() == GL_NO_ERROR );

Now some shader code:


varying vec2 uv;

uniform float layer;
uniform float layerInvSize;

void main()
{
	gl_FragData[0].rgb = vec3( layer + 0.0 );
	gl_FragData[1].rgb = vec3( layer + 1.0 );
	gl_FragData[2].rgb = vec3( layer + 2.0 );
	gl_FragData[3].rgb = vec3( layer + 3.0 );
	gl_FragData[4].rgb = vec3( layer + 4.0 );
	gl_FragData[5].rgb = vec3( layer + 5.0 );
	gl_FragData[6].rgb = vec3( layer + 6.0 );
	gl_FragData[7].rgb = vec3( layer + 7.0 );
}

Expected result would be to get increasing float32 values from 0 to 255 in this case, here is however the actual result:


0.000000
0.000000
0.000000
0.000000
4.000000
0.000000
0.000000
0.000000
8.000000
8.000000
8.000000
8.000000
12.000000
8.000000
8.000000
8.000000
16.000000
16.000000
16.000000
16.000000
20.000000
16.000000
16.000000
16.000000
24.000000
24.000000
.....
224.000000
232.000000
232.000000
232.000000
232.000000
236.000000
232.000000
232.000000
232.000000
240.000000
240.000000
240.000000
240.000000
244.000000
240.000000
240.000000
240.000000
248.000000
248.000000
248.000000
248.000000
252.000000
248.000000
248.000000
248.000000

So… anyone has an idea what i did wrong? :s
Last detail, hardware is a radeon 4870 under windows 7 64 bits using latest drivers (9.12)…

Regards and thank you for any help in advance… :slight_smile:

I still haven’t solved this one… Is it a driver bug or is there a problem in my code?

I’ll try d3d10 render to 3d texture too…

regards,

Packing ? Should not be a problem with GL_FLOAT however, but that does not hurt :
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
Did you try to write “3.0” everywhere, to verify if the problem is when adressing or when rendering ?
You do not detail your renderTo3DTexture, maybe a problem in it ?

Hi,

the renderTo3DTexture, is, well, in the wrapper code here: http://pastebin.com/f62d8799b (sorry for that non-obvious oddity).

I fixed it now, it seems we cannot use more than one color attachment per pass when rendering to a 3D texture. I have to explicitly disable MRT to make it work… (checking the NVIDIA opengl SDK volume rendering sample inspired that solution, they also don’t use MRT with rendering to 3D textures). For some reason ( i hardly believe i have a CPU bottleneck here :wink: ), the rendering time is now disappointing, but i prefer a slow and correct result to nothing of course! :slight_smile:

cheers & regards :slight_smile: