• 9
• 16
• 15
• 12
• 9

# incredible slow copy from depth buffer

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

## Recommended Posts

i'm fiddeling around here with a technic used in shadow mapping: copying the depth-buffer to a texture and use it later on. now for compatibility reason i use glCopyTexSubImage2D, which i do already for color-to-texture copies. now the strange thing is that color-to-texture is speedy and quick whereas depth-to-texture copies are so horribly slow you can't even belief it ( 3 or 4 frames per second with depth-to-texture but color-to-texture runs with 50 or more ). any ideas why copy from depth buffer is nearly 10 times slower than copy from the color buffer? i'm doing the following:
	OGL_CHECK( glGenTextures( 1, &pTexture ) );
OGL_CHECK( glBindTexture( GL_TEXTURE_2D, pTexture ) );
OGL_CHECK( glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ) );
OGL_CHECK( glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ) );
OGL_CHECK( glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ) );
OGL_CHECK( glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ) );
OGL_CHECK( glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ) );
int newRealWidth, newRealHeight;
for( newRealWidth=1; newRealWidth<width; newRealWidth<<=1 );
for( newRealHeight=1; newRealHeight<height; newRealHeight<<=1 );
OGL_CHECK( glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, newRealWidth,
newRealHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL ) );
OGL_CHECK( glCopyTexSubImage2D( GL_TEXTURE_2D,
0, // mimap level
0, newRealHeight - height, // texture offset
x, y, // render target offset
width, height ) );

with x=0, y=0, width=800, height=600.

##### Share on other sites
Are You doing all this every frame or just glCopyTexSubImage()? Try using framebuffer objects and rectangle textures.

##### Share on other sites
nope, i do only the glCopyTexSubImage2D each frame but for summary purpose cut together all here. tested it on my stronger dev-machine and there it worked flawlessly. i suppose i overflow the ram on my older pc resulting in the slowdown.

framebuffer objects i put in after things stabalized for speed up. for the moment i have to develope 'conservative' for older machines... which is not so easy.

considering those rectangular textures: i read the ARB extension for it but i don't get them. it sounds like a nice plan but there are some things i don't get so far especially how the texture coordinates work. i read once that you have to access rectangular textures with int coords ( hence 0, 1, 2, ... n-1 ). is that right or do i still use 0.0-1.0 ?

##### Share on other sites
Do you by any chance have an ATI card? I used glCopyTexSubImage2D() to copy the depth-buffer to a texture in an older program of mine without any problems. When I updated my video-drivers my app went from 400fps to +/- 5fps. I seems newer ATI drivers have issues with glCopyTexSubImage2D(), for some reason.

FBO's (Frame Buffer Objects) are the way to go.

##### Share on other sites
i have two ATI and an NVidia card for testing here.i use linux too so i have anyways not the windows drivers but the linux counterparts. so far it worked out. i'll scale down the textures on runtime by factor two on that slower machine to see if i really simply overflowed the ram of my graphic card.

some tutorial about FBOs around? i poked only quickly into it but so far i didn't fully get the principle of them. i hope the FBO is a generic extension and not windows specific as i am deving on a linux machine.

##### Share on other sites
Quote:
 Original post by RPTDi hope the FBO is a generic extension and not windows specific as i am deving on a linux machine.

Yes it is and You should use it. Try rectangular textures.

Quote:
 you have to access rectangular textures with int coords ( hence 0, 1, 2, ... n-1 ). is that right or do i still use 0.0-1.0 ?

You have to use int values to access rect. tex. The mapping is: 1 - one textel.

##### Share on other sites
i'll look at the FBO once upon time. currently i noticed my major speed problem to be with the amount of triangles rendered but completly hidden. tried occlusion query extension but i get out-of-memory error all the time. looks like i need to come up with a technic on my own for that :| .

concerning rectangular textures: they don't work. i have no idea why but whereas TEXTURE_2D is now working ( i got some mipmap code litering around that made it break ) i simply can not get rect textures to work no matter what i do ( always black ). i checked the extensions doc but i see nothing in the preconditions that i is not fullfilled. furthermore i can anyways not use mipmapping with rect textures which is a problem. any ideas why rect textures simply do not want to work whereas the 2d ones do? they don't work neither on ati nor on nvidia cards i coult test ( again with no error message at all ).

##### Share on other sites
Quote:
 any ideas why rect textures simply do not want to work whereas the 2d ones do?

Can You post Your texture initialization code?

##### Share on other sites
mostly same as above.

init:
	OGL_CHECK( glGenTextures( 1, &pTexture ) );				OGL_CHECK( glBindTexture( GL_TEXTURE_RECTANGLE_ARB, pTexture ) );				OGL_CHECK( glTexImage2D( GL_TEXTURE_RECTANGLE_ARB, 0, GL_DEPTH_COMPONENT,					pWidth, pHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL ) );		OGL_CHECK( glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ) );		OGL_CHECK( glCopyTexSubImage2D( GL_TEXTURE_RECTANGLE_ARB,			0, // mimap level			0, 0, // texture offset			x, y, // render target offset			pWidth, pHeight ) );

usage:
		OGL_CHECK( glEnable( GL_TEXTURE_RECTANGLE_ARB ) );		OGL_CHECK( glBindTexture( GL_TEXTURE_RECTANGLE_ARB, pTexture ) );		OGL_CHECK( glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ) );		OGL_CHECK( glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ) );		OGL_CHECK( glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ) );		OGL_CHECK( glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ) );		pSetMatrix( GL_TEXTURE, decMatrix::CreateTranslation( -rx, -ry, 0.0 ) );[/quote]hence exactly the same as the TEXTURE_2D one but just with another target.