OpenSceneGraph 3.6.5
Texture2DArray
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_TEXTURE2DARRAY
15#define OSG_TEXTURE2DARRAY 1
16
17#include <osg/Texture>
18#include <list>
19
20namespace osg {
21
29{
30
31 public :
32
34
37
39
41 virtual int compare(const StateAttribute& rhs) const;
42
43 virtual GLenum getTextureTarget() const { return GL_TEXTURE_2D_ARRAY; }
44
46 virtual bool getModeUsage(StateAttribute::ModeUsage&) const { return false; }
47
49 virtual void setImage(unsigned int layer, Image* image);
50
51 template<class T> void setImage(unsigned int layer, const ref_ptr<T>& image) { setImage(layer, image.get()); }
52
54 virtual Image* getImage(unsigned int layer);
55
57 virtual const Image* getImage(unsigned int layer) const;
58
64 virtual unsigned int getNumImages() const { return _images.size(); }
65
67 virtual bool isDirty(unsigned int contextID) const
68 {
69 for(unsigned int i=0; i<_images.size(); ++i)
70 {
71 if (_images[i].valid() && _images[i]->getModifiedCount()!=_modifiedCount[i][contextID]) return true;
72 }
73 return false;
74 }
75
77 inline unsigned int& getModifiedCount(unsigned int layer, unsigned int contextID) const
78 {
79 // get the modified count for the current contextID.
80 return _modifiedCount[layer][contextID];
81 }
82
87 void setTextureSize(int width, int height, int depth);
88
89 void setTextureWidth(int width) { _textureWidth=width; }
90 void setTextureHeight(int height) { _textureHeight=height; }
91 void setTextureDepth(int depth);
92
93 virtual int getTextureWidth() const { return _textureWidth; }
94 virtual int getTextureHeight() const { return _textureHeight; }
95 virtual int getTextureDepth() const { return _textureDepth; }
96
98 {
99 public:
100 virtual void load(const Texture2DArray& texture,State& state) const = 0;
101 virtual void subload(const Texture2DArray& texture,State& state) const = 0;
102 };
103
104
106
108
109 const SubloadCallback* getSubloadCallback() const { return _subloadCallback.get(); }
110
111
112
116 void setNumMipmapLevels(unsigned int num) const { _numMipmapLevels=num; }
117
119 unsigned int getNumMipmapLevels() const { return _numMipmapLevels; }
120
129 void copyTexSubImage2DArray(State& state, int xoffset, int yoffset, int zoffset, int x, int y, int width, int height );
130
133 virtual void apply(State& state) const;
134
135 protected :
136
138
139 bool imagesValid() const;
140
141 virtual void computeInternalFormat() const;
142 GLsizei computeTextureDepth() const;
143 void allocateMipmap(State& state) const;
144
145 void applyTexImage2DArray_subload(State& state, Image* image, GLsizei layer, GLsizei inwidth, GLsizei inheight, GLsizei indepth, GLint inInternalFormat, GLsizei& numMipmapLevels) const;
146
147 typedef std::vector< ref_ptr<Image> > Images;
149
150 // subloaded images can have different texture and image sizes.
152
153 // number of mip map levels the texture has been created with,
154 mutable GLsizei _numMipmapLevels;
155
157
159 mutable std::vector<ImageModifiedCount> _modifiedCount;
160};
161
162}
163
164#endif
#define GL_TEXTURE_2D_ARRAY
Definition GLDefines:634
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
Definition StateAttribute:308
const SubloadCallback * getSubloadCallback() const
Definition Texture2DArray:109
virtual bool getModeUsage(StateAttribute::ModeUsage &) const
Texture2DArray is related to non fixed pipeline usage only so isn't appropriate to enable/disable.
Definition Texture2DArray:46
virtual int compare(const StateAttribute &rhs) const
Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.
void setTextureWidth(int width)
Definition Texture2DArray:89
virtual int getTextureDepth() const
Definition Texture2DArray:95
GLsizei _textureWidth
Definition Texture2DArray:151
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 Texture2DArray:67
virtual ~Texture2DArray()
void setTextureSize(int width, int height, int depth)
Set the texture width and height.
void setImage(unsigned int layer, const ref_ptr< T > &image)
Definition Texture2DArray:51
virtual void apply(State &state) const
Bind the texture if already compiled.
virtual void setImage(unsigned int layer, Image *image)
Set the texture image for specified layer.
void setNumMipmapLevels(unsigned int num) const
Set the number of mip map levels the texture has been created with.
Definition Texture2DArray:116
virtual Image * getImage(unsigned int layer)
Get the texture image for specified layer.
bool imagesValid() const
Texture2DArray(const Texture2DArray &cm, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
virtual void computeInternalFormat() const
std::vector< ImageModifiedCount > _modifiedCount
Definition Texture2DArray:159
void copyTexSubImage2DArray(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.
virtual unsigned int getNumImages() const
Get the number of images that are assigned to the Texture.
Definition Texture2DArray:64
virtual GLenum getTextureTarget() const
Definition Texture2DArray:43
void setSubloadCallback(SubloadCallback *cb)
Definition Texture2DArray:105
GLsizei _textureHeight
Definition Texture2DArray:151
std::vector< ref_ptr< Image > > Images
Definition Texture2DArray:147
void applyTexImage2DArray_subload(State &state, Image *image, GLsizei layer, GLsizei inwidth, GLsizei inheight, GLsizei indepth, GLint inInternalFormat, GLsizei &numMipmapLevels) const
unsigned int & getModifiedCount(unsigned int layer, unsigned int contextID) const
Check how often was a certain layer in the given context modified.
Definition Texture2DArray:77
virtual const Image * getImage(unsigned int layer) const
Get the const texture image for specified layer.
void allocateMipmap(State &state) const
Allocate mipmap levels of the texture by subsequent calling of glTexImage* function.
virtual int getTextureHeight() const
Definition Texture2DArray:94
ref_ptr< SubloadCallback > _subloadCallback
Definition Texture2DArray:156
Images _images
Definition Texture2DArray:148
GLsizei _textureDepth
Definition Texture2DArray:151
SubloadCallback * getSubloadCallback()
Definition Texture2DArray:107
virtual int getTextureWidth() const
Definition Texture2DArray:93
unsigned int getNumMipmapLevels() const
Get the number of mip map levels the texture has been created with.
Definition Texture2DArray:119
META_StateAttribute(osg, Texture2DArray, TEXTURE)
void setTextureDepth(int depth)
GLsizei computeTextureDepth() const
GLsizei _numMipmapLevels
Definition Texture2DArray:154
void setTextureHeight(int height)
Definition Texture2DArray:90
buffered_value< unsigned int > ImageModifiedCount
Definition Texture2DArray:158
Definition Texture2DArray:98
virtual void load(const Texture2DArray &texture, State &state) const =0
virtual void subload(const Texture2DArray &texture, State &state) const =0
#define OSG_EXPORT
Definition Export:39

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.