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

Revision 13041, 9.7 kB (checked in by robert, 3 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_TEXTURE3D
15#define OSG_TEXTURE3D 1
16
17#include <osg/Texture>
18
19#ifndef GL_MAX_3D_TEXTURE_SIZE
20    #define GL_MAX_3D_TEXTURE_SIZE      0x8073
21#endif
22
23namespace osg {
24
25/** Encapsulates OpenGL 2D texture functionality. Doesn't support cube maps,
26  * so ignore \a face parameters.
27*/
28class OSG_EXPORT Texture3D : public Texture
29{
30
31    public :
32
33        Texture3D();
34
35        Texture3D(Image* image);
36
37        /** Copy constructor using CopyOp to manage deep vs shallow copy. */
38        Texture3D(const Texture3D& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
39
40        META_StateAttribute(osg, Texture3D,TEXTURE);
41
42        /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
43        virtual int compare(const StateAttribute& rhs) const;
44
45        virtual GLenum getTextureTarget() const { return GL_TEXTURE_3D; }
46
47        /** Sets the texture image. */
48        void setImage(Image* image);
49
50        /** Gets the texture image. */
51        Image* getImage() { return _image.get(); }
52
53        /** Gets the const texture image. */
54        inline const Image* getImage() const { return _image.get(); }
55
56        inline unsigned int& getModifiedCount(unsigned int contextID) const
57        {
58            // get the modified count for the current contextID.
59            return _modifiedCount[contextID];
60        }
61
62        /** Sets the texture image, ignoring face. */
63        virtual void setImage(unsigned int, Image* image) { setImage(image); }
64
65        /** Gets the texture image, ignoring face. */
66        virtual Image* getImage(unsigned int) { return _image.get(); }
67
68        /** Gets the const texture image, ignoring face. */
69        virtual const Image* getImage(unsigned int) const { return _image.get(); }
70
71        /** Gets the number of images that can be assigned to the Texture. */
72        virtual unsigned int getNumImages() const { return 1; }
73
74
75        /** Sets the texture width, height, and depth. If width, height, or
76          * depth are zero, calculate the respective value from the source
77          * image size. */
78        inline void setTextureSize(int width, int height, int depth) const
79        {
80            _textureWidth = width;
81            _textureHeight = height;
82            _textureDepth = depth;
83        }
84
85        /** Gets the texture subload width. */
86        inline void getTextureSize(int& width, int& height, int& depth) const
87        {
88            width = _textureWidth;
89            height = _textureHeight;
90            depth = _textureDepth;
91        }
92
93        void setTextureWidth(int width) { _textureWidth=width; }
94        void setTextureHeight(int height) { _textureHeight=height; }
95        void setTextureDepth(int depth) { _textureDepth=depth; }
96
97        virtual int getTextureWidth() const { return _textureWidth; }
98        virtual int getTextureHeight() const { return _textureHeight; }
99        virtual int getTextureDepth() const { return _textureDepth; }
100
101
102        class OSG_EXPORT SubloadCallback : public Referenced
103        {
104            public:
105                virtual void load(const Texture3D& texture,State& state) const = 0;
106                virtual void subload(const Texture3D& texture,State& state) const = 0;
107        };
108
109        void setSubloadCallback(SubloadCallback* cb) { _subloadCallback = cb;; }
110
111        SubloadCallback* getSubloadCallback() { return _subloadCallback.get(); }
112
113        const SubloadCallback* getSubloadCallback() const { return _subloadCallback.get(); }
114
115
116        /** Helper function. Sets the number of mipmap levels created for this
117          * texture. Should only be called within an osg::Texture::apply(), or
118          * during a custom OpenGL texture load. */
119        void setNumMipmapLevels(unsigned int num) const { _numMipmapLevels=num; }
120
121        /** Gets the number of mipmap levels created. */
122        unsigned int getNumMipmapLevels() const { return _numMipmapLevels; }
123
124
125        /** Copies a two-dimensional texture subimage, as per
126          * glCopyTexSubImage3D. Updates a portion of an existing OpenGL
127          * texture object from the current OpenGL background framebuffer
128          * contents at position \a x, \a y with width \a width and height
129          * \a height. Loads framebuffer data into the texture using offsets
130          * \a xoffset, \a yoffset, and \a zoffset. \a width and \a height
131          * must be powers of two. */
132        void copyTexSubImage3D(State& state, int xoffset, int yoffset, int zoffset, int x, int y, int width, int height);
133
134
135        /** Bind the texture object. If the texture object hasn't already been
136          * compiled, create the texture mipmap levels. */
137        virtual void apply(State& state) const;
138
139
140        /** Encapsulates queries of extension availability, obtains extension
141          * function pointers, and provides convenience wrappers for
142          * calling extension functions. */
143        class OSG_EXPORT Extensions : public osg::Referenced
144        {
145            public:
146                Extensions(unsigned int contextID);
147
148                Extensions(const Extensions& rhs);
149
150                void lowestCommonDenominator(const Extensions& rhs);
151
152                void setupGLExtensions(unsigned int contextID);
153
154                void setTexture3DSupported(bool flag) { _isTexture3DSupported=flag; }
155                bool isTexture3DSupported() const { return _isTexture3DSupported; }
156
157                void setTexture3DFast(bool flag) { _isTexture3DFast=flag; }
158                bool isTexture3DFast() const { return _isTexture3DFast; }
159
160                void setMaxTexture3DSize(GLint maxsize) { _maxTexture3DSize=maxsize; }
161                GLint maxTexture3DSize() const { return _maxTexture3DSize; }
162
163                bool isCompressedTexImage3DSupported() const { return glCompressedTexImage3D!=0; }
164
165                bool isCompressedTexSubImage3DSupported() const { return glCompressedTexSubImage3D!=0; }
166
167                typedef void (GL_APIENTRY * GLTexImage3DProc)      ( GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
168                typedef void (GL_APIENTRY * GLTexSubImage3DProc)   ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels);
169                typedef void (GL_APIENTRY * CompressedTexImage3DArbProc) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid *data);
170                typedef void (GL_APIENTRY * CompressedTexSubImage3DArbProc) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid *data);
171                typedef void (GL_APIENTRY * GLCopyTexSubImageProc) ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height );
172
173                GLTexImage3DProc glTexImage3D;
174                GLTexSubImage3DProc glTexSubImage3D;
175                CompressedTexImage3DArbProc glCompressedTexImage3D;
176                CompressedTexSubImage3DArbProc   glCompressedTexSubImage3D;
177                GLCopyTexSubImageProc glCopyTexSubImage3D;
178
179            protected:
180
181                ~Extensions() {}
182
183                bool    _isTexture3DSupported;
184                bool    _isTexture3DFast;
185                GLint   _maxTexture3DSize;
186        };
187
188        /** Encapsulates queries of extension availability, obtains extension
189          * function pointers, and provides convenience wrappers for
190          * calling extension functions. */
191        static Extensions* getExtensions(unsigned int contextID,bool createIfNotInitalized);
192
193        /** Overrides Extensions objects across graphics contexts. Typically
194          * used to ensure the same lowest common denominator of extensions
195          * on systems with different graphics pipes. */
196        static void setExtensions(unsigned int contextID,Extensions* extensions);
197
198    protected :
199
200        virtual ~Texture3D();
201
202        void computeRequiredTextureDimensions(State& state, const osg::Image& image,GLsizei& width, GLsizei& height,GLsizei& depth, GLsizei& numMipmapLevels) const;
203
204        virtual void computeInternalFormat() const;
205        void allocateMipmap(State& state) const;
206
207        void applyTexImage3D(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight, GLsizei& indepth, GLsizei& numMipmapLevels) const;
208
209        /** It's not ideal that _image is mutable, but it's required since
210          * Image::ensureDimensionsArePowerOfTwo() can only be called in a
211          * valid OpenGL context, and therefore within Texture::apply, which
212          * is const. */
213        mutable ref_ptr<Image> _image;
214
215        /** Subloaded images can have different texture and image sizes. */
216        mutable GLsizei _textureWidth, _textureHeight, _textureDepth;
217
218        /** Number of mip map levels the the texture has been created with, */
219        mutable GLsizei _numMipmapLevels;
220
221        ref_ptr<SubloadCallback> _subloadCallback;
222
223        typedef buffered_value<unsigned int> ImageModifiedCount;
224        mutable ImageModifiedCount _modifiedCount;
225
226};
227
228}
229
230#endif
Note: See TracBrowser for help on using the browser.