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

Revision 13041, 5.7 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// -*-c++-*-
15
16#ifndef OSG_TEXTURE1D
17#define OSG_TEXTURE1D 1
18
19#include <osg/Texture>
20
21#ifndef GL_TEXTURE_1D
22    #define GL_TEXTURE_1D 0x0DE0
23#endif
24
25namespace osg {
26
27/** Encapsulates OpenGL 1D texture functionality. Doesn't support cube maps,
28  * so ignore \a face parameters.
29*/
30class OSG_EXPORT Texture1D : public Texture
31{
32
33    public :
34
35        Texture1D();
36
37        Texture1D(Image* image);
38
39        /** Copy constructor using CopyOp to manage deep vs shallow copy. */
40        Texture1D(const Texture1D& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
41
42        META_StateAttribute(osg, Texture1D,TEXTURE);
43
44        /** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
45        virtual int compare(const StateAttribute& rhs) const;
46
47        virtual GLenum getTextureTarget() const { return GL_TEXTURE_1D; }
48
49        /** Sets the texture image. */
50        void setImage(Image* image);
51
52        /** Gets the texture image. */
53        Image* getImage() { return _image.get(); }
54
55        /** Gets the const texture image. */
56        inline const Image* getImage() const { return _image.get(); }
57
58        inline unsigned int& getModifiedCount(unsigned int contextID) const
59        {
60            // get the modified count for the current contextID.
61            return _modifiedCount[contextID];
62        }
63
64
65        /** Sets the texture image, ignoring face. */
66        virtual void setImage(unsigned int, Image* image) { setImage(image); }
67
68        /** Gets the texture image, ignoring face. */
69        virtual Image* getImage(unsigned int) { return _image.get(); }
70
71        /** Gets the const texture image, ignoring face. */
72        virtual const Image* getImage(unsigned int) const { return _image.get(); }
73
74        /** Gets the number of images that can be assigned to the Texture. */
75        virtual unsigned int getNumImages() const { return 1; }
76
77
78        /** Sets the texture width. If width is zero, calculate the value
79          * from the source image width. */
80        inline void setTextureWidth(int width) { _textureWidth = width; }
81
82        /** Gets the texture width. */
83        virtual int getTextureWidth() const { return _textureWidth; }
84        virtual int getTextureHeight() const { return 1; }
85        virtual int getTextureDepth() const { return 1; }
86
87
88        class OSG_EXPORT SubloadCallback : public Referenced
89        {
90            public:
91                virtual void load(const Texture1D& texture,State& state) const = 0;
92                virtual void subload(const Texture1D& texture,State& state) const = 0;
93        };
94
95        void setSubloadCallback(SubloadCallback* cb) { _subloadCallback = cb;; }
96
97        SubloadCallback* getSubloadCallback() { return _subloadCallback.get(); }
98
99        const SubloadCallback* getSubloadCallback() const { return _subloadCallback.get(); }
100
101
102        /** Helper function. Sets the number of mipmap levels created for this
103          * texture. Should only be called within an osg::Texture::apply(), or
104          * during a custom OpenGL texture load. */
105        void setNumMipmapLevels(unsigned int num) const { _numMipmapLevels=num; }
106
107        /** Gets the number of mipmap levels created. */
108        unsigned int getNumMipmapLevels() const { return _numMipmapLevels; }
109
110
111        /** Copies pixels into a 1D texture image, as per glCopyTexImage1D.
112          * Creates an OpenGL texture object from the current OpenGL background
113          * framebuffer contents at position \a x, \a y with width \a width.
114          * \a width must be a power of two. */
115        void copyTexImage1D(State& state, int x, int y, int width);
116
117        /** Copies a one-dimensional texture subimage, as per
118          * glCopyTexSubImage1D. Updates a portion of an existing OpenGL
119          * texture object from the current OpenGL background framebuffer
120          * contents at position \a x, \a y with width \a width. */
121        void copyTexSubImage1D(State& state, int xoffset, int x, int y, int width);
122
123
124        /** Bind the texture object. If the texture object hasn't already been
125          * compiled, create the texture mipmap levels. */
126        virtual void apply(State& state) const;
127
128    protected :
129
130        virtual ~Texture1D();
131
132        virtual void computeInternalFormat() const;
133        void allocateMipmap(State& state) const;
134
135        /** Helper method. Create the texture without setting or using a
136          * texture binding. */
137        void applyTexImage1D(GLenum target, Image* image, State& state, GLsizei& width, GLsizei& numMipmapLevels) const;
138
139
140        /** It's not ideal that _image is mutable, but it's required since
141          * Image::ensureDimensionsArePowerOfTwo() can only be called in a
142          * valid OpenGL context, and therefore within Texture::apply, which
143          * is const. */
144        mutable ref_ptr<Image> _image;
145
146        /** Subloaded images can have different texture and image sizes. */
147        mutable GLsizei _textureWidth;
148
149        /** Number of mipmap levels created. */
150        mutable GLsizei _numMipmapLevels;
151
152        ref_ptr<SubloadCallback> _subloadCallback;
153
154        typedef buffered_value<unsigned int> ImageModifiedCount;
155        mutable ImageModifiedCount _modifiedCount;
156
157
158};
159
160}
161
162#endif
Note: See TracBrowser for help on using the browser.