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

KWinLibraries

kwinglutils.h

Go to the documentation of this file.
00001 /********************************************************************
00002  KWin - the KDE window manager
00003  This file is part of the KDE project.
00004 
00005 Copyright (C) 2006-2007 Rivo Laks <rivolaks@hot.ee>
00006 
00007 This program is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2 of the License, or
00010 (at your option) any later version.
00011 
00012 This program 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 General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 *********************************************************************/
00020 
00021 #ifndef KWIN_GLUTILS_H
00022 #define KWIN_GLUTILS_H
00023 
00024 #include <kwinconfig.h> // KWIN_HAVE_OPENGL
00025 
00026 #ifdef KWIN_HAVE_OPENGL
00027 #include <kwinglutils_funcs.h>
00028 
00029 #include <QtGui/QPixmap>
00030 
00031 #include <QtGui/QImage>
00032 #include <QtCore/QSize>
00033 #include <QtCore/QSharedData>
00034 
00039 template< class K, class V > class QHash;
00040 
00041 
00042 namespace KWin
00043 {
00044 
00045 
00046 class GLTexture;
00047 
00048 
00049 // Initializes GLX function pointers
00050 void KWIN_EXPORT initGLX();
00051 // Initializes OpenGL stuff. This includes resolving function pointers as
00052 //  well as checking for GL version and extensions
00053 //  Note that GL context has to be created by the time this function is called
00054 void KWIN_EXPORT initGL();
00055 
00056 
00057 // Number of supported texture units
00058 extern KWIN_EXPORT int glTextureUnitsCount;
00059 
00060 
00061 bool KWIN_EXPORT hasGLVersion(int major, int minor, int release = 0);
00062 bool KWIN_EXPORT hasGLXVersion(int major, int minor, int release = 0);
00063 // use for both OpenGL and GLX extensions
00064 bool KWIN_EXPORT hasGLExtension(const QString& extension);
00065 
00066 // detect OpenGL error (add to various places in code to pinpoint the place)
00067 bool KWIN_EXPORT checkGLError( const char* txt );
00068 
00069 inline bool KWIN_EXPORT isPowerOfTwo( int x ) { return (( x & ( x - 1 )) == 0 ); }
00074 int KWIN_EXPORT nearestPowerOfTwo( int x );
00075 
00086 KWIN_EXPORT void renderGLGeometry( const QRegion& region, int count,
00087     const float* vertices, const float* texture = 0, const float* color = 0,
00088     int dim = 2, int stride = 0 );
00092 KWIN_EXPORT void renderGLGeometry( int count,
00093     const float* vertices, const float* texture = 0, const float* color = 0,
00094     int dim = 2, int stride = 0 );
00095 
00096 
00097 KWIN_EXPORT void renderGLGeometryImmediate( int count,
00098     const float* vertices, const float* texture = 0, const float* color = 0,
00099     int dim = 2, int stride = 0 );
00100 
00101 
00102 KWIN_EXPORT void renderRoundBox( const QRect& area, float roundness = 10.0f, GLTexture* texture = 0 );
00103 KWIN_EXPORT void renderRoundBoxWithEdge( const QRect& area, float roundness = 10.0f );
00104 
00105 
00106 class KWIN_EXPORT GLTexture
00107     : public QSharedData
00108     {
00109     public:
00110         GLTexture();
00111         explicit GLTexture( const QImage& image, GLenum target = GL_TEXTURE_2D );
00112         explicit GLTexture( const QPixmap& pixmap, GLenum target = GL_TEXTURE_2D );
00113         GLTexture( const QString& fileName );
00114         GLTexture( int width, int height );
00115         virtual ~GLTexture();
00116 
00117         bool isNull() const;
00118         QSize size() const;
00119 
00120         virtual bool load( const QImage& image, GLenum target = GL_TEXTURE_2D );
00121         virtual bool load( const QPixmap& pixmap, GLenum target = GL_TEXTURE_2D );
00122         virtual bool load( const QString& fileName );
00123         virtual void discard();
00124         virtual void bind();
00125         virtual void unbind();
00126         void render( QRegion region, const QRect& rect );
00127         void enableUnnormalizedTexCoords();
00128         void disableUnnormalizedTexCoords();
00129 
00130         GLuint texture() const;
00131         GLenum target() const;
00132         GLenum filter() const;
00133         virtual bool isDirty() const;
00134         void setTexture( GLuint texture );
00135         void setTarget( GLenum target );
00136         void setFilter( GLenum filter );
00137         void setWrapMode( GLenum mode );
00138         virtual void setDirty();
00139 
00140         static void initStatic();
00141         static bool NPOTTextureSupported()  { return mNPOTTextureSupported; }
00142         static bool framebufferObjectSupported()  { return mFramebufferObjectSupported; }
00143         static bool saturationSupported()  { return mSaturationSupported; }
00144 
00145     protected:
00146         void enableFilter();
00147         QImage convertToGLFormat( const QImage& img ) const;
00148 
00149         GLuint mTexture;
00150         GLenum mTarget;
00151         GLenum mFilter;
00152         QSize mSize;
00153         QSizeF mScale; // to un-normalize GL_TEXTURE_2D
00154         bool y_inverted; // texture has y inverted
00155         bool can_use_mipmaps;
00156         bool has_valid_mipmaps;
00157 
00158     private:
00159         void init();
00160 
00161         static bool mNPOTTextureSupported;
00162         static bool mFramebufferObjectSupported;
00163         static bool mSaturationSupported;
00164         Q_DISABLE_COPY( GLTexture )
00165     };
00166 
00167 class KWIN_EXPORT GLShader
00168     {
00169     public:
00170         GLShader(const QString& vertexfile, const QString& fragmentfile);
00171         ~GLShader();
00172 
00173         bool isValid() const  { return mValid; }
00174         void bind();
00175         void unbind();
00176 
00177         int uniformLocation(const QString& name);
00178         bool setUniform(const QString& name, float value);
00179         bool setUniform(const QString& name, int value);
00180         int attributeLocation(const QString& name);
00181         bool setAttribute(const QString& name, float value);
00182 
00183 
00184         static void initStatic();
00185         static bool fragmentShaderSupported()  { return mFragmentShaderSupported; }
00186         static bool vertexShaderSupported()  { return mVertexShaderSupported; }
00187 
00188 
00189     protected:
00190         bool loadFromFiles(const QString& vertexfile, const QString& fragmentfile);
00191         bool load(const QString& vertexsource, const QString& fragmentsource);
00192 
00193 
00194     private:
00195         unsigned int mProgram;
00196         bool mValid;
00197         QHash< QString, int >* mVariableLocations;
00198         static bool mFragmentShaderSupported;
00199         static bool mVertexShaderSupported;
00200     };
00201 
00210 class KWIN_EXPORT GLRenderTarget
00211 {
00212     public:
00217         GLRenderTarget(GLTexture* color);
00218         ~GLRenderTarget();
00219 
00225         bool enable();
00230         bool disable();
00231 
00232         bool valid() const  { return mValid; }
00233 
00234         static void initStatic();
00235         static bool supported()  { return mSupported; }
00236 
00237 
00238     protected:
00239         void initFBO();
00240 
00241 
00242     private:
00243         static bool mSupported;
00244 
00245         GLTexture* mTexture;
00246         bool mValid;
00247 
00248         GLuint mFramebuffer;
00249 };
00250 
00251 } // namespace
00252 
00253 #endif
00254 
00257 #endif

KWinLibraries

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

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
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