PBuffer and glCopyTexSubImage2D

Ave!

I worte a ShadowMapping demo some days ago that copied the contents of the depthbuffer to a depthtexture via glCopyTexSubImage2D and then projected that onto the scene.
That went fine, but the problem was that the shadowmaps resolution had to be smaller or equal to the size of the applications viewport.

So I decided to use PBuffers for offscreen-rendering, to avoid this limitation.I then wrote an PBuffer-class that works fine, and the scene gets correctly rendered to to the PBuffer.
But after the scene from the lights point-of-view is in the PBuffers framebuffer, I want to copy the depthcomponents of it to my depthtexture that’s needed for shadowmapping.But when doing this with glCopyTexSubImage2D I don’t get a correct shadow-texture.

So could someone please take a look at these screenshots and tell me what I’ve done wrong ?

The scene from the viewers point-of-view : http://www.delphigl.de/misc/pbuffer3.jpg
The scene from the lights point-of-view rendered to the PBuffer : http://www.delphigl.de/misc/pbuffer1.jpg
And the depthtexture after getting the depthcomponents of the PBuffer : http://www.delphigl.de/misc/pbuffer2.jpg

So something must have gone wrong, as the texture even is wrong when I copy the contents of the PBuffers framebuffer instead its depthvalues.

Looks like your CopyTexSubImage parameters are wrong. It seems to be copying one line of the source to the entire destination, e.g. the single line is stretched vertically. Comparing the 2nd and 3rd images it appears to be a line from somewhere near the bottom of the source image.

Might want to make sure you created
your pbuffer glContext so it can share textures
with your display context.

@tbfx :
I’m already sharing textures between the context of my app and the pixelbuffer.Only reason you don’t see any textures in the PBuffer is that I don’t render any textured object (the room on which the objects cast shadows) when rendering the scene from the light’s point-of-view.

@paulc :
I don’t think that this line is wrong, because it works flawlessly when I use plain copy-to-texture instead of rendering to the pbuffer.

But perhaps something isn’t compatible with the PBuffer, so here are some parts of the Delphi-sourecode…

Creating the depth-texture to which the depthvalues of the PBuffer will get copied :
PixelBuffer.Enable;
glGenTextures(1, @ShadowTexture);
glBindTexture(GL_TEXTURE_2D, ShadowTexture);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, PixelBuffer.Width, PixelBuffer.Height, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_SHADOW_AMBIENT_SGIX, 0.6);
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
PixelBuffer.Disable;

Copying the depthvalues of the PBuffer to the depthtexture :
PixelBuffer.Enable;
// Set light’s pov, Polygonoffset and draw the scene
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, PixelBuffer.Width, PixelBuffer.Height);
PixelBuffer.Disable;

PixelBuffer.Enable - Activate PBuffers RC
PixelBuffer.Disable - Switch Back to the Apps’s DC

That are the most important parts of the code, and I can’t find the problem…