Special renderer for "impossible 3D scene"

I am writing a special renderer for “impossible 3D scenes” (like the ones that the artist M.C. Escher drew). So if i have a scene that consist of few objects (box sphere etc.), i need to render each one of them separately and save the color buffer and depth buffer for each object and than combine all of them in a special way. For some technical reasons i couldn’t succeed in this mission (It is also extremely slow) so i thought about other idea. I can identify each pixel in an image by the alpha value so each object will have a special number that identify it. But than i need a way to influence only pixels that belong to a specific object, i.e. the pixels have a specific alpha value. What i mean is something like this: I want to draw a phere (object number 1) and than draw a box (object number 2) but the new pixels that belong to the box should only influence the pixels of the sphere. and than add another object that i am going to render twise: one render is suppose to influence the pixels that belong to the box and one render is suppose to inluence the pixels that belong to the sphere. and so on…

If you had an idea please help.
thank you very much.

Sounds like a job for the stencil buffer, not the alpha buffer.