~mc-return/compiz/compiz.merge-src-screen.cpp-improvements

« back to all changes in this revision

Viewing changes to plugins/opengl/include/opengl/opengl.h

  • Committer: Dennis kasprzyk
  • Author(s): Dennis Kasprzyk
  • Date: 2009-03-15 05:09:18 UTC
  • Revision ID: git-v1:163f6b6f3c3b7764987cbdf8e03cc355edeaa499
New generalized build system.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2008 Dennis Kasprzyk
 
3
 * Copyright © 2007 Novell, Inc.
 
4
 *
 
5
 * Permission to use, copy, modify, distribute, and sell this software
 
6
 * and its documentation for any purpose is hereby granted without
 
7
 * fee, provided that the above copyright notice appear in all copies
 
8
 * and that both that copyright notice and this permission notice
 
9
 * appear in supporting documentation, and that the name of
 
10
 * Dennis Kasprzyk not be used in advertising or publicity pertaining to
 
11
 * distribution of the software without specific, written prior permission.
 
12
 * Dennis Kasprzyk makes no representations about the suitability of this
 
13
 * software for any purpose. It is provided "as is" without express or
 
14
 * implied warranty.
 
15
 *
 
16
 * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
17
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
 
18
 * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
19
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
 
20
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 
21
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 
22
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
23
 *
 
24
 * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
 
25
 *          David Reveman <davidr@novell.com>
 
26
 */
 
27
 
 
28
#ifndef _COMPIZ_OPENGL_H
 
29
#define _COMPIZ_OPENGL_H
 
30
 
 
31
#include <GL/gl.h>
 
32
#include <GL/glx.h>
 
33
 
 
34
#include <opengl/matrix.h>
 
35
#include <opengl/texture.h>
 
36
#include <opengl/fragment.h>
 
37
 
 
38
#define COMPIZ_OPENGL_ABI 1
 
39
 
 
40
#include <core/privatehandler.h>
 
41
 
 
42
/* camera distance from screen, 0.5 * tan (FOV) */
 
43
#define DEFAULT_Z_CAMERA 0.866025404f
 
44
 
 
45
#define RED_SATURATION_WEIGHT   0.30f
 
46
#define GREEN_SATURATION_WEIGHT 0.59f
 
47
#define BLUE_SATURATION_WEIGHT  0.11f
 
48
 
 
49
class PrivateGLScreen;
 
50
class PrivateGLWindow;
 
51
 
 
52
extern GLushort   defaultColor[4];
 
53
 
 
54
#ifndef GLX_EXT_texture_from_pixmap
 
55
#define GLX_BIND_TO_TEXTURE_RGB_EXT        0x20D0
 
56
#define GLX_BIND_TO_TEXTURE_RGBA_EXT       0x20D1
 
57
#define GLX_BIND_TO_MIPMAP_TEXTURE_EXT     0x20D2
 
58
#define GLX_BIND_TO_TEXTURE_TARGETS_EXT    0x20D3
 
59
#define GLX_Y_INVERTED_EXT                 0x20D4
 
60
#define GLX_TEXTURE_FORMAT_EXT             0x20D5
 
61
#define GLX_TEXTURE_TARGET_EXT             0x20D6
 
62
#define GLX_MIPMAP_TEXTURE_EXT             0x20D7
 
63
#define GLX_TEXTURE_FORMAT_NONE_EXT        0x20D8
 
64
#define GLX_TEXTURE_FORMAT_RGB_EXT         0x20D9
 
65
#define GLX_TEXTURE_FORMAT_RGBA_EXT        0x20DA
 
66
#define GLX_TEXTURE_1D_BIT_EXT             0x00000001
 
67
#define GLX_TEXTURE_2D_BIT_EXT             0x00000002
 
68
#define GLX_TEXTURE_RECTANGLE_BIT_EXT      0x00000004
 
69
#define GLX_TEXTURE_1D_EXT                 0x20DB
 
70
#define GLX_TEXTURE_2D_EXT                 0x20DC
 
71
#define GLX_TEXTURE_RECTANGLE_EXT          0x20DD
 
72
#define GLX_FRONT_LEFT_EXT                 0x20DE
 
73
#endif
 
74
 
 
75
namespace GL {
 
76
 
 
77
    typedef void (*FuncPtr) (void);
 
78
    typedef FuncPtr (*GLXGetProcAddressProc) (const GLubyte *procName);
 
79
 
 
80
    typedef void    (*GLXBindTexImageProc)    (Display   *display,
 
81
                                               GLXDrawable       drawable,
 
82
                                               int               buffer,
 
83
                                               int               *attribList);
 
84
    typedef void    (*GLXReleaseTexImageProc) (Display   *display,
 
85
                                               GLXDrawable       drawable,
 
86
                                               int               buffer);
 
87
    typedef void    (*GLXQueryDrawableProc)   (Display   *display,
 
88
                                               GLXDrawable       drawable,
 
89
                                               int               attribute,
 
90
                                               unsigned int  *value);
 
91
 
 
92
    typedef void (*GLXCopySubBufferProc) (Display     *display,
 
93
                                          GLXDrawable drawable,
 
94
                                          int     x,
 
95
                                          int     y,
 
96
                                          int     width,
 
97
                                          int     height);
 
98
 
 
99
    typedef int (*GLXGetVideoSyncProc)  (unsigned int *count);
 
100
    typedef int (*GLXWaitVideoSyncProc) (int      divisor,
 
101
                                         int      remainder,
 
102
                                         unsigned int *count);
 
103
 
 
104
    #ifndef GLX_VERSION_1_3
 
105
    typedef struct __GLXFBConfigRec *GLXFBConfig;
 
106
    #endif
 
107
 
 
108
    typedef GLXFBConfig *(*GLXGetFBConfigsProc) (Display *display,
 
109
                                                 int     screen,
 
110
                                                 int     *nElements);
 
111
    typedef int (*GLXGetFBConfigAttribProc) (Display     *display,
 
112
                                             GLXFBConfig config,
 
113
                                             int             attribute,
 
114
                                             int             *value);
 
115
    typedef GLXPixmap (*GLXCreatePixmapProc) (Display     *display,
 
116
                                              GLXFBConfig config,
 
117
                                              Pixmap      pixmap,
 
118
                                              const int   *attribList);
 
119
 
 
120
    typedef void (*GLActiveTextureProc) (GLenum texture);
 
121
    typedef void (*GLClientActiveTextureProc) (GLenum texture);
 
122
    typedef void (*GLMultiTexCoord2fProc) (GLenum, GLfloat, GLfloat);
 
123
 
 
124
    typedef void (*GLGenProgramsProc) (GLsizei n,
 
125
                                       GLuint  *programs);
 
126
    typedef void (*GLDeleteProgramsProc) (GLsizei n,
 
127
                                          GLuint  *programs);
 
128
    typedef void (*GLBindProgramProc) (GLenum target,
 
129
                                       GLuint program);
 
130
    typedef void (*GLProgramStringProc) (GLenum   target,
 
131
                                         GLenum   format,
 
132
                                         GLsizei          len,
 
133
                                         const GLvoid *string);
 
134
    typedef void (*GLProgramParameter4fProc) (GLenum  target,
 
135
                                              GLuint  index,
 
136
                                              GLfloat x,
 
137
                                              GLfloat y,
 
138
                                              GLfloat z,
 
139
                                              GLfloat w);
 
140
    typedef void (*GLGetProgramivProc) (GLenum target,
 
141
                                        GLenum pname,
 
142
                                        int    *params);
 
143
 
 
144
    typedef void (*GLGenFramebuffersProc) (GLsizei n,
 
145
                                           GLuint  *framebuffers);
 
146
    typedef void (*GLDeleteFramebuffersProc) (GLsizei n,
 
147
                                              GLuint  *framebuffers);
 
148
    typedef void (*GLBindFramebufferProc) (GLenum target,
 
149
                                           GLuint framebuffer);
 
150
    typedef GLenum (*GLCheckFramebufferStatusProc) (GLenum target);
 
151
    typedef void (*GLFramebufferTexture2DProc) (GLenum target,
 
152
                                                GLenum attachment,
 
153
                                                GLenum textarget,
 
154
                                                GLuint texture,
 
155
                                                GLint  level);
 
156
    typedef void (*GLGenerateMipmapProc) (GLenum target);
 
157
 
 
158
    extern GLXBindTexImageProc      bindTexImage;
 
159
    extern GLXReleaseTexImageProc   releaseTexImage;
 
160
    extern GLXQueryDrawableProc     queryDrawable;
 
161
    extern GLXCopySubBufferProc     copySubBuffer;
 
162
    extern GLXGetVideoSyncProc      getVideoSync;
 
163
    extern GLXWaitVideoSyncProc     waitVideoSync;
 
164
    extern GLXGetFBConfigsProc      getFBConfigs;
 
165
    extern GLXGetFBConfigAttribProc getFBConfigAttrib;
 
166
    extern GLXCreatePixmapProc      createPixmap;
 
167
 
 
168
    extern GLActiveTextureProc       activeTexture;
 
169
    extern GLClientActiveTextureProc clientActiveTexture;
 
170
    extern GLMultiTexCoord2fProc     multiTexCoord2f;
 
171
 
 
172
    extern GLGenProgramsProc        genPrograms;
 
173
    extern GLDeleteProgramsProc     deletePrograms;
 
174
    extern GLBindProgramProc        bindProgram;
 
175
    extern GLProgramStringProc      programString;
 
176
    extern GLProgramParameter4fProc programEnvParameter4f;
 
177
    extern GLProgramParameter4fProc programLocalParameter4f;
 
178
    extern GLGetProgramivProc       getProgramiv;
 
179
 
 
180
    extern GLGenFramebuffersProc        genFramebuffers;
 
181
    extern GLDeleteFramebuffersProc     deleteFramebuffers;
 
182
    extern GLBindFramebufferProc        bindFramebuffer;
 
183
    extern GLCheckFramebufferStatusProc checkFramebufferStatus;
 
184
    extern GLFramebufferTexture2DProc   framebufferTexture2D;
 
185
    extern GLGenerateMipmapProc         generateMipmap;
 
186
 
 
187
    extern bool  textureFromPixmap;
 
188
    extern bool  textureRectangle;
 
189
    extern bool  textureNonPowerOfTwo;
 
190
    extern bool  textureEnvCombine;
 
191
    extern bool  textureEnvCrossbar;
 
192
    extern bool  textureBorderClamp;
 
193
    extern bool  textureCompression;
 
194
    extern GLint maxTextureSize;
 
195
    extern bool  fbo;
 
196
    extern bool  fragmentProgram;
 
197
    extern GLint maxTextureUnits;
 
198
 
 
199
    extern bool canDoSaturated;
 
200
    extern bool canDoSlightlySaturated;
 
201
};
 
202
 
 
203
struct GLScreenPaintAttrib {
 
204
    GLfloat xRotate;
 
205
    GLfloat yRotate;
 
206
    GLfloat vRotate;
 
207
    GLfloat xTranslate;
 
208
    GLfloat yTranslate;
 
209
    GLfloat zTranslate;
 
210
    GLfloat zCamera;
 
211
};
 
212
 
 
213
#define MAX_DEPTH 32
 
214
 
 
215
struct GLFBConfig {
 
216
    GLXFBConfig fbConfig;
 
217
    int         yInverted;
 
218
    int         mipmap;
 
219
    int         textureFormat;
 
220
    int         textureTargets;
 
221
};
 
222
 
 
223
#define NOTHING_TRANS_FILTER 0
 
224
#define SCREEN_TRANS_FILTER  1
 
225
#define WINDOW_TRANS_FILTER  2
 
226
 
 
227
 
 
228
extern GLScreenPaintAttrib defaultScreenPaintAttrib;
 
229
 
 
230
class GLScreen;
 
231
 
 
232
class GLScreenInterface :
 
233
    public WrapableInterface<GLScreen, GLScreenInterface>
 
234
{
 
235
    public:
 
236
        virtual bool glPaintOutput (const GLScreenPaintAttrib &,
 
237
                                    const GLMatrix &, const CompRegion &,
 
238
                                    CompOutput *, unsigned int);
 
239
        virtual void glPaintTransformedOutput (const GLScreenPaintAttrib &,
 
240
                                               const GLMatrix &,
 
241
                                               const CompRegion &,
 
242
                                               CompOutput *, unsigned int);
 
243
        virtual void glApplyTransform (const GLScreenPaintAttrib &,
 
244
                                       CompOutput *, GLMatrix *);
 
245
 
 
246
        virtual void glEnableOutputClipping (const GLMatrix &,
 
247
                                             const CompRegion &,
 
248
                                             CompOutput *);
 
249
        virtual void glDisableOutputClipping ();
 
250
 
 
251
};
 
252
 
 
253
 
 
254
class GLScreen :
 
255
    public WrapableHandler<GLScreenInterface, 5>,
 
256
    public PrivateHandler<GLScreen, CompScreen, COMPIZ_OPENGL_ABI>
 
257
{
 
258
    public:
 
259
        GLScreen (CompScreen *s);
 
260
        ~GLScreen ();
 
261
 
 
262
        CompOption::Vector & getOptions ();
 
263
        bool setOption (const char *name, CompOption::Value &value);
 
264
        CompOption * getOption (const char *name);
 
265
 
 
266
        GLenum textureFilter ();
 
267
        void setTextureFilter (GLenum);
 
268
 
 
269
        void clearTargetOutput (unsigned int mask);
 
270
 
 
271
        GL::FuncPtr getProcAddress (const char *name);
 
272
 
 
273
        void updateBackground ();
 
274
 
 
275
        GLTexture::Filter filter (int);
 
276
        void setFilter (int, GLTexture::Filter);
 
277
 
 
278
        GLFragment::Storage * fragmentStorage ();
 
279
 
 
280
        void setTexEnvMode (GLenum mode);
 
281
        void setLighting (bool lighting);
 
282
        bool lighting ();
 
283
 
 
284
        void clearOutput (CompOutput *output, unsigned int mask);
 
285
 
 
286
        void setDefaultViewport ();
 
287
 
 
288
        GLTexture::BindPixmapHandle registerBindPixmap (GLTexture::BindPixmapProc);
 
289
        void unregisterBindPixmap (GLTexture::BindPixmapHandle);
 
290
        
 
291
        GLFBConfig * glxPixmapFBConfig (unsigned int depth);
 
292
 
 
293
        GLTexture *defaultIcon ();
 
294
 
 
295
        void resetRasterPos ();
 
296
 
 
297
        const float * projectionMatrix ();
 
298
 
 
299
        WRAPABLE_HND (0, GLScreenInterface, bool, glPaintOutput,
 
300
                      const GLScreenPaintAttrib &, const GLMatrix &,
 
301
                      const CompRegion &, CompOutput *, unsigned int);
 
302
        WRAPABLE_HND (1, GLScreenInterface, void, glPaintTransformedOutput,
 
303
                      const GLScreenPaintAttrib &,
 
304
                      const GLMatrix &, const CompRegion &, CompOutput *,
 
305
                      unsigned int);
 
306
        WRAPABLE_HND (2, GLScreenInterface, void, glApplyTransform,
 
307
                      const GLScreenPaintAttrib &, CompOutput *, GLMatrix *);
 
308
 
 
309
        WRAPABLE_HND (3, GLScreenInterface, void, glEnableOutputClipping,
 
310
                      const GLMatrix &, const CompRegion &, CompOutput *);
 
311
        WRAPABLE_HND (4, GLScreenInterface, void, glDisableOutputClipping);
 
312
 
 
313
        friend class GLTexture;
 
314
 
 
315
    private:
 
316
        PrivateGLScreen *priv;
 
317
};
 
318
 
 
319
struct GLWindowPaintAttrib {
 
320
    GLushort opacity;
 
321
    GLushort brightness;
 
322
    GLushort saturation;
 
323
    GLfloat  xScale;
 
324
    GLfloat  yScale;
 
325
    GLfloat  xTranslate;
 
326
    GLfloat  yTranslate;
 
327
};
 
328
 
 
329
class GLWindow;
 
330
 
 
331
class GLWindowInterface :
 
332
    public WrapableInterface<GLWindow, GLWindowInterface>
 
333
{
 
334
    public:
 
335
        virtual bool glPaint (const GLWindowPaintAttrib &, const GLMatrix &,
 
336
                              const CompRegion &, unsigned int);
 
337
        virtual bool glDraw (const GLMatrix &, GLFragment::Attrib &,
 
338
                             const CompRegion &, unsigned int);
 
339
        virtual void glAddGeometry (const GLTexture::MatrixList &,
 
340
                                    const CompRegion &,const CompRegion &);
 
341
        virtual void glDrawTexture (GLTexture *texture, GLFragment::Attrib &,
 
342
                                    unsigned int);
 
343
        virtual void glDrawGeometry ();
 
344
};
 
345
 
 
346
class GLWindow :
 
347
    public WrapableHandler<GLWindowInterface, 5>,
 
348
    public PrivateHandler<GLWindow, CompWindow, COMPIZ_OPENGL_ABI>
 
349
{
 
350
    public:
 
351
 
 
352
        class Geometry {
 
353
            public:
 
354
                Geometry ();
 
355
                ~Geometry ();
 
356
 
 
357
                void reset ();
 
358
                
 
359
                bool moreVertices (int newSize);
 
360
                bool moreIndices (int newSize);
 
361
 
 
362
            public:
 
363
                GLfloat  *vertices;
 
364
                int      vertexSize;
 
365
                int      vertexStride;
 
366
                GLushort *indices;
 
367
                int      indexSize;
 
368
                int      vCount;
 
369
                int      texUnits;
 
370
                int      texCoordSize;
 
371
                int      indexCount;
 
372
        };
 
373
        
 
374
        static GLWindowPaintAttrib defaultPaintAttrib;
 
375
    public:
 
376
 
 
377
        GLWindow (CompWindow *w);
 
378
        ~GLWindow ();
 
379
 
 
380
        const CompRegion & clip () const;
 
381
 
 
382
        GLWindowPaintAttrib & paintAttrib ();
 
383
        GLWindowPaintAttrib & lastPaintAttrib ();
 
384
 
 
385
        unsigned int lastMask () const;
 
386
 
 
387
        bool bind ();
 
388
        void release ();
 
389
 
 
390
        const GLTexture::List &       textures () const;
 
391
        const GLTexture::MatrixList & matrices () const;
 
392
 
 
393
        void updatePaintAttribs ();
 
394
 
 
395
        Geometry & geometry ();
 
396
 
 
397
        GLTexture *getIcon (int width, int height);
 
398
 
 
399
        WRAPABLE_HND (0, GLWindowInterface, bool, glPaint,
 
400
                      const GLWindowPaintAttrib &, const GLMatrix &,
 
401
                      const CompRegion &, unsigned int);
 
402
        WRAPABLE_HND (1, GLWindowInterface, bool, glDraw, const GLMatrix &,
 
403
                      GLFragment::Attrib &, const CompRegion &, unsigned int);
 
404
        WRAPABLE_HND (2, GLWindowInterface, void, glAddGeometry,
 
405
                      const GLTexture::MatrixList &, const CompRegion &,
 
406
                      const CompRegion &);
 
407
        WRAPABLE_HND (3, GLWindowInterface, void, glDrawTexture,
 
408
                      GLTexture *texture, GLFragment::Attrib &, unsigned int);
 
409
        WRAPABLE_HND (4, GLWindowInterface, void, glDrawGeometry);
 
410
 
 
411
        friend class GLScreen;
 
412
        friend class PrivateGLScreen;
 
413
        
 
414
    private:
 
415
        PrivateGLWindow *priv;
 
416
};
 
417
 
 
418
#endif