OpenSceneGraph 3.6.5
TextureRectangle
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
27namespace osg {
28
31{
32
33 public :
34
36
38
39 template<class T> TextureRectangle(const osg::ref_ptr<T>& image):
42 {
45
48
49 setImage(image.get());
50 }
51
54
56
58 virtual int compare(const StateAttribute& rhs) const;
59
60 virtual GLenum getTextureTarget() const { return GL_TEXTURE_RECTANGLE; }
61
63 void setImage(Image* image);
64
65 template<class T> void setImage(const ref_ptr<T>& image) { setImage(image.get()); }
66
68 Image* getImage() { return _image.get(); }
69
71 inline const Image* getImage() const { return _image.get(); }
72
74 virtual bool isDirty(unsigned int contextID) const { return (_image.valid() && _image->getModifiedCount()!=_modifiedCount[contextID]); }
75
76 inline unsigned int& getModifiedCount(unsigned int contextID) const
77 {
78 // get the modified count for the current contextID.
79 return _modifiedCount[contextID];
80 }
81
82
84 virtual void setImage(unsigned int, Image* image) { setImage(image); }
85
87 virtual Image* getImage(unsigned int) { return _image.get(); }
88
90 virtual const Image* getImage(unsigned int) const { return _image.get(); }
91
93 virtual unsigned int getNumImages() const { return 1; }
94
95
99 inline void setTextureSize(int width, int height) const
100 {
101 _textureWidth = width;
102 _textureHeight = height;
103 }
104
105 void setTextureWidth(int width) { _textureWidth=width; }
106 void setTextureHeight(int height) { _textureHeight=height; }
107
108 virtual int getTextureWidth() const { return _textureWidth; }
109 virtual int getTextureHeight() const { return _textureHeight; }
110 virtual int getTextureDepth() const { return 1; }
111
113 {
114 public:
115 virtual void load(const TextureRectangle&, State&) const = 0;
116 virtual void subload(const TextureRectangle&, State&) const = 0;
117 };
118
121 const SubloadCallback* getSubloadCallback() const { return _subloadCallback.get(); }
122
127 void copyTexImage2D(State& state, int x, int y, int width, int height );
128
136 void copyTexSubImage2D(State& state, int xoffset, int yoffset, int x, int y, int width, int height );
137
141 virtual void apply(State& state) const;
142
143 protected :
144
146
147 virtual void computeInternalFormat() const;
148 void allocateMipmap(State& state) const;
149
150 void applyTexImage_load(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight) const;
151 void applyTexImage_subload(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight, GLint& inInternalFormat) const;
152
154
155 // subloaded images can have different texture and image sizes.
157
159
162};
163
164}
165
166#endif
#define GL_TEXTURE_RECTANGLE
Definition GLDefines:406
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
Implements a simple buffered value for values that need to be buffered on a per graphics context basi...
Definition buffered_value:27
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
Image class for encapsulating the storage texture image data.
Definition Image:179
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
T * get() const
Definition ref_ptr:117
Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings,...
Definition State:80
Base class for state attributes.
Definition StateAttribute:77
@ TEXTURE
Definition StateAttribute:125
void setFilter(FilterParameter which, FilterMode filter)
Sets the texture filter mode.
@ LINEAR
Definition Texture:500
@ CLAMP
Definition Texture:468
@ WRAP_S
Definition Texture:462
@ WRAP_T
Definition Texture:463
@ MAG_FILTER
Definition Texture:496
@ MIN_FILTER
Definition Texture:495
void setWrap(WrapParameter which, WrapMode wrap)
Sets the texture wrap mode.
const SubloadCallback * getSubloadCallback() const
Definition TextureRectangle:121
GLsizei _textureWidth
Definition TextureRectangle:156
void setImage(Image *image)
Set the texture image.
virtual int compare(const StateAttribute &rhs) const
Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.
buffered_value< unsigned int > ImageModifiedCount
Definition TextureRectangle:160
void setSubloadCallback(SubloadCallback *cb)
Definition TextureRectangle:119
TextureRectangle(Image *image)
unsigned int & getModifiedCount(unsigned int contextID) const
Definition TextureRectangle:76
void setTextureWidth(int width)
Definition TextureRectangle:105
void setTextureSize(int width, int height) const
Set the texture width and height.
Definition TextureRectangle:99
virtual void setImage(unsigned int, Image *image)
Set the texture image, ignoring face value as there is only one image.
Definition TextureRectangle:84
virtual int getTextureWidth() const
Definition TextureRectangle:108
ref_ptr< Image > _image
Definition TextureRectangle:153
Image * getImage()
Get the texture image.
Definition TextureRectangle:68
void applyTexImage_subload(GLenum target, Image *image, State &state, GLsizei &inwidth, GLsizei &inheight, GLint &inInternalFormat) const
virtual bool isDirty(unsigned int contextID) const
return true if the texture image data has been modified and the associated GL texture object needs to...
Definition TextureRectangle:74
ref_ptr< SubloadCallback > _subloadCallback
Definition TextureRectangle:158
void allocateMipmap(State &state) const
Allocate mipmap levels of the texture by subsequent calling of glTexImage* function.
void setImage(const ref_ptr< T > &image)
Definition TextureRectangle:65
ImageModifiedCount _modifiedCount
Definition TextureRectangle:161
TextureRectangle(const TextureRectangle &text, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
const Image * getImage() const
Get the const texture image.
Definition TextureRectangle:71
TextureRectangle(const osg::ref_ptr< T > &image)
Definition TextureRectangle:39
void setTextureHeight(int height)
Definition TextureRectangle:106
virtual void apply(State &state) const
On first apply (unless already compiled), create and bind the texture, subsequent apply will simply b...
void applyTexImage_load(GLenum target, Image *image, State &state, GLsizei &inwidth, GLsizei &inheight) const
virtual int getTextureDepth() const
Definition TextureRectangle:110
void copyTexImage2D(State &state, int x, int y, int width, int height)
Copies pixels into a 2D texture image, as per glCopyTexImage2D.
virtual Image * getImage(unsigned int)
Get the texture image, ignoring face value as there is only one image.
Definition TextureRectangle:87
virtual GLenum getTextureTarget() const
Definition TextureRectangle:60
virtual int getTextureHeight() const
Definition TextureRectangle:109
META_StateAttribute(osg, TextureRectangle, TEXTURE)
void copyTexSubImage2D(State &state, int xoffset, int yoffset, int x, int y, int width, int height)
Copies a two-dimensional texture subimage, as per glCopyTexSubImage2D.
SubloadCallback * getSubloadCallback()
Definition TextureRectangle:120
virtual const Image * getImage(unsigned int) const
Get the const texture image, ignoring face value as there is only one image.
Definition TextureRectangle:90
virtual void computeInternalFormat() const
virtual unsigned int getNumImages() const
Get the number of images that can be assigned to the Texture.
Definition TextureRectangle:93
GLsizei _textureHeight
Definition TextureRectangle:156
virtual ~TextureRectangle()
Definition TextureRectangle:113
virtual void load(const TextureRectangle &, State &) const =0
virtual void subload(const TextureRectangle &, State &) const =0
#define OSG_EXPORT
Definition Export:39

osg logo
Generated at Wed Jul 23 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.