glc_texture.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  http://glc-lib.sourceforge.net
00006 
00007  GLC-lib is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU Lesser General Public License as published by
00009  the Free Software Foundation; either version 3 of the License, or
00010  (at your option) any later version.
00011 
00012  GLC-lib is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU Lesser General Public License for more details.
00016 
00017  You should have received a copy of the GNU Lesser General Public License
00018  along with GLC-lib; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021 *****************************************************************************/
00022 
00024 
00025 #ifndef GLC_TEXTURE_H_
00026 #define GLC_TEXTURE_H_
00027 
00028 #include <QFile>
00029 #include <QtOpenGL>
00030 
00031 #include "../glc_config.h"
00032 
00035 
00038 
00039 
00040 
00041 class GLC_LIB_EXPORT GLC_Texture
00042 {
00044 
00046 
00047 
00048 public:
00050         GLC_Texture();
00051 
00053         GLC_Texture(const QString&);
00054 
00056         GLC_Texture(const QFile&);
00057 
00059         GLC_Texture(const QImage&, const QString& fileName= QString());
00060 
00062         GLC_Texture(const GLC_Texture& TextureToCopy);
00063 
00065         GLC_Texture& operator=(const GLC_Texture&);
00066 
00068         virtual ~GLC_Texture();
00070 
00072 
00074 
00075 public:
00077         inline QGLContext* context() const
00078         {return m_pQGLContext;}
00079 
00081         inline QString fileName() const
00082         {return m_FileName;}
00083 
00085         inline GLuint GL_ID() const
00086         {return m_GlTextureID;}
00087 
00089         inline bool isLoaded() const
00090         {return (m_GlTextureID != 0);}
00091 
00093         inline QSize size() const
00094         {return m_TextureSize;}
00095 
00097         static QSize maxSize()
00098         {return m_MaxTextureSize;}
00099 
00101         bool operator==(const GLC_Texture&) const;
00102 
00104         inline bool hasAlphaChannel() const
00105         { return m_HasAlphaChannel;}
00106 
00108         inline QImage imageOfTexture() const
00109         { return m_textureImage;}
00110 
00111 
00113 
00115 
00117 
00118 public:
00119         // Set the maximum texture size
00120         static void setMaxTextureSize(const QSize&);
00121 
00123 
00124 
00126 
00127 public:
00129         void glLoadTexture(QGLContext* pContext= NULL);
00131         void glcBindTexture(void);
00132 
00133 
00135 
00137 
00138 private:
00140         QImage loadFromFile(const QString& fileName);
00141 
00143         void removeThisOpenGLTextureId();
00144 
00146         void addThisOpenGLTextureId();
00147 
00149 
00151 // Private members
00153 
00154 private:
00156         QGLContext *m_pQGLContext;
00157 
00159         QString m_FileName;
00160 
00162         GLuint  m_GlTextureID;
00163 
00165         QImage m_textureImage;
00166 
00168         QSize m_TextureSize;
00169 
00171         bool m_HasAlphaChannel;
00172 
00174         static QSize m_MaxTextureSize;
00175         static const QSize m_MinTextureSize;
00176 
00178         static QHash<GLuint, int> m_TextureIdUsage;
00179 };
00180 
00182 QDataStream &operator<<(QDataStream &, const GLC_Texture &);
00183 QDataStream &operator>>(QDataStream &, GLC_Texture &);
00184 
00185 
00186 #endif //GLC_TEXTURE_H_

SourceForge.net Logo

©2005-2011 Laurent Ribon