root/OpenSceneGraph/trunk/include/osg/TextureCubeMap @ 13041

Revision 13041, 7.0 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
22/** TextureCubeMap state class which encapsulates OpenGL texture cubemap functionality. */
23class OSG_EXPORT TextureCubeMap : public Texture
24{
25
26    public :
27
28        TextureCubeMap();
29
30        /** Copy constructor using CopyOp to manage deep vs shallow copy. */
31        TextureCubeMap(const TextureCubeMap& cm,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
32
33        META_StateAttribute(osg, TextureCubeMap,TEXTURE);
34
35        /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
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
49        /** Set the texture image for specified face. */
50        virtual void setImage(unsigned int face, Image* image);
51
52        /** Get the texture image for specified face. */
53        virtual Image* getImage(unsigned int face);
54
55        /** Get the const texture image for specified face. */
56        virtual const Image* getImage(unsigned int face) const;
57
58        /** Get the number of images that can be assigned to the Texture. */
59        virtual unsigned int getNumImages() const { return 6; }
60
61        inline unsigned int& getModifiedCount(unsigned int face,unsigned int contextID) const
62        {
63            // get the modified count for the current contextID.
64            return _modifiedCount[face][contextID];
65        }
66
67        /** Set the texture width and height. If width or height are zero then
68          * the respective size value is calculated from the source image sizes.
69        */
70        inline void setTextureSize(int width, int height) const
71        {
72            _textureWidth = width;
73            _textureHeight = height;
74        }
75
76        void setTextureWidth(int width) { _textureWidth=width; }
77        void setTextureHeight(int height) { _textureHeight=height; }
78
79        virtual int getTextureWidth() const { return _textureWidth; }
80        virtual int getTextureHeight() const { return _textureHeight; }
81        virtual int getTextureDepth() const { return 1; }
82
83        class OSG_EXPORT SubloadCallback : public Referenced
84        {
85            public:
86                virtual void load(const TextureCubeMap& texture,State& state) const = 0;
87                virtual void subload(const TextureCubeMap& texture,State& state) const = 0;
88        };
89
90        void setSubloadCallback(SubloadCallback* cb) { _subloadCallback = cb;; }
91
92        SubloadCallback* getSubloadCallback() { return _subloadCallback.get(); }
93
94        const SubloadCallback* getSubloadCallback() const { return _subloadCallback.get(); }
95
96
97        /** Set the number of mip map levels the the texture has been created with.
98          * Should only be called within an osg::Texuture::apply() and custom OpenGL texture load.
99        */
100        void setNumMipmapLevels(unsigned int num) const { _numMipmapLevels=num; }
101
102        /** Get the number of mip map levels the the texture has been created with. */
103        unsigned int getNumMipmapLevels() const { return _numMipmapLevels; }
104
105        /** Copies a two-dimensional texture subimage, as per
106          * glCopyTexSubImage2D. Updates a portion of an existing OpenGL
107          * texture object from the current OpenGL background framebuffer
108          * contents at position \a x, \a y with width \a width and height
109          * \a height. Loads framebuffer data into the texture using offsets
110          * \a xoffset and \a yoffset. \a width and \a height must be powers
111          * of two. */
112        void copyTexSubImageCubeMap(State& state, int face, int xoffset, int yoffset, int x, int y, int width, int height );
113
114
115        /** On first apply (unless already compiled), create the mipmapped
116          * texture and bind it. Subsequent apply will simple bind to texture.
117        */
118        virtual void apply(State& state) const;
119
120
121        /** Extensions class which encapsulates the querying of extensions and
122          * associated function pointers, and provides convenience wrappers to
123          * check for the extensions or use the associated functions.
124        */
125        class OSG_EXPORT Extensions : public osg::Referenced
126        {
127            public:
128                Extensions(unsigned int contextID);
129
130                Extensions(const Extensions& rhs);
131
132                void lowestCommonDenominator(const Extensions& rhs);
133
134                void setupGLExtensions(unsigned int contextID);
135
136                void setCubeMapSupported(bool flag) { _isCubeMapSupported=flag; }
137                bool isCubeMapSupported() const { return _isCubeMapSupported; }
138
139            protected:
140
141                ~Extensions() {}
142
143                bool    _isCubeMapSupported;
144
145        };
146
147        /** Function to call to get the extension of a specified context.
148          * If the Extensions object for that context has not yet been created
149          * and the 'createIfNotInitalized' flag been set to false then returns NULL.
150          * If 'createIfNotInitalized' is true then the Extensions object is
151          * automatically created. However, in this case the extension object will
152          * only be created with the graphics context associated with ContextID.
153        */
154        static Extensions* getExtensions(unsigned int contextID,bool createIfNotInitalized);
155
156        /** The setExtensions method allows users to override the extensions across graphics contexts.
157          * Typically used when you have different extensions supported across graphics pipes
158          * but need to ensure that they all use the same low common denominator extensions.
159        */
160        static void setExtensions(unsigned int contextID,Extensions* extensions);
161
162
163    protected :
164
165        virtual ~TextureCubeMap();
166
167        bool imagesValid() const;
168
169        virtual void computeInternalFormat() const;
170        void allocateMipmap(State& state) const;
171
172        ref_ptr<Image> _images[6];
173
174        // subloaded images can have different texture and image sizes.
175        mutable GLsizei _textureWidth, _textureHeight;
176
177        // number of mip map levels the the texture has been created with,
178        mutable GLsizei _numMipmapLevels;
179
180        ref_ptr<SubloadCallback> _subloadCallback;
181
182        typedef buffered_value<unsigned int> ImageModifiedCount;
183        mutable ImageModifiedCount _modifiedCount[6];
184};
185
186}
187
188#endif
Note: See TracBrowser for help on using the browser.