krita

kis_opengl_image_context.h

00001 /*
00002  *  Copyright (c) 2005 Adrian Page <adrian@pagenet.plus.com>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program 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
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 #ifndef KIS_OPENGL_IMAGE_CONTEXT_H_
00019 #define KIS_OPENGL_IMAGE_CONTEXT_H_
00020 
00021 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024 
00025 #ifdef HAVE_GL
00026 
00027 #include <map>
00028 
00029 #include <qgl.h>
00030 #include <qobject.h>
00031 #include <qvaluevector.h>
00032 
00033 #include <koffice_export.h>
00034 
00035 #include "kis_types.h"
00036 
00037 class QRegion;
00038 
00039 class KisOpenGLImageContext;
00040 typedef KSharedPtr<KisOpenGLImageContext> KisOpenGLImageContextSP;
00041 class KisColorSpace;
00042 
00043 class KRITACORE_EXPORT KisOpenGLImageContext : public QObject , public KShared {
00044 
00045     Q_OBJECT
00046 
00047 public:
00048     static KisOpenGLImageContextSP getImageContext(KisImageSP image, KisProfile *monitorProfile);
00049 
00050     KisOpenGLImageContext();
00051     virtual ~KisOpenGLImageContext();
00052 
00053 public:
00054     // In order to use the image textures, the caller must pass
00055     // the sharedContextWidget() as the shareWidget argument to the 
00056     // QGLWidget constructor.
00057     QGLWidget *sharedContextWidget() const;
00058 
00059     void setMonitorProfile(KisProfile *profile);
00060     void setHDRExposure(float exposure);
00061 
00062     GLuint backgroundTexture() const;
00063 
00064     static const int BACKGROUND_TEXTURE_WIDTH = 32;
00065     static const int BACKGROUND_TEXTURE_HEIGHT = 32;
00066 
00067     // Get the image texture tile containing the point (pixelX, pixelY).
00068     GLuint imageTextureTile(int pixelX, int pixelY) const;
00069 
00070     int imageTextureTileWidth() const;
00071     int imageTextureTileHeight() const;
00072 
00078     void setSelectionDisplayEnabled(bool enable);
00079 
00085     void update(const QRect& imageRect);
00086 
00087 signals:
00100     void sigImageUpdated(QRect rc);
00101 
00108     void sigSizeChanged(Q_INT32 width, Q_INT32 height);
00109 
00110 protected:
00111     KisOpenGLImageContext(KisImageSP image, KisProfile *monitorProfile);
00112 
00113     void generateBackgroundTexture();
00114     void createImageTextureTiles();
00115     void destroyImageTextureTiles();
00116     int imageTextureTileIndex(int x, int y) const;
00117     void updateImageTextureTiles(const QRect& rect);
00118 
00119     static KisColorSpace* textureColorSpaceForImageColorSpace(KisColorSpace *imageColorSpace);
00120     static bool imageCanShareImageContext(KisImageSP image);
00121 
00122 protected slots:
00123     void slotImageUpdated(QRect r);
00124     void slotImageSizeChanged(Q_INT32 w, Q_INT32 h);
00125 
00126 private:
00127     KisImageSP m_image;
00128     KisProfile *m_monitorProfile;
00129     float m_exposure;
00130     bool m_displaySelection;
00131 
00132     GLuint m_backgroundTexture;
00133 
00134     static const int PREFERRED_IMAGE_TEXTURE_WIDTH = 256;
00135     static const int PREFERRED_IMAGE_TEXTURE_HEIGHT = 256;
00136 
00137     QValueVector<GLuint> m_imageTextureTiles;
00138     int m_imageTextureTileWidth;
00139     int m_imageTextureTileHeight;
00140     int m_numImageTextureTileColumns;
00141 
00142     // We create a single OpenGL context and share it between all views
00143     // in the process. Apparently with some OpenGL implementations, only
00144     // one context will be hardware accelerated.
00145     static QGLWidget *SharedContextWidget;
00146     static int SharedContextWidgetRefCount;
00147 
00148     typedef std::map<KisImageSP, KisOpenGLImageContext*> ImageContextMap;
00149 
00150     static ImageContextMap imageContextMap;
00151 };
00152 
00153 #endif // HAVE_GL
00154 
00155 #endif // KIS_OPENGL_IMAGE_CONTEXT_H_
00156 
KDE Home | KDE Accessibility Home | Description of Access Keys