OpenSceneGraph 3.6.5
Texture3D
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
19namespace osg {
20
25{
26
27 public :
28
30
32
33
34 template<class T> Texture3D(const osg::ref_ptr<T>& image):
39 {
40 setImage(image.get());
41 }
42
44 Texture3D(const Texture3D& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
45
47
49 virtual int compare(const StateAttribute& rhs) const;
50
51 virtual GLenum getTextureTarget() const { return GL_TEXTURE_3D; }
52
54 void setImage(Image* image);
55
56 template<class T> void setImage(const ref_ptr<T>& image) { setImage(image.get()); }
57
59 Image* getImage() { return _image.get(); }
60
62 inline const Image* getImage() const { return _image.get(); }
63
65 virtual bool isDirty(unsigned int contextID) const { return (_image.valid() && _image->getModifiedCount()!=_modifiedCount[contextID]); }
66
67 inline unsigned int& getModifiedCount(unsigned int contextID) const
68 {
69 // get the modified count for the current contextID.
70 return _modifiedCount[contextID];
71 }
72
74 virtual void setImage(unsigned int, Image* image) { setImage(image); }
75
77 virtual Image* getImage(unsigned int) { return _image.get(); }
78
80 virtual const Image* getImage(unsigned int) const { return _image.get(); }
81
83 virtual unsigned int getNumImages() const { return 1; }
84
85
89 inline void setTextureSize(int width, int height, int depth) const
90 {
91 _textureWidth = width;
92 _textureHeight = height;
93 _textureDepth = depth;
94 }
95
97 inline void getTextureSize(int& width, int& height, int& depth) const
98 {
99 width = _textureWidth;
100 height = _textureHeight;
101 depth = _textureDepth;
102 }
103
104 void setTextureWidth(int width) { _textureWidth=width; }
105 void setTextureHeight(int height) { _textureHeight=height; }
106 void setTextureDepth(int depth) { _textureDepth=depth; }
107
108 virtual int getTextureWidth() const { return _textureWidth; }
109 virtual int getTextureHeight() const { return _textureHeight; }
110 virtual int getTextureDepth() const { return _textureDepth; }
111
112
114 {
115 public:
116 virtual void load(const Texture3D& texture,State& state) const = 0;
117 virtual void subload(const Texture3D& texture,State& state) const = 0;
118 };
119
121
123
124 const SubloadCallback* getSubloadCallback() const { return _subloadCallback.get(); }
125
126
130 void setNumMipmapLevels(unsigned int num) const { _numMipmapLevels=num; }
131
133 unsigned int getNumMipmapLevels() const { return _numMipmapLevels; }
134
135
143 void copyTexSubImage3D(State& state, int xoffset, int yoffset, int zoffset, int x, int y, int width, int height);
144
145
148 virtual void apply(State& state) const;
149
150 protected :
151
152 virtual ~Texture3D();
153
154 void computeRequiredTextureDimensions(State& state, const osg::Image& image,GLsizei& width, GLsizei& height,GLsizei& depth, GLsizei& numMipmapLevels) const;
155
156 virtual void computeInternalFormat() const;
157 void allocateMipmap(State& state) const;
158
159 void applyTexImage3D(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight, GLsizei& indepth, GLsizei& numMipmapLevels) const;
160
166
169
171 mutable GLsizei _numMipmapLevels;
172
174
177
178};
179
180}
181
182#endif
#define GL_TEXTURE_3D
Definition Texture:188
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 setImage(Image *image)
Sets the texture image.
SubloadCallback * getSubloadCallback()
Definition Texture3D:122
unsigned int getNumMipmapLevels() const
Gets the number of mipmap levels created.
Definition Texture3D:133
virtual int getTextureHeight() const
Definition Texture3D:109
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 Texture3D:65
void setTextureDepth(int depth)
Definition Texture3D:106
const SubloadCallback * getSubloadCallback() const
Definition Texture3D:124
GLsizei _textureDepth
Definition Texture3D:168
void setTextureSize(int width, int height, int depth) const
Sets the texture width, height, and depth.
Definition Texture3D:89
void setImage(const ref_ptr< T > &image)
Definition Texture3D:56
ImageModifiedCount _modifiedCount
Definition Texture3D:176
ref_ptr< SubloadCallback > _subloadCallback
Definition Texture3D:173
const Image * getImage() const
Gets the const texture image.
Definition Texture3D:62
virtual const Image * getImage(unsigned int) const
Gets the const texture image, ignoring face.
Definition Texture3D:80
GLsizei _textureWidth
Subloaded images can have different texture and image sizes.
Definition Texture3D:168
void applyTexImage3D(GLenum target, Image *image, State &state, GLsizei &inwidth, GLsizei &inheight, GLsizei &indepth, GLsizei &numMipmapLevels) const
virtual void computeInternalFormat() const
GLsizei _numMipmapLevels
Number of mip map levels the texture has been created with,.
Definition Texture3D:171
buffered_value< unsigned int > ImageModifiedCount
Definition Texture3D:175
void getTextureSize(int &width, int &height, int &depth) const
Gets the texture subload width.
Definition Texture3D:97
void setTextureHeight(int height)
Definition Texture3D:105
META_StateAttribute(osg, Texture3D, TEXTURE)
Texture3D(Image *image)
unsigned int & getModifiedCount(unsigned int contextID) const
Definition Texture3D:67
void setNumMipmapLevels(unsigned int num) const
Helper function.
Definition Texture3D:130
void setTextureWidth(int width)
Definition Texture3D:104
virtual GLenum getTextureTarget() const
Definition Texture3D:51
virtual int getTextureWidth() const
Definition Texture3D:108
void copyTexSubImage3D(State &state, int xoffset, int yoffset, int zoffset, int x, int y, int width, int height)
Copies a two-dimensional texture subimage, as per glCopyTexSubImage3D.
ref_ptr< Image > _image
It's not ideal that _image is mutable, but it's required since Image::ensureDimensionsArePowerOfTwo()...
Definition Texture3D:165
virtual int getTextureDepth() const
Definition Texture3D:110
virtual int compare(const StateAttribute &rhs) const
Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.
virtual ~Texture3D()
Texture3D(const Texture3D &text, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
void allocateMipmap(State &state) const
Allocate mipmap levels of the texture by subsequent calling of glTexImage* function.
virtual Image * getImage(unsigned int)
Gets the texture image, ignoring face.
Definition Texture3D:77
virtual unsigned int getNumImages() const
Gets the number of images that can be assigned to the Texture.
Definition Texture3D:83
virtual void setImage(unsigned int, Image *image)
Sets the texture image, ignoring face.
Definition Texture3D:74
virtual void apply(State &state) const
Bind the texture object.
void computeRequiredTextureDimensions(State &state, const osg::Image &image, GLsizei &width, GLsizei &height, GLsizei &depth, GLsizei &numMipmapLevels) const
void setSubloadCallback(SubloadCallback *cb)
Definition Texture3D:120
GLsizei _textureHeight
Definition Texture3D:168
Image * getImage()
Gets the texture image.
Definition Texture3D:59
Texture3D(const osg::ref_ptr< T > &image)
Definition Texture3D:34
Definition Texture3D:114
virtual void load(const Texture3D &texture, State &state) const =0
virtual void subload(const Texture3D &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.