Le mercredi 17 février 2010 à 18:51 +0530, Amit Pundir a écrit :
> Hi team,
> 
> I'm trying to create a semi-transparent X11 window. My main aim is to
> draw a translucent window and some 3D(OpenGL-ES2) objects on top of
> it.
> 
> Here is the code http://pastebin.com/m23f802ed For a visual depth=24
> it says that no ARGB visual is found and if I set visual depth=32 then
> I get this error http://pastebin.com/m9b40116
> 
> I'm running X.Org version: 1.7.3, xf86-video-omapfb driver on OMAP3
> based BeagleBoard.
> xdpyinfo is here http://pastebin.com/m11cc1811
> 
> Kindly let me know if I'm missing something.
> 

Perhaps the 32bits visual is not supported by OpenGL.

I don't know how EGL interact with visuals, I'm more used to GLX.
AFAIK not all visuals are compatibles with OpenGL, especially if you
want to use ARGB with composite (+manager). 
In previous tests, only binary NVidia drivers were able to render
correctly in a translucent ARGB window (i have to do tests with newer
X.org KMS drivers ati, nouveau and intel drivers).

Attached is a patch against an old glxgears which search for a visual
matching : Composite ARGB + OpenGL ARGB32.

BTW, could you add the output of glxinfo ?

Regards.

-- 
Yann Droneaud

diff --git a/progs/xdemos/glxgears.c b/progs/xdemos/glxgears.c
index 2dc157a..95564b2 100644
--- a/progs/xdemos/glxgears.c
+++ b/progs/xdemos/glxgears.c
@@ -38,6 +38,7 @@
 #include <X11/keysym.h>
 #include <GL/gl.h>
 #include <GL/glx.h>
+#include <X11/extensions/Xrender.h>
 
 static int is_glx_extension_supported(Display *dpy, const char *query);
 
@@ -250,6 +251,7 @@ gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
 static void
 draw(void)
 {
+  glClearColor(0.0, 0.0, 0.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
    glPushMatrix();
@@ -389,9 +391,9 @@ static void
 init(void)
 {
    static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 };
-   static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 };
-   static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 };
-   static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 };
+   static GLfloat red[4] = { 0.8, 0.1, 0.0, 0.9 };
+   static GLfloat green[4] = { 0.0, 0.8, 0.2, 0.5 };
+   static GLfloat blue[4] = { 0.2, 0.2, 1.0, 0.3 };
 
    glLightfv(GL_LIGHT0, GL_POSITION, pos);
    glEnable(GL_CULL_FACE);
@@ -478,11 +480,13 @@ make_window( Display *dpy, const char *name,
              Window *winRet, GLXContext *ctxRet)
 {
    int attribs[] = { GLX_RGBA,
-                     GLX_RED_SIZE, 1,
-                     GLX_GREEN_SIZE, 1,
-                     GLX_BLUE_SIZE, 1,
+                     GLX_RED_SIZE, 8,
+                     GLX_GREEN_SIZE, 8,
+                     GLX_BLUE_SIZE, 8,
+                     GLX_ALPHA_SIZE, 8,
                      GLX_DOUBLEBUFFER,
                      GLX_DEPTH_SIZE, 1,
+		     GLX_BUFFER_SIZE, 32,
                      None };
    int stereoAttribs[] = { GLX_RGBA,
                            GLX_RED_SIZE, 1,
@@ -500,8 +504,27 @@ make_window( Display *dpy, const char *name,
    GLXContext ctx;
    XVisualInfo *visinfo;
 
+   XVisualInfo *xvinfos;
+   XVisualInfo *xvinfo;
+   /* try to lookup a RGBA visual */
+   XVisualInfo xvinfo_template;
+   int count;
+
+   XRenderPictFormat *pict_format = NULL;
+
    scrnum = DefaultScreen( dpy );
    root = RootWindow( dpy, scrnum );
+   xvinfo = glXChooseVisual(dpy, scrnum, attribs);
+   if (xvinfo == NULL) {
+     fprintf(stderr, "No glx visual matching\n");
+   } else {
+    printf("glxChooseVisual: depth %d, class %d, colormap %d, bits per rgb %d visual id %x\n", 
+	   xvinfo->depth,
+	   xvinfo->class,
+	   xvinfo->colormap_size,
+	   xvinfo->bits_per_rgb,
+	   (unsigned int)xvinfo->visualid);
+   }
 
    if (fullscreen) {
       x = 0; y = 0;
@@ -509,30 +532,142 @@ make_window( Display *dpy, const char *name,
       height = DisplayHeight( dpy, scrnum );
    }
 
-   if (stereo)
-      visinfo = glXChooseVisual( dpy, scrnum, stereoAttribs );
-   else
-      visinfo = glXChooseVisual( dpy, scrnum, attribs );
-   if (!visinfo) {
-      if (stereo) {
-         printf("Error: couldn't get an RGB, "
-                "Double-buffered, Stereo visual\n");
-      } else
-         printf("Error: couldn't get an RGB, Double-buffered visual\n");
-      exit(1);
-   }
+
+  xvinfo_template.screen = scrnum;
+
+  xvinfos = XGetVisualInfo(dpy, 
+			   VisualScreenMask 
+			   /* VisualBitsPerRGBMask */,
+			   &xvinfo_template, &count);
+  
+  if (xvinfos == NULL) {
+    fprintf(stderr, "Can't get visuals\n");
+    return;
+  }
+
+  int i;
+    
+  for(i = 0; i < count; i++) {
+    printf("%d: depth %d, class %d, colormap %d, bits per rgb %d visual id %x\n", 
+	   i,
+	   xvinfos[i].depth,
+	   xvinfos[i].class,
+	   xvinfos[i].colormap_size,
+	   xvinfos[i].bits_per_rgb,
+	   (unsigned int)xvinfos[i].visualid);
+
+    pict_format = XRenderFindVisualFormat(dpy, xvinfos[i].visual);
+    if (pict_format == NULL) {
+      fprintf(stderr, "no format\n");
+      continue;
+    }
+    
+    printf (" 0x%02lx: ", (unsigned long) pict_format->id);
+    switch(pict_format->type) {
+    case PictTypeIndexed:
+      printf("PictTypeIndexed");
+      break;
+    case PictTypeDirect:
+      printf("PictTypeDirect");
+      break;
+    default:
+      printf("Unknown\n");
+    }
+    
+    printf(" %2d R(%d|0x%02x) G(%d|0x%02x) B(%d|0x%02x) A(%d|0x%02x) %lu\n",
+	   pict_format->depth,
+	   pict_format->direct.red,
+	   pict_format->direct.redMask,
+	   pict_format->direct.green,
+	   pict_format->direct.greenMask,
+	   pict_format->direct.blue,
+	   pict_format->direct.blueMask,
+	   pict_format->direct.alpha,
+	   pict_format->direct.alphaMask,
+	   (unsigned long) pict_format->colormap);
+
+    int value;
+    int ret;
+
+    value = 0;
+    ret = glXGetConfig(dpy, &xvinfos[i], GLX_USE_GL, &value);
+    if (ret != 0 || value != True) {
+      printf(" no GL support\n");
+      continue;
+    }
+
+    value = 0;
+    ret = glXGetConfig(dpy, &xvinfos[i], GLX_RGBA, &value);
+    if (ret != 0 || value != True) {
+      printf(" no ARGB support\n");
+      continue;
+    }
+
+    value = 0;
+    ret = glXGetConfig(dpy, &xvinfos[i], GLX_BUFFER_SIZE, &value);
+    if (ret != 0 || value < 32) {
+      printf(" depth < 32\n");
+      continue;
+    }
+
+    value = 0;
+    ret = glXGetConfig(dpy, &xvinfos[i], GLX_RED_SIZE, &value);
+    if (ret != 0 || value < 8) {
+      printf(" red depth < 8\n");
+      continue;
+    }
+    value = 0;
+    ret = glXGetConfig(dpy, &xvinfos[i], GLX_GREEN_SIZE, &value);
+    if (ret != 0 || value < 8) {
+      printf(" green depth < 8\n");
+      continue;
+    }
+    value = 0;
+    ret = glXGetConfig(dpy, &xvinfos[i], GLX_BLUE_SIZE, &value);
+    if (ret != 0 || value < 8) {
+      printf(" blue depth < 8\n");
+      continue;
+    }
+    value = 0;
+    ret = glXGetConfig(dpy, &xvinfos[i], GLX_ALPHA_SIZE, &value);
+    if (ret != 0 || value < 8) {
+      printf(" alpha depth < 8\n");
+      continue;
+    }
+    value = 0;
+    ret = glXGetConfig(dpy, &xvinfos[i], GLX_DOUBLEBUFFER, &value);
+    if (ret != 0 || value != True) {
+      printf(" No double buffer\n");
+#if 0
+      continue;
+#endif
+    }
+
+    if (pict_format->type == PictTypeDirect &&
+	pict_format->depth == 32 && pict_format->direct.alphaMask == 0xff) {
+
+      printf("found visual\n");
+	  	  
+      xvinfo = &xvinfos[i];
+      
+      break;
+
+    } else {
+      printf("not valid pict format for render\n");
+    }
+  }
 
    /* window attributes */
    attr.background_pixel = 0;
    attr.border_pixel = 0;
-   attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
+   attr.colormap = XCreateColormap( dpy, root, xvinfo->visual, AllocNone);
    attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
    /* XXX this is a bad way to get a borderless window! */
    mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
 
    win = XCreateWindow( dpy, root, x, y, width, height,
-		        0, visinfo->depth, InputOutput,
-		        visinfo->visual, mask, &attr );
+		        0, xvinfo->depth, InputOutput,
+		        xvinfo->visual, mask, &attr );
 
    if (fullscreen)
       no_border(dpy, win);
@@ -550,14 +685,12 @@ make_window( Display *dpy, const char *name,
                               None, (char **)NULL, 0, &sizehints);
    }
 
-   ctx = glXCreateContext( dpy, visinfo, NULL, True );
+   ctx = glXCreateContext( dpy, xvinfo, NULL, True );
    if (!ctx) {
       printf("Error: glXCreateContext failed\n");
       exit(1);
    }
 
-   XFree(visinfo);
-
    *winRet = win;
    *ctxRet = ctx;
 }
_______________________________________________
xorg-devel mailing list
[email protected]
http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to