Hi Laurens, I have now implemented an alternative approach to ViewportArray, attached is osg::ViewportIndexed which wraps up glViewportIndex, subclassing from osg::Viewport.
I modified your example thus : (#if 0 is your old usage, #else is new one)
#if 0
osg::ViewportArray *viewportArray = new osg::ViewportArray();
osg::Viewport *left = new osg::Viewport(0.0, 0.0, width * 0.5, height);
osg::Viewport *right = new osg::Viewport(width * 0.5, 0.0, width *
0.5, height);
viewportArray->setViewport(0, left);
viewportArray->setViewport(1, right);
stateSet->setAttribute(viewportArray);
#else
stateSet->setAttribute(new osg::ViewportIndexed(0, 0.0, 0.0, width
* 0.5, height)); // left
stateSet->setAttribute(new osg::ViewportIndexed(1, width * 0.5,
0.0, width * 0.5, height)); // right
#endif
The advantage of osg::ViewportIndexed approach is that you can
individually set/override/protected the viewports.
I'm not aware of any disavantages with this approach, could you have a
look over and see if I've missed anything. If it all looks good then
I'll implement similar versions for the other *Indexed variants.
Robert.
ViewportIndexed
Description: Binary data
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#include <osg/ViewportIndexed>
#include <osg/GLExtensions>
#include <osg/State>
using namespace osg;
ViewportIndexed::ViewportIndexed():
_index(0)
{
}
ViewportIndexed::~ViewportIndexed()
{
}
void ViewportIndexed::setIndex(unsigned int index)
{
if (_index==index) return;
ReassignToParents needToReassingToParentsWhenMemberValueChanges(this);
_index = index;
}
void ViewportIndexed::apply(State& state) const
{
const GLExtensions* extensions = state.get<GLExtensions>();
if (extensions->glViewportIndexedf)
{
extensions->glViewportIndexedf(static_cast<GLuint>(_index),
static_cast<GLfloat>(_x),
static_cast<GLfloat>(_y),
static_cast<GLfloat>(_width),
static_cast<GLfloat>(_height));
}
else
{
OSG_WARN<<"Warning: ViewportIndexed::apply(..) failed, glViewportIndexed is not support by OpenGL driver."<<std::endl;
}
}
_______________________________________________ osg-submissions mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
