OpenSceneGraph 3.6.5
buffered_value
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
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.
7 *
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.
12*/
13
14#ifndef OSG_BUFFERED_VALUE
15#define OSG_BUFFERED_VALUE 1
16
17#include <osg/DisplaySettings>
18#include <vector>
19
20namespace osg {
21
25template<class T>
27{
28 public:
29
31 _array(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0)
32 {}
33
34 inline buffered_value(unsigned int size):
35 _array(size,0)
36 {}
37
39 {
40 _array = rhs._array;
41 return *this;
42 }
43
44 inline void setAllElementsTo(const T& t) { std::fill(_array.begin(),_array.end(),t); }
45
46 inline void clear() { _array.clear(); }
47
48 inline bool empty() const { return _array.empty(); }
49
50 inline unsigned int size() const { return _array.size(); }
51
52 inline void resize(unsigned int newSize) { _array.resize(newSize,0); }
53
54 inline T& operator[] (unsigned int pos)
55 {
56 // automatically resize array.
57 if (_array.size()<=pos)
58 _array.resize(pos+1,0);
59
60 return _array[pos];
61 }
62
63 inline T operator[] (unsigned int pos) const
64 {
65 // automatically resize array.
66 if (_array.size()<=pos)
67 _array.resize(pos+1,0);
68
69 return _array[pos];
70 }
71
72 protected:
73
74 mutable std::vector<T> _array;
75};
76
77template<class T>
79{
80 public:
81
83 _array(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts())
84 {}
85
86 inline buffered_object(unsigned int size):
88 {}
89
91 {
92 _array = rhs._array;
93 return *this;
94 }
95
96 inline void setAllElementsTo(const T& t) { std::fill(_array.begin(),_array.end(),t); }
97
98 inline void clear() { _array.clear(); }
99
100 inline bool empty() const { return _array.empty(); }
101
102 inline unsigned int size() const { return _array.size(); }
103
104 inline void resize(unsigned int newSize) { _array.resize(newSize); }
105
106 inline T& operator[] (unsigned int pos)
107 {
108 // automatically resize array.
109 if (_array.size()<=pos)
110 _array.resize(pos+1);
111
112 return _array[pos];
113 }
114
115 inline const T& operator[] (unsigned int pos) const
116 {
117 // automatically resize array.
118 if (_array.size()<=pos)
119 _array.resize(pos+1);
120
121 return _array[pos];
122 }
123
124
125 protected:
126
127 mutable std::vector<T> _array;
128};
129
130}
131
132#endif
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
buffered_value(unsigned int size)
Definition buffered_value:34
unsigned int size() const
Definition buffered_value:50
void clear()
Definition buffered_value:46
bool empty() const
Definition buffered_value:48
void resize(unsigned int newSize)
Definition buffered_value:52
void setAllElementsTo(const T &t)
Definition buffered_value:44
std::vector< unsigned int > _array
Definition buffered_value:74
T & operator[](unsigned int pos)
Definition buffered_value:54
buffered_value()
Definition buffered_value:30
buffered_value & operator=(const buffered_value &rhs)
Definition buffered_value:38
buffered_object(unsigned int size)
Definition buffered_value:86
T & operator[](unsigned int pos)
Definition buffered_value:106
buffered_object()
Definition buffered_value:82
buffered_object & operator=(const buffered_object &rhs)
Definition buffered_value:90
void clear()
Definition buffered_value:98
unsigned int size() const
Definition buffered_value:102
void setAllElementsTo(const T &t)
Definition buffered_value:96
std::vector< osg::ref_ptr< GLBufferObject > > _array
Definition buffered_value:127
void resize(unsigned int newSize)
Definition buffered_value:104
bool empty() const
Definition buffered_value:100
DisplaySettings class for encapsulating what visuals are required and have been set up,...
Definition DisplaySettings:34

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.