OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TextureRectangle.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_TEXTURERECTANGLE
15 #define OSG_TEXTURERECTANGLE 1
16 
17 #include <osg/Texture>
18 
19 #ifndef GL_TEXTURE_RECTANGLE_NV
20 #define GL_TEXTURE_RECTANGLE_NV 0x84F5
21 #endif
22 
23 #ifndef GL_TEXTURE_RECTANGLE
24 #define GL_TEXTURE_RECTANGLE GL_TEXTURE_RECTANGLE_NV
25 #endif
26 
27 namespace osg {
28 
31 {
32 
33  public :
34 
36 
37  TextureRectangle(Image* image);
38 
41 
43 
45  virtual int compare(const StateAttribute& rhs) const;
46 
47  virtual GLenum getTextureTarget() const { return GL_TEXTURE_RECTANGLE; }
48 
50  void setImage(Image* image);
51 
53  Image* getImage() { return _image.get(); }
54 
56  inline const Image* getImage() const { return _image.get(); }
57 
58  inline unsigned int& getModifiedCount(unsigned int contextID) const
59  {
60  // get the modified count for the current contextID.
61  return _modifiedCount[contextID];
62  }
63 
64 
66  virtual void setImage(unsigned int, Image* image) { setImage(image); }
67 
69  virtual Image* getImage(unsigned int) { return _image.get(); }
70 
72  virtual const Image* getImage(unsigned int) const { return _image.get(); }
73 
75  virtual unsigned int getNumImages() const { return 1; }
76 
77 
81  inline void setTextureSize(int width, int height) const
82  {
83  _textureWidth = width;
84  _textureHeight = height;
85  }
86 
87  void setTextureWidth(int width) { _textureWidth=width; }
88  void setTextureHeight(int height) { _textureHeight=height; }
89 
90  virtual int getTextureWidth() const { return _textureWidth; }
91  virtual int getTextureHeight() const { return _textureHeight; }
92  virtual int getTextureDepth() const { return 1; }
93 
94  class SubloadCallback : public Referenced
95  {
96  public:
97  virtual void load(const TextureRectangle&, State&) const = 0;
98  virtual void subload(const TextureRectangle&, State&) const = 0;
99  };
100 
101  void setSubloadCallback(SubloadCallback* cb) { _subloadCallback = cb;; }
102  SubloadCallback* getSubloadCallback() { return _subloadCallback.get(); }
103  const SubloadCallback* getSubloadCallback() const { return _subloadCallback.get(); }
104 
109  void copyTexImage2D(State& state, int x, int y, int width, int height );
110 
118  void copyTexSubImage2D(State& state, int xoffset, int yoffset, int x, int y, int width, int height );
119 
123  virtual void apply(State& state) const;
124 
125  protected :
126 
127  virtual ~TextureRectangle();
128 
129  virtual void computeInternalFormat() const;
130  void allocateMipmap(State& state) const;
131 
132  void applyTexImage_load(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight) const;
133  void applyTexImage_subload(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight, GLint& inInternalFormat) const;
134 
136 
137  // subloaded images can have different texture and image sizes.
138  mutable GLsizei _textureWidth, _textureHeight;
139 
141 
143  mutable ImageModifiedCount _modifiedCount;
144 };
145 
146 }
147 
148 #endif
void setSubloadCallback(SubloadCallback *cb)
void setTextureWidth(int width)
#define OSG_EXPORT
Definition: Export.h:43
virtual GLenum getTextureTarget() const
const Image * getImage() const
#define GL_TEXTURE_RECTANGLE
virtual int getTextureWidth() const
virtual Image * getImage(unsigned int)
void setTextureSize(int width, int height) const
ref_ptr< SubloadCallback > _subloadCallback
void setTextureHeight(int height)
ImageModifiedCount _modifiedCount
SubloadCallback * getSubloadCallback()
GLint GLenum GLsizei width
Definition: GLU.h:71
virtual void setImage(unsigned int, Image *image)
virtual int getTextureDepth() const
virtual unsigned int getNumImages() const
unsigned int & getModifiedCount(unsigned int contextID) const
#define META_StateAttribute(library, name, type)
GLint GLenum GLsizei GLsizei height
Definition: GLU.h:71
buffered_value< unsigned int > ImageModifiedCount
const SubloadCallback * getSubloadCallback() const
Definition: AlphaFunc.h:19
virtual int getTextureHeight() const
virtual const Image * getImage(unsigned int) const
ref_ptr< Image > _image