2006-11-08 19:10:07 +00:00
|
|
|
/*****************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
2007-02-05 19:57:05 +00:00
|
|
|
Copyright (C) 2006-2007 Rivo Laks <rivolaks@hot.ee>
|
2006-11-08 19:10:07 +00:00
|
|
|
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
#ifndef KWIN_GLUTILS_H
|
|
|
|
#define KWIN_GLUTILS_H
|
|
|
|
|
2007-04-10 13:02:08 +00:00
|
|
|
#include <config.h>
|
2006-11-08 19:10:07 +00:00
|
|
|
|
2007-02-13 23:28:36 +00:00
|
|
|
#ifdef HAVE_OPENGL
|
2006-11-08 19:10:07 +00:00
|
|
|
#include <GL/gl.h>
|
|
|
|
#include <GL/glx.h>
|
2007-04-10 13:02:08 +00:00
|
|
|
#include <fixx11h.h>
|
2007-02-13 23:28:36 +00:00
|
|
|
#endif
|
2007-02-05 19:57:05 +00:00
|
|
|
|
2007-04-10 13:02:08 +00:00
|
|
|
#include <QPixmap>
|
|
|
|
#include <QString>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QSize>
|
|
|
|
|
|
|
|
#include <kwinglutils_funcs.h>
|
2007-02-05 19:57:05 +00:00
|
|
|
|
2006-11-08 19:10:07 +00:00
|
|
|
|
2007-02-05 18:11:15 +00:00
|
|
|
template< class K, class V > class QHash;
|
|
|
|
|
2006-11-08 19:10:07 +00:00
|
|
|
|
2007-04-05 12:07:35 +00:00
|
|
|
namespace KWin
|
2006-11-08 19:10:07 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
// Initializes GLX function pointers
|
2007-04-10 13:02:08 +00:00
|
|
|
void KWIN_EXPORT initGLX();
|
2006-11-08 19:10:07 +00:00
|
|
|
// Initializes OpenGL stuff. This includes resolving function pointers as
|
|
|
|
// well as checking for GL version and extensions
|
|
|
|
// Note that GL context has to be created by the time this function is called
|
2007-04-10 13:02:08 +00:00
|
|
|
void KWIN_EXPORT initGL();
|
2006-11-08 19:10:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Number of supported texture units
|
2007-04-10 13:02:08 +00:00
|
|
|
extern KWIN_EXPORT int glTextureUnitsCount;
|
2006-11-08 19:10:07 +00:00
|
|
|
|
|
|
|
|
2007-04-10 13:02:08 +00:00
|
|
|
bool KWIN_EXPORT hasGLVersion(int major, int minor, int release = 0);
|
|
|
|
bool KWIN_EXPORT hasGLXVersion(int major, int minor, int release = 0);
|
2006-11-14 11:52:20 +00:00
|
|
|
// use for both OpenGL and GLX extensions
|
2007-04-10 13:02:08 +00:00
|
|
|
bool KWIN_EXPORT hasGLExtension(const QString& extension);
|
2006-11-08 19:10:07 +00:00
|
|
|
|
2007-04-10 13:02:08 +00:00
|
|
|
inline bool KWIN_EXPORT isPowerOfTwo( int x ) { return (( x & ( x - 1 )) == 0 ); }
|
|
|
|
int KWIN_EXPORT nearestPowerOfTwo( int x );
|
2006-11-08 19:10:07 +00:00
|
|
|
|
2007-02-13 23:28:36 +00:00
|
|
|
#ifdef HAVE_OPENGL
|
2007-02-05 18:11:15 +00:00
|
|
|
|
2007-04-10 13:02:08 +00:00
|
|
|
class KWIN_EXPORT GLTexture
|
Add GLTexture class. This is a convenient wrapper around managing an OpenGL texture, as well as loading an image into it. Includes support for loading from QImage, QPixmap, and a file. Defaults to a GL_TEXTURE_2D target, and will scale image if necessary.
Also add SceneOpenGL::Texture class, based on GLTexture. Optimised for SceneOpenGL::Window, this adds support for loading from an X Pixmap, as well as taking advantage of texture_from_pixmap/shm when available. Automatically detects what texture target should be used, so be sure to enableUnnormalizedTexCoords() before painting.
Make SceneOpenGL::Window, BoxSwitchEffect, and ExplosionEffect use the new classes.
svn path=/branches/work/kwin_composite/; revision=645125
2007-03-21 18:14:09 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
GLTexture();
|
|
|
|
GLTexture( const QImage& image, GLenum target = GL_TEXTURE_2D );
|
|
|
|
GLTexture( const QPixmap& pixmap, GLenum target = GL_TEXTURE_2D );
|
|
|
|
GLTexture( const QString& fileName );
|
|
|
|
virtual ~GLTexture();
|
|
|
|
|
|
|
|
bool isNull() const;
|
|
|
|
|
|
|
|
virtual bool load( const QImage& image, GLenum target = GL_TEXTURE_2D );
|
|
|
|
virtual bool load( const QPixmap& pixmap, GLenum target = GL_TEXTURE_2D );
|
|
|
|
virtual bool load( const QString& fileName );
|
|
|
|
virtual void discard();
|
|
|
|
virtual void bind();
|
|
|
|
virtual void unbind();
|
|
|
|
void enableUnnormalizedTexCoords();
|
|
|
|
void disableUnnormalizedTexCoords();
|
|
|
|
|
|
|
|
GLuint texture() const;
|
|
|
|
GLenum target() const;
|
|
|
|
GLenum filter() const;
|
|
|
|
virtual bool isDirty() const;
|
|
|
|
void setTexture( GLuint texture );
|
|
|
|
void setTarget( GLenum target );
|
|
|
|
void setFilter( GLenum filter );
|
|
|
|
virtual void setDirty();
|
|
|
|
|
|
|
|
static void initStatic();
|
|
|
|
static bool NPOTTextureSupported() { return mNPOTTextureSupported; }
|
|
|
|
static bool framebufferObjectSupported() { return mFramebufferObjectSupported; }
|
|
|
|
static bool saturationSupported() { return mSaturationSupported; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void enableFilter();
|
|
|
|
QImage convertToGLFormat( const QImage& img ) const;
|
|
|
|
|
|
|
|
GLuint mTexture;
|
|
|
|
GLenum mTarget;
|
|
|
|
GLenum mFilter;
|
|
|
|
QSize mSize;
|
|
|
|
QSizeF mScale; // to un-normalize GL_TEXTURE_2D
|
|
|
|
bool y_inverted; // texture has y inverted
|
|
|
|
bool can_use_mipmaps;
|
|
|
|
bool has_valid_mipmaps;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void init();
|
|
|
|
|
|
|
|
static bool mNPOTTextureSupported;
|
|
|
|
static bool mFramebufferObjectSupported;
|
|
|
|
static bool mSaturationSupported;
|
|
|
|
};
|
|
|
|
|
2007-04-10 13:02:08 +00:00
|
|
|
class KWIN_EXPORT GLShader
|
2007-02-05 18:11:15 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
GLShader(const QString& vertexfile, const QString& fragmentfile);
|
|
|
|
|
|
|
|
bool isValid() const { return mValid; }
|
|
|
|
void bind();
|
|
|
|
void unbind();
|
|
|
|
|
|
|
|
int uniformLocation(const QString& name);
|
|
|
|
bool setUniform(const QString& name, float value);
|
|
|
|
bool setUniform(const QString& name, int value);
|
|
|
|
int attributeLocation(const QString& name);
|
|
|
|
bool setAttribute(const QString& name, float value);
|
|
|
|
|
|
|
|
|
2007-03-21 16:17:19 +00:00
|
|
|
static void initStatic();
|
|
|
|
static bool fragmentShaderSupported() { return mFragmentShaderSupported; }
|
|
|
|
static bool vertexShaderSupported() { return mVertexShaderSupported; }
|
|
|
|
|
|
|
|
|
2007-02-05 18:11:15 +00:00
|
|
|
protected:
|
|
|
|
bool loadFromFiles(const QString& vertexfile, const QString& fragmentfile);
|
|
|
|
bool load(const QString& vertexsource, const QString& fragmentsource);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned int mProgram;
|
|
|
|
bool mValid;
|
|
|
|
QHash< QString, int >* mVariableLocations;
|
2007-03-21 16:17:19 +00:00
|
|
|
static bool mFragmentShaderSupported;
|
|
|
|
static bool mVertexShaderSupported;
|
2007-02-05 18:11:15 +00:00
|
|
|
};
|
|
|
|
|
2007-02-13 23:28:36 +00:00
|
|
|
#endif
|
|
|
|
|
2006-11-08 19:10:07 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif
|