OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Texture3D.h
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_TEXTURE3D
15 #define OSG_TEXTURE3D 1
16 
17 #include <osg/Texture>
18 
19 namespace osg {
20 
25 {
26 
27  public :
28 
29  Texture3D();
30 
31  Texture3D(Image* image);
32 
34  Texture3D(const Texture3D& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
35 
37 
39  virtual int compare(const StateAttribute& rhs) const;
40 
41  virtual GLenum getTextureTarget() const { return GL_TEXTURE_3D; }
42 
44  void setImage(Image* image);
45 
47  Image* getImage() { return _image.get(); }
48 
50  inline const Image* getImage() const { return _image.get(); }
51 
52  inline unsigned int& getModifiedCount(unsigned int contextID) const
53  {
54  // get the modified count for the current contextID.
55  return _modifiedCount[contextID];
56  }
57 
59  virtual void setImage(unsigned int, Image* image) { setImage(image); }
60 
62  virtual Image* getImage(unsigned int) { return _image.get(); }
63 
65  virtual const Image* getImage(unsigned int) const { return _image.get(); }
66 
68  virtual unsigned int getNumImages() const { return 1; }
69 
70 
74  inline void setTextureSize(int width, int height, int depth) const
75  {
76  _textureWidth = width;
77  _textureHeight = height;
78  _textureDepth = depth;
79  }
80 
82  inline void getTextureSize(int& width, int& height, int& depth) const
83  {
84  width = _textureWidth;
85  height = _textureHeight;
86  depth = _textureDepth;
87  }
88 
89  void setTextureWidth(int width) { _textureWidth=width; }
90  void setTextureHeight(int height) { _textureHeight=height; }
91  void setTextureDepth(int depth) { _textureDepth=depth; }
92 
93  virtual int getTextureWidth() const { return _textureWidth; }
94  virtual int getTextureHeight() const { return _textureHeight; }
95  virtual int getTextureDepth() const { return _textureDepth; }
96 
97 
99  {
100  public:
101  virtual void load(const Texture3D& texture,State& state) const = 0;
102  virtual void subload(const Texture3D& texture,State& state) const = 0;
103  };
104 
105  void setSubloadCallback(SubloadCallback* cb) { _subloadCallback = cb;; }
106 
107  SubloadCallback* getSubloadCallback() { return _subloadCallback.get(); }
108 
109  const SubloadCallback* getSubloadCallback() const { return _subloadCallback.get(); }
110 
111 
115  void setNumMipmapLevels(unsigned int num) const { _numMipmapLevels=num; }
116 
118  unsigned int getNumMipmapLevels() const { return _numMipmapLevels; }
119 
120 
128  void copyTexSubImage3D(State& state, int xoffset, int yoffset, int zoffset, int x, int y, int width, int height);
129 
130 
133  virtual void apply(State& state) const;
134 
135  protected :
136 
137  virtual ~Texture3D();
138 
139  void computeRequiredTextureDimensions(State& state, const osg::Image& image,GLsizei& width, GLsizei& height,GLsizei& depth, GLsizei& numMipmapLevels) const;
140 
141  virtual void computeInternalFormat() const;
142  void allocateMipmap(State& state) const;
143 
144  void applyTexImage3D(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight, GLsizei& indepth, GLsizei& numMipmapLevels) const;
145 
151 
153  mutable GLsizei _textureWidth, _textureHeight, _textureDepth;
154 
156  mutable GLsizei _numMipmapLevels;
157 
159 
161  mutable ImageModifiedCount _modifiedCount;
162 
163 };
164 
165 }
166 
167 #endif
const Image * getImage() const
Definition: Texture3D.h:50
#define OSG_EXPORT
Definition: Export.h:43
void setTextureHeight(int height)
Definition: Texture3D.h:90
ref_ptr< Image > _image
Definition: Texture3D.h:150
virtual int getTextureDepth() const
Definition: Texture3D.h:95
void setNumMipmapLevels(unsigned int num) const
Definition: Texture3D.h:115
void getTextureSize(int &width, int &height, int &depth) const
Definition: Texture3D.h:82
GLint GLenum GLsizei GLsizei GLsizei depth
Definition: GLU.h:71
ImageModifiedCount _modifiedCount
Definition: Texture3D.h:161
ref_ptr< SubloadCallback > _subloadCallback
Definition: Texture3D.h:158
void setTextureDepth(int depth)
Definition: Texture3D.h:91
SubloadCallback * getSubloadCallback()
Definition: Texture3D.h:107
#define GL_TEXTURE_3D
Definition: Texture.h:188
virtual GLenum getTextureTarget() const
Definition: Texture3D.h:41
virtual Image * getImage(unsigned int)
Definition: Texture3D.h:62
unsigned int & getModifiedCount(unsigned int contextID) const
Definition: Texture3D.h:52
GLint GLenum GLsizei width
Definition: GLU.h:71
Image * getImage()
Definition: Texture3D.h:47
const SubloadCallback * getSubloadCallback() const
Definition: Texture3D.h:109
virtual const Image * getImage(unsigned int) const
Definition: Texture3D.h:65
buffered_value< unsigned int > ImageModifiedCount
Definition: Texture3D.h:160
GLsizei _numMipmapLevels
Definition: Texture3D.h:156
void setTextureSize(int width, int height, int depth) const
Definition: Texture3D.h:74
#define META_StateAttribute(library, name, type)
GLint GLenum GLsizei GLsizei height
Definition: GLU.h:71
virtual int getTextureWidth() const
Definition: Texture3D.h:93
unsigned int getNumMipmapLevels() const
Definition: Texture3D.h:118
virtual void setImage(unsigned int, Image *image)
Definition: Texture3D.h:59
void setTextureWidth(int width)
Definition: Texture3D.h:89
Definition: AlphaFunc.h:19
virtual unsigned int getNumImages() const
Definition: Texture3D.h:68
virtual int getTextureHeight() const
Definition: Texture3D.h:94
GLsizei _textureWidth
Definition: Texture3D.h:153
void setSubloadCallback(SubloadCallback *cb)
Definition: Texture3D.h:105