My problem is that I would like to confine a scene render to a (possibly rotated) rectangle without using glViewport(). I don't want to use it to save, if possible, some cycles that would otherwise be spent on state switching. Also, there is the tantalizing possibility of rotating the scene render, which is not possible with glViewport... Is it possible to confine a scene render to this (possible rotated) rectangle in this way?


You can adjust the scene position, rotation, and scale in the viewport, by simply concatenating the desired 2D transformations onto your projection matrix.

You can also mask out areas of the viewport you don't want to be rendered, by rendering some black geometry at the near clip plane, thus preventing anything else from showing up in those areas (since it will fail the depth test). The masked areas can be any shape you wish, since they're just geometry rendered like anything else. This will be pretty efficient, too, since modern GPU hardware has very efficient Z-culling.

All that being said, though, this question smells of premature optimization. :) Have you actually measured the time taken by glViewport and is it really a performance problem for your application? If not, that would be a good thing to do before spending a bunch of time implementing a subsitute method.

  • \$\begingroup\$ I need to test your claim. If I manage to make it work, I'll accept. \$\endgroup\$ – user1095108 Aug 5 '14 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.