2
* Copyright © 2005 Novell, Inc.
4
* Permission to use, copy, modify, distribute, and sell this software
5
* and its documentation for any purpose is hereby granted without
6
* fee, provided that the above copyright notice appear in all copies
7
* and that both that copyright notice and this permission notice
8
* appear in supporting documentation, and that the name of
9
* Novell, Inc. not be used in advertising or publicity pertaining to
10
* distribution of the software without specific, written prior permission.
11
* Novell, Inc. makes no representations about the suitability of this
12
* software for any purpose. It is provided "as is" without express or
15
* NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17
* NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23
* Author: David Reveman <davidr@novell.com>
30
#include <boost/foreach.hpp>
31
#define foreach BOOST_FOREACH
33
#include <core/core.h>
34
#include <opengl/opengl.h>
39
GLScreenPaintAttrib defaultScreenPaintAttrib = {
40
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -DEFAULT_Z_CAMERA
43
GLWindowPaintAttrib defaultWindowPaintAttrib = {
44
OPAQUE, BRIGHT, COLOR, 1.0f, 1.0f, 0.0f, 0.0f
48
GLScreen::glApplyTransform (const GLScreenPaintAttrib &sAttrib,
52
WRAPABLE_HND_FUNC(2, glApplyTransform, sAttrib, output, transform)
54
transform->translate (sAttrib.xTranslate,
56
sAttrib.zTranslate + sAttrib.zCamera);
57
transform->rotate (sAttrib.xRotate, 0.0f, 1.0f, 0.0f);
58
transform->rotate (sAttrib.vRotate,
59
cosf (sAttrib.xRotate * DEG2RAD),
61
sinf (sAttrib.xRotate * DEG2RAD));
62
transform->rotate (sAttrib.yRotate, 0.0f, 1.0f, 0.0f);
66
PrivateGLScreen::paintBackground (const CompRegion ®ion,
69
BoxPtr pBox = const_cast <Region> (region.handle ())->rects;
70
int n, nBox = const_cast <Region> (region.handle ())->numRects;
76
if (screen->desktopWindowCount ())
78
if (!backgroundTextures.empty ())
80
backgroundTextures.clear ();
83
backgroundLoaded = false;
89
if (!backgroundLoaded)
90
updateScreenBackground ();
92
backgroundLoaded = true;
95
data = new GLfloat [nBox * 16];
102
if (backgroundTextures.empty ())
121
glVertexPointer (2, GL_FLOAT, sizeof (GLfloat) * 2, data + 2);
123
glColor4us (0, 0, 0, 0);
124
glDrawArrays (GL_QUADS, 0, nBox * 4);
125
glColor4usv (defaultColor);
129
for (unsigned int i = 0; i < backgroundTextures.size (); i++)
131
GLTexture *bg = backgroundTextures[i];
132
CompRegion r = region & *bg;
134
pBox = const_cast <Region> (r.handle ())->rects;
135
nBox = const_cast <Region> (r.handle ())->numRects;
141
*d++ = COMP_TEX_COORD_X (bg->matrix (), pBox->x1);
142
*d++ = COMP_TEX_COORD_Y (bg->matrix (), pBox->y2);
147
*d++ = COMP_TEX_COORD_X (bg->matrix (), pBox->x2);
148
*d++ = COMP_TEX_COORD_Y (bg->matrix (), pBox->y2);
153
*d++ = COMP_TEX_COORD_X (bg->matrix (), pBox->x2);
154
*d++ = COMP_TEX_COORD_Y (bg->matrix (), pBox->y1);
159
*d++ = COMP_TEX_COORD_X (bg->matrix (), pBox->x1);
160
*d++ = COMP_TEX_COORD_Y (bg->matrix (), pBox->y1);
168
glTexCoordPointer (2, GL_FLOAT, sizeof (GLfloat) * 4, data);
169
glVertexPointer (2, GL_FLOAT, sizeof (GLfloat) * 4, data + 2);
174
bg->enable (GLTexture::Good);
176
bg->enable (GLTexture::Fast);
178
glDrawArrays (GL_QUADS, 0, nBox * 4);
189
/* This function currently always performs occlusion detection to
190
minimize paint regions. OpenGL precision requirements are no good
191
enough to guarantee that the results from using occlusion detection
192
is the same as without. It's likely not possible to see any
193
difference with most hardware but occlusion detection in the
194
transformed screen case should be made optional for those who do
197
PrivateGLScreen::paintOutputRegion (const GLMatrix &transform,
198
const CompRegion ®ion,
202
CompRegion tmpRegion (region);
205
int count, windowMask, odMask;
206
CompWindow *fullscreenWindow = NULL;
207
bool status, unredirectFS;
208
bool withOffset = false;
213
CompWindowList::reverse_iterator rit;
215
unredirectFS = CompositeScreen::get (screen)->
216
getOption("unredirect_fullscreen_windows")->value ().b ();
220
if (mask & PAINT_SCREEN_TRANSFORMED_MASK)
222
windowMask = PAINT_WINDOW_ON_TRANSFORMED_SCREEN_MASK;
231
pl = cScreen->getWindowPaintList ();
233
if (!(mask & PAINT_SCREEN_NO_OCCLUSION_DETECTION_MASK))
235
/* detect occlusions */
236
for (rit = pl.rbegin (); rit != pl.rend(); rit++)
239
gw = GLWindow::get (w);
246
if (!w->isViewable () ||
247
!CompositeWindow::get (w)->damaged ())
252
gw->priv->clip = tmpRegion;
254
odMask = PAINT_WINDOW_OCCLUSION_DETECTION_MASK;
256
if ((cScreen->windowPaintOffset ().x () != 0 ||
257
cScreen->windowPaintOffset ().x () != 0) &&
258
!w->onAllViewports ())
262
offXY = w->getMovementForOffset (cScreen->windowPaintOffset ());
264
vTransform = transform;
265
vTransform.translate (offXY.x (), offXY.y (), 0);
267
gw->priv->clip.translate (-offXY.x (), -offXY. y());
269
odMask |= PAINT_WINDOW_WITH_OFFSET_MASK;
270
status = gw->glPaint (gw->paintAttrib (), vTransform,
276
status = gw->glPaint (gw->paintAttrib (), transform, tmpRegion,
284
tmpRegion -= w->region ().translated (offXY);
287
tmpRegion -= w->region ();
289
/* unredirect top most fullscreen windows. */
290
if (count == 0 && unredirectFS)
292
if (w->region () == screen->region () &&
293
tmpRegion.isEmpty ())
295
fullscreenWindow = w;
299
foreach (CompOutput &o, screen->outputDevs ())
300
if (w->region () == CompRegion (o))
301
fullscreenWindow = w;
310
if (fullscreenWindow)
311
CompositeWindow::get (fullscreenWindow)->unredirect ();
313
if (!(mask & PAINT_SCREEN_NO_BACKGROUND_MASK))
314
paintBackground (tmpRegion, (mask & PAINT_SCREEN_TRANSFORMED_MASK));
316
/* paint all windows from bottom to top */
322
if (w == fullscreenWindow)
327
if (!w->isViewable () ||
328
!CompositeWindow::get (w)->damaged ())
332
gw = GLWindow::get (w);
334
const CompRegion &clip =
335
(!(mask & PAINT_SCREEN_NO_OCCLUSION_DETECTION_MASK)) ?
336
gw->clip () : region;
338
if ((cScreen->windowPaintOffset ().x () != 0 ||
339
cScreen->windowPaintOffset ().y () != 0) &&
340
!w->onAllViewports ())
342
offXY = w->getMovementForOffset (cScreen->windowPaintOffset ());
344
vTransform = transform;
345
vTransform.translate (offXY.x (), offXY.y (), 0);
346
gw->glPaint (gw->paintAttrib (), vTransform, clip,
347
windowMask | PAINT_WINDOW_WITH_OFFSET_MASK);
351
gw->glPaint (gw->paintAttrib (), transform, clip, windowMask);
357
GLScreen::glEnableOutputClipping (const GLMatrix &transform,
358
const CompRegion ®ion,
361
WRAPABLE_HND_FUNC(3, glEnableOutputClipping, transform, region, output)
363
GLdouble h = screen->height ();
365
GLdouble p1[2] = { region.handle ()->extents.x1,
366
h - region.handle ()->extents.y2 };
367
GLdouble p2[2] = { region.handle ()->extents.x2,
368
h - region.handle ()->extents.y1 };
370
GLdouble halfW = output->width () / 2.0;
371
GLdouble halfH = output->height () / 2.0;
373
GLdouble cx = output->x1 () + halfW;
374
GLdouble cy = (h - output->y2 ()) + halfH;
376
GLdouble top[4] = { 0.0, halfH / (cy - p1[1]), 0.0, 0.5 };
377
GLdouble bottom[4] = { 0.0, halfH / (cy - p2[1]), 0.0, 0.5 };
378
GLdouble left[4] = { halfW / (cx - p1[0]), 0.0, 0.0, 0.5 };
379
GLdouble right[4] = { halfW / (cx - p2[0]), 0.0, 0.0, 0.5 };
382
glLoadMatrixf (transform.getMatrix ());
384
glClipPlane (GL_CLIP_PLANE0, top);
385
glClipPlane (GL_CLIP_PLANE1, bottom);
386
glClipPlane (GL_CLIP_PLANE2, left);
387
glClipPlane (GL_CLIP_PLANE3, right);
389
glEnable (GL_CLIP_PLANE0);
390
glEnable (GL_CLIP_PLANE1);
391
glEnable (GL_CLIP_PLANE2);
392
glEnable (GL_CLIP_PLANE3);
398
GLScreen::glDisableOutputClipping ()
400
WRAPABLE_HND_FUNC(4, glDisableOutputClipping)
402
glDisable (GL_CLIP_PLANE0);
403
glDisable (GL_CLIP_PLANE1);
404
glDisable (GL_CLIP_PLANE2);
405
glDisable (GL_CLIP_PLANE3);
408
#define CLIP_PLANE_MASK (PAINT_SCREEN_TRANSFORMED_MASK | \
409
PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_MASK)
412
GLScreen::glPaintTransformedOutput (const GLScreenPaintAttrib &sAttrib,
413
const GLMatrix &transform,
414
const CompRegion ®ion,
418
WRAPABLE_HND_FUNC(1, glPaintTransformedOutput, sAttrib, transform,
419
region, output, mask)
421
GLMatrix sTransform = transform;
423
if (mask & PAINT_SCREEN_CLEAR_MASK)
424
clearTargetOutput (GL_COLOR_BUFFER_BIT);
428
glApplyTransform (sAttrib, output, &sTransform);
430
if ((mask & CLIP_PLANE_MASK) == CLIP_PLANE_MASK)
432
glEnableOutputClipping (sTransform, region, output);
434
sTransform.toScreenSpace (output, -sAttrib.zTranslate);
437
glLoadMatrixf (sTransform.getMatrix ());
439
priv->paintOutputRegion (sTransform, region, output, mask);
443
glDisableOutputClipping ();
447
sTransform.toScreenSpace (output, -sAttrib.zTranslate);
450
glLoadMatrixf (sTransform.getMatrix ());
452
priv->paintOutputRegion (sTransform, region, output, mask);
459
GLScreen::glPaintOutput (const GLScreenPaintAttrib &sAttrib,
460
const GLMatrix &transform,
461
const CompRegion ®ion,
465
WRAPABLE_HND_FUNC_RETURN(0, bool, glPaintOutput, sAttrib, transform,
466
region, output, mask)
468
GLMatrix sTransform = transform;
470
if (mask & PAINT_SCREEN_REGION_MASK)
472
if (mask & PAINT_SCREEN_TRANSFORMED_MASK)
474
if (mask & PAINT_SCREEN_FULL_MASK)
476
glPaintTransformedOutput (sAttrib, sTransform,
477
CompRegion (*output), output, mask);
485
/* fall through and redraw region */
487
else if (mask & PAINT_SCREEN_FULL_MASK)
489
glPaintTransformedOutput (sAttrib, sTransform, CompRegion (*output),
499
sTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA);
502
glLoadMatrixf (sTransform.getMatrix ());
504
priv->paintOutputRegion (sTransform, region, output, mask);
511
#define ADD_RECT(data, m, n, x1, y1, x2, y2) \
512
for (it = 0; it < n; it++) \
514
*(data)++ = COMP_TEX_COORD_X (m[it], x1); \
515
*(data)++ = COMP_TEX_COORD_Y (m[it], y1); \
520
for (it = 0; it < n; it++) \
522
*(data)++ = COMP_TEX_COORD_X (m[it], x1); \
523
*(data)++ = COMP_TEX_COORD_Y (m[it], y2); \
528
for (it = 0; it < n; it++) \
530
*(data)++ = COMP_TEX_COORD_X (m[it], x2); \
531
*(data)++ = COMP_TEX_COORD_Y (m[it], y2); \
536
for (it = 0; it < n; it++) \
538
*(data)++ = COMP_TEX_COORD_X (m[it], x2); \
539
*(data)++ = COMP_TEX_COORD_Y (m[it], y1); \
545
#define ADD_QUAD(data, m, n, x1, y1, x2, y2) \
546
for (it = 0; it < n; it++) \
548
*(data)++ = COMP_TEX_COORD_XY (m[it], x1, y1); \
549
*(data)++ = COMP_TEX_COORD_YX (m[it], x1, y1); \
554
for (it = 0; it < n; it++) \
556
*(data)++ = COMP_TEX_COORD_XY (m[it], x1, y2); \
557
*(data)++ = COMP_TEX_COORD_YX (m[it], x1, y2); \
562
for (it = 0; it < n; it++) \
564
*(data)++ = COMP_TEX_COORD_XY (m[it], x2, y2); \
565
*(data)++ = COMP_TEX_COORD_YX (m[it], x2, y2); \
570
for (it = 0; it < n; it++) \
572
*(data)++ = COMP_TEX_COORD_XY (m[it], x2, y1); \
573
*(data)++ = COMP_TEX_COORD_YX (m[it], x2, y1); \
580
GLWindow::glDrawGeometry ()
582
WRAPABLE_HND_FUNC(4, glDrawGeometry)
584
int texUnit = priv->geometry.texUnits;
585
int currentTexUnit = 0;
586
int stride = priv->geometry.vertexStride;
587
GLfloat *vertices = priv->geometry.vertices + (stride - 3);
589
stride *= sizeof (GLfloat);
591
glVertexPointer (3, GL_FLOAT, stride, vertices);
595
if (texUnit != currentTexUnit)
597
(*GL::clientActiveTexture) (GL_TEXTURE0_ARB + texUnit);
598
glEnableClientState (GL_TEXTURE_COORD_ARRAY);
599
currentTexUnit = texUnit;
601
vertices -= priv->geometry.texCoordSize;
602
glTexCoordPointer (priv->geometry.texCoordSize,
603
GL_FLOAT, stride, vertices);
606
glDrawArrays (GL_QUADS, 0, priv->geometry.vCount);
608
/* disable all texture coordinate arrays except 0 */
609
texUnit = priv->geometry.texUnits;
614
(*GL::clientActiveTexture) (GL_TEXTURE0_ARB + texUnit);
615
glDisableClientState (GL_TEXTURE_COORD_ARRAY);
618
(*GL::clientActiveTexture) (GL_TEXTURE0_ARB);
623
GLWindow::glAddGeometry (const GLTexture::MatrixList &matrix,
624
const CompRegion ®ion,
625
const CompRegion &clip)
627
WRAPABLE_HND_FUNC(2, glAddGeometry, matrix, region, clip)
630
int nMatrix = matrix.size ();
632
priv->geometry.texUnits = nMatrix;
634
full = clip.handle ()->extents;
635
if (region.handle ()->extents.x1 > full.x1)
636
full.x1 = region.handle ()->extents.x1;
637
if (region.handle ()->extents.y1 > full.y1)
638
full.y1 = region.handle ()->extents.y1;
639
if (region.handle ()->extents.x2 < full.x2)
640
full.x2 = region.handle ()->extents.x2;
641
if (region.handle ()->extents.y2 < full.y2)
642
full.y2 = region.handle ()->extents.y2;
644
if (full.x1 < full.x2 && full.y1 < full.y2)
652
int n, it, x1, y1, x2, y2;
656
for (it = 0; it < nMatrix; it++)
658
if (matrix[it].xy != 0.0f || matrix[it].yx != 0.0f)
665
pBox = const_cast <Region> (region.handle ())->rects;
666
nBox = const_cast <Region> (region.handle ())->numRects;
668
vSize = 3 + nMatrix * 2;
670
n = priv->geometry.vCount / 4;
672
if ((n + nBox) * vSize * 4 > priv->geometry.vertexSize)
674
if (!priv->geometry.moreVertices ((n + nBox) * vSize * 4))
678
d = priv->geometry.vertices + (priv->geometry.vCount * vSize);
698
if (x1 < x2 && y1 < y2)
700
nClip = const_cast <Region> (clip.handle ())->numRects;
706
ADD_RECT (d, matrix, nMatrix, x1, y1, x2, y2);
710
ADD_QUAD (d, matrix, nMatrix, x1, y1, x2, y2);
717
pClip = const_cast <Region> (clip.handle ())->rects;
719
if (((n + nClip) * vSize * 4) > priv->geometry.vertexSize)
721
if (!priv->geometry.moreVertices ((n + nClip) *
725
d = priv->geometry.vertices + (n * vSize * 4);
743
if (cbox.x1 < cbox.x2 && cbox.y1 < cbox.y2)
747
ADD_RECT (d, matrix, nMatrix,
748
cbox.x1, cbox.y1, cbox.x2, cbox.y2);
752
ADD_QUAD (d, matrix, nMatrix,
753
cbox.x1, cbox.y1, cbox.x2, cbox.y2);
763
priv->geometry.vCount = n * 4;
764
priv->geometry.vertexStride = vSize;
765
priv->geometry.texCoordSize = 2;
770
enableFragmentProgramAndDrawGeometry (GLScreen *gs,
773
GLFragment::Attrib &attrib,
774
GLTexture::Filter filter,
777
GLFragment::Attrib fa (attrib);
780
if (GL::canDoSaturated && attrib.getSaturation () != COLOR)
784
param = fa.allocParameters (1);
786
GLFragment::getSaturateFragmentFunction (texture, param);
788
fa.addFunction (function);
790
(*GL::programEnvParameter4f) (GL_FRAGMENT_PROGRAM_ARB, param,
791
RED_SATURATION_WEIGHT,
792
GREEN_SATURATION_WEIGHT,
793
BLUE_SATURATION_WEIGHT,
794
attrib.getSaturation () / 65535.0f);
797
if (!fa.enable (&blending))
800
texture->enable (filter);
802
if (mask & PAINT_WINDOW_BLEND_MASK)
807
if (attrib.getOpacity () != OPAQUE || attrib.getBrightness () != BRIGHT)
811
color = (attrib.getOpacity () * attrib.getBrightness ()) >> 16;
813
gs->setTexEnvMode (GL_MODULATE);
814
glColor4us (color, color, color, attrib.getOpacity ());
816
w->glDrawGeometry ();
818
glColor4usv (defaultColor);
819
gs->setTexEnvMode (GL_REPLACE);
823
w->glDrawGeometry ();
827
glDisable (GL_BLEND);
829
else if (attrib.getBrightness () != BRIGHT)
831
gs->setTexEnvMode (GL_MODULATE);
832
glColor4us (attrib.getBrightness (), attrib.getBrightness (),
833
attrib.getBrightness (), BRIGHT);
835
w->glDrawGeometry ();
837
glColor4usv (defaultColor);
838
gs->setTexEnvMode (GL_REPLACE);
842
w->glDrawGeometry ();
853
enableFragmentOperationsAndDrawGeometry (GLScreen *gs,
856
GLFragment::Attrib &attrib,
857
GLTexture::Filter filter,
860
if (GL::canDoSaturated && attrib.getSaturation () != COLOR)
864
if (mask & PAINT_WINDOW_BLEND_MASK)
867
texture->enable (filter);
869
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
871
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
872
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
873
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR);
874
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_PRIMARY_COLOR);
875
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
876
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
877
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
879
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
880
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);
881
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
883
glColor4f (1.0f, 1.0f, 1.0f, 0.5f);
885
GL::activeTexture (GL_TEXTURE1_ARB);
887
texture->enable (filter);
889
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
891
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGB);
892
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
893
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT);
894
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
895
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
897
if (GL::canDoSlightlySaturated && attrib.getSaturation () > 0)
899
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
900
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS);
901
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
903
constant[0] = 0.5f + 0.5f * RED_SATURATION_WEIGHT;
904
constant[1] = 0.5f + 0.5f * GREEN_SATURATION_WEIGHT;
905
constant[2] = 0.5f + 0.5f * BLUE_SATURATION_WEIGHT;
908
glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constant);
910
GL::activeTexture (GL_TEXTURE2_ARB);
912
texture->enable (filter);
914
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
916
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
917
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE0);
918
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS);
919
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_CONSTANT);
920
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
921
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
922
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
924
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
925
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS);
926
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
928
constant[3] = attrib.getSaturation () / 65535.0f;
930
glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constant);
932
if (attrib.getOpacity () < OPAQUE ||
933
attrib.getBrightness () != BRIGHT)
935
GL::activeTexture (GL_TEXTURE3_ARB);
937
texture->enable (filter);
939
constant[3] = attrib.getOpacity () / 65535.0f;
940
constant[0] = constant[1] = constant[2] = constant[3] *
941
attrib.getBrightness () / 65535.0f;
943
glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constant);
945
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
947
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
948
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
949
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT);
950
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
951
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
953
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
954
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS);
955
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_CONSTANT);
956
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
957
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
959
w->glDrawGeometry ();
963
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
965
GL::activeTexture (GL_TEXTURE2_ARB);
969
w->glDrawGeometry ();
974
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
976
GL::activeTexture (GL_TEXTURE1_ARB);
980
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
981
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS);
982
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_CONSTANT);
983
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
984
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
986
constant[3] = attrib.getOpacity () / 65535.0f;
987
constant[0] = constant[1] = constant[2] = constant[3] *
988
attrib.getBrightness ()/ 65535.0f;
990
constant[0] = 0.5f + 0.5f * RED_SATURATION_WEIGHT * constant[0];
991
constant[1] = 0.5f + 0.5f * GREEN_SATURATION_WEIGHT * constant[1];
992
constant[2] = 0.5f + 0.5f * BLUE_SATURATION_WEIGHT * constant[2];
994
glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constant);
996
w->glDrawGeometry ();
1001
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1003
GL::activeTexture (GL_TEXTURE0_ARB);
1005
texture->disable ();
1007
glColor4usv (defaultColor);
1008
gs->setTexEnvMode (GL_REPLACE);
1010
if (mask & PAINT_WINDOW_BLEND_MASK)
1011
glDisable (GL_BLEND);
1015
texture->enable (filter);
1017
if (mask & PAINT_WINDOW_BLEND_MASK)
1019
glEnable (GL_BLEND);
1020
if (attrib.getOpacity ()!= OPAQUE ||
1021
attrib.getBrightness () != BRIGHT)
1025
color = (attrib.getOpacity () * attrib.getBrightness ()) >> 16;
1027
gs->setTexEnvMode (GL_MODULATE);
1028
glColor4us (color, color, color, attrib.getOpacity ());
1030
w->glDrawGeometry ();
1032
glColor4usv (defaultColor);
1033
gs->setTexEnvMode (GL_REPLACE);
1037
w->glDrawGeometry ();
1040
glDisable (GL_BLEND);
1042
else if (attrib.getBrightness () != BRIGHT)
1044
gs->setTexEnvMode (GL_MODULATE);
1045
glColor4us (attrib.getBrightness (), attrib.getBrightness (),
1046
attrib.getBrightness (), BRIGHT);
1048
w->glDrawGeometry ();
1050
glColor4usv (defaultColor);
1051
gs->setTexEnvMode (GL_REPLACE);
1055
w->glDrawGeometry ();
1058
texture->disable ();
1063
GLWindow::glDrawTexture (GLTexture *texture,
1064
GLFragment::Attrib &attrib,
1067
WRAPABLE_HND_FUNC(3, glDrawTexture, texture, attrib, mask)
1069
GLTexture::Filter filter;
1071
if (mask & (PAINT_WINDOW_TRANSFORMED_MASK |
1072
PAINT_WINDOW_ON_TRANSFORMED_SCREEN_MASK))
1073
filter = priv->gScreen->filter (SCREEN_TRANS_FILTER);
1075
filter = priv->gScreen->filter (NOTHING_TRANS_FILTER);
1077
if ((!attrib.hasFunctions () && (!priv->gScreen->lighting () ||
1078
attrib.getSaturation () == COLOR || attrib.getSaturation () == 0)) ||
1079
!enableFragmentProgramAndDrawGeometry (priv->gScreen, this, texture,
1080
attrib, filter, mask))
1082
enableFragmentOperationsAndDrawGeometry (priv->gScreen, this, texture,
1083
attrib, filter, mask);
1088
GLWindow::glDraw (const GLMatrix &transform,
1089
GLFragment::Attrib &fragment,
1090
const CompRegion ®ion,
1093
WRAPABLE_HND_FUNC_RETURN(1, bool, glDraw, transform, fragment, region, mask)
1095
const CompRegion reg = (mask & PAINT_WINDOW_TRANSFORMED_MASK) ?
1096
infiniteRegion : region;
1101
if (!priv->window->isViewable ())
1104
if (priv->textures.empty () && !bind ())
1107
if (mask & PAINT_WINDOW_TRANSLUCENT_MASK)
1108
mask |= PAINT_WINDOW_BLEND_MASK;
1110
GLTexture::MatrixList ml (1);
1112
if (priv->textures.size () == 1)
1114
ml[0] = priv->matrices[0];
1115
priv->geometry.reset ();
1116
glAddGeometry (ml, priv->window->region (), reg);
1117
if (priv->geometry.vCount)
1118
glDrawTexture (priv->textures[0], fragment, mask);
1122
if (priv->updateReg)
1123
priv->updateWindowRegions ();
1124
for (unsigned int i = 0; i < priv->textures.size (); i++)
1126
ml[0] = priv->matrices[i];
1127
priv->geometry.reset ();
1128
glAddGeometry (ml, priv->regions[i], reg);
1129
if (priv->geometry.vCount)
1130
glDrawTexture (priv->textures[i], fragment, mask);
1138
GLWindow::glPaint (const GLWindowPaintAttrib &attrib,
1139
const GLMatrix &transform,
1140
const CompRegion ®ion,
1143
WRAPABLE_HND_FUNC_RETURN(0, bool, glPaint, attrib, transform, region, mask)
1145
GLFragment::Attrib fragment (attrib);
1148
priv->lastPaint = attrib;
1150
if (priv->window->alpha () || attrib.opacity != OPAQUE)
1151
mask |= PAINT_WINDOW_TRANSLUCENT_MASK;
1153
priv->lastMask = mask;
1155
if (mask & PAINT_WINDOW_OCCLUSION_DETECTION_MASK)
1157
if (mask & PAINT_WINDOW_TRANSFORMED_MASK)
1160
if (mask & PAINT_WINDOW_NO_CORE_INSTANCE_MASK)
1163
if (mask & PAINT_WINDOW_TRANSLUCENT_MASK)
1166
if (priv->window->shaded ())
1172
if (mask & PAINT_WINDOW_NO_CORE_INSTANCE_MASK)
1175
if (mask & PAINT_WINDOW_TRANSFORMED_MASK ||
1176
mask & PAINT_WINDOW_WITH_OFFSET_MASK)
1179
glLoadMatrixf (transform.getMatrix ());
1182
status = glDraw (transform, fragment, region, mask);
1184
if (mask & PAINT_WINDOW_TRANSFORMED_MASK ||
1185
mask & PAINT_WINDOW_WITH_OFFSET_MASK)