openscenegraph
TextureRectangle
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_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
31{
32
33 public :
34
36
38
39 template<class T> TextureRectangle(const osg::ref_ptr<T>& image):
40 _textureWidth(0),
41 _textureHeight(0)
42 {
43 setWrap(WRAP_S, CLAMP);
44 setWrap(WRAP_T, CLAMP);
45
46 setFilter(MIN_FILTER, LINEAR);
47 setFilter(MAG_FILTER, LINEAR);
48
49 setImage(image.get());
50 }
51
53 TextureRectangle(const TextureRectangle& text,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
54
56
58 virtual int compare(const StateAttribute& rhs) const;
59
60 virtual GLenum getTextureTarget() const { return GL_TEXTURE_RECTANGLE; }
61
63 void setImage(Image* image);
64
65 template<class T> void setImage(const ref_ptr<T>& image) { setImage(image.get()); }
66
68 Image* getImage() { return _image.get(); }
69
71 inline const Image* getImage() const { return _image.get(); }
72
74 virtual bool isDirty(unsigned int contextID) const { return (_image.valid() && _image->getModifiedCount()!=_modifiedCount[contextID]); }
75
76 inline unsigned int& getModifiedCount(unsigned int contextID) const
77 {
78 // get the modified count for the current contextID.
79 return _modifiedCount[contextID];
80 }
81
82
84 virtual void setImage(unsigned int, Image* image) { setImage(image); }
85
87 virtual Image* getImage(unsigned int) { return _image.get(); }
88
90 virtual const Image* getImage(unsigned int) const { return _image.get(); }
91
93 virtual unsigned int getNumImages() const { return 1; }
94
95
99 inline void setTextureSize(int width, int height) const
100 {
101 _textureWidth = width;
102 _textureHeight = height;
103 }
104
105 void setTextureWidth(int width) { _textureWidth=width; }
106 void setTextureHeight(int height) { _textureHeight=height; }
107
108 virtual int getTextureWidth() const { return _textureWidth; }
109 virtual int getTextureHeight() const { return _textureHeight; }
110 virtual int getTextureDepth() const { return 1; }
111
113 {
114 public:
115 virtual void load(const TextureRectangle&, State&) const = 0;
116 virtual void subload(const TextureRectangle&, State&) const = 0;
117 };
118
119 void setSubloadCallback(SubloadCallback* cb) { _subloadCallback = cb;; }
120 SubloadCallback* getSubloadCallback() { return _subloadCallback.get(); }
121 const SubloadCallback* getSubloadCallback() const { return _subloadCallback.get(); }
122
127 void copyTexImage2D(State& state, int x, int y, int width, int height );
128
136 void copyTexSubImage2D(State& state, int xoffset, int yoffset, int x, int y, int width, int height );
137
141 virtual void apply(State& state) const;
142
143 protected :
144
146
147 virtual void computeInternalFormat() const;
148 void allocateMipmap(State& state) const;
149
150 void applyTexImage_load(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight) const;
151 void applyTexImage_subload(GLenum target, Image* image, State& state, GLsizei& inwidth, GLsizei& inheight, GLint& inInternalFormat) const;
152
154
155 // subloaded images can have different texture and image sizes.
156 mutable GLsizei _textureWidth, _textureHeight;
157
159
162};
163
164}
165
166#endif
#define GL_TEXTURE_RECTANGLE
Definition GLDefines:406
Definition CopyOp:41
Definition Image:179
Definition Referenced:44
Definition StateAttribute:77
Definition State:80
Definition TextureRectangle:113
virtual void load(const TextureRectangle &, State &) const =0
virtual void subload(const TextureRectangle &, State &) const =0
Definition TextureRectangle:31
const SubloadCallback * getSubloadCallback() const
Definition TextureRectangle:121
void setImage(Image *image)
virtual int compare(const StateAttribute &rhs) const
buffered_value< unsigned int > ImageModifiedCount
Definition TextureRectangle:160
void setSubloadCallback(SubloadCallback *cb)
Definition TextureRectangle:119
TextureRectangle(Image *image)
unsigned int & getModifiedCount(unsigned int contextID) const
Definition TextureRectangle:76
void setTextureWidth(int width)
Definition TextureRectangle:105
void setTextureSize(int width, int height) const
Definition TextureRectangle:99
virtual void setImage(unsigned int, Image *image)
Definition TextureRectangle:84
virtual int getTextureWidth() const
Definition TextureRectangle:108
ref_ptr< Image > _image
Definition TextureRectangle:153
Image * getImage()
Definition TextureRectangle:68
void applyTexImage_subload(GLenum target, Image *image, State &state, GLsizei &inwidth, GLsizei &inheight, GLint &inInternalFormat) const
virtual bool isDirty(unsigned int contextID) const
Definition TextureRectangle:74
ref_ptr< SubloadCallback > _subloadCallback
Definition TextureRectangle:158
void allocateMipmap(State &state) const
void setImage(const ref_ptr< T > &image)
Definition TextureRectangle:65
ImageModifiedCount _modifiedCount
Definition TextureRectangle:161
TextureRectangle(const TextureRectangle &text, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
const Image * getImage() const
Definition TextureRectangle:71
TextureRectangle(const osg::ref_ptr< T > &image)
Definition TextureRectangle:39
void setTextureHeight(int height)
Definition TextureRectangle:106
virtual void apply(State &state) const
void applyTexImage_load(GLenum target, Image *image, State &state, GLsizei &inwidth, GLsizei &inheight) const
virtual int getTextureDepth() const
Definition TextureRectangle:110
void copyTexImage2D(State &state, int x, int y, int width, int height)
virtual Image * getImage(unsigned int)
Definition TextureRectangle:87
virtual GLenum getTextureTarget() const
Definition TextureRectangle:60
virtual int getTextureHeight() const
Definition TextureRectangle:109
META_StateAttribute(osg, TextureRectangle, TEXTURE)
void copyTexSubImage2D(State &state, int xoffset, int yoffset, int x, int y, int width, int height)
SubloadCallback * getSubloadCallback()
Definition TextureRectangle:120
virtual const Image * getImage(unsigned int) const
Definition TextureRectangle:90
virtual void computeInternalFormat() const
virtual unsigned int getNumImages() const
Definition TextureRectangle:93
GLsizei _textureHeight
Definition TextureRectangle:156
virtual ~TextureRectangle()
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