OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Texture2D.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_TEXTURE2D
15 #define OSG_TEXTURE2D 1
16 
17 #include <osg/Texture>
18 
19 namespace osg {
20 
25 {
26 
27  public :
28 
29  Texture2D();
30 
31  Texture2D(Image* image);
32 
34  Texture2D(const Texture2D& 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_2D; }
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 
58 
60  virtual void setImage(unsigned int, Image* image) { setImage(image); }
61 
63  virtual Image* getImage(unsigned int) { return _image.get(); }
64 
66  virtual const Image* getImage(unsigned int) const { return _image.get(); }
67 
69  virtual unsigned int getNumImages() const { return 1; }
70 
71 
74  inline void setTextureSize(int width, int height) const
75  {
76  _textureWidth = width;
77  _textureHeight = height;
78  }
79 
80  void setTextureWidth(int width) { _textureWidth=width; }
81  void setTextureHeight(int height) { _textureHeight=height; }
82 
83  virtual int getTextureWidth() const { return _textureWidth; }
84  virtual int getTextureHeight() const { return _textureHeight; }
85  virtual int getTextureDepth() const { return 1; }
86 
88  {
89  public:
90 
91  virtual bool textureObjectValid(const Texture2D& texture, State& state) const
92  {
93  return texture.textureObjectValid(state);
94  }
95 
96  virtual TextureObject* generateTextureObject(const Texture2D& texture, State& state) const
97  {
98  return osg::Texture::generateTextureObject(&texture, state.getContextID(), GL_TEXTURE_2D).release();
99  }
100 
101  virtual void load(const Texture2D& texture,State& state) const = 0;
102  virtual void subload(const Texture2D& 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 
125  void copyTexImage2D(State& state, int x, int y, int width, int height );
126 
134  void copyTexSubImage2D(State& state, int xoffset, int yoffset, int x, int y, int width, int height );
135 
136 
139  virtual void apply(State& state) const;
140 
141 
142 
143  protected :
144 
145  virtual ~Texture2D();
146 
147  virtual void computeInternalFormat() const;
148  void allocateMipmap(State& state) const;
149 
151  bool textureObjectValid(State& state) const;
152 
153  friend class SubloadCallback;
154 
156 
158  mutable GLsizei _textureWidth, _textureHeight;
159 
161  mutable GLsizei _numMipmapLevels;
162 
164 
166  mutable ImageModifiedCount _modifiedCount;
167 
168 };
169 
170 }
171 
172 #endif
void setTextureSize(int width, int height) const
Definition: Texture2D.h:74
#define OSG_EXPORT
Definition: Export.h:43
const SubloadCallback * getSubloadCallback() const
Definition: Texture2D.h:109
void setTextureWidth(int width)
Definition: Texture2D.h:80
GLsizei _numMipmapLevels
Definition: Texture2D.h:161
unsigned int & getModifiedCount(unsigned int contextID) const
Definition: Texture2D.h:52
void setSubloadCallback(SubloadCallback *cb)
Definition: Texture2D.h:105
void setTextureHeight(int height)
Definition: Texture2D.h:81
virtual GLenum getTextureTarget() const
Definition: Texture2D.h:41
virtual const Image * getImage(unsigned int) const
Definition: Texture2D.h:66
virtual void setImage(unsigned int, Image *image)
Definition: Texture2D.h:60
ref_ptr< SubloadCallback > _subloadCallback
Definition: Texture2D.h:163
GLint GLenum GLsizei width
Definition: GLU.h:71
virtual int getTextureHeight() const
Definition: Texture2D.h:84
ImageModifiedCount _modifiedCount
Definition: Texture2D.h:166
bool textureObjectValid(State &state) const
ref_ptr< Image > _image
Definition: Texture2D.h:155
SubloadCallback * getSubloadCallback()
Definition: Texture2D.h:107
unsigned int getContextID() const
Definition: State.h:151
#define META_StateAttribute(library, name, type)
virtual int getTextureDepth() const
Definition: Texture2D.h:85
GLint GLenum GLsizei GLsizei height
Definition: GLU.h:71
const Image * getImage() const
Definition: Texture2D.h:50
virtual bool textureObjectValid(const Texture2D &texture, State &state) const
Definition: Texture2D.h:91
virtual unsigned int getNumImages() const
Definition: Texture2D.h:69
Definition: AlphaFunc.h:19
virtual Image * getImage(unsigned int)
Definition: Texture2D.h:63
virtual int getTextureWidth() const
Definition: Texture2D.h:83
Image * getImage()
Definition: Texture2D.h:47
virtual TextureObject * generateTextureObject(const Texture2D &texture, State &state) const
Definition: Texture2D.h:96
GLsizei _textureWidth
Definition: Texture2D.h:158
buffered_value< unsigned int > ImageModifiedCount
Definition: Texture2D.h:165
void setNumMipmapLevels(unsigned int num) const
Definition: Texture2D.h:115
unsigned int getNumMipmapLevels() const
Definition: Texture2D.h:118
static osg::ref_ptr< TextureObject > generateTextureObject(const Texture *texture, unsigned int contextID, GLenum target)