TextureNode.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 8548 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2010-02-12 14:40:13 +0100 (Fr, 12. Feb 2010) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 //=============================================================================
00047 //
00048 //  CLASS TextureNode
00049 //
00050 //=============================================================================
00051 
00052 
00053 #ifndef ACG_TEXTURE_NODE_HH
00054 #define ACG_TEXTURE_NODE_HH
00055 
00056 
00057 //== INCLUDES =================================================================
00058 
00059 
00060 #include "BaseNode.hh"
00061 
00062 #include <string>
00063 #include <QImage>
00064 
00065 
00066 //== NAMESPACES ===============================================================
00067 
00068 namespace ACG {
00069 namespace SceneGraph {
00070 
00071 
00072 //== CLASS DEFINITION =========================================================
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 } // namespace SceneGraph
00327 } // namespace ACG
00328 //=============================================================================
00329 #endif // ACG_TEXTURE_NODE_HH defined
00330 //=============================================================================
00331 

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .