TextureNode.hh
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #ifndef ACG_TEXTURE_NODE_HH
00054 #define ACG_TEXTURE_NODE_HH
00055
00056
00057
00058
00059
00060 #include "BaseNode.hh"
00061
00062 #include <string>
00063 #include <QImage>
00064
00065
00066
00067
00068 namespace ACG {
00069 namespace SceneGraph {
00070
00071
00072
00073
00074
00084 class ACGDLLEXPORT TextureNode : public BaseNode
00085 {
00086 public:
00087
00089 TextureNode( BaseNode* _parent = 0,
00090 const std::string& _name = "<TextureNode>",
00091 bool _texture_repeat = true,
00092 GLint _texture_filter = GL_LINEAR );
00093
00095 virtual ~TextureNode();
00096
00098 ACG_CLASSNAME(TextureNode);
00099
00101 bool alpha() { return alpha_; }
00102
00104 void set_alpha(bool _status) { alpha_ = _status; }
00105
00107 bool repeat() { return texture_repeat_; }
00108
00110 void set_repeat(bool _status) { texture_repeat_ = _status; }
00111
00113 GLint filter() { return texture_filter_; }
00114
00116 void set_filter( GLint _filter ) { texture_filter_ = _filter; }
00117
00118 void set_texture_mode( GLenum _mode) { tex_mode_ = _mode; }
00119
00120
00121
00124
00125
00128
00131
00132
00133 public:
00134
00135
00139 GLuint add_texture(const QImage& _image);
00140
00141 private:
00144 void applyTextureParameters( int _id );
00145
00148 void applyGLSettings( );
00149
00152
00155
00156
00157 public :
00158
00164 bool activateTexture(GLuint _id);
00165
00171 GLuint activeTexture();
00172
00178 bool read(const char* _filename);
00179
00185 void set_texture(const QImage& _image);
00186
00194 void set_texture(const float * _image, int _width, int _height);
00195
00196
00204 void set_texture(const unsigned char * _image, int _width, int _height);
00205
00208
00211
00212
00213 public :
00214
00220 bool read(const char* _filename, GLuint _id );
00221
00227 void set_texture(const QImage& _image, GLuint _id);
00228
00236 void set_texture(const float * _image, int _width, int _height, GLuint _id);
00237
00238
00246 void set_texture(const unsigned char * _image, int _width, int _height, GLuint _id);
00247
00250
00253
00254
00255 public:
00258 void enter(GLState& _state, DrawModes::DrawMode _drawmode);
00259
00262 void leave(GLState& _state, DrawModes::DrawMode _drawmode);
00263
00266 void enterPick(GLState& _state, PickTarget _target, DrawModes::DrawMode _drawMode );
00267
00270 void leavePick(GLState& _state, PickTarget _target, DrawModes::DrawMode _drawMode );
00271
00274 private:
00275
00276 class TextureInfo {
00277 public:
00278 TextureInfo():
00279 id(0),
00280 mipmapAvailable(false)
00281 {
00282
00283 }
00284
00285 GLuint id;
00286 bool mipmapAvailable;
00287 };
00288
00289 void setTextureDataGL ( GLuint _textureId,
00290 GLenum _target,
00291 GLint _width ,
00292 GLint _height,
00293 GLenum _format ,
00294 GLenum _type,
00295 const void * _data) ;
00296
00297 std::vector<TextureInfo> textures_;
00298 bool alpha_;
00299 bool texture_repeat_;
00300 GLenum tex_mode_;
00301 GLint texture_filter_;
00302
00308 void checkEmpty();
00309
00315 int available( GLuint _id );
00316
00321 int activeTexture_;
00322 };
00323
00324
00325
00326 }
00327 }
00328
00329 #endif // ACG_TEXTURE_NODE_HH defined
00330
00331