Public feed #601193

Untitled

public text v1 · immutable
Raw Edit
·published 2007-07-03 11:02 UTC
rendered paste body
From b6ed3efdcd695e55d5066af84572a4b77351e7b8 Mon Sep 17 00:00:00 2001
From: Roi Cohen <roico@roico-desktop.(none)>
Date: Tue, 3 Jul 2007 14:01:58 +0300
Subject: [PATCH] add wrappable function - setClipPlanes and wrap it by cube to get correct clipPlanes for 3d

---
 include/compiz.h |    9 +++++++++
 include/cube.h   |    3 ++-
 plugins/cube.c   |   42 ++++++++++++++++++++++++++++++++++++++++++
 src/paint.c      |   43 +++++++++++++++++++++++--------------------
 src/screen.c     |    1 +
 5 files changed, 77 insertions(+), 21 deletions(-)

diff --git a/include/compiz.h b/include/compiz.h
index dd34f00..5e010fc 100644
--- a/include/compiz.h
+++ b/include/compiz.h
@@ -1320,6 +1320,10 @@ typedef void (*PaintBackgroundProc) (CompScreen   *screen,
 				     Region	  region,
 				     unsigned int mask);
 
+typedef void (*SetClipPlanesProc) (CompScreen	*screen,
+				   Region	region,
+				   CompOutput	*output);
+
 void
 preparePaintScreen (CompScreen *screen,
 		    int	       msSinceLastPaint);
@@ -1414,6 +1418,10 @@ paintBackground (CompScreen   *screen,
 		 Region	      region,
 		 unsigned int mask);
 
+void
+setClipPlanes (CompScreen   *screen,
+	       Region	    region,
+	       CompOutput   *output);
 
 /* texture.c */
 
@@ -2003,6 +2011,7 @@ struct _CompScreen {
     PaintTransformedOutputProc	   paintTransformedOutput;
     ApplyScreenTransformProc	   applyScreenTransform;
     PaintBackgroundProc		   paintBackground;
+    SetClipPlanesProc		   setClipPlanes;
     PaintWindowProc		   paintWindow;
     DrawWindowProc		   drawWindow;
     AddWindowGeometryProc	   addWindowGeometry;
diff --git a/include/cube.h b/include/cube.h
index b4670cb..c1dba8f 100644
--- a/include/cube.h
+++ b/include/cube.h
@@ -25,7 +25,7 @@
 
 #include <compiz.h>
 
-#define CUBE_ABIVERSION 20070621
+#define CUBE_ABIVERSION 20070703
 
 #define CUBE_DISPLAY_OPTION_ABI    0
 #define CUBE_DISPLAY_OPTION_INDEX  1
@@ -112,6 +112,7 @@ typedef struct _CubeScreen {
     PaintOutputProc	       paintOutput;
     PaintTransformedOutputProc paintTransformedOutput;
     PaintBackgroundProc        paintBackground;
+    SetClipPlanesProc          setClipPlanes;
     PaintWindowProc            paintWindow;
     ApplyScreenTransformProc   applyScreenTransform;
     SetScreenOptionProc	       setScreenOption;
diff --git a/plugins/cube.c b/plugins/cube.c
index 63a428e..3523e7b 100644
--- a/plugins/cube.c
+++ b/plugins/cube.c
@@ -1681,6 +1681,46 @@ cubePaintBackground (CompScreen   *s,
     cubeUnSetBackgroundOpacity(s);
 }
 
+static void
+cubeSetClipPlanes (CompScreen	*s,
+		   Region	region,
+		   CompOutput*	output)
+{
+    CUBE_SCREEN(s);
+
+    glTranslatef(cs->outputXOffset, -cs->outputYOffset, 0.0f);
+    glScalef( cs->outputXScale, cs->outputYScale, 1.0f);
+
+    UNWRAP(cs, s, setClipPlanes);
+    (*s->setClipPlanes) (s, region, output);
+    WRAP(cs, s, setClipPlanes, cubeSetClipPlanes);
+
+    if (cs->invert == 1)
+    {
+	GLdouble clipPlane0[] = { 1.0, 0.0, 0.5 / cs->distance, 0.0 };
+	GLdouble clipPlane1[] = { -1.0,  0.0, 0.5 / cs->distance, 0.0 };
+	GLdouble clipPlane2[] = { 0.0,  -1.0, 0.5 / cs->distance, 0.0 };
+	GLdouble clipPlane3[] = { 0.0,  1.0, 0.5 / cs->distance, 0.0 };
+
+	glClipPlane (GL_CLIP_PLANE0, clipPlane0);
+	glClipPlane (GL_CLIP_PLANE1, clipPlane1);
+	glClipPlane (GL_CLIP_PLANE2, clipPlane2);
+	glClipPlane (GL_CLIP_PLANE3, clipPlane3);
+    }
+    else
+    {
+	GLdouble clipPlane0[] = { -1.0, 0.0, -0.5 / cs->distance, 0.0 };
+	GLdouble clipPlane1[] = { 1.0,  0.0, -0.5 / cs->distance, 0.0 };
+	GLdouble clipPlane2[] = { 0.0,  1.0, -0.5 / cs->distance, 0.0 };
+	GLdouble clipPlane3[] = { 0.0,  -1.0, -0.5 / cs->distance, 0.0 };
+
+	glClipPlane (GL_CLIP_PLANE0, clipPlane0);
+	glClipPlane (GL_CLIP_PLANE1, clipPlane1);
+	glClipPlane (GL_CLIP_PLANE2, clipPlane2);
+	glClipPlane (GL_CLIP_PLANE3, clipPlane3);
+    }
+}
+
 static Bool
 cubePaintWindow (CompWindow		  *w,
 		 const WindowPaintAttrib  *attrib,
@@ -2133,6 +2173,7 @@ cubeInitScreen (CompPlugin *p,
     WRAP (cs, s, paintOutput, cubePaintOutput);
     WRAP (cs, s, paintTransformedOutput, cubePaintTransformedOutput);
     WRAP (cs, s, paintBackground, cubePaintBackground);
+    WRAP (cs, s, setClipPlanes, cubeSetClipPlanes);
     WRAP (cs, s, paintWindow, cubePaintWindow);
     WRAP (cs, s, applyScreenTransform, cubeApplyScreenTransform);
     WRAP (cs, s, setScreenOption, cubeSetGlobalScreenOption);
@@ -2156,6 +2197,7 @@ cubeFiniScreen (CompPlugin *p,
     UNWRAP (cs, s, paintOutput);
     UNWRAP (cs, s, paintTransformedOutput);
     UNWRAP (cs, s, paintBackground);
+    UNWRAP (cs, s, setClipPlanes);
     UNWRAP (cs, s, paintWindow);
     UNWRAP (cs, s, applyScreenTransform);
     UNWRAP (cs, s, setScreenOption);
diff --git a/src/paint.c b/src/paint.c
index 00cbf73..148f6c8 100644
--- a/src/paint.c
+++ b/src/paint.c
@@ -272,29 +272,10 @@ paintTransformedOutput (CompScreen		*screen,
 
     if ((mask & CLIP_PLANE_MASK) == CLIP_PLANE_MASK)
     {
-	GLdouble h = screen->height;
-
-	GLdouble p1[2] = { region->extents.x1, h - region->extents.y2 };
-	GLdouble p2[2] = { region->extents.x2, h - region->extents.y1 };
-
-	GLdouble halfW = output->width / 2.0;
-	GLdouble halfH = output->height / 2.0;
-
-	GLdouble cx = output->region.extents.x1 + halfW;
-	GLdouble cy = (h - output->region.extents.y2) + halfH;
-
-	GLdouble top[4]    = { 0.0, halfH / (cy - p1[1]), 0.0, 0.5 };
-	GLdouble bottom[4] = { 0.0, halfH / (cy - p2[1]), 0.0, 0.5 };
-	GLdouble left[4]   = { halfW / (cx - p1[0]), 0.0, 0.0, 0.5 };
-	GLdouble right[4]  = { halfW / (cx - p2[0]), 0.0, 0.0, 0.5 };
-
 	glPushMatrix ();
 	glLoadMatrixf (sTransform.m);
 
-	glClipPlane (GL_CLIP_PLANE0, top);
-	glClipPlane (GL_CLIP_PLANE1, bottom);
-	glClipPlane (GL_CLIP_PLANE2, left);
-	glClipPlane (GL_CLIP_PLANE3, right);
+	(*screen->setClipPlanes) (screen, region, output);
 
 	glEnable (GL_CLIP_PLANE0);
 	glEnable (GL_CLIP_PLANE1);
@@ -1167,3 +1148,25 @@ paintBackground (CompScreen   *s,
 
     free (data);
 }
+
+void
+setClipPlanes (CompScreen   *screen,
+	       Region	    region,
+	       CompOutput   *output)
+{
+    GLdouble h = screen->height;
+
+    GLdouble p1[2] = { region->extents.x1, h - region->extents.y2 };
+    GLdouble p2[2] = { region->extents.x2, h - region->extents.y1 };
+
+    GLdouble halfW = output->width / 2.0;
+    GLdouble halfH = output->height / 2.0;
+
+    GLdouble cx = output->region.extents.x1 + halfW;
+    GLdouble cy = (h - output->region.extents.y2) + halfH;
+
+    GLdouble top[4]    = { 0.0, halfH / (cy - p1[1]), 0.0, 0.5 };
+    GLdouble bottom[4] = { 0.0, halfH / (cy - p2[1]), 0.0, 0.5 };
+    GLdouble left[4]   = { halfW / (cx - p1[0]), 0.0, 0.0, 0.5 };
+    GLdouble right[4]  = { halfW / (cx - p2[0]), 0.0, 0.0, 0.5 };
+}
diff --git a/src/screen.c b/src/screen.c
index 9c69c79..46a58b8 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -1565,6 +1565,7 @@ addScreen (CompDisplay *display,
     s->applyScreenTransform	  = applyScreenTransform;
     s->paintBackground		  = paintBackground;
     s->paintWindow		  = paintWindow;
+    s->setClipPlanes		  = setClipPlanes;
     s->drawWindow		  = drawWindow;
     s->addWindowGeometry	  = addWindowGeometry;
     s->drawWindowTexture	  = drawWindowTexture;
-- 
1.5.2.1.280.g38570