OpenSceneGraph 3.6.5
BufferTemplate
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 Robert Osfield
2 * Copyright (C) 2012 David Callu
3 * std::vector specialization : Pawel Ksiezopolski
4 *
5 * This library is open source and may be redistributed and/or modified under
6 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
7 * (at your option) any later version. The full license is in LICENSE file
8 * included with this distribution, and on the openscenegraph.org website.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * OpenSceneGraph Public License for more details.
14*/
15
16#ifndef OSG_BUFFERTEMPLATE
17#define OSG_BUFFERTEMPLATE 1
18
19#include <osg/BufferObject>
20#include <vector>
21
22namespace osg
23{
24
28template <typename T>
30{
31 public:
33 BufferData(),
34 _data(T())
35 {}
36
39 osg::BufferData(bt,copyop),
40 _data(bt._data)
41 {}
42
43 virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const BufferTemplate<T>*>(obj)!=NULL; }
44 virtual const char* libraryName() const { return "osg"; }
45 virtual const char* className() const { return "BufferTemplate<T>"; }
46
47 virtual Object* cloneType() const { return new BufferTemplate<T>(); }
48 virtual Object* clone(const CopyOp& copyop) const { return new BufferTemplate<T>(*this,copyop); }
49
50 virtual const GLvoid* getDataPointer() const { return &_data; }
51 virtual unsigned int getTotalDataSize() const { return sizeof(T); }
52
53 const T& getData() const { return _data; }
54 T& getData() { return _data; }
55 void setData(const T& data) { _data = data; dirty(); }
56
57 protected:
58 virtual ~BufferTemplate() {};
59
60 private:
61 T _data;
62};
63
66template <typename T>
67class BufferTemplate< std::vector<T> > : public BufferData
68{
69 public:
71 BufferData(),
72 _data()
73 {}
74
76 BufferTemplate(const BufferTemplate< std::vector<T> >& bt,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
77 osg::BufferData(bt,copyop),
78 _data(bt._data)
79 {}
80
81 virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const BufferTemplate< std::vector<T> >*>(obj)!=NULL; }
82 virtual const char* libraryName() const { return "osg"; }
83 virtual const char* className() const { return "BufferTemplate<std::vector<T> >"; }
84
85 virtual Object* cloneType() const { return new BufferTemplate< std::vector<T> >(); }
86 virtual Object* clone(const CopyOp& copyop) const { return new BufferTemplate< std::vector<T> >(*this,copyop); }
87
88 virtual const GLvoid* getDataPointer() const { return &_data[0]; }
89 virtual unsigned int getTotalDataSize() const { return _data.size() * sizeof(T); }
90
91 const std::vector<T>& getData() const { return _data; }
92 std::vector<T>& getData() { return _data; }
93 void setData(const std::vector<T>& data) { _data = data; dirty(); }
94
95 protected:
96 virtual ~BufferTemplate() {};
97
98 private:
99 std::vector<T> _data;
100};
101
102}
103
104#endif
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
BufferData()
Definition BufferObject:498
void dirty()
Dirty the primitive, which increments the modified count, to force buffer objects to update.
Definition BufferObject:556
virtual const GLvoid * getDataPointer() const
Definition BufferTemplate:50
virtual ~BufferTemplate()
Definition BufferTemplate:58
BufferTemplate()
Definition BufferTemplate:32
virtual bool isSameKindAs(const Object *obj) const
Definition BufferTemplate:43
void setData(const T &data)
Definition BufferTemplate:55
virtual Object * clone(const CopyOp &copyop) const
Clone an object, with Object* return type.
Definition BufferTemplate:48
T & getData()
Definition BufferTemplate:54
virtual const char * className() const
return the name of the object's class type.
Definition BufferTemplate:45
const T & getData() const
Definition BufferTemplate:53
BufferTemplate(const BufferTemplate< T > &bt, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
Definition BufferTemplate:38
virtual Object * cloneType() const
Clone the type of an object, with Object* return type.
Definition BufferTemplate:47
virtual const char * libraryName() const
return the name of the object's library.
Definition BufferTemplate:44
virtual unsigned int getTotalDataSize() const
Definition BufferTemplate:51
virtual ~BufferTemplate()
Definition BufferTemplate:96
virtual bool isSameKindAs(const Object *obj) const
Definition BufferTemplate:81
virtual const char * libraryName() const
return the name of the object's library.
Definition BufferTemplate:82
BufferTemplate(const BufferTemplate< std::vector< T > > &bt, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
Definition BufferTemplate:76
const std::vector< T > & getData() const
Definition BufferTemplate:91
void setData(const std::vector< T > &data)
Definition BufferTemplate:93
BufferTemplate()
Definition BufferTemplate:70
virtual unsigned int getTotalDataSize() const
Definition BufferTemplate:89
virtual Object * clone(const CopyOp &copyop) const
Clone an object, with Object* return type.
Definition BufferTemplate:86
virtual Object * cloneType() const
Clone the type of an object, with Object* return type.
Definition BufferTemplate:85
std::vector< T > & getData()
Definition BufferTemplate:92
virtual const GLvoid * getDataPointer() const
Definition BufferTemplate:88
virtual const char * className() const
return the name of the object's class type.
Definition BufferTemplate:83
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Base class/standard interface for objects which require IO support, cloning and reference counting.
Definition Object:61
#define NULL
Definition Export:55

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