1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
14#ifndef OSG_BUFFERED_VALUE
15#define OSG_BUFFERED_VALUE 1
17#include <osg/DisplaySettings>
22/** Implements a simple buffered value for values that need to be buffered on
23 * a per graphics context basis.
30 inline buffered_value():
31 _array(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0)
34 inline buffered_value(unsigned int size):
38 buffered_value& operator = (const buffered_value& rhs)
44 inline void setAllElementsTo(const T& t) { std::fill(_array.begin(),_array.end(),t); }
46 inline void clear() { _array.clear(); }
48 inline bool empty() const { return _array.empty(); }
50 inline unsigned int size() const { return _array.size(); }
52 inline void resize(unsigned int newSize) { _array.resize(newSize,0); }
54 inline T& operator[] (unsigned int pos)
56 // automatically resize array.
57 if (_array.size()<=pos)
58 _array.resize(pos+1,0);
63 inline T operator[] (unsigned int pos) const
65 // automatically resize array.
66 if (_array.size()<=pos)
67 _array.resize(pos+1,0);
74 mutable std::vector<T> _array;
82 inline buffered_object():
83 _array(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts())
86 inline buffered_object(unsigned int size):
90 buffered_object& operator = (const buffered_object& rhs)
96 inline void setAllElementsTo(const T& t) { std::fill(_array.begin(),_array.end(),t); }
98 inline void clear() { _array.clear(); }
100 inline bool empty() const { return _array.empty(); }
102 inline unsigned int size() const { return _array.size(); }
104 inline void resize(unsigned int newSize) { _array.resize(newSize); }
106 inline T& operator[] (unsigned int pos)
108 // automatically resize array.
109 if (_array.size()<=pos)
110 _array.resize(pos+1);
115 inline const T& operator[] (unsigned int pos) const
117 // automatically resize array.
118 if (_array.size()<=pos)
119 _array.resize(pos+1);
127 mutable std::vector<T> _array;