First, OptiX generally accesses CUDA buffers only. You can setup some CUDA-OpenGL interoperability though.
The OptiX SDK examples often do OpenGL interop with a PixelBufferObject (PBO) for the color image display.
More examples doing that with the older OptiX 5/6 API can be found in the OptiX Advanced Samples “Introduction” examples in this thread (search the code for m_interop):
https://forums.developer.nvidia.com/t/optix-advanced-samples-on-github/48410
With OptiX 7.0.0 things are getting more flexible. There you can interop with everything CUDA supports and to other APIs: Vulkan, DX, OpenGL.
For OpenGL that includes PBO, copies into CUDA texture arrays from device-to-device, or directly reading from or writing to surfaces.
Unfortunately the surface access doesn’t seem to be working inside OptiX 7.0.0: https://forums.developer.nvidia.com/t/surf2dread-in-optix-kernel/118601
The OptiX 7.0.0 examples in this post (same thread as above): https://forums.developer.nvidia.com/t/optix-advanced-samples-on-github/48410/4
contains a multi-GPU example which is doing no OpenGL interop (copying to host), PBO interop, and direct copy into CUDA texture array registered from OpenGL.
The no OpenGL interop case is going through the host, which is the simplest and slowest case and what you’d need to start implementing since this is also going to work if there is no NVIDIA OpenGL implementation running on a system to interop with.
Unfortunately none of the examples is rendering a depth buffer. That would really be your task to implement via the same interoperability mechanisms.