On Tuesday, November 23, 2004, at 10:58PM, Nicholas Francis <email@hidden> wrote:
>A quick question:
>Is it possible to share the depth buffer between 2 drawables, where one
>is on-screen and one is offscreen?
>
>To elaborate:
>------------------
>I'm looking at a profile of our upcoming game, GooBall, and a
>glTexSubImage is literally jumping out at me. We use it for refraction
>through a glass sphere along these lines:
>
>Set up render-to-texture
>Render Scene.
>do a copyTexSubImage around the ball.
>Render ball with the texture copied above to fake refraction
>Set up rendering to screen.
>Post-process texture to main screen.
>
>We're already rendering to a texture & putting that on screen with
>various post-processing FX applied. What I would like to do would be
>something along these lines:
>
>Set up render-to-texture
>Render Scene
>Set up rendering to screen.
>Post-process texture to main screen.
>Render ball with texture generated above
>
>This would effectively eliminate my glCopyTexSubImage, but gives me one
>problem: when rendering to the main screen, I don't have the Z buffer
>from the actual scene, hence the ball would appear in front of any
>geometry that might be between the camera & the ball. I can live with
>the geometry getting refracted incorrectly (as it does in the current
>scheme), but I cannot separate the geometry between the ball and the
>camera.
>
>Any ideas?
This is a tricky one. In DirectX, you can specify the depth buffer as a separate render target, and you can share it between offscreen colour render targets, and your on-screen render target. Unfortunately, the OpenGL APIs give us no way to specify a 'depth-stencil-only' pbuffer that could be attached to a context alongside a colour pbuffer.
Rather than do a glCopyTexSubImage, you could create another offscreen buffer to help your glass ball rendering.
I'd do this:
- create two offscreen pbuffers of the same size
- render your world into buffer 1
- render buffer 1 into the main buffer with your post-processing effects, etc.
- switch to buffer 2, and using buffer 1 as the texture source (using aglBindPBuffer), draw a quad into buffer 2 which completely covers the draw surface (ie 640x480)
- switch back to buffer 1, clear the colour channels and render your ball, using buffer 2 as the texture source
- copy buffer 1 into the main buffer (with src-alpha to mask out everything but the ball)
I use pbuffers to blit copies of my texture data around the GPU, and it is pretty efficient.
I originally used the aglSurfaceTexture APIs to do this. With those, for each offscreen context, I could create another window (which I would hide), attach an OpenGL context to it, and use it as a texture source in another context by binding it to an OpenGL texture object in the target context using aglSurfaceTexture(). This is an option if you have to support a machine which for some reason doesn't do pbuffers; perhaps OSes < 10.3, for example- I'm not sure when pbuffer support came in.
--
James Milne
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/mac-opengl/email@hidden
This email sent to email@hidden