• Skip to content
  • Skip to link menu
KDE 4.2 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 
00088 KWIN_EXPORT void renderGLGeometry( const QRegion& region, int count,
00089     const float* vertices, const float* texture = 0, const float* color = 0,
00090     int dim = 2, int stride = 0 );
00094 KWIN_EXPORT void renderGLGeometry( int count,
00095     const float* vertices, const float* texture = 0, const float* color = 0,
00096     int dim = 2, int stride = 0 );
00097 
00098 
00099 KWIN_EXPORT void renderGLGeometryImmediate( int count,
00100     const float* vertices, const float* texture = 0, const float* color = 0,
00101     int dim = 2, int stride = 0 );
00102 
00103 
00104 KWIN_EXPORT void renderRoundBox( const QRect& area, float roundness = 10.0f, GLTexture* texture = 0 );
00105 KWIN_EXPORT void renderRoundBoxWithEdge( const QRect& area, float roundness = 10.0f );
00106 
00107 
00108 class KWIN_EXPORT GLTexture
00109     : public QSharedData
00110     {
00111     public:
00112         GLTexture();
00113         explicit GLTexture( const QImage& image, GLenum target = GL_TEXTURE_2D );
00114         explicit GLTexture( const QPixmap& pixmap, GLenum target = GL_TEXTURE_2D );
00115         GLTexture( const QString& fileName );
00116         GLTexture( int width, int height );
00117         virtual ~GLTexture();
00118 
00119         bool isNull() const;
00120         QSize size() const;
00121 
00122         virtual bool load( const QImage& image, GLenum target = GL_TEXTURE_2D );
00123         virtual bool load( const QPixmap& pixmap, GLenum target = GL_TEXTURE_2D );
00124         virtual bool load( const QString& fileName );
00125         virtual void discard();
00126         virtual void bind();
00127         virtual void unbind();
00128         void render( QRegion region, const QRect& rect );
00137         void enableUnnormalizedTexCoords();
00141         void disableUnnormalizedTexCoords();
00150         void enableNormalizedTexCoords();
00154         void disableNormalizedTexCoords();
00155 
00156         GLuint texture() const;
00157         GLenum target() const;
00158         GLenum filter() const;
00159         virtual bool isDirty() const;
00160         void setTexture( GLuint texture );
00161         void setTarget( GLenum target );
00162         void setFilter( GLenum filter );
00163         void setWrapMode( GLenum mode );
00164         virtual void setDirty();
00165 
00166         static void initStatic();
00167         static bool NPOTTextureSupported()  { return mNPOTTextureSupported; }
00168         static bool framebufferObjectSupported()  { return mFramebufferObjectSupported; }
00169         static bool saturationSupported()  { return mSaturationSupported; }
00170 
00171     protected:
00172         void enableFilter();
00173         QImage convertToGLFormat( const QImage& img ) const;
00174 
00175         GLuint mTexture;
00176         GLenum mTarget;
00177         GLenum mFilter;
00178         QSize mSize;
00179         QSizeF mScale; // to un-normalize GL_TEXTURE_2D
00180         bool y_inverted; // texture has y inverted
00181         bool can_use_mipmaps;
00182         bool has_valid_mipmaps;
00183 
00184     private:
00185         void init();
00186         int mUnnormalizeActive; // 0 - no, otherwise refcount
00187         int mNormalizeActive; // 0 - no, otherwise refcount
00188 
00189         static bool mNPOTTextureSupported;
00190         static bool mFramebufferObjectSupported;
00191         static bool mSaturationSupported;
00192         Q_DISABLE_COPY( GLTexture )
00193     };
00194 
00195 class KWIN_EXPORT GLShader
00196     {
00197     public:
00198         GLShader(const QString& vertexfile, const QString& fragmentfile);
00199         ~GLShader();
00200 
00201         bool isValid() const  { return mValid; }
00202         void bind();
00203         void unbind();
00204 
00205         int uniformLocation(const QString& name);
00206         bool setUniform(const QString& name, float value);
00207         bool setUniform(const QString& name, int value);
00208         int attributeLocation(const QString& name);
00209         bool setAttribute(const QString& name, float value);
00210 
00211 
00212         static void initStatic();
00213         static bool fragmentShaderSupported()  { return mFragmentShaderSupported; }
00214         static bool vertexShaderSupported()  { return mVertexShaderSupported; }
00215 
00216 
00217     protected:
00218         bool loadFromFiles(const QString& vertexfile, const QString& fragmentfile);
00219         bool load(const QString& vertexsource, const QString& fragmentsource);
00220 
00221 
00222     private:
00223         unsigned int mProgram;
00224         bool mValid;
00225         QHash< QString, int >* mVariableLocations;
00226         static bool mFragmentShaderSupported;
00227         static bool mVertexShaderSupported;
00228     };
00229 
00238 class KWIN_EXPORT GLRenderTarget
00239 {
00240     public:
00245         GLRenderTarget(GLTexture* color);
00246         ~GLRenderTarget();
00247 
00253         bool enable();
00258         bool disable();
00259 
00260         bool valid() const  { return mValid; }
00261 
00262         static void initStatic();
00263         static bool supported()  { return mSupported; }
00264 
00265 
00266     protected:
00267         void initFBO();
00268 
00269 
00270     private:
00271         static bool mSupported;
00272 
00273         GLTexture* mTexture;
00274         bool mValid;
00275 
00276         GLuint mFramebuffer;
00277 };
00278 
00279 } // namespace
00280 
00281 #endif
00282 
00285 #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
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
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