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

Revision 13041, 5.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_TEXTURERECTANGLE
15#define OSG_TEXTURERECTANGLE 1
16
17#include <osg/Texture>
18
19#ifndef GL_TEXTURE_RECTANGLE_NV
20#define GL_TEXTURE_RECTANGLE_NV           0x84F5
21#endif
22
23#ifndef GL_TEXTURE_RECTANGLE
24#define GL_TEXTURE_RECTANGLE GL_TEXTURE_RECTANGLE_NV
25#endif
26
27namespace osg {
28
29/** Texture state class which encapsulates OpenGL texture functionality. */
30class OSG_EXPORT TextureRectangle : public Texture
31{
32
33    public :
34
35        TextureRectangle();
36
37        TextureRectangle(Image* image);
38
39        /** Copy constructor using CopyOp to manage deep vs shallow copy. */
40        TextureRectangle(const TextureRectangle& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
41
42        META_StateAttribute(osg, TextureRectangle, 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_RECTANGLE; }
48
49        /** Set the texture image. */
50        void setImage(Image* image);
51
52        /** Get the texture image. */
53        Image* getImage() { return _image.get(); }
54
55        /** Get 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        /** Set the texture image, ignoring face value as there is only one image. */
66        virtual void setImage(unsigned int, Image* image) { setImage(image); }
67
68        /** Get the texture image, ignoring face value as there is only one image. */
69        virtual Image* getImage(unsigned int) { return _image.get(); }
70
71        /** Get the const texture image, ignoring face value as there is only one image. */
72        virtual const Image* getImage(unsigned int) const { return _image.get(); }
73
74        /** Get the number of images that can be assigned to the Texture. */
75        virtual unsigned int getNumImages() const { return 1; }
76
77
78        /** Set the texture width and height. If width or height are zero then
79          * the respective size value is calculated from the source image sizes.
80        */
81        inline void setTextureSize(int width, int height) const
82        {
83            _textureWidth = width;
84            _textureHeight = height;
85        }
86
87        void setTextureWidth(int width) { _textureWidth=width; }
88        void setTextureHeight(int height) { _textureHeight=height; }
89
90        virtual int getTextureWidth() const { return _textureWidth; }
91        virtual int getTextureHeight() const { return _textureHeight; }
92        virtual int getTextureDepth() const { return 1; }
93
94        class SubloadCallback : public Referenced
95        {
96        public:
97            virtual void load(const TextureRectangle&, State&) const = 0;
98            virtual void subload(const TextureRectangle&, State&) const = 0;
99        };
100
101        void setSubloadCallback(SubloadCallback* cb) { _subloadCallback = cb;; }
102        SubloadCallback* getSubloadCallback() { return _subloadCallback.get(); }
103        const SubloadCallback* getSubloadCallback() const { return _subloadCallback.get(); }
104
105        /** Copies pixels into a 2D texture image, as per glCopyTexImage2D.
106          * Creates an OpenGL texture object from the current OpenGL background
107          * framebuffer contents at position \a x, \a y with width \a width and
108          * height \a height. \a width and \a height must be a power of two. */
109        void copyTexImage2D(State& state, int x, int y, int width, int height );
110
111        /** Copies a two-dimensional texture subimage, as per
112          * glCopyTexSubImage2D. Updates a portion of an existing OpenGL
113          * texture object from the current OpenGL background framebuffer
114          * contents at position \a x, \a y with width \a width and height
115          * \a height. Loads framebuffer data into the texture using offsets
116          * \a xoffset and \a yoffset. \a width and \a height must be powers
117          * of two. */
118        void copyTexSubImage2D(State& state, int xoffset, int yoffset, int x, int y, int width, int height );
119
120        /** On first apply (unless already compiled), create and bind the
121          * texture, subsequent apply will simply bind to texture.
122        */
123        virtual void apply(State& state) const;
124
125    protected :
126
127        virtual ~TextureRectangle();
128
129        virtual void computeInternalFormat() const;
130        void allocateMipmap(State& state) const;
131
132        void applyTexImage_load(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight) const;
133        void applyTexImage_subload(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight, GLint& inInternalFormat) const;
134
135        ref_ptr<Image> _image;
136
137        // subloaded images can have different texture and image sizes.
138        mutable GLsizei _textureWidth, _textureHeight;
139
140        ref_ptr<SubloadCallback> _subloadCallback;
141
142        typedef buffered_value<unsigned int> ImageModifiedCount;
143        mutable ImageModifiedCount _modifiedCount;
144};
145
146}
147
148#endif
Note: See TracBrowser for help on using the browser.