OpenSceneGraph 3.6.5
Texture1D
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// -*-c++-*-
15
16#ifndef OSG_TEXTURE1D
17#define OSG_TEXTURE1D 1
18
19#include <osg/Texture>
20
21#ifndef GL_TEXTURE_1D
22 #define GL_TEXTURE_1D 0x0DE0
23#endif
24
25namespace osg {
26
31{
32
33 public :
34
36
38
39 template<class T> Texture1D(const osg::ref_ptr<T>& image):
42 {
43 setImage(image.get());
44 }
45
47 Texture1D(const Texture1D& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
48
50
52 virtual int compare(const StateAttribute& rhs) const;
53
54 virtual GLenum getTextureTarget() const { return GL_TEXTURE_1D; }
55
57 void setImage(Image* image);
58
59 template<class T> void setImage(const ref_ptr<T>& image) { setImage(image.get()); }
60
62 Image* getImage() { return _image.get(); }
63
65 inline const Image* getImage() const { return _image.get(); }
66
67
69 virtual bool isDirty(unsigned int contextID) const { return (_image.valid() && _image->getModifiedCount()!=_modifiedCount[contextID]); }
70
71
72 inline unsigned int& getModifiedCount(unsigned int contextID) const
73 {
74 // get the modified count for the current contextID.
75 return _modifiedCount[contextID];
76 }
77
78
80 virtual void setImage(unsigned int, Image* image) { setImage(image); }
81
83 virtual Image* getImage(unsigned int) { return _image.get(); }
84
86 virtual const Image* getImage(unsigned int) const { return _image.get(); }
87
89 virtual unsigned int getNumImages() const { return 1; }
90
91
94 inline void setTextureWidth(int width) { _textureWidth = width; }
95
97 virtual int getTextureWidth() const { return _textureWidth; }
98 virtual int getTextureHeight() const { return 1; }
99 virtual int getTextureDepth() const { return 1; }
100
101
103 {
104 public:
105 virtual void load(const Texture1D& texture,State& state) const = 0;
106 virtual void subload(const Texture1D& texture,State& state) const = 0;
107 };
108
110
112
113 const SubloadCallback* getSubloadCallback() const { return _subloadCallback.get(); }
114
115
119 void setNumMipmapLevels(unsigned int num) const { _numMipmapLevels=num; }
120
122 unsigned int getNumMipmapLevels() const { return _numMipmapLevels; }
123
124
129 void copyTexImage1D(State& state, int x, int y, int width);
130
135 void copyTexSubImage1D(State& state, int xoffset, int x, int y, int width);
136
137
140 virtual void apply(State& state) const;
141
142 protected :
143
144 virtual ~Texture1D();
145
146 virtual void computeInternalFormat() const;
147 void allocateMipmap(State& state) const;
148
151 void applyTexImage1D(GLenum target, Image* image, State& state, GLsizei& width, GLsizei& numMipmapLevels) const;
152
153
159
161 mutable GLsizei _textureWidth;
162
164 mutable GLsizei _numMipmapLevels;
165
167
170
171
172};
173
174}
175
176#endif
#define GL_TEXTURE_1D
Definition Texture1D:22
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
unsigned int & getModifiedCount(unsigned int contextID) const
Definition Texture1D:72
virtual ~Texture1D()
const Image * getImage() const
Gets the const texture image.
Definition Texture1D:65
void setSubloadCallback(SubloadCallback *cb)
Definition Texture1D:109
Texture1D(Image *image)
virtual Image * getImage(unsigned int)
Gets the texture image, ignoring face.
Definition Texture1D:83
void allocateMipmap(State &state) const
Allocate mipmap levels of the texture by subsequent calling of glTexImage* function.
SubloadCallback * getSubloadCallback()
Definition Texture1D:111
GLsizei _numMipmapLevels
Number of mipmap levels created.
Definition Texture1D:164
Texture1D(const osg::ref_ptr< T > &image)
Definition Texture1D:39
ref_ptr< Image > _image
It's not ideal that _image is mutable, but it's required since Image::ensureDimensionsArePowerOfTwo()...
Definition Texture1D:158
META_StateAttribute(osg, Texture1D, TEXTURE)
virtual void apply(State &state) const
Bind the texture object.
Image * getImage()
Gets the texture image.
Definition Texture1D:62
virtual GLenum getTextureTarget() const
Definition Texture1D:54
void setNumMipmapLevels(unsigned int num) const
Helper function.
Definition Texture1D:119
virtual const Image * getImage(unsigned int) const
Gets the const texture image, ignoring face.
Definition Texture1D:86
void applyTexImage1D(GLenum target, Image *image, State &state, GLsizei &width, GLsizei &numMipmapLevels) const
Helper method.
ImageModifiedCount _modifiedCount
Definition Texture1D:169
buffered_value< unsigned int > ImageModifiedCount
Definition Texture1D:168
GLsizei _textureWidth
Subloaded images can have different texture and image sizes.
Definition Texture1D:161
virtual int compare(const StateAttribute &rhs) const
Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.
Texture1D(const Texture1D &text, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
virtual int getTextureDepth() const
Definition Texture1D:99
void setTextureWidth(int width)
Sets the texture width.
Definition Texture1D:94
virtual int getTextureWidth() const
Gets the texture width.
Definition Texture1D:97
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 Texture1D:69
ref_ptr< SubloadCallback > _subloadCallback
Definition Texture1D:166
virtual unsigned int getNumImages() const
Gets the number of images that can be assigned to the Texture.
Definition Texture1D:89
virtual int getTextureHeight() const
Definition Texture1D:98
void copyTexImage1D(State &state, int x, int y, int width)
Copies pixels into a 1D texture image, as per glCopyTexImage1D.
const SubloadCallback * getSubloadCallback() const
Definition Texture1D:113
void setImage(Image *image)
Sets the texture image.
void copyTexSubImage1D(State &state, int xoffset, int x, int y, int width)
Copies a one-dimensional texture subimage, as per glCopyTexSubImage1D.
virtual void computeInternalFormat() const
void setImage(const ref_ptr< T > &image)
Definition Texture1D:59
virtual void setImage(unsigned int, Image *image)
Sets the texture image, ignoring face.
Definition Texture1D:80
unsigned int getNumMipmapLevels() const
Gets the number of mipmap levels created.
Definition Texture1D:122
Definition Texture1D:103
virtual void load(const Texture1D &texture, State &state) const =0
virtual void subload(const Texture1D &texture, State &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.