OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BufferTemplate.h
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 
22 namespace osg
23 {
24 
28 template <typename T>
29 class BufferTemplate : public BufferData
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 
66 template <typename T>
67 class 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
void setData(const std::vector< T > &data)
BufferTemplate(const BufferTemplate< std::vector< T > > &bt, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
virtual const char * libraryName() const
#define NULL
Definition: Export.h:59
virtual bool isSameKindAs(const Object *obj) const
virtual Object * clone(const CopyOp &copyop) const
virtual Object * clone(const CopyOp &copyop) const
const T & getData() const
virtual unsigned int getTotalDataSize() const
virtual Object * cloneType() const
virtual const GLvoid * getDataPointer() const
virtual bool isSameKindAs(const Object *obj) const
virtual const GLvoid * getDataPointer() const
virtual ~BufferTemplate()
virtual const char * libraryName() const
BufferTemplate(const BufferTemplate< T > &bt, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Definition: AlphaFunc.h:19
const std::vector< T > & getData() const
virtual Object * cloneType() const
virtual const char * className() const
virtual unsigned int getTotalDataSize() const
void setData(const T &data)
virtual const char * className() const