Added finer control over viewport setting on begin/end

As suggested in issue #1199