I know sometimes draw function may want to alter it. In that case, it can make its own copy from the const reference if required.
Is this not a good design?It is. Passing the render states by value is also a good design. The thing is, nobody cares because the difference will never be noticeable. There's really nothing else to say about it ;)
Say I want to share a web page with you.
If I tell you the URL, I'm passing by reference. You can use that URL to see the same web page I can see. If that page is changed, we both see the changes. If you delete the URL, all you're doing is destroying your reference to that page - you're not deleting the actual page itself.
If I print out the page and give you the printout, I'm passing by value. Your page is a disconnected copy of the original. You won't see any subsequent changes, and any changes that you make (e.g. scribbling on your printout) will not show up on the original page. If you destroy the printout, you have actually destroyed your copy of the object - but the original web page remains intact.
I can believe that the cost of passing render states by value is trivial and so there's no point worrying about it.
I am reluctant to believe the compiler can optimize away the copy in a pass by value in this case. Draw is a virtual function and it may not be known until run-time whether the states parameter is modified or not by the resolved function.
I am reluctant to believe the compiler can optimize away the copy in a pass by value in this case. Draw is a virtual function and it may not be known until run-time whether the states parameter is modified or not by the resolved function.Programming is never about any kind of believe. Study, try, test, profile. The easiest way is really to go write reliable test cases. The harder way is to go study what the standard allows and what the compilers actually do (of course that only works for open source compilers). ;)