openscenegraph
TextureCubeMap
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_TEXTURECUBEMAP
15#define OSG_TEXTURECUBEMAP 1
16
17#include <osg/Texture>
18
19
20namespace osg {
21
24{
25
26 public :
27
29
31 TextureCubeMap(const TextureCubeMap& cm,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
32
34
36 virtual int compare(const StateAttribute& rhs) const;
37
38 virtual GLenum getTextureTarget() const { return GL_TEXTURE_CUBE_MAP; }
39
40 enum Face {
41 POSITIVE_X=0,
42 NEGATIVE_X=1,
43 POSITIVE_Y=2,
44 NEGATIVE_Y=3,
45 POSITIVE_Z=4,
46 NEGATIVE_Z=5
47 };
48
50 virtual void setImage(unsigned int face, Image* image);
51
52 template<class T> void setImage(unsigned int face, const ref_ptr<T>& image) { setImage(face, image.get()); }
53
55 virtual Image* getImage(unsigned int face);
56
58 virtual const Image* getImage(unsigned int face) const;
59
61 virtual unsigned int getNumImages() const { return 6; }
62
63
65 virtual bool isDirty(unsigned int contextID) const
66 {
67 return (_images[0].valid() && _images[0]->getModifiedCount()!=_modifiedCount[0][contextID]) ||
68 (_images[1].valid() && _images[1]->getModifiedCount()!=_modifiedCount[1][contextID]) ||
69 (_images[2].valid() && _images[2]->getModifiedCount()!=_modifiedCount[2][contextID]) ||
70 (_images[3].valid() && _images[3]->getModifiedCount()!=_modifiedCount[3][contextID]) ||
71 (_images[4].valid() && _images[4]->getModifiedCount()!=_modifiedCount[4][contextID]) ||
72 (_images[5].valid() && _images[5]->getModifiedCount()!=_modifiedCount[5][contextID]);
73 }
74
75 inline unsigned int& getModifiedCount(unsigned int face,unsigned int contextID) const
76 {
77 // get the modified count for the current contextID.
78 return _modifiedCount[face][contextID];
79 }
80
84 inline void setTextureSize(int width, int height) const
85 {
86 _textureWidth = width;
87 _textureHeight = height;
88 }
89
90 void setTextureWidth(int width) { _textureWidth=width; }
91 void setTextureHeight(int height) { _textureHeight=height; }
92
93 virtual int getTextureWidth() const { return _textureWidth; }
94 virtual int getTextureHeight() const { return _textureHeight; }
95 virtual int getTextureDepth() const { return 1; }
96
98 {
99 public:
100 virtual void load(const TextureCubeMap& texture,State& state) const = 0;
101 virtual void subload(const TextureCubeMap& texture,State& state) const = 0;
102 };
103
104 void setSubloadCallback(SubloadCallback* cb) { _subloadCallback = cb;; }
105
106 SubloadCallback* getSubloadCallback() { return _subloadCallback.get(); }
107
108 const SubloadCallback* getSubloadCallback() const { return _subloadCallback.get(); }
109
110
114 void setNumMipmapLevels(unsigned int num) const { _numMipmapLevels=num; }
115
117 unsigned int getNumMipmapLevels() const { return _numMipmapLevels; }
118
126 void copyTexSubImageCubeMap(State& state, int face, int xoffset, int yoffset, int x, int y, int width, int height );
127
128
132 virtual void apply(State& state) const;
133
134 protected :
135
137
138 bool imagesValid() const;
139
140 virtual void computeInternalFormat() const;
141 void allocateMipmap(State& state) const;
142
143 ref_ptr<Image> _images[6];
144
145 // subloaded images can have different texture and image sizes.
146 mutable GLsizei _textureWidth, _textureHeight;
147
148 // number of mip map levels the texture has been created with,
149 mutable GLsizei _numMipmapLevels;
150
152
154 mutable ImageModifiedCount _modifiedCount[6];
155};
156
157}
158
159#endif
#define GL_TEXTURE_CUBE_MAP
Definition Texture:193
Definition CopyOp:41
Definition Image:179
Definition Referenced:44
Definition StateAttribute:77
Definition State:80
Definition TextureCubeMap:98
virtual void subload(const TextureCubeMap &texture, State &state) const =0
virtual void load(const TextureCubeMap &texture, State &state) const =0
Definition TextureCubeMap:24
SubloadCallback * getSubloadCallback()
Definition TextureCubeMap:106
unsigned int & getModifiedCount(unsigned int face, unsigned int contextID) const
Definition TextureCubeMap:75
virtual int compare(const StateAttribute &rhs) const
virtual unsigned int getNumImages() const
Definition TextureCubeMap:61
unsigned int getNumMipmapLevels() const
Definition TextureCubeMap:117
void setTextureHeight(int height)
Definition TextureCubeMap:91
virtual int getTextureDepth() const
Definition TextureCubeMap:95
void setTextureSize(int width, int height) const
Definition TextureCubeMap:84
virtual void setImage(unsigned int face, Image *image)
const SubloadCallback * getSubloadCallback() const
Definition TextureCubeMap:108
virtual void apply(State &state) const
bool imagesValid() const
void setNumMipmapLevels(unsigned int num) const
Definition TextureCubeMap:114
GLsizei _textureHeight
Definition TextureCubeMap:146
GLsizei _numMipmapLevels
Definition TextureCubeMap:149
virtual int getTextureHeight() const
Definition TextureCubeMap:94
TextureCubeMap(const TextureCubeMap &cm, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
ref_ptr< SubloadCallback > _subloadCallback
Definition TextureCubeMap:151
void allocateMipmap(State &state) const
void setSubloadCallback(SubloadCallback *cb)
Definition TextureCubeMap:104
virtual void computeInternalFormat() const
void copyTexSubImageCubeMap(State &state, int face, int xoffset, int yoffset, int x, int y, int width, int height)
virtual GLenum getTextureTarget() const
Definition TextureCubeMap:38
virtual ~TextureCubeMap()
META_StateAttribute(osg, TextureCubeMap, TEXTURE)
virtual bool isDirty(unsigned int contextID) const
Definition TextureCubeMap:65
virtual int getTextureWidth() const
Definition TextureCubeMap:93
Face
Definition TextureCubeMap:40
virtual const Image * getImage(unsigned int face) const
virtual Image * getImage(unsigned int face)
void setTextureWidth(int width)
Definition TextureCubeMap:90
void setImage(unsigned int face, const ref_ptr< T > &image)
Definition TextureCubeMap:52
buffered_value< unsigned int > ImageModifiedCount
Definition TextureCubeMap:153
Definition Texture:422
Definition buffered_value:27
Definition ref_ptr:32
T * get() const
Definition ref_ptr:117
author: Julien Valentin 2017 (mp3butcher@hotmail.com)
Definition AlphaFunc:19
#define OSG_EXPORT
Definition osg/Export:39