chalk

kis_opengl_image_context.h
1/*
2 * Copyright (c) 2005 Adrian Page <adrian@pagenet.plus.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18#ifndef KIS_OPENGL_IMAGE_CONTEXT_H_
19#define KIS_OPENGL_IMAGE_CONTEXT_H_
20
21#ifdef HAVE_CONFIG_H
22#include <config.h>
23#endif
24
25#ifdef HAVE_GL
26
27#include <map>
28
29#include <tqgl.h>
30#include <tqobject.h>
31#include <tqvaluevector.h>
32
33#include <koffice_export.h>
34
35#include "kis_types.h"
36
37class TQRegion;
38
39class KisOpenGLImageContext;
40typedef TDESharedPtr<KisOpenGLImageContext> KisOpenGLImageContextSP;
41class KisColorSpace;
42
43class KRITACORE_EXPORT KisOpenGLImageContext : public TQObject , public TDEShared {
44
45 TQ_OBJECT
46
47
48public:
49 static KisOpenGLImageContextSP getImageContext(KisImageSP image, KisProfile *monitorProfile);
50
51 KisOpenGLImageContext();
52 virtual ~KisOpenGLImageContext();
53
54public:
55 // In order to use the image textures, the caller must pass
56 // the sharedContextWidget() as the shareWidget argument to the
57 // TQGLWidget constructor.
58 TQGLWidget *sharedContextWidget() const;
59
60 void setMonitorProfile(KisProfile *profile);
61 void setHDRExposure(float exposure);
62
63 GLuint backgroundTexture() const;
64
65 static const int BACKGROUND_TEXTURE_WIDTH = 32;
66 static const int BACKGROUND_TEXTURE_HEIGHT = 32;
67
68 // Get the image texture tile containing the point (pixelX, pixelY).
69 GLuint imageTextureTile(int pixelX, int pixelY) const;
70
71 int imageTextureTileWidth() const;
72 int imageTextureTileHeight() const;
73
79 void setSelectionDisplayEnabled(bool enable);
80
86 void update(const TQRect& imageRect);
87
88signals:
95
101 void sigImageUpdated(TQRect rc);
102
109 void sigSizeChanged(TQ_INT32 width, TQ_INT32 height);
110
111protected:
112 KisOpenGLImageContext(KisImageSP image, KisProfile *monitorProfile);
113
114 void generateBackgroundTexture();
115 void createImageTextureTiles();
116 void destroyImageTextureTiles();
117 int imageTextureTileIndex(int x, int y) const;
118 void updateImageTextureTiles(const TQRect& rect);
119
120 static KisColorSpace* textureColorSpaceForImageColorSpace(KisColorSpace *imageColorSpace);
121 static bool imageCanShareImageContext(KisImageSP image);
122
123protected slots:
124 void slotImageUpdated(TQRect r);
125 void slotImageSizeChanged(TQ_INT32 w, TQ_INT32 h);
126
127private:
128 KisImageSP m_image;
129 KisProfile *m_monitorProfile;
130 float m_exposure;
131 bool m_displaySelection;
132
133 GLuint m_backgroundTexture;
134
135 static const int PREFERRED_IMAGE_TEXTURE_WIDTH = 256;
136 static const int PREFERRED_IMAGE_TEXTURE_HEIGHT = 256;
137
138 TQValueVector<GLuint> m_imageTextureTiles;
139 int m_imageTextureTileWidth;
140 int m_imageTextureTileHeight;
141 int m_numImageTextureTileColumns;
142
143 // We create a single OpenGL context and share it between all views
144 // in the process. Apparently with some OpenGL implementations, only
145 // one context will be hardware accelerated.
146 static TQGLWidget *SharedContextWidget;
147 static int SharedContextWidgetRefCount;
148
149 typedef std::map<KisImageSP, KisOpenGLImageContext*> ImageContextMap;
150
151 static ImageContextMap imageContextMap;
152};
153
154#endif // HAVE_GL
155
156#endif // KIS_OPENGL_IMAGE_CONTEXT_H_
157
A colorspace is the definition of a certain color model in Chalk.