"Sealed" OpenGL Command Blocks ?

Is there a way to issue a batch of commands in OpenGL which have no effect to the outside world, just like Push-Pop Matrix.

For example, I want my Rendering environment to have a specified Fill mode(Solid,wire,point). But I want each individual 3D objects to override it if they wish. In order to do that, I have to issue glPolygonMode before drawing the object that want fill mode different to that of the environment. After the drawing command I have to issue glPolygonMode again to restore the environments Fill Mode.

Is there a way to avoid issuing twice such commands?

Thank you.

There is glPushAttrib/glPopAttrib, but the usual way is to do lazy state. That is have application “lazy state” wrappers around the GL state setting that only changes state if you know its changed.

If you want to avoid multiple state switches, then just sort your objects by state.
First draw objects that use the global setting, then draw objects that use custom setting.