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

« back to all changes in this revision

Viewing changes to plugins/opengl/screen.cpp

  • 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
 
#include "privates.h"
29
 
 
30
 
#include <dlfcn.h>
31
 
#include <math.h>
32
 
 
33
 
namespace GL {
34
 
    GLXBindTexImageProc      bindTexImage = 0;
35
 
    GLXReleaseTexImageProc   releaseTexImage = 0;
36
 
    GLXQueryDrawableProc     queryDrawable = 0;
37
 
    GLXCopySubBufferProc     copySubBuffer = 0;
38
 
    GLXGetVideoSyncProc      getVideoSync = 0;
39
 
    GLXWaitVideoSyncProc     waitVideoSync = 0;
40
 
    GLXGetFBConfigsProc      getFBConfigs = 0;
41
 
    GLXGetFBConfigAttribProc getFBConfigAttrib = 0;
42
 
    GLXCreatePixmapProc      createPixmap = 0;
43
 
 
44
 
    GLActiveTextureProc       activeTexture = 0;
45
 
    GLClientActiveTextureProc clientActiveTexture = 0;
46
 
    GLMultiTexCoord2fProc     multiTexCoord2f = 0;
47
 
 
48
 
    GLGenProgramsProc        genPrograms = 0;
49
 
    GLDeleteProgramsProc     deletePrograms = 0;
50
 
    GLBindProgramProc        bindProgram = 0;
51
 
    GLProgramStringProc      programString = 0;
52
 
    GLProgramParameter4fProc programEnvParameter4f = 0;
53
 
    GLProgramParameter4fProc programLocalParameter4f = 0;
54
 
    GLGetProgramivProc       getProgramiv = 0;
55
 
 
56
 
    GLGenFramebuffersProc        genFramebuffers = 0;
57
 
    GLDeleteFramebuffersProc     deleteFramebuffers = 0;
58
 
    GLBindFramebufferProc        bindFramebuffer = 0;
59
 
    GLCheckFramebufferStatusProc checkFramebufferStatus = 0;
60
 
    GLFramebufferTexture2DProc   framebufferTexture2D = 0;
61
 
    GLGenerateMipmapProc         generateMipmap = 0;
62
 
 
63
 
    bool  textureFromPixmap = true;
64
 
    bool  textureRectangle = false;
65
 
    bool  textureNonPowerOfTwo = false;
66
 
    bool  textureEnvCombine = false;
67
 
    bool  textureEnvCrossbar = false;
68
 
    bool  textureBorderClamp = false;
69
 
    bool  textureCompression = false;
70
 
    GLint maxTextureSize = 0;
71
 
    bool  fbo = false;
72
 
    bool  fragmentProgram = false;
73
 
    GLint maxTextureUnits = 1;
74
 
 
75
 
    bool canDoSaturated = false;
76
 
    bool canDoSlightlySaturated = false;
77
 
}
78
 
 
79
 
CompOutput *targetOutput = NULL;
80
 
 
81
 
GLScreen::GLScreen (CompScreen *s) :
82
 
    PrivateHandler<GLScreen, CompScreen, COMPIZ_OPENGL_ABI> (s),
83
 
    priv (new PrivateGLScreen (this))
84
 
{
85
 
    Display              *dpy = s->dpy ();
86
 
    XVisualInfo          templ;
87
 
    XVisualInfo          *visinfo;
88
 
    GLXFBConfig          *fbConfigs;
89
 
    int                  defaultDepth, nvisinfo, nElements, value, i;
90
 
    const char           *glxExtensions, *glExtensions;
91
 
    GLfloat              globalAmbient[]  = { 0.1f, 0.1f,  0.1f, 0.1f };
92
 
    GLfloat              ambientLight[]   = { 0.0f, 0.0f,  0.0f, 0.0f };
93
 
    GLfloat              diffuseLight[]   = { 0.9f, 0.9f,  0.9f, 0.9f };
94
 
    GLfloat              light0Position[] = { -0.5f, 0.5f, -9.0f, 1.0f };
95
 
    XWindowAttributes    attr;
96
 
 
97
 
    if (indirectRendering)
98
 
    {
99
 
        /* force Mesa libGL into indirect rendering mode, because
100
 
           glXQueryExtensionsString is context-independant */
101
 
        setenv ("LIBGL_ALWAYS_INDIRECT", "1", True);
102
 
    }
103
 
 
104
 
    if (!openglVTable->getMetadata ()->initOptions (glOptionInfo, GL_OPTION_NUM,
105
 
                                                    priv->opt))
106
 
    {
107
 
        setFailed ();
108
 
        return;
109
 
    }
110
 
 
111
 
    if (!XGetWindowAttributes (dpy, s->root (), &attr))
112
 
    {
113
 
        setFailed ();
114
 
        return;
115
 
    }
116
 
 
117
 
    templ.visualid = XVisualIDFromVisual (attr.visual);
118
 
 
119
 
    visinfo = XGetVisualInfo (dpy, VisualIDMask, &templ, &nvisinfo);
120
 
    if (!nvisinfo)
121
 
    {
122
 
        compLogMessage ("opengl", CompLogLevelFatal,
123
 
                        "Couldn't get visual info for default visual");
124
 
        setFailed ();
125
 
        return;
126
 
    }
127
 
 
128
 
    defaultDepth = visinfo->depth;
129
 
 
130
 
    glXGetConfig (dpy, visinfo, GLX_USE_GL, &value);
131
 
    if (!value)
132
 
    {
133
 
        compLogMessage ("opengl", CompLogLevelFatal,
134
 
                        "Root visual is not a GL visual");
135
 
        XFree (visinfo);
136
 
        setFailed ();
137
 
        return;
138
 
    }
139
 
 
140
 
    glXGetConfig (dpy, visinfo, GLX_DOUBLEBUFFER, &value);
141
 
    if (!value)
142
 
    {
143
 
        compLogMessage ("opengl", CompLogLevelFatal,
144
 
                        "Root visual is not a double buffered GL visual");
145
 
        XFree (visinfo);
146
 
        setFailed ();
147
 
        return;
148
 
    }
149
 
 
150
 
    priv->ctx = glXCreateContext (dpy, visinfo, NULL, !indirectRendering);
151
 
    if (!priv->ctx)
152
 
    {
153
 
        compLogMessage ("opengl", CompLogLevelFatal,
154
 
                        "glXCreateContext failed");
155
 
        XFree (visinfo);
156
 
 
157
 
        setFailed ();
158
 
        return;
159
 
    }
160
 
 
161
 
    XFree (visinfo);
162
 
    glxExtensions = glXQueryExtensionsString (dpy, s->screenNum ());
163
 
 
164
 
    if (!strstr (glxExtensions, "GLX_SGIX_fbconfig"))
165
 
    {
166
 
        compLogMessage ("opengl", CompLogLevelFatal,
167
 
                        "GLX_SGIX_fbconfig is missing");
168
 
        setFailed ();
169
 
        return;
170
 
    }
171
 
 
172
 
    priv->getProcAddress = (GL::GLXGetProcAddressProc)
173
 
        getProcAddress ("glXGetProcAddressARB");
174
 
    GL::bindTexImage = (GL::GLXBindTexImageProc)
175
 
        getProcAddress ("glXBindTexImageEXT");
176
 
    GL::releaseTexImage = (GL::GLXReleaseTexImageProc)
177
 
        getProcAddress ("glXReleaseTexImageEXT");
178
 
    GL::queryDrawable = (GL::GLXQueryDrawableProc)
179
 
        getProcAddress ("glXQueryDrawable");
180
 
    GL::getFBConfigs = (GL::GLXGetFBConfigsProc)
181
 
        getProcAddress ("glXGetFBConfigs");
182
 
    GL::getFBConfigAttrib = (GL::GLXGetFBConfigAttribProc)
183
 
        getProcAddress ("glXGetFBConfigAttrib");
184
 
    GL::createPixmap = (GL::GLXCreatePixmapProc)
185
 
        getProcAddress ("glXCreatePixmap");
186
 
 
187
 
 
188
 
    if (!strstr (glxExtensions, "GLX_EXT_texture_from_pixmap") ||
189
 
        !GL::bindTexImage || !GL::releaseTexImage)
190
 
    {
191
 
        compLogMessage ("opengl", CompLogLevelFatal,
192
 
                        "GLX_EXT_texture_from_pixmap is missing");
193
 
        GL::textureFromPixmap = false;
194
 
    }
195
 
    else
196
 
        GL::textureFromPixmap = true;
197
 
 
198
 
    if (!GL::queryDrawable     ||
199
 
        !GL::getFBConfigs      ||
200
 
        !GL::getFBConfigAttrib ||
201
 
        !GL::createPixmap)
202
 
    {
203
 
        compLogMessage ("opengl", CompLogLevelFatal,
204
 
                        "fbconfig functions missing");
205
 
        setFailed ();
206
 
        return;
207
 
    }
208
 
 
209
 
    if (strstr (glxExtensions, "GLX_MESA_copy_sub_buffer"))
210
 
        GL::copySubBuffer = (GL::GLXCopySubBufferProc)
211
 
            getProcAddress ("glXCopySubBufferMESA");
212
 
 
213
 
    if (strstr (glxExtensions, "GLX_SGI_video_sync"))
214
 
    {
215
 
        GL::getVideoSync = (GL::GLXGetVideoSyncProc)
216
 
            getProcAddress ("glXGetVideoSyncSGI");
217
 
 
218
 
        GL::waitVideoSync = (GL::GLXWaitVideoSyncProc)
219
 
            getProcAddress ("glXWaitVideoSyncSGI");
220
 
    }
221
 
 
222
 
    glXMakeCurrent (dpy, CompositeScreen::get (s)->output (), priv->ctx);
223
 
 
224
 
    glExtensions = (const char *) glGetString (GL_EXTENSIONS);
225
 
    if (!glExtensions)
226
 
    {
227
 
        compLogMessage ("opengl", CompLogLevelFatal,
228
 
                        "No valid GL extensions string found.");
229
 
        setFailed ();
230
 
        return;
231
 
    }
232
 
 
233
 
    if (strstr (glExtensions, "GL_ARB_texture_non_power_of_two"))
234
 
        GL::textureNonPowerOfTwo = true;
235
 
 
236
 
    glGetIntegerv (GL_MAX_TEXTURE_SIZE, &GL::maxTextureSize);
237
 
 
238
 
    if (strstr (glExtensions, "GL_NV_texture_rectangle")  ||
239
 
        strstr (glExtensions, "GL_EXT_texture_rectangle") ||
240
 
        strstr (glExtensions, "GL_ARB_texture_rectangle"))
241
 
    {
242
 
        GL::textureRectangle = true;
243
 
 
244
 
        if (!GL::textureNonPowerOfTwo)
245
 
        {
246
 
            GLint maxTextureSize;
247
 
 
248
 
            glGetIntegerv (GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, &maxTextureSize);
249
 
            if (maxTextureSize > GL::maxTextureSize)
250
 
                GL::maxTextureSize = maxTextureSize;
251
 
        }
252
 
    }
253
 
 
254
 
    if (!(GL::textureRectangle || GL::textureNonPowerOfTwo))
255
 
    {
256
 
        compLogMessage ("opengl", CompLogLevelFatal,
257
 
                        "Support for non power of two textures missing");
258
 
        setFailed ();
259
 
        return;
260
 
    }
261
 
 
262
 
    if (strstr (glExtensions, "GL_ARB_texture_env_combine"))
263
 
    {
264
 
        GL::textureEnvCombine = true;
265
 
 
266
 
        /* XXX: GL_NV_texture_env_combine4 need special code but it seams to
267
 
           be working anyway for now... */
268
 
        if (strstr (glExtensions, "GL_ARB_texture_env_crossbar") ||
269
 
            strstr (glExtensions, "GL_NV_texture_env_combine4"))
270
 
            GL::textureEnvCrossbar = true;
271
 
    }
272
 
 
273
 
    if (strstr (glExtensions, "GL_ARB_texture_border_clamp") ||
274
 
        strstr (glExtensions, "GL_SGIS_texture_border_clamp"))
275
 
        GL::textureBorderClamp = true;
276
 
 
277
 
    GL::maxTextureUnits = 1;
278
 
    if (strstr (glExtensions, "GL_ARB_multitexture"))
279
 
    {
280
 
        GL::activeTexture = (GL::GLActiveTextureProc)
281
 
            getProcAddress ("glActiveTexture");
282
 
        GL::clientActiveTexture = (GL::GLClientActiveTextureProc)
283
 
            getProcAddress ("glClientActiveTexture");
284
 
        GL::multiTexCoord2f = (GL::GLMultiTexCoord2fProc)
285
 
            getProcAddress ("glMultiTexCoord2f");
286
 
 
287
 
        if (GL::activeTexture && GL::clientActiveTexture && GL::multiTexCoord2f)
288
 
            glGetIntegerv (GL_MAX_TEXTURE_UNITS_ARB, &GL::maxTextureUnits);
289
 
    }
290
 
 
291
 
    if (strstr (glExtensions, "GL_ARB_fragment_program"))
292
 
    {
293
 
        GL::genPrograms = (GL::GLGenProgramsProc)
294
 
            getProcAddress ("glGenProgramsARB");
295
 
        GL::deletePrograms = (GL::GLDeleteProgramsProc)
296
 
            getProcAddress ("glDeleteProgramsARB");
297
 
        GL::bindProgram = (GL::GLBindProgramProc)
298
 
            getProcAddress ("glBindProgramARB");
299
 
        GL::programString = (GL::GLProgramStringProc)
300
 
            getProcAddress ("glProgramStringARB");
301
 
        GL::programEnvParameter4f = (GL::GLProgramParameter4fProc)
302
 
            getProcAddress ("glProgramEnvParameter4fARB");
303
 
        GL::programLocalParameter4f = (GL::GLProgramParameter4fProc)
304
 
            getProcAddress ("glProgramLocalParameter4fARB");
305
 
        GL::getProgramiv = (GL::GLGetProgramivProc)
306
 
            getProcAddress ("glGetProgramivARB");
307
 
 
308
 
        if (GL::genPrograms             &&
309
 
            GL::deletePrograms          &&
310
 
            GL::bindProgram             &&
311
 
            GL::programString           &&
312
 
            GL::programEnvParameter4f   &&
313
 
            GL::programLocalParameter4f &&
314
 
            GL::getProgramiv)
315
 
            GL::fragmentProgram = true;
316
 
    }
317
 
 
318
 
    if (strstr (glExtensions, "GL_EXT_framebuffer_object"))
319
 
    {
320
 
        GL::genFramebuffers = (GL::GLGenFramebuffersProc)
321
 
            getProcAddress ("glGenFramebuffersEXT");
322
 
        GL::deleteFramebuffers = (GL::GLDeleteFramebuffersProc)
323
 
            getProcAddress ("glDeleteFramebuffersEXT");
324
 
        GL::bindFramebuffer = (GL::GLBindFramebufferProc)
325
 
            getProcAddress ("glBindFramebufferEXT");
326
 
        GL::checkFramebufferStatus = (GL::GLCheckFramebufferStatusProc)
327
 
            getProcAddress ("glCheckFramebufferStatusEXT");
328
 
        GL::framebufferTexture2D = (GL::GLFramebufferTexture2DProc)
329
 
            getProcAddress ("glFramebufferTexture2DEXT");
330
 
        GL::generateMipmap = (GL::GLGenerateMipmapProc)
331
 
            getProcAddress ("glGenerateMipmapEXT");
332
 
 
333
 
        if (GL::genFramebuffers        &&
334
 
            GL::deleteFramebuffers     &&
335
 
            GL::bindFramebuffer        &&
336
 
            GL::checkFramebufferStatus &&
337
 
            GL::framebufferTexture2D   &&
338
 
            GL::generateMipmap)
339
 
            GL::fbo = true;
340
 
    }
341
 
 
342
 
    if (strstr (glExtensions, "GL_ARB_texture_compression"))
343
 
        GL::textureCompression = true;
344
 
 
345
 
    fbConfigs = (*GL::getFBConfigs) (dpy, s->screenNum (), &nElements);
346
 
 
347
 
    for (i = 0; i <= MAX_DEPTH; i++)
348
 
    {
349
 
        int j, db, stencil, depth, alpha, mipmap, rgba;
350
 
 
351
 
        priv->glxPixmapFBConfigs[i].fbConfig       = NULL;
352
 
        priv->glxPixmapFBConfigs[i].mipmap         = 0;
353
 
        priv->glxPixmapFBConfigs[i].yInverted      = 0;
354
 
        priv->glxPixmapFBConfigs[i].textureFormat  = 0;
355
 
        priv->glxPixmapFBConfigs[i].textureTargets = 0;
356
 
 
357
 
        db      = MAXSHORT;
358
 
        stencil = MAXSHORT;
359
 
        depth   = MAXSHORT;
360
 
        mipmap  = 0;
361
 
        rgba    = 0;
362
 
 
363
 
        for (j = 0; j < nElements; j++)
364
 
        {
365
 
            XVisualInfo *vi;
366
 
            int         visualDepth;
367
 
 
368
 
            vi = glXGetVisualFromFBConfig (dpy, fbConfigs[j]);
369
 
            if (vi == NULL)
370
 
                continue;
371
 
 
372
 
            visualDepth = vi->depth;
373
 
 
374
 
            XFree (vi);
375
 
 
376
 
            if (visualDepth != i)
377
 
                continue;
378
 
 
379
 
            (*GL::getFBConfigAttrib) (dpy, fbConfigs[j],
380
 
                                      GLX_ALPHA_SIZE, &alpha);
381
 
            (*GL::getFBConfigAttrib) (dpy, fbConfigs[j],
382
 
                                      GLX_BUFFER_SIZE, &value);
383
 
            if (value != i && (value - alpha) != i)
384
 
                continue;
385
 
 
386
 
            value = 0;
387
 
            if (i == 32)
388
 
            {
389
 
                (*GL::getFBConfigAttrib) (dpy, fbConfigs[j],
390
 
                                          GLX_BIND_TO_TEXTURE_RGBA_EXT, &value);
391
 
 
392
 
                if (value)
393
 
                {
394
 
                    rgba = 1;
395
 
 
396
 
                    priv->glxPixmapFBConfigs[i].textureFormat =
397
 
                        GLX_TEXTURE_FORMAT_RGBA_EXT;
398
 
                }
399
 
            }
400
 
 
401
 
            if (!value)
402
 
            {
403
 
                if (rgba)
404
 
                    continue;
405
 
 
406
 
                (*GL::getFBConfigAttrib) (dpy, fbConfigs[j],
407
 
                                          GLX_BIND_TO_TEXTURE_RGB_EXT, &value);
408
 
                if (!value)
409
 
                    continue;
410
 
 
411
 
                priv->glxPixmapFBConfigs[i].textureFormat =
412
 
                    GLX_TEXTURE_FORMAT_RGB_EXT;
413
 
            }
414
 
 
415
 
            (*GL::getFBConfigAttrib) (dpy, fbConfigs[j],
416
 
                                      GLX_DOUBLEBUFFER, &value);
417
 
            if (value > db)
418
 
                continue;
419
 
 
420
 
            db = value;
421
 
 
422
 
            (*GL::getFBConfigAttrib) (dpy, fbConfigs[j],
423
 
                                      GLX_STENCIL_SIZE, &value);
424
 
            if (value > stencil)
425
 
                continue;
426
 
 
427
 
            stencil = value;
428
 
 
429
 
            (*GL::getFBConfigAttrib) (dpy, fbConfigs[j],
430
 
                                      GLX_DEPTH_SIZE, &value);
431
 
            if (value > depth)
432
 
                continue;
433
 
 
434
 
            depth = value;
435
 
 
436
 
            if (GL::fbo)
437
 
            {
438
 
                (*GL::getFBConfigAttrib) (dpy, fbConfigs[j],
439
 
                                          GLX_BIND_TO_MIPMAP_TEXTURE_EXT,
440
 
                                          &value);
441
 
                if (value < mipmap)
442
 
                    continue;
443
 
 
444
 
                mipmap = value;
445
 
            }
446
 
 
447
 
            (*GL::getFBConfigAttrib) (dpy, fbConfigs[j],
448
 
                                      GLX_Y_INVERTED_EXT, &value);
449
 
 
450
 
            priv->glxPixmapFBConfigs[i].yInverted = value;
451
 
 
452
 
            (*GL::getFBConfigAttrib) (dpy, fbConfigs[j],
453
 
                                      GLX_BIND_TO_TEXTURE_TARGETS_EXT, &value);
454
 
 
455
 
            priv->glxPixmapFBConfigs[i].textureTargets = value;
456
 
 
457
 
            priv->glxPixmapFBConfigs[i].fbConfig = fbConfigs[j];
458
 
            priv->glxPixmapFBConfigs[i].mipmap   = mipmap;
459
 
        }
460
 
    }
461
 
 
462
 
    if (nElements)
463
 
        XFree (fbConfigs);
464
 
 
465
 
    if (!priv->glxPixmapFBConfigs[defaultDepth].fbConfig)
466
 
    {
467
 
        compLogMessage ("opengl", CompLogLevelFatal,
468
 
                        "No GLXFBConfig for default depth, "
469
 
                        "this isn't going to work.");
470
 
        setFailed ();
471
 
        return;
472
 
    }
473
 
 
474
 
    glClearColor (0.0, 0.0, 0.0, 1.0);
475
 
    glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
476
 
    glEnable (GL_CULL_FACE);
477
 
    glDisable (GL_BLEND);
478
 
    glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
479
 
    glColor4usv (defaultColor);
480
 
    glEnableClientState (GL_VERTEX_ARRAY);
481
 
    glEnableClientState (GL_TEXTURE_COORD_ARRAY);
482
 
 
483
 
    if (GL::textureEnvCombine && GL::maxTextureUnits >= 2)
484
 
    {
485
 
        GL::canDoSaturated = true;
486
 
        if (GL::textureEnvCrossbar && GL::maxTextureUnits >= 4)
487
 
            GL::canDoSlightlySaturated = true;
488
 
    }
489
 
 
490
 
    priv->updateView ();
491
 
 
492
 
    glLightModelfv (GL_LIGHT_MODEL_AMBIENT, globalAmbient);
493
 
 
494
 
    glEnable (GL_LIGHT0);
495
 
    glLightfv (GL_LIGHT0, GL_AMBIENT, ambientLight);
496
 
    glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuseLight);
497
 
    glLightfv (GL_LIGHT0, GL_POSITION, light0Position);
498
 
 
499
 
    glColorMaterial (GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
500
 
 
501
 
    glNormal3f (0.0f, 0.0f, -1.0f);
502
 
 
503
 
    priv->lighting = false;
504
 
 
505
 
 
506
 
    priv->filter[NOTHING_TRANS_FILTER] = GLTexture::Fast;
507
 
    priv->filter[SCREEN_TRANS_FILTER]  = GLTexture::Good;
508
 
    priv->filter[WINDOW_TRANS_FILTER]  = GLTexture::Good;
509
 
 
510
 
    if (GL::textureFromPixmap)
511
 
        registerBindPixmap (TfpTexture::bindPixmapToTexture);
512
 
 
513
 
}
514
 
 
515
 
GLScreen::~GLScreen ()
516
 
{
517
 
    if (priv->hasCompositing)
518
 
        CompositeScreen::get (screen)->unregisterPaintHandler ();
519
 
    glXDestroyContext (screen->dpy (), priv->ctx);
520
 
    delete priv;
521
 
}
522
 
 
523
 
PrivateGLScreen::PrivateGLScreen (GLScreen   *gs) :
524
 
    gScreen (gs),
525
 
    cScreen (CompositeScreen::get (screen)),
526
 
    textureFilter (GL_LINEAR),
527
 
    backgroundTextures (),
528
 
    backgroundLoaded (false),
529
 
    rasterPos (0, 0),
530
 
    fragmentStorage (),
531
 
    clearBuffers (true),
532
 
    lighting (false),
533
 
    getProcAddress (0),
534
 
    outputRegion (),
535
 
    pendingCommands (false),
536
 
    bindPixmap (),
537
 
    hasCompositing (false)
538
 
{
539
 
    ScreenInterface::setHandler (screen);
540
 
}
541
 
 
542
 
PrivateGLScreen::~PrivateGLScreen ()
543
 
{
544
 
}
545
 
 
546
 
GLushort defaultColor[4] = { 0xffff, 0xffff, 0xffff, 0xffff };
547
 
 
548
 
 
549
 
 
550
 
GLenum
551
 
GLScreen::textureFilter ()
552
 
{
553
 
    return priv->textureFilter;
554
 
}
555
 
 
556
 
void
557
 
GLScreen::setTextureFilter (GLenum filter)
558
 
{
559
 
    priv->textureFilter = filter;
560
 
}
561
 
 
562
 
void
563
 
PrivateGLScreen::handleEvent (XEvent *event)
564
 
{
565
 
    CompWindow *w;
566
 
 
567
 
    screen->handleEvent (event);
568
 
 
569
 
    switch (event->type) {
570
 
        case PropertyNotify:
571
 
            if (event->xproperty.atom == Atoms::xBackground[0] ||
572
 
                event->xproperty.atom == Atoms::xBackground[1])
573
 
            {
574
 
                if (event->xproperty.window == screen->root ())
575
 
                    gScreen->updateBackground ();
576
 
            }
577
 
            else if (event->xproperty.atom == Atoms::winOpacity ||
578
 
                     event->xproperty.atom == Atoms::winBrightness ||
579
 
                     event->xproperty.atom == Atoms::winSaturation)
580
 
            {
581
 
                w = screen->findWindow (event->xproperty.window);
582
 
                if (w)
583
 
                    GLWindow::get (w)->updatePaintAttribs ();
584
 
            }
585
 
            else if (event->xproperty.atom == Atoms::wmIcon)
586
 
            {
587
 
                w = screen->findWindow (event->xproperty.window);
588
 
                if (w)
589
 
                    GLWindow::get (w)->priv->icons.clear ();
590
 
            }
591
 
            break;
592
 
        break;
593
 
        default:
594
 
            if (event->type == cScreen->damageEvent () + XDamageNotify)
595
 
            {
596
 
                XDamageNotifyEvent *de = (XDamageNotifyEvent *) event;
597
 
 
598
 
                std::map<Damage, TfpTexture*>::iterator it =
599
 
                    boundPixmapTex.find (de->damage);
600
 
                if (it != boundPixmapTex.end ())
601
 
                {
602
 
                    it->second->damaged = true;
603
 
                }
604
 
            }
605
 
            break;
606
 
    }
607
 
}
608
 
 
609
 
void
610
 
GLScreen::clearTargetOutput (unsigned int mask)
611
 
{
612
 
    clearOutput (targetOutput, mask);
613
 
}
614
 
 
615
 
 
616
 
static void
617
 
frustum (GLfloat *m,
618
 
         GLfloat left,
619
 
         GLfloat right,
620
 
         GLfloat bottom,
621
 
         GLfloat top,
622
 
         GLfloat nearval,
623
 
         GLfloat farval)
624
 
{
625
 
    GLfloat x, y, a, b, c, d;
626
 
 
627
 
    x = (2.0 * nearval) / (right - left);
628
 
    y = (2.0 * nearval) / (top - bottom);
629
 
    a = (right + left) / (right - left);
630
 
    b = (top + bottom) / (top - bottom);
631
 
    c = -(farval + nearval) / ( farval - nearval);
632
 
    d = -(2.0 * farval * nearval) / (farval - nearval);
633
 
 
634
 
#define M(row,col)  m[col*4+row]
635
 
    M(0,0) = x;     M(0,1) = 0.0f;  M(0,2) = a;      M(0,3) = 0.0f;
636
 
    M(1,0) = 0.0f;  M(1,1) = y;     M(1,2) = b;      M(1,3) = 0.0f;
637
 
    M(2,0) = 0.0f;  M(2,1) = 0.0f;  M(2,2) = c;      M(2,3) = d;
638
 
    M(3,0) = 0.0f;  M(3,1) = 0.0f;  M(3,2) = -1.0f;  M(3,3) = 0.0f;
639
 
#undef M
640
 
 
641
 
}
642
 
 
643
 
static void
644
 
perspective (GLfloat *m,
645
 
             GLfloat fovy,
646
 
             GLfloat aspect,
647
 
             GLfloat zNear,
648
 
             GLfloat zFar)
649
 
{
650
 
    GLfloat xmin, xmax, ymin, ymax;
651
 
 
652
 
    ymax = zNear * tan (fovy * M_PI / 360.0);
653
 
    ymin = -ymax;
654
 
    xmin = ymin * aspect;
655
 
    xmax = ymax * aspect;
656
 
 
657
 
    frustum (m, xmin, xmax, ymin, ymax, zNear, zFar);
658
 
}
659
 
 
660
 
void
661
 
PrivateGLScreen::updateView ()
662
 
{
663
 
    glMatrixMode (GL_PROJECTION);
664
 
    glLoadIdentity ();
665
 
    glMatrixMode (GL_MODELVIEW);
666
 
    glLoadIdentity ();
667
 
    glDepthRange (0, 1);
668
 
    glViewport (-1, -1, 2, 2);
669
 
    glRasterPos2f (0, 0);
670
 
 
671
 
    rasterPos = CompPoint (0, 0);
672
 
 
673
 
    perspective (projection, 60.0f, 1.0f, 0.1f, 100.0f);
674
 
 
675
 
    glMatrixMode (GL_PROJECTION);
676
 
    glLoadIdentity ();
677
 
    glMultMatrixf (projection);
678
 
    glMatrixMode (GL_MODELVIEW);
679
 
 
680
 
    CompRegion region (screen->region ());
681
 
    /* remove all output regions from visible screen region */
682
 
    foreach (CompOutput &o, screen->outputDevs ())
683
 
        region -= o;
684
 
 
685
 
    /* we should clear color buffers before swapping if we have visible
686
 
        regions without output */
687
 
    clearBuffers = !region.isEmpty ();
688
 
 
689
 
    gScreen->setDefaultViewport ();
690
 
}
691
 
 
692
 
void
693
 
PrivateGLScreen::outputChangeNotify ()
694
 
{
695
 
    screen->outputChangeNotify ();
696
 
 
697
 
    updateView ();
698
 
}
699
 
 
700
 
GL::FuncPtr
701
 
GLScreen::getProcAddress (const char *name)
702
 
{
703
 
    static void *dlhand = NULL;
704
 
    GL::FuncPtr funcPtr = NULL;
705
 
 
706
 
    if (priv->getProcAddress)
707
 
        funcPtr = priv->getProcAddress ((GLubyte *) name);
708
 
 
709
 
    if (!funcPtr)
710
 
    {
711
 
        if (!dlhand)
712
 
            dlhand = dlopen ("libopengl.so", RTLD_LAZY);
713
 
 
714
 
        if (dlhand)
715
 
        {
716
 
            dlerror ();
717
 
            funcPtr = (GL::FuncPtr) dlsym (dlhand, name);
718
 
            if (dlerror () != NULL)
719
 
                funcPtr = NULL;
720
 
        }
721
 
    }
722
 
 
723
 
    return funcPtr;
724
 
}
725
 
 
726
 
void
727
 
PrivateGLScreen::updateScreenBackground ()
728
 
{
729
 
    Display       *dpy = screen->dpy ();
730
 
    Atom          pixmapAtom, actualType;
731
 
    int           actualFormat, i, status;
732
 
    unsigned int  width = 1, height = 1, depth = 0;
733
 
    unsigned long nItems;
734
 
    unsigned long bytesAfter;
735
 
    unsigned char *prop;
736
 
    Pixmap        pixmap = 0;
737
 
 
738
 
    pixmapAtom = XInternAtom (dpy, "PIXMAP", FALSE);
739
 
 
740
 
    for (i = 0; pixmap == 0 && i < 2; i++)
741
 
    {
742
 
        status = XGetWindowProperty (dpy, screen->root (),
743
 
                                     Atoms::xBackground[i],
744
 
                                     0, 4, FALSE, AnyPropertyType,
745
 
                                     &actualType, &actualFormat, &nItems,
746
 
                                     &bytesAfter, &prop);
747
 
 
748
 
        if (status == Success && nItems && prop)
749
 
        {
750
 
            if (actualType   == pixmapAtom &&
751
 
                actualFormat == 32         &&
752
 
                nItems       == 1)
753
 
            {
754
 
                Pixmap p;
755
 
 
756
 
                memcpy (&p, prop, 4);
757
 
 
758
 
                if (p)
759
 
                {
760
 
                    unsigned int ui;
761
 
                    int          i;
762
 
                    Window       w;
763
 
 
764
 
                    if (XGetGeometry (dpy, p, &w, &i, &i,
765
 
                                      &width, &height, &ui, &depth))
766
 
                    {
767
 
                        if ((int) depth == screen->attrib ().depth)
768
 
                            pixmap = p;
769
 
                    }
770
 
                }
771
 
            }
772
 
 
773
 
            XFree (prop);
774
 
        }
775
 
    }
776
 
 
777
 
    if (pixmap)
778
 
    {
779
 
        backgroundTextures =
780
 
            GLTexture::bindPixmapToTexture (pixmap, width, height, depth);
781
 
        if (backgroundTextures.empty ())
782
 
        {
783
 
            compLogMessage ("core", CompLogLevelWarn,
784
 
                            "Couldn't bind background pixmap 0x%x to "
785
 
                            "texture", (int) pixmap);
786
 
        }
787
 
    }
788
 
    else
789
 
    {
790
 
        backgroundTextures.clear ();
791
 
    }
792
 
 
793
 
    if (backgroundTextures.empty () && backgroundImage)
794
 
    {
795
 
        CompSize   size;
796
 
        CompString fileName (backgroundImage);
797
 
 
798
 
        backgroundTextures = GLTexture::readImageToTexture (fileName, size);
799
 
    }
800
 
 
801
 
    if (!backgroundTextures.empty ())
802
 
    {
803
 
        foreach (GLTexture *t, backgroundTextures)
804
 
            if (t->target () == GL_TEXTURE_2D)
805
 
            {
806
 
                glBindTexture (t->target (), t->name ());
807
 
                glTexParameteri (t->target (), GL_TEXTURE_WRAP_S, GL_REPEAT);
808
 
                glTexParameteri (t->target (), GL_TEXTURE_WRAP_T, GL_REPEAT);
809
 
                glBindTexture (t->target (), 0);
810
 
            }
811
 
    }
812
 
}
813
 
 
814
 
void
815
 
GLScreen::setTexEnvMode (GLenum mode)
816
 
{
817
 
    if (priv->lighting)
818
 
        glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
819
 
    else
820
 
        glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode);
821
 
}
822
 
 
823
 
void
824
 
GLScreen::setLighting (bool lighting)
825
 
{
826
 
    if (priv->lighting != lighting)
827
 
    {
828
 
        if (!priv->opt[GL_OPTION_LIGHTING].value ().b ())
829
 
            lighting = false;
830
 
 
831
 
        if (lighting)
832
 
        {
833
 
            glEnable (GL_COLOR_MATERIAL);
834
 
            glEnable (GL_LIGHTING);
835
 
        }
836
 
        else
837
 
        {
838
 
            glDisable (GL_COLOR_MATERIAL);
839
 
            glDisable (GL_LIGHTING);
840
 
        }
841
 
 
842
 
        priv->lighting = lighting;
843
 
 
844
 
        setTexEnvMode (GL_REPLACE);
845
 
    }
846
 
}
847
 
 
848
 
bool
849
 
GLScreenInterface::glPaintOutput (const GLScreenPaintAttrib &sAttrib,
850
 
                                  const GLMatrix            &transform,
851
 
                                  const CompRegion          &region,
852
 
                                  CompOutput                *output,
853
 
                                  unsigned int              mask)
854
 
    WRAPABLE_DEF (glPaintOutput, sAttrib, transform, region, output, mask)
855
 
 
856
 
void
857
 
GLScreenInterface::glPaintTransformedOutput (const GLScreenPaintAttrib &sAttrib,
858
 
                                             const GLMatrix            &transform,
859
 
                                             const CompRegion          &region,
860
 
                                             CompOutput                *output,
861
 
                                             unsigned int              mask)
862
 
    WRAPABLE_DEF (glPaintTransformedOutput, sAttrib, transform, region,
863
 
                  output, mask)
864
 
 
865
 
void
866
 
GLScreenInterface::glApplyTransform (const GLScreenPaintAttrib &sAttrib,
867
 
                                     CompOutput                *output,
868
 
                                     GLMatrix                  *transform)
869
 
    WRAPABLE_DEF (glApplyTransform, sAttrib, output, transform)
870
 
 
871
 
void
872
 
GLScreenInterface::glEnableOutputClipping (const GLMatrix   &transform,
873
 
                                           const CompRegion &region,
874
 
                                           CompOutput       *output)
875
 
    WRAPABLE_DEF (glEnableOutputClipping, transform, region, output)
876
 
 
877
 
void
878
 
GLScreenInterface::glDisableOutputClipping ()
879
 
    WRAPABLE_DEF (glDisableOutputClipping)
880
 
 
881
 
void
882
 
GLScreen::updateBackground ()
883
 
{
884
 
    priv->backgroundTextures.clear ();
885
 
 
886
 
    if (priv->backgroundLoaded)
887
 
    {
888
 
        priv->backgroundLoaded = false;
889
 
        CompositeScreen::get (screen)->damageScreen ();
890
 
    }
891
 
}
892
 
 
893
 
bool
894
 
GLScreen::lighting ()
895
 
{
896
 
    return priv->lighting;
897
 
}
898
 
 
899
 
GLTexture::Filter
900
 
GLScreen::filter (int filter)
901
 
{
902
 
    return priv->filter[filter];
903
 
}
904
 
 
905
 
void
906
 
GLScreen::setFilter (int num, GLTexture::Filter filter)
907
 
{
908
 
    priv->filter[num] = filter;
909
 
}
910
 
 
911
 
GLFragment::Storage *
912
 
GLScreen::fragmentStorage ()
913
 
{
914
 
    return &priv->fragmentStorage;
915
 
}
916
 
 
917
 
GLFBConfig*
918
 
GLScreen::glxPixmapFBConfig (unsigned int depth)
919
 
{
920
 
    return &priv->glxPixmapFBConfigs[depth];
921
 
}
922
 
 
923
 
void
924
 
GLScreen::clearOutput (CompOutput   *output,
925
 
                       unsigned int mask)
926
 
{
927
 
    BoxPtr pBox = &output->region ()->extents;
928
 
 
929
 
    if (pBox->x1 != 0        ||
930
 
        pBox->y1 != 0        ||
931
 
        pBox->x2 != (int) screen->width () ||
932
 
        pBox->y2 != (int) screen->height ())
933
 
    {
934
 
        glPushAttrib (GL_SCISSOR_BIT);
935
 
 
936
 
        glEnable (GL_SCISSOR_TEST);
937
 
        glScissor (pBox->x1,
938
 
                   screen->height () - pBox->y2,
939
 
                   pBox->x2 - pBox->x1,
940
 
                   pBox->y2 - pBox->y1);
941
 
        glClear (mask);
942
 
 
943
 
        glPopAttrib ();
944
 
    }
945
 
    else
946
 
    {
947
 
        glClear (mask);
948
 
    }
949
 
}
950
 
 
951
 
void
952
 
GLScreen::setDefaultViewport ()
953
 
{
954
 
    priv->lastViewport.x      = screen->outputDevs ()[0].x1 ();
955
 
    priv->lastViewport.y      = screen->height () -
956
 
                                screen->outputDevs ()[0].y2 ();
957
 
    priv->lastViewport.width  = screen->outputDevs ()[0].width ();
958
 
    priv->lastViewport.height = screen->outputDevs ()[0].height ();
959
 
 
960
 
    glViewport (priv->lastViewport.x,
961
 
                priv->lastViewport.y,
962
 
                priv->lastViewport.width,
963
 
                priv->lastViewport.height);
964
 
}
965
 
 
966
 
void
967
 
PrivateGLScreen::waitForVideoSync ()
968
 
{
969
 
    unsigned int sync;
970
 
 
971
 
    if (!opt[GL_OPTION_SYNC_TO_VBLANK].value ().b ())
972
 
        return;
973
 
 
974
 
    if (GL::getVideoSync)
975
 
    {
976
 
        glFlush ();
977
 
 
978
 
        (*GL::getVideoSync) (&sync);
979
 
        (*GL::waitVideoSync) (2, (sync + 1) % 2, &sync);
980
 
    }
981
 
}
982
 
 
983
 
CompOption *
984
 
GLScreen::getOption (const char *name)
985
 
{
986
 
    CompOption *o = CompOption::findOption (priv->opt, name);
987
 
    return o;
988
 
}
989
 
 
990
 
void
991
 
PrivateGLScreen::paintOutputs (CompOutput::ptrList &outputs,
992
 
                               unsigned int        mask,
993
 
                               const CompRegion    &region)
994
 
{
995
 
    XRectangle r;
996
 
 
997
 
    if (clearBuffers)
998
 
    {
999
 
        if (mask & COMPOSITE_SCREEN_DAMAGE_ALL_MASK)
1000
 
            glClear (GL_COLOR_BUFFER_BIT);
1001
 
    }
1002
 
 
1003
 
    CompRegion tmpRegion (region);
1004
 
 
1005
 
    foreach (CompOutput *output, outputs)
1006
 
    {
1007
 
        targetOutput = output;
1008
 
 
1009
 
        r.x      = output->x1 ();
1010
 
        r.y      = screen->height () - output->y2 ();
1011
 
        r.width  = output->width ();
1012
 
        r.height = output->height ();
1013
 
 
1014
 
        if (lastViewport.x      != r.x     ||
1015
 
            lastViewport.y      != r.y     ||
1016
 
            lastViewport.width  != r.width ||
1017
 
            lastViewport.height != r.height)
1018
 
        {
1019
 
            glViewport (r.x, r.y, r.width, r.height);
1020
 
            lastViewport = r;
1021
 
        }
1022
 
 
1023
 
        if (mask & COMPOSITE_SCREEN_DAMAGE_ALL_MASK)
1024
 
        {
1025
 
            GLMatrix identity;
1026
 
 
1027
 
            gScreen->glPaintOutput (defaultScreenPaintAttrib,
1028
 
                                    identity,
1029
 
                                    CompRegion (*output), output,
1030
 
                                    PAINT_SCREEN_REGION_MASK |
1031
 
                                    PAINT_SCREEN_FULL_MASK);
1032
 
        }
1033
 
        else if (mask & COMPOSITE_SCREEN_DAMAGE_REGION_MASK)
1034
 
        {
1035
 
            GLMatrix identity;
1036
 
 
1037
 
            outputRegion = tmpRegion & CompRegion (*output);
1038
 
 
1039
 
            if (!gScreen->glPaintOutput (defaultScreenPaintAttrib,
1040
 
                                         identity,
1041
 
                                         outputRegion, output,
1042
 
                                         PAINT_SCREEN_REGION_MASK))
1043
 
            {
1044
 
                identity.reset ();
1045
 
 
1046
 
                gScreen->glPaintOutput (defaultScreenPaintAttrib,
1047
 
                                        identity,
1048
 
                                        CompRegion (*output), output,
1049
 
                                        PAINT_SCREEN_FULL_MASK);
1050
 
 
1051
 
                tmpRegion += *output;
1052
 
 
1053
 
            }
1054
 
        }
1055
 
    }
1056
 
 
1057
 
    targetOutput = &screen->outputDevs ()[0];
1058
 
 
1059
 
    waitForVideoSync ();
1060
 
 
1061
 
    if (mask & COMPOSITE_SCREEN_DAMAGE_ALL_MASK)
1062
 
    {
1063
 
        glXSwapBuffers (screen->dpy (), cScreen->output ());
1064
 
    }
1065
 
    else
1066
 
    {
1067
 
        BoxPtr pBox;
1068
 
        int    nBox, y;
1069
 
 
1070
 
        pBox = const_cast <Region> (tmpRegion.handle ())->rects;
1071
 
        nBox = const_cast <Region> (tmpRegion.handle ())->numRects;
1072
 
 
1073
 
        if (GL::copySubBuffer)
1074
 
        {
1075
 
            while (nBox--)
1076
 
            {
1077
 
                y = screen->height () - pBox->y2;
1078
 
 
1079
 
                (*GL::copySubBuffer) (screen->dpy (), cScreen->output (),
1080
 
                                      pBox->x1, y,
1081
 
                                      pBox->x2 - pBox->x1,
1082
 
                                      pBox->y2 - pBox->y1);
1083
 
 
1084
 
                pBox++;
1085
 
            }
1086
 
        }
1087
 
        else
1088
 
        {
1089
 
            glEnable (GL_SCISSOR_TEST);
1090
 
            glDrawBuffer (GL_FRONT);
1091
 
 
1092
 
            while (nBox--)
1093
 
            {
1094
 
                y = screen->height () - pBox->y2;
1095
 
 
1096
 
                glBitmap (0, 0, 0, 0,
1097
 
                          pBox->x1 - rasterPos.x (),
1098
 
                          y - rasterPos.y (),
1099
 
                          NULL);
1100
 
 
1101
 
                rasterPos = CompPoint (pBox->x1, y);
1102
 
 
1103
 
                glScissor (pBox->x1, y,
1104
 
                           pBox->x2 - pBox->x1,
1105
 
                           pBox->y2 - pBox->y1);
1106
 
 
1107
 
                glCopyPixels (pBox->x1, y,
1108
 
                              pBox->x2 - pBox->x1,
1109
 
                              pBox->y2 - pBox->y1,
1110
 
                              GL_COLOR);
1111
 
 
1112
 
                pBox++;
1113
 
            }
1114
 
 
1115
 
            glDrawBuffer (GL_BACK);
1116
 
            glDisable (GL_SCISSOR_TEST);
1117
 
            glFlush ();
1118
 
        }
1119
 
    }
1120
 
}
1121
 
 
1122
 
bool
1123
 
PrivateGLScreen::hasVSync ()
1124
 
{
1125
 
   return (GL::getVideoSync &&
1126
 
           opt[GL_OPTION_SYNC_TO_VBLANK].value ().b ());
1127
 
}
1128
 
 
1129
 
void
1130
 
PrivateGLScreen::prepareDrawing ()
1131
 
{
1132
 
    if (pendingCommands)
1133
 
    {
1134
 
        glFinish ();
1135
 
        pendingCommands = false;
1136
 
    }
1137
 
}
1138
 
 
1139
 
GLTexture::BindPixmapHandle
1140
 
GLScreen::registerBindPixmap (GLTexture::BindPixmapProc proc)
1141
 
{
1142
 
    priv->bindPixmap.push_back (proc);
1143
 
    if (!priv->hasCompositing &&
1144
 
        CompositeScreen::get (screen)->registerPaintHandler (priv))
1145
 
        priv->hasCompositing = true;
1146
 
    return priv->bindPixmap.size () - 1;
1147
 
}
1148
 
 
1149
 
void
1150
 
GLScreen::unregisterBindPixmap (GLTexture::BindPixmapHandle hnd)
1151
 
{
1152
 
    bool hasBP = false;
1153
 
    priv->bindPixmap[hnd].clear ();
1154
 
    for (unsigned int i = 0; i < priv->bindPixmap.size (); i++)
1155
 
        if (!priv->bindPixmap[i].empty ())
1156
 
            hasBP = true;
1157
 
    if (!hasBP && priv->hasCompositing)
1158
 
    {
1159
 
        CompositeScreen::get (screen)->unregisterPaintHandler ();
1160
 
        priv->hasCompositing = false;
1161
 
    }
1162
 
}
1163
 
 
1164
 
GLTexture *
1165
 
GLScreen::defaultIcon ()
1166
 
{
1167
 
    CompIcon *i = screen->defaultIcon ();
1168
 
    CompSize size;
1169
 
 
1170
 
    if (!i)
1171
 
        return NULL;
1172
 
    
1173
 
    if (!i->width () || !i->height ())
1174
 
        return NULL;
1175
 
 
1176
 
    if (priv->defaultIcon.icon == i)
1177
 
        return priv->defaultIcon.textures[0];
1178
 
 
1179
 
    priv->defaultIcon.textures =
1180
 
        GLTexture::imageBufferToTexture ((char *) i->data (), *i);
1181
 
 
1182
 
    if (priv->defaultIcon.textures.size () == 1)
1183
 
        priv->defaultIcon.icon = i;
1184
 
    else
1185
 
    {
1186
 
        priv->defaultIcon.icon = NULL;
1187
 
        priv->defaultIcon.textures.clear ();
1188
 
    }
1189
 
 
1190
 
    return priv->defaultIcon.textures[0];
1191
 
}
1192
 
 
1193
 
void
1194
 
GLScreen::resetRasterPos ()
1195
 
{
1196
 
    glRasterPos2f (0, 0);
1197
 
    priv->rasterPos.setX (0);
1198
 
    priv->rasterPos.setY (0);
1199
 
}
1200
 
 
1201
 
const float *
1202
 
GLScreen::projectionMatrix ()
1203
 
{
1204
 
    return priv->projection;
1205
 
}