• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KGLLib

texture.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008 Rivo Laks <rivolaks@hot.ee>
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either 
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public 
00015  * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #ifndef KGLLIB_TEXTURE_H
00019 #define KGLLIB_TEXTURE_H
00020 
00021 #include "kgllib.h"
00022 
00023 #include <QtCore/QString>
00024 #include <QtCore/QSize>
00025 
00026 
00027 class QPixmap;
00028 class QImage;
00029 class QRectF;
00030 
00031 namespace KGLLib
00032 {
00033 
00044 class KGLLIB_EXPORT TextureBase
00045 {
00046 public:
00052     TextureBase();
00056     TextureBase(const QString& name);
00060     virtual ~TextureBase();
00061 
00065     bool isValid() const  { return mValid; }
00066 
00070     virtual void bind() const;
00078     virtual void unbind() const;
00084     virtual void enable(bool bind = true) const;
00090     virtual void disable(bool unbind = true) const;
00091 
00111     virtual void setFilter(GLenum filter);
00112 
00125     virtual void setWrapMode(GLenum coordinate, GLenum mode);
00131     virtual void setWrapMode(GLenum mode) = 0;
00132 
00137     QString name() const  { return mName; }
00143     void setName(const QString& name);
00144 
00145     // TODO: rename?
00146     virtual QString debugString() const;
00147 
00152     virtual GLenum glTarget() const = 0;
00156     virtual GLuint glId() const  { return mGLId; }
00157 
00158 protected:
00159     void setValid(bool valid)  { mValid = valid; }
00160 
00161 protected:
00162     bool mValid;
00163     GLuint mGLId;
00164     QString mName;
00165     GLenum mFormat;
00166     GLenum mInternalFormat;
00167 };
00168 
00169 
00212 class KGLLIB_EXPORT Texture : public TextureBase
00213 {
00214 public:
00221     explicit Texture(const QImage& img, GLenum filter = GL_LINEAR_MIPMAP_LINEAR);
00228     explicit Texture(const QPixmap& pix, GLenum filter = GL_LINEAR_MIPMAP_LINEAR);
00235     explicit Texture(const QString& filename, GLenum filter = GL_LINEAR_MIPMAP_LINEAR);
00244     Texture(int width, int height, GLint internalformat = GL_RGBA, GLint format = 0);
00245     virtual ~Texture();
00246 
00252     int width() const  { return mWidth; }
00258     int height() const  { return mHeight; }
00264     QSize size() const  { return QSize(mWidth, mHeight); }
00265 
00272     virtual void setWrapMode(GLenum mode);
00273 
00274     virtual GLenum glTarget() const { return GL_TEXTURE_2D; }
00275 
00276     void render(const QRectF& rect) const;
00277     QImage convertToGLFormat(const QImage& img) const;
00278 
00279 protected:
00280     bool init(int width, int height, GLint internalformat = GL_RGBA, GLint format = 0);
00281     bool init(const QImage& img, GLenum filter);
00282     bool init(const QString& filename, GLenum filter);
00283 
00284 protected:
00285     int mWidth;
00286     int mHeight;
00287 };
00288 
00292 class KGLLIB_EXPORT Texture3D : public TextureBase
00293 {
00294 public:
00295     Texture3D(int width, int height, int depth);
00296     virtual ~Texture3D();
00297 
00298     virtual void setWrapMode(GLenum mode);
00299 
00300     virtual GLenum glTarget() const { return GL_TEXTURE_3D; }
00301 };
00302 
00303 }
00304 
00305 #endif

KGLLib

Skip menu "KGLLib"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KGLLib
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal